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

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

Issue 15754002: ash: Add functionality to specify how long a tooltip is shown for a window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/tooltip_controller.h ('k') | no next file » | 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 30 matching lines...) Expand all
41 const int kTooltipMaxWidthPixels = 400; 41 const int kTooltipMaxWidthPixels = 400;
42 42
43 // Maximum number of lines we allow in the tooltip. 43 // Maximum number of lines we allow in the tooltip.
44 const size_t kMaxLines = 10; 44 const size_t kMaxLines = 10;
45 45
46 // TODO(derat): This padding is needed on Chrome OS devices but seems excessive 46 // TODO(derat): This padding is needed on Chrome OS devices but seems excessive
47 // when running the same binary on a Linux workstation; presumably there's a 47 // when running the same binary on a Linux workstation; presumably there's a
48 // difference in font metrics. Rationalize this. 48 // difference in font metrics. Rationalize this.
49 const int kTooltipVerticalPadding = 2; 49 const int kTooltipVerticalPadding = 2;
50 const int kTooltipTimeoutMs = 500; 50 const int kTooltipTimeoutMs = 500;
51 const int kTooltipShownTimeoutMs = 10000; 51 const int kDefaultTooltipShownTimeoutMs = 10000;
52 52
53 // FIXME: get cursor offset from actual cursor size. 53 // FIXME: get cursor offset from actual cursor size.
54 const int kCursorOffsetX = 10; 54 const int kCursorOffsetX = 10;
55 const int kCursorOffsetY = 15; 55 const int kCursorOffsetY = 15;
56 56
57 // Maximum number of characters we allow in a tooltip. 57 // Maximum number of characters we allow in a tooltip.
58 const size_t kMaxTooltipLength = 1024; 58 const size_t kMaxTooltipLength = 1024;
59 59
60 gfx::Font GetDefaultFont() { 60 gfx::Font GetDefaultFont() {
61 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure 61 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (!tooltip_timer_.IsRunning()) { 223 if (!tooltip_timer_.IsRunning()) {
224 if (tooltip_window_ != target || (tooltip_window_ && 224 if (tooltip_window_ != target || (tooltip_window_ &&
225 tooltip_text_ != aura::client::GetTooltipText(tooltip_window_))) { 225 tooltip_text_ != aura::client::GetTooltipText(tooltip_window_))) {
226 tooltip_timer_.Start(FROM_HERE, 226 tooltip_timer_.Start(FROM_HERE,
227 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), 227 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
228 this, &TooltipController::TooltipTimerFired); 228 this, &TooltipController::TooltipTimerFired);
229 } 229 }
230 } 230 }
231 } 231 }
232 232
233 void TooltipController::SetTooltipShownTimeout(aura::Window* target,
234 int timeout_in_ms) {
235 tooltip_shown_timeout_map_[target] = timeout_in_ms;
236 }
237
233 void TooltipController::SetTooltipsEnabled(bool enable) { 238 void TooltipController::SetTooltipsEnabled(bool enable) {
234 if (tooltips_enabled_ == enable) 239 if (tooltips_enabled_ == enable)
235 return; 240 return;
236 tooltips_enabled_ = enable; 241 tooltips_enabled_ = enable;
237 UpdateTooltip(tooltip_window_); 242 UpdateTooltip(tooltip_window_);
238 } 243 }
239 244
240 void TooltipController::OnKeyEvent(ui::KeyEvent* event) { 245 void TooltipController::OnKeyEvent(ui::KeyEvent* event) {
241 // On key press, we want to hide the tooltip and not show it until change. 246 // On key press, we want to hide the tooltip and not show it until change.
242 // This is the same behavior as hiding tooltips on timeout. Hence, we can 247 // This is the same behavior as hiding tooltips on timeout. Hence, we can
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 tooltip_window_ = NULL; 307 tooltip_window_ = NULL;
303 } 308 }
304 309
305 void TooltipController::OnCancelMode(ui::CancelModeEvent* event) { 310 void TooltipController::OnCancelMode(ui::CancelModeEvent* event) {
306 if (tooltip_.get() && tooltip_->IsVisible()) 311 if (tooltip_.get() && tooltip_->IsVisible())
307 tooltip_->Hide(); 312 tooltip_->Hide();
308 } 313 }
309 314
310 void TooltipController::OnWindowDestroyed(aura::Window* window) { 315 void TooltipController::OnWindowDestroyed(aura::Window* window) {
311 if (tooltip_window_ == window) { 316 if (tooltip_window_ == window) {
317 tooltip_shown_timeout_map_.erase(tooltip_window_);
312 tooltip_window_->RemoveObserver(this); 318 tooltip_window_->RemoveObserver(this);
313 tooltip_window_ = NULL; 319 tooltip_window_ = NULL;
314 } 320 }
315 } 321 }
316 322
317 //////////////////////////////////////////////////////////////////////////////// 323 ////////////////////////////////////////////////////////////////////////////////
318 // TooltipController private: 324 // TooltipController private:
319 325
320 int TooltipController::GetMaxWidth(const gfx::Point& location) const { 326 int TooltipController::GetMaxWidth(const gfx::Point& location) const {
321 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure 327 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } else { 476 } else {
471 gfx::Point widget_loc = curr_mouse_loc_ + 477 gfx::Point widget_loc = curr_mouse_loc_ +
472 tooltip_window_->GetBoundsInScreen().OffsetFromOrigin(); 478 tooltip_window_->GetBoundsInScreen().OffsetFromOrigin();
473 gfx::Rect bounds(GetBoundsForTooltip(widget_loc)); 479 gfx::Rect bounds(GetBoundsForTooltip(widget_loc));
474 if (bounds.IsEmpty()) { 480 if (bounds.IsEmpty()) {
475 tooltip_text_.clear(); 481 tooltip_text_.clear();
476 GetTooltip()->Hide(); 482 GetTooltip()->Hide();
477 } else { 483 } else {
478 GetTooltip()->SetText(tooltip_window_, tooltip_text_, widget_loc); 484 GetTooltip()->SetText(tooltip_window_, tooltip_text_, widget_loc);
479 GetTooltip()->Show(); 485 GetTooltip()->Show();
480 tooltip_shown_timer_.Start(FROM_HERE, 486 int timeout = GetTooltipShownTimeout();
481 base::TimeDelta::FromMilliseconds(kTooltipShownTimeoutMs), 487 if (timeout > 0) {
482 this, &TooltipController::TooltipShownTimerFired); 488 tooltip_shown_timer_.Start(FROM_HERE,
489 base::TimeDelta::FromMilliseconds(timeout),
490 this, &TooltipController::TooltipShownTimerFired);
491 }
483 } 492 }
484 } 493 }
485 } 494 }
486 } 495 }
487 496
488 bool TooltipController::IsTooltipVisible() { 497 bool TooltipController::IsTooltipVisible() {
489 return GetTooltip()->IsVisible(); 498 return GetTooltip()->IsVisible();
490 } 499 }
491 500
492 bool TooltipController::IsDragDropInProgress() { 501 bool TooltipController::IsDragDropInProgress() {
(...skipping 15 matching lines...) Expand all
508 return false; 517 return false;
509 aura::RootWindow* root = tooltip_window_->GetRootWindow(); 518 aura::RootWindow* root = tooltip_window_->GetRootWindow();
510 if (!root) 519 if (!root)
511 return false; 520 return false;
512 aura::client::CursorClient* cursor_client = 521 aura::client::CursorClient* cursor_client =
513 aura::client::GetCursorClient(root); 522 aura::client::GetCursorClient(root);
514 // |cursor_client| may be NULL in tests, treat NULL as always visible. 523 // |cursor_client| may be NULL in tests, treat NULL as always visible.
515 return !cursor_client || cursor_client->IsCursorVisible(); 524 return !cursor_client || cursor_client->IsCursorVisible();
516 } 525 }
517 526
527 int TooltipController::GetTooltipShownTimeout() {
528 std::map<aura::Window*, int>::const_iterator it =
529 tooltip_shown_timeout_map_.find(tooltip_window_);
530 if (it == tooltip_shown_timeout_map_.end())
531 return kDefaultTooltipShownTimeoutMs;
532 return it->second;
533 }
534
518 } // namespace corewm 535 } // namespace corewm
519 } // namespace views 536 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/tooltip_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698