Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: third_party/WebKit/Source/core/layout/shapes/Shape.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 27 matching lines...) Expand all
38 #include "core/layout/shapes/RasterShape.h" 38 #include "core/layout/shapes/RasterShape.h"
39 #include "core/layout/shapes/RectangleShape.h" 39 #include "core/layout/shapes/RectangleShape.h"
40 #include "core/style/ComputedStyle.h" 40 #include "core/style/ComputedStyle.h"
41 #include "core/svg/graphics/SVGImage.h" 41 #include "core/svg/graphics/SVGImage.h"
42 #include "platform/LengthFunctions.h" 42 #include "platform/LengthFunctions.h"
43 #include "platform/geometry/FloatRoundedRect.h" 43 #include "platform/geometry/FloatRoundedRect.h"
44 #include "platform/geometry/FloatSize.h" 44 #include "platform/geometry/FloatSize.h"
45 #include "platform/graphics/GraphicsTypes.h" 45 #include "platform/graphics/GraphicsTypes.h"
46 #include "platform/graphics/ImageBuffer.h" 46 #include "platform/graphics/ImageBuffer.h"
47 #include "wtf/MathExtras.h" 47 #include "wtf/MathExtras.h"
48 #include "wtf/OwnPtr.h" 48 #include "wtf/PtrUtil.h"
49 #include "wtf/typed_arrays/ArrayBufferContents.h" 49 #include "wtf/typed_arrays/ArrayBufferContents.h"
50 #include <memory>
50 51
51 namespace blink { 52 namespace blink {
52 53
53 static PassOwnPtr<Shape> createInsetShape(const FloatRoundedRect& bounds) 54 static std::unique_ptr<Shape> createInsetShape(const FloatRoundedRect& bounds)
54 { 55 {
55 ASSERT(bounds.rect().width() >= 0 && bounds.rect().height() >= 0); 56 ASSERT(bounds.rect().width() >= 0 && bounds.rect().height() >= 0);
56 return adoptPtr(new BoxShape(bounds)); 57 return wrapUnique(new BoxShape(bounds));
57 } 58 }
58 59
59 static PassOwnPtr<Shape> createCircleShape(const FloatPoint& center, float radiu s) 60 static std::unique_ptr<Shape> createCircleShape(const FloatPoint& center, float radius)
60 { 61 {
61 ASSERT(radius >= 0); 62 ASSERT(radius >= 0);
62 return adoptPtr(new RectangleShape(FloatRect(center.x() - radius, center.y() - radius, radius*2, radius*2), FloatSize(radius, radius))); 63 return wrapUnique(new RectangleShape(FloatRect(center.x() - radius, center.y () - radius, radius*2, radius*2), FloatSize(radius, radius)));
63 } 64 }
64 65
65 static PassOwnPtr<Shape> createEllipseShape(const FloatPoint& center, const Floa tSize& radii) 66 static std::unique_ptr<Shape> createEllipseShape(const FloatPoint& center, const FloatSize& radii)
66 { 67 {
67 ASSERT(radii.width() >= 0 && radii.height() >= 0); 68 ASSERT(radii.width() >= 0 && radii.height() >= 0);
68 return adoptPtr(new RectangleShape(FloatRect(center.x() - radii.width(), cen ter.y() - radii.height(), radii.width()*2, radii.height()*2), radii)); 69 return wrapUnique(new RectangleShape(FloatRect(center.x() - radii.width(), c enter.y() - radii.height(), radii.width()*2, radii.height()*2), radii));
69 } 70 }
70 71
71 static PassOwnPtr<Shape> createPolygonShape(PassOwnPtr<Vector<FloatPoint>> verti ces, WindRule fillRule) 72 static std::unique_ptr<Shape> createPolygonShape(std::unique_ptr<Vector<FloatPoi nt>> vertices, WindRule fillRule)
72 { 73 {
73 return adoptPtr(new PolygonShape(std::move(vertices), fillRule)); 74 return wrapUnique(new PolygonShape(std::move(vertices), fillRule));
74 } 75 }
75 76
76 static inline FloatRect physicalRectToLogical(const FloatRect& rect, float logic alBoxHeight, WritingMode writingMode) 77 static inline FloatRect physicalRectToLogical(const FloatRect& rect, float logic alBoxHeight, WritingMode writingMode)
77 { 78 {
78 if (isHorizontalWritingMode(writingMode)) 79 if (isHorizontalWritingMode(writingMode))
79 return rect; 80 return rect;
80 if (isFlippedBlocksWritingMode(writingMode)) 81 if (isFlippedBlocksWritingMode(writingMode))
81 return FloatRect(rect.y(), logicalBoxHeight - rect.maxX(), rect.height() , rect.width()); 82 return FloatRect(rect.y(), logicalBoxHeight - rect.maxX(), rect.height() , rect.width());
82 return rect.transposedRect(); 83 return rect.transposedRect();
83 } 84 }
84 85
85 static inline FloatPoint physicalPointToLogical(const FloatPoint& point, float l ogicalBoxHeight, WritingMode writingMode) 86 static inline FloatPoint physicalPointToLogical(const FloatPoint& point, float l ogicalBoxHeight, WritingMode writingMode)
86 { 87 {
87 if (isHorizontalWritingMode(writingMode)) 88 if (isHorizontalWritingMode(writingMode))
88 return point; 89 return point;
89 if (isFlippedBlocksWritingMode(writingMode)) 90 if (isFlippedBlocksWritingMode(writingMode))
90 return FloatPoint(point.y(), logicalBoxHeight - point.x()); 91 return FloatPoint(point.y(), logicalBoxHeight - point.x());
91 return point.transposedPoint(); 92 return point.transposedPoint();
92 } 93 }
93 94
94 static inline FloatSize physicalSizeToLogical(const FloatSize& size, WritingMode writingMode) 95 static inline FloatSize physicalSizeToLogical(const FloatSize& size, WritingMode writingMode)
95 { 96 {
96 if (isHorizontalWritingMode(writingMode)) 97 if (isHorizontalWritingMode(writingMode))
97 return size; 98 return size;
98 return size.transposedSize(); 99 return size.transposedSize();
99 } 100 }
100 101
101 PassOwnPtr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutS ize& logicalBoxSize, WritingMode writingMode, float margin) 102 std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const La youtSize& logicalBoxSize, WritingMode writingMode, float margin)
102 { 103 {
103 ASSERT(basicShape); 104 ASSERT(basicShape);
104 105
105 bool horizontalWritingMode = isHorizontalWritingMode(writingMode); 106 bool horizontalWritingMode = isHorizontalWritingMode(writingMode);
106 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() : logicalBoxSize.height().toFloat(); 107 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() : logicalBoxSize.height().toFloat();
107 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat() : logicalBoxSize.width().toFloat(); 108 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat() : logicalBoxSize.width().toFloat();
108 OwnPtr<Shape> shape; 109 std::unique_ptr<Shape> shape;
109 110
110 switch (basicShape->type()) { 111 switch (basicShape->type()) {
111 112
112 case BasicShape::BasicShapeCircleType: { 113 case BasicShape::BasicShapeCircleType: {
113 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape); 114 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape);
114 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir cle->centerY(), FloatSize(boxWidth, boxHeight)); 115 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir cle->centerY(), FloatSize(boxWidth, boxHeight));
115 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH eight)); 116 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH eight));
116 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode); 117 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode);
117 118
118 shape = createCircleShape(logicalCenter, radius); 119 shape = createCircleShape(logicalCenter, radius);
119 break; 120 break;
120 } 121 }
121 122
122 case BasicShape::BasicShapeEllipseType: { 123 case BasicShape::BasicShapeEllipseType: {
123 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape); 124 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape);
124 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el lipse->centerY(), FloatSize(boxWidth, boxHeight)); 125 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el lipse->centerY(), FloatSize(boxWidth, boxHeight));
125 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce nter.x(), boxWidth); 126 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce nter.x(), boxWidth);
126 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce nter.y(), boxHeight); 127 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce nter.y(), boxHeight);
127 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode); 128 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode);
128 129
129 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); 130 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY));
130 break; 131 break;
131 } 132 }
132 133
133 case BasicShape::BasicShapePolygonType: { 134 case BasicShape::BasicShapePolygonType: {
134 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape); 135 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape);
135 const Vector<Length>& values = polygon->values(); 136 const Vector<Length>& values = polygon->values();
136 size_t valuesSize = values.size(); 137 size_t valuesSize = values.size();
137 ASSERT(!(valuesSize % 2)); 138 ASSERT(!(valuesSize % 2));
138 OwnPtr<Vector<FloatPoint>> vertices = adoptPtr(new Vector<FloatPoint>(va luesSize / 2)); 139 std::unique_ptr<Vector<FloatPoint>> vertices = wrapUnique(new Vector<Flo atPoint>(valuesSize / 2));
139 for (unsigned i = 0; i < valuesSize; i += 2) { 140 for (unsigned i = 0; i < valuesSize; i += 2) {
140 FloatPoint vertex( 141 FloatPoint vertex(
141 floatValueForLength(values.at(i), boxWidth), 142 floatValueForLength(values.at(i), boxWidth),
142 floatValueForLength(values.at(i + 1), boxHeight)); 143 floatValueForLength(values.at(i + 1), boxHeight));
143 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h eight().toFloat(), writingMode); 144 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h eight().toFloat(), writingMode);
144 } 145 }
145 shape = createPolygonShape(std::move(vertices), polygon->getWindRule()); 146 shape = createPolygonShape(std::move(vertices), polygon->getWindRule());
146 break; 147 break;
147 } 148 }
148 149
(...skipping 23 matching lines...) Expand all
172 default: 173 default:
173 ASSERT_NOT_REACHED(); 174 ASSERT_NOT_REACHED();
174 } 175 }
175 176
176 shape->m_writingMode = writingMode; 177 shape->m_writingMode = writingMode;
177 shape->m_margin = margin; 178 shape->m_margin = margin;
178 179
179 return shape; 180 return shape;
180 } 181 }
181 182
182 PassOwnPtr<Shape> Shape::createEmptyRasterShape(WritingMode writingMode, float m argin) 183 std::unique_ptr<Shape> Shape::createEmptyRasterShape(WritingMode writingMode, fl oat margin)
183 { 184 {
184 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(0 , 0)); 185 std::unique_ptr<RasterShapeIntervals> intervals = wrapUnique(new RasterShape Intervals(0, 0));
185 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(std::move(interva ls), IntSize())); 186 std::unique_ptr<RasterShape> rasterShape = wrapUnique(new RasterShape(std::m ove(intervals), IntSize()));
186 rasterShape->m_writingMode = writingMode; 187 rasterShape->m_writingMode = writingMode;
187 rasterShape->m_margin = margin; 188 rasterShape->m_margin = margin;
188 return std::move(rasterShape); 189 return std::move(rasterShape);
189 } 190 }
190 191
191 PassOwnPtr<Shape> Shape::createRasterShape(Image* image, float threshold, const LayoutRect& imageR, const LayoutRect& marginR, WritingMode writingMode, float ma rgin) 192 std::unique_ptr<Shape> Shape::createRasterShape(Image* image, float threshold, c onst LayoutRect& imageR, const LayoutRect& marginR, WritingMode writingMode, flo at margin)
192 { 193 {
193 IntRect imageRect = pixelSnappedIntRect(imageR); 194 IntRect imageRect = pixelSnappedIntRect(imageR);
194 IntRect marginRect = pixelSnappedIntRect(marginR); 195 IntRect marginRect = pixelSnappedIntRect(marginR);
195 196
196 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(m arginRect.height(), -marginRect.y())); 197 std::unique_ptr<RasterShapeIntervals> intervals = wrapUnique(new RasterShape Intervals(marginRect.height(), -marginRect.y()));
197 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageRect.size()); 198 std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::create(imageRect.siz e());
198 199
199 if (image && imageBuffer) { 200 if (image && imageBuffer) {
200 // FIXME: This is not totally correct but it is needed to prevent shapes 201 // FIXME: This is not totally correct but it is needed to prevent shapes
201 // that loads SVG Images during paint invalidations to mark layoutObject s for 202 // that loads SVG Images during paint invalidations to mark layoutObject s for
202 // layout, which is not allowed. See https://crbug.com/429346 203 // layout, which is not allowed. See https://crbug.com/429346
203 ImageObserverDisabler disabler(image); 204 ImageObserverDisabler disabler(image);
204 SkPaint paint; 205 SkPaint paint;
205 IntRect imageSourceRect(IntPoint(), image->size()); 206 IntRect imageSourceRect(IntPoint(), image->size());
206 IntRect imageDestRect(IntPoint(), imageRect.size()); 207 IntRect imageDestRect(IntPoint(), imageRect.size());
207 image->draw(imageBuffer->canvas(), paint, imageDestRect, imageSourceRect , DoNotRespectImageOrientation, Image::DoNotClampImageToSourceRect); 208 image->draw(imageBuffer->canvas(), paint, imageDestRect, imageSourceRect , DoNotRespectImageOrientation, Image::DoNotClampImageToSourceRect);
(...skipping 19 matching lines...) Expand all
227 startX = x; 228 startX = x;
228 } else if (startX != -1 && (!alphaAboveThreshold || x == imageRe ct.width() - 1)) { 229 } else if (startX != -1 && (!alphaAboveThreshold || x == imageRe ct.width() - 1)) {
229 int endX = alphaAboveThreshold ? x + 1 : x; 230 int endX = alphaAboveThreshold ? x + 1 : x;
230 intervals->intervalAt(y + imageRect.y()).unite(IntShapeInter val(startX + imageRect.x(), endX + imageRect.x())); 231 intervals->intervalAt(y + imageRect.y()).unite(IntShapeInter val(startX + imageRect.x(), endX + imageRect.x()));
231 startX = -1; 232 startX = -1;
232 } 233 }
233 } 234 }
234 } 235 }
235 } 236 }
236 237
237 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(std::move(interva ls), marginRect.size())); 238 std::unique_ptr<RasterShape> rasterShape = wrapUnique(new RasterShape(std::m ove(intervals), marginRect.size()));
238 rasterShape->m_writingMode = writingMode; 239 rasterShape->m_writingMode = writingMode;
239 rasterShape->m_margin = margin; 240 rasterShape->m_margin = margin;
240 return std::move(rasterShape); 241 return std::move(rasterShape);
241 } 242 }
242 243
243 PassOwnPtr<Shape> Shape::createLayoutBoxShape(const FloatRoundedRect& roundedRec t, WritingMode writingMode, float margin) 244 std::unique_ptr<Shape> Shape::createLayoutBoxShape(const FloatRoundedRect& round edRect, WritingMode writingMode, float margin)
244 { 245 {
245 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height() ); 246 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height() );
246 FloatRoundedRect bounds(rect, roundedRect.getRadii()); 247 FloatRoundedRect bounds(rect, roundedRect.getRadii());
247 OwnPtr<Shape> shape = createInsetShape(bounds); 248 std::unique_ptr<Shape> shape = createInsetShape(bounds);
248 shape->m_writingMode = writingMode; 249 shape->m_writingMode = writingMode;
249 shape->m_margin = margin; 250 shape->m_margin = margin;
250 251
251 return shape; 252 return shape;
252 } 253 }
253 254
254 } // namespace blink 255 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/shapes/Shape.h ('k') | third_party/WebKit/Source/core/layout/shapes/ShapeOutsideInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698