OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/accessibility_cursor_ring_layer.h" | 5 #include "chrome/browser/chromeos/ui/accessibility_cursor_ring_layer.h" |
6 | 6 |
7 #include "ash/shell_port.h" | 7 #include "ash/shell_port.h" |
8 #include "ash/wm_window.h" | 8 #include "ash/wm_window.h" |
9 #include "third_party/skia/include/core/SkPaint.h" | 9 #include "third_party/skia/include/core/SkPaint.h" |
10 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
13 #include "ui/compositor/paint_recorder.h" | 13 #include "ui/compositor/paint_recorder.h" |
14 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
15 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/wm/core/coordinate_conversion.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // The number of pixels in the color gradient that fades to transparent. | 23 // The number of pixels in the color gradient that fades to transparent. |
23 const int kGradientWidth = 8; | 24 const int kGradientWidth = 8; |
24 | 25 |
25 // The radius of the ring in pixels. | 26 // The radius of the ring in pixels. |
26 const int kCursorRingRadius = 24; | 27 const int kCursorRingRadius = 24; |
(...skipping 14 matching lines...) Expand all Loading... |
41 | 42 |
42 void AccessibilityCursorRingLayer::Set(const gfx::Point& location) { | 43 void AccessibilityCursorRingLayer::Set(const gfx::Point& location) { |
43 location_ = location; | 44 location_ = location; |
44 | 45 |
45 gfx::Rect bounds = gfx::Rect(location.x(), location.y(), 0, 0); | 46 gfx::Rect bounds = gfx::Rect(location.x(), location.y(), 0, 0); |
46 int inset = kGradientWidth + kCursorRingRadius + kLayerMargin; | 47 int inset = kGradientWidth + kCursorRingRadius + kLayerMargin; |
47 bounds.Inset(-inset, -inset, -inset, -inset); | 48 bounds.Inset(-inset, -inset, -inset, -inset); |
48 | 49 |
49 display::Display display = | 50 display::Display display = |
50 display::Screen::GetScreen()->GetDisplayMatching(bounds); | 51 display::Screen::GetScreen()->GetDisplayMatching(bounds); |
51 ash::WmWindow* root_wm_window = | 52 aura::Window* root_window = |
52 ash::ShellPort::Get()->GetRootWindowForDisplayId(display.id()); | 53 ash::ShellPort::Get()->GetRootWindowForDisplayId(display.id()); |
53 aura::Window* root_window = root_wm_window->aura_window(); | 54 ::wm::ConvertRectFromScreen(root_window, &bounds); |
54 bounds = root_wm_window->ConvertRectFromScreen(bounds); | |
55 CreateOrUpdateLayer(root_window, "AccessibilityCursorRing", bounds); | 55 CreateOrUpdateLayer(root_window, "AccessibilityCursorRing", bounds); |
56 } | 56 } |
57 | 57 |
58 void AccessibilityCursorRingLayer::OnPaintLayer( | 58 void AccessibilityCursorRingLayer::OnPaintLayer( |
59 const ui::PaintContext& context) { | 59 const ui::PaintContext& context) { |
60 ui::PaintRecorder recorder(context, layer()->size()); | 60 ui::PaintRecorder recorder(context, layer()->size()); |
61 | 61 |
62 cc::PaintFlags flags; | 62 cc::PaintFlags flags; |
63 flags.setAntiAlias(true); | 63 flags.setAntiAlias(true); |
64 flags.setStyle(cc::PaintFlags::kStroke_Style); | 64 flags.setStyle(cc::PaintFlags::kStroke_Style); |
65 flags.setStrokeWidth(2); | 65 flags.setStrokeWidth(2); |
66 | 66 |
67 gfx::Rect r = layer()->bounds(); | 67 gfx::Rect r = layer()->bounds(); |
68 r.Offset(-r.OffsetFromOrigin()); | 68 r.Offset(-r.OffsetFromOrigin()); |
69 r.Inset(kLayerMargin, kLayerMargin, kLayerMargin, kLayerMargin); | 69 r.Inset(kLayerMargin, kLayerMargin, kLayerMargin, kLayerMargin); |
70 const int w = kGradientWidth; | 70 const int w = kGradientWidth; |
71 for (int i = 0; i < w; ++i) { | 71 for (int i = 0; i < w; ++i) { |
72 flags.setColor( | 72 flags.setColor( |
73 SkColorSetARGBMacro(255 * (i) * (i) / (w * w), red_, green_, blue_)); | 73 SkColorSetARGBMacro(255 * (i) * (i) / (w * w), red_, green_, blue_)); |
74 SkPath path; | 74 SkPath path; |
75 path.addOval(SkRect::MakeXYWH(r.x(), r.y(), r.width(), r.height())); | 75 path.addOval(SkRect::MakeXYWH(r.x(), r.y(), r.width(), r.height())); |
76 r.Inset(1, 1, 1, 1); | 76 r.Inset(1, 1, 1, 1); |
77 recorder.canvas()->DrawPath(path, flags); | 77 recorder.canvas()->DrawPath(path, flags); |
78 } | 78 } |
79 } | 79 } |
80 | 80 |
81 } // namespace chromeos | 81 } // namespace chromeos |
OLD | NEW |