summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/go_button.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-15 18:08:49 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-15 18:08:49 +0000
commitc398981aa94189d9173b304e5b1d67f97e79fbc8 (patch)
treea76be0ddc0038b3e9c2d28736e351fc0117e1320 /chrome/browser/views/go_button.cc
parent8aa31e5bb274abd6f5eb43e6297e00cf6d365856 (diff)
downloadchromium_src-c398981aa94189d9173b304e5b1d67f97e79fbc8.zip
chromium_src-c398981aa94189d9173b304e5b1d67f97e79fbc8.tar.gz
chromium_src-c398981aa94189d9173b304e5b1d67f97e79fbc8.tar.bz2
Fix regression I introduced where Stop/Go button would toggle state instantly instead of having protections against accidental user actions while the mouse was hovering the button.
I elected to condense ChangeMode() and ScheduleChangeMode() into one function, which as a result became pretty simple. BUG=9843 Review URL: http://codereview.chromium.org/67156 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13761 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/go_button.cc')
-rw-r--r--chrome/browser/views/go_button.cc44
1 files changed, 12 insertions, 32 deletions
diff --git a/chrome/browser/views/go_button.cc b/chrome/browser/views/go_button.cc
index f276e92..4c6de94 100644
--- a/chrome/browser/views/go_button.cc
+++ b/chrome/browser/views/go_button.cc
@@ -32,33 +32,17 @@ GoButton::~GoButton() {
stop_timer_.RevokeAll();
}
-void GoButton::ChangeMode(Mode mode) {
- stop_timer_.RevokeAll();
-
- SetToggled(mode == MODE_STOP);
+void GoButton::ChangeMode(Mode mode, bool force) {
intended_mode_ = mode;
- visible_mode_ = mode;
-}
-void GoButton::ScheduleChangeMode(Mode mode) {
- if (mode == MODE_STOP) {
- // If we still have a timer running, we can't yet change to a stop sign,
- // so we'll queue up the change for when the timer expires or for when
- // the mouse exits the button.
- if (!stop_timer_.empty() && state() == BS_HOT) {
- intended_mode_ = MODE_STOP;
- } else {
- ChangeMode(MODE_STOP);
- }
- } else {
- // If we want to change the button to a go button, but the user's mouse
- // is hovering, don't change the mode just yet - this prevents the
- // stop button changing to a go under the user's mouse cursor.
- if (visible_mode_ == MODE_STOP && state() == BS_HOT) {
- intended_mode_ = MODE_GO;
- } else {
- ChangeMode(MODE_GO);
- }
+ // If the change is forced, or the user isn't hovering the icon, or it's safe
+ // to change it to the other image type, make the change immediately;
+ // otherwise we'll let it happen later.
+ if (force || (state() != BS_HOT) || ((mode == MODE_STOP) ?
+ stop_timer_.empty() : (visible_mode_ != MODE_STOP))) {
+ stop_timer_.RevokeAll();
+ SetToggled(mode == MODE_STOP);
+ visible_mode_ = mode;
}
}
@@ -71,7 +55,7 @@ void GoButton::ButtonPressed(views::Button* button) {
// The user has clicked, so we can feel free to update the button,
// even if the mouse is still hovering.
- ChangeMode(MODE_GO);
+ ChangeMode(MODE_GO, true);
} else if (visible_mode_ == MODE_GO && stop_timer_.empty()) {
// If the go button is visible and not within the double click timer, go.
browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags()));
@@ -98,9 +82,7 @@ void GoButton::ButtonPressed(views::Button* button) {
// GoButton, View overrides:
void GoButton::OnMouseExited(const views::MouseEvent& e) {
- if (visible_mode_ != intended_mode_)
- ChangeMode(intended_mode_);
-
+ ChangeMode(intended_mode_, true);
if (state() != BS_DISABLED)
SetState(BS_NORMAL);
}
@@ -140,8 +122,6 @@ bool GoButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
// GoButton, private:
void GoButton::OnButtonTimer() {
- if (intended_mode_ != visible_mode_)
- ChangeMode(intended_mode_);
-
stop_timer_.RevokeAll();
+ ChangeMode(intended_mode_, true);
}