Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / ui / accessibility_focus_ring_controller.h
blob22c9a0da6710f69bf5699ae5ab62d3ce19a47f6b
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_
8 #include <vector>
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/geometry/rect.h"
18 namespace ui {
19 class Compositor;
22 namespace chromeos {
24 // AccessibilityFocusRingController manages a custom focus ring (or multiple
25 // rings) for accessibility.
26 class AccessibilityFocusRingController
27 : public FocusRingLayerDelegate,
28 public ui::CompositorAnimationObserver {
29 public:
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
34 // coordinates.
35 void SetFocusRing(const std::vector<gfx::Rect>& rects);
37 protected:
38 AccessibilityFocusRingController();
39 ~AccessibilityFocusRingController() override;
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;
51 private:
52 // FocusRingLayerDelegate.
53 void OnDeviceScaleFactorChanged() override;
55 // CompositorAnimationObserver.
56 void OnAnimationStep(base::TimeTicks timestamp) override;
57 void OnCompositingShuttingDown(ui::Compositor* compositor) override;
59 void Update();
61 AccessibilityFocusRing RingFromSortedRects(
62 const std::vector<gfx::Rect>& rects) const;
63 void SplitIntoParagraphShape(
64 const std::vector<gfx::Rect>& rects,
65 gfx::Rect* top,
66 gfx::Rect* middle,
67 gfx::Rect* bottom) const;
68 bool Intersects(const gfx::Rect& r1, const gfx::Rect& r2) const;
70 std::vector<gfx::Rect> rects_;
71 std::vector<AccessibilityFocusRing> previous_rings_;
72 std::vector<AccessibilityFocusRing> rings_;
73 ScopedVector<AccessibilityFocusRingLayer> layers_;
74 base::TimeTicks focus_change_time_;
75 ui::Compositor* compositor_;
77 friend struct base::DefaultSingletonTraits<AccessibilityFocusRingController>;
79 DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingController);
82 } // namespace chromeos
84 #endif // CHROME_BROWSER_CHROMEOS_UI_ACCESSIBILITY_FOCUS_RING_CONTROLLER_H_