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/insets.h"
9 #include "ui/gfx/skia_util.h"
10 #include "ui/native_theme/native_theme.h"
14 // Define the size of the insets
15 const int kTopInsetSize = 4;
16 const int kLeftInsetSize = 4;
17 const int kBottomInsetSize = 4;
18 const int kRightInsetSize = 4;
24 FocusableBorder::FocusableBorder()
26 insets_(kTopInsetSize, kLeftInsetSize,
27 kBottomInsetSize, kRightInsetSize),
28 override_color_(SK_ColorWHITE),
29 use_default_color_(true) {
32 void FocusableBorder::SetColor(SkColor color) {
33 override_color_ = color;
34 use_default_color_ = false;
37 void FocusableBorder::UseDefaultColor() {
38 use_default_color_ = true;
41 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) {
43 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction);
45 paint.setStyle(SkPaint::kStroke_Style);
46 SkColor color = override_color_;
47 if (use_default_color_) {
48 color = view.GetNativeTheme()->GetSystemColor(
49 has_focus_ ? ui::NativeTheme::kColorId_FocusedBorderColor :
50 ui::NativeTheme::kColorId_UnfocusedBorderColor);
53 paint.setColor(color);
54 paint.setStrokeWidth(SkIntToScalar(2));
56 canvas->DrawPath(path, paint);
59 gfx::Insets FocusableBorder::GetInsets() const {
63 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) {
64 insets_.Set(top, left, bottom, right);