OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/views/controls/focus_ring.h" | |
6 | |
7 #include "ui/gfx/canvas.h" | |
8 #include "ui/native_theme/native_theme.h" | |
9 #include "ui/views/controls/focusable_border.h" | |
10 | |
11 namespace views { | |
12 | |
13 namespace { | |
14 | |
15 // The stroke width of the focus border in dp. | |
16 constexpr float kFocusHaloThicknessDp = 2.f; | |
17 | |
18 // The focus indicator should hug the normal border, when present (as in the | |
19 // case of text buttons). Since it's drawn outside the parent view, we have to | |
20 // increase the rounding slightly. | |
21 constexpr float kFocusHaloCornerRadiusDp = | |
22 FocusableBorder::kCornerRadiusDp + kFocusHaloThicknessDp / 2.f; | |
23 | |
24 } // namespace | |
25 | |
26 FocusRing::FocusRing() { | |
sky
2016/10/03 23:53:15
WDYT of making this take the View to add to?
| |
27 // A layer is necessary to paint beyond the parent's bounds. | |
28 SetPaintToLayer(true); | |
29 layer()->SetFillsBoundsOpaquely(false); | |
30 } | |
31 | |
32 FocusRing::~FocusRing() {} | |
33 | |
34 bool FocusRing::CanProcessEventsWithinSubtree() const { | |
35 return false; | |
36 } | |
37 | |
38 void FocusRing::Layout() { | |
39 // The focus ring handles its own sizing, which is simply to fill the parent | |
40 // and extend a little beyond its borders. | |
41 gfx::Rect focus_bounds = parent()->GetLocalBounds(); | |
42 focus_bounds.Inset(gfx::Insets(-kFocusHaloThicknessDp)); | |
43 SetBoundsRect(focus_bounds); | |
44 } | |
45 | |
46 void FocusRing::OnPaint(gfx::Canvas* canvas) { | |
47 SkPaint paint; | |
48 paint.setAntiAlias(true); | |
49 paint.setColor(SkColorSetA(GetNativeTheme()->GetSystemColor( | |
50 ui::NativeTheme::kColorId_FocusedBorderColor), | |
51 0x66)); | |
52 paint.setStyle(SkPaint::kStroke_Style); | |
53 paint.setStrokeWidth(kFocusHaloThicknessDp); | |
54 gfx::RectF rect(GetLocalBounds()); | |
55 rect.Inset(gfx::InsetsF(kFocusHaloThicknessDp / 2.f)); | |
56 canvas->DrawRoundRect(rect, kFocusHaloCornerRadiusDp, paint); | |
57 } | |
58 | |
59 } // namespace views | |
OLD | NEW |