Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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), root_window_(nullptr), |
| 33 has_custom_color_(false), custom_color_(SK_ColorBLACK), | |
| 34 compositor_(nullptr) {} | |
|
xiyuan
2017/03/30 21:27:38
nit: move initialization to header since you are h
dmazzoni
2017/03/30 21:34:52
Done.
| |
| 33 | 35 |
| 34 FocusRingLayer::~FocusRingLayer() { | 36 FocusRingLayer::~FocusRingLayer() { |
| 35 if (compositor_ && compositor_->HasAnimationObserver(this)) | 37 if (compositor_ && compositor_->HasAnimationObserver(this)) |
| 36 compositor_->RemoveAnimationObserver(this); | 38 compositor_->RemoveAnimationObserver(this); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { | 41 void FocusRingLayer::Set(aura::Window* root_window, const gfx::Rect& bounds) { |
| 40 focus_ring_ = bounds; | 42 focus_ring_ = bounds; |
| 41 gfx::Rect layer_bounds = bounds; | 43 gfx::Rect layer_bounds = bounds; |
| 42 int inset = -(kShadowRadius + 2); | 44 int inset = -(kShadowRadius + 2); |
| 43 layer_bounds.Inset(inset, inset, inset, inset); | 45 layer_bounds.Inset(inset, inset, inset, inset); |
| 44 CreateOrUpdateLayer(root_window, "FocusRing", layer_bounds); | 46 CreateOrUpdateLayer(root_window, "FocusRing", layer_bounds); |
| 45 } | 47 } |
| 46 | 48 |
| 47 bool FocusRingLayer::CanAnimate() const { | 49 bool FocusRingLayer::CanAnimate() const { |
| 48 return compositor_ && compositor_->HasAnimationObserver(this); | 50 return compositor_ && compositor_->HasAnimationObserver(this); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void FocusRingLayer::SetOpacity(float opacity) { | 53 void FocusRingLayer::SetOpacity(float opacity) { |
| 52 layer()->SetOpacity(opacity); | 54 layer()->SetOpacity(opacity); |
| 53 } | 55 } |
| 54 | 56 |
| 57 void FocusRingLayer::SetColor(SkColor color) { | |
| 58 has_custom_color_ = true; | |
| 59 custom_color_ = color; | |
| 60 } | |
| 61 | |
| 62 void FocusRingLayer::ResetColor() { | |
| 63 has_custom_color_ = false; | |
| 64 } | |
| 65 | |
| 55 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window, | 66 void FocusRingLayer::CreateOrUpdateLayer(aura::Window* root_window, |
| 56 const char* layer_name, | 67 const char* layer_name, |
| 57 const gfx::Rect& bounds) { | 68 const gfx::Rect& bounds) { |
| 58 if (!layer_ || root_window != root_window_) { | 69 if (!layer_ || root_window != root_window_) { |
| 59 root_window_ = root_window; | 70 root_window_ = root_window; |
| 60 ui::Layer* root_layer = root_window->layer(); | 71 ui::Layer* root_layer = root_window->layer(); |
| 61 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | 72 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
| 62 layer_->set_name(layer_name); | 73 layer_->set_name(layer_name); |
| 63 layer_->set_delegate(this); | 74 layer_->set_delegate(this); |
| 64 layer_->SetFillsBoundsOpaquely(false); | 75 layer_->SetFillsBoundsOpaquely(false); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 85 } | 96 } |
| 86 | 97 |
| 87 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { | 98 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { |
| 88 if (!root_window_ || focus_ring_.IsEmpty()) | 99 if (!root_window_ || focus_ring_.IsEmpty()) |
| 89 return; | 100 return; |
| 90 | 101 |
| 91 ui::PaintRecorder recorder(context, layer_->size()); | 102 ui::PaintRecorder recorder(context, layer_->size()); |
| 92 | 103 |
| 93 cc::PaintFlags flags; | 104 cc::PaintFlags flags; |
| 94 flags.setAntiAlias(true); | 105 flags.setAntiAlias(true); |
| 95 flags.setColor(kShadowColor); | 106 flags.setColor(has_custom_color_ ? custom_color_ : kShadowColor); |
| 96 flags.setStyle(cc::PaintFlags::kStroke_Style); | 107 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 97 flags.setStrokeWidth(2); | 108 flags.setStrokeWidth(2); |
| 98 | 109 |
| 99 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); | 110 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); |
| 100 int r = kShadowRadius; | 111 int r = kShadowRadius; |
| 101 for (int i = 0; i < r; i++) { | 112 for (int i = 0; i < r; i++) { |
| 102 // Fade out alpha quadratically. | 113 // Fade out alpha quadratically. |
| 103 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); | 114 flags.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); |
| 104 gfx::Rect outsetRect = bounds; | 115 gfx::Rect outsetRect = bounds; |
| 105 outsetRect.Inset(-i, -i, -i, -i); | 116 outsetRect.Inset(-i, -i, -i, -i); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 121 } | 132 } |
| 122 | 133 |
| 123 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) { | 134 void FocusRingLayer::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| 124 if (compositor == compositor_) { | 135 if (compositor == compositor_) { |
| 125 compositor->RemoveAnimationObserver(this); | 136 compositor->RemoveAnimationObserver(this); |
| 126 compositor_ = nullptr; | 137 compositor_ = nullptr; |
| 127 } | 138 } |
| 128 } | 139 } |
| 129 | 140 |
| 130 } // namespace chromeos | 141 } // namespace chromeos |
| OLD | NEW |