Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Side by Side Diff: ash/magnifier/partial_magnification_controller.h

Issue 2269383002: Magnifier border is now more visible on light backgrounds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ 5 #ifndef ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
6 #define ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ 6 #define ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
7 7
8 #include <memory>
9
10 #include "ash/ash_export.h"
8 #include "base/macros.h" 11 #include "base/macros.h"
9 #include "ui/aura/window_observer.h" 12 #include "ui/aura/window_observer.h"
10 #include "ui/events/event_handler.h" 13 #include "ui/events/event_handler.h"
11 #include "ui/gfx/geometry/point.h" 14 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/size.h"
12 #include "ui/views/widget/widget_observer.h" 16 #include "ui/views/widget/widget_observer.h"
13 17
18 namespace ui {
19 class Layer;
20 class LocatedEvent;
21 struct PointerDetails;
22 }
23
14 namespace ash { 24 namespace ash {
15 25
16 const float kDefaultPartialMagnifiedScale = 1.5f;
17 const float kNonPartialMagnifiedScale = 1.0f;
18
19 // Controls the partial screen magnifier, which is a small area of the screen 26 // Controls the partial screen magnifier, which is a small area of the screen
20 // which is zoomed in. The zoomed area follows the mouse cursor when enabled. 27 // which is zoomed in. The zoomed area follows the mouse cursor when enabled.
21 class PartialMagnificationController : public ui::EventHandler, 28 class ASH_EXPORT PartialMagnificationController : public ui::EventHandler,
22 public aura::WindowObserver, 29 public aura::WindowObserver,
23 public views::WidgetObserver { 30 public views::WidgetObserver {
24 public: 31 public:
25 PartialMagnificationController(); 32 PartialMagnificationController();
26 ~PartialMagnificationController() override; 33 ~PartialMagnificationController() override;
27 34
28 // Enables (or disables if |enabled| is false) partial screen magnifier 35 // Turns the partial screen magnifier feature on or off. Turning the magnifier
29 // feature. 36 // on does not imply that it will be displayed; the magnifier is only
30 virtual void SetEnabled(bool enabled); 37 // displayed when it is both enabled and active.
31 38 void SetEnabled(bool enabled);
32 bool is_enabled() const { return is_enabled_; }
33
34 // Sets the magnification ratio. 1.0f means no magnification.
35 void SetScale(float scale);
36
37 // Returns the current magnification ratio.
38 float GetScale() const { return scale_; }
39 39
40 // Switch PartialMagnified RootWindow to |new_root_window|. This does 40 // Switch PartialMagnified RootWindow to |new_root_window|. This does
41 // following: 41 // following:
42 // - Remove the magnifier from the current root window. 42 // - Remove the magnifier from the current root window.
43 // - Create a magnifier in the new root_window |new_root_window|. 43 // - Create a magnifier in the new root_window |new_root_window|.
44 // - Switch the target window from current window to |new_root_window|. 44 // - Switch the target window from current window to |new_root_window|.
45 void SwitchTargetRootWindow(aura::Window* new_root_window); 45 void SwitchTargetRootWindowIfNeeded(aura::Window* new_root_window);
46 46
47 private: 47 private:
48 void OnMouseMove(const gfx::Point& location_in_root); 48 friend class PartialMagnificationControllerTestApi;
49 49
50 // Returns the root window that contains the mouse cursor. 50 class ContentMask;
51 aura::Window* GetCurrentRootWindow(); 51 class BorderRenderer;
52 52
53 // Return true if the magnification scale > kMinPartialMagnifiedScaleThreshold 53 // ui::EventHandler:
54 bool IsPartialMagnified() const; 54 void OnMouseEvent(ui::MouseEvent* event) override;
55 void OnTouchEvent(ui::TouchEvent* event) override;
55 56
56 // Create the magnifier window. 57 // WindowObserver:
57 void CreateMagnifierWindow(); 58 void OnWindowDestroying(aura::Window* window) override;
58 59
59 // Cleans up the window if needed. 60 // WidgetObserver:
61 void OnWidgetDestroying(views::Widget* widget) override;
62
63 // Enables or disables the actual magnifier window.
64 void SetActive(bool active);
65
66 // Contains common logic between OnMouseEvent and OnTouchEvent.
67 void OnLocatedEvent(ui::LocatedEvent* event,
68 const ui::PointerDetails& pointer_details);
69
70 // Create or close the magnifier window.
71 void CreateMagnifierWindow(aura::Window* root_window);
60 void CloseMagnifierWindow(); 72 void CloseMagnifierWindow();
61 73
62 // Removes this as an observer of the zoom widget and the root window. 74 // Removes this as an observer of the zoom widget and the root window.
63 void RemoveZoomWidgetObservers(); 75 void RemoveZoomWidgetObservers();
64 76
65 // ui::EventHandler overrides: 77 bool is_enabled_ = false;
66 void OnMouseEvent(ui::MouseEvent* event) override; 78 bool is_active_ = false;
67 79
68 // Overridden from WindowObserver: 80 // The host widget is the root parent for all of the layers. The widget's
69 void OnWindowDestroying(aura::Window* window) override; 81 // location follows the mouse, which causes the layers to also move.
82 views::Widget* host_widget_ = nullptr;
70 83
71 // Overridden from WidgetObserver: 84 // Draws the background with a zoom filter applied.
72 void OnWidgetDestroying(views::Widget* widget) override; 85 std::unique_ptr<ui::Layer> zoom_layer_;
73 86 // Draws an outline that is overlayed on top of |zoom_layer_|.
74 bool is_enabled_; 87 std::unique_ptr<ui::Layer> border_layer_;
75 88 // Masks the content of |zoom_layer_| so that only a circle is magnified.
76 // Current scale, origin (left-top) position of the magnification window. 89 std::unique_ptr<ContentMask> zoom_mask_;
77 float scale_; 90 // Masks the content of |border_layer_| so that only a circle outline is
78 gfx::Point origin_; 91 // drawn.
79 92 std::unique_ptr<ContentMask> border_mask_;
80 views::Widget* zoom_widget_;
81 93
82 DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController); 94 DISALLOW_COPY_AND_ASSIGN(PartialMagnificationController);
83 }; 95 };
84 96
85 } // namespace ash 97 } // namespace ash
86 98
87 #endif // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_ 99 #endif // ASH_MAGNIFIER_PARTIAL_MAGNIFICATION_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698