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

Side by Side Diff: sky/engine/core/rendering/shapes/Shape.cpp

Issue 683803006: Remove all writing mode function arguments and remove writing mode from RenderStyle. (Closed) Base URL: git@github.com:domokit/mojo.git@writingmode
Patch Set: Created 6 years, 1 month 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 { 63 {
64 ASSERT(radii.width() >= 0 && radii.height() >= 0); 64 ASSERT(radii.width() >= 0 && radii.height() >= 0);
65 return adoptPtr(new RectangleShape(FloatRect(center.x() - radii.width(), cen ter.y() - radii.height(), radii.width()*2, radii.height()*2), radii)); 65 return adoptPtr(new RectangleShape(FloatRect(center.x() - radii.width(), cen ter.y() - radii.height(), radii.width()*2, radii.height()*2), radii));
66 } 66 }
67 67
68 static PassOwnPtr<Shape> createPolygonShape(PassOwnPtr<Vector<FloatPoint> > vert ices, WindRule fillRule) 68 static PassOwnPtr<Shape> createPolygonShape(PassOwnPtr<Vector<FloatPoint> > vert ices, WindRule fillRule)
69 { 69 {
70 return adoptPtr(new PolygonShape(vertices, fillRule)); 70 return adoptPtr(new PolygonShape(vertices, fillRule));
71 } 71 }
72 72
73 static inline FloatRect physicalRectToLogical(const FloatRect& rect, float logic alBoxHeight, WritingMode writingMode) 73 static inline FloatRect physicalRectToLogical(const FloatRect& rect, float logic alBoxHeight)
74 { 74 {
75 if (isHorizontalWritingMode(writingMode)) 75 if (isHorizontalWritingMode())
76 return rect; 76 return rect;
77 if (isFlippedBlocksWritingMode(writingMode)) 77 if (isFlippedBlocksWritingMode())
78 return FloatRect(rect.y(), logicalBoxHeight - rect.maxX(), rect.height() , rect.width()); 78 return FloatRect(rect.y(), logicalBoxHeight - rect.maxX(), rect.height() , rect.width());
79 return rect.transposedRect(); 79 return rect.transposedRect();
80 } 80 }
81 81
82 static inline FloatPoint physicalPointToLogical(const FloatPoint& point, float l ogicalBoxHeight, WritingMode writingMode) 82 static inline FloatPoint physicalPointToLogical(const FloatPoint& point, float l ogicalBoxHeight)
83 { 83 {
84 if (isHorizontalWritingMode(writingMode)) 84 if (isHorizontalWritingMode())
85 return point; 85 return point;
86 if (isFlippedBlocksWritingMode(writingMode)) 86 if (isFlippedBlocksWritingMode())
87 return FloatPoint(point.y(), logicalBoxHeight - point.x()); 87 return FloatPoint(point.y(), logicalBoxHeight - point.x());
88 return point.transposedPoint(); 88 return point.transposedPoint();
89 } 89 }
90 90
91 static inline FloatSize physicalSizeToLogical(const FloatSize& size, WritingMode writingMode) 91 static inline FloatSize physicalSizeToLogical(const FloatSize& size)
92 { 92 {
93 if (isHorizontalWritingMode(writingMode)) 93 if (isHorizontalWritingMode())
94 return size; 94 return size;
95 return size.transposedSize(); 95 return size.transposedSize();
96 } 96 }
97 97
98 PassOwnPtr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutS ize& logicalBoxSize, WritingMode writingMode, float margin) 98 PassOwnPtr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutS ize& logicalBoxSize, float margin)
99 { 99 {
100 ASSERT(basicShape); 100 ASSERT(basicShape);
101 101
102 bool horizontalWritingMode = isHorizontalWritingMode(writingMode); 102 bool horizontalWritingMode = isHorizontalWritingMode();
103 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() : logicalBoxSize.height().toFloat(); 103 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() : logicalBoxSize.height().toFloat();
104 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat() : logicalBoxSize.width().toFloat(); 104 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat() : logicalBoxSize.width().toFloat();
105 OwnPtr<Shape> shape; 105 OwnPtr<Shape> shape;
106 106
107 switch (basicShape->type()) { 107 switch (basicShape->type()) {
108 108
109 case BasicShape::BasicShapeCircleType: { 109 case BasicShape::BasicShapeCircleType: {
110 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape); 110 const BasicShapeCircle* circle = toBasicShapeCircle(basicShape);
111 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir cle->centerY(), FloatSize(boxWidth, boxHeight)); 111 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir cle->centerY(), FloatSize(boxWidth, boxHeight));
112 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH eight)); 112 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH eight));
113 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode); 113 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat());
114 114
115 shape = createCircleShape(logicalCenter, radius); 115 shape = createCircleShape(logicalCenter, radius);
116 break; 116 break;
117 } 117 }
118 118
119 case BasicShape::BasicShapeEllipseType: { 119 case BasicShape::BasicShapeEllipseType: {
120 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape); 120 const BasicShapeEllipse* ellipse = toBasicShapeEllipse(basicShape);
121 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el lipse->centerY(), FloatSize(boxWidth, boxHeight)); 121 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el lipse->centerY(), FloatSize(boxWidth, boxHeight));
122 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce nter.x(), boxWidth); 122 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce nter.x(), boxWidth);
123 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce nter.y(), boxHeight); 123 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce nter.y(), boxHeight);
124 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat(), writingMode); 124 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize .height().toFloat());
125 125
126 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); 126 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY));
127 break; 127 break;
128 } 128 }
129 129
130 case BasicShape::BasicShapePolygonType: { 130 case BasicShape::BasicShapePolygonType: {
131 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape); 131 const BasicShapePolygon* polygon = toBasicShapePolygon(basicShape);
132 const Vector<Length>& values = polygon->values(); 132 const Vector<Length>& values = polygon->values();
133 size_t valuesSize = values.size(); 133 size_t valuesSize = values.size();
134 ASSERT(!(valuesSize % 2)); 134 ASSERT(!(valuesSize % 2));
135 OwnPtr<Vector<FloatPoint> > vertices = adoptPtr(new Vector<FloatPoint>(v aluesSize / 2)); 135 OwnPtr<Vector<FloatPoint> > vertices = adoptPtr(new Vector<FloatPoint>(v aluesSize / 2));
136 for (unsigned i = 0; i < valuesSize; i += 2) { 136 for (unsigned i = 0; i < valuesSize; i += 2) {
137 FloatPoint vertex( 137 FloatPoint vertex(
138 floatValueForLength(values.at(i), boxWidth), 138 floatValueForLength(values.at(i), boxWidth),
139 floatValueForLength(values.at(i + 1), boxHeight)); 139 floatValueForLength(values.at(i + 1), boxHeight));
140 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h eight().toFloat(), writingMode); 140 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h eight().toFloat());
141 } 141 }
142 shape = createPolygonShape(vertices.release(), polygon->windRule()); 142 shape = createPolygonShape(vertices.release(), polygon->windRule());
143 break; 143 break;
144 } 144 }
145 145
146 case BasicShape::BasicShapeInsetType: { 146 case BasicShape::BasicShapeInsetType: {
147 const BasicShapeInset& inset = *toBasicShapeInset(basicShape); 147 const BasicShapeInset& inset = *toBasicShapeInset(basicShape);
148 float left = floatValueForLength(inset.left(), boxWidth); 148 float left = floatValueForLength(inset.left(), boxWidth);
149 float top = floatValueForLength(inset.top(), boxHeight); 149 float top = floatValueForLength(inset.top(), boxHeight);
150 float right = floatValueForLength(inset.right(), boxWidth); 150 float right = floatValueForLength(inset.right(), boxWidth);
151 float bottom = floatValueForLength(inset.bottom(), boxHeight); 151 float bottom = floatValueForLength(inset.bottom(), boxHeight);
152 FloatRect rect(left, top, std::max<float>(boxWidth - left - right, 0), s td::max<float>(boxHeight - top - bottom, 0)); 152 FloatRect rect(left, top, std::max<float>(boxWidth - left - right, 0), s td::max<float>(boxHeight - top - bottom, 0));
153 FloatRect logicalRect = physicalRectToLogical(rect, logicalBoxSize.heigh t().toFloat(), writingMode); 153 FloatRect logicalRect = physicalRectToLogical(rect, logicalBoxSize.heigh t().toFloat());
154 154
155 FloatSize boxSize(boxWidth, boxHeight); 155 FloatSize boxSize(boxWidth, boxHeight);
156 FloatSize topLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(i nset.topLeftRadius(), boxSize), writingMode); 156 FloatSize topLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(i nset.topLeftRadius(), boxSize));
157 FloatSize topRightRadius = physicalSizeToLogical(floatSizeForLengthSize( inset.topRightRadius(), boxSize), writingMode); 157 FloatSize topRightRadius = physicalSizeToLogical(floatSizeForLengthSize( inset.topRightRadius(), boxSize));
158 FloatSize bottomLeftRadius = physicalSizeToLogical(floatSizeForLengthSiz e(inset.bottomLeftRadius(), boxSize), writingMode); 158 FloatSize bottomLeftRadius = physicalSizeToLogical(floatSizeForLengthSiz e(inset.bottomLeftRadius(), boxSize));
159 FloatSize bottomRightRadius = physicalSizeToLogical(floatSizeForLengthSi ze(inset.bottomRightRadius(), boxSize), writingMode); 159 FloatSize bottomRightRadius = physicalSizeToLogical(floatSizeForLengthSi ze(inset.bottomRightRadius(), boxSize));
160 FloatRoundedRect::Radii cornerRadii(topLeftRadius, topRightRadius, botto mLeftRadius, bottomRightRadius); 160 FloatRoundedRect::Radii cornerRadii(topLeftRadius, topRightRadius, botto mLeftRadius, bottomRightRadius);
161 161
162 cornerRadii.scale(calcBorderRadiiConstraintScaleFor(logicalRect, cornerR adii)); 162 cornerRadii.scale(calcBorderRadiiConstraintScaleFor(logicalRect, cornerR adii));
163 163
164 shape = createInsetShape(FloatRoundedRect(logicalRect, cornerRadii)); 164 shape = createInsetShape(FloatRoundedRect(logicalRect, cornerRadii));
165 break; 165 break;
166 } 166 }
167 167
168 default: 168 default:
169 ASSERT_NOT_REACHED(); 169 ASSERT_NOT_REACHED();
170 } 170 }
171 171
172 shape->m_writingMode = writingMode;
173 shape->m_margin = margin; 172 shape->m_margin = margin;
174 173
175 return shape.release(); 174 return shape.release();
176 } 175 }
177 176
178 PassOwnPtr<Shape> Shape::createEmptyRasterShape(WritingMode writingMode, float m argin) 177 PassOwnPtr<Shape> Shape::createEmptyRasterShape(float margin)
179 { 178 {
180 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(0 , 0)); 179 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(0 , 0));
181 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), IntSize())); 180 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), IntSize()));
182 rasterShape->m_writingMode = writingMode;
183 rasterShape->m_margin = margin; 181 rasterShape->m_margin = margin;
184 return rasterShape.release(); 182 return rasterShape.release();
185 } 183 }
186 184
187 PassOwnPtr<Shape> Shape::createRasterShape(Image* image, float threshold, const LayoutRect& imageR, const LayoutRect& marginR, WritingMode writingMode, float ma rgin) 185 PassOwnPtr<Shape> Shape::createRasterShape(Image* image, float threshold, const LayoutRect& imageR, const LayoutRect& marginR, float margin)
188 { 186 {
189 IntRect imageRect = pixelSnappedIntRect(imageR); 187 IntRect imageRect = pixelSnappedIntRect(imageR);
190 IntRect marginRect = pixelSnappedIntRect(marginR); 188 IntRect marginRect = pixelSnappedIntRect(marginR);
191 189
192 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(m arginRect.height(), -marginRect.y())); 190 OwnPtr<RasterShapeIntervals> intervals = adoptPtr(new RasterShapeIntervals(m arginRect.height(), -marginRect.y()));
193 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageRect.size()); 191 OwnPtr<ImageBuffer> imageBuffer = ImageBuffer::create(imageRect.size());
194 192
195 if (imageBuffer) { 193 if (imageBuffer) {
196 GraphicsContext* graphicsContext = imageBuffer->context(); 194 GraphicsContext* graphicsContext = imageBuffer->context();
197 graphicsContext->drawImage(image, IntRect(IntPoint(), imageRect.size())) ; 195 graphicsContext->drawImage(image, IntRect(IntPoint(), imageRect.size())) ;
(...skipping 17 matching lines...) Expand all
215 } else if (startX != -1 && (!alphaAboveThreshold || x == imageRe ct.width() - 1)) { 213 } else if (startX != -1 && (!alphaAboveThreshold || x == imageRe ct.width() - 1)) {
216 int endX = alphaAboveThreshold ? x + 1 : x; 214 int endX = alphaAboveThreshold ? x + 1 : x;
217 intervals->intervalAt(y + imageRect.y()).unite(IntShapeInter val(startX + imageRect.x(), endX + imageRect.x())); 215 intervals->intervalAt(y + imageRect.y()).unite(IntShapeInter val(startX + imageRect.x(), endX + imageRect.x()));
218 startX = -1; 216 startX = -1;
219 } 217 }
220 } 218 }
221 } 219 }
222 } 220 }
223 221
224 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), marginRect.size())); 222 OwnPtr<RasterShape> rasterShape = adoptPtr(new RasterShape(intervals.release (), marginRect.size()));
225 rasterShape->m_writingMode = writingMode;
226 rasterShape->m_margin = margin; 223 rasterShape->m_margin = margin;
227 return rasterShape.release(); 224 return rasterShape.release();
228 } 225 }
229 226
230 PassOwnPtr<Shape> Shape::createLayoutBoxShape(const RoundedRect& roundedRect, Wr itingMode writingMode, float margin) 227 PassOwnPtr<Shape> Shape::createLayoutBoxShape(const RoundedRect& roundedRect, fl oat margin)
231 { 228 {
232 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height() ); 229 FloatRect rect(0, 0, roundedRect.rect().width(), roundedRect.rect().height() );
233 FloatRoundedRect bounds(rect, roundedRect.radii()); 230 FloatRoundedRect bounds(rect, roundedRect.radii());
234 OwnPtr<Shape> shape = createInsetShape(bounds); 231 OwnPtr<Shape> shape = createInsetShape(bounds);
235 shape->m_writingMode = writingMode;
236 shape->m_margin = margin; 232 shape->m_margin = margin;
237 233
238 return shape.release(); 234 return shape.release();
239 } 235 }
240 236
241 } // namespace blink 237 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/rendering/shapes/Shape.h ('k') | sky/engine/core/rendering/shapes/ShapeOutsideInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698