1 // Copyright (c) 2011 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 "views/controls/focusable_border.h"
7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/canvas_skia.h"
9 #include "ui/gfx/insets.h"
13 // Define the size of the insets
14 const int kTopInsetSize
= 4;
15 const int kLeftInsetSize
= 4;
16 const int kBottomInsetSize
= 4;
17 const int kRightInsetSize
= 4;
19 // Color settings for border.
20 // These are tentative, and should be derived from theme, system
21 // settings and current settings.
22 // TODO(saintlou): understand why this is not factored/shared somewhere
23 const SkColor kFocusedBorderColor
= SK_ColorCYAN
;
24 const SkColor kDefaultBorderColor
= SK_ColorGRAY
;
30 FocusableBorder::FocusableBorder()
32 insets_(kTopInsetSize
, kLeftInsetSize
,
33 kBottomInsetSize
, kRightInsetSize
) {
36 void FocusableBorder::Paint(const View
& view
, gfx::Canvas
* canvas
) const {
38 rect
.set(SkIntToScalar(0), SkIntToScalar(0),
39 SkIntToScalar(view
.width()), SkIntToScalar(view
.height()));
40 SkScalar corners
[8] = {
42 SkIntToScalar(insets_
.left()),
43 SkIntToScalar(insets_
.top()),
45 SkIntToScalar(insets_
.right()),
46 SkIntToScalar(insets_
.top()),
48 SkIntToScalar(insets_
.right()),
49 SkIntToScalar(insets_
.bottom()),
51 SkIntToScalar(insets_
.left()),
52 SkIntToScalar(insets_
.bottom()),
55 path
.addRoundRect(rect
, corners
);
57 paint
.setStyle(SkPaint::kStroke_Style
);
58 paint
.setFlags(SkPaint::kAntiAlias_Flag
);
59 // TODO(oshima): Copy what WebKit does for focused border.
60 paint
.setColor(has_focus_
? kFocusedBorderColor
: kDefaultBorderColor
);
61 paint
.setStrokeWidth(SkIntToScalar(has_focus_
? 2 : 1));
63 canvas
->GetSkCanvas()->drawPath(path
, paint
);
66 void FocusableBorder::GetInsets(gfx::Insets
* insets
) const {
70 void FocusableBorder::SetInsets(int top
, int left
, int bottom
, int right
) {
71 insets_
.Set(top
, left
, bottom
, right
);