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 UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
6 #define UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "ui/views/controls/button/label_button.h" |
9 #include "ui/views/context_menu_controller.h" | 9 #include "ui/views/context_menu_controller.h" |
10 #include "ui/views/controls/button/image_button.h" | 10 #include "ui/views/controls/button/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; | |
18 } | |
17 | 19 |
18 class MenuRunner; | 20 // This class provides basic drawing and mouse-over behavior for buttons |
21 // appearing in the toolbar. | |
22 // See ButtonDropDown. | |
Peter Kasting
2013/11/15 03:28:58
ButtonDropDown no longer exists, AFAICT.
Greg Billock
2013/11/15 19:36:50
ui/views/controls/button/button_dropdown.h still e
Peter Kasting
2013/11/15 22:11:56
My guiding principle is "scope things narrowly", s
| |
23 class ToolbarButton : public views::LabelButton, | |
Peter Kasting
2013/11/15 03:28:58
Would we also make the "wrench" button (as it's st
Greg Billock
2013/11/15 19:36:50
Yes. I only did the one here to make sure we have
Peter Kasting
2013/11/15 22:11:56
K. Either way is OK, whatever ends up being simpl
| |
24 public views::ButtonListener, | |
25 public views::ContextMenuController { | |
26 public: | |
27 // Takes ownership of the |model|, which can be null if no menu | |
28 // is to be shown. | |
29 ToolbarButton(ui::MenuModel* model); | |
30 virtual ~ToolbarButton(); | |
19 | 31 |
20 //////////////////////////////////////////////////////////////////////////////// | 32 // Set up basic behavior. Should be called by any subclasses. |
21 // | 33 void Init(); |
22 // ButtonDropDown | |
23 // | |
24 // A button class that when pressed (and held) or pressed (and drag down) will | |
25 // display a menu | |
26 // | |
27 //////////////////////////////////////////////////////////////////////////////// | |
28 class VIEWS_EXPORT ButtonDropDown : public ImageButton, | |
29 public ContextMenuController { | |
30 public: | |
31 // The button's class name. | |
32 static const char kViewClassName[]; | |
33 | 34 |
34 // Takes ownership of the |model|. | 35 // views::ButtonListener. Default implementation does nothing. |
35 ButtonDropDown(ButtonListener* listener, ui::MenuModel* model); | 36 virtual void ButtonPressed(views::Button* sender, |
36 virtual ~ButtonDropDown(); | 37 const ui::Event& event) OVERRIDE; |
37 | 38 |
38 // If menu is currently pending for long press - stop it. | 39 // Methods for handling ButtonDropDown-style menus. |
39 void ClearPendingMenu(); | 40 void ClearPendingMenu(); |
40 | |
41 // Indicates if menu is currently showing. | |
42 bool IsMenuShowing() const; | 41 bool IsMenuShowing() const; |
43 | 42 |
44 // Overridden from views::View | 43 // Overridden from views::View |
45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 44 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
46 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | 45 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
47 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 46 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. | 47 // Showing the drop down results in a MouseCaptureLost, we need to ignore it. |
50 virtual void OnMouseCaptureLost() OVERRIDE {} | 48 virtual void OnMouseCaptureLost() OVERRIDE {} |
51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 49 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
52 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 50 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
53 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 51 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
54 | 52 |
55 // Overridden from views::ContextMenuController | 53 // Overridden from views::ContextMenuController |
56 virtual void ShowContextMenuForView(View* source, | 54 virtual void ShowContextMenuForView(View* source, |
57 const gfx::Point& point, | 55 const gfx::Point& point, |
58 ui::MenuSourceType source_type) OVERRIDE; | 56 ui::MenuSourceType source_type) OVERRIDE; |
(...skipping 15 matching lines...) Expand all Loading... | |
74 // The model that populates the attached menu. | 72 // The model that populates the attached menu. |
75 scoped_ptr<ui::MenuModel> model_; | 73 scoped_ptr<ui::MenuModel> model_; |
76 | 74 |
77 // Indicates if menu is currently showing. | 75 // Indicates if menu is currently showing. |
78 bool menu_showing_; | 76 bool menu_showing_; |
79 | 77 |
80 // Y position of mouse when left mouse button is pressed | 78 // Y position of mouse when left mouse button is pressed |
81 int y_position_on_lbuttondown_; | 79 int y_position_on_lbuttondown_; |
82 | 80 |
83 // Menu runner to display drop down menu. | 81 // Menu runner to display drop down menu. |
84 scoped_ptr<MenuRunner> menu_runner_; | 82 scoped_ptr<views::MenuRunner> menu_runner_; |
85 | 83 |
86 // A factory for tasks that show the dropdown context menu for the button. | 84 // A factory for tasks that show the dropdown context menu for the button. |
87 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_; | 85 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; |
88 | 86 |
89 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown); | 87 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); |
90 }; | 88 }; |
91 | 89 |
92 } // namespace views | 90 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
93 | |
94 #endif // UI_VIEWS_CONTROLS_BUTTON_BUTTON_DROPDOWN_H_ | |
OLD | NEW |