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

Side by Side Diff: ash/tooltips/tooltip_controller.cc

Issue 10790127: aura: couple of tooltip UX changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 years, 5 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 | « ash/tooltips/tooltip_controller.h ('k') | ash/tooltips/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 "ash/tooltips/tooltip_controller.h" 5 #include "ash/tooltips/tooltip_controller.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/shell.h" 10 #include "ash/shell.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 52
52 // FIXME: get cursor offset from actual cursor size. 53 // FIXME: get cursor offset from actual cursor size.
53 const int kCursorOffsetX = 10; 54 const int kCursorOffsetX = 10;
54 const int kCursorOffsetY = 15; 55 const int kCursorOffsetY = 15;
55 56
56 // Maximum number of characters we allow in a tooltip. 57 // Maximum number of characters we allow in a tooltip.
57 const size_t kMaxTooltipLength = 1024; 58 const size_t kMaxTooltipLength = 1024;
58 59
59 gfx::Font GetDefaultFont() { 60 gfx::Font GetDefaultFont() {
60 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure 61 // TODO(varunjain): implementation duplicated in tooltip_manager_aura. Figure
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 195
195 TooltipController::~TooltipController() { 196 TooltipController::~TooltipController() {
196 if (tooltip_window_) 197 if (tooltip_window_)
197 tooltip_window_->RemoveObserver(this); 198 tooltip_window_->RemoveObserver(this);
198 } 199 }
199 200
200 void TooltipController::UpdateTooltip(aura::Window* target) { 201 void TooltipController::UpdateTooltip(aura::Window* target) {
201 // If tooltip is visible, we may want to hide it. If it is not, we are ok. 202 // If tooltip is visible, we may want to hide it. If it is not, we are ok.
202 if (tooltip_window_ == target && tooltip_->IsVisible()) 203 if (tooltip_window_ == target && tooltip_->IsVisible())
203 UpdateIfRequired(); 204 UpdateIfRequired();
205
206 // If we had stopped the tooltip timer for some reason, we must restart it if
207 // there is a change in the tooltip.
208 if (!tooltip_timer_.IsRunning()) {
209 if (tooltip_window_ != target || (tooltip_window_ &&
210 tooltip_text_ != aura::client::GetTooltipText(tooltip_window_))) {
211 tooltip_timer_.Start(FROM_HERE,
212 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
213 this, &TooltipController::TooltipTimerFired);
214 }
215 }
204 } 216 }
205 217
206 void TooltipController::SetTooltipsEnabled(bool enable) { 218 void TooltipController::SetTooltipsEnabled(bool enable) {
207 if (tooltips_enabled_ == enable) 219 if (tooltips_enabled_ == enable)
208 return; 220 return;
209 tooltips_enabled_ = enable; 221 tooltips_enabled_ = enable;
210 UpdateTooltip(tooltip_window_); 222 UpdateTooltip(tooltip_window_);
211 } 223 }
212 224
213 bool TooltipController::PreHandleKeyEvent(aura::Window* target, 225 bool TooltipController::PreHandleKeyEvent(aura::Window* target,
214 aura::KeyEvent* event) { 226 aura::KeyEvent* event) {
227 // On key press, we want to hide the tooltip and not show it until change.
228 // This is the same behavior as hiding tooltips on timeout. Hence, we can
229 // simply simulate a timeout.
230 if (tooltip_shown_timer_.IsRunning()) {
231 tooltip_shown_timer_.Stop();
232 TooltipShownTimerFired();
233 }
215 return false; 234 return false;
216 } 235 }
217 236
218 bool TooltipController::PreHandleMouseEvent(aura::Window* target, 237 bool TooltipController::PreHandleMouseEvent(aura::Window* target,
219 aura::MouseEvent* event) { 238 aura::MouseEvent* event) {
220 switch (event->type()) { 239 switch (event->type()) {
221 case ui::ET_MOUSE_MOVED: 240 case ui::ET_MOUSE_MOVED:
222 case ui::ET_MOUSE_DRAGGED: 241 case ui::ET_MOUSE_DRAGGED:
223 if (tooltip_window_ != target) { 242 if (tooltip_window_ != target) {
224 if (tooltip_window_) 243 if (tooltip_window_)
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 result.append(*l); 386 result.append(*l);
368 } 387 }
369 } 388 }
370 *text = result; 389 *text = result;
371 } 390 }
372 391
373 void TooltipController::TooltipTimerFired() { 392 void TooltipController::TooltipTimerFired() {
374 UpdateIfRequired(); 393 UpdateIfRequired();
375 } 394 }
376 395
396 void TooltipController::TooltipShownTimerFired() {
397 tooltip_->Hide();
398
399 // Since the user presumably no longer needs the tooltip, we also stop the
400 // tooltip timer so that tooltip does not pop back up. We will restart this
401 // timer if the tooltip changes (see UpdateTooltip()).
402 tooltip_timer_.Stop();
403 }
404
377 void TooltipController::UpdateIfRequired() { 405 void TooltipController::UpdateIfRequired() {
378 if (!tooltips_enabled_ || mouse_pressed_ || IsDragDropInProgress() || 406 if (!tooltips_enabled_ || mouse_pressed_ || IsDragDropInProgress() ||
379 !aura::Env::GetInstance()->cursor_manager()->cursor_visible()) { 407 !aura::Env::GetInstance()->cursor_manager()->cursor_visible()) {
380 tooltip_->Hide(); 408 tooltip_->Hide();
381 return; 409 return;
382 } 410 }
383 411
384 string16 tooltip_text; 412 string16 tooltip_text;
385 if (tooltip_window_) 413 if (tooltip_window_)
386 tooltip_text = aura::client::GetTooltipText(tooltip_window_); 414 tooltip_text = aura::client::GetTooltipText(tooltip_window_);
387 415
388 // If the user pressed a mouse button. We will hide the tooltip and not show 416 // If the user pressed a mouse button. We will hide the tooltip and not show
389 // it until there is a change in the tooltip. 417 // it until there is a change in the tooltip.
390 if (tooltip_window_at_mouse_press_) { 418 if (tooltip_window_at_mouse_press_) {
391 if (tooltip_window_ == tooltip_window_at_mouse_press_ && 419 if (tooltip_window_ == tooltip_window_at_mouse_press_ &&
392 tooltip_text == tooltip_text_at_mouse_press_) { 420 tooltip_text == tooltip_text_at_mouse_press_) {
393 tooltip_->Hide(); 421 tooltip_->Hide();
394 return; 422 return;
395 } 423 }
396 tooltip_window_at_mouse_press_ = NULL; 424 tooltip_window_at_mouse_press_ = NULL;
397 } 425 }
398 426
399 // We add the !tooltip_->IsVisible() below because when we come here from 427 // We add the !tooltip_->IsVisible() below because when we come here from
400 // TooltipTimerFired(), the tooltip_text may not have changed but we still 428 // TooltipTimerFired(), the tooltip_text may not have changed but we still
401 // want to update the tooltip because the timer has fired. 429 // want to update the tooltip because the timer has fired.
402 // If we come here from UpdateTooltip(), we have already checked for tooltip 430 // If we come here from UpdateTooltip(), we have already checked for tooltip
403 // visibility and this check below will have no effect. 431 // visibility and this check below will have no effect.
404 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) { 432 if (tooltip_text_ != tooltip_text || !tooltip_->IsVisible()) {
433 tooltip_shown_timer_.Stop();
405 tooltip_text_ = tooltip_text; 434 tooltip_text_ = tooltip_text;
406 if (tooltip_text_.empty()) { 435 if (tooltip_text_.empty()) {
407 tooltip_->Hide(); 436 tooltip_->Hide();
408 } else { 437 } else {
409 string16 tooltip_text(tooltip_text_); 438 string16 tooltip_text(tooltip_text_);
410 gfx::Point widget_loc = curr_mouse_loc_; 439 gfx::Point widget_loc = curr_mouse_loc_;
411 widget_loc = widget_loc.Add( 440 widget_loc = widget_loc.Add(
412 tooltip_window_->GetScreenBounds().origin()); 441 tooltip_window_->GetScreenBounds().origin());
413 tooltip_->SetText(tooltip_text, widget_loc); 442 tooltip_->SetText(tooltip_text, widget_loc);
414 tooltip_->Show(); 443 tooltip_->Show();
444 tooltip_shown_timer_.Start(FROM_HERE,
445 base::TimeDelta::FromMilliseconds(kTooltipShownTimeoutMs),
446 this, &TooltipController::TooltipShownTimerFired);
415 } 447 }
416 } 448 }
417 } 449 }
418 450
419 bool TooltipController::IsTooltipVisible() { 451 bool TooltipController::IsTooltipVisible() {
420 return tooltip_->IsVisible(); 452 return tooltip_->IsVisible();
421 } 453 }
422 454
423 bool TooltipController::IsDragDropInProgress() { 455 bool TooltipController::IsDragDropInProgress() {
424 return drag_drop_client_->IsDragDropInProgress(); 456 return drag_drop_client_->IsDragDropInProgress();
425 } 457 }
426 458
427 } // namespace internal 459 } // namespace internal
428 } // namespace ash 460 } // namespace ash
OLDNEW
« no previous file with comments | « ash/tooltips/tooltip_controller.h ('k') | ash/tooltips/tooltip_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698