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