| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_TOOLBAR_RELOAD_BUTTON_H__ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ | 6 #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| 11 #include "chrome/browser/ui/views/toolbar/button_dropdown.h" | 11 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 12 #include "ui/base/models/simple_menu_model.h" | 12 #include "ui/base/models/simple_menu_model.h" |
| 13 #include "ui/views/controls/button/button.h" |
| 13 | 14 |
| 14 class CommandUpdater; | 15 class CommandUpdater; |
| 15 class LocationBarView; | 16 class LocationBarView; |
| 16 | 17 |
| 17 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 18 // | 19 // |
| 19 // ReloadButton | 20 // ReloadButton |
| 20 // | 21 // |
| 21 // The reload button in the toolbar, which changes to a stop button when a page | 22 // 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 // 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 // button not change back to 'reload' if the user's mouse is hovering over it |
| 24 // (to prevent mis-clicks). | 25 // (to prevent mis-clicks). |
| 25 // | 26 // |
| 26 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
| 27 | 28 |
| 28 class ReloadButton : public ButtonDropDown, | 29 class ReloadButton : public ToolbarButton, |
| 29 public views::ButtonListener, | 30 public views::ButtonListener, |
| 30 public ui::SimpleMenuModel::Delegate { | 31 public ui::SimpleMenuModel::Delegate { |
| 31 public: | 32 public: |
| 32 enum Mode { MODE_RELOAD = 0, MODE_STOP }; | 33 enum Mode { MODE_RELOAD = 0, MODE_STOP }; |
| 33 | 34 |
| 34 // The button's class name. | 35 // The button's class name. |
| 35 static const char kViewClassName[]; | 36 static const char kViewClassName[]; |
| 36 | 37 |
| 37 ReloadButton(LocationBarView* location_bar, | 38 ReloadButton(LocationBarView* location_bar, |
| 38 CommandUpdater* command_updater); | 39 CommandUpdater* command_updater); |
| 39 virtual ~ReloadButton(); | 40 virtual ~ReloadButton(); |
| 40 | 41 |
| 41 // Ask for a specified button state. If |force| is true this will be applied | 42 // Ask for a specified button state. If |force| is true this will be applied |
| 42 // immediately. | 43 // immediately. |
| 43 void ChangeMode(Mode mode, bool force); | 44 void ChangeMode(Mode mode, bool force); |
| 44 | 45 |
| 45 // Enable reload drop-down menu. | 46 // Enable reload drop-down menu. |
| 46 void set_menu_enabled(bool enable) { menu_enabled_ = enable; } | 47 void set_menu_enabled(bool enable) { menu_enabled_ = enable; } |
| 47 | 48 |
| 48 void LoadImages(); | 49 void LoadImages(); |
| 49 | 50 |
| 50 // Overridden from views::View: | 51 // ToolbarButton: |
| 51 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 52 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 52 virtual bool GetTooltipText(const gfx::Point& p, | 53 virtual bool GetTooltipText(const gfx::Point& p, |
| 53 string16* tooltip) const OVERRIDE; | 54 string16* tooltip) const OVERRIDE; |
| 54 virtual const char* GetClassName() const OVERRIDE; | 55 virtual const char* GetClassName() const OVERRIDE; |
| 55 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 56 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 56 | |
| 57 // Overridden from views::ButtonDropDown: | |
| 58 virtual bool ShouldShowMenu() OVERRIDE; | 57 virtual bool ShouldShowMenu() OVERRIDE; |
| 59 virtual void ShowDropDownMenu(ui::MenuSourceType source_type) OVERRIDE; | 58 virtual void ShowDropDownMenu(ui::MenuSourceType source_type) OVERRIDE; |
| 60 | 59 |
| 61 // Overridden from views::ButtonListener: | 60 // views::ButtonListener: |
| 62 virtual void ButtonPressed(views::Button* /* button */, | 61 virtual void ButtonPressed(views::Button* /* button */, |
| 63 const ui::Event& event) OVERRIDE; | 62 const ui::Event& event) OVERRIDE; |
| 64 | 63 |
| 65 // Overridden from ui::SimpleMenuModel::Delegate: | 64 // ui::SimpleMenuModel::Delegate: |
| 66 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 65 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 67 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 66 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 68 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; | 67 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; |
| 69 virtual bool GetAcceleratorForCommandId( | 68 virtual bool GetAcceleratorForCommandId( |
| 70 int command_id, | 69 int command_id, |
| 71 ui::Accelerator* accelerator) OVERRIDE; | 70 ui::Accelerator* accelerator) OVERRIDE; |
| 72 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; | 71 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 friend class ReloadButtonTest; | 74 friend class ReloadButtonTest; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 96 Mode visible_mode_; | 95 Mode visible_mode_; |
| 97 | 96 |
| 98 // The delay times for the timers. These are members so that tests can modify | 97 // The delay times for the timers. These are members so that tests can modify |
| 99 // them. | 98 // them. |
| 100 base::TimeDelta double_click_timer_delay_; | 99 base::TimeDelta double_click_timer_delay_; |
| 101 base::TimeDelta stop_to_reload_timer_delay_; | 100 base::TimeDelta stop_to_reload_timer_delay_; |
| 102 | 101 |
| 103 // Indicates if reload menu is enabled. | 102 // Indicates if reload menu is enabled. |
| 104 bool menu_enabled_; | 103 bool menu_enabled_; |
| 105 | 104 |
| 106 // The parent class's images_ member is used for the current images, | |
| 107 // and this array is used to hold the alternative images. | |
| 108 // We swap between the two when changing mode. | |
| 109 gfx::ImageSkia alternate_images_[STATE_COUNT]; | |
| 110 | |
| 111 // TESTING ONLY | 105 // TESTING ONLY |
| 112 // True if we should pretend the button is hovered. | 106 // True if we should pretend the button is hovered. |
| 113 bool testing_mouse_hovered_; | 107 bool testing_mouse_hovered_; |
| 114 // Increments when we would tell the browser to "reload", so | 108 // Increments when we would tell the browser to "reload", so |
| 115 // test code can tell whether we did so (as there may be no |browser_|). | 109 // test code can tell whether we did so (as there may be no |browser_|). |
| 116 int testing_reload_count_; | 110 int testing_reload_count_; |
| 117 | 111 |
| 118 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton); | 112 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton); |
| 119 }; | 113 }; |
| 120 | 114 |
| 121 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ | 115 #endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_RELOAD_BUTTON_H__ |
| OLD | NEW |