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 #include "chrome/browser/ui/views/reload_button.h" | 5 #include "chrome/browser/ui/views/reload_button.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/command_updater.h" |
10 #include "chrome/browser/ui/views/event_utils.h" | 10 #include "chrome/browser/ui/views/event_utils.h" |
11 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 11 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/views/metrics.h" | 14 #include "ui/views/metrics.h" |
15 | 15 |
16 // static | 16 // static |
17 const char ReloadButton::kViewClassName[] = "browser/ui/views/ReloadButton"; | 17 const char ReloadButton::kViewClassName[] = "browser/ui/views/ReloadButton"; |
18 | 18 |
19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
20 // ReloadButton, public: | 20 // ReloadButton, public: |
21 | 21 |
22 ReloadButton::ReloadButton(LocationBarView* location_bar, Browser* browser) | 22 ReloadButton::ReloadButton(LocationBarView* location_bar, |
23 CommandUpdater* command_updater) | |
23 : ALLOW_THIS_IN_INITIALIZER_LIST(ToggleImageButton(this)), | 24 : ALLOW_THIS_IN_INITIALIZER_LIST(ToggleImageButton(this)), |
24 location_bar_(location_bar), | 25 location_bar_(location_bar), |
25 browser_(browser), | 26 command_updater_(command_updater), |
26 intended_mode_(MODE_RELOAD), | 27 intended_mode_(MODE_RELOAD), |
27 visible_mode_(MODE_RELOAD), | 28 visible_mode_(MODE_RELOAD), |
28 double_click_timer_delay_( | 29 double_click_timer_delay_( |
29 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())), | 30 base::TimeDelta::FromMilliseconds(views::GetDoubleClickInterval())), |
30 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)), | 31 stop_to_reload_timer_delay_(base::TimeDelta::FromMilliseconds(1350)), |
31 testing_mouse_hovered_(false), | 32 testing_mouse_hovered_(false), |
32 testing_reload_count_(0) { | 33 testing_reload_count_(0) { |
33 } | 34 } |
34 | 35 |
35 ReloadButton::~ReloadButton() { | 36 ReloadButton::~ReloadButton() { |
(...skipping 29 matching lines...) Expand all Loading... | |
65 } | 66 } |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
70 // ReloadButton, views::ButtonListener implementation: | 71 // ReloadButton, views::ButtonListener implementation: |
71 | 72 |
72 void ReloadButton::ButtonPressed(views::Button* /* button */, | 73 void ReloadButton::ButtonPressed(views::Button* /* button */, |
73 const views::Event& event) { | 74 const views::Event& event) { |
74 if (visible_mode_ == MODE_STOP) { | 75 if (visible_mode_ == MODE_STOP) { |
75 if (browser_) | 76 if (command_updater_) |
76 browser_->Stop(); | 77 command_updater_->ExecuteCommandWithDisposition(IDC_STOP, CURRENT_TAB); |
77 // The user has clicked, so we can feel free to update the button, | 78 // The user has clicked, so we can feel free to update the button, |
78 // even if the mouse is still hovering. | 79 // even if the mouse is still hovering. |
79 ChangeMode(MODE_RELOAD, true); | 80 ChangeMode(MODE_RELOAD, true); |
80 } else if (!double_click_timer_.IsRunning()) { | 81 } else if (!double_click_timer_.IsRunning()) { |
81 // Shift-clicking or ctrl-clicking the reload button means we should ignore | 82 // Shift-clicking or ctrl-clicking the reload button means we should ignore |
82 // any cached content. | 83 // any cached content. |
83 // TODO(avayvod): eliminate duplication of this logic in | |
84 // CompactLocationBarView. | |
85 int command; | 84 int command; |
86 int flags = mouse_event_flags(); | 85 int flags = mouse_event_flags(); |
87 if (event.IsShiftDown() || event.IsControlDown()) { | 86 if (event.IsShiftDown() || event.IsControlDown()) { |
88 command = IDC_RELOAD_IGNORING_CACHE; | 87 command = IDC_RELOAD_IGNORING_CACHE; |
89 // Mask off Shift and Control so they don't affect the disposition below. | 88 // Mask off Shift and Control so they don't affect the disposition below. |
90 flags &= ~(ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); | 89 flags &= ~(ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); |
91 } else { | 90 } else { |
92 command = IDC_RELOAD; | 91 command = IDC_RELOAD; |
93 } | 92 } |
94 | 93 |
95 WindowOpenDisposition disposition = | 94 WindowOpenDisposition disposition = |
96 event_utils::DispositionFromEventFlags(flags); | 95 event_utils::DispositionFromEventFlags(flags); |
97 if ((disposition == CURRENT_TAB) && location_bar_) { | 96 if ((disposition == CURRENT_TAB) && location_bar_) { |
98 // Forcibly reset the location bar, since otherwise it won't discard any | 97 // Forcibly reset the location bar, since otherwise it won't discard any |
99 // ongoing user edits, since it doesn't realize this is a user-initiated | 98 // ongoing user edits, since it doesn't realize this is a user-initiated |
100 // action. | 99 // action. |
101 location_bar_->Revert(); | 100 location_bar_->Revert(); |
102 } | 101 } |
103 | 102 |
104 // Start a timer - while this timer is running, the reload button cannot be | 103 // Start a timer - while this timer is running, the reload button cannot be |
105 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP | 104 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP |
106 // here as the browser will do that when it actually starts loading (which | 105 // here as the browser will do that when it actually starts loading (which |
107 // may happen synchronously, thus the need to do this before telling the | 106 // may happen synchronously, thus the need to do this before telling the |
108 // browser to execute the reload command). | 107 // browser to execute the reload command). |
109 double_click_timer_.Start(FROM_HERE, double_click_timer_delay_, this, | 108 double_click_timer_.Start(FROM_HERE, double_click_timer_delay_, this, |
110 &ReloadButton::OnDoubleClickTimer); | 109 &ReloadButton::OnDoubleClickTimer); |
111 | 110 |
112 if (browser_) | 111 if (command_updater_) { |
sky
2012/03/12 20:59:19
nit: no {}
altimofeev
2012/03/13 15:38:05
Done.
| |
113 browser_->ExecuteCommandWithDisposition(command, disposition); | 112 command_updater_->ExecuteCommandWithDisposition(command, disposition); |
113 } | |
114 ++testing_reload_count_; | 114 ++testing_reload_count_; |
115 } | 115 } |
116 } | 116 } |
117 | 117 |
118 //////////////////////////////////////////////////////////////////////////////// | 118 //////////////////////////////////////////////////////////////////////////////// |
119 // ReloadButton, View overrides: | 119 // ReloadButton, View overrides: |
120 | 120 |
121 void ReloadButton::OnMouseExited(const views::MouseEvent& event) { | 121 void ReloadButton::OnMouseExited(const views::MouseEvent& event) { |
122 ChangeMode(intended_mode_, true); | 122 ChangeMode(intended_mode_, true); |
123 if (state() != BS_DISABLED) | 123 if (state() != BS_DISABLED) |
(...skipping 15 matching lines...) Expand all Loading... | |
139 //////////////////////////////////////////////////////////////////////////////// | 139 //////////////////////////////////////////////////////////////////////////////// |
140 // ReloadButton, private: | 140 // ReloadButton, private: |
141 | 141 |
142 void ReloadButton::OnDoubleClickTimer() { | 142 void ReloadButton::OnDoubleClickTimer() { |
143 ChangeMode(intended_mode_, false); | 143 ChangeMode(intended_mode_, false); |
144 } | 144 } |
145 | 145 |
146 void ReloadButton::OnStopToReloadTimer() { | 146 void ReloadButton::OnStopToReloadTimer() { |
147 ChangeMode(intended_mode_, true); | 147 ChangeMode(intended_mode_, true); |
148 } | 148 } |
OLD | NEW |