1 // Copyright (c) 2011 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. 4 5 #ifndef CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 6 #define CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 7 #pragma once 8 9 #include "base/basictypes.h" 10 #include "base/gtest_prod_util.h" 11 #include "base/timer.h" 12 #include "views/controls/button/image_button.h" 13 14 class Browser; 15 class LocationBarView; 16 17 //////////////////////////////////////////////////////////////////////////////// 18 // 19 // ReloadButton 20 // 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). 25 // 26 //////////////////////////////////////////////////////////////////////////////// 27 28 class ReloadButton : public views::ToggleImageButton, 29 public views::ButtonListener { 30 public: 31 enum Mode { MODE_RELOAD = 0, MODE_STOP }; 32 33 ReloadButton(LocationBarView* location_bar, Browser* Browser); 34 virtual ~ReloadButton(); 35 36 // Ask for a specified button state. If |force| is true this will be applied 37 // immediately. 38 void ChangeMode(Mode mode, bool force); 39 40 // Overridden from views::ButtonListener: 41 virtual void ButtonPressed(views::Button* /* button */, 42 const views::Event& event) OVERRIDE; 43 44 // Overridden from views::View: 45 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; 46 virtual bool GetTooltipText(const gfx::Point& p, 47 std::wstring* tooltip) OVERRIDE; 48 49 private: 50 friend class ReloadButtonTest; 51 52 void OnDoubleClickTimer(); 53 void OnStopToReloadTimer(); 54 55 base::OneShotTimer<ReloadButton> double_click_timer_; 56 base::OneShotTimer<ReloadButton> stop_to_reload_timer_; 57 58 // These may be NULL when testing. 59 LocationBarView* location_bar_; 60 Browser* browser_; 61 62 // The mode we should be in assuming no timers are running. 63 Mode intended_mode_; 64 65 // The currently-visible mode - this may differ from the intended mode. 66 Mode visible_mode_; 67 68 // The delay times for the timers. These are members so that tests can modify 69 // them. 70 base::TimeDelta double_click_timer_delay_; 71 base::TimeDelta stop_to_reload_timer_delay_; 72 73 // TESTING ONLY 74 // True if we should pretend the button is hovered. 75 bool testing_mouse_hovered_; 76 // Increments when we would tell the browser to "reload", so 77 // test code can tell whether we did so (as there may be no |browser_|). 78 int testing_reload_count_; 79 80 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton); 81 }; 82 83 #endif // CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 84