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

Unified Diff: Source/core/css/CSSBasicShapes.cpp

Issue 185133006: [CSS Shapes] Serialize circle/ellipse positions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix test expectation Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
}
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698