OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_BUTTON_DROPDOWN_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BUTTON_DROPDOWN_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | |
9 #include "ui/views/context_menu_controller.h" | 8 #include "ui/views/context_menu_controller.h" |
10 #include "ui/views/controls/button/image_button.h" | 9 #include "ui/views/controls/button/button.h" |
10 #include "ui/views/controls/button/label_button.h" | |
11 | 11 |
12 namespace ui { | 12 namespace ui { |
13 class MenuModel; | 13 class MenuModel; |
14 } | 14 } |
15 | 15 |
16 namespace views { | 16 namespace views { |
17 class MenuRunner; | 17 class MenuRunner; |
18 } | 18 } |
19 | 19 |
20 //////////////////////////////////////////////////////////////////////////////// | 20 // This class provides basic drawing and mouse-over behavior for buttons |
21 // | 21 // appearing in the toolbar. |
22 // ButtonDropDown | 22 class ToolbarButton : public views::LabelButton, |
23 // | 23 public views::ContextMenuController { |
24 // A button class that when pressed (and held) or pressed (and drag down) will | |
25 // display a menu | |
26 // | |
27 //////////////////////////////////////////////////////////////////////////////// | |
28 class ButtonDropDown : public views::ImageButton, | |
29 public views::ContextMenuController { | |
30 public: | 24 public: |
31 // The button's class name. | 25 // Takes ownership of the |model|, which can be null if no menu |
32 static const char kViewClassName[]; | 26 // is to be shown. |
27 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model); | |
28 virtual ~ToolbarButton(); | |
33 | 29 |
34 // Takes ownership of the |model|. | 30 // Set up basic mouseover border behavior. |
35 ButtonDropDown(views::ButtonListener* listener, ui::MenuModel* model); | 31 // Should be called before first paint. |
36 virtual ~ButtonDropDown(); | 32 void Init(); |
37 | 33 |
38 // If menu is currently pending for long press - stop it. | 34 // Methods for handling ButtonDropDown-style menus. |
39 void ClearPendingMenu(); | 35 void ClearPendingMenu(); |
40 | |
41 // Indicates if menu is currently showing. | |
42 bool IsMenuShowing() const; | 36 bool IsMenuShowing() const; |
43 | 37 |
44 // Overridden from views::View | 38 // views::LabelButton: |
39 virtual gfx::Size GetPreferredSize(); | |
45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 40 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
46 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | 41 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
47 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 42 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
48 virtual const char* GetClassName() const OVERRIDE; | |
49 // Showing the drop down results in a MouseCaptureLost, we need to ignore it. | 43 // Showing the drop down results in a MouseCaptureLost, we need to ignore it. |
50 virtual void OnMouseCaptureLost() OVERRIDE {} | 44 virtual void OnMouseCaptureLost() OVERRIDE; |
51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 45 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
52 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 46 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
53 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 47 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
48 virtual gfx::Rect GetThemePaintRect() const OVERRIDE; | |
Peter Kasting
2013/11/23 00:23:55
Because only the back button needs this override,
Greg Billock
2013/11/25 17:16:30
Makes sense. Looking at the wrench menu, it wants
Peter Kasting
2013/11/26 02:25:46
Is your intent to do this in a separate change, th
Greg Billock
2013/11/26 16:58:32
Yeah I'd like to check this in so the site chip cl
| |
54 | 49 |
55 // Overridden from views::ContextMenuController | 50 // views::ContextMenuController: |
56 virtual void ShowContextMenuForView(views::View* source, | 51 virtual void ShowContextMenuForView(View* source, |
57 const gfx::Point& point, | 52 const gfx::Point& point, |
58 ui::MenuSourceType source_type) OVERRIDE; | 53 ui::MenuSourceType source_type) OVERRIDE; |
59 | 54 |
55 void SetLeftMargin(int margin); | |
56 | |
60 protected: | 57 protected: |
61 // Overridden from CustomButton. Returns true if the button should become | 58 // Overridden from CustomButton. Returns true if the button should become |
62 // pressed when a user holds the mouse down over the button. For this | 59 // pressed when a user holds the mouse down over the button. For this |
63 // implementation, both left and right mouse buttons can trigger a change | 60 // implementation, both left and right mouse buttons can trigger a change |
64 // to the PUSHED state. | 61 // to the PUSHED state. |
65 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE; | 62 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE; |
66 | 63 |
67 // Returns if menu should be shown. Override this to change default behavior. | 64 // Returns if menu should be shown. Override this to change default behavior. |
68 virtual bool ShouldShowMenu(); | 65 virtual bool ShouldShowMenu(); |
69 | 66 |
70 // Function to show the dropdown menu. | 67 // Function to show the dropdown menu. |
71 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); | 68 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); |
72 | 69 |
73 private: | 70 private: |
74 // The model that populates the attached menu. | 71 // The model that populates the attached menu. |
75 scoped_ptr<ui::MenuModel> model_; | 72 scoped_ptr<ui::MenuModel> model_; |
76 | 73 |
77 // Indicates if menu is currently showing. | 74 // Indicates if menu is currently showing. |
78 bool menu_showing_; | 75 bool menu_showing_; |
79 | 76 |
80 // Y position of mouse when left mouse button is pressed | 77 // Y position of mouse when left mouse button is pressed |
81 int y_position_on_lbuttondown_; | 78 int y_position_on_lbuttondown_; |
82 | 79 |
80 // Any leading margin to be applied. Used when toolbar buttons are in | |
81 // a maximized state to extend to the full window width. | |
82 int margin_left_; | |
83 | |
83 // Menu runner to display drop down menu. | 84 // Menu runner to display drop down menu. |
84 scoped_ptr<views::MenuRunner> menu_runner_; | 85 scoped_ptr<views::MenuRunner> menu_runner_; |
85 | 86 |
86 // A factory for tasks that show the dropdown context menu for the button. | 87 // A factory for tasks that show the dropdown context menu for the button. |
87 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_; | 88 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown); | 90 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); |
90 }; | 91 }; |
91 | 92 |
92 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BUTTON_DROPDOWN_H_ | 93 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
OLD | NEW |