| 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 "ui/views/context_menu_controller.h" | 8 #include "ui/views/context_menu_controller.h" |
| 9 #include "ui/views/controls/button/button.h" | 9 #include "ui/views/controls/button/button.h" |
| 10 #include "ui/views/controls/button/label_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 // This class provides basic drawing and mouse-over behavior for buttons | 20 // This class provides basic drawing and mouse-over behavior for buttons |
| 21 // appearing in the toolbar. | 21 // appearing in the toolbar. |
| 22 class ToolbarButton : public views::LabelButton, | 22 class ToolbarButton : public views::LabelButton, |
| 23 public views::ContextMenuController { | 23 public views::ContextMenuController { |
| 24 public: | 24 public: |
| 25 // Takes ownership of the |model|, which can be null if no menu | 25 // Takes ownership of the |model|, which can be null if no menu |
| 26 // is to be shown. | 26 // is to be shown. |
| 27 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model); | 27 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model); |
| 28 virtual ~ToolbarButton(); | 28 ~ToolbarButton() override; |
| 29 | 29 |
| 30 // Set up basic mouseover border behavior. | 30 // Set up basic mouseover border behavior. |
| 31 // Should be called before first paint. | 31 // Should be called before first paint. |
| 32 void Init(); | 32 void Init(); |
| 33 | 33 |
| 34 // Methods for handling ButtonDropDown-style menus. | 34 // Methods for handling ButtonDropDown-style menus. |
| 35 void ClearPendingMenu(); | 35 void ClearPendingMenu(); |
| 36 bool IsMenuShowing() const; | 36 bool IsMenuShowing() const; |
| 37 | 37 |
| 38 // views::LabelButton: | 38 // views::LabelButton: |
| 39 virtual gfx::Size GetPreferredSize() const override; | 39 gfx::Size GetPreferredSize() const override; |
| 40 virtual bool OnMousePressed(const ui::MouseEvent& event) override; | 40 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 41 virtual bool OnMouseDragged(const ui::MouseEvent& event) override; | 41 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 42 virtual void OnMouseReleased(const ui::MouseEvent& event) override; | 42 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 43 // 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. |
| 44 virtual void OnMouseCaptureLost() override; | 44 void OnMouseCaptureLost() override; |
| 45 virtual void OnMouseExited(const ui::MouseEvent& event) override; | 45 void OnMouseExited(const ui::MouseEvent& event) override; |
| 46 virtual void OnGestureEvent(ui::GestureEvent* event) override; | 46 void OnGestureEvent(ui::GestureEvent* event) override; |
| 47 virtual void GetAccessibleState(ui::AXViewState* state) override; | 47 void GetAccessibleState(ui::AXViewState* state) override; |
| 48 virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const | 48 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; |
| 49 override; | |
| 50 | 49 |
| 51 // views::ContextMenuController: | 50 // views::ContextMenuController: |
| 52 virtual void ShowContextMenuForView(View* source, | 51 void ShowContextMenuForView(View* source, |
| 53 const gfx::Point& point, | 52 const gfx::Point& point, |
| 54 ui::MenuSourceType source_type) override; | 53 ui::MenuSourceType source_type) override; |
| 55 | 54 |
| 56 protected: | 55 protected: |
| 57 // Overridden from CustomButton. Returns true if the button should become | 56 // Overridden from CustomButton. Returns true if the button should become |
| 58 // pressed when a user holds the mouse down over the button. For this | 57 // pressed when a user holds the mouse down over the button. For this |
| 59 // implementation, both left and right mouse buttons can trigger a change | 58 // implementation, both left and right mouse buttons can trigger a change |
| 60 // to the PUSHED state. | 59 // to the PUSHED state. |
| 61 virtual bool ShouldEnterPushedState(const ui::Event& event) override; | 60 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 62 | 61 |
| 63 // Returns if menu should be shown. Override this to change default behavior. | 62 // Returns if menu should be shown. Override this to change default behavior. |
| 64 virtual bool ShouldShowMenu(); | 63 virtual bool ShouldShowMenu(); |
| 65 | 64 |
| 66 // Function to show the dropdown menu. | 65 // Function to show the dropdown menu. |
| 67 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); | 66 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 // The model that populates the attached menu. | 69 // The model that populates the attached menu. |
| 71 scoped_ptr<ui::MenuModel> model_; | 70 scoped_ptr<ui::MenuModel> model_; |
| 72 | 71 |
| 73 // Indicates if menu is currently showing. | 72 // Indicates if menu is currently showing. |
| 74 bool menu_showing_; | 73 bool menu_showing_; |
| 75 | 74 |
| 76 // Y position of mouse when left mouse button is pressed | 75 // Y position of mouse when left mouse button is pressed |
| 77 int y_position_on_lbuttondown_; | 76 int y_position_on_lbuttondown_; |
| 78 | 77 |
| 79 // Menu runner to display drop down menu. | 78 // Menu runner to display drop down menu. |
| 80 scoped_ptr<views::MenuRunner> menu_runner_; | 79 scoped_ptr<views::MenuRunner> menu_runner_; |
| 81 | 80 |
| 82 // A factory for tasks that show the dropdown context menu for the button. | 81 // A factory for tasks that show the dropdown context menu for the button. |
| 83 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; | 82 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; |
| 84 | 83 |
| 85 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); | 84 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ | 87 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ |
| OLD | NEW |