Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_button.h

Issue 1478303003: Converted all Views to use an InkDropDelegate instead of a InkDropAnimationController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved some ripple controlling logic up the Button hierarchy. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
21 class MenuRunner; 20 class MenuRunner;
22 } 21 }
23 22
24 // This class provides basic drawing and mouse-over behavior for buttons 23 // This class provides basic drawing and mouse-over behavior for buttons
25 // appearing in the toolbar. 24 // appearing in the toolbar.
26 class ToolbarButton : public views::LabelButton, 25 class ToolbarButton : public views::LabelButton,
27 public views::ContextMenuController, 26 public views::ContextMenuController,
28 public views::InkDropHost { 27 public views::InkDropHost {
29 public: 28 public:
30 // 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
31 // is to be shown. 30 // is to be shown.
32 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model); 31 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model);
33 ~ToolbarButton() override; 32 ~ToolbarButton() override;
34 33
35 // Set up basic mouseover border behavior. 34 // Set up basic mouseover border behavior.
36 // Should be called before first paint. 35 // Should be called before first paint.
37 void Init(); 36 void Init();
38 37
39 // Methods for handling ButtonDropDown-style menus. 38 // Methods for handling ButtonDropDown-style menus.
40 void ClearPendingMenu(); 39 void ClearPendingMenu();
41 bool IsMenuShowing() const; 40 bool IsMenuShowing() const;
42 41
43 // views::LabelButton: 42 // views::LabelButton:
44 gfx::Size GetPreferredSize() const override; 43 gfx::Size GetPreferredSize() const override;
45 void Layout() override;
46 bool OnMousePressed(const ui::MouseEvent& event) override; 44 bool OnMousePressed(const ui::MouseEvent& event) override;
47 bool OnMouseDragged(const ui::MouseEvent& event) override; 45 bool OnMouseDragged(const ui::MouseEvent& event) override;
48 void OnMouseReleased(const ui::MouseEvent& event) override; 46 void OnMouseReleased(const ui::MouseEvent& event) 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 void OnMouseCaptureLost() override; 48 void OnMouseCaptureLost() override;
51 void OnMouseExited(const ui::MouseEvent& event) override; 49 void OnMouseExited(const ui::MouseEvent& event) override;
52 void OnGestureEvent(ui::GestureEvent* event) override; 50 void OnGestureEvent(ui::GestureEvent* event) override;
53 void GetAccessibleState(ui::AXViewState* state) override; 51 void GetAccessibleState(ui::AXViewState* state) override;
54 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override; 52 scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const override;
55 53
56 // views::ContextMenuController: 54 // views::ContextMenuController:
57 void ShowContextMenuForView(View* source, 55 void ShowContextMenuForView(View* source,
58 const gfx::Point& point, 56 const gfx::Point& point,
59 ui::MenuSourceType source_type) override; 57 ui::MenuSourceType source_type) override;
60 58
61 // views::InkDropHost: 59 // views::InkDropHost:
62 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; 60 void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
63 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; 61 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
64 62
65 protected: 63 protected:
66 // views::LabelButton: 64 // views::LabelButton:
67 bool ShouldEnterPushedState(const ui::Event& event) override; 65 bool ShouldEnterPushedState(const ui::Event& event) override;
68 void NotifyClick(const ui::Event& event) override;
69 void OnClickCanceled(const ui::Event& event) override;
70 66
71 // Returns if menu should be shown. Override this to change default behavior. 67 // Returns if menu should be shown. Override this to change default behavior.
72 virtual bool ShouldShowMenu(); 68 virtual bool ShouldShowMenu();
73 69
74 // Function to show the dropdown menu. 70 // Function to show the dropdown menu.
75 virtual void ShowDropDownMenu(ui::MenuSourceType source_type); 71 virtual void ShowDropDownMenu(ui::MenuSourceType source_type);
76 72
77 views::InkDropAnimationController* ink_drop_animation_controller() {
78 return ink_drop_animation_controller_.get();
79 }
80
81 private: 73 private:
82 // views::LabelButton: 74 // views::LabelButton:
83 const char* GetClassName() const override; 75 const char* GetClassName() const override;
84 76
85 // views::InkDropHost: 77 // views::InkDropHost:
86 gfx::Point CalculateInkDropCenter() const override; 78 gfx::Point CalculateInkDropCenter() const override;
87 79
88 // The model that populates the attached menu. 80 // The model that populates the attached menu.
89 scoped_ptr<ui::MenuModel> model_; 81 scoped_ptr<ui::MenuModel> model_;
90 82
91 // Indicates if menu is currently showing. 83 // Indicates if menu is currently showing.
92 bool menu_showing_; 84 bool menu_showing_;
93 85
94 // Y position of mouse when left mouse button is pressed. 86 // Y position of mouse when left mouse button is pressed.
95 int y_position_on_lbuttondown_; 87 int y_position_on_lbuttondown_;
96 88
97 // Menu runner to display drop down menu. 89 // Menu runner to display drop down menu.
98 scoped_ptr<views::MenuRunner> menu_runner_; 90 scoped_ptr<views::MenuRunner> menu_runner_;
99 91
100 // Animation controller for the ink drop ripple effect.
101 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_;
102
103 // A factory for tasks that show the dropdown context menu for the button. 92 // A factory for tasks that show the dropdown context menu for the button.
104 base::WeakPtrFactory<ToolbarButton> show_menu_factory_; 93 base::WeakPtrFactory<ToolbarButton> show_menu_factory_;
105 94
106 DISALLOW_COPY_AND_ASSIGN(ToolbarButton); 95 DISALLOW_COPY_AND_ASSIGN(ToolbarButton);
107 }; 96 };
108 97
109 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_ 98 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698