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 "third_party/skia/include/core/SkPaint.h" | 7 #include "third_party/skia/include/core/SkPaint.h" |
| 8 #include "third_party/skia/include/core/SkPath.h" | 8 #include "third_party/skia/include/core/SkPath.h" |
| 9 #include "ui/base/material_design/material_design_controller.h" | 9 #include "ui/base/material_design/material_design_controller.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/color_palette.h" | 11 #include "ui/gfx/color_palette.h" |
| 12 #include "ui/gfx/geometry/insets.h" | 12 #include "ui/gfx/geometry/insets.h" |
| 13 #include "ui/gfx/scoped_canvas.h" | |
| 13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
| 14 #include "ui/native_theme/native_theme.h" | 15 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/views/controls/textfield/textfield.h" | 16 #include "ui/views/controls/textfield/textfield.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const int kInsetSize = 1; | 20 const int kInsetSize = 1; |
| 20 | 21 |
| 21 } // namespace | 22 } // namespace |
| 22 | 23 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 38 | 39 |
| 39 void FocusableBorder::UseDefaultColor() { | 40 void FocusableBorder::UseDefaultColor() { |
| 40 use_default_color_ = true; | 41 use_default_color_ = true; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { | 44 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| 44 SkPaint paint; | 45 SkPaint paint; |
| 45 paint.setStyle(SkPaint::kStroke_Style); | 46 paint.setStyle(SkPaint::kStroke_Style); |
| 46 paint.setColor(GetCurrentColor(view)); | 47 paint.setColor(GetCurrentColor(view)); |
| 47 | 48 |
| 48 SkPath path; | |
| 49 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 49 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 50 path.moveTo(Textfield::kTextPadding, view.height() - 1); | 50 gfx::ScopedCanvas scoped(canvas); |
| 51 path.rLineTo(view.width() - Textfield::kTextPadding * 2, 0); | 51 float dsf = canvas->UndoDeviceScaleFactor(); |
| 52 path.offset(0.5f, 0.5f); | 52 gfx::RectF rect((gfx::Rect(view.GetLocalBounds()))); |
|
sky
2016/08/08 19:24:22
I'm surprised you're using floating point for this
| |
| 53 paint.setStrokeWidth(SkIntToScalar(1)); | 53 rect = ScaleRect(rect, dsf, dsf); |
| 54 rect.Inset(gfx::InsetsF(0.5f)); | |
| 55 SkPath path; | |
| 56 float corner_radius_px = kCornerRadiusDp * dsf; | |
| 57 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, | |
| 58 corner_radius_px); | |
| 59 const int kStrokeWidthPx = 1; | |
| 60 paint.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); | |
| 61 paint.setAntiAlias(true); | |
| 62 canvas->DrawPath(path, paint); | |
| 54 } else { | 63 } else { |
| 64 SkPath path; | |
| 55 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), | 65 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), |
| 56 SkPath::kCW_Direction); | 66 SkPath::kCW_Direction); |
| 57 paint.setStrokeWidth(SkIntToScalar(2)); | 67 paint.setStrokeWidth(SkIntToScalar(2)); |
| 68 canvas->DrawPath(path, paint); | |
| 58 } | 69 } |
| 59 canvas->DrawPath(path, paint); | |
| 60 } | 70 } |
| 61 | 71 |
| 62 gfx::Insets FocusableBorder::GetInsets() const { | 72 gfx::Insets FocusableBorder::GetInsets() const { |
| 63 return insets_; | 73 return insets_; |
| 64 } | 74 } |
| 65 | 75 |
| 66 gfx::Size FocusableBorder::GetMinimumSize() const { | 76 gfx::Size FocusableBorder::GetMinimumSize() const { |
| 67 return gfx::Size(); | 77 return gfx::Size(); |
| 68 } | 78 } |
| 69 | 79 |
| 70 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { | 80 void FocusableBorder::SetInsets(int top, int left, int bottom, int right) { |
| 71 insets_.Set(top, left, bottom, right); | 81 insets_.Set(top, left, bottom, right); |
| 72 } | 82 } |
| 73 | 83 |
| 74 SkColor FocusableBorder::GetCurrentColor(const View& view) const { | 84 SkColor FocusableBorder::GetCurrentColor(const View& view) const { |
| 75 if (!use_default_color_) | 85 if (!use_default_color_) |
| 76 return override_color_; | 86 return override_color_; |
| 77 return view.GetNativeTheme()->GetSystemColor( | 87 return view.GetNativeTheme()->GetSystemColor( |
| 78 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : | 88 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : |
| 79 ui::NativeTheme::kColorId_UnfocusedBorderColor); | 89 ui::NativeTheme::kColorId_UnfocusedBorderColor); |
| 80 } | 90 } |
| 81 | 91 |
| 82 } // namespace views | 92 } // namespace views |
| OLD | NEW |