Commit 0f6c1bd7 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

Add support for two color accessibility focus rings

This change is to support the Switch Access focus ring style described
in this spec: https://gallery.googleplex.com/projects/MCHbtQVoQ2HCZQBEKUk1sS_U/files/MCHtA7U1iMGr6-mR9r6ArPGAjSutDL__KP4

Bug: 925103
Change-Id: I6aeda730fd8717282cb49867840010aea7a92f83
Reviewed-on: https://chromium-review.googlesource.com/c/1435435
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626224}
parent 773e8566
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
namespace ash { namespace ash {
...@@ -20,10 +19,8 @@ namespace { ...@@ -20,10 +19,8 @@ namespace {
// The number of pixels in the color gradient that fades to transparent. // The number of pixels in the color gradient that fades to transparent.
const int kGradientWidth = 6; const int kGradientWidth = 6;
// The color of the focus ring. In the future this might be a parameter. // The default color of the focus ring.
const int kFocusRingColorRed = 247; const SkColor kDefaultFocusRingColor = SkColorSetARGB(255, 247, 152, 58);
const int kFocusRingColorGreen = 152;
const int kFocusRingColorBlue = 58;
int sign(int x) { int sign(int x) {
return ((x > 0) ? 1 : (x == 0) ? 0 : -1); return ((x > 0) ? 1 : (x == 0) ? 0 : -1);
...@@ -106,6 +103,15 @@ void AccessibilityFocusRingLayer::Set(const AccessibilityFocusRing& ring) { ...@@ -106,6 +103,15 @@ void AccessibilityFocusRingLayer::Set(const AccessibilityFocusRing& ring) {
CreateOrUpdateLayer(root_window, "AccessibilityFocusRing", bounds); CreateOrUpdateLayer(root_window, "AccessibilityFocusRing", bounds);
} }
void AccessibilityFocusRingLayer::EnableDoubleFocusRing(
SkColor secondary_color) {
secondary_color_ = secondary_color;
}
void AccessibilityFocusRingLayer::DisableDoubleFocusRing() {
secondary_color_.reset();
}
void AccessibilityFocusRingLayer::OnPaintLayer( void AccessibilityFocusRingLayer::OnPaintLayer(
const ui::PaintContext& context) { const ui::PaintContext& context) {
ui::PaintRecorder recorder(context, layer()->size()); ui::PaintRecorder recorder(context, layer()->size());
...@@ -115,11 +121,33 @@ void AccessibilityFocusRingLayer::OnPaintLayer( ...@@ -115,11 +121,33 @@ void AccessibilityFocusRingLayer::OnPaintLayer(
flags.setStyle(cc::PaintFlags::kStroke_Style); flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setStrokeWidth(2); flags.setStrokeWidth(2);
if (secondary_color_)
DrawDoubleFocusRing(recorder, flags);
else
DrawFocusRing(recorder, flags);
}
void AccessibilityFocusRingLayer::DrawDoubleFocusRing(
ui::PaintRecorder& recorder,
cc::PaintFlags& flags) {
SkColor base_color =
has_custom_color() ? custom_color() : kDefaultFocusRingColor;
SkPath path;
gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin();
flags.setColor(base_color);
path = MakePath(ring_, 0, offset);
recorder.canvas()->DrawPath(path, flags);
flags.setColor(*(secondary_color_));
path = MakePath(ring_, 2, offset);
recorder.canvas()->DrawPath(path, flags);
}
void AccessibilityFocusRingLayer::DrawFocusRing(ui::PaintRecorder& recorder,
cc::PaintFlags& flags) {
SkColor base_color = SkColor base_color =
has_custom_color() has_custom_color() ? custom_color() : kDefaultFocusRingColor;
? custom_color()
: SkColorSetARGB(255, kFocusRingColorRed, kFocusRingColorGreen,
kFocusRingColorBlue);
SkPath path; SkPath path;
gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin(); gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/accessibility/focus_ring_layer.h" #include "ash/accessibility/focus_ring_layer.h"
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/compositor/paint_recorder.h"
namespace ash { namespace ash {
...@@ -23,12 +24,20 @@ class ASH_EXPORT AccessibilityFocusRingLayer : public FocusRingLayer { ...@@ -23,12 +24,20 @@ class ASH_EXPORT AccessibilityFocusRingLayer : public FocusRingLayer {
// Create the layer and update its bounds and position in the hierarchy. // Create the layer and update its bounds and position in the hierarchy.
void Set(const AccessibilityFocusRing& ring); void Set(const AccessibilityFocusRing& ring);
void EnableDoubleFocusRing(SkColor secondary_color);
void DisableDoubleFocusRing();
private: private:
// ui::LayerDelegate overrides: // ui::LayerDelegate overrides:
void OnPaintLayer(const ui::PaintContext& context) override; void OnPaintLayer(const ui::PaintContext& context) override;
void DrawFocusRing(ui::PaintRecorder& recorder, cc::PaintFlags& flags);
void DrawDoubleFocusRing(ui::PaintRecorder& recorder, cc::PaintFlags& flags);
// The outline of the current focus ring. // The outline of the current focus ring.
AccessibilityFocusRing ring_; AccessibilityFocusRing ring_;
// The secondary color, if there is a double focus ring.
base::Optional<SkColor> secondary_color_;
DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingLayer); DISALLOW_COPY_AND_ASSIGN(AccessibilityFocusRingLayer);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment