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
ash / wm / gestures / back_gesture / back_gesture_util.cc [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/gestures/back_gesture/back_gesture_util.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/highlight_border.h"
#include "ui/views/view.h"
namespace ash {
namespace {
constexpr float kOuterHightlightBorderThickness =
1.5 * views::kHighlightBorderThickness;
constexpr float kInnerHightlightBorderThickness =
views::kHighlightBorderThickness / 2.f;
SkColor GetHighlightBorderInnerColor(views::View* view) {
DCHECK(view);
return view->GetColorProvider()->GetColor(
ui::kColorHighlightBorderHighlight1);
}
SkColor GetHighlightBorderOuterColor(views::View* view) {
DCHECK(view);
return view->GetColorProvider()->GetColor(ui::kColorHighlightBorderBorder1);
}
cc::PaintFlags GetHighlightBorderPaintFlags() {
cc::PaintFlags hb_flags;
hb_flags.setStrokeWidth(views::kHighlightBorderThickness);
hb_flags.setStyle(cc::PaintFlags::kStroke_Style);
hb_flags.setAntiAlias(true);
return hb_flags;
}
} // namespace
void DrawCircleHighlightBorder(views::View* view,
gfx::Canvas* canvas,
const gfx::PointF& circle_center,
int radius) {
gfx::ScopedCanvas scoped_canvas(canvas);
// Scale bounds and corner radius with device scale factor to make sure
// border bounds match content bounds but keep border stroke width the same.
const float dsf = canvas->UndoDeviceScaleFactor();
const float scaled_corner_radius = dsf * radius;
gfx::PointF scaled_circle_center = circle_center;
scaled_circle_center.Scale(dsf);
cc::PaintFlags hb_flags = GetHighlightBorderPaintFlags();
hb_flags.setColor(GetHighlightBorderOuterColor(view));
canvas->DrawCircle(scaled_circle_center,
scaled_corner_radius + kOuterHightlightBorderThickness,
hb_flags);
hb_flags.setColor(GetHighlightBorderInnerColor(view));
canvas->DrawCircle(scaled_circle_center,
scaled_corner_radius + kInnerHightlightBorderThickness,
hb_flags);
}
void DrawRoundRectHighlightBorder(views::View* view,
gfx::Canvas* canvas,
const gfx::Rect& bounds,
int corner_radius) {
gfx::ScopedCanvas scoped_canvas(canvas);
const float dsf = canvas->UndoDeviceScaleFactor();
const float scaled_corner_radius = dsf * corner_radius;
auto scaled_outer_bounds = gfx::ScaleToEnclosingRect(bounds, dsf);
scaled_outer_bounds.Inset(-kOuterHightlightBorderThickness);
auto scaled_inner_bounds = gfx::ScaleToEnclosingRect(bounds, dsf);
scaled_inner_bounds.Inset(-kInnerHightlightBorderThickness);
cc::PaintFlags hb_flags = GetHighlightBorderPaintFlags();
hb_flags.setColor(GetHighlightBorderOuterColor(view));
canvas->DrawRoundRect(scaled_outer_bounds,
scaled_corner_radius + kOuterHightlightBorderThickness,
hb_flags);
hb_flags.setColor(GetHighlightBorderInnerColor(view));
canvas->DrawRoundRect(scaled_inner_bounds,
scaled_corner_radius + kInnerHightlightBorderThickness,
hb_flags);
}
} // namespace ash