Home | History | Annotate | Download | only in magnifier
      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 void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
     71 
     72   // Overridden from WindowObserver:
     73   virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
     74 
     75   // Overridden from WidgetObserver:
     76   virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
     77 
     78   // True if the magnified window is in motion of zooming or un-zooming effect.
     79   // Otherwise, false.
     80   bool is_on_zooming_;
     81 
     82   bool is_enabled_;
     83 
     84   // Current scale, origin (left-top) position of the magnification window.
     85   float scale_;
     86   gfx::Point origin_;
     87 
     88   views::Widget* zoom_widget_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController);
     91 };
     92 
     93 }  // namespace ash
     94 
     95 #endif  // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
     96