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

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

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

Powered by Google App Engine
This is Rietveld 408576698