| 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 21 matching lines...) Expand all Loading... |
| 32 void FocusableBorder::SetColorId( | 32 void FocusableBorder::SetColorId( |
| 33 const base::Optional<ui::NativeTheme::ColorId>& color_id) { | 33 const base::Optional<ui::NativeTheme::ColorId>& color_id) { |
| 34 override_color_id_ = color_id; | 34 override_color_id_ = color_id; |
| 35 } | 35 } |
| 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 paint; | 42 cc::PaintFlags flags; |
| 43 paint.setStyle(cc::PaintFlags::kStroke_Style); | 43 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 44 paint.setColor(GetCurrentColor(view)); | 44 flags.setColor(GetCurrentColor(view)); |
| 45 | 45 |
| 46 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 46 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 47 gfx::ScopedCanvas scoped(canvas); | 47 gfx::ScopedCanvas scoped(canvas); |
| 48 float dsf = canvas->UndoDeviceScaleFactor(); | 48 float dsf = canvas->UndoDeviceScaleFactor(); |
| 49 // Scale the rect and snap to pixel boundaries. | 49 // Scale the rect and snap to pixel boundaries. |
| 50 gfx::RectF rect(gfx::ScaleToEnclosingRect(view.GetLocalBounds(), dsf)); | 50 gfx::RectF rect(gfx::ScaleToEnclosingRect(view.GetLocalBounds(), dsf)); |
| 51 rect.Inset(gfx::InsetsF(0.5f)); | 51 rect.Inset(gfx::InsetsF(0.5f)); |
| 52 SkPath path; | 52 SkPath path; |
| 53 float corner_radius_px = kCornerRadiusDp * dsf; | 53 float corner_radius_px = kCornerRadiusDp * dsf; |
| 54 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, | 54 path.addRoundRect(gfx::RectFToSkRect(rect), corner_radius_px, |
| 55 corner_radius_px); | 55 corner_radius_px); |
| 56 const int kStrokeWidthPx = 1; | 56 const int kStrokeWidthPx = 1; |
| 57 paint.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); | 57 flags.setStrokeWidth(SkIntToScalar(kStrokeWidthPx)); |
| 58 paint.setAntiAlias(true); | 58 flags.setAntiAlias(true); |
| 59 canvas->DrawPath(path, paint); | 59 canvas->DrawPath(path, flags); |
| 60 } else { | 60 } else { |
| 61 SkPath path; | 61 SkPath path; |
| 62 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), | 62 path.addRect(gfx::RectToSkRect(view.GetLocalBounds()), |
| 63 SkPath::kCW_Direction); | 63 SkPath::kCW_Direction); |
| 64 paint.setStrokeWidth(SkIntToScalar(2)); | 64 flags.setStrokeWidth(SkIntToScalar(2)); |
| 65 canvas->DrawPath(path, paint); | 65 canvas->DrawPath(path, flags); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 gfx::Insets FocusableBorder::GetInsets() const { | 69 gfx::Insets FocusableBorder::GetInsets() const { |
| 70 return insets_; | 70 return insets_; |
| 71 } | 71 } |
| 72 | 72 |
| 73 gfx::Size FocusableBorder::GetMinimumSize() const { | 73 gfx::Size FocusableBorder::GetMinimumSize() const { |
| 74 return gfx::Size(); | 74 return gfx::Size(); |
| 75 } | 75 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 89 SkColor color = view.GetNativeTheme()->GetSystemColor(color_id); | 89 SkColor color = view.GetNativeTheme()->GetSystemColor(color_id); |
| 90 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && | 90 if (ui::MaterialDesignController::IsSecondaryUiMaterial() && |
| 91 !view.enabled()) { | 91 !view.enabled()) { |
| 92 return color_utils::BlendTowardOppositeLuma(color, | 92 return color_utils::BlendTowardOppositeLuma(color, |
| 93 gfx::kDisabledControlAlpha); | 93 gfx::kDisabledControlAlpha); |
| 94 } | 94 } |
| 95 return color; | 95 return color; |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace views | 98 } // namespace views |
| OLD | NEW |