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

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

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