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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/time/time.h" |
11 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h" | 12 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h" |
| 13 #include "ui/compositor/compositor_animation_observer.h" |
12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
13 | 15 |
| 16 namespace ui { |
| 17 class Compositor; |
| 18 } |
| 19 |
14 namespace chromeos { | 20 namespace chromeos { |
15 | 21 |
16 // AccessibilityFocusRingController manages a custom focus ring (or multiple | 22 // AccessibilityFocusRingController manages a custom focus ring (or multiple |
17 // rings) for accessibility. | 23 // rings) for accessibility. |
18 class AccessibilityFocusRingController : public FocusRingLayerDelegate { | 24 class AccessibilityFocusRingController |
| 25 : public FocusRingLayerDelegate, |
| 26 public ui::CompositorAnimationObserver { |
19 public: | 27 public: |
20 // Get the single instance of this class. | 28 // Get the single instance of this class. |
21 static AccessibilityFocusRingController* GetInstance(); | 29 static AccessibilityFocusRingController* GetInstance(); |
22 | 30 |
23 // Draw a focus ring around the given set of rects, in global screen | 31 // Draw a focus ring around the given set of rects, in global screen |
24 // coordinates. | 32 // coordinates. |
25 void SetFocusRing(const std::vector<gfx::Rect>& rects); | 33 void SetFocusRing(const std::vector<gfx::Rect>& rects); |
26 | 34 |
27 protected: | 35 protected: |
28 AccessibilityFocusRingController(); | 36 AccessibilityFocusRingController(); |
29 virtual ~AccessibilityFocusRingController(); | 37 virtual ~AccessibilityFocusRingController(); |
30 | 38 |
31 // Given an unordered vector of bounding rectangles that cover everything | 39 // Given an unordered vector of bounding rectangles that cover everything |
32 // that currently has focus, populate a vector of one or more | 40 // that currently has focus, populate a vector of one or more |
33 // AccessibilityFocusRings that surround the rectangles. Adjacent or | 41 // AccessibilityFocusRings that surround the rectangles. Adjacent or |
34 // overlapping rectangles are combined first. This function is protected | 42 // overlapping rectangles are combined first. This function is protected |
35 // so it can be unit-tested. | 43 // so it can be unit-tested. |
36 void RectsToRings(const std::vector<gfx::Rect>& rects, | 44 void RectsToRings(const std::vector<gfx::Rect>& rects, |
37 std::vector<AccessibilityFocusRing>* rings) const; | 45 std::vector<AccessibilityFocusRing>* rings) const; |
38 | 46 |
39 virtual int GetMargin() const; | 47 virtual int GetMargin() const; |
40 | 48 |
41 private: | 49 private: |
42 // FocusRingLayerDelegate. | 50 // FocusRingLayerDelegate. |
43 virtual void OnDeviceScaleFactorChanged() OVERRIDE; | 51 virtual void OnDeviceScaleFactorChanged() OVERRIDE; |
44 | 52 |
| 53 // CompositorAnimationObserver. |
| 54 virtual void OnAnimationStep(base::TimeTicks timestamp) OVERRIDE; |
| 55 |
45 void Update(); | 56 void Update(); |
46 | 57 |
47 AccessibilityFocusRing RingFromSortedRects( | 58 AccessibilityFocusRing RingFromSortedRects( |
48 const std::vector<gfx::Rect>& rects) const; | 59 const std::vector<gfx::Rect>& rects) const; |
49 void SplitIntoParagraphShape( | 60 void SplitIntoParagraphShape( |
50 const std::vector<gfx::Rect>& rects, | 61 const std::vector<gfx::Rect>& rects, |
51 gfx::Rect* top, | 62 gfx::Rect* top, |
52 gfx::Rect* middle, | 63 gfx::Rect* middle, |
53 gfx::Rect* bottom) const; | 64 gfx::Rect* bottom) const; |
54 bool Intersects(const gfx::Rect& r1, const gfx::Rect& r2) const; | 65 bool Intersects(const gfx::Rect& r1, const gfx::Rect& r2) const; |
55 | 66 |
56 std::vector<gfx::Rect> rects_; | 67 std::vector<gfx::Rect> rects_; |
| 68 std::vector<AccessibilityFocusRing> previous_rings_; |
57 std::vector<AccessibilityFocusRing> rings_; | 69 std::vector<AccessibilityFocusRing> rings_; |
58 scoped_ptr<AccessibilityFocusRingLayer> main_focus_ring_layer_; | 70 std::vector<scoped_ptr<AccessibilityFocusRingLayer> > layers_; |
59 std::vector<scoped_ptr<AccessibilityFocusRingLayer> > extra_layers_; | 71 base::TimeTicks focus_change_time_; |
| 72 ui::Compositor* compositor_; |
60 | 73 |
61 friend struct DefaultSingletonTraits<AccessibilityFocusRingController>; | 74 friend struct DefaultSingletonTraits<AccessibilityFocusRingController>; |
62 | 75 |
63 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController); | 76 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController); |
64 }; | 77 }; |
65 | 78 |
66 } // namespace chromeos | 79 } // namespace chromeos |
67 | 80 |
68 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ | 81 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_ |
OLD | NEW |