| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/go_button.h" | 5 #include "chrome/browser/views/go_button.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/views/event_utils.h" | 10 #include "chrome/browser/views/event_utils.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 stop_timer_(this) { | 25 stop_timer_(this) { |
| 26 DCHECK(location_bar_); | 26 DCHECK(location_bar_); |
| 27 set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | | 27 set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | |
| 28 views::Event::EF_MIDDLE_BUTTON_DOWN); | 28 views::Event::EF_MIDDLE_BUTTON_DOWN); |
| 29 } | 29 } |
| 30 | 30 |
| 31 GoButton::~GoButton() { | 31 GoButton::~GoButton() { |
| 32 stop_timer_.RevokeAll(); | 32 stop_timer_.RevokeAll(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void GoButton::ChangeMode(Mode mode) { | 35 void GoButton::ChangeMode(Mode mode, bool force) { |
| 36 stop_timer_.RevokeAll(); | 36 intended_mode_ = mode; |
| 37 | 37 |
| 38 SetToggled(mode == MODE_STOP); | 38 // If the change is forced, or the user isn't hovering the icon, or it's safe |
| 39 intended_mode_ = mode; | 39 // to change it to the other image type, make the change immediately; |
| 40 visible_mode_ = mode; | 40 // otherwise we'll let it happen later. |
| 41 } | 41 if (force || (state() != BS_HOT) || ((mode == MODE_STOP) ? |
| 42 | 42 stop_timer_.empty() : (visible_mode_ != MODE_STOP))) { |
| 43 void GoButton::ScheduleChangeMode(Mode mode) { | 43 stop_timer_.RevokeAll(); |
| 44 if (mode == MODE_STOP) { | 44 SetToggled(mode == MODE_STOP); |
| 45 // If we still have a timer running, we can't yet change to a stop sign, | 45 visible_mode_ = mode; |
| 46 // so we'll queue up the change for when the timer expires or for when | |
| 47 // the mouse exits the button. | |
| 48 if (!stop_timer_.empty() && state() == BS_HOT) { | |
| 49 intended_mode_ = MODE_STOP; | |
| 50 } else { | |
| 51 ChangeMode(MODE_STOP); | |
| 52 } | |
| 53 } else { | |
| 54 // If we want to change the button to a go button, but the user's mouse | |
| 55 // is hovering, don't change the mode just yet - this prevents the | |
| 56 // stop button changing to a go under the user's mouse cursor. | |
| 57 if (visible_mode_ == MODE_STOP && state() == BS_HOT) { | |
| 58 intended_mode_ = MODE_GO; | |
| 59 } else { | |
| 60 ChangeMode(MODE_GO); | |
| 61 } | |
| 62 } | 46 } |
| 63 } | 47 } |
| 64 | 48 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
| 66 // GoButton, views::ButtonListener implementation: | 50 // GoButton, views::ButtonListener implementation: |
| 67 | 51 |
| 68 void GoButton::ButtonPressed(views::Button* button) { | 52 void GoButton::ButtonPressed(views::Button* button) { |
| 69 if (visible_mode_ == MODE_STOP) { | 53 if (visible_mode_ == MODE_STOP) { |
| 70 browser_->Stop(); | 54 browser_->Stop(); |
| 71 | 55 |
| 72 // The user has clicked, so we can feel free to update the button, | 56 // The user has clicked, so we can feel free to update the button, |
| 73 // even if the mouse is still hovering. | 57 // even if the mouse is still hovering. |
| 74 ChangeMode(MODE_GO); | 58 ChangeMode(MODE_GO, true); |
| 75 } else if (visible_mode_ == MODE_GO && stop_timer_.empty()) { | 59 } else if (visible_mode_ == MODE_GO && stop_timer_.empty()) { |
| 76 // If the go button is visible and not within the double click timer, go. | 60 // If the go button is visible and not within the double click timer, go. |
| 77 browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags())); | 61 browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags())); |
| 78 | 62 |
| 79 // Figure out the system double-click time. | 63 // Figure out the system double-click time. |
| 80 if (button_delay_ == NULL) | 64 if (button_delay_ == NULL) |
| 81 button_delay_ = GetDoubleClickTime(); | 65 button_delay_ = GetDoubleClickTime(); |
| 82 | 66 |
| 83 // Stop any existing timers. | 67 // Stop any existing timers. |
| 84 stop_timer_.RevokeAll(); | 68 stop_timer_.RevokeAll(); |
| 85 | 69 |
| 86 // Start a timer - while this timer is running, the go button | 70 // Start a timer - while this timer is running, the go button |
| 87 // cannot be changed to a stop button. We do not set intended_mode_ | 71 // cannot be changed to a stop button. We do not set intended_mode_ |
| 88 // to MODE_STOP here as we want to wait for the browser to tell | 72 // to MODE_STOP here as we want to wait for the browser to tell |
| 89 // us that it has started loading (and this may occur only after | 73 // us that it has started loading (and this may occur only after |
| 90 // some delay). | 74 // some delay). |
| 91 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 75 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 92 stop_timer_.NewRunnableMethod(&GoButton::OnButtonTimer), | 76 stop_timer_.NewRunnableMethod(&GoButton::OnButtonTimer), |
| 93 button_delay_); | 77 button_delay_); |
| 94 } | 78 } |
| 95 } | 79 } |
| 96 | 80 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 98 // GoButton, View overrides: | 82 // GoButton, View overrides: |
| 99 | 83 |
| 100 void GoButton::OnMouseExited(const views::MouseEvent& e) { | 84 void GoButton::OnMouseExited(const views::MouseEvent& e) { |
| 101 if (visible_mode_ != intended_mode_) | 85 ChangeMode(intended_mode_, true); |
| 102 ChangeMode(intended_mode_); | |
| 103 | |
| 104 if (state() != BS_DISABLED) | 86 if (state() != BS_DISABLED) |
| 105 SetState(BS_NORMAL); | 87 SetState(BS_NORMAL); |
| 106 } | 88 } |
| 107 | 89 |
| 108 bool GoButton::GetTooltipText(int x, int y, std::wstring* tooltip) { | 90 bool GoButton::GetTooltipText(int x, int y, std::wstring* tooltip) { |
| 109 if (visible_mode_ == MODE_STOP) { | 91 if (visible_mode_ == MODE_STOP) { |
| 110 tooltip->assign(l10n_util::GetString(IDS_TOOLTIP_STOP)); | 92 tooltip->assign(l10n_util::GetString(IDS_TOOLTIP_STOP)); |
| 111 return true; | 93 return true; |
| 112 } | 94 } |
| 113 | 95 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 tooltip->assign(true ? | 115 tooltip->assign(true ? |
| 134 l10n_util::GetStringF(IDS_TOOLTIP_GO_SITE, current_text) : | 116 l10n_util::GetStringF(IDS_TOOLTIP_GO_SITE, current_text) : |
| 135 l10n_util::GetStringF(IDS_TOOLTIP_GO_SEARCH, L"Google", current_text)); | 117 l10n_util::GetStringF(IDS_TOOLTIP_GO_SEARCH, L"Google", current_text)); |
| 136 return true; | 118 return true; |
| 137 } | 119 } |
| 138 | 120 |
| 139 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
| 140 // GoButton, private: | 122 // GoButton, private: |
| 141 | 123 |
| 142 void GoButton::OnButtonTimer() { | 124 void GoButton::OnButtonTimer() { |
| 143 if (intended_mode_ != visible_mode_) | |
| 144 ChangeMode(intended_mode_); | |
| 145 | |
| 146 stop_timer_.RevokeAll(); | 125 stop_timer_.RevokeAll(); |
| 126 ChangeMode(intended_mode_, true); |
| 147 } | 127 } |
| OLD | NEW |