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.
4 
5 #ifndef ASH_ACCESSIBILITY_ACCESSIBILITY_FOCUS_RING_LAYER_H_
6 #define ASH_ACCESSIBILITY_ACCESSIBILITY_FOCUS_RING_LAYER_H_
7 
8 #include "ash/accessibility/accessibility_focus_ring.h"
9 #include "ash/accessibility/focus_ring_layer.h"
10 #include "ash/ash_export.h"
11 #include "ash/public/cpp/accessibility_focus_ring_info.h"
12 #include "base/macros.h"
13 #include "ui/compositor/paint_recorder.h"
14 
15 namespace ash {
16 
17 // A subclass of FocusRingLayer intended for use by ChromeVox, Select to Speak
18 // and Switch Access; it supports nonrectangular focus rings in order to
19 // highlight groups of elements or a range of text on a page.
20 class ASH_EXPORT AccessibilityFocusRingLayer : public FocusRingLayer {
21  public:
22   explicit AccessibilityFocusRingLayer(AccessibilityLayerDelegate* delegate);
23   ~AccessibilityFocusRingLayer() override;
24 
25   // Create the layer and update its bounds and position in the hierarchy.
26   void Set(const AccessibilityFocusRing& ring);
27 
28   void SetAppearance(FocusRingType type,
29                      SkColor color,
30                      SkColor secondary_color,
31                      SkColor background_alpha);
32 
color_for_testing()33   SkColor color_for_testing() { return custom_color(); }
34 
35  private:
36   // ui::LayerDelegate overrides:
37   void OnPaintLayer(const ui::PaintContext& context) override;
38 
39   void DrawGlowFocusRing(ui::PaintRecorder& recorder, cc::PaintFlags& flags);
40   void DrawSolidFocusRing(ui::PaintRecorder& recorder, cc::PaintFlags& flags);
41   void DrawDashedFocusRing(ui::PaintRecorder& recorder, cc::PaintFlags& flags);
42   void DrawFocusBackground(ui::PaintRecorder& recorder);
43 
44   // The outline of the current focus ring.
45   AccessibilityFocusRing ring_;
46   // The type of focus ring.
47   FocusRingType type_;
48   // The secondary color.
49   SkColor secondary_color_;
50   // The color of the background. When fully transparent, no background will be
51   // drawn.
52   SkColor background_color_ = SK_ColorTRANSPARENT;
53 
54   DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingLayer);
55 };
56 
57 }  // namespace ash
58 
59 #endif  // ASH_ACCESSIBILITY_ACCESSIBILITY_FOCUS_RING_LAYER_H_
60