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 "cc/paint/paint_flags.h" | 7 #include "cc/paint/paint_flags.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 25 matching lines...) Expand all Loading... | |
| 36 | 36 |
| 37 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { | 37 void FocusableBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| 38 // In harmony, the focus indicator is a FocusRing. | 38 // In harmony, the focus indicator is a FocusRing. |
| 39 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && view.HasFocus()) | 39 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && view.HasFocus()) |
| 40 return; | 40 return; |
| 41 | 41 |
| 42 cc::PaintFlags flags; | 42 cc::PaintFlags flags; |
| 43 flags.setStyle(cc::PaintFlags::kStroke_Style); | 43 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 44 flags.setColor(GetCurrentColor(view)); | 44 flags.setColor(GetCurrentColor(view)); |
| 45 | 45 |
| 46 gfx::ScopedCanvas scoped(canvas); | |
| 47 float dsf = canvas->UndoDeviceScaleFactor(); | |
| 48 | |
| 49 const int stroke_width_px = | |
| 50 ui::MaterialDesignController::IsSecondaryUiMaterial() ? 1 : dsf; | |
|
Peter Kasting
2017/02/14 00:30:32
It seems like the old pre-Harmony code was trying
Evan Stade
2017/02/14 00:37:47
That was just a hacky way to get a 1dip border. 1d
Peter Kasting
2017/02/14 00:45:59
I see.
Why was the old code producing poorer-look
| |
| 51 flags.setStrokeWidth(SkIntToScalar(stroke_width_px)); | |
| 52 | |
| 53 // Scale the rect and snap to pixel boundaries. | |
| 54 gfx::RectF rect(gfx::ScaleToEnclosingRect(view.GetLocalBounds(), dsf)); | |
| 55 rect.Inset(gfx::InsetsF(stroke_width_px / 2.0f)); | |
| 56 | |
| 57 SkPath path; | |
| 46 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 58 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 47 gfx::ScopedCanvas scoped(canvas); | 59 flags.setAntiAlias(true); |
| 48 float dsf = canvas->UndoDeviceScaleFactor(); | |
| 49 // Scale the rect and snap to pixel boundaries. | |
| 50 gfx::RectF rect(gfx::ScaleToEnclosingRect(view.GetLocalBounds(), dsf)); | |
| 51 rect.Inset(gfx::InsetsF(0.5f)); | |
| 52 SkPath path; | |
| 53 float corner_radius_px = kCornerRadiusDp * dsf; | 60 float corner_radius_px = kCornerRadiusDp * dsf; |
| 54 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, | 61 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, |
| 55 corner_radius_px); | 62 corner_radius_px); |
| 56 const int kStrokeWidthPx = 1; | |
| 57 flags.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); | |
| 58 flags.setAntiAlias(true); | |
| 59 canvas->DrawPath(path, flags); | |
| 60 } else { | 63 } else { |
| 61 SkPath path; | 64 path.addRect(gfx::RectFToSkRect(rect), SkPath::kCW_Direction); |
| 62 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), | |
| 63 SkPath::kCW_Direction); | |
| 64 flags.setStrokeWidth(SkIntToScalar(2)); | |
| 65 canvas->DrawPath(path, flags); | |
| 66 } | 65 } |
| 66 | |
| 67 canvas->DrawPath(path, flags); | |
| 67 } | 68 } |
| 68 | 69 |
| 69 gfx::Insets FocusableBorder::GetInsets() const { | 70 gfx::Insets FocusableBorder::GetInsets() const { |
| 70 return insets_; | 71 return insets_; |
| 71 } | 72 } |
| 72 | 73 |
| 73 gfx::Size FocusableBorder::GetMinimumSize() const { | 74 gfx::Size FocusableBorder::GetMinimumSize() const { |
| 74 return gfx::Size(); | 75 return gfx::Size(); |
| 75 } | 76 } |
| 76 | 77 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 89 SkColor color = view.GetNativeTheme()->GetSystemColor(color_id); | 90 SkColor color = view.GetNativeTheme()->GetSystemColor(color_id); |
| 90 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && | 91 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && |
| 91 !view.enabled()) { | 92 !view.enabled()) { |
| 92 return color_utils::BlendTowardOppositeLuma(color, | 93 return color_utils::BlendTowardOppositeLuma(color, |
| 93 gfx::kDisabledControlAlpha); | 94 gfx::kDisabledControlAlpha); |
| 94 } | 95 } |
| 95 return color; | 96 return color; |
| 96 } | 97 } |
| 97 | 98 |
| 98 } // namespace views | 99 } // namespace views |
| OLD | NEW |