Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/chromeos/ui/focus_ring_layer.cc

Issue 2789583004: Add a color argument to accessibilityPrivate.setFocusRing (Closed)
Patch Set: Address feedback Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome/browser/chromeos/ui/focus_ring_layer.h" 5 #include "chrome/browser/chromeos/ui/focus_ring_layer.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/compositor/compositor_animation_observer.h" 8 #include "ui/compositor/compositor_animation_observer.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/paint_recorder.h" 10 #include "ui/compositor/paint_recorder.h"
(...skipping 11 matching lines...) Expand all
22 22
23 const int kShadowRadius = 10; 23 const int kShadowRadius = 10;
24 const int kShadowAlpha = 90; 24 const int kShadowAlpha = 90;
25 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); 25 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254);
26 26
27 } // namespace 27 } // namespace
28 28
29 FocusRingLayerDelegate::~FocusRingLayerDelegate() {} 29 FocusRingLayerDelegate::~FocusRingLayerDelegate() {}
30 30
31 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate) 31 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate)
32 : delegate_(delegate), root_window_(nullptr), compositor_(nullptr) {} 32 : delegate_(delegate) {}
33 33
34 FocusRingLayer::~FocusRingLayer() { 34 FocusRingLayer::~FocusRingLayer() {
35 if (compositor_ && compositor_->HasAnimationObserver(this)) 35 if (compositor_ && compositor_->HasAnimationObserver(this))
36 compositor_->RemoveAnimationObserver(this); 36 compositor_->RemoveAnimationObserver(this);
37 } 37 }
38 38
39 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { 39 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) {
40 focus_ring_ = bounds; 40 focus_ring_ = bounds;
41 gfx::Rect layer_bounds = bounds; 41 gfx::Rect layer_bounds = bounds;
42 int inset = -(kShadowRadius + 2); 42 int inset = -(kShadowRadius + 2);
43 layer_bounds.Inset(inset, inset, inset, inset); 43 layer_bounds.Inset(inset, inset, inset, inset);
44 CreateOrUpdateLayer(root_window, "FocusRing", layer_bounds); 44 CreateOrUpdateLayer(root_window, "FocusRing", layer_bounds);
45 } 45 }
46 46
47 bool FocusRingLayer::CanAnimate() const { 47 bool FocusRingLayer::CanAnimate() const {
48 return compositor_ && compositor_->HasAnimationObserver(this); 48 return compositor_ && compositor_->HasAnimationObserver(this);
49 } 49 }
50 50
51 void FocusRingLayer::SetOpacity(float opacity) { 51 void FocusRingLayer::SetOpacity(float opacity) {
52 layer()->SetOpacity(opacity); 52 layer()->SetOpacity(opacity);
53 } 53 }
54 54
55 void FocusRingLayer::SetColor(SkColor color) {
56 has_custom_color_ = true;
57 custom_color_ = color;
58 }
59
60 void FocusRingLayer::ResetColor() {
61 has_custom_color_ = false;
62 }
63
55 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window, 64 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window,
56 const char* layer_name, 65 const char* layer_name,
57 const gfx::Rect& bounds) { 66 const gfx::Rect& bounds) {
58 if (!layer_ || root_window != root_window_) { 67 if (!layer_ || root_window != root_window_) {
59 root_window_ = root_window; 68 root_window_ = root_window;
60 ui::Layer* root_layer = root_window->layer(); 69 ui::Layer* root_layer = root_window->layer();
61 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); 70 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
62 layer_->set_name(layer_name); 71 layer_->set_name(layer_name);
63 layer_->set_delegate(this); 72 layer_->set_delegate(this);
64 layer_->SetFillsBoundsOpaquely(false); 73 layer_->SetFillsBoundsOpaquely(false);
(...skipping 20 matching lines...) Expand all
85 } 94 }
86 95
87 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { 96 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) {
88 if (!root_window_ || focus_ring_.IsEmpty()) 97 if (!root_window_ || focus_ring_.IsEmpty())
89 return; 98 return;
90 99
91 ui::PaintRecorder recorder(context, layer_->size()); 100 ui::PaintRecorder recorder(context, layer_->size());
92 101
93 cc::PaintFlags flags; 102 cc::PaintFlags flags;
94 flags.setAntiAlias(true); 103 flags.setAntiAlias(true);
95 flags.setColor(kShadowColor); 104 flags.setColor(has_custom_color_ ? custom_color_ : kShadowColor);
96 flags.setStyle(cc::PaintFlags::kStroke_Style); 105 flags.setStyle(cc::PaintFlags::kStroke_Style);
97 flags.setStrokeWidth(2); 106 flags.setStrokeWidth(2);
98 107
99 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); 108 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin();
100 int r = kShadowRadius; 109 int r = kShadowRadius;
101 for (int i = 0; i < r; i++) { 110 for (int i = 0; i < r; i++) {
102 // Fade out alpha quadratically. 111 // Fade out alpha quadratically.
103 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); 112 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r));
104 gfx::Rect outsetRect = bounds; 113 gfx::Rect outsetRect = bounds;
105 outsetRect.Inset(-i, -i, -i, -i); 114 outsetRect.Inset(-i, -i, -i, -i);
(...skipping 15 matching lines...) Expand all
121 } 130 }
122 131
123 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) { 132 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) {
124 if (compositor == compositor_) { 133 if (compositor == compositor_) {
125 compositor->RemoveAnimationObserver(this); 134 compositor->RemoveAnimationObserver(this);
126 compositor_ = nullptr; 135 compositor_ = nullptr;
127 } 136 }
128 } 137 }
129 138
130 } // namespace chromeos 139 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698