Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: chrome/browser/views/reload_button.cc

Issue 3198005: Disable the stop button when the user is hovering it and the page finishes lo... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/reload_button_gtk.cc ('k') | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/reload_button.h" 5 #include "chrome/browser/views/reload_button.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.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
25 25
26 ReloadButton::~ReloadButton() { 26 ReloadButton::~ReloadButton() {
27 } 27 }
28 28
29 void ReloadButton::ChangeMode(Mode mode, bool force) { 29 void ReloadButton::ChangeMode(Mode mode, bool force) {
30 intended_mode_ = mode; 30 intended_mode_ = mode;
31 31
32 // If the change is forced, or the user isn't hovering the icon, or it's safe 32 // If the change is forced, or the user isn't hovering the icon, or it's safe
33 // to change it to the other image type, make the change immediately; 33 // to change it to the other image type, make the change immediately;
34 // otherwise we'll let it happen later. 34 // otherwise we'll let it happen later.
35 if (force || (state() != BS_HOT) || ((mode == MODE_STOP) ? 35 if (force || !IsMouseHovered() || ((mode == MODE_STOP) ?
36 !timer_.IsRunning() : (visible_mode_ != MODE_STOP))) { 36 !timer_.IsRunning() : (visible_mode_ != MODE_STOP))) {
37 timer_.Stop(); 37 timer_.Stop();
38 SetToggled(mode == MODE_STOP); 38 SetToggled(mode == MODE_STOP);
39 visible_mode_ = mode; 39 visible_mode_ = mode;
40 SetEnabled(true);
41
42 // We want to disable the button if we're preventing a change from stop to
43 // reload due to hovering, but not if we're preventing a change from reload to
44 // stop due to the timer running. (There is no disabled reload state.)
45 } else if (visible_mode_ != MODE_RELOAD) {
46 SetEnabled(false);
40 } 47 }
41 } 48 }
42 49
43 //////////////////////////////////////////////////////////////////////////////// 50 ////////////////////////////////////////////////////////////////////////////////
44 // ReloadButton, views::ButtonListener implementation: 51 // ReloadButton, views::ButtonListener implementation:
45 52
46 void ReloadButton::ButtonPressed(views::Button* button, 53 void ReloadButton::ButtonPressed(views::Button* button,
47 const views::Event& event) { 54 const views::Event& event) {
48 if (visible_mode_ == MODE_STOP) { 55 if (visible_mode_ == MODE_STOP) {
49 browser_->Stop(); 56 browser_->Stop();
(...skipping 17 matching lines...) Expand all
67 74
68 WindowOpenDisposition disposition = 75 WindowOpenDisposition disposition =
69 event_utils::DispositionFromEventFlags(flags); 76 event_utils::DispositionFromEventFlags(flags);
70 if (disposition == CURRENT_TAB) { 77 if (disposition == CURRENT_TAB) {
71 // Forcibly reset the location bar, since otherwise it won't discard any 78 // Forcibly reset the location bar, since otherwise it won't discard any
72 // ongoing user edits, since it doesn't realize this is a user-initiated 79 // ongoing user edits, since it doesn't realize this is a user-initiated
73 // action. 80 // action.
74 location_bar_->Revert(); 81 location_bar_->Revert();
75 } 82 }
76 83
77 browser_->ExecuteCommandWithDisposition(command, disposition);
78
79 // Stop the timer.
80 timer_.Stop();
81
82 // Start a timer - while this timer is running, the reload button cannot be 84 // Start a timer - while this timer is running, the reload button cannot be
83 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP 85 // changed to a stop button. We do not set |intended_mode_| to MODE_STOP
84 // here as we want to wait for the browser to tell us that it has started 86 // here as the browser will do that when it actually starts loading (which
85 // loading (and this may occur only after some delay). 87 // may happen synchronously, thus the need to do this before telling the
88 // browser to execute the reload command).
89 timer_.Stop();
86 timer_.Start(base::TimeDelta::FromMilliseconds(GetDoubleClickTimeMS()), 90 timer_.Start(base::TimeDelta::FromMilliseconds(GetDoubleClickTimeMS()),
87 this, &ReloadButton::OnButtonTimer); 91 this, &ReloadButton::OnButtonTimer);
92
93 browser_->ExecuteCommandWithDisposition(command, disposition);
88 } 94 }
89 } 95 }
90 96
91 //////////////////////////////////////////////////////////////////////////////// 97 ////////////////////////////////////////////////////////////////////////////////
92 // ReloadButton, View overrides: 98 // ReloadButton, View overrides:
93 99
94 void ReloadButton::OnMouseExited(const views::MouseEvent& e) { 100 void ReloadButton::OnMouseExited(const views::MouseEvent& e) {
95 ChangeMode(intended_mode_, true); 101 ChangeMode(intended_mode_, true);
96 if (state() != BS_DISABLED) 102 if (state() != BS_DISABLED)
97 SetState(BS_NORMAL); 103 SetState(BS_NORMAL);
98 } 104 }
99 105
100 bool ReloadButton::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { 106 bool ReloadButton::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
101 tooltip->assign(l10n_util::GetString((visible_mode_ == MODE_RELOAD) ? 107 tooltip->assign(l10n_util::GetString((visible_mode_ == MODE_RELOAD) ?
102 IDS_TOOLTIP_RELOAD : IDS_TOOLTIP_STOP)); 108 IDS_TOOLTIP_RELOAD : IDS_TOOLTIP_STOP));
103 return true; 109 return true;
104 } 110 }
105 111
106 //////////////////////////////////////////////////////////////////////////////// 112 ////////////////////////////////////////////////////////////////////////////////
107 // ReloadButton, private: 113 // ReloadButton, private:
108 114
109 void ReloadButton::OnButtonTimer() { 115 void ReloadButton::OnButtonTimer() {
110 ChangeMode(intended_mode_, true); 116 ChangeMode(intended_mode_, false);
111 } 117 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/reload_button_gtk.cc ('k') | chrome/browser/views/toolbar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698