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 "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" |
11 #include "ash/wm/cursor_manager.h" | 11 #include "ash/wm/cursor_manager.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "ui/aura/client/drag_drop_client.h" | 16 #include "ui/aura/client/drag_drop_client.h" |
17 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
18 #include "ui/aura/event.h" | |
19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/base/event.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/base/text/text_elider.h" | 22 #include "ui/base/text/text_elider.h" |
23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
24 #include "ui/gfx/point.h" | 24 #include "ui/gfx/point.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/views/background.h" | 27 #include "ui/views/background.h" |
28 #include "ui/views/border.h" | 28 #include "ui/views/border.h" |
29 #include "ui/views/controls/label.h" | 29 #include "ui/views/controls/label.h" |
30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 | 232 |
233 void TooltipController::SetTooltipsEnabled(bool enable) { | 233 void TooltipController::SetTooltipsEnabled(bool enable) { |
234 if (tooltips_enabled_ == enable) | 234 if (tooltips_enabled_ == enable) |
235 return; | 235 return; |
236 tooltips_enabled_ = enable; | 236 tooltips_enabled_ = enable; |
237 UpdateTooltip(tooltip_window_); | 237 UpdateTooltip(tooltip_window_); |
238 } | 238 } |
239 | 239 |
240 bool TooltipController::PreHandleKeyEvent(aura::Window* target, | 240 bool TooltipController::PreHandleKeyEvent(aura::Window* target, |
241 aura::KeyEvent* event) { | 241 ui::KeyEvent* event) { |
242 // On key press, we want to hide the tooltip and not show it until change. | 242 // On key press, we want to hide the tooltip and not show it until change. |
243 // This is the same behavior as hiding tooltips on timeout. Hence, we can | 243 // This is the same behavior as hiding tooltips on timeout. Hence, we can |
244 // simply simulate a timeout. | 244 // simply simulate a timeout. |
245 if (tooltip_shown_timer_.IsRunning()) { | 245 if (tooltip_shown_timer_.IsRunning()) { |
246 tooltip_shown_timer_.Stop(); | 246 tooltip_shown_timer_.Stop(); |
247 TooltipShownTimerFired(); | 247 TooltipShownTimerFired(); |
248 } | 248 } |
249 return false; | 249 return false; |
250 } | 250 } |
251 | 251 |
252 bool TooltipController::PreHandleMouseEvent(aura::Window* target, | 252 bool TooltipController::PreHandleMouseEvent(aura::Window* target, |
253 aura::MouseEvent* event) { | 253 ui::MouseEvent* event) { |
254 switch (event->type()) { | 254 switch (event->type()) { |
255 case ui::ET_MOUSE_MOVED: | 255 case ui::ET_MOUSE_MOVED: |
256 case ui::ET_MOUSE_DRAGGED: | 256 case ui::ET_MOUSE_DRAGGED: |
257 if (tooltip_window_ != target) { | 257 if (tooltip_window_ != target) { |
258 if (tooltip_window_) | 258 if (tooltip_window_) |
259 tooltip_window_->RemoveObserver(this); | 259 tooltip_window_->RemoveObserver(this); |
260 tooltip_window_ = target; | 260 tooltip_window_ = target; |
261 tooltip_window_->AddObserver(this); | 261 tooltip_window_->AddObserver(this); |
262 } | 262 } |
263 curr_mouse_loc_ = event->location(); | 263 curr_mouse_loc_ = event->location(); |
(...skipping 24 matching lines...) Expand all Loading... |
288 GetTooltip()->Hide(); | 288 GetTooltip()->Hide(); |
289 break; | 289 break; |
290 default: | 290 default: |
291 break; | 291 break; |
292 } | 292 } |
293 return false; | 293 return false; |
294 } | 294 } |
295 | 295 |
296 ui::TouchStatus TooltipController::PreHandleTouchEvent( | 296 ui::TouchStatus TooltipController::PreHandleTouchEvent( |
297 aura::Window* target, | 297 aura::Window* target, |
298 aura::TouchEvent* event) { | 298 ui::TouchEventImpl* event) { |
299 // TODO(varunjain): need to properly implement tooltips for | 299 // TODO(varunjain): need to properly implement tooltips for |
300 // touch events. | 300 // touch events. |
301 // Hide the tooltip for touch events. | 301 // Hide the tooltip for touch events. |
302 if (GetTooltip()->IsVisible()) | 302 if (GetTooltip()->IsVisible()) |
303 GetTooltip()->Hide(); | 303 GetTooltip()->Hide(); |
304 if (tooltip_window_) | 304 if (tooltip_window_) |
305 tooltip_window_->RemoveObserver(this); | 305 tooltip_window_->RemoveObserver(this); |
306 tooltip_window_ = NULL; | 306 tooltip_window_ = NULL; |
307 return ui::TOUCH_STATUS_UNKNOWN; | 307 return ui::TOUCH_STATUS_UNKNOWN; |
308 } | 308 } |
309 | 309 |
310 ui::GestureStatus TooltipController::PreHandleGestureEvent( | 310 ui::GestureStatus TooltipController::PreHandleGestureEvent( |
311 aura::Window* target, | 311 aura::Window* target, |
312 aura::GestureEvent* event) { | 312 ui::GestureEventImpl* event) { |
313 return ui::GESTURE_STATUS_UNKNOWN; | 313 return ui::GESTURE_STATUS_UNKNOWN; |
314 } | 314 } |
315 | 315 |
316 void TooltipController::OnWindowDestroyed(aura::Window* window) { | 316 void TooltipController::OnWindowDestroyed(aura::Window* window) { |
317 if (tooltip_window_ == window) { | 317 if (tooltip_window_ == window) { |
318 tooltip_window_->RemoveObserver(this); | 318 tooltip_window_->RemoveObserver(this); |
319 tooltip_window_ = NULL; | 319 tooltip_window_ = NULL; |
320 } | 320 } |
321 } | 321 } |
322 | 322 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 } | 472 } |
473 | 473 |
474 TooltipController::Tooltip* TooltipController::GetTooltip() { | 474 TooltipController::Tooltip* TooltipController::GetTooltip() { |
475 if (!tooltip_.get()) | 475 if (!tooltip_.get()) |
476 tooltip_.reset(new Tooltip); | 476 tooltip_.reset(new Tooltip); |
477 return tooltip_.get(); | 477 return tooltip_.get(); |
478 } | 478 } |
479 | 479 |
480 } // namespace internal | 480 } // namespace internal |
481 } // namespace ash | 481 } // namespace ash |
OLD | NEW |