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

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

Issue 916423002: Tooltip Cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win build fix Created 5 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 | « ui/views/corewm/tooltip_controller.h ('k') | 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 <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"
11 #include "ui/aura/client/capture_client.h" 11 #include "ui/aura/client/capture_client.h"
12 #include "ui/aura/client/cursor_client.h" 12 #include "ui/aura/client/cursor_client.h"
13 #include "ui/aura/client/screen_position_client.h" 13 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/events/event.h" 16 #include "ui/events/event.h"
17 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
18 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 #include "ui/gfx/text_elider.h"
20 #include "ui/views/corewm/tooltip.h" 21 #include "ui/views/corewm/tooltip.h"
21 #include "ui/views/widget/tooltip_manager.h" 22 #include "ui/views/widget/tooltip_manager.h"
22 #include "ui/wm/public/drag_drop_client.h" 23 #include "ui/wm/public/drag_drop_client.h"
23 24
24 namespace views { 25 namespace views {
25 namespace corewm { 26 namespace corewm {
26 namespace { 27 namespace {
27 28
28 const int kTooltipTimeoutMs = 500; 29 const int kTooltipTimeoutMs = 500;
29 const int kDefaultTooltipShownTimeoutMs = 10000; 30 const int kDefaultTooltipShownTimeoutMs = 10000;
31 const size_t kMaxTooltipLength = 1024;
30 32
31 // Returns true if |target| is a valid window to get the tooltip from. 33 // Returns true if |target| is a valid window to get the tooltip from.
32 // |event_target| is the original target from the event and |target| the window 34 // |event_target| is the original target from the event and |target| the window
33 // at the same location. 35 // at the same location.
34 bool IsValidTarget(aura::Window* event_target, aura::Window* target) { 36 bool IsValidTarget(aura::Window* event_target, aura::Window* target) {
35 if (!target || (event_target == target)) 37 if (!target || (event_target == target))
36 return true; 38 return true;
37 39
38 void* event_target_grouping_id = event_target->GetNativeWindowProperty( 40 void* event_target_grouping_id = event_target->GetNativeWindowProperty(
39 TooltipManager::kGroupingPropertyKey); 41 TooltipManager::kGroupingPropertyKey);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 tooltip_timer_.Start(FROM_HERE, 124 tooltip_timer_.Start(FROM_HERE,
123 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), 125 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
124 this, &TooltipController::TooltipTimerFired); 126 this, &TooltipController::TooltipTimerFired);
125 } 127 }
126 128
127 TooltipController::~TooltipController() { 129 TooltipController::~TooltipController() {
128 if (tooltip_window_) 130 if (tooltip_window_)
129 tooltip_window_->RemoveObserver(this); 131 tooltip_window_->RemoveObserver(this);
130 } 132 }
131 133
134 int TooltipController::GetMaxWidth(const gfx::Point& location,
135 gfx::NativeView context) const {
136 return tooltip_->GetMaxWidth(location, context);
137 }
138
132 void TooltipController::UpdateTooltip(aura::Window* target) { 139 void TooltipController::UpdateTooltip(aura::Window* target) {
133 // If tooltip is visible, we may want to hide it. If it is not, we are ok. 140 // If tooltip is visible, we may want to hide it. If it is not, we are ok.
134 if (tooltip_window_ == target && tooltip_->IsVisible()) 141 if (tooltip_window_ == target && tooltip_->IsVisible())
135 UpdateIfRequired(); 142 UpdateIfRequired();
136 143
137 // Reset |tooltip_window_at_mouse_press_| if the moving within the same window 144 // Reset |tooltip_window_at_mouse_press_| if the moving within the same window
138 // but over a region that has different tooltip text. By resetting 145 // but over a region that has different tooltip text. By resetting
139 // |tooltip_window_at_mouse_press_| we ensure the next time the timer fires 146 // |tooltip_window_at_mouse_press_| we ensure the next time the timer fires
140 // we'll requery for the tooltip text. 147 // we'll requery for the tooltip text.
141 // This handles the case of clicking on a view, moving within the same window 148 // This handles the case of clicking on a view, moving within the same window
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 tooltip_id_ = tooltip_id; 298 tooltip_id_ = tooltip_id;
292 299
293 // We add the !tooltip_->IsVisible() below because when we come here from 300 // We add the !tooltip_->IsVisible() below because when we come here from
294 // TooltipTimerFired(), the tooltip_text may not have changed but we still 301 // TooltipTimerFired(), the tooltip_text may not have changed but we still
295 // want to update the tooltip because the timer has fired. 302 // want to update the tooltip because the timer has fired.
296 // If we come here from UpdateTooltip(), we have already checked for tooltip 303 // If we come here from UpdateTooltip(), we have already checked for tooltip
297 // visibility and this check below will have no effect. 304 // visibility and this check below will have no effect.
298 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) { 305 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible() || ids_differ) {
299 tooltip_shown_timer_.Stop(); 306 tooltip_shown_timer_.Stop();
300 tooltip_text_ = tooltip_text; 307 tooltip_text_ = tooltip_text;
301 base::string16 trimmed_text(tooltip_text_); 308 base::string16 trimmed_text =
302 views::TooltipManager::TrimTooltipText(&trimmed_text); 309 gfx::TruncateString(tooltip_text_, kMaxTooltipLength, gfx::WORD_BREAK);
303 // If the string consists entirely of whitespace, then don't both showing it 310 // If the string consists entirely of whitespace, then don't both showing it
304 // (an empty tooltip is useless). 311 // (an empty tooltip is useless).
305 base::string16 whitespace_removed_text; 312 base::string16 whitespace_removed_text;
306 base::TrimWhitespace(trimmed_text, base::TRIM_ALL, 313 base::TrimWhitespace(trimmed_text, base::TRIM_ALL,
307 &whitespace_removed_text); 314 &whitespace_removed_text);
308 if (whitespace_removed_text.empty()) { 315 if (whitespace_removed_text.empty()) {
309 tooltip_->Hide(); 316 tooltip_->Hide();
310 } else { 317 } else {
311 gfx::Point widget_loc = curr_mouse_loc_ + 318 gfx::Point widget_loc = curr_mouse_loc_ +
312 tooltip_window_->GetBoundsInScreen().OffsetFromOrigin(); 319 tooltip_window_->GetBoundsInScreen().OffsetFromOrigin();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 return; 366 return;
360 if (tooltip_window_) 367 if (tooltip_window_)
361 tooltip_window_->RemoveObserver(this); 368 tooltip_window_->RemoveObserver(this);
362 tooltip_window_ = target; 369 tooltip_window_ = target;
363 if (tooltip_window_) 370 if (tooltip_window_)
364 tooltip_window_->AddObserver(this); 371 tooltip_window_->AddObserver(this);
365 } 372 }
366 373
367 } // namespace corewm 374 } // namespace corewm
368 } // namespace views 375 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/tooltip_controller.h ('k') | ui/views/corewm/tooltip_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698