[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / toolbar / reload_button.h
blob5cbdf4230e88cb8589f88b1228bad7f72ffcf348
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"
15 class CommandUpdater;
17 ////////////////////////////////////////////////////////////////////////////////
19 // ReloadButton
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 {
31 public:
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 virtual ~ReloadButton();
40 // Ask for a specified button state. If |force| is true this will be applied
41 // immediately.
42 void ChangeMode(Mode mode, bool force);
44 // Enable reload drop-down menu.
45 void set_menu_enabled(bool enable) { menu_enabled_ = enable; }
47 void LoadImages();
49 // ToolbarButton:
50 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
51 virtual bool GetTooltipText(const gfx::Point& p,
52 base::string16* tooltip) const OVERRIDE;
53 virtual const char* GetClassName() const OVERRIDE;
54 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
55 virtual bool ShouldShowMenu() OVERRIDE;
56 virtual void ShowDropDownMenu(ui::MenuSourceType source_type) OVERRIDE;
58 // views::ButtonListener:
59 virtual void ButtonPressed(views::Button* /* button */,
60 const ui::Event& event) OVERRIDE;
62 // ui::SimpleMenuModel::Delegate:
63 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
64 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
65 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE;
66 virtual bool GetAcceleratorForCommandId(
67 int command_id,
68 ui::Accelerator* accelerator) OVERRIDE;
69 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
71 private:
72 friend class ReloadButtonTest;
74 ui::SimpleMenuModel* CreateMenuModel();
76 void ExecuteBrowserCommand(int command, int event_flags);
77 void ChangeModeInternal(Mode mode);
79 void OnDoubleClickTimer();
80 void OnStopToReloadTimer();
82 base::OneShotTimer<ReloadButton> double_click_timer_;
83 base::OneShotTimer<ReloadButton> stop_to_reload_timer_;
85 // This may be NULL when testing.
86 CommandUpdater* command_updater_;
88 // The mode we should be in assuming no timers are running.
89 Mode intended_mode_;
91 // The currently-visible mode - this may differ from the intended mode.
92 Mode visible_mode_;
94 // The delay times for the timers. These are members so that tests can modify
95 // them.
96 base::TimeDelta double_click_timer_delay_;
97 base::TimeDelta stop_to_reload_timer_delay_;
99 // Indicates if reload menu is enabled.
100 bool menu_enabled_;
102 // TESTING ONLY
103 // True if we should pretend the button is hovered.
104 bool testing_mouse_hovered_;
105 // Increments when we would tell the browser to "reload", so
106 // test code can tell whether we did so (as there may be no |browser_|).
107 int testing_reload_count_;
109 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton);
112 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__