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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { | 44 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { |
45 SkPaint paint; | 45 SkPaint paint; |
46 paint.setStyle(SkPaint::kStroke_Style); | 46 paint.setStyle(SkPaint::kStroke_Style); |
47 paint.setColor(GetCurrentColor(view)); | 47 paint.setColor(GetCurrentColor(view)); |
48 | 48 |
49 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 49 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
50 gfx::ScopedCanvas scoped(canvas); | 50 gfx::ScopedCanvas scoped(canvas); |
51 float dsf = canvas->UndoDeviceScaleFactor(); | 51 float dsf = canvas->UndoDeviceScaleFactor(); |
52 // Scale the rect and snap to pixel boundaries. | 52 // Scale the rect and snap to pixel boundaries. |
53 gfx::RectF rect = gfx::RectF(gfx::ToEnclosedRect( | 53 gfx::RectF rect(gfx::ScaleToEnclosingRect(view.GetLocalBounds(), dsf)); |
54 ScaleRect(gfx::RectF(view.GetLocalBounds()), dsf, dsf))); | |
55 rect.Inset(gfx::InsetsF(0.5f)); | 54 rect.Inset(gfx::InsetsF(0.5f)); |
56 SkPath path; | 55 SkPath path; |
57 float corner_radius_px = kCornerRadiusDp * dsf; | 56 float corner_radius_px = kCornerRadiusDp * dsf; |
58 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, | 57 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, |
59 corner_radius_px); | 58 corner_radius_px); |
60 const int kStrokeWidthPx = 1; | 59 const int kStrokeWidthPx = 1; |
61 paint.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); | 60 paint.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); |
62 paint.setAntiAlias(true); | 61 paint.setAntiAlias(true); |
63 canvas->DrawPath(path, paint); | 62 canvas->DrawPath(path, paint); |
64 } else { | 63 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
84 | 83 |
85 SkColor FocusableBorder::GetCurrentColor(const View& view) const { | 84 SkColor FocusableBorder::GetCurrentColor(const View& view) const { |
86 if (!use_default_color_) | 85 if (!use_default_color_) |
87 return override_color_; | 86 return override_color_; |
88 return view.GetNativeTheme()->GetSystemColor( | 87 return view.GetNativeTheme()->GetSystemColor( |
89 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : | 88 view.HasFocus() ? ui::NativeTheme::kColorId_FocusedBorderColor : |
90 ui::NativeTheme::kColorId_UnfocusedBorderColor); | 89 ui::NativeTheme::kColorId_UnfocusedBorderColor); |
91 } | 90 } |
92 | 91 |
93 } // namespace views | 92 } // namespace views |
OLD | NEW |