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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__
6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__
8 #include "base/basictypes.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/timer/timer.h"
11 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
12 #include "ui/base/models/simple_menu_model.h"
13 #include "ui/views/controls/button/button.h"
16 class LocationBarView
;
18 ////////////////////////////////////////////////////////////////////////////////
22 // The reload button in the toolbar, which changes to a stop button when a page
23 // load is in progress. Trickiness comes from the desire to have the 'stop'
24 // button not change back to 'reload' if the user's mouse is hovering over it
25 // (to prevent mis-clicks).
27 ////////////////////////////////////////////////////////////////////////////////
29 class ReloadButton
: public ToolbarButton
,
30 public views::ButtonListener
,
31 public ui::SimpleMenuModel::Delegate
{
33 enum Mode
{ MODE_RELOAD
= 0, MODE_STOP
};
35 // The button's class name.
36 static const char kViewClassName
[];
38 ReloadButton(LocationBarView
* location_bar
,
39 CommandUpdater
* command_updater
);
40 virtual ~ReloadButton();
42 // Ask for a specified button state. If |force| is true this will be applied
44 void ChangeMode(Mode mode
, bool force
);
46 // Enable reload drop-down menu.
47 void set_menu_enabled(bool enable
) { menu_enabled_
= enable
; }
52 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
53 virtual bool GetTooltipText(const gfx::Point
& p
,
54 base::string16
* tooltip
) const OVERRIDE
;
55 virtual const char* GetClassName() const OVERRIDE
;
56 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
57 virtual bool ShouldShowMenu() OVERRIDE
;
58 virtual void ShowDropDownMenu(ui::MenuSourceType source_type
) OVERRIDE
;
60 // views::ButtonListener:
61 virtual void ButtonPressed(views::Button
* /* button */,
62 const ui::Event
& event
) OVERRIDE
;
64 // ui::SimpleMenuModel::Delegate:
65 virtual bool IsCommandIdChecked(int command_id
) const OVERRIDE
;
66 virtual bool IsCommandIdEnabled(int command_id
) const OVERRIDE
;
67 virtual bool IsCommandIdVisible(int command_id
) const OVERRIDE
;
68 virtual bool GetAcceleratorForCommandId(
70 ui::Accelerator
* accelerator
) OVERRIDE
;
71 virtual void ExecuteCommand(int command_id
, int event_flags
) OVERRIDE
;
74 friend class ReloadButtonTest
;
76 ui::SimpleMenuModel
* CreateMenuModel();
78 void ExecuteBrowserCommand(int command
, int event_flags
);
79 void ChangeModeInternal(Mode mode
);
81 void OnDoubleClickTimer();
82 void OnStopToReloadTimer();
84 base::OneShotTimer
<ReloadButton
> double_click_timer_
;
85 base::OneShotTimer
<ReloadButton
> stop_to_reload_timer_
;
87 // These may be NULL when testing.
88 LocationBarView
* location_bar_
;
89 CommandUpdater
* command_updater_
;
91 // The mode we should be in assuming no timers are running.
94 // The currently-visible mode - this may differ from the intended mode.
97 // The delay times for the timers. These are members so that tests can modify
99 base::TimeDelta double_click_timer_delay_
;
100 base::TimeDelta stop_to_reload_timer_delay_
;
102 // Indicates if reload menu is enabled.
106 // True if we should pretend the button is hovered.
107 bool testing_mouse_hovered_
;
108 // Increments when we would tell the browser to "reload", so
109 // test code can tell whether we did so (as there may be no |browser_|).
110 int testing_reload_count_
;
112 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton
);
115 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__