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