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.
5 #ifndef ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
6 #define ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
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"
19 const float kDefaultPartialMagnifiedScale
= 1.5f
;
20 const float kNonPartialMagnifiedScale
= 1.0f
;
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
{
29 PartialMagnificationController();
30 virtual ~PartialMagnificationController();
32 // Enables (or disables if |enabled| is false) partial screen magnifier
34 virtual void SetEnabled(bool enabled
);
36 bool is_enabled() const { return is_enabled_
; }
38 // Sets the magnification ratio. 1.0f means no magnification.
39 void SetScale(float scale
);
41 // Returns the current magnification ratio.
42 float GetScale() const { return scale_
; }
45 void OnMouseMove(const gfx::Point
& location_in_root
);
47 // Switch PartialMagnified RootWindow to |new_root_window|. This does
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
);
54 // Returns the root window that contains the mouse cursor.
55 aura::RootWindow
* GetCurrentRootWindow();
57 // Return true if the magnification scale > kMinPartialMagnifiedScaleThreshold
58 bool IsPartialMagnified() const;
60 // Create the magnifier window.
61 void CreateMagnifierWindow();
63 // Cleans up the window if needed.
64 void CloseMagnifierWindow();
66 // Removes this as an observer of the zoom widget and the root window.
67 void RemoveZoomWidgetObservers();
69 // ui::EventHandler overrides:
70 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
72 // Overridden from WindowObserver:
73 virtual void OnWindowDestroying(aura::Window
* window
) OVERRIDE
;
75 // Overridden from WidgetObserver:
76 virtual void OnWidgetDestroying(views::Widget
* widget
) OVERRIDE
;
78 // True if the magnified window is in motion of zooming or un-zooming effect.
84 // Current scale, origin (left-top) position of the magnification window.
88 views::Widget
* zoom_widget_
;
90 DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController
);
95 #endif // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_