Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 return NULL; | 108 return NULL; |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| 113 //////////////////////////////////////////////////////////////////////////////// | 113 //////////////////////////////////////////////////////////////////////////////// |
| 114 // TooltipController public: | 114 // TooltipController public: |
| 115 | 115 |
| 116 TooltipController::TooltipController(scoped_ptr<Tooltip> tooltip) | 116 TooltipController::TooltipController(scoped_ptr<Tooltip> tooltip) |
| 117 : tooltip_window_(NULL), | 117 : tooltip_window_(NULL), |
| 118 tooltip_id_(NULL), | |
| 118 tooltip_window_at_mouse_press_(NULL), | 119 tooltip_window_at_mouse_press_(NULL), |
| 119 tooltip_(tooltip.Pass()), | 120 tooltip_(tooltip.Pass()), |
| 120 tooltips_enabled_(true) { | 121 tooltips_enabled_(true) { |
| 121 tooltip_timer_.Start(FROM_HERE, | 122 tooltip_timer_.Start(FROM_HERE, |
| 122 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), | 123 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), |
| 123 this, &TooltipController::TooltipTimerFired); | 124 this, &TooltipController::TooltipTimerFired); |
| 124 } | 125 } |
| 125 | 126 |
| 126 TooltipController::~TooltipController() { | 127 TooltipController::~TooltipController() { |
| 127 if (tooltip_window_) | 128 if (tooltip_window_) |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 // it until there is a change in the tooltip. | 276 // it until there is a change in the tooltip. |
| 276 if (tooltip_window_at_mouse_press_) { | 277 if (tooltip_window_at_mouse_press_) { |
| 277 if (tooltip_window_ == tooltip_window_at_mouse_press_ && | 278 if (tooltip_window_ == tooltip_window_at_mouse_press_ && |
| 278 tooltip_text == tooltip_text_at_mouse_press_) { | 279 tooltip_text == tooltip_text_at_mouse_press_) { |
| 279 tooltip_->Hide(); | 280 tooltip_->Hide(); |
| 280 return; | 281 return; |
| 281 } | 282 } |
| 282 tooltip_window_at_mouse_press_ = NULL; | 283 tooltip_window_at_mouse_press_ = NULL; |
| 283 } | 284 } |
| 284 | 285 |
| 286 // If the uniqueness indicator is different from the previously encountered | |
| 287 // one, we should force tooltip update | |
| 288 const void* tooltip_id = aura::client::GetTooltipId(tooltip_window_); | |
| 289 bool ids_differ = false; | |
| 290 if (tooltip_id) { | |
|
sky
2014/06/02 15:39:47
Why the if here? Can't you always compare tooltip_
| |
| 291 ids_differ = tooltip_id_ != tooltip_id; | |
| 292 tooltip_id_ = tooltip_id; | |
| 293 } else { | |
| 294 tooltip_id_ = NULL; | |
| 295 } | |
| 296 | |
| 285 // We add the !tooltip_->IsVisible() below because when we come here from | 297 // We add the !tooltip_->IsVisible() below because when we come here from |
| 286 // TooltipTimerFired(), the tooltip_text may not have changed but we still | 298 // TooltipTimerFired(), the tooltip_text may not have changed but we still |
| 287 // want to update the tooltip because the timer has fired. | 299 // want to update the tooltip because the timer has fired. |
| 288 // If we come here from UpdateTooltip(), we have already checked for tooltip | 300 // If we come here from UpdateTooltip(), we have already checked for tooltip |
| 289 // visibility and this check below will have no effect. | 301 // visibility and this check below will have no effect. |
| 290 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) { | 302 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) { |
| 291 tooltip_shown_timer_.Stop(); | 303 tooltip_shown_timer_.Stop(); |
| 292 tooltip_text_ = tooltip_text; | 304 tooltip_text_ = tooltip_text; |
| 293 base::string16 trimmed_text(tooltip_text_); | 305 base::string16 trimmed_text(tooltip_text_); |
| 294 views::TooltipManager::TrimTooltipText(&trimmed_text); | 306 views::TooltipManager::TrimTooltipText(&trimmed_text); |
| 295 // If the string consists entirely of whitespace, then don't both showing it | 307 // If the string consists entirely of whitespace, then don't both showing it |
| 296 // (an empty tooltip is useless). | 308 // (an empty tooltip is useless). |
| 297 base::string16 whitespace_removed_text; | 309 base::string16 whitespace_removed_text; |
| 298 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, | 310 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, |
| 299 &whitespace_removed_text); | 311 &whitespace_removed_text); |
| 300 if (whitespace_removed_text.empty()) { | 312 if (whitespace_removed_text.empty()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 return; | 363 return; |
| 352 if (tooltip_window_) | 364 if (tooltip_window_) |
| 353 tooltip_window_->RemoveObserver(this); | 365 tooltip_window_->RemoveObserver(this); |
| 354 tooltip_window_ = target; | 366 tooltip_window_ = target; |
| 355 if (tooltip_window_) | 367 if (tooltip_window_) |
| 356 tooltip_window_->AddObserver(this); | 368 tooltip_window_->AddObserver(this); |
| 357 } | 369 } |
| 358 | 370 |
| 359 } // namespace corewm | 371 } // namespace corewm |
| 360 } // namespace views | 372 } // namespace views |
| OLD | NEW |