OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" |
| 6 |
| 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/shell.h" |
| 9 #include "base/bind.h" |
| 10 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "third_party/skia/include/core/SkPath.h" |
| 12 #include "ui/aura/window.h" |
| 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/compositor/paint_recorder.h" |
| 15 #include "ui/gfx/canvas.h" |
| 16 |
| 17 namespace chromeos { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // The number of pixels in the color gradient that fades to transparent. |
| 22 const int kGradientWidth = 8; |
| 23 |
| 24 // The radius of the ring in pixels. |
| 25 const int kCursorRingRadius = 24; |
| 26 |
| 27 // Extra margin to add to the layer in pixels. |
| 28 const int kLayerMargin = 8; |
| 29 |
| 30 } // namespace |
| 31 |
| 32 AccessibilityCursorRingLayer::AccessibilityCursorRingLayer( |
| 33 FocusRingLayerDelegate* delegate, |
| 34 int red, |
| 35 int green, |
| 36 int blue) |
| 37 : FocusRingLayer(delegate), red_(red), green_(green), blue_(blue) {} |
| 38 |
| 39 AccessibilityCursorRingLayer::~AccessibilityCursorRingLayer() {} |
| 40 |
| 41 void AccessibilityCursorRingLayer::Set(const gfx::Point& location) { |
| 42 location_ = location; |
| 43 |
| 44 gfx::Rect bounds = gfx::Rect(location.x(), location.y(), 0, 0); |
| 45 int inset = kGradientWidth + kCursorRingRadius + kLayerMargin; |
| 46 bounds.Inset(-inset, -inset, -inset, -inset); |
| 47 |
| 48 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayMatching(bounds); |
| 49 aura::Window* root_window = ash::Shell::GetInstance() |
| 50 ->window_tree_host_manager() |
| 51 ->GetRootWindowForDisplayId(display.id()); |
| 52 CreateOrUpdateLayer(root_window, "AccessibilityCursorRing"); |
| 53 |
| 54 // Update the layer bounds. |
| 55 layer()->SetBounds(bounds); |
| 56 } |
| 57 |
| 58 void AccessibilityCursorRingLayer::SetOpacity(float opacity) { |
| 59 layer()->SetOpacity(opacity); |
| 60 } |
| 61 |
| 62 void AccessibilityCursorRingLayer::OnPaintLayer( |
| 63 const ui::PaintContext& context) { |
| 64 ui::PaintRecorder recorder(context, layer()->size()); |
| 65 |
| 66 SkPaint paint; |
| 67 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 68 paint.setStyle(SkPaint::kStroke_Style); |
| 69 paint.setStrokeWidth(2); |
| 70 |
| 71 gfx::Rect r = layer()->bounds(); |
| 72 r.Offset(-r.OffsetFromOrigin()); |
| 73 r.Inset(kLayerMargin, kLayerMargin, kLayerMargin, kLayerMargin); |
| 74 const int w = kGradientWidth; |
| 75 for (int i = 0; i < w; ++i) { |
| 76 paint.setColor( |
| 77 SkColorSetARGBMacro(255 * (i) * (i) / (w * w), red_, green_, blue_)); |
| 78 SkPath path; |
| 79 path.addOval(SkRect::MakeXYWH(r.x(), r.y(), r.width(), r.height())); |
| 80 r.Inset(1, 1, 1, 1); |
| 81 recorder.canvas()->DrawPath(path, paint); |
| 82 } |
| 83 } |
| 84 |
| 85 } // namespace chromeos |
OLD | NEW |