| 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 ids_differ = tooltip_id_ != tooltip_id; |
| 291 tooltip_id_ = tooltip_id; |
| 292 |
| 285 // We add the !tooltip_->IsVisible() below because when we come here from | 293 // We add the !tooltip_->IsVisible() below because when we come here from |
| 286 // TooltipTimerFired(), the tooltip_text may not have changed but we still | 294 // TooltipTimerFired(), the tooltip_text may not have changed but we still |
| 287 // want to update the tooltip because the timer has fired. | 295 // want to update the tooltip because the timer has fired. |
| 288 // If we come here from UpdateTooltip(), we have already checked for tooltip | 296 // If we come here from UpdateTooltip(), we have already checked for tooltip |
| 289 // visibility and this check below will have no effect. | 297 // visibility and this check below will have no effect. |
| 290 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) { | 298 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) { |
| 291 tooltip_shown_timer_.Stop(); | 299 tooltip_shown_timer_.Stop(); |
| 292 tooltip_text_ = tooltip_text; | 300 tooltip_text_ = tooltip_text; |
| 293 base::string16 trimmed_text(tooltip_text_); | 301 base::string16 trimmed_text(tooltip_text_); |
| 294 views::TooltipManager::TrimTooltipText(&trimmed_text); | 302 views::TooltipManager::TrimTooltipText(&trimmed_text); |
| 295 // If the string consists entirely of whitespace, then don't both showing it | 303 // If the string consists entirely of whitespace, then don't both showing it |
| 296 // (an empty tooltip is useless). | 304 // (an empty tooltip is useless). |
| 297 base::string16 whitespace_removed_text; | 305 base::string16 whitespace_removed_text; |
| 298 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, | 306 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, |
| 299 &whitespace_removed_text); | 307 &whitespace_removed_text); |
| 300 if (whitespace_removed_text.empty()) { | 308 if (whitespace_removed_text.empty()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 return; | 359 return; |
| 352 if (tooltip_window_) | 360 if (tooltip_window_) |
| 353 tooltip_window_->RemoveObserver(this); | 361 tooltip_window_->RemoveObserver(this); |
| 354 tooltip_window_ = target; | 362 tooltip_window_ = target; |
| 355 if (tooltip_window_) | 363 if (tooltip_window_) |
| 356 tooltip_window_->AddObserver(this); | 364 tooltip_window_->AddObserver(this); |
| 357 } | 365 } |
| 358 | 366 |
| 359 } // namespace corewm | 367 } // namespace corewm |
| 360 } // namespace views | 368 } // namespace views |
| OLD | NEW |