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