| 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/magnifier/magnification_controller.h" | 5 #include "ash/magnifier/magnification_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_delegate.h" | 9 #include "ash/shell_delegate.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| 11 #include "base/synchronization/waitable_event.h" |
| 11 #include "ui/aura/client/cursor_client.h" | 12 #include "ui/aura/client/cursor_client.h" |
| 12 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_property.h" | 15 #include "ui/aura/window_property.h" |
| 15 #include "ui/base/events/event.h" | 16 #include "ui/base/events/event.h" |
| 16 #include "ui/base/events/event_handler.h" | 17 #include "ui/base/events/event_handler.h" |
| 17 #include "ui/compositor/dip_util.h" | 18 #include "ui/compositor/dip_util.h" |
| 18 #include "ui/compositor/layer.h" | 19 #include "ui/compositor/layer.h" |
| 19 #include "ui/compositor/layer_animation_observer.h" | 20 #include "ui/compositor/layer_animation_observer.h" |
| 20 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 22 #include "ui/gfx/point3_f.h" |
| 21 #include "ui/gfx/point_conversions.h" | 23 #include "ui/gfx/point_conversions.h" |
| 22 #include "ui/gfx/point_f.h" | 24 #include "ui/gfx/point_f.h" |
| 23 #include "ui/gfx/rect_conversions.h" | 25 #include "ui/gfx/rect_conversions.h" |
| 24 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 25 #include "ui/views/corewm/compound_event_filter.h" | 27 #include "ui/views/corewm/compound_event_filter.h" |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 const float kMaxMagnifiedScale = 4.0f; | 31 const float kMaxMagnifiedScale = 4.0f; |
| 30 const float kMaxMagnifiedScaleThreshold = 4.0f; | 32 const float kMaxMagnifiedScaleThreshold = 4.0f; |
| 31 const float kMinMagnifiedScaleThreshold = 1.1f; | 33 const float kMinMagnifiedScaleThreshold = 1.1f; |
| 32 const float kNonMagnifiedScale = 1.0f; | 34 const float kNonMagnifiedScale = 1.0f; |
| 33 | 35 |
| 34 const float kInitialMagnifiedScale = 2.0f; | 36 const float kInitialMagnifiedScale = 2.0f; |
| 35 const float kScrollScaleChangeFactor = 0.05f; | 37 const float kScrollScaleChangeFactor = 0.05f; |
| 36 | 38 |
| 37 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of | 39 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of |
| 38 // |kPanningMergin| from the edge, the view-port moves. | 40 // |kPanningMergin| from the edge, the view-port moves. |
| 39 const int kPanningMergin = 100; | 41 const int kPanningMergin = 100; |
| 40 | 42 |
| 43 void MoveCursorTo(aura::RootWindow* root_window, |
| 44 const gfx::Point root_location) { |
| 45 gfx::Point3F host_location_3f(root_location); |
| 46 root_window->layer()->transform().TransformPoint(host_location_3f); |
| 47 root_window->MoveCursorToHostLocation( |
| 48 gfx::ToCeiledPoint(host_location_3f.AsPointF())); |
| 49 } |
| 50 |
| 41 } // namespace | 51 } // namespace |
| 42 | 52 |
| 43 namespace ash { | 53 namespace ash { |
| 44 | 54 |
| 45 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
| 46 // MagnificationControllerImpl: | 56 // MagnificationControllerImpl: |
| 47 | 57 |
| 48 class MagnificationControllerImpl : virtual public MagnificationController, | 58 class MagnificationControllerImpl : virtual public MagnificationController, |
| 49 public ui::EventHandler, | 59 public ui::EventHandler, |
| 50 public ui::ImplicitAnimationObserver, | 60 public ui::ImplicitAnimationObserver, |
| 51 public aura::WindowObserver { | 61 public aura::WindowObserver { |
| 52 public: | 62 public: |
| 53 MagnificationControllerImpl(); | 63 MagnificationControllerImpl(); |
| 54 virtual ~MagnificationControllerImpl(); | 64 virtual ~MagnificationControllerImpl(); |
| 55 | 65 |
| 56 // MagnificationController overrides: | 66 // MagnificationController overrides: |
| 57 virtual void SetEnabled(bool enabled) OVERRIDE; | 67 virtual void SetEnabled(bool enabled) OVERRIDE; |
| 58 virtual bool IsEnabled() const OVERRIDE; | 68 virtual bool IsEnabled() const OVERRIDE; |
| 59 virtual void SetScale(float scale, bool animate) OVERRIDE; | 69 virtual void SetScale(float scale, bool animate) OVERRIDE; |
| 60 virtual float GetScale() const OVERRIDE { return scale_; } | 70 virtual float GetScale() const OVERRIDE { return scale_; } |
| 61 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; | 71 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; |
| 62 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; | 72 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; |
| 63 virtual gfx::Point GetWindowPosition() const OVERRIDE { | 73 virtual gfx::Point GetWindowPosition() const OVERRIDE { |
| 64 return gfx::ToFlooredPoint(origin_); | 74 return gfx::ToFlooredPoint(origin_); |
| 65 } | 75 } |
| 66 virtual void EnsureRectIsVisible(const gfx::Rect& rect, | 76 virtual void EnsureRectIsVisible(const gfx::Rect& rect, |
| 67 bool animate) OVERRIDE; | 77 bool animate) OVERRIDE; |
| 68 virtual void EnsurePointIsVisible(const gfx::Point& point, | 78 virtual void EnsurePointIsVisible(const gfx::Point& point, |
| 69 bool animate) OVERRIDE; | 79 bool animate) OVERRIDE; |
| 80 // For test |
| 81 virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE { |
| 82 return point_of_interest_; |
| 83 } |
| 70 | 84 |
| 71 private: | 85 private: |
| 72 // ui::ImplicitAnimationObserver overrides: | 86 // ui::ImplicitAnimationObserver overrides: |
| 73 virtual void OnImplicitAnimationsCompleted() OVERRIDE; | 87 virtual void OnImplicitAnimationsCompleted() OVERRIDE; |
| 74 | 88 |
| 75 // aura::WindowObserver overrides: | 89 // aura::WindowObserver overrides: |
| 76 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE; | 90 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE; |
| 77 | 91 |
| 78 // Redraws the magnification window with the given origin position and the | 92 // Redraws the magnification window with the given origin position and the |
| 79 // given scale. Returns true if the window is changed; otherwise, false. | 93 // given scale. Returns true if the window is changed; otherwise, false. |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 y = top + y_diff; | 365 y = top + y_diff; |
| 352 | 366 |
| 353 if (start_zoom && !is_on_animation_) { | 367 if (start_zoom && !is_on_animation_) { |
| 354 // No animation on panning. | 368 // No animation on panning. |
| 355 bool animate = false; | 369 bool animate = false; |
| 356 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); | 370 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); |
| 357 | 371 |
| 358 if (ret) { | 372 if (ret) { |
| 359 // If the magnified region is moved, hides the mouse cursor and moves it. | 373 // If the magnified region is moved, hides the mouse cursor and moves it. |
| 360 if (x_diff != 0 || y_diff != 0) | 374 if (x_diff != 0 || y_diff != 0) |
| 361 root_window_->MoveCursorTo(mouse); | 375 MoveCursorTo(root_window_, mouse); |
| 362 } | 376 } |
| 363 } | 377 } |
| 364 } | 378 } |
| 365 | 379 |
| 366 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( | 380 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( |
| 367 const gfx::Point& location) { | 381 const gfx::Point& location) { |
| 368 DCHECK(root_window_); | 382 DCHECK(root_window_); |
| 369 | 383 |
| 370 aura::client::CursorClient* cursor_client = | 384 aura::client::CursorClient* cursor_client = |
| 371 aura::client::GetCursorClient(root_window_); | 385 aura::client::GetCursorClient(root_window_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 *scale = kMaxMagnifiedScale; | 425 *scale = kMaxMagnifiedScale; |
| 412 | 426 |
| 413 DCHECK(kNonMagnifiedScale <= *scale && *scale <= kMaxMagnifiedScale); | 427 DCHECK(kNonMagnifiedScale <= *scale && *scale <= kMaxMagnifiedScale); |
| 414 } | 428 } |
| 415 | 429 |
| 416 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { | 430 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { |
| 417 if (!is_on_animation_) | 431 if (!is_on_animation_) |
| 418 return; | 432 return; |
| 419 | 433 |
| 420 if (move_cursor_after_animation_) { | 434 if (move_cursor_after_animation_) { |
| 421 root_window_->MoveCursorTo(position_after_animation_); | 435 MoveCursorTo(root_window_, position_after_animation_); |
| 422 move_cursor_after_animation_ = false; | 436 move_cursor_after_animation_ = false; |
| 423 | 437 |
| 424 aura::client::CursorClient* cursor_client = | 438 aura::client::CursorClient* cursor_client = |
| 425 aura::client::GetCursorClient(root_window_); | 439 aura::client::GetCursorClient(root_window_); |
| 426 if (cursor_client) | 440 if (cursor_client) |
| 427 cursor_client->EnableMouseEvents(); | 441 cursor_client->EnableMouseEvents(); |
| 428 } | 442 } |
| 429 | 443 |
| 430 is_on_animation_ = false; | 444 is_on_animation_ = false; |
| 431 } | 445 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 | 610 |
| 597 //////////////////////////////////////////////////////////////////////////////// | 611 //////////////////////////////////////////////////////////////////////////////// |
| 598 // MagnificationController: | 612 // MagnificationController: |
| 599 | 613 |
| 600 // static | 614 // static |
| 601 MagnificationController* MagnificationController::CreateInstance() { | 615 MagnificationController* MagnificationController::CreateInstance() { |
| 602 return new MagnificationControllerImpl(); | 616 return new MagnificationControllerImpl(); |
| 603 } | 617 } |
| 604 | 618 |
| 605 } // namespace ash | 619 } // namespace ash |
| OLD | NEW |