Chromium Code Reviews| Index: Source/core/css/CSSBasicShapes.cpp |
| diff --git a/Source/core/css/CSSBasicShapes.cpp b/Source/core/css/CSSBasicShapes.cpp |
| index 1104f176ef96fcff14c0862a34fdc729007ed307..468d9041177bf5093759fdac7e8e02c83e9331f5 100644 |
| --- a/Source/core/css/CSSBasicShapes.cpp |
| +++ b/Source/core/css/CSSBasicShapes.cpp |
| @@ -107,14 +107,41 @@ bool CSSBasicShapeRectangle::hasVariableReference() const |
| || (m_radiusY.get() && m_radiusY->hasVariableReference()); |
| } |
| -static String buildCircleString(const String& x, const String& y, const String& radius) |
| +static String buildCircleString(const String& radius, const String& centerX, const String& centerY, const String& box) |
| { |
| - return "circle(" + x + ", " + y + ", " + radius + ')'; |
| + char opening[] = "circle("; |
| + char at[] = "at"; |
| + char separator[] = " "; |
| + StringBuilder result; |
| + // Compute the required capacity in advance to reduce allocations. |
| + result.reserveCapacity((sizeof(opening) - 1) + (3 * (sizeof(separator) - 1)) + 1 + radius.length() + sizeof(at) + centerX.length() + centerY.length()); |
|
bemjb
2013/12/07 00:05:32
It looks like you didn't pull the latest patch: I'
|
| + result.append(opening); |
| + if (!radius.isNull()) |
| + result.append(radius); |
| + |
| + if (!centerX.isNull() || !centerY.isNull()) { |
| + if (!radius.isNull()) |
| + result.append(separator); |
| + result.append(at); |
| + result.append(separator); |
| + result.append(centerX); |
| + result.append(separator); |
| + result.append(centerY); |
| + } |
| + result.append(")"); |
| + if (box.length()) { |
| + result.append(separator); |
| + result.append(box); |
| + } |
| + return result.toString(); |
| } |
| String CSSBasicShapeCircle::cssText() const |
| { |
| - return buildCircleString(m_centerX->cssText(), m_centerY->cssText(), m_radius->cssText()); |
| + return buildCircleString(m_radius ? m_radius->cssText() : String(), |
| + m_centerX ? m_centerX->cssText() : String(), |
| + m_centerY ? m_centerY->cssText() : String(), |
| + m_box ? m_box->cssText() : String()); |
| } |
| bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
| @@ -125,31 +152,103 @@ bool CSSBasicShapeCircle::equals(const CSSBasicShape& shape) const |
| const CSSBasicShapeCircle& other = static_cast<const CSSBasicShapeCircle&>(shape); |
| return compareCSSValuePtr(m_centerX, other.m_centerX) |
| && compareCSSValuePtr(m_centerY, other.m_centerY) |
| - && compareCSSValuePtr(m_radius, other.m_radius); |
| + && compareCSSValuePtr(m_radius, other.m_radius) |
| + && compareCSSValuePtr(m_box, other.m_box); |
| } |
| String CSSBasicShapeCircle::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const |
| { |
| - return buildCircleString(m_centerX->serializeResolvingVariables(variables), |
| + return buildCircleString(m_radius.get() ? m_radius->serializeResolvingVariables(variables) : String(), |
| + m_centerX.get() ? m_centerX->serializeResolvingVariables(variables) : String(), |
| + m_centerY.get() ? m_centerY->serializeResolvingVariables(variables) : String(), |
| + m_box.get() ? m_box->serializeResolvingVariables(variables) : String()); |
| +} |
| + |
| +bool CSSBasicShapeCircle::hasVariableReference() const |
| +{ |
| + return (m_centerX && m_centerX->hasVariableReference()) |
| + || (m_centerY && m_centerY->hasVariableReference()) |
| + || (m_radius && m_radius->hasVariableReference()); |
| +} |
| + |
| +static String buildDeprecatedCircleString(const String& x, const String& y, const String& radius) |
| +{ |
| + return "circle(" + x + ", " + y + ", " + radius + ')'; |
| +} |
| + |
| +String CSSDeprecatedBasicShapeCircle::cssText() const |
| +{ |
| + return buildDeprecatedCircleString(m_centerX->cssText(), m_centerY->cssText(), m_radius->cssText()); |
| +} |
| + |
| +bool CSSDeprecatedBasicShapeCircle::equals(const CSSBasicShape& shape) const |
| +{ |
| + if (shape.type() != CSSDeprecatedBasicShapeCircleType) |
| + return false; |
| + |
| + const CSSDeprecatedBasicShapeCircle& other = static_cast<const CSSDeprecatedBasicShapeCircle&>(shape); |
| + return compareCSSValuePtr(m_centerX, other.m_centerX) |
| + && compareCSSValuePtr(m_centerY, other.m_centerY) |
| + && compareCSSValuePtr(m_radius, other.m_radius); |
| +} |
| + |
| +String CSSDeprecatedBasicShapeCircle::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const |
| +{ |
| + return buildDeprecatedCircleString(m_centerX->serializeResolvingVariables(variables), |
| m_centerY->serializeResolvingVariables(variables), |
| m_radius->serializeResolvingVariables(variables)); |
| } |
| -bool CSSBasicShapeCircle::hasVariableReference() const |
| +bool CSSDeprecatedBasicShapeCircle::hasVariableReference() const |
| { |
| return m_centerX->hasVariableReference() |
| || m_centerY->hasVariableReference() |
| || m_radius->hasVariableReference(); |
| } |
| -static String buildEllipseString(const String& x, const String& y, const String& radiusX, const String& radiusY) |
| +static String buildEllipseString(const String& radiusX, const String& radiusY, const String& centerX, const String& centerY, const String& box) |
| { |
| - return "ellipse(" + x + ", " + y + ", " + radiusX + ", " + radiusY + ')'; |
| + char opening[] = "ellipse("; |
| + char at[] = "at"; |
| + char separator[] = " "; |
| + StringBuilder result; |
| + result.appendLiteral(opening); |
| + bool needsSeparator = false; |
| + if (!radiusX.isNull()) { |
| + result.append(radiusX); |
| + needsSeparator = true; |
| + } |
| + if (!radiusY.isNull()) { |
| + if (needsSeparator) |
| + result.appendLiteral(separator); |
| + result.append(radiusY); |
| + needsSeparator = true; |
| + } |
| + |
| + if (!centerX.isNull() || !centerY.isNull()) { |
| + if (needsSeparator) |
| + result.appendLiteral(separator); |
| + result.appendLiteral(at); |
| + result.appendLiteral(separator); |
| + result.append(centerX); |
| + result.appendLiteral(separator); |
| + result.append(centerY); |
| + } |
| + result.append(")"); |
| + if (box.length()) { |
| + result.appendLiteral(separator); |
| + result.append(box); |
| + } |
| + return result.toString(); |
| } |
| String CSSBasicShapeEllipse::cssText() const |
| { |
| - return buildEllipseString(m_centerX->cssText(), m_centerY->cssText(), m_radiusX->cssText(), m_radiusY->cssText()); |
| + return buildEllipseString(m_radiusX ? m_radiusX->cssText() : String(), |
| + m_radiusY ? m_radiusY->cssText() : String(), |
| + m_centerX ? m_centerX->cssText() : String(), |
| + m_centerY ? m_centerY->cssText() : String(), |
| + m_box ? m_box->cssText() : String()); |
| } |
| bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
| @@ -161,18 +260,58 @@ bool CSSBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
| return compareCSSValuePtr(m_centerX, other.m_centerX) |
| && compareCSSValuePtr(m_centerY, other.m_centerY) |
| && compareCSSValuePtr(m_radiusX, other.m_radiusX) |
| - && compareCSSValuePtr(m_radiusY, other.m_radiusY); |
| + && compareCSSValuePtr(m_radiusY, other.m_radiusY) |
| + && compareCSSValuePtr(m_box, other.m_box); |
| } |
| String CSSBasicShapeEllipse::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const |
| { |
| - return buildEllipseString(m_centerX->serializeResolvingVariables(variables), |
| + return buildEllipseString(m_radiusX.get() ? m_radiusX->serializeResolvingVariables(variables) : String(), |
| + m_radiusY.get() ? m_radiusY->serializeResolvingVariables(variables) : String(), |
| + m_centerX.get() ? m_centerX->serializeResolvingVariables(variables) : String(), |
| + m_centerY.get() ? m_centerY->serializeResolvingVariables(variables) : String(), |
| + m_box.get() ? m_box->serializeResolvingVariables(variables) : String()); |
| +} |
| + |
| +bool CSSBasicShapeEllipse::hasVariableReference() const |
| +{ |
| + return (m_centerX && m_centerX->hasVariableReference()) |
| + || (m_centerY && m_centerY->hasVariableReference()) |
| + || (m_radiusX && m_radiusX->hasVariableReference()) |
| + || (m_radiusY && m_radiusY->hasVariableReference()); |
| +} |
| + |
| +static String buildDeprecatedEllipseString(const String& x, const String& y, const String& radiusX, const String& radiusY) |
| +{ |
| + return "ellipse(" + x + ", " + y + ", " + radiusX + ", " + radiusY + ')'; |
| +} |
| + |
| +String CSSDeprecatedBasicShapeEllipse::cssText() const |
| +{ |
| + return buildDeprecatedEllipseString(m_centerX->cssText(), m_centerY->cssText(), m_radiusX->cssText(), m_radiusY->cssText()); |
| +} |
| + |
| +bool CSSDeprecatedBasicShapeEllipse::equals(const CSSBasicShape& shape) const |
| +{ |
| + if (shape.type() != CSSDeprecatedBasicShapeEllipseType) |
| + return false; |
| + |
| + const CSSDeprecatedBasicShapeEllipse& other = static_cast<const CSSDeprecatedBasicShapeEllipse&>(shape); |
| + return compareCSSValuePtr(m_centerX, other.m_centerX) |
| + && compareCSSValuePtr(m_centerY, other.m_centerY) |
| + && compareCSSValuePtr(m_radiusX, other.m_radiusX) |
| + && compareCSSValuePtr(m_radiusY, other.m_radiusY); |
| +} |
| + |
| +String CSSDeprecatedBasicShapeEllipse::serializeResolvingVariables(const HashMap<AtomicString, String>& variables) const |
| +{ |
| + return buildDeprecatedEllipseString(m_centerX->serializeResolvingVariables(variables), |
| m_centerY->serializeResolvingVariables(variables), |
| m_radiusX->serializeResolvingVariables(variables), |
| m_radiusY->serializeResolvingVariables(variables)); |
| } |
| -bool CSSBasicShapeEllipse::hasVariableReference() const |
| +bool CSSDeprecatedBasicShapeEllipse::hasVariableReference() const |
| { |
| return m_centerX->hasVariableReference() |
| || m_centerY->hasVariableReference() |