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

Side by Side Diff: ui/views/corewm/tooltip_controller.cc

Issue 213833018: Aura tooltips do not move on mouse move in case of many neighboring views with the same label (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Write unit test for the case when a tooltip moves from one view to another with the same tooltip bu… Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/corewm/tooltip_controller.h" 5 #include "ui/views/corewm/tooltip_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 tooltip_timer_.Start(FROM_HERE, 121 tooltip_timer_.Start(FROM_HERE,
122 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), 122 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
123 this, &TooltipController::TooltipTimerFired); 123 this, &TooltipController::TooltipTimerFired);
124 } 124 }
125 125
126 TooltipController::~TooltipController() { 126 TooltipController::~TooltipController() {
127 if (tooltip_window_) 127 if (tooltip_window_)
128 tooltip_window_->RemoveObserver(this); 128 tooltip_window_->RemoveObserver(this);
129 } 129 }
130 130
131 void TooltipController::UpdateTooltip(aura::Window* target) { 131 void TooltipController::UpdateTooltip(aura::Window* target,
132 bool force) {
132 // If tooltip is visible, we may want to hide it. If it is not, we are ok. 133 // If tooltip is visible, we may want to hide it. If it is not, we are ok.
133 if (tooltip_window_ == target && tooltip_->IsVisible()) 134 if (tooltip_window_ == target && tooltip_->IsVisible())
134 UpdateIfRequired(); 135 UpdateIfRequired(force);
135 136
136 // Reset |tooltip_window_at_mouse_press_| if the moving within the same window 137 // Reset |tooltip_window_at_mouse_press_| if the moving within the same window
137 // but over a region that has different tooltip text. By resetting 138 // but over a region that has different tooltip text. By resetting
138 // |tooltip_window_at_mouse_press_| we ensure the next time the timer fires 139 // |tooltip_window_at_mouse_press_| we ensure the next time the timer fires
139 // we'll requery for the tooltip text. 140 // we'll requery for the tooltip text.
140 // This handles the case of clicking on a view, moving within the same window 141 // This handles the case of clicking on a view, moving within the same window
141 // but over a different view, than back to the original. 142 // but over a different view, than back to the original.
142 if (tooltip_window_at_mouse_press_ && 143 if (tooltip_window_at_mouse_press_ &&
143 target == tooltip_window_at_mouse_press_ && 144 target == tooltip_window_at_mouse_press_ &&
144 aura::client::GetTooltipText(target) != tooltip_text_at_mouse_press_) { 145 aura::client::GetTooltipText(target) != tooltip_text_at_mouse_press_) {
(...skipping 14 matching lines...) Expand all
159 160
160 void TooltipController::SetTooltipShownTimeout(aura::Window* target, 161 void TooltipController::SetTooltipShownTimeout(aura::Window* target,
161 int timeout_in_ms) { 162 int timeout_in_ms) {
162 tooltip_shown_timeout_map_[target] = timeout_in_ms; 163 tooltip_shown_timeout_map_[target] = timeout_in_ms;
163 } 164 }
164 165
165 void TooltipController::SetTooltipsEnabled(bool enable) { 166 void TooltipController::SetTooltipsEnabled(bool enable) {
166 if (tooltips_enabled_ == enable) 167 if (tooltips_enabled_ == enable)
167 return; 168 return;
168 tooltips_enabled_ = enable; 169 tooltips_enabled_ = enable;
169 UpdateTooltip(tooltip_window_); 170 UpdateTooltip(tooltip_window_, false);
170 } 171 }
171 172
172 void TooltipController::OnKeyEvent(ui::KeyEvent* event) { 173 void TooltipController::OnKeyEvent(ui::KeyEvent* event) {
173 // On key press, we want to hide the tooltip and not show it until change. 174 // On key press, we want to hide the tooltip and not show it until change.
174 // This is the same behavior as hiding tooltips on timeout. Hence, we can 175 // This is the same behavior as hiding tooltips on timeout. Hence, we can
175 // simply simulate a timeout. 176 // simply simulate a timeout.
176 if (tooltip_shown_timer_.IsRunning()) { 177 if (tooltip_shown_timer_.IsRunning()) {
177 tooltip_shown_timer_.Stop(); 178 tooltip_shown_timer_.Stop();
178 TooltipShownTimerFired(); 179 TooltipShownTimerFired();
179 } 180 }
180 } 181 }
181 182
182 void TooltipController::OnMouseEvent(ui::MouseEvent* event) { 183 void TooltipController::OnMouseEvent(ui::MouseEvent* event) {
183 switch (event->type()) { 184 switch (event->type()) {
184 case ui::ET_MOUSE_CAPTURE_CHANGED: 185 case ui::ET_MOUSE_CAPTURE_CHANGED:
185 case ui::ET_MOUSE_EXITED: 186 case ui::ET_MOUSE_EXITED:
186 case ui::ET_MOUSE_MOVED: 187 case ui::ET_MOUSE_MOVED:
187 case ui::ET_MOUSE_DRAGGED: { 188 case ui::ET_MOUSE_DRAGGED: {
188 curr_mouse_loc_ = event->location(); 189 curr_mouse_loc_ = event->location();
189 aura::Window* target = GetTooltipTarget(*event, &curr_mouse_loc_); 190 aura::Window* target = GetTooltipTarget(*event, &curr_mouse_loc_);
190 SetTooltipWindow(target); 191 SetTooltipWindow(target);
191 if (tooltip_timer_.IsRunning()) 192 if (tooltip_timer_.IsRunning())
192 tooltip_timer_.Reset(); 193 tooltip_timer_.Reset();
193 194
194 if (tooltip_->IsVisible()) 195 if (tooltip_->IsVisible())
195 UpdateIfRequired(); 196 UpdateIfRequired(false);
196 break; 197 break;
197 } 198 }
198 case ui::ET_MOUSE_PRESSED: 199 case ui::ET_MOUSE_PRESSED:
199 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0) { 200 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0) {
200 aura::Window* target = static_cast<aura::Window*>(event->target()); 201 aura::Window* target = static_cast<aura::Window*>(event->target());
201 // We don't get a release for non-client areas. 202 // We don't get a release for non-client areas.
202 tooltip_window_at_mouse_press_ = target; 203 tooltip_window_at_mouse_press_ = target;
203 if (target) 204 if (target)
204 tooltip_text_at_mouse_press_ = aura::client::GetTooltipText(target); 205 tooltip_text_at_mouse_press_ = aura::client::GetTooltipText(target);
205 } 206 }
(...skipping 26 matching lines...) Expand all
232 if (tooltip_window_ == window) { 233 if (tooltip_window_ == window) {
233 tooltip_->Hide(); 234 tooltip_->Hide();
234 tooltip_shown_timeout_map_.erase(tooltip_window_); 235 tooltip_shown_timeout_map_.erase(tooltip_window_);
235 tooltip_window_ = NULL; 236 tooltip_window_ = NULL;
236 } 237 }
237 } 238 }
238 239
239 //////////////////////////////////////////////////////////////////////////////// 240 ////////////////////////////////////////////////////////////////////////////////
240 // TooltipController private: 241 // TooltipController private:
241 242
242 void TooltipController::TooltipTimerFired() { 243 void TooltipController::TooltipTimerFired() { UpdateIfRequired(false); }
243 UpdateIfRequired();
244 }
245 244
246 void TooltipController::TooltipShownTimerFired() { 245 void TooltipController::TooltipShownTimerFired() {
247 tooltip_->Hide(); 246 tooltip_->Hide();
248 247
249 // Since the user presumably no longer needs the tooltip, we also stop the 248 // Since the user presumably no longer needs the tooltip, we also stop the
250 // tooltip timer so that tooltip does not pop back up. We will restart this 249 // tooltip timer so that tooltip does not pop back up. We will restart this
251 // timer if the tooltip changes (see UpdateTooltip()). 250 // timer if the tooltip changes (see UpdateTooltip()).
252 tooltip_timer_.Stop(); 251 tooltip_timer_.Stop();
253 } 252 }
254 253
255 void TooltipController::UpdateIfRequired() { 254 void TooltipController::UpdateIfRequired(bool force) {
256 if (!tooltips_enabled_ || 255 if (!tooltips_enabled_ ||
257 aura::Env::GetInstance()->IsMouseButtonDown() || 256 aura::Env::GetInstance()->IsMouseButtonDown() ||
258 IsDragDropInProgress() || !IsCursorVisible()) { 257 IsDragDropInProgress() || !IsCursorVisible()) {
259 tooltip_->Hide(); 258 tooltip_->Hide();
260 return; 259 return;
261 } 260 }
262 261
263 base::string16 tooltip_text; 262 base::string16 tooltip_text;
264 if (tooltip_window_) 263 if (tooltip_window_)
265 tooltip_text = aura::client::GetTooltipText(tooltip_window_); 264 tooltip_text = aura::client::GetTooltipText(tooltip_window_);
266 265
267 // If the user pressed a mouse button. We will hide the tooltip and not show 266 // If the user pressed a mouse button. We will hide the tooltip and not show
268 // it until there is a change in the tooltip. 267 // it until there is a change in the tooltip.
269 if (tooltip_window_at_mouse_press_) { 268 if (tooltip_window_at_mouse_press_) {
270 if (tooltip_window_ == tooltip_window_at_mouse_press_ && 269 if (tooltip_window_ == tooltip_window_at_mouse_press_ &&
271 tooltip_text == tooltip_text_at_mouse_press_) { 270 tooltip_text == tooltip_text_at_mouse_press_) {
272 tooltip_->Hide(); 271 tooltip_->Hide();
273 return; 272 return;
274 } 273 }
275 tooltip_window_at_mouse_press_ = NULL; 274 tooltip_window_at_mouse_press_ = NULL;
276 } 275 }
277 276
278 // We add the !tooltip_->IsVisible() below because when we come here from 277 // We add the !tooltip_->IsVisible() below because when we come here from
279 // TooltipTimerFired(), the tooltip_text may not have changed but we still 278 // TooltipTimerFired(), the tooltip_text may not have changed but we still
280 // want to update the tooltip because the timer has fired. 279 // want to update the tooltip because the timer has fired.
281 // If we come here from UpdateTooltip(), we have already checked for tooltip 280 // If we come here from UpdateTooltip(), we have already checked for tooltip
282 // visibility and this check below will have no effect. 281 // visibility and this check below will have no effect.
283 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) { 282 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || force) {
284 tooltip_shown_timer_.Stop(); 283 tooltip_shown_timer_.Stop();
285 tooltip_text_ = tooltip_text; 284 tooltip_text_ = tooltip_text;
286 base::string16 trimmed_text(tooltip_text_); 285 base::string16 trimmed_text(tooltip_text_);
287 views::TooltipManager::TrimTooltipText(&trimmed_text); 286 views::TooltipManager::TrimTooltipText(&trimmed_text);
288 // If the string consists entirely of whitespace, then don't both showing it 287 // If the string consists entirely of whitespace, then don't both showing it
289 // (an empty tooltip is useless). 288 // (an empty tooltip is useless).
290 base::string16 whitespace_removed_text; 289 base::string16 whitespace_removed_text;
291 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, 290 base::TrimWhitespace(trimmed_text, base::TRIM_ALL,
292 &whitespace_removed_text); 291 &whitespace_removed_text);
293 if (whitespace_removed_text.empty()) { 292 if (whitespace_removed_text.empty()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 return; 343 return;
345 if (tooltip_window_) 344 if (tooltip_window_)
346 tooltip_window_->RemoveObserver(this); 345 tooltip_window_->RemoveObserver(this);
347 tooltip_window_ = target; 346 tooltip_window_ = target;
348 if (tooltip_window_) 347 if (tooltip_window_)
349 tooltip_window_->AddObserver(this); 348 tooltip_window_->AddObserver(this);
350 } 349 }
351 350
352 } // namespace corewm 351 } // namespace corewm
353 } // namespace views 352 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698