1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef UI_VIEWS_TOUCHUI_TOUCH_SELECTION_MENU_VIEWS_H_
6 #define UI_VIEWS_TOUCHUI_TOUCH_SELECTION_MENU_VIEWS_H_
7 
8 #include "base/macros.h"
9 #include "ui/views/bubble/bubble_dialog_delegate_view.h"
10 #include "ui/views/touchui/touch_selection_menu_runner_views.h"
11 
12 namespace ui {
13 class TouchSelectionMenuClient;
14 }  // namespace ui
15 
16 namespace views {
17 class LabelButton;
18 
19 // A bubble that contains actions available for the selected text. An object of
20 // this type, as a BubbleDialogDelegateView, manages its own lifetime.
21 class VIEWS_EXPORT TouchSelectionMenuViews : public BubbleDialogDelegateView {
22  public:
23   METADATA_HEADER(TouchSelectionMenuViews);
24 
25   enum ButtonViewId : int { kEllipsisButton = 1 };
26 
27   TouchSelectionMenuViews(TouchSelectionMenuRunnerViews* owner,
28                           ui::TouchSelectionMenuClient* client,
29                           aura::Window* context);
30 
31   void ShowMenu(const gfx::Rect& anchor_rect,
32                 const gfx::Size& handle_image_size);
33 
34   // Checks whether there is any command available to show in the menu.
35   static bool IsMenuAvailable(const ui::TouchSelectionMenuClient* client);
36 
37   // Closes the menu. This will eventually self-destroy the object.
38   void CloseMenu();
39 
40  protected:
41   ~TouchSelectionMenuViews() override;
42 
43   // Queries the |client_| for what commands to show in the menu and sizes the
44   // menu appropriately.
45   virtual void CreateButtons();
46 
47   // Helper method to create a single button.
48   LabelButton* CreateButton(const base::string16& title,
49                             Button::PressedCallback callback);
50 
51  private:
52   friend class TouchSelectionMenuRunnerViews::TestApi;
53 
54   void ButtonPressed(int command, const ui::Event& event);
55 
56   // Helper to disconnect this menu object from its owning menu runner.
57   void DisconnectOwner();
58 
59   // BubbleDialogDelegateView:
60   void OnPaint(gfx::Canvas* canvas) override;
61   void WindowClosing() override;
62 
63   TouchSelectionMenuRunnerViews* owner_;
64   ui::TouchSelectionMenuClient* const client_;
65 
66   DISALLOW_COPY_AND_ASSIGN(TouchSelectionMenuViews);
67 };
68 
69 }  // namespace views
70 
71 #endif  // UI_VIEWS_TOUCHUI_TOUCH_SELECTION_MENU_VIEWS_H_
72