| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 : BasePaintedLayerDelegate(color), radius_(radius) {} | 51 : BasePaintedLayerDelegate(color), radius_(radius) {} |
| 52 | 52 |
| 53 CircleLayerDelegate::~CircleLayerDelegate() {} | 53 CircleLayerDelegate::~CircleLayerDelegate() {} |
| 54 | 54 |
| 55 gfx::Rect CircleLayerDelegate::GetPaintedBounds() const { | 55 gfx::Rect CircleLayerDelegate::GetPaintedBounds() const { |
| 56 const int diameter = radius_ * 2; | 56 const int diameter = radius_ * 2; |
| 57 return gfx::Rect(0, 0, diameter, diameter); | 57 return gfx::Rect(0, 0, diameter, diameter); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 60 void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 61 cc::PaintFlags paint; | 61 cc::PaintFlags flags; |
| 62 paint.setColor(color()); | 62 flags.setColor(color()); |
| 63 paint.setAntiAlias(true); | 63 flags.setAntiAlias(true); |
| 64 paint.setStyle(cc::PaintFlags::kFill_Style); | 64 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 65 | 65 |
| 66 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 66 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); |
| 67 gfx::Canvas* canvas = recorder.canvas(); | 67 gfx::Canvas* canvas = recorder.canvas(); |
| 68 | 68 |
| 69 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, paint); | 69 canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, flags); |
| 70 } | 70 } |
| 71 | 71 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 73 // | 73 // |
| 74 // RectangleLayerDelegate | 74 // RectangleLayerDelegate |
| 75 // | 75 // |
| 76 | 76 |
| 77 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size) | 77 RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size) |
| 78 : BasePaintedLayerDelegate(color), size_(size) {} | 78 : BasePaintedLayerDelegate(color), size_(size) {} |
| 79 | 79 |
| 80 RectangleLayerDelegate::~RectangleLayerDelegate() {} | 80 RectangleLayerDelegate::~RectangleLayerDelegate() {} |
| 81 | 81 |
| 82 gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const { | 82 gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const { |
| 83 return gfx::Rect(size_); | 83 return gfx::Rect(size_); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 86 void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 87 cc::PaintFlags paint; | 87 cc::PaintFlags flags; |
| 88 paint.setColor(color()); | 88 flags.setColor(color()); |
| 89 paint.setAntiAlias(true); | 89 flags.setAntiAlias(true); |
| 90 paint.setStyle(cc::PaintFlags::kFill_Style); | 90 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 91 | 91 |
| 92 ui::PaintRecorder recorder(context, size_); | 92 ui::PaintRecorder recorder(context, size_); |
| 93 gfx::Canvas* canvas = recorder.canvas(); | 93 gfx::Canvas* canvas = recorder.canvas(); |
| 94 canvas->DrawRect(GetPaintedBounds(), paint); | 94 canvas->DrawRect(GetPaintedBounds(), flags); |
| 95 } | 95 } |
| 96 | 96 |
| 97 //////////////////////////////////////////////////////////////////////////////// | 97 //////////////////////////////////////////////////////////////////////////////// |
| 98 // | 98 // |
| 99 // RoundedRectangleLayerDelegate | 99 // RoundedRectangleLayerDelegate |
| 100 // | 100 // |
| 101 | 101 |
| 102 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( | 102 RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate( |
| 103 SkColor color, | 103 SkColor color, |
| 104 const gfx::Size& size, | 104 const gfx::Size& size, |
| 105 int corner_radius) | 105 int corner_radius) |
| 106 : BasePaintedLayerDelegate(color), | 106 : BasePaintedLayerDelegate(color), |
| 107 size_(size), | 107 size_(size), |
| 108 corner_radius_(corner_radius) {} | 108 corner_radius_(corner_radius) {} |
| 109 | 109 |
| 110 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} | 110 RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {} |
| 111 | 111 |
| 112 gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const { | 112 gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const { |
| 113 return gfx::Rect(size_); | 113 return gfx::Rect(size_); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void RoundedRectangleLayerDelegate::OnPaintLayer( | 116 void RoundedRectangleLayerDelegate::OnPaintLayer( |
| 117 const ui::PaintContext& context) { | 117 const ui::PaintContext& context) { |
| 118 cc::PaintFlags paint; | 118 cc::PaintFlags flags; |
| 119 paint.setColor(color()); | 119 flags.setColor(color()); |
| 120 paint.setAntiAlias(true); | 120 flags.setAntiAlias(true); |
| 121 paint.setStyle(cc::PaintFlags::kFill_Style); | 121 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 122 | 122 |
| 123 ui::PaintRecorder recorder(context, size_); | 123 ui::PaintRecorder recorder(context, size_); |
| 124 recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, paint); | 124 recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, flags); |
| 125 } | 125 } |
| 126 | 126 |
| 127 //////////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////////// |
| 128 // | 128 // |
| 129 // BorderShadowLayerDelegate | 129 // BorderShadowLayerDelegate |
| 130 // | 130 // |
| 131 | 131 |
| 132 BorderShadowLayerDelegate::BorderShadowLayerDelegate( | 132 BorderShadowLayerDelegate::BorderShadowLayerDelegate( |
| 133 const std::vector<gfx::ShadowValue>& shadows, | 133 const std::vector<gfx::ShadowValue>& shadows, |
| 134 const gfx::Rect& shadowed_area_bounds, | 134 const gfx::Rect& shadowed_area_bounds, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 146 gfx::Rect total_rect(bounds_); | 146 gfx::Rect total_rect(bounds_); |
| 147 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); | 147 total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_)); |
| 148 return total_rect; | 148 return total_rect; |
| 149 } | 149 } |
| 150 | 150 |
| 151 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { | 151 gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const { |
| 152 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); | 152 return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 155 void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
| 156 cc::PaintFlags paint; | 156 cc::PaintFlags flags; |
| 157 paint.setStyle(cc::PaintFlags::kFill_Style); | 157 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 158 paint.setAntiAlias(true); | 158 flags.setAntiAlias(true); |
| 159 paint.setColor(fill_color_); | 159 flags.setColor(fill_color_); |
| 160 | 160 |
| 161 gfx::RectF rrect_bounds = | 161 gfx::RectF rrect_bounds = |
| 162 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); | 162 gfx::RectF(bounds_ - GetPaintedBounds().OffsetFromOrigin()); |
| 163 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), | 163 SkRRect r_rect = SkRRect::MakeRectXY(gfx::RectFToSkRect(rrect_bounds), |
| 164 corner_radius_, corner_radius_); | 164 corner_radius_, corner_radius_); |
| 165 | 165 |
| 166 // First the fill color. | 166 // First the fill color. |
| 167 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); | 167 ui::PaintRecorder recorder(context, GetPaintedBounds().size()); |
| 168 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); | 168 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); |
| 169 | 169 |
| 170 // Now the shadow. | 170 // Now the shadow. |
| 171 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); | 171 flags.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows_)); |
| 172 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, | 172 recorder.canvas()->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, |
| 173 true); | 173 true); |
| 174 recorder.canvas()->sk_canvas()->drawRRect(r_rect, paint); | 174 recorder.canvas()->sk_canvas()->drawRRect(r_rect, flags); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace views | 177 } // namespace views |
| OLD | NEW |