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

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

Issue 2038093003: Refactor accessible focus ring code so the layers are animation observers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@improve_highlights
Patch Set: Created 4 years, 6 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
« no previous file with comments | « chrome/browser/chromeos/ui/focus_ring_layer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/compositor/compositor_animation_observer.h"
9 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
10 #include "ui/compositor/paint_recorder.h" 11 #include "ui/compositor/paint_recorder.h"
12 #include "ui/display/display.h"
13 #include "ui/display/screen.h"
11 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
12 15
16 namespace ui {
17 class Compositor;
18 }
19
13 namespace chromeos { 20 namespace chromeos {
14 21
15 namespace { 22 namespace {
16 23
17 const int kShadowRadius = 10; 24 const int kShadowRadius = 10;
18 const int kShadowAlpha = 90; 25 const int kShadowAlpha = 90;
19 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); 26 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254);
20 27
21 } // namespace 28 } // namespace
22 29
23 FocusRingLayerDelegate::~FocusRingLayerDelegate() {} 30 FocusRingLayerDelegate::~FocusRingLayerDelegate() {}
24 31
25 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate) 32 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate)
26 : delegate_(delegate), 33 : delegate_(delegate), root_window_(nullptr), compositor_(nullptr) {}
27 root_window_(NULL) { 34
35 FocusRingLayer::~FocusRingLayer() {
36 if (compositor_ && compositor_->HasAnimationObserver(this))
37 compositor_->RemoveAnimationObserver(this);
28 } 38 }
29 39
30 FocusRingLayer::~FocusRingLayer() {}
31
32 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { 40 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) {
33 focus_ring_ = bounds; 41 focus_ring_ = bounds;
34 CreateOrUpdateLayer(root_window, "FocusRing");
35
36 // Update the layer bounds.
37 gfx::Rect layer_bounds = bounds; 42 gfx::Rect layer_bounds = bounds;
38 int inset = -(kShadowRadius + 2); 43 int inset = -(kShadowRadius + 2);
39 layer_bounds.Inset(inset, inset, inset, inset); 44 layer_bounds.Inset(inset, inset, inset, inset);
40 layer_->SetBounds(layer_bounds); 45 CreateOrUpdateLayer(root_window, "FocusRing", layer_bounds);
41 } 46 }
42 47
43 void FocusRingLayer::CreateOrUpdateLayer( 48 bool FocusRingLayer::CanAnimate() const {
44 aura::Window* root_window, const char* layer_name) { 49 return compositor_ && compositor_->HasAnimationObserver(this);
50 }
51
52 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window,
53 const char* layer_name,
54 const gfx::Rect& bounds) {
45 if (!layer_ || root_window != root_window_) { 55 if (!layer_ || root_window != root_window_) {
46 root_window_ = root_window; 56 root_window_ = root_window;
47 ui::Layer* root_layer = root_window->layer(); 57 ui::Layer* root_layer = root_window->layer();
48 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); 58 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
49 layer_->set_name(layer_name); 59 layer_->set_name(layer_name);
50 layer_->set_delegate(this); 60 layer_->set_delegate(this);
51 layer_->SetFillsBoundsOpaquely(false); 61 layer_->SetFillsBoundsOpaquely(false);
52 root_layer->Add(layer_.get()); 62 root_layer->Add(layer_.get());
53 } 63 }
54 64
55 // Keep moving it to the top in case new layers have been added 65 // Keep moving it to the top in case new layers have been added
56 // since we created this layer. 66 // since we created this layer.
57 layer_->parent()->StackAtTop(layer_.get()); 67 layer_->parent()->StackAtTop(layer_.get());
68
69 layer_->SetBounds(bounds);
70
71 // Update the animation observer.
72 display::Display display =
73 display::Screen::GetScreen()->GetDisplayMatching(bounds);
74 ui::Compositor* compositor = root_window->layer()->GetCompositor();
75 if (compositor != compositor_) {
76 if (compositor_ && compositor_->HasAnimationObserver(this))
77 compositor_->RemoveAnimationObserver(this);
78 compositor_ = compositor;
79 if (compositor_ && !compositor_->HasAnimationObserver(this))
80 compositor_->AddAnimationObserver(this);
81 }
58 } 82 }
59 83
60 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { 84 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) {
61 if (!root_window_ || focus_ring_.IsEmpty()) 85 if (!root_window_ || focus_ring_.IsEmpty())
62 return; 86 return;
63 87
64 ui::PaintRecorder recorder(context, layer_->size()); 88 ui::PaintRecorder recorder(context, layer_->size());
65 89
66 SkPaint paint; 90 SkPaint paint;
67 paint.setColor(kShadowColor); 91 paint.setColor(kShadowColor);
(...skipping 18 matching lines...) Expand all
86 110
87 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) { 111 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) {
88 if (delegate_) 112 if (delegate_)
89 delegate_->OnDeviceScaleFactorChanged(); 113 delegate_->OnDeviceScaleFactorChanged();
90 } 114 }
91 115
92 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() { 116 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() {
93 return base::Bind(&base::DoNothing); 117 return base::Bind(&base::DoNothing);
94 } 118 }
95 119
120 void FocusRingLayer::OnAnimationStep(base::TimeTicks timestamp) {
121 delegate_->OnAnimationStep(timestamp);
122 }
123
124 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) {
125 if (compositor == compositor_) {
126 compositor->RemoveAnimationObserver(this);
127 compositor_ = nullptr;
128 }
129 }
130
96 } // namespace chromeos 131 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/ui/focus_ring_layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698