1 // Copyright (c) 2012 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.
5 #include "ui/views/controls/focusable_border.h"
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/geometry/insets.h"
9 #include "ui/gfx/skia_util.h"
10 #include "ui/native_theme/native_theme.h"
14 const int kInsetSize
= 1;
20 FocusableBorder::FocusableBorder()
21 : insets_(kInsetSize
, kInsetSize
, kInsetSize
, kInsetSize
),
22 override_color_(SK_ColorWHITE
),
23 use_default_color_(true) {
26 FocusableBorder::~FocusableBorder() {
29 void FocusableBorder::SetColor(SkColor color
) {
30 override_color_
= color
;
31 use_default_color_
= false;
34 void FocusableBorder::UseDefaultColor() {
35 use_default_color_
= true;
38 void FocusableBorder::Paint(const View
& view
, gfx::Canvas
* canvas
) {
40 path
.addRect(gfx::RectToSkRect(view
.GetLocalBounds()), SkPath::kCW_Direction
);
42 paint
.setStyle(SkPaint::kStroke_Style
);
43 SkColor color
= override_color_
;
44 if (use_default_color_
) {
45 color
= view
.GetNativeTheme()->GetSystemColor(
46 view
.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor
:
47 ui::NativeTheme::kColorId_UnfocusedBorderColor
);
50 paint
.setColor(color
);
51 paint
.setStrokeWidth(SkIntToScalar(2));
53 canvas
->DrawPath(path
, paint
);
56 gfx::Insets
FocusableBorder::GetInsets() const {
60 gfx::Size
FocusableBorder::GetMinimumSize() const {
64 void FocusableBorder::SetInsets(int top
, int left
, int bottom
, int right
) {
65 insets_
.Set(top
, left
, bottom
, right
);