OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" |
14 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h" | 15 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h" |
15 #include "ui/compositor/compositor_animation_observer.h" | 16 #include "ui/compositor/compositor_animation_observer.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
19 class Compositor; | 20 class Compositor; |
20 } | 21 } |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 // AccessibilityFocusRingController manages a custom focus ring (or multiple | 25 // AccessibilityFocusRingController handles drawing custom rings around |
25 // rings) for accessibility. | 26 // the focused object, cursor, and/or caret for accessibility. |
26 class AccessibilityFocusRingController | 27 class AccessibilityFocusRingController |
27 : public FocusRingLayerDelegate, | 28 : public FocusRingLayerDelegate, |
28 public ui::CompositorAnimationObserver { | 29 public ui::CompositorAnimationObserver { |
29 public: | 30 public: |
30 // Get the single instance of this class. | 31 // Get the single instance of this class. |
31 static AccessibilityFocusRingController* GetInstance(); | 32 static AccessibilityFocusRingController* GetInstance(); |
32 | 33 |
33 // Draw a focus ring around the given set of rects, in global screen | 34 // Draw a focus ring around the given set of rects, in global screen |
34 // coordinates. | 35 // coordinates. |
35 void SetFocusRing(const std::vector<gfx::Rect>& rects); | 36 void SetFocusRing(const std::vector<gfx::Rect>& rects); |
36 | 37 |
| 38 // Draw a ring around the mouse cursor. |
| 39 void SetCursorRing(const gfx::Point& location); |
| 40 |
| 41 // Draw a ring around the text caret. |
| 42 void SetCaretRing(const gfx::Point& location); |
| 43 |
37 protected: | 44 protected: |
38 AccessibilityFocusRingController(); | 45 AccessibilityFocusRingController(); |
39 ~AccessibilityFocusRingController() override; | 46 ~AccessibilityFocusRingController() override; |
40 | 47 |
41 // Given an unordered vector of bounding rectangles that cover everything | 48 // Given an unordered vector of bounding rectangles that cover everything |
42 // that currently has focus, populate a vector of one or more | 49 // that currently has focus, populate a vector of one or more |
43 // AccessibilityFocusRings that surround the rectangles. Adjacent or | 50 // AccessibilityFocusRings that surround the rectangles. Adjacent or |
44 // overlapping rectangles are combined first. This function is protected | 51 // overlapping rectangles are combined first. This function is protected |
45 // so it can be unit-tested. | 52 // so it can be unit-tested. |
46 void RectsToRings(const std::vector<gfx::Rect>& rects, | 53 void RectsToRings(const std::vector<gfx::Rect>& rects, |
47 std::vector<AccessibilityFocusRing>* rings) const; | 54 std::vector<AccessibilityFocusRing>* rings) const; |
48 | 55 |
49 virtual int GetMargin() const; | 56 virtual int GetMargin() const; |
50 | 57 |
51 private: | 58 private: |
52 // FocusRingLayerDelegate. | 59 // FocusRingLayerDelegate. |
53 void OnDeviceScaleFactorChanged() override; | 60 void OnDeviceScaleFactorChanged() override; |
54 | 61 |
55 // CompositorAnimationObserver. | 62 // CompositorAnimationObserver. |
56 void OnAnimationStep(base::TimeTicks timestamp) override; | 63 void OnAnimationStep(base::TimeTicks timestamp) override; |
57 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 64 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
58 | 65 |
59 void Update(); | 66 void Update(); |
60 | 67 |
| 68 void AnimateFocusRings(base::TimeTicks timestamp); |
| 69 void AnimateCursorRing(base::TimeTicks timestamp); |
| 70 |
61 AccessibilityFocusRing RingFromSortedRects( | 71 AccessibilityFocusRing RingFromSortedRects( |
62 const std::vector<gfx::Rect>& rects) const; | 72 const std::vector<gfx::Rect>& rects) const; |
63 void SplitIntoParagraphShape( | 73 void SplitIntoParagraphShape( |
64 const std::vector<gfx::Rect>& rects, | 74 const std::vector<gfx::Rect>& rects, |
65 gfx::Rect* top, | 75 gfx::Rect* top, |
66 gfx::Rect* middle, | 76 gfx::Rect* middle, |
67 gfx::Rect* bottom) const; | 77 gfx::Rect* bottom) const; |
68 bool Intersects(const gfx::Rect& r1, const gfx::Rect& r2) const; | 78 bool Intersects(const gfx::Rect& r1, const gfx::Rect& r2) const; |
| 79 ui::Compositor* CompositorForBounds(const gfx::Rect& bounds); |
| 80 void RemoveAnimationObservers(); |
| 81 void AddAnimationObservers(); |
69 | 82 |
70 std::vector<gfx::Rect> rects_; | 83 std::vector<gfx::Rect> rects_; |
71 std::vector<AccessibilityFocusRing> previous_rings_; | 84 std::vector<AccessibilityFocusRing> previous_rings_; |
72 std::vector<AccessibilityFocusRing> rings_; | 85 std::vector<AccessibilityFocusRing> rings_; |
73 ScopedVector<AccessibilityFocusRingLayer> layers_; | 86 ScopedVector<AccessibilityFocusRingLayer> layers_; |
74 base::TimeTicks focus_change_time_; | 87 base::TimeTicks focus_change_time_; |
75 ui::Compositor* compositor_; | 88 ui::Compositor* compositor_; |
76 | 89 |
| 90 base::TimeTicks cursor_start_time_; |
| 91 base::TimeTicks cursor_change_time_; |
| 92 gfx::Point cursor_location_; |
| 93 float cursor_opacity_; |
| 94 scoped_ptr<AccessibilityCursorRingLayer> cursor_layer_; |
| 95 ui::Compositor* cursor_compositor_; |
| 96 |
| 97 gfx::Point caret_location_; |
| 98 scoped_ptr<AccessibilityCursorRingLayer> caret_layer_; |
| 99 |
77 friend struct base::DefaultSingletonTraits<AccessibilityFocusRingController>; | 100 friend struct base::DefaultSingletonTraits<AccessibilityFocusRingController>; |
78 | 101 |
79 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController); | 102 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController); |
80 }; | 103 }; |
81 | 104 |
82 } // namespace chromeos | 105 } // namespace chromeos |
83 | 106 |
84 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ | 107 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ |
OLD | NEW |