forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint_scan_layer.cc
94 lines (78 loc) · 2.41 KB
/
point_scan_layer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accessibility/point_scan_layer.h"
#include "ash/shell.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
namespace {
const int kDefaultStrokeWidth = 6;
display::Display GetPrimaryDisplay() {
DCHECK(display::Screen::GetScreen());
return display::Screen::GetScreen()->GetPrimaryDisplay();
}
} // namespace
PointScanLayer::PointScanLayer(AccessibilityLayerDelegate* delegate)
: AccessibilityLayer(delegate) {
aura::Window* root_window =
Shell::GetRootWindowForDisplayId(GetPrimaryDisplay().id());
CreateOrUpdateLayer(root_window, "PointScanning", gfx::Rect());
SetOpacity(1.0);
bounds_ = GetPrimaryDisplay().bounds();
layer()->SetBounds(bounds_);
}
void PointScanLayer::StartHorizontalScanning() {
gfx::Point end = bounds_.bottom_left();
bounds_.set_origin(line_.start);
line_.end = end;
is_moving_ = true;
}
void PointScanLayer::PauseHorizontalScanning() {
is_moving_ = false;
}
void PointScanLayer::StartVerticalScanning() {
gfx::Point end = bounds_.top_right();
bounds_.set_origin(line_.start);
line_.end = end;
is_moving_ = true;
}
void PointScanLayer::PauseVerticalScanning() {
is_moving_ = false;
}
gfx::Rect PointScanLayer::GetBounds() const {
return bounds_;
}
bool PointScanLayer::IsMoving() const {
return is_moving_;
}
bool PointScanLayer::CanAnimate() const {
return true;
}
bool PointScanLayer::NeedToAnimate() const {
return true;
}
int PointScanLayer::GetInset() const {
return 0;
}
void PointScanLayer::OnPaintLayer(const ui::PaintContext& context) {
ui::PaintRecorder recorder(context, layer()->size());
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setStyle(cc::PaintFlags::kStroke_Style);
flags.setStrokeWidth(kDefaultStrokeWidth);
flags.setColor(gfx::kGoogleBlue300);
SkPath path;
path.moveTo(line_.start.x(), line_.start.y());
path.lineTo(line_.end.x(), line_.end.y());
recorder.canvas()->DrawPath(path, flags);
}
} // namespace ash