1 // Copyright 2020 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 "ash/accessibility/point_scan_layer.h" 6 7 #include "ash/shell.h" 8 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPath.h" 10 #include "ui/aura/window.h" 11 #include "ui/compositor/layer.h" 12 #include "ui/compositor/paint_recorder.h" 13 #include "ui/display/display.h" 14 #include "ui/display/screen.h" 15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/color_palette.h" 17 #include "ui/wm/core/coordinate_conversion.h" 18 19 namespace ash { 20 21 namespace { 22 const int kDefaultStrokeWidth = 6; 23 GetPrimaryDisplay()24display::Display GetPrimaryDisplay() { 25 DCHECK(display::Screen::GetScreen()); 26 return display::Screen::GetScreen()->GetPrimaryDisplay(); 27 } 28 } // namespace 29 PointScanLayer(AccessibilityLayerDelegate * delegate)30PointScanLayer::PointScanLayer(AccessibilityLayerDelegate* delegate) 31 : AccessibilityLayer(delegate) { 32 aura::Window* root_window = 33 Shell::GetRootWindowForDisplayId(GetPrimaryDisplay().id()); 34 CreateOrUpdateLayer(root_window, "PointScanning", gfx::Rect()); 35 SetOpacity(1.0); 36 bounds_ = GetPrimaryDisplay().bounds(); 37 layer()->SetBounds(bounds_); 38 } 39 StartHorizontalScanning()40void PointScanLayer::StartHorizontalScanning() { 41 gfx::Point end = bounds_.bottom_left(); 42 bounds_.set_origin(line_.start); 43 line_.end = end; 44 is_moving_ = true; 45 } 46 PauseHorizontalScanning()47void PointScanLayer::PauseHorizontalScanning() { 48 is_moving_ = false; 49 } 50 StartVerticalScanning()51void PointScanLayer::StartVerticalScanning() { 52 gfx::Point end = bounds_.top_right(); 53 bounds_.set_origin(line_.start); 54 line_.end = end; 55 is_moving_ = true; 56 } 57 PauseVerticalScanning()58void PointScanLayer::PauseVerticalScanning() { 59 is_moving_ = false; 60 } 61 GetBounds() const62gfx::Rect PointScanLayer::GetBounds() const { 63 return bounds_; 64 } 65 IsMoving() const66bool PointScanLayer::IsMoving() const { 67 return is_moving_; 68 } 69 CanAnimate() const70bool PointScanLayer::CanAnimate() const { 71 return true; 72 } NeedToAnimate() const73bool PointScanLayer::NeedToAnimate() const { 74 return true; 75 } GetInset() const76int PointScanLayer::GetInset() const { 77 return 0; 78 } 79 OnPaintLayer(const ui::PaintContext & context)80void PointScanLayer::OnPaintLayer(const ui::PaintContext& context) { 81 ui::PaintRecorder recorder(context, layer()->size()); 82 cc::PaintFlags flags; 83 flags.setAntiAlias(true); 84 flags.setStyle(cc::PaintFlags::kStroke_Style); 85 flags.setStrokeWidth(kDefaultStrokeWidth); 86 flags.setColor(gfx::kGoogleBlue300); 87 88 SkPath path; 89 path.moveTo(line_.start.x(), line_.start.y()); 90 path.lineTo(line_.end.x(), line_.end.y()); 91 recorder.canvas()->DrawPath(path, flags); 92 } 93 94 } // namespace ash 95