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

Side by Side Diff: chrome/browser/ui/views/toolbar/reload_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: Account for maximized state. 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 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_RELOAD_BUTTON_H__ 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
11 #include "chrome/browser/ui/views/toolbar/button_dropdown.h" 11 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
12 #include "ui/base/models/simple_menu_model.h" 12 #include "ui/base/models/simple_menu_model.h"
13 #include "ui/views/controls/button/button.h"
13 14
14 class CommandUpdater; 15 class CommandUpdater;
15 class LocationBarView; 16 class LocationBarView;
16 17
17 //////////////////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////////////////
18 // 19 //
19 // ReloadButton 20 // ReloadButton
20 // 21 //
21 // The reload button in the toolbar, which changes to a stop button when a page 22 // The reload button in the toolbar, which changes to a stop button when a page
22 // load is in progress. Trickiness comes from the desire to have the 'stop' 23 // load is in progress. Trickiness comes from the desire to have the 'stop'
23 // button not change back to 'reload' if the user's mouse is hovering over it 24 // button not change back to 'reload' if the user's mouse is hovering over it
24 // (to prevent mis-clicks). 25 // (to prevent mis-clicks).
25 // 26 //
26 //////////////////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////////////////
27 28
28 class ReloadButton : public ButtonDropDown, 29 class ReloadButton : public ToolbarButton,
29 public views::ButtonListener, 30 public views::ButtonListener,
30 public ui::SimpleMenuModel::Delegate { 31 public ui::SimpleMenuModel::Delegate {
31 public: 32 public:
32 enum Mode { MODE_RELOAD = 0, MODE_STOP }; 33 enum Mode { MODE_RELOAD = 0, MODE_STOP };
33 34
34 // The button's class name. 35 // The button's class name.
35 static const char kViewClassName[]; 36 static const char kViewClassName[];
36 37
37 ReloadButton(LocationBarView* location_bar, 38 ReloadButton(LocationBarView* location_bar,
38 CommandUpdater* command_updater); 39 CommandUpdater* command_updater);
39 virtual ~ReloadButton(); 40 virtual ~ReloadButton();
40 41
41 // Ask for a specified button state. If |force| is true this will be applied 42 // Ask for a specified button state. If |force| is true this will be applied
42 // immediately. 43 // immediately.
43 void ChangeMode(Mode mode, bool force); 44 void ChangeMode(Mode mode, bool force);
44 45
45 // Enable reload drop-down menu. 46 // Enable reload drop-down menu.
46 void set_menu_enabled(bool enable) { menu_enabled_ = enable; } 47 void set_menu_enabled(bool enable) { menu_enabled_ = enable; }
47 48
48 void LoadImages(); 49 void LoadImages();
49 50
50 // Overridden from views::View: 51 // views::View:
Peter Kasting 2013/11/23 00:23:55 Nit: Either in this change or a followup, merge th
Greg Billock 2013/11/25 17:16:30 Done.
51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 52 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
52 virtual bool GetTooltipText(const gfx::Point& p, 53 virtual bool GetTooltipText(const gfx::Point& p,
53 string16* tooltip) const OVERRIDE; 54 string16* tooltip) const OVERRIDE;
54 virtual const char* GetClassName() const OVERRIDE; 55 virtual const char* GetClassName() const OVERRIDE;
55 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 56 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
56 57
57 // Overridden from views::ButtonDropDown: 58 // ToolbarButton:
58 virtual bool ShouldShowMenu() OVERRIDE; 59 virtual bool ShouldShowMenu() OVERRIDE;
59 virtual void ShowDropDownMenu(ui::MenuSourceType source_type) OVERRIDE; 60 virtual void ShowDropDownMenu(ui::MenuSourceType source_type) OVERRIDE;
60 61
61 // Overridden from views::ButtonListener: 62 // views::ButtonListener:
62 virtual void ButtonPressed(views::Button* /* button */, 63 virtual void ButtonPressed(views::Button* /* button */,
63 const ui::Event& event) OVERRIDE; 64 const ui::Event& event) OVERRIDE;
64 65
65 // Overridden from ui::SimpleMenuModel::Delegate: 66 // ui::SimpleMenuModel::Delegate:
66 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 67 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
67 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 68 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
68 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; 69 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE;
69 virtual bool GetAcceleratorForCommandId( 70 virtual bool GetAcceleratorForCommandId(
70 int command_id, 71 int command_id,
71 ui::Accelerator* accelerator) OVERRIDE; 72 ui::Accelerator* accelerator) OVERRIDE;
72 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 73 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
73 74
74 private: 75 private:
75 friend class ReloadButtonTest; 76 friend class ReloadButtonTest;
(...skipping 20 matching lines...) Expand all
96 Mode visible_mode_; 97 Mode visible_mode_;
97 98
98 // The delay times for the timers. These are members so that tests can modify 99 // The delay times for the timers. These are members so that tests can modify
99 // them. 100 // them.
100 base::TimeDelta double_click_timer_delay_; 101 base::TimeDelta double_click_timer_delay_;
101 base::TimeDelta stop_to_reload_timer_delay_; 102 base::TimeDelta stop_to_reload_timer_delay_;
102 103
103 // Indicates if reload menu is enabled. 104 // Indicates if reload menu is enabled.
104 bool menu_enabled_; 105 bool menu_enabled_;
105 106
106 // The parent class's images_ member is used for the current images,
107 // and this array is used to hold the alternative images.
108 // We swap between the two when changing mode.
109 gfx::ImageSkia alternate_images_[STATE_COUNT];
110
111 // TESTING ONLY 107 // TESTING ONLY
112 // True if we should pretend the button is hovered. 108 // True if we should pretend the button is hovered.
113 bool testing_mouse_hovered_; 109 bool testing_mouse_hovered_;
114 // Increments when we would tell the browser to "reload", so 110 // Increments when we would tell the browser to "reload", so
115 // test code can tell whether we did so (as there may be no |browser_|). 111 // test code can tell whether we did so (as there may be no |browser_|).
116 int testing_reload_count_; 112 int testing_reload_count_;
117 113
118 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton); 114 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton);
119 }; 115 };
120 116
121 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ 117 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698