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_unique_(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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 // it until there is a change in the tooltip. | 269 // it until there is a change in the tooltip. |
269 if (tooltip_window_at_mouse_press_) { | 270 if (tooltip_window_at_mouse_press_) { |
270 if (tooltip_window_ == tooltip_window_at_mouse_press_ && | 271 if (tooltip_window_ == tooltip_window_at_mouse_press_ && |
271 tooltip_text == tooltip_text_at_mouse_press_) { | 272 tooltip_text == tooltip_text_at_mouse_press_) { |
272 tooltip_->Hide(); | 273 tooltip_->Hide(); |
273 return; | 274 return; |
274 } | 275 } |
275 tooltip_window_at_mouse_press_ = NULL; | 276 tooltip_window_at_mouse_press_ = NULL; |
276 } | 277 } |
277 | 278 |
279 // If the uniqueness indicator is different from the previously encountered | |
280 // one, we should force tooltip update | |
281 const void* tooltip_unique = aura::client::GetTooltipUnique(tooltip_window_); | |
282 bool force = false; | |
sky
2014/04/23 20:08:46
force->ids_differ
Mikus
2014/04/24 08:39:56
Done.
| |
283 if (tooltip_unique) { | |
284 force = tooltip_unique_ != tooltip_unique; | |
285 tooltip_unique_ = tooltip_unique; | |
286 } else { | |
287 tooltip_unique_ = NULL; | |
288 } | |
289 | |
278 // We add the !tooltip_->IsVisible() below because when we come here from | 290 // We add the !tooltip_->IsVisible() below because when we come here from |
279 // TooltipTimerFired(), the tooltip_text may not have changed but we still | 291 // TooltipTimerFired(), the tooltip_text may not have changed but we still |
280 // want to update the tooltip because the timer has fired. | 292 // want to update the tooltip because the timer has fired. |
281 // If we come here from UpdateTooltip(), we have already checked for tooltip | 293 // If we come here from UpdateTooltip(), we have already checked for tooltip |
282 // visibility and this check below will have no effect. | 294 // visibility and this check below will have no effect. |
283 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) { | 295 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || force) { |
284 tooltip_shown_timer_.Stop(); | 296 tooltip_shown_timer_.Stop(); |
285 tooltip_text_ = tooltip_text; | 297 tooltip_text_ = tooltip_text; |
286 base::string16 trimmed_text(tooltip_text_); | 298 base::string16 trimmed_text(tooltip_text_); |
287 views::TooltipManager::TrimTooltipText(&trimmed_text); | 299 views::TooltipManager::TrimTooltipText(&trimmed_text); |
288 // If the string consists entirely of whitespace, then don't both showing it | 300 // If the string consists entirely of whitespace, then don't both showing it |
289 // (an empty tooltip is useless). | 301 // (an empty tooltip is useless). |
290 base::string16 whitespace_removed_text; | 302 base::string16 whitespace_removed_text; |
291 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, | 303 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, |
292 &whitespace_removed_text); | 304 &whitespace_removed_text); |
293 if (whitespace_removed_text.empty()) { | 305 if (whitespace_removed_text.empty()) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 return; | 356 return; |
345 if (tooltip_window_) | 357 if (tooltip_window_) |
346 tooltip_window_->RemoveObserver(this); | 358 tooltip_window_->RemoveObserver(this); |
347 tooltip_window_ = target; | 359 tooltip_window_ = target; |
348 if (tooltip_window_) | 360 if (tooltip_window_) |
349 tooltip_window_->AddObserver(this); | 361 tooltip_window_->AddObserver(this); |
350 } | 362 } |
351 | 363 |
352 } // namespace corewm | 364 } // namespace corewm |
353 } // namespace views | 365 } // namespace views |
OLD | NEW |