OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
10 #include "ui/views/animation/ink_drop_host.h" | |
11 #include "ui/views/context_menu_controller.h" | 10 #include "ui/views/context_menu_controller.h" |
12 #include "ui/views/controls/button/button.h" | 11 #include "ui/views/controls/button/button.h" |
13 #include "ui/views/controls/button/label_button.h" | 12 #include "ui/views/controls/button/label_button.h" |
14 | 13 |
15 class Profile; | 14 class Profile; |
16 | 15 |
17 namespace ui { | 16 namespace ui { |
18 class MenuModel; | 17 class MenuModel; |
19 } | 18 } |
20 | 19 |
21 namespace views { | 20 namespace views { |
22 class InkDropDelegate; | 21 class InkDropDelegate; |
23 class MenuRunner; | 22 class MenuRunner; |
24 } | 23 } |
25 | 24 |
26 // This class provides basic drawing and mouse-over behavior for buttons | 25 // This class provides basic drawing and mouse-over behavior for buttons |
27 // appearing in the toolbar. | 26 // appearing in the toolbar. |
28 class ToolbarButton : public views::LabelButton, | 27 class ToolbarButton : public views::LabelButton, |
29 public views::ContextMenuController, | 28 public views::ContextMenuController { |
30 public views::InkDropHost { | |
31 public: | 29 public: |
32 // Takes ownership of the |model|, which can be null if no menu | 30 // Takes ownership of the |model|, which can be null if no menu |
33 // is to be shown. | 31 // is to be shown. |
34 ToolbarButton(Profile* profile, | 32 ToolbarButton(Profile* profile, |
35 views::ButtonListener* listener, | 33 views::ButtonListener* listener, |
36 ui::MenuModel* model); | 34 ui::MenuModel* model); |
37 ~ToolbarButton() override; | 35 ~ToolbarButton() override; |
38 | 36 |
39 // Set up basic mouseover border behavior. | 37 // Set up basic mouseover border behavior. |
40 // Should be called before first paint. | 38 // Should be called before first paint. |
41 void Init(); | 39 void Init(); |
42 | 40 |
43 // Methods for handling ButtonDropDown-style menus. | 41 // Methods for handling ButtonDropDown-style menus. |
44 void ClearPendingMenu(); | 42 void ClearPendingMenu(); |
45 bool IsMenuShowing() const; | 43 bool IsMenuShowing() const; |
46 | 44 |
47 // views::LabelButton: | 45 // views::LabelButton: |
48 gfx::Size GetPreferredSize() const override; | 46 gfx::Size GetPreferredSize() const override; |
49 bool OnMousePressed(const ui::MouseEvent& event) override; | 47 bool OnMousePressed(const ui::MouseEvent& event) override; |
50 bool OnMouseDragged(const ui::MouseEvent& event) override; | 48 bool OnMouseDragged(const ui::MouseEvent& event) override; |
51 void OnMouseReleased(const ui::MouseEvent& event) override; | 49 void OnMouseReleased(const ui::MouseEvent& event) override; |
52 // Showing the drop down results in a MouseCaptureLost, we need to ignore it. | 50 // Showing the drop down results in a MouseCaptureLost, we need to ignore it. |
53 void OnMouseCaptureLost() override; | 51 void OnMouseCaptureLost() override; |
54 void OnMouseExited(const ui::MouseEvent& event) override; | 52 void OnMouseExited(const ui::MouseEvent& event) override; |
55 void OnGestureEvent(ui::GestureEvent* event) override; | 53 void OnGestureEvent(ui::GestureEvent* event) override; |
56 void GetAccessibleState(ui::AXViewState* state) override; | 54 void GetAccessibleState(ui::AXViewState* state) override; |
57 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; | 55 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
| 56 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 57 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
58 | 58 |
59 // views::ContextMenuController: | 59 // views::ContextMenuController: |
60 void ShowContextMenuForView(View* source, | 60 void ShowContextMenuForView(View* source, |
61 const gfx::Point& point, | 61 const gfx::Point& point, |
62 ui::MenuSourceType source_type) override; | 62 ui::MenuSourceType source_type) override; |
63 | 63 |
64 // views::InkDropHost: | |
65 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | |
66 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; | |
67 | |
68 protected: | 64 protected: |
69 // views::LabelButton: | 65 // views::LabelButton: |
70 bool ShouldEnterPushedState(const ui::Event& event) override; | 66 bool ShouldEnterPushedState(const ui::Event& event) override; |
71 | 67 |
72 // Returns if menu should be shown. Override this to change default behavior. | 68 // Returns if menu should be shown. Override this to change default behavior. |
73 virtual bool ShouldShowMenu(); | 69 virtual bool ShouldShowMenu(); |
74 | 70 |
75 // Function to show the dropdown menu. | 71 // Function to show the dropdown menu. |
76 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); | 72 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); |
77 | 73 |
78 private: | 74 private: |
79 // views::LabelButton: | 75 // views::LabelButton: |
80 const char* GetClassName() const override; | 76 const char* GetClassName() const override; |
81 | 77 |
82 // views::InkDropHost: | |
83 gfx::Point CalculateInkDropCenter() const override; | |
84 | |
85 // The associated profile. The browser theme affects rendering. | 78 // The associated profile. The browser theme affects rendering. |
86 Profile* profile_; | 79 Profile* profile_; |
87 | 80 |
88 // The model that populates the attached menu. | 81 // The model that populates the attached menu. |
89 scoped_ptr<ui::MenuModel> model_; | 82 scoped_ptr<ui::MenuModel> model_; |
90 | 83 |
91 // Indicates if menu is currently showing. | 84 // Indicates if menu is currently showing. |
92 bool menu_showing_; | 85 bool menu_showing_; |
93 | 86 |
94 // Y position of mouse when left mouse button is pressed. | 87 // Y position of mouse when left mouse button is pressed. |
95 int y_position_on_lbuttondown_; | 88 int y_position_on_lbuttondown_; |
96 | 89 |
97 // Menu runner to display drop down menu. | 90 // Menu runner to display drop down menu. |
98 scoped_ptr<views::MenuRunner> menu_runner_; | 91 scoped_ptr<views::MenuRunner> menu_runner_; |
99 | 92 |
100 // Controls the visual feedback for the button state. | 93 // Controls the visual feedback for the button state. |
101 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; | 94 scoped_ptr<views::InkDropDelegate> ink_drop_delegate_; |
102 | 95 |
103 // A factory for tasks that show the dropdown context menu for the button. | 96 // A factory for tasks that show the dropdown context menu for the button. |
104 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; | 97 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; |
105 | 98 |
106 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); | 99 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); |
107 }; | 100 }; |
108 | 101 |
109 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ | 102 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
OLD | NEW |