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