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

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

Issue 2652353003: Fix regression: empty tooltip appears in Linux and Chrome OS (Closed)
Patch Set: Cancel the timer when tooltip text is set to empty. Created 3 years, 10 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
« no previous file with comments | « no previous file | ui/views/corewm/tooltip_controller_unittest.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) 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 tooltip_shown_timer_.Stop(); 301 tooltip_shown_timer_.Stop();
302 tooltip_text_ = tooltip_text; 302 tooltip_text_ = tooltip_text;
303 base::string16 trimmed_text = 303 base::string16 trimmed_text =
304 gfx::TruncateString(tooltip_text_, kMaxTooltipLength, gfx::WORD_BREAK); 304 gfx::TruncateString(tooltip_text_, kMaxTooltipLength, gfx::WORD_BREAK);
305 // If the string consists entirely of whitespace, then don't both showing it 305 // If the string consists entirely of whitespace, then don't both showing it
306 // (an empty tooltip is useless). 306 // (an empty tooltip is useless).
307 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, 307 base::TrimWhitespace(trimmed_text, base::TRIM_ALL,
308 &tooltip_text_whitespace_trimmed_); 308 &tooltip_text_whitespace_trimmed_);
309 if (tooltip_text_whitespace_trimmed_.empty()) { 309 if (tooltip_text_whitespace_trimmed_.empty()) {
310 tooltip_->Hide(); 310 tooltip_->Hide();
311 if (tooltip_defer_timer_.IsRunning()) {
sky 2017/01/26 18:25:37 no {}
chengx 2017/01/26 21:04:03 Done.
312 tooltip_defer_timer_.Reset();
313 }
311 } else if (tooltip_show_delayed_) { 314 } else if (tooltip_show_delayed_) {
312 // Initialize the one-shot timer to show the tooltip in a while. 315 // Initialize the one-shot timer to show the tooltip in a while.
313 // If there is already a request queued then cancel it and post the new 316 // If there is already a request queued then cancel it and post the new
314 // request. This ensures that tooltip won't show up too early. 317 // request. This ensures that tooltip won't show up too early.
315 // The delayed appearance of a tooltip is by default. 318 // The delayed appearance of a tooltip is by default.
316 if (tooltip_defer_timer_.IsRunning()) { 319 if (tooltip_defer_timer_.IsRunning()) {
317 tooltip_defer_timer_.Reset(); 320 tooltip_defer_timer_.Reset();
318 } else { 321 } else {
319 tooltip_defer_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( 322 tooltip_defer_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
320 kDelayForTooltipUpdateInMs), 323 kDelayForTooltipUpdateInMs),
321 this, &TooltipController::ShowTooltip); 324 this, &TooltipController::ShowTooltip);
322 } 325 }
323 } else { 326 } else {
324 ShowTooltip(); // Allow tooltip to show up without delay for unit tests. 327 ShowTooltip(); // Allow tooltip to show up without delay for unit tests.
325 } 328 }
326 } 329 }
327 } 330 }
328 331
329 void TooltipController::ShowTooltip() { 332 void TooltipController::ShowTooltip() {
330 if (!tooltip_window_) 333 if (!tooltip_window_ || tooltip_text_whitespace_trimmed_.empty())
331 return; 334 return;
332 gfx::Point widget_loc = 335 gfx::Point widget_loc =
333 curr_mouse_loc_ + tooltip_window_->GetBoundsInScreen().OffsetFromOrigin(); 336 curr_mouse_loc_ + tooltip_window_->GetBoundsInScreen().OffsetFromOrigin();
334 tooltip_->SetText(tooltip_window_, tooltip_text_whitespace_trimmed_, 337 tooltip_->SetText(tooltip_window_, tooltip_text_whitespace_trimmed_,
335 widget_loc); 338 widget_loc);
336 tooltip_->Show(); 339 tooltip_->Show();
337 int timeout = GetTooltipShownTimeout(); 340 int timeout = GetTooltipShownTimeout();
338 if (timeout > 0) { 341 if (timeout > 0) {
339 tooltip_shown_timer_.Start(FROM_HERE, 342 tooltip_shown_timer_.Start(FROM_HERE,
340 base::TimeDelta::FromMilliseconds(timeout), this, 343 base::TimeDelta::FromMilliseconds(timeout), this,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 return; 382 return;
380 if (tooltip_window_) 383 if (tooltip_window_)
381 tooltip_window_->RemoveObserver(this); 384 tooltip_window_->RemoveObserver(this);
382 tooltip_window_ = target; 385 tooltip_window_ = target;
383 if (tooltip_window_) 386 if (tooltip_window_)
384 tooltip_window_->AddObserver(this); 387 tooltip_window_->AddObserver(this);
385 } 388 }
386 389
387 } // namespace corewm 390 } // namespace corewm
388 } // namespace views 391 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/corewm/tooltip_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698