Writing-mode-dependent properties don't apply if their value is a variable
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2016 18:33:02 +0000 (18:33 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Jun 2016 18:33:02 +0000 (18:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=158449
<rdar://problem/26662478>

Reviewed by Simon Fraser.

Source/WebCore:

Test: fast/css/variables/direction-dependent-variable-properties.html

* css/CSSParser.cpp:
(WebCore::CSSParser::parseVariableDependentValue):
* css/CSSParser.h:
* css/StyleResolver.cpp:
(WebCore::StyleResolver::resolvedVariableValue):
CSSVariableDependentValue stores the unresolved (direction-dependent) property ID,
because the property that it resolves to cannot be determined until style resolution time.
Plumb the requisite direction and writing mode information into parseVariableDependentValue
at style resolution time so that the property can be resolved to the correct
non-direction-dependent property for each use of the value.

LayoutTests:

* fast/css/variables/direction-dependent-variable-properties-expected.html: Added.
* fast/css/variables/direction-dependent-variable-properties.html: Added.
Add a test ensuring that direction-dependent properties work correctly,
including flipping when the direction is flipped.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@201875 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css/variables/direction-dependent-variable-properties-expected.html [new file with mode: 0644]
LayoutTests/fast/css/variables/direction-dependent-variable-properties.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/StyleResolver.cpp

index 347f969..6628acb 100644 (file)
@@ -1,3 +1,16 @@
+2016-06-09  Tim Horton  <timothy_horton@apple.com>
+
+        Writing-mode-dependent properties don't apply if their value is a variable
+        https://bugs.webkit.org/show_bug.cgi?id=158449
+        <rdar://problem/26662478>
+
+        Reviewed by Simon Fraser.
+
+        * fast/css/variables/direction-dependent-variable-properties-expected.html: Added.
+        * fast/css/variables/direction-dependent-variable-properties.html: Added.
+        Add a test ensuring that direction-dependent properties work correctly,
+        including flipping when the direction is flipped.
+
 2016-06-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Marking editing/selection/selection-in-iframe-removed-crash.html as flaky on Mac
diff --git a/LayoutTests/fast/css/variables/direction-dependent-variable-properties-expected.html b/LayoutTests/fast/css/variables/direction-dependent-variable-properties-expected.html
new file mode 100644 (file)
index 0000000..fb84309
--- /dev/null
@@ -0,0 +1,33 @@
+<head>
+<style>
+.first {
+    padding-left: 50px;
+    padding-right: 25px;
+    height: 50px;
+    margin: 20px;
+}
+
+.second {
+    padding-left: 25px;
+    padding-right: 50px;
+    height: 50px;
+    margin: 20px;
+}
+
+.inner {
+    width: 50px;
+    height: 50px;
+    background-color: blue;
+}
+
+div {
+    display: inline-block;
+    background-color: green;
+}
+</style>
+</head>
+<body>
+    <div class="first"><div class="inner"></div></div>
+    <div class="second"><div class="inner"></div></div>
+</body>
+</html>
\ No newline at end of file
diff --git a/LayoutTests/fast/css/variables/direction-dependent-variable-properties.html b/LayoutTests/fast/css/variables/direction-dependent-variable-properties.html
new file mode 100644 (file)
index 0000000..637127c
--- /dev/null
@@ -0,0 +1,31 @@
+<head>
+<style>
+body {
+    --large: 50px;
+    --small: 25px;
+}
+
+.first {
+    -webkit-padding-start: var(--large);
+    -webkit-padding-end: var(--small);
+    height: 50px;
+    margin: 20px;
+}
+
+.inner {
+    width: 50px;
+    height: 50px;
+    background-color: blue;
+}
+
+div {
+    display: inline-block;
+    background-color: green;
+}
+</style>
+</head>
+<body>
+    <div class="first"><div class="inner"></div></div>
+    <span dir="rtl"><div class="first"><div class="inner"></div></div></span>
+</body>
+</html>
\ No newline at end of file
index 09e2eb8..ee43fae 100644 (file)
@@ -1,3 +1,24 @@
+2016-06-09  Tim Horton  <timothy_horton@apple.com>
+
+        Writing-mode-dependent properties don't apply if their value is a variable
+        https://bugs.webkit.org/show_bug.cgi?id=158449
+        <rdar://problem/26662478>
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/css/variables/direction-dependent-variable-properties.html
+
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseVariableDependentValue):
+        * css/CSSParser.h:
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::resolvedVariableValue):
+        CSSVariableDependentValue stores the unresolved (direction-dependent) property ID,
+        because the property that it resolves to cannot be determined until style resolution time.
+        Plumb the requisite direction and writing mode information into parseVariableDependentValue
+        at style resolution time so that the property can be resolved to the correct
+        non-direction-dependent property for each use of the value.
+
 2016-06-09  Ryan Haddad  <ryanhaddad@apple.com>
 
         Attempt to fix the iOS build.
index 57dab02..479c681 100644 (file)
@@ -1856,13 +1856,19 @@ void CSSParser::addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&
         addProperty(longhands[i], value.copyRef(), important);
 }
 
-RefPtr<CSSValue> CSSParser::parseVariableDependentValue(CSSPropertyID propID, const CSSVariableDependentValue& dependentValue, const CustomPropertyValueMap& customProperties)
+RefPtr<CSSValue> CSSParser::parseVariableDependentValue(CSSPropertyID propID, const CSSVariableDependentValue& dependentValue, const CustomPropertyValueMap& customProperties, TextDirection direction, WritingMode writingMode)
 {
     m_valueList.reset(new CSSParserValueList());
     if (!dependentValue.valueList().buildParserValueListSubstitutingVariables(m_valueList.get(), customProperties))
         return nullptr;
-    if (!parseValue(dependentValue.propertyID(), false))
+
+    CSSPropertyID dependentValuePropertyID = dependentValue.propertyID();
+    if (CSSProperty::isDirectionAwareProperty(dependentValuePropertyID))
+        dependentValuePropertyID = CSSProperty::resolveDirectionAwareProperty(dependentValuePropertyID, direction, writingMode);
+
+    if (!parseValue(dependentValuePropertyID, false))
         return nullptr;
+
     for (auto& property : m_parsedProperties) {
         if (property.id() == propID)
             return property.value();
index 9642086..139dec3 100644 (file)
@@ -499,7 +499,7 @@ public:
 
     void setCustomPropertyName(const AtomicString& propertyName) { m_customPropertyName = propertyName; }
 
-    RefPtr<CSSValue> parseVariableDependentValue(CSSPropertyID, const CSSVariableDependentValue&, const CustomPropertyValueMap& customProperties);
+    RefPtr<CSSValue> parseVariableDependentValue(CSSPropertyID, const CSSVariableDependentValue&, const CustomPropertyValueMap& customProperties, TextDirection, WritingMode);
 
 private:
     bool is8BitSource() { return m_is8BitSource; }
index 2b154ad..f44a8dc 100644 (file)
@@ -1698,7 +1698,7 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue* value, SelectorChe
 RefPtr<CSSValue> StyleResolver::resolvedVariableValue(CSSPropertyID propID, const CSSVariableDependentValue& value)
 {
     CSSParser parser(m_state.document());
-    return parser.parseVariableDependentValue(propID, value, m_state.style()->customProperties());
+    return parser.parseVariableDependentValue(propID, value, m_state.style()->customProperties(), m_state.style()->direction(), m_state.style()->writingMode());
 }
 
 RefPtr<StyleImage> StyleResolver::styleImage(CSSPropertyID property, CSSValue& value)