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

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

Issue 2789583004: Add a color argument to accessibilityPrivate.setFocusRing (Closed)
Patch Set: Rebase 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 custom_color_ = color;
57 }
58
59 void FocusRingLayer::ResetColor() {
60 custom_color_.reset();
61 }
62
55 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window, 63 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window,
56 const char* layer_name, 64 const char* layer_name,
57 const gfx::Rect& bounds) { 65 const gfx::Rect& bounds) {
58 if (!layer_ || root_window != root_window_) { 66 if (!layer_ || root_window != root_window_) {
59 root_window_ = root_window; 67 root_window_ = root_window;
60 ui::Layer* root_layer = root_window->layer(); 68 ui::Layer* root_layer = root_window->layer();
61 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); 69 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
62 layer_->set_name(layer_name); 70 layer_->set_name(layer_name);
63 layer_->set_delegate(this); 71 layer_->set_delegate(this);
64 layer_->SetFillsBoundsOpaquely(false); 72 layer_->SetFillsBoundsOpaquely(false);
(...skipping 20 matching lines...) Expand all
85 } 93 }
86 94
87 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { 95 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) {
88 if (!root_window_ || focus_ring_.IsEmpty()) 96 if (!root_window_ || focus_ring_.IsEmpty())
89 return; 97 return;
90 98
91 ui::PaintRecorder recorder(context, layer_->size()); 99 ui::PaintRecorder recorder(context, layer_->size());
92 100
93 cc::PaintFlags flags; 101 cc::PaintFlags flags;
94 flags.setAntiAlias(true); 102 flags.setAntiAlias(true);
95 flags.setColor(kShadowColor); 103 flags.setColor(custom_color_ ? *custom_color_ : kShadowColor);
96 flags.setStyle(cc::PaintFlags::kStroke_Style); 104 flags.setStyle(cc::PaintFlags::kStroke_Style);
97 flags.setStrokeWidth(2); 105 flags.setStrokeWidth(2);
98 106
99 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); 107 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin();
100 int r = kShadowRadius; 108 int r = kShadowRadius;
101 for (int i = 0; i < r; i++) { 109 for (int i = 0; i < r; i++) {
102 // Fade out alpha quadratically. 110 // Fade out alpha quadratically.
103 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); 111 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r));
104 gfx::Rect outsetRect = bounds; 112 gfx::Rect outsetRect = bounds;
105 outsetRect.Inset(-i, -i, -i, -i); 113 outsetRect.Inset(-i, -i, -i, -i);
(...skipping 15 matching lines...) Expand all
121 } 129 }
122 130
123 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) { 131 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) {
124 if (compositor == compositor_) { 132 if (compositor == compositor_) {
125 compositor->RemoveAnimationObserver(this); 133 compositor->RemoveAnimationObserver(this);
126 compositor_ = nullptr; 134 compositor_ = nullptr;
127 } 135 }
128 } 136 }
129 137
130 } // namespace chromeos 138 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/ui/focus_ring_layer.h ('k') | chrome/browser/resources/chromeos/select_to_speak/select_to_speak.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698