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