summaryrefslogtreecommitdiffstats
path: root/ash/magnifier/partial_magnification_controller.h
blob: fc61e4117775e225192462c500a30a8e9fbb3653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
#define ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_

#include "ui/aura/window_observer.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/widget/widget_observer.h"

namespace ash {

const float kDefaultPartialMagnifiedScale = 1.5f;
const float kNonPartialMagnifiedScale = 1.0f;

// Controls the partial screen magnifier, which is a small area of the screen
// which is zoomed in.  The zoomed area follows the mouse cursor when enabled.
class PartialMagnificationController
  : public ui::EventHandler,
    public aura::WindowObserver,
    public views::WidgetObserver {
 public:
  PartialMagnificationController();
  ~PartialMagnificationController() override;

  // Enables (or disables if |enabled| is false) partial screen magnifier
  // feature.
  virtual void SetEnabled(bool enabled);

  bool is_enabled() const { return is_enabled_; }

  // Sets the magnification ratio. 1.0f means no magnification.
  void SetScale(float scale);

  // Returns the current magnification ratio.
  float GetScale() const { return scale_; }

  // Switch PartialMagnified RootWindow to |new_root_window|. This does
  // following:
  //  - Remove the magnifier from the current root window.
  //  - Create a magnifier in the new root_window |new_root_window|.
  //  - Switch the target window from current window to |new_root_window|.
  void SwitchTargetRootWindow(aura::Window* new_root_window);

 private:
  void OnMouseMove(const gfx::Point& location_in_root);

  // Returns the root window that contains the mouse cursor.
  aura::Window* GetCurrentRootWindow();

  // Return true if the magnification scale > kMinPartialMagnifiedScaleThreshold
  bool IsPartialMagnified() const;

  // Create the magnifier window.
  void CreateMagnifierWindow();

  // Cleans up the window if needed.
  void CloseMagnifierWindow();

  // Removes this as an observer of the zoom widget and the root window.
  void RemoveZoomWidgetObservers();

  // ui::EventHandler overrides:
  void OnMouseEvent(ui::MouseEvent* event) override;

  // Overridden from WindowObserver:
  void OnWindowDestroying(aura::Window* window) override;

  // Overridden from WidgetObserver:
  void OnWidgetDestroying(views::Widget* widget) override;

  bool is_enabled_;

  // Current scale, origin (left-top) position of the magnification window.
  float scale_;
  gfx::Point origin_;

  views::Widget* zoom_widget_;

  DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController);
};

}  // namespace ash

#endif  // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_