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

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

Issue 62873007: [Toolbar] Base toolbar button class with background images for button states (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add home button Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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_BUTTON_DROPDOWN_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BUTTON_DROPDOWN_H_ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
7 7
8 #include "base/memory/weak_ptr.h"
9 #include "ui/views/context_menu_controller.h" 8 #include "ui/views/context_menu_controller.h"
10 #include "ui/views/controls/button/image_button.h" 9 #include "ui/views/controls/button/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 //////////////////////////////////////////////////////////////////////////////// 20 // This class provides basic drawing and mouse-over behavior for buttons
21 // 21 // appearing in the toolbar.
22 // ButtonDropDown 22 // See ButtonDropDown.
Peter Kasting 2013/11/19 02:28:50 I don't understand why we're saying "See ButtonDro
Greg Billock 2013/11/20 00:59:03 This was stale. Deleting.
23 // 23 class ToolbarButton : public views::LabelButton,
24 // A button class that when pressed (and held) or pressed (and drag down) will 24 public views::ButtonListener,
25 // display a menu 25 public views::ContextMenuController {
26 //
27 ////////////////////////////////////////////////////////////////////////////////
28 class ButtonDropDown : public views::ImageButton,
29 public views::ContextMenuController {
30 public: 26 public:
31 // The button's class name. 27 // Takes ownership of the |model|, which can be null if no menu
32 static const char kViewClassName[]; 28 // is to be shown.
29 ToolbarButton(views::ButtonListener* listener, ui::MenuModel* model);
30 virtual ~ToolbarButton();
33 31
34 // Takes ownership of the |model|. 32 // Set up basic behavior. Should be called by any subclasses.
Peter Kasting 2013/11/19 02:28:50 Nit: When?
Greg Billock 2013/11/20 00:59:03 Done.
35 ButtonDropDown(views::ButtonListener* listener, ui::MenuModel* model); 33 void Init();
Peter Kasting 2013/11/19 02:28:50 Nit: Place all overrides together and all non-over
Greg Billock 2013/11/20 00:59:03 Done. I like Init() type methods right after the c
36 virtual ~ButtonDropDown();
37 34
38 // If menu is currently pending for long press - stop it. 35 // views::ButtonListener. Default implementation does nothing.
Peter Kasting 2013/11/19 02:28:50 Why do we need to subclass ButtonListener at all?
Greg Billock 2013/11/20 00:59:03 It's something we'll want for the site chip, but a
36 virtual void ButtonPressed(views::Button* sender,
37 const ui::Event& event) OVERRIDE;
38
39 // Methods for handling ButtonDropDown-style menus.
39 void ClearPendingMenu(); 40 void ClearPendingMenu();
40
41 // Indicates if menu is currently showing.
42 bool IsMenuShowing() const; 41 bool IsMenuShowing() const;
43 42
44 // Overridden from views::View 43 // Overridden from views::View
Peter Kasting 2013/11/19 02:28:50 Nit: While here, fix these comments to just look l
Greg Billock 2013/11/20 00:59:03 Done.
45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 44 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
46 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; 45 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
47 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 46 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
48 virtual const char* GetClassName() const 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 virtual void OnMouseCaptureLost() OVERRIDE {} 48 virtual void OnMouseCaptureLost() OVERRIDE {}
Peter Kasting 2013/11/19 02:28:50 Nit: While here, don't define virtual function bod
Greg Billock 2013/11/20 00:59:03 Done.
51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 49 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
52 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 50 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
53 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 51 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
52 virtual gfx::Size GetPreferredSize();
Peter Kasting 2013/11/19 02:28:50 Nit: This should be at the top of the list instead
Greg Billock 2013/11/20 00:59:03 Done.
54 53
55 // Overridden from views::ContextMenuController 54 // Overridden from views::ContextMenuController
56 virtual void ShowContextMenuForView(views::View* source, 55 virtual void ShowContextMenuForView(View* source,
57 const gfx::Point& point, 56 const gfx::Point& point,
58 ui::MenuSourceType source_type) OVERRIDE; 57 ui::MenuSourceType source_type) OVERRIDE;
59 58
60 protected: 59 protected:
61 // Overridden from CustomButton. Returns true if the button should become 60 // Overridden from CustomButton. Returns true if the button should become
62 // pressed when a user holds the mouse down over the button. For this 61 // pressed when a user holds the mouse down over the button. For this
63 // implementation, both left and right mouse buttons can trigger a change 62 // implementation, both left and right mouse buttons can trigger a change
64 // to the PUSHED state. 63 // to the PUSHED state.
65 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE; 64 virtual bool ShouldEnterPushedState(const ui::Event& event) OVERRIDE;
66 65
(...skipping 10 matching lines...) Expand all
77 // Indicates if menu is currently showing. 76 // Indicates if menu is currently showing.
78 bool menu_showing_; 77 bool menu_showing_;
79 78
80 // Y position of mouse when left mouse button is pressed 79 // Y position of mouse when left mouse button is pressed
81 int y_position_on_lbuttondown_; 80 int y_position_on_lbuttondown_;
82 81
83 // Menu runner to display drop down menu. 82 // Menu runner to display drop down menu.
84 scoped_ptr<views::MenuRunner> menu_runner_; 83 scoped_ptr<views::MenuRunner> menu_runner_;
85 84
86 // A factory for tasks that show the dropdown context menu for the button. 85 // A factory for tasks that show the dropdown context menu for the button.
87 base::WeakPtrFactory<ButtonDropDown> show_menu_factory_; 86 base::WeakPtrFactory<ToolbarButton> show_menu_factory_;
88 87
89 DISALLOW_COPY_AND_ASSIGN(ButtonDropDown); 88 DISALLOW_COPY_AND_ASSIGN(ToolbarButton);
90 }; 89 };
91 90
92 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BUTTON_DROPDOWN_H_ 91 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698