CSS3 calc: Implement CSSOM support
authormikelawther@chromium.org <mikelawther@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 07:01:08 +0000 (07:01 +0000)
committermikelawther@chromium.org <mikelawther@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 May 2012 07:01:08 +0000 (07:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84551

Reviewed by Ryosuke Niwa.

Source/WebCore:

Adds a pretty printer for the calc expression tree.

Test: css3/calc/cssom.html

* css/CSSCalculationValue.cpp:
(WebCore::CSSCalcValue::customCssText):
(WebCore::CSSCalcPrimitiveValue::customCssText):
(WebCore::CSSCalcBinaryOperation::customCssText):
(CSSCalcBinaryOperation):
* css/CSSCalculationValue.h:
(CSSCalcExpressionNode):

LayoutTests:

* css3/calc/cssom-expected.txt: Added.
* css3/calc/cssom.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/css3/calc/cssom-expected.txt [new file with mode: 0644]
LayoutTests/css3/calc/cssom.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSCalculationValue.h

index e9d0466..c4f4f72 100644 (file)
@@ -1,3 +1,13 @@
+2012-05-30  Mike Lawther  <mikelawther@chromium.org>
+
+        CSS3 calc: Implement CSSOM support
+        https://bugs.webkit.org/show_bug.cgi?id=84551
+
+        Reviewed by Ryosuke Niwa.
+
+        * css3/calc/cssom-expected.txt: Added.
+        * css3/calc/cssom.html: Added.
+
 2012-05-29  Li Yin  <li.yin@intel.com>
 
         [FileAPI] The result attribute of FileReader shuold use null to replace empty string
diff --git a/LayoutTests/css3/calc/cssom-expected.txt b/LayoutTests/css3/calc/cssom-expected.txt
new file mode 100644 (file)
index 0000000..f618429
--- /dev/null
@@ -0,0 +1,15 @@
+This tests calc() and the CSSOM
+
+10px => -webkit-calc(10px)
+10px + 15px => -webkit-calc(10px + 15px)
+100% => -webkit-calc(100%)
+100% - 10px => -webkit-calc(100% - 10px)
+10px + 10px * 5 => -webkit-calc(10px + (10px * 5))
+5px + 2em + 6in => -webkit-calc((5px + 2em) + 6in)
+100% - 10px / 2 => -webkit-calc(100% - (10px / 2))
+1px + 2em - 3rem + 4in => -webkit-calc(((1px + 2em) - 3rem) + 4in)
+100px * (1 + 2 * 3 - 4 / 5) => -webkit-calc(100px * ((1 + (2 * 3)) - (4 / 5)))
+(100px) + 200px => -webkit-calc(100px + 200px)
+((((((((((100px)))))))))) => -webkit-calc(100px)
+flimstix => -webkit-calc(100px)
+
diff --git a/LayoutTests/css3/calc/cssom.html b/LayoutTests/css3/calc/cssom.html
new file mode 100644 (file)
index 0000000..5ffbb47
--- /dev/null
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<div id="dummy"></div>
+<div id="results">This tests calc() and the CSSOM<br><br></div>
+<script>
+if (window.layoutTestController)
+    window.layoutTestController.dumpAsText();
+
+var tests = ["10px", 
+             "10px + 15px", 
+             "100%", 
+             "100% - 10px",
+             "10px + 10px * 5",
+             "5px + 2em + 6in",
+             "100% - 10px / 2",
+             "1px + 2em - 3rem + 4in",
+             "100px * (1 + 2 * 3 - 4 / 5)",
+             "(100px) + 200px",
+             "((((((((((100px))))))))))",
+             "flimstix"];
+             
+var results = document.getElementById("results");
+var dummy = document.getElementById("dummy");
+for (var i = 0; i < tests.length; ++i) {
+    var expression = tests[i];
+    dummy.style.width = 'calc(' + expression + ')';
+    dummy.style.width = '-webkit-calc(' + expression + ')';
+    dummy.style.width = '-moz-calc(' + expression + ')';
+    results.innerHTML += expression + " => " + dummy.style.width + "<br>";
+}
+</script>
index 92af20a..a4cf82e 100644 (file)
@@ -1,3 +1,22 @@
+2012-05-30  Mike Lawther  <mikelawther@chromium.org>
+
+        CSS3 calc: Implement CSSOM support
+        https://bugs.webkit.org/show_bug.cgi?id=84551
+
+        Reviewed by Ryosuke Niwa.
+
+        Adds a pretty printer for the calc expression tree. 
+
+        Test: css3/calc/cssom.html
+
+        * css/CSSCalculationValue.cpp:
+        (WebCore::CSSCalcValue::customCssText):
+        (WebCore::CSSCalcPrimitiveValue::customCssText):
+        (WebCore::CSSCalcBinaryOperation::customCssText):
+        (CSSCalcBinaryOperation):
+        * css/CSSCalculationValue.h:
+        (CSSCalcExpressionNode):
+
 2012-05-29  Li Yin  <li.yin@intel.com>
 
         [FileAPI] The result attribute of FileReader shuold use null to replace empty string
index 618c39c..54247e0 100755 (executable)
@@ -74,7 +74,17 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitTypes type)
     
 String CSSCalcValue::customCssText() const
 {
-    return "";
+    StringBuilder result;
+    
+    result.append("-webkit-calc");
+    String expression = m_expression->customCssText();
+    bool expressionHasSingleTerm = expression[0] != '(';
+    if (expressionHasSingleTerm)
+        result.append('(');
+    result.append(expression);
+    if (expressionHasSingleTerm)
+        result.append(')');
+    return result.toString(); 
 }
     
 double CSSCalcValue::clampToPermittedRange(double value) const
@@ -109,7 +119,7 @@ public:
         return !m_value->getDoubleValue();
     }
 
-    virtual String cssText() const
+    virtual String customCssText() const
     {
         return m_value->cssText();
     }
@@ -250,6 +260,20 @@ public:
         return evaluate(leftValue, rightValue);
     }
 
+    virtual String customCssText() const
+    {
+        StringBuilder result;
+        result.append('(');
+        result.append(m_leftSide->customCssText());
+        result.append(' ');
+        result.append(static_cast<char>(m_operator));
+        result.append(' ');
+        result.append(m_rightSide->customCssText());
+        result.append(')');
+    
+        return result.toString();    
+    }
+
 private:
     CSSCalcBinaryOperation(PassRefPtr<CSSCalcExpressionNode> leftSide, PassRefPtr<CSSCalcExpressionNode> rightSide, CalcOperator op, CalculationCategory category)
         : CSSCalcExpressionNode(category, leftSide->isInteger() && rightSide->isInteger())
index ac9be46..57a249f 100755 (executable)
@@ -63,6 +63,7 @@ public:
     virtual PassOwnPtr<CalcExpressionNode> toCalcValue(RenderStyle*, RenderStyle* rootStyle, double zoom = 1.0) const = 0;    
     virtual double doubleValue() const = 0;
     virtual double computeLengthPx(RenderStyle* currentStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false) const = 0;
+    virtual String customCssText() const = 0;
     
     CalculationCategory category() const { return m_category; }    
     bool isInteger() const { return m_isInteger; }