| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/animation/ink_drop_painted_layer_delegates.h" | 5 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
| 6 | 6 |
| 7 #include "cc/paint/paint_canvas.h" | 7 #include "cc/paint/paint_canvas.h" |
| 8 #include "cc/paint/paint_flags.h" | 8 #include "cc/paint/paint_flags.h" |
| 9 #include "third_party/skia/include/core/SkDrawLooper.h" | 9 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 10 #include "third_party/skia/include/core/SkRRect.h" | 10 #include "third_party/skia/include/core/SkRRect.h" |
| 11 #include "ui/compositor/paint_recorder.h" | 11 #include "ui/compositor/paint_recorder.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/color_palette.h" | 13 #include "ui/gfx/color_palette.h" |
| 14 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
| 15 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/point_conversions.h" | 16 #include "ui/gfx/geometry/point_conversions.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/gfx/geometry/rect_conversions.h" |
| 18 #include "ui/gfx/geometry/rect_f.h" | 19 #include "ui/gfx/geometry/rect_f.h" |
| 20 #include "ui/gfx/geometry/size_conversions.h" |
| 19 #include "ui/gfx/skia_paint_util.h" | 21 #include "ui/gfx/skia_paint_util.h" |
| 20 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 21 | 23 |
| 22 namespace views { | 24 namespace views { |
| 23 | 25 |
| 24 //////////////////////////////////////////////////////////////////////////////// | 26 //////////////////////////////////////////////////////////////////////////////// |
| 25 // | 27 // |
| 26 // BasePaintedLayerDelegate | 28 // BasePaintedLayerDelegate |
| 27 // | 29 // |
| 28 | 30 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 46 // | 48 // |
| 47 // CircleLayerDelegate | 49 // CircleLayerDelegate |
| 48 // | 50 // |
| 49 | 51 |
| 50 CircleLayerDelegate::CircleLayerDelegate(SkColor color, int radius) | 52 CircleLayerDelegate::CircleLayerDelegate(SkColor color, int radius) |
| 51 : BasePaintedLayerDelegate(color), radius_(radius) {} | 53 : BasePaintedLayerDelegate(color), radius_(radius) {} |
| 52 | 54 |
| 53 CircleLayerDelegate::~CircleLayerDelegate() {} | 55 CircleLayerDelegate::~CircleLayerDelegate() {} |
| 54 | 56 |
| 55 gfx::Rect CircleLayerDelegate::GetPaintedBounds() const { | 57 gfx::RectF CircleLayerDelegate::GetPaintedBounds() const { |
| 56 const int diameter = radius_ * 2; | 58 const int diameter = radius_ * 2; |
| 57 return gfx::Rect(0, 0, diameter, diameter); | 59 return gfx::RectF(0, 0, diameter, diameter); |
| 58 } | 60 } |
| 59 | 61 |
| 60 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 62 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 61 cc::PaintFlags flags; | 63 cc::PaintFlags flags; |
| 62 flags.setColor(color()); | 64 flags.setColor(color()); |
| 63 flags.setAntiAlias(true); | 65 flags.setAntiAlias(true); |
| 64 flags.setStyle(cc::PaintFlags::kFill_Style); | 66 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 65 | 67 |
| 66 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 68 ui::PaintRecorder recorder(context, |
| 69 gfx::ToEnclosingRect(GetPaintedBounds()).size()); |
| 67 gfx::Canvas* canvas = recorder.canvas(); | 70 gfx::Canvas* canvas = recorder.canvas(); |
| 68 | 71 |
| 69 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, flags); | 72 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, flags); |
| 70 } | 73 } |
| 71 | 74 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 73 // | 76 // |
| 74 // RectangleLayerDelegate | 77 // RectangleLayerDelegate |
| 75 // | 78 // |
| 76 | 79 |
| 77 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size) | 80 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::SizeF size) |
| 78 : BasePaintedLayerDelegate(color), size_(size) {} | 81 : BasePaintedLayerDelegate(color), size_(size) {} |
| 79 | 82 |
| 80 RectangleLayerDelegate::~RectangleLayerDelegate() {} | 83 RectangleLayerDelegate::~RectangleLayerDelegate() {} |
| 81 | 84 |
| 82 gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const { | 85 gfx::RectF RectangleLayerDelegate::GetPaintedBounds() const { |
| 83 return gfx::Rect(size_); | 86 return gfx::RectF(size_); |
| 84 } | 87 } |
| 85 | 88 |
| 86 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 89 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 87 cc::PaintFlags flags; | 90 cc::PaintFlags flags; |
| 88 flags.setColor(color()); | 91 flags.setColor(color()); |
| 89 flags.setAntiAlias(true); | 92 flags.setAntiAlias(true); |
| 90 flags.setStyle(cc::PaintFlags::kFill_Style); | 93 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 91 | 94 |
| 92 ui::PaintRecorder recorder(context, size_); | 95 ui::PaintRecorder recorder(context, gfx::ToCeiledSize(size_)); |
| 93 gfx::Canvas* canvas = recorder.canvas(); | 96 gfx::Canvas* canvas = recorder.canvas(); |
| 94 canvas->DrawRect(GetPaintedBounds(), flags); | 97 canvas->DrawRect(GetPaintedBounds(), flags); |
| 95 } | 98 } |
| 96 | 99 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
| 98 // | 101 // |
| 99 // RoundedRectangleLayerDelegate | 102 // RoundedRectangleLayerDelegate |
| 100 // | 103 // |
| 101 | 104 |
| 102 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( | 105 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( |
| 103 SkColor color, | 106 SkColor color, |
| 104 const gfx::Size& size, | 107 const gfx::SizeF& size, |
| 105 int corner_radius) | 108 int corner_radius) |
| 106 : BasePaintedLayerDelegate(color), | 109 : BasePaintedLayerDelegate(color), |
| 107 size_(size), | 110 size_(size), |
| 108 corner_radius_(corner_radius) {} | 111 corner_radius_(corner_radius) {} |
| 109 | 112 |
| 110 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} | 113 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} |
| 111 | 114 |
| 112 gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const { | 115 gfx::RectF RoundedRectangleLayerDelegate::GetPaintedBounds() const { |
| 113 return gfx::Rect(size_); | 116 return gfx::RectF(size_); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void RoundedRectangleLayerDelegate::OnPaintLayer( | 119 void RoundedRectangleLayerDelegate::OnPaintLayer( |
| 117 const ui::PaintContext& context) { | 120 const ui::PaintContext& context) { |
| 118 cc::PaintFlags flags; | 121 cc::PaintFlags flags; |
| 119 flags.setColor(color()); | 122 flags.setColor(color()); |
| 120 flags.setAntiAlias(true); | 123 flags.setAntiAlias(true); |
| 121 flags.setStyle(cc::PaintFlags::kFill_Style); | 124 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 122 | 125 |
| 123 ui::PaintRecorder recorder(context, size_); | 126 ui::PaintRecorder recorder(context, gfx::ToCeiledSize(size_)); |
| 124 recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, flags); | 127 const float dsf = recorder.canvas()->UndoDeviceScaleFactor(); |
| 128 gfx::RectF rect = GetPaintedBounds(); |
| 129 rect.Scale(dsf); |
| 130 recorder.canvas()->DrawRoundRect(gfx::ToEnclosingRect(rect), |
| 131 dsf * corner_radius_, flags); |
| 125 } | 132 } |
| 126 | 133 |
| 127 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
| 128 // | 135 // |
| 129 // BorderShadowLayerDelegate | 136 // BorderShadowLayerDelegate |
| 130 // | 137 // |
| 131 | 138 |
| 132 BorderShadowLayerDelegate::BorderShadowLayerDelegate( | 139 BorderShadowLayerDelegate::BorderShadowLayerDelegate( |
| 133 const std::vector<gfx::ShadowValue>& shadows, | 140 const std::vector<gfx::ShadowValue>& shadows, |
| 134 const gfx::Rect& shadowed_area_bounds, | 141 const gfx::Rect& shadowed_area_bounds, |
| 135 SkColor fill_color, | 142 SkColor fill_color, |
| 136 int corner_radius) | 143 int corner_radius) |
| 137 : BasePaintedLayerDelegate(gfx::kPlaceholderColor), | 144 : BasePaintedLayerDelegate(gfx::kPlaceholderColor), |
| 138 shadows_(shadows), | 145 shadows_(shadows), |
| 139 bounds_(shadowed_area_bounds), | 146 bounds_(shadowed_area_bounds), |
| 140 fill_color_(fill_color), | 147 fill_color_(fill_color), |
| 141 corner_radius_(corner_radius) {} | 148 corner_radius_(corner_radius) {} |
| 142 | 149 |
| 143 BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {} | 150 BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {} |
| 144 | 151 |
| 145 gfx::Rect BorderShadowLayerDelegate::GetPaintedBounds() const { | 152 gfx::RectF BorderShadowLayerDelegate::GetPaintedBounds() const { |
| 146 gfx::Rect total_rect(bounds_); | 153 gfx::Rect total_rect(bounds_); |
| 147 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); | 154 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); |
| 148 return total_rect; | 155 return gfx::RectF(total_rect); |
| 149 } | 156 } |
| 150 | 157 |
| 151 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { | 158 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { |
| 152 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); | 159 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); |
| 153 } | 160 } |
| 154 | 161 |
| 155 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 162 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 156 cc::PaintFlags flags; | 163 cc::PaintFlags flags; |
| 157 flags.setStyle(cc::PaintFlags::kFill_Style); | 164 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 158 flags.setAntiAlias(true); | 165 flags.setAntiAlias(true); |
| 159 flags.setColor(fill_color_); | 166 flags.setColor(fill_color_); |
| 160 | 167 |
| 161 gfx::RectF rrect_bounds = | 168 gfx::RectF rrect_bounds = |
| 162 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); | 169 gfx::RectF(bounds_) - GetPaintedBounds().OffsetFromOrigin(); |
| 163 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), | 170 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), |
| 164 corner_radius_, corner_radius_); | 171 corner_radius_, corner_radius_); |
| 165 | 172 |
| 166 // First the fill color. | 173 // First the fill color. |
| 167 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 174 ui::PaintRecorder recorder(context, |
| 175 gfx::ToCeiledSize(GetPaintedBounds().size())); |
| 168 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); | 176 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); |
| 169 | 177 |
| 170 // Now the shadow. | 178 // Now the shadow. |
| 171 flags.setLooper(gfx::CreateShadowDrawLooper(shadows_)); | 179 flags.setLooper(gfx::CreateShadowDrawLooper(shadows_)); |
| 172 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, | 180 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, |
| 173 true); | 181 true); |
| 174 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); | 182 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); |
| 175 } | 183 } |
| 176 | 184 |
| 177 } // namespace views | 185 } // namespace views |
| OLD | NEW |