diff options
-rw-r--r-- | chrome/browser/gtk/go_button_gtk.cc | 48 | ||||
-rw-r--r-- | chrome/browser/gtk/go_button_gtk.h | 11 |
2 files changed, 16 insertions, 43 deletions
diff --git a/chrome/browser/gtk/go_button_gtk.cc b/chrome/browser/gtk/go_button_gtk.cc index 21e3536..ebc48bb 100644 --- a/chrome/browser/gtk/go_button_gtk.cc +++ b/chrome/browser/gtk/go_button_gtk.cc @@ -48,35 +48,18 @@ GoButtonGtk::~GoButtonGtk() { widget_.Destroy(); } -void GoButtonGtk::ChangeMode(Mode mode) { - if (mode != visible_mode_) { - gtk_widget_queue_draw(widget_.get()); - visible_mode_ = mode; - SetTooltip(); - } - stop_timer_.RevokeAll(); +void GoButtonGtk::ChangeMode(Mode mode, bool force) { intended_mode_ = mode; -} -void GoButtonGtk::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(); + gtk_widget_queue_draw(widget_.get()); + SetTooltip(); + visible_mode_ = mode; } } @@ -85,11 +68,8 @@ Task* GoButtonGtk::CreateButtonTimerTask() { } void GoButtonGtk::OnButtonTimer() { - if (intended_mode_ != visible_mode_) { - ChangeMode(intended_mode_); - } - stop_timer_.RevokeAll(); + ChangeMode(intended_mode_, true); } // static @@ -114,9 +94,7 @@ gboolean GoButtonGtk::OnEnter(GtkButton* widget, GoButtonGtk* button) { gboolean GoButtonGtk::OnLeave(GtkButton* widget, GoButtonGtk* button) { DCHECK_EQ(BS_HOT, button->state()); button->state_ = BS_NORMAL; - if (button->visible_mode_ != button->intended_mode_) { - button->ChangeMode(button->intended_mode_); - } + button->ChangeMode(button->intended_mode_, true); return TRUE; } @@ -128,7 +106,7 @@ gboolean GoButtonGtk::OnClicked(GtkButton* widget, GoButtonGtk* button) { // The user has clicked, so we can feel free to update the button, // even if the mouse is still hovering. - button->ChangeMode(MODE_GO); + button->ChangeMode(MODE_GO, true); } else if (button->visible_mode_ == MODE_GO && button->stop_timer_.empty()) { // If the go button is visible and not within the double click timer, go. if (button->browser_) diff --git a/chrome/browser/gtk/go_button_gtk.h b/chrome/browser/gtk/go_button_gtk.h index e69f842..0b41c6a 100644 --- a/chrome/browser/gtk/go_button_gtk.h +++ b/chrome/browser/gtk/go_button_gtk.h @@ -27,14 +27,9 @@ class GoButtonGtk { GtkWidget* widget() const { return widget_.get(); } ButtonState state() const { return state_; } - // Force the button state. Useful for when the foreground tab changes. - void ChangeMode(Mode mode); - - // Ask for a specified button state. This is called when the loading state of - // the tab changes. This method may postpone the actual ChangeMode() call - // until another event (such as waiting for a potential double click to end, - // or for the mouse to stop hovering over the button). - void ScheduleChangeMode(Mode mode); + // Ask for a specified button state. If |force| is true this will be applied + // immediately. + void ChangeMode(Mode mode, bool force); private: friend class GoButtonGtkPeer; |