Index: Source/core/css/CSSBasicShapes.cpp |
diff --git a/Source/core/css/CSSBasicShapes.cpp b/Source/core/css/CSSBasicShapes.cpp |
index e7f03f5c31abc281179e60dc69cf76fcbe92c7c4..147cda676df7f868db918470c3dafbaffe5c0ea9 100644 |
--- a/Source/core/css/CSSBasicShapes.cpp |
+++ b/Source/core/css/CSSBasicShapes.cpp |
@@ -30,7 +30,9 @@ |
#include "config.h" |
#include "core/css/CSSBasicShapes.h" |
+#include "core/css/CSSValuePool.h" |
#include "core/css/Pair.h" |
+#include "platform/Length.h" |
#include "wtf/text/StringBuilder.h" |
using namespace WTF; |
@@ -131,11 +133,56 @@ static String buildCircleString(const String& radius, const String& centerX, con |
return result.toString(); |
} |
+static String serializePositionOffset(const Pair& offset, const Pair& other) |
+{ |
+ if ((offset.first()->getValueID() == CSSValueLeft && other.first()->getValueID() == CSSValueTop) |
+ || (offset.first()->getValueID() == CSSValueTop && other.first()->getValueID() == CSSValueLeft)) |
+ return offset.second()->cssText(); |
+ return offset.cssText(); |
+} |
+ |
+static PassRefPtr<CSSPrimitiveValue> buildSerializablePositionOffset(PassRefPtr<CSSPrimitiveValue> offset, CSSValueID defaultSide) |
+{ |
+ CSSValueID side = defaultSide; |
+ RefPtr<CSSPrimitiveValue> amount; |
+ |
+ if (!offset) { |
+ side = CSSValueCenter; |
+ } else if (offset->isValueID()) { |
+ side = offset->getValueID(); |
+ } else if (Pair* pair = offset->getPairValue()) { |
+ side = pair->first()->getValueID(); |
+ amount = pair->second(); |
+ } else { |
+ amount = offset; |
+ } |
+ |
+ if (side == CSSValueCenter) { |
+ side = defaultSide; |
+ amount = cssValuePool().createValue(Length(50, Percent)); |
+ } else if ((side == CSSValueRight || side == CSSValueBottom) |
+ && amount->isPercentage()) { |
+ side = defaultSide; |
+ amount = cssValuePool().createValue(Length(100 - amount->getFloatValue(), Percent)); |
+ } else if (amount->isLength() && !amount->getFloatValue()) { |
+ if (side == CSSValueRight || side == CSSValueBottom) |
+ amount = cssValuePool().createValue(Length(100, Percent)); |
+ else |
+ amount = cssValuePool().createValue(Length(0, Percent)); |
+ side = defaultSide; |
+ } |
+ |
+ return cssValuePool().createValue(Pair::create(cssValuePool().createValue(side), amount.release(), Pair::KeepIdenticalValues)); |
+} |
+ |
String CSSBasicShapeCircle::cssText() const |
{ |
+ RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft); |
+ RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop); |
+ |
return buildCircleString(m_radius ? m_radius->cssText() : String(), |
- m_centerX ? m_centerX->cssText() : String(), |
- m_centerY ? m_centerY->cssText() : String(), |
+ serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->getPairValue()), |
+ serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->getPairValue()), |
m_layoutBox ? m_layoutBox->cssText() : String()); |
} |
@@ -225,10 +272,13 @@ static String buildEllipseString(const String& radiusX, const String& radiusY, c |
String CSSBasicShapeEllipse::cssText() const |
{ |
+ RefPtr<CSSPrimitiveValue> normalizedCX = buildSerializablePositionOffset(m_centerX, CSSValueLeft); |
+ RefPtr<CSSPrimitiveValue> normalizedCY = buildSerializablePositionOffset(m_centerY, CSSValueTop); |
+ |
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(), |
+ serializePositionOffset(*normalizedCX->getPairValue(), *normalizedCY->getPairValue()), |
+ serializePositionOffset(*normalizedCY->getPairValue(), *normalizedCX->getPairValue()), |
m_layoutBox ? m_layoutBox->cssText() : String()); |
} |