| 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 "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/compositor/paint_context.h" | 10 #include "ui/compositor/paint_recorder.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int kShadowRadius = 10; | 17 const int kShadowRadius = 10; |
| 18 const int kShadowAlpha = 90; | 18 const int kShadowAlpha = 90; |
| 19 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); | 19 const SkColor kShadowColor = SkColorSetRGB(77, 144, 254); |
| 20 | 20 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Keep moving it to the top in case new layers have been added | 55 // Keep moving it to the top in case new layers have been added |
| 56 // since we created this layer. | 56 // since we created this layer. |
| 57 layer_->parent()->StackAtTop(layer_.get()); | 57 layer_->parent()->StackAtTop(layer_.get()); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { | 60 void FocusRingLayer::OnPaintLayer(const ui::PaintContext& context) { |
| 61 if (!root_window_ || focus_ring_.IsEmpty()) | 61 if (!root_window_ || focus_ring_.IsEmpty()) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 gfx::Canvas* canvas = context.canvas(); | 64 ui::PaintRecorder recorder(context); |
| 65 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); | 65 |
| 66 SkPaint paint; | 66 SkPaint paint; |
| 67 paint.setColor(kShadowColor); | 67 paint.setColor(kShadowColor); |
| 68 paint.setFlags(SkPaint::kAntiAlias_Flag); | 68 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 69 paint.setStyle(SkPaint::kStroke_Style); | 69 paint.setStyle(SkPaint::kStroke_Style); |
| 70 paint.setStrokeWidth(2); | 70 paint.setStrokeWidth(2); |
| 71 |
| 72 gfx::Rect bounds = focus_ring_ - layer_->bounds().OffsetFromOrigin(); |
| 71 int r = kShadowRadius; | 73 int r = kShadowRadius; |
| 72 for (int i = 0; i < r; i++) { | 74 for (int i = 0; i < r; i++) { |
| 73 // Fade out alpha quadratically. | 75 // Fade out alpha quadratically. |
| 74 paint.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); | 76 paint.setAlpha((kShadowAlpha * (r - i) * (r - i)) / (r * r)); |
| 75 gfx::Rect outsetRect = bounds; | 77 gfx::Rect outsetRect = bounds; |
| 76 outsetRect.Inset(-i, -i, -i, -i); | 78 outsetRect.Inset(-i, -i, -i, -i); |
| 77 canvas->DrawRect(outsetRect, paint); | 79 recorder.canvas()->DrawRect(outsetRect, paint); |
| 78 } | 80 } |
| 79 } | 81 } |
| 80 | 82 |
| 81 void FocusRingLayer::OnDelegatedFrameDamage( | 83 void FocusRingLayer::OnDelegatedFrameDamage( |
| 82 const gfx::Rect& damage_rect_in_dip) { | 84 const gfx::Rect& damage_rect_in_dip) { |
| 83 } | 85 } |
| 84 | 86 |
| 85 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) { | 87 void FocusRingLayer::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 86 if (delegate_) | 88 if (delegate_) |
| 87 delegate_->OnDeviceScaleFactorChanged(); | 89 delegate_->OnDeviceScaleFactorChanged(); |
| 88 } | 90 } |
| 89 | 91 |
| 90 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() { | 92 base::Closure FocusRingLayer::PrepareForLayerBoundsChange() { |
| 91 return base::Bind(&base::DoNothing); | 93 return base::Bind(&base::DoNothing); |
| 92 } | 94 } |
| 93 | 95 |
| 94 } // namespace chromeos | 96 } // namespace chromeos |
| OLD | NEW |