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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_vector.h"
12 #include "base/memory/singleton.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h"
15 #include "ui/compositor/compositor_animation_observer.h"
16 #include "ui/gfx/rect.h"
24 // AccessibilityFocusRingController manages a custom focus ring (or multiple
25 // rings) for accessibility.
26 class AccessibilityFocusRingController
27 : public FocusRingLayerDelegate
,
28 public ui::CompositorAnimationObserver
{
30 // Get the single instance of this class.
31 static AccessibilityFocusRingController
* GetInstance();
33 // Draw a focus ring around the given set of rects, in global screen
35 void SetFocusRing(const std::vector
<gfx::Rect
>& rects
);
38 AccessibilityFocusRingController();
39 virtual ~AccessibilityFocusRingController();
41 // Given an unordered vector of bounding rectangles that cover everything
42 // that currently has focus, populate a vector of one or more
43 // AccessibilityFocusRings that surround the rectangles. Adjacent or
44 // overlapping rectangles are combined first. This function is protected
45 // so it can be unit-tested.
46 void RectsToRings(const std::vector
<gfx::Rect
>& rects
,
47 std::vector
<AccessibilityFocusRing
>* rings
) const;
49 virtual int GetMargin() const;
52 // FocusRingLayerDelegate.
53 virtual void OnDeviceScaleFactorChanged() override
;
55 // CompositorAnimationObserver.
56 virtual void OnAnimationStep(base::TimeTicks timestamp
) override
;
60 AccessibilityFocusRing
RingFromSortedRects(
61 const std::vector
<gfx::Rect
>& rects
) const;
62 void SplitIntoParagraphShape(
63 const std::vector
<gfx::Rect
>& rects
,
66 gfx::Rect
* bottom
) const;
67 bool Intersects(const gfx::Rect
& r1
, const gfx::Rect
& r2
) const;
69 std::vector
<gfx::Rect
> rects_
;
70 std::vector
<AccessibilityFocusRing
> previous_rings_
;
71 std::vector
<AccessibilityFocusRing
> rings_
;
72 ScopedVector
<AccessibilityFocusRingLayer
> layers_
;
73 base::TimeTicks focus_change_time_
;
74 ui::Compositor
* compositor_
;
76 friend struct DefaultSingletonTraits
<AccessibilityFocusRingController
>;
78 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController
);
81 } // namespace chromeos
83 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_