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