OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_focus_ring_layer.h" | 5 #include "chrome/browser/chromeos/ui/accessibility_focus_ring_layer.h" |
6 | 6 |
7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
| 12 #include "ui/compositor/paint_context.h" |
12 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
13 | 14 |
14 namespace chromeos { | 15 namespace chromeos { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // The number of pixels in the color gradient that fades to transparent. | 19 // The number of pixels in the color gradient that fades to transparent. |
19 const int kGradientWidth = 6; | 20 const int kGradientWidth = 6; |
20 | 21 |
21 // The color of the focus ring. In the future this might be a parameter. | 22 // The color of the focus ring. In the future this might be a parameter. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 gfx::Display display = | 103 gfx::Display display = |
103 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds); | 104 gfx::Screen::GetNativeScreen()->GetDisplayMatching(bounds); |
104 aura::Window* root_window = ash::Shell::GetInstance()->display_controller() | 105 aura::Window* root_window = ash::Shell::GetInstance()->display_controller() |
105 ->GetRootWindowForDisplayId(display.id()); | 106 ->GetRootWindowForDisplayId(display.id()); |
106 CreateOrUpdateLayer(root_window, "AccessibilityFocusRing"); | 107 CreateOrUpdateLayer(root_window, "AccessibilityFocusRing"); |
107 | 108 |
108 // Update the layer bounds. | 109 // Update the layer bounds. |
109 layer()->SetBounds(bounds); | 110 layer()->SetBounds(bounds); |
110 } | 111 } |
111 | 112 |
112 void AccessibilityFocusRingLayer::OnPaintLayer(gfx::Canvas* canvas) { | 113 void AccessibilityFocusRingLayer::OnPaintLayer( |
| 114 const ui::PaintContext& context) { |
113 gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin(); | 115 gfx::Vector2d offset = layer()->bounds().OffsetFromOrigin(); |
114 | 116 |
115 SkPaint paint; | 117 SkPaint paint; |
116 paint.setFlags(SkPaint::kAntiAlias_Flag); | 118 paint.setFlags(SkPaint::kAntiAlias_Flag); |
117 paint.setStyle(SkPaint::kStroke_Style); | 119 paint.setStyle(SkPaint::kStroke_Style); |
118 paint.setStrokeWidth(2); | 120 paint.setStrokeWidth(2); |
119 | 121 |
| 122 gfx::Canvas* canvas = context.canvas(); |
| 123 |
120 SkPath path; | 124 SkPath path; |
121 const int w = kGradientWidth; | 125 const int w = kGradientWidth; |
122 for (int i = 0; i < w; ++i) { | 126 for (int i = 0; i < w; ++i) { |
123 paint.setColor( | 127 paint.setColor( |
124 SkColorSetARGBMacro( | 128 SkColorSetARGBMacro( |
125 255 * (w - i) * (w - i) / (w * w), | 129 255 * (w - i) * (w - i) / (w * w), |
126 kFocusRingColorRed, kFocusRingColorGreen, kFocusRingColorBlue)); | 130 kFocusRingColorRed, kFocusRingColorGreen, kFocusRingColorBlue)); |
127 path = MakePath(ring_, i, offset); | 131 path = MakePath(ring_, i, offset); |
128 canvas->DrawPath(path, paint); | 132 canvas->DrawPath(path, paint); |
129 } | 133 } |
130 } | 134 } |
131 | 135 |
132 } // namespace chromeos | 136 } // namespace chromeos |
OLD | NEW |