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