| OLD | NEW |
| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 radii.setWidth(reductionRatio * radii.width()); | 109 radii.setWidth(reductionRatio * radii.width()); |
| 110 radii.setHeight(reductionRatio * radii.height()); | 110 radii.setHeight(reductionRatio * radii.height()); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 PassOwnPtr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutS
ize& logicalBoxSize, WritingMode writingMode, Length margin, Length padding) | 114 PassOwnPtr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutS
ize& logicalBoxSize, WritingMode writingMode, Length margin, Length padding) |
| 115 { | 115 { |
| 116 ASSERT(basicShape); | 116 ASSERT(basicShape); |
| 117 | 117 |
| 118 bool horizontalWritingMode = isHorizontalWritingMode(writingMode); | 118 bool horizontalWritingMode = isHorizontalWritingMode(writingMode); |
| 119 float boxWidth = horizontalWritingMode ? logicalBoxSize.width() : logicalBox
Size.height(); | 119 float boxWidth = horizontalWritingMode ? logicalBoxSize.width().toFloat() :
logicalBoxSize.height().toFloat(); |
| 120 float boxHeight = horizontalWritingMode ? logicalBoxSize.height() : logicalB
oxSize.width(); | 120 float boxHeight = horizontalWritingMode ? logicalBoxSize.height().toFloat()
: logicalBoxSize.width().toFloat(); |
| 121 OwnPtr<Shape> shape; | 121 OwnPtr<Shape> shape; |
| 122 | 122 |
| 123 switch (basicShape->type()) { | 123 switch (basicShape->type()) { |
| 124 | 124 |
| 125 case BasicShape::BasicShapeRectangleType: { | 125 case BasicShape::BasicShapeRectangleType: { |
| 126 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); | 126 const BasicShapeRectangle* rectangle = static_cast<const BasicShapeRecta
ngle*>(basicShape); |
| 127 FloatRect bounds( | 127 FloatRect bounds( |
| 128 floatValueForLength(rectangle->x(), boxWidth), | 128 floatValueForLength(rectangle->x(), boxWidth), |
| 129 floatValueForLength(rectangle->y(), boxHeight), | 129 floatValueForLength(rectangle->y(), boxHeight), |
| 130 floatValueForLength(rectangle->width(), boxWidth), | 130 floatValueForLength(rectangle->width(), boxWidth), |
| 131 floatValueForLength(rectangle->height(), boxHeight)); | 131 floatValueForLength(rectangle->height(), boxHeight)); |
| 132 FloatSize cornerRadii( | 132 FloatSize cornerRadii( |
| 133 floatValueForLength(rectangle->cornerRadiusX(), boxWidth), | 133 floatValueForLength(rectangle->cornerRadiusX(), boxWidth), |
| 134 floatValueForLength(rectangle->cornerRadiusY(), boxHeight)); | 134 floatValueForLength(rectangle->cornerRadiusY(), boxHeight)); |
| 135 ensureRadiiDoNotOverlap(bounds, cornerRadii); | 135 ensureRadiiDoNotOverlap(bounds, cornerRadii); |
| 136 FloatRect logicalBounds = physicalRectToLogical(bounds, logicalBoxSize.h
eight(), writingMode); | 136 FloatRect logicalBounds = physicalRectToLogical(bounds, logicalBoxSize.h
eight().toFloat(), writingMode); |
| 137 | 137 |
| 138 shape = createRectangleShape(logicalBounds, physicalSizeToLogical(corner
Radii, writingMode)); | 138 shape = createRectangleShape(logicalBounds, physicalSizeToLogical(corner
Radii, writingMode)); |
| 139 break; | 139 break; |
| 140 } | 140 } |
| 141 | 141 |
| 142 case BasicShape::DeprecatedBasicShapeCircleType: { | 142 case BasicShape::DeprecatedBasicShapeCircleType: { |
| 143 const DeprecatedBasicShapeCircle* circle = static_cast<const DeprecatedB
asicShapeCircle*>(basicShape); | 143 const DeprecatedBasicShapeCircle* circle = static_cast<const DeprecatedB
asicShapeCircle*>(basicShape); |
| 144 float centerX = floatValueForLength(circle->centerX(), boxWidth); | 144 float centerX = floatValueForLength(circle->centerX(), boxWidth); |
| 145 float centerY = floatValueForLength(circle->centerY(), boxHeight); | 145 float centerY = floatValueForLength(circle->centerY(), boxHeight); |
| 146 // This method of computing the radius is as defined in SVG | 146 // This method of computing the radius is as defined in SVG |
| 147 // (http://www.w3.org/TR/SVG/coords.html#Units). It bases the radius | 147 // (http://www.w3.org/TR/SVG/coords.html#Units). It bases the radius |
| 148 // off of the diagonal of the box and ensures that if the box is | 148 // off of the diagonal of the box and ensures that if the box is |
| 149 // square, the radius is equal to half the diagonal. | 149 // square, the radius is equal to half the diagonal. |
| 150 float radius = floatValueForLength(circle->radius(), sqrtf((boxWidth * b
oxWidth + boxHeight * boxHeight) / 2)); | 150 float radius = floatValueForLength(circle->radius(), sqrtf((boxWidth * b
oxWidth + boxHeight * boxHeight) / 2)); |
| 151 FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, ce
nterY), logicalBoxSize.height(), writingMode); | 151 FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, ce
nterY), logicalBoxSize.height().toFloat(), writingMode); |
| 152 | 152 |
| 153 shape = createCircleShape(logicalCenter, radius); | 153 shape = createCircleShape(logicalCenter, radius); |
| 154 break; | 154 break; |
| 155 } | 155 } |
| 156 | 156 |
| 157 case BasicShape::BasicShapeCircleType: { | 157 case BasicShape::BasicShapeCircleType: { |
| 158 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); | 158 const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(ba
sicShape); |
| 159 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir
cle->centerY(), FloatSize(boxWidth, boxHeight)); | 159 FloatPoint center = floatPointForCenterCoordinate(circle->centerX(), cir
cle->centerY(), FloatSize(boxWidth, boxHeight)); |
| 160 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH
eight)); | 160 float radius = circle->floatValueForRadiusInBox(FloatSize(boxWidth, boxH
eight)); |
| 161 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize
.height(), writingMode); | 161 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize
.height().toFloat(), writingMode); |
| 162 | 162 |
| 163 shape = createCircleShape(logicalCenter, radius); | 163 shape = createCircleShape(logicalCenter, radius); |
| 164 break; | 164 break; |
| 165 } | 165 } |
| 166 | 166 |
| 167 case BasicShape::DeprecatedBasicShapeEllipseType: { | 167 case BasicShape::DeprecatedBasicShapeEllipseType: { |
| 168 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate
dBasicShapeEllipse*>(basicShape); | 168 const DeprecatedBasicShapeEllipse* ellipse = static_cast<const Deprecate
dBasicShapeEllipse*>(basicShape); |
| 169 float centerX = floatValueForLength(ellipse->centerX(), boxWidth); | 169 float centerX = floatValueForLength(ellipse->centerX(), boxWidth); |
| 170 float centerY = floatValueForLength(ellipse->centerY(), boxHeight); | 170 float centerY = floatValueForLength(ellipse->centerY(), boxHeight); |
| 171 float radiusX = floatValueForLength(ellipse->radiusX(), boxWidth); | 171 float radiusX = floatValueForLength(ellipse->radiusX(), boxWidth); |
| 172 float radiusY = floatValueForLength(ellipse->radiusY(), boxHeight); | 172 float radiusY = floatValueForLength(ellipse->radiusY(), boxHeight); |
| 173 FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, ce
nterY), logicalBoxSize.height(), writingMode); | 173 FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, ce
nterY), logicalBoxSize.height().toFloat(), writingMode); |
| 174 FloatSize logicalRadii = physicalSizeToLogical(FloatSize(radiusX, radius
Y), writingMode); | 174 FloatSize logicalRadii = physicalSizeToLogical(FloatSize(radiusX, radius
Y), writingMode); |
| 175 | 175 |
| 176 shape = createEllipseShape(logicalCenter, logicalRadii); | 176 shape = createEllipseShape(logicalCenter, logicalRadii); |
| 177 break; | 177 break; |
| 178 } | 178 } |
| 179 | 179 |
| 180 case BasicShape::BasicShapeEllipseType: { | 180 case BasicShape::BasicShapeEllipseType: { |
| 181 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>
(basicShape); | 181 const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>
(basicShape); |
| 182 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el
lipse->centerY(), FloatSize(boxWidth, boxHeight)); | 182 FloatPoint center = floatPointForCenterCoordinate(ellipse->centerX(), el
lipse->centerY(), FloatSize(boxWidth, boxHeight)); |
| 183 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce
nter.x(), boxWidth); | 183 float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), ce
nter.x(), boxWidth); |
| 184 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce
nter.y(), boxHeight); | 184 float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), ce
nter.y(), boxHeight); |
| 185 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize
.height(), writingMode); | 185 FloatPoint logicalCenter = physicalPointToLogical(center, logicalBoxSize
.height().toFloat(), writingMode); |
| 186 | 186 |
| 187 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); | 187 shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); |
| 188 break; | 188 break; |
| 189 } | 189 } |
| 190 | 190 |
| 191 case BasicShape::BasicShapePolygonType: { | 191 case BasicShape::BasicShapePolygonType: { |
| 192 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>
(basicShape); | 192 const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>
(basicShape); |
| 193 const Vector<Length>& values = polygon->values(); | 193 const Vector<Length>& values = polygon->values(); |
| 194 size_t valuesSize = values.size(); | 194 size_t valuesSize = values.size(); |
| 195 ASSERT(!(valuesSize % 2)); | 195 ASSERT(!(valuesSize % 2)); |
| 196 OwnPtr<Vector<FloatPoint> > vertices = adoptPtr(new Vector<FloatPoint>(v
aluesSize / 2)); | 196 OwnPtr<Vector<FloatPoint> > vertices = adoptPtr(new Vector<FloatPoint>(v
aluesSize / 2)); |
| 197 for (unsigned i = 0; i < valuesSize; i += 2) { | 197 for (unsigned i = 0; i < valuesSize; i += 2) { |
| 198 FloatPoint vertex( | 198 FloatPoint vertex( |
| 199 floatValueForLength(values.at(i), boxWidth), | 199 floatValueForLength(values.at(i), boxWidth), |
| 200 floatValueForLength(values.at(i + 1), boxHeight)); | 200 floatValueForLength(values.at(i + 1), boxHeight)); |
| 201 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h
eight(), writingMode); | 201 (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.h
eight().toFloat(), writingMode); |
| 202 } | 202 } |
| 203 shape = createPolygonShape(vertices.release(), polygon->windRule()); | 203 shape = createPolygonShape(vertices.release(), polygon->windRule()); |
| 204 break; | 204 break; |
| 205 } | 205 } |
| 206 | 206 |
| 207 case BasicShape::BasicShapeInsetRectangleType: { | 207 case BasicShape::BasicShapeInsetRectangleType: { |
| 208 const BasicShapeInsetRectangle* rectangle = static_cast<const BasicShape
InsetRectangle*>(basicShape); | 208 const BasicShapeInsetRectangle* rectangle = static_cast<const BasicShape
InsetRectangle*>(basicShape); |
| 209 float left = floatValueForLength(rectangle->left(), boxWidth); | 209 float left = floatValueForLength(rectangle->left(), boxWidth); |
| 210 float top = floatValueForLength(rectangle->top(), boxHeight); | 210 float top = floatValueForLength(rectangle->top(), boxHeight); |
| 211 float right = floatValueForLength(rectangle->right(), boxWidth); | 211 float right = floatValueForLength(rectangle->right(), boxWidth); |
| 212 float bottom = floatValueForLength(rectangle->bottom(), boxHeight); | 212 float bottom = floatValueForLength(rectangle->bottom(), boxHeight); |
| 213 FloatRect bounds( | 213 FloatRect bounds( |
| 214 left, | 214 left, |
| 215 top, | 215 top, |
| 216 std::max<float>(boxWidth - left - right, 0), | 216 std::max<float>(boxWidth - left - right, 0), |
| 217 std::max<float>(boxHeight - top - bottom, 0)); | 217 std::max<float>(boxHeight - top - bottom, 0)); |
| 218 FloatSize cornerRadii( | 218 FloatSize cornerRadii( |
| 219 floatValueForLength(rectangle->cornerRadiusX(), boxWidth), | 219 floatValueForLength(rectangle->cornerRadiusX(), boxWidth), |
| 220 floatValueForLength(rectangle->cornerRadiusY(), boxHeight)); | 220 floatValueForLength(rectangle->cornerRadiusY(), boxHeight)); |
| 221 ensureRadiiDoNotOverlap(bounds, cornerRadii); | 221 ensureRadiiDoNotOverlap(bounds, cornerRadii); |
| 222 FloatRect logicalBounds = physicalRectToLogical(bounds, logicalBoxSize.h
eight(), writingMode); | 222 FloatRect logicalBounds = physicalRectToLogical(bounds, logicalBoxSize.h
eight().toFloat(), writingMode); |
| 223 | 223 |
| 224 shape = createRectangleShape(logicalBounds, physicalSizeToLogical(corner
Radii, writingMode)); | 224 shape = createRectangleShape(logicalBounds, physicalSizeToLogical(corner
Radii, writingMode)); |
| 225 break; | 225 break; |
| 226 } | 226 } |
| 227 | 227 |
| 228 case BasicShape::BasicShapeInsetType: { | 228 case BasicShape::BasicShapeInsetType: { |
| 229 const BasicShapeInset& inset = *static_cast<const BasicShapeInset*>(basi
cShape); | 229 const BasicShapeInset& inset = *static_cast<const BasicShapeInset*>(basi
cShape); |
| 230 float left = floatValueForLength(inset.left(), boxWidth); | 230 float left = floatValueForLength(inset.left(), boxWidth); |
| 231 float top = floatValueForLength(inset.top(), boxHeight); | 231 float top = floatValueForLength(inset.top(), boxHeight); |
| 232 float right = floatValueForLength(inset.right(), boxWidth); | 232 float right = floatValueForLength(inset.right(), boxWidth); |
| 233 float bottom = floatValueForLength(inset.bottom(), boxHeight); | 233 float bottom = floatValueForLength(inset.bottom(), boxHeight); |
| 234 FloatRect rect(left, top, std::max<float>(boxWidth - left - right, 0), s
td::max<float>(boxHeight - top - bottom, 0)); | 234 FloatRect rect(left, top, std::max<float>(boxWidth - left - right, 0), s
td::max<float>(boxHeight - top - bottom, 0)); |
| 235 FloatRect logicalRect = physicalRectToLogical(rect, logicalBoxSize.heigh
t(), writingMode); | 235 FloatRect logicalRect = physicalRectToLogical(rect, logicalBoxSize.heigh
t().toFloat(), writingMode); |
| 236 | 236 |
| 237 FloatSize boxSize(boxWidth, boxHeight); | 237 FloatSize boxSize(boxWidth, boxHeight); |
| 238 FloatSize topLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(i
nset.topLeftRadius(), boxSize), writingMode); | 238 FloatSize topLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(i
nset.topLeftRadius(), boxSize), writingMode); |
| 239 FloatSize topRightRadius = physicalSizeToLogical(floatSizeForLengthSize(
inset.topRightRadius(), boxSize), writingMode); | 239 FloatSize topRightRadius = physicalSizeToLogical(floatSizeForLengthSize(
inset.topRightRadius(), boxSize), writingMode); |
| 240 FloatSize bottomLeftRadius = physicalSizeToLogical(floatSizeForLengthSiz
e(inset.bottomLeftRadius(), boxSize), writingMode); | 240 FloatSize bottomLeftRadius = physicalSizeToLogical(floatSizeForLengthSiz
e(inset.bottomLeftRadius(), boxSize), writingMode); |
| 241 FloatSize bottomRightRadius = physicalSizeToLogical(floatSizeForLengthSi
ze(inset.bottomRightRadius(), boxSize), writingMode); | 241 FloatSize bottomRightRadius = physicalSizeToLogical(floatSizeForLengthSi
ze(inset.bottomRightRadius(), boxSize), writingMode); |
| 242 FloatRoundedRect::Radii cornerRadii(topLeftRadius, topRightRadius, botto
mLeftRadius, bottomRightRadius); | 242 FloatRoundedRect::Radii cornerRadii(topLeftRadius, topRightRadius, botto
mLeftRadius, bottomRightRadius); |
| 243 | 243 |
| 244 cornerRadii.scale(calcBorderRadiiConstraintScaleFor(logicalRect, cornerR
adii)); | 244 cornerRadii.scale(calcBorderRadiiConstraintScaleFor(logicalRect, cornerR
adii)); |
| 245 | 245 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 FloatRoundedRect bounds(rect, roundedRect.radii()); | 306 FloatRoundedRect bounds(rect, roundedRect.radii()); |
| 307 OwnPtr<Shape> shape = createInsetShape(bounds); | 307 OwnPtr<Shape> shape = createInsetShape(bounds); |
| 308 shape->m_writingMode = writingMode; | 308 shape->m_writingMode = writingMode; |
| 309 shape->m_margin = floatValueForLength(margin, 0); | 309 shape->m_margin = floatValueForLength(margin, 0); |
| 310 shape->m_padding = floatValueForLength(padding, 0); | 310 shape->m_padding = floatValueForLength(padding, 0); |
| 311 | 311 |
| 312 return shape.release(); | 312 return shape.release(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 } // namespace WebCore | 315 } // namespace WebCore |
| OLD | NEW |