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

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

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

Powered by Google App Engine
This is Rietveld 408576698