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"
17 ////////////////////////////////////////////////////////////////////////////////
21 // 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 // button not change back to 'reload' if the user's mouse is hovering over it
24 // (to prevent mis-clicks).
26 ////////////////////////////////////////////////////////////////////////////////
28 class ReloadButton
: public ToolbarButton
,
29 public views::ButtonListener
,
30 public ui::SimpleMenuModel::Delegate
{
32 enum Mode
{ MODE_RELOAD
= 0, MODE_STOP
};
34 // The button's class name.
35 static const char kViewClassName
[];
37 explicit ReloadButton(CommandUpdater
* command_updater
);
38 ~ReloadButton() override
;
40 // Ask for a specified button state. If |force| is true this will be applied
42 void ChangeMode(Mode mode
, bool force
);
44 // Enable reload drop-down menu.
45 void set_menu_enabled(bool enable
) { menu_enabled_
= enable
; }
50 void OnMouseExited(const ui::MouseEvent
& event
) override
;
51 bool GetTooltipText(const gfx::Point
& p
,
52 base::string16
* tooltip
) const override
;
53 const char* GetClassName() const override
;
54 void GetAccessibleState(ui::AXViewState
* state
) override
;
55 bool ShouldShowMenu() override
;
56 void ShowDropDownMenu(ui::MenuSourceType source_type
) override
;
58 // views::ButtonListener:
59 void ButtonPressed(views::Button
* /* button */,
60 const ui::Event
& event
) override
;
62 // ui::SimpleMenuModel::Delegate:
63 bool IsCommandIdChecked(int command_id
) const override
;
64 bool IsCommandIdEnabled(int command_id
) const override
;
65 bool IsCommandIdVisible(int command_id
) const override
;
66 bool GetAcceleratorForCommandId(int command_id
,
67 ui::Accelerator
* accelerator
) override
;
68 void ExecuteCommand(int command_id
, int event_flags
) override
;
71 friend class ReloadButtonTest
;
73 ui::SimpleMenuModel
* CreateMenuModel();
75 void ExecuteBrowserCommand(int command
, int event_flags
);
76 void ChangeModeInternal(Mode mode
);
78 void OnDoubleClickTimer();
79 void OnStopToReloadTimer();
81 base::OneShotTimer
<ReloadButton
> double_click_timer_
;
82 base::OneShotTimer
<ReloadButton
> stop_to_reload_timer_
;
84 // This may be NULL when testing.
85 CommandUpdater
* command_updater_
;
87 // The mode we should be in assuming no timers are running.
90 // The currently-visible mode - this may differ from the intended mode.
93 // The delay times for the timers. These are members so that tests can modify
95 base::TimeDelta double_click_timer_delay_
;
96 base::TimeDelta stop_to_reload_timer_delay_
;
98 // Indicates if reload menu is enabled.
102 // True if we should pretend the button is hovered.
103 bool testing_mouse_hovered_
;
104 // Increments when we would tell the browser to "reload", so
105 // test code can tell whether we did so (as there may be no |browser_|).
106 int testing_reload_count_
;
108 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton
);
111 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__