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

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

Issue 557393003: Introduce AccessibilityFocusRing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accessibility_private_histograms
Patch Set: Address feedback Created 6 years, 3 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 11
12 namespace chromeos { 12 namespace chromeos {
13 13
14 namespace { 14 namespace {
15 15
16 const int kShadowRadius = 10; 16 const int kShadowRadius = 10;
17 const int kShadowAlpha = 90; 17 const int kShadowAlpha = 90;
18 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); 18 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254);
19 19
20 } // namespace 20 } // namespace
21 21
22 FocusRingLayerDelegate::~FocusRingLayerDelegate() {} 22 FocusRingLayerDelegate::~FocusRingLayerDelegate() {}
23 23
24 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate) 24 FocusRingLayer::FocusRingLayer(FocusRingLayerDelegate* delegate)
25 : delegate_(delegate), 25 : root_window_(NULL),
26 root_window_(NULL) { 26 delegate_(delegate) {
27 } 27 }
28 28
29 FocusRingLayer::~FocusRingLayer() {} 29 FocusRingLayer::~FocusRingLayer() {}
30 30
31 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { 31 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) {
32 focus_ring_ = bounds; 32 focus_ring_ = bounds;
33 CreateOrUpdateLayer(root_window, "FocusRing");
34
35 // Update the layer bounds.
36 gfx::Rect layer_bounds = bounds;
37 int inset = -(kShadowRadius + 2);
38 layer_bounds.Inset(inset, inset, inset, inset);
39 layer_->SetBounds(layer_bounds);
40 }
41
42 void FocusRingLayer::CreateOrUpdateLayer(
43 aura::Window* root_window, const char* layer_name) {
33 if (!layer_ || root_window != root_window_) { 44 if (!layer_ || root_window != root_window_) {
34 root_window_ = root_window; 45 root_window_ = root_window;
35 ui::Layer* root_layer = root_window->layer(); 46 ui::Layer* root_layer = root_window->layer();
36 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); 47 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
37 layer_->set_name("FocusRing"); 48 layer_->set_name(layer_name);
38 layer_->set_delegate(this); 49 layer_->set_delegate(this);
39 layer_->SetFillsBoundsOpaquely(false); 50 layer_->SetFillsBoundsOpaquely(false);
40 root_layer->Add(layer_.get()); 51 root_layer->Add(layer_.get());
41 } 52 }
42 53
43 // Keep moving it to the top in case new layers have been added 54 // Keep moving it to the top in case new layers have been added
44 // since we created this layer. 55 // since we created this layer.
45 layer_->parent()->StackAtTop(layer_.get()); 56 layer_->parent()->StackAtTop(layer_.get());
46
47 // Update the layer bounds.
48 gfx::Rect layer_bounds = bounds;
49 int inset = -(kShadowRadius + 2);
50 layer_bounds.Inset(inset, inset, inset, inset);
51 layer_->SetBounds(layer_bounds);
52 } 57 }
53 58
54 void FocusRingLayer::OnPaintLayer(gfx::Canvas* canvas) { 59 void FocusRingLayer::OnPaintLayer(gfx::Canvas* canvas) {
55 if (!root_window_ || focus_ring_.IsEmpty()) 60 if (!root_window_ || focus_ring_.IsEmpty())
56 return; 61 return;
57 62
58 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); 63 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin();
59 SkPaint paint; 64 SkPaint paint;
60 paint.setColor(kShadowColor); 65 paint.setColor(kShadowColor);
61 paint.setFlags(SkPaint::kAntiAlias_Flag); 66 paint.setFlags(SkPaint::kAntiAlias_Flag);
(...skipping 16 matching lines...) Expand all
78 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) { 83 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) {
79 if (delegate_) 84 if (delegate_)
80 delegate_->OnDeviceScaleFactorChanged(); 85 delegate_->OnDeviceScaleFactorChanged();
81 } 86 }
82 87
83 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() { 88 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() {
84 return base::Bind(&base::DoNothing); 89 return base::Bind(&base::DoNothing);
85 } 90 }
86 91
87 } // namespace chromeos 92 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698