OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ |
| 6 #define ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ |
| 7 |
| 8 #include "ui/aura/window_observer.h" |
| 9 #include "ui/base/events/event_handler.h" |
| 10 #include "ui/gfx/point.h" |
| 11 #include "ui/views/widget/widget_observer.h" |
| 12 |
| 13 namespace aura { |
| 14 class RootWindow; |
| 15 } |
| 16 |
| 17 namespace ash { |
| 18 |
| 19 const float kDefaultPartialMagnifiedScale = 1.5f; |
| 20 const float kNonPartialMagnifiedScale = 1.0f; |
| 21 |
| 22 // Controls the partial screen magnifier, which is a small area of the screen |
| 23 // which is zoomed in. The zoomed area follows the mouse cursor when enabled. |
| 24 class PartialMagnificationController |
| 25 : public ui::EventHandler, |
| 26 public aura::WindowObserver, |
| 27 public views::WidgetObserver { |
| 28 public: |
| 29 PartialMagnificationController(); |
| 30 virtual ~PartialMagnificationController(); |
| 31 |
| 32 // Enables (or disables if |enabled| is false) partial screen magnifier |
| 33 // feature. |
| 34 virtual void SetEnabled(bool enabled); |
| 35 |
| 36 bool is_enabled() const { return is_enabled_; } |
| 37 |
| 38 // Sets the magnification ratio. 1.0f means no magnification. |
| 39 void SetScale(float scale); |
| 40 |
| 41 // Returns the current magnification ratio. |
| 42 float GetScale() const { return scale_; } |
| 43 |
| 44 private: |
| 45 void OnMouseMove(const gfx::Point& location_in_root); |
| 46 |
| 47 // Switch PartialMagnified RootWindow to |new_root_window|. This does |
| 48 // following: |
| 49 // - Remove the magnifier from the current root window. |
| 50 // - Create a magnifier in the new root_window |new_root_window|. |
| 51 // - Switch the target window from current window to |new_root_window|. |
| 52 void SwitchTargetRootWindow(aura::RootWindow* new_root_window); |
| 53 |
| 54 // Returns the root window that contains the mouse cursor. |
| 55 aura::RootWindow* GetCurrentRootWindow(); |
| 56 |
| 57 // Return true if the magnification scale > kMinPartialMagnifiedScaleThreshold |
| 58 bool IsPartialMagnified() const; |
| 59 |
| 60 // Create the magnifier window. |
| 61 void CreateMagnifierWindow(); |
| 62 |
| 63 // Cleans up the window if needed. |
| 64 void CloseMagnifierWindow(); |
| 65 |
| 66 // Removes this as an observer of the zoom widget and the root window. |
| 67 void RemoveZoomWidgetObservers(); |
| 68 |
| 69 // ui::EventHandler overrides: |
| 70 virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 71 virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 72 virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 73 virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; |
| 74 virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 75 |
| 76 // Overridden from WindowObserver: |
| 77 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 78 |
| 79 // Overridden from WidgetObserver: |
| 80 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
| 81 |
| 82 // True if the magnified window is in motion of zooming or un-zooming effect. |
| 83 // Otherwise, false. |
| 84 bool is_on_zooming_; |
| 85 |
| 86 bool is_enabled_; |
| 87 |
| 88 // Current scale, origin (left-top) position of the magnification window. |
| 89 float scale_; |
| 90 gfx::Point origin_; |
| 91 |
| 92 views::Widget* zoom_widget_; |
| 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController); |
| 95 }; |
| 96 |
| 97 } // namespace ash |
| 98 |
| 99 #endif // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ |
OLD | NEW |