| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ui/views/controls/focusable_border.h" | |
| 6 | |
| 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" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 const int kInsetSize = 1; | |
| 15 | |
| 16 } // namespace | |
| 17 | |
| 18 namespace views { | |
| 19 | |
| 20 FocusableBorder::FocusableBorder() | |
| 21 : insets_(kInsetSize, kInsetSize, kInsetSize, kInsetSize), | |
| 22 override_color_(SK_ColorWHITE), | |
| 23 use_default_color_(true) { | |
| 24 } | |
| 25 | |
| 26 FocusableBorder::~FocusableBorder() { | |
| 27 } | |
| 28 | |
| 29 void FocusableBorder::SetColor(SkColor color) { | |
| 30 override_color_ = color; | |
| 31 use_default_color_ = false; | |
| 32 } | |
| 33 | |
| 34 void FocusableBorder::UseDefaultColor() { | |
| 35 use_default_color_ = true; | |
| 36 } | |
| 37 | |
| 38 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { | |
| 39 SkPath path; | |
| 40 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction); | |
| 41 SkPaint paint; | |
| 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); | |
| 48 } | |
| 49 | |
| 50 paint.setColor(color); | |
| 51 paint.setStrokeWidth(SkIntToScalar(2)); | |
| 52 | |
| 53 canvas->DrawPath(path, paint); | |
| 54 } | |
| 55 | |
| 56 gfx::Insets FocusableBorder::GetInsets() const { | |
| 57 return insets_; | |
| 58 } | |
| 59 | |
| 60 gfx::Size FocusableBorder::GetMinimumSize() const { | |
| 61 return gfx::Size(); | |
| 62 } | |
| 63 | |
| 64 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { | |
| 65 insets_.Set(top, left, bottom, right); | |
| 66 } | |
| 67 | |
| 68 } // namespace views | |
| OLD | NEW |