Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/focusable_border.h" | 5 #include "ui/views/controls/focusable_border.h" |
| 6 | 6 |
| 7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" |
| 8 #include "ui/gfx/insets.h" | 8 #include "ui/gfx/insets.h" |
| 9 #include "ui/gfx/skia_util.h" | 9 #include "ui/gfx/skia_util.h" |
| 10 #include "ui/native_theme/native_theme.h" | 10 #include "ui/native_theme/native_theme.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // Define the size of the insets | 14 const int kInsetSize = 1; |
| 15 const int kTopInsetSize = 4; | |
| 16 const int kLeftInsetSize = 4; | |
| 17 const int kBottomInsetSize = 4; | |
| 18 const int kRightInsetSize = 4; | |
| 19 | 15 |
| 20 } // namespace | 16 } // namespace |
| 21 | 17 |
| 22 namespace views { | 18 namespace views { |
| 23 | 19 |
| 24 FocusableBorder::FocusableBorder() | 20 FocusableBorder::FocusableBorder() |
| 25 : insets_(kTopInsetSize, kLeftInsetSize, | 21 : insets_(kInsetSize, kInsetSize, kInsetSize, kInsetSize), |
| 26 kBottomInsetSize, kRightInsetSize), | |
| 27 override_color_(SK_ColorWHITE), | 22 override_color_(SK_ColorWHITE), |
| 28 use_default_color_(true) { | 23 use_default_color_(true) { |
| 29 } | 24 } |
| 30 | 25 |
| 26 FocusableBorder::~FocusableBorder() { | |
| 27 } | |
| 28 | |
| 31 void FocusableBorder::SetColor(SkColor color) { | 29 void FocusableBorder::SetColor(SkColor color) { |
| 32 override_color_ = color; | 30 override_color_ = color; |
| 33 use_default_color_ = false; | 31 use_default_color_ = false; |
| 34 } | 32 } |
| 35 | 33 |
| 36 void FocusableBorder::UseDefaultColor() { | 34 void FocusableBorder::UseDefaultColor() { |
| 37 use_default_color_ = true; | 35 use_default_color_ = true; |
| 38 } | 36 } |
| 39 | 37 |
| 40 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { | 38 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| 41 SkPath path; | 39 SkPath path; |
| 42 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction); | 40 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), SkPath::kCW_Direction); |
| 43 SkPaint paint; | 41 SkPaint paint; |
| 44 paint.setStyle(SkPaint::kStroke_Style); | 42 paint.setStyle(SkPaint::kStroke_Style); |
| 45 SkColor color = override_color_; | 43 SkColor color = override_color_; |
| 46 if (use_default_color_) { | 44 if (use_default_color_) { |
| 47 color = view.GetNativeTheme()->GetSystemColor( | 45 color = view.GetNativeTheme()->GetSystemColor( |
| 48 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : | 46 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : |
| 49 ui::NativeTheme::kColorId_UnfocusedBorderColor); | 47 ui::NativeTheme::kColorId_UnfocusedBorderColor); |
| 50 } | 48 } |
| 51 | 49 |
| 52 paint.setColor(color); | 50 paint.setColor(color); |
| 53 paint.setStrokeWidth(SkIntToScalar(2)); | 51 paint.setStrokeWidth(SkIntToScalar(2 * kInsetSize)); |
|
Peter Kasting
2014/08/29 21:09:11
This probably deserves a comment on why the stroke
msw
2014/08/30 00:17:48
I reverted this; it's just drawing a rect at the l
Peter Kasting
2014/08/30 00:46:42
Maybe then we should just draw a kInsetSize-px lin
msw
2014/09/04 01:25:51
Feel free to rewrite this separately.
| |
| 54 | 52 |
| 55 canvas->DrawPath(path, paint); | 53 canvas->DrawPath(path, paint); |
| 56 } | 54 } |
| 57 | 55 |
| 58 gfx::Insets FocusableBorder::GetInsets() const { | 56 gfx::Insets FocusableBorder::GetInsets() const { |
| 59 return insets_; | 57 return insets_; |
| 60 } | 58 } |
| 61 | 59 |
| 62 gfx::Size FocusableBorder::GetMinimumSize() const { | 60 gfx::Size FocusableBorder::GetMinimumSize() const { |
| 63 return gfx::Size(); | 61 return gfx::Size(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { | 64 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { |
| 67 insets_.Set(top, left, bottom, right); | 65 insets_.Set(top, left, bottom, right); |
| 68 } | 66 } |
| 69 | 67 |
| 70 } // namespace views | 68 } // namespace views |
| OLD | NEW |