Title: [101317] trunk/Source/WebCore
Revision
101317
Author
[email protected]
Date
2011-11-28 19:24:41 -0800 (Mon, 28 Nov 2011)

Log Message

Implement CSSPropertySize in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=73000

Reviewed by Andreas Kling.

This refactoring moves the implementation of the page size calculation into CSSStyleApplyProperty
and removes the existing code from CSSStyleSelector.

No new tests / refactoring only.

* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyPageSize::mmLength):
(WebCore::ApplyPropertyPageSize::inchLength):
(WebCore::ApplyPropertyPageSize::pageSizeFromName):
(WebCore::ApplyPropertyPageSize::applyInheritValue):
(WebCore::ApplyPropertyPageSize::applyInitialValue):
(WebCore::ApplyPropertyPageSize::applyValue):
(WebCore::ApplyPropertyPageSize::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
* css/CSSStyleSelector.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (101316 => 101317)


--- trunk/Source/WebCore/ChangeLog	2011-11-29 03:01:00 UTC (rev 101316)
+++ trunk/Source/WebCore/ChangeLog	2011-11-29 03:24:41 UTC (rev 101317)
@@ -1,3 +1,28 @@
+2011-11-28  Luke Macpherson   <[email protected]>
+
+        Implement CSSPropertySize in CSSStyleApplyProperty.
+        https://bugs.webkit.org/show_bug.cgi?id=73000
+
+        Reviewed by Andreas Kling.
+
+        This refactoring moves the implementation of the page size calculation into CSSStyleApplyProperty
+        and removes the existing code from CSSStyleSelector.
+
+        No new tests / refactoring only.
+
+        * css/CSSStyleApplyProperty.cpp:
+        (WebCore::ApplyPropertyPageSize::mmLength):
+        (WebCore::ApplyPropertyPageSize::inchLength):
+        (WebCore::ApplyPropertyPageSize::pageSizeFromName):
+        (WebCore::ApplyPropertyPageSize::applyInheritValue):
+        (WebCore::ApplyPropertyPageSize::applyInitialValue):
+        (WebCore::ApplyPropertyPageSize::applyValue):
+        (WebCore::ApplyPropertyPageSize::createHandler):
+        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        * css/CSSStyleSelector.h:
+
 2011-11-28  Timothy Hatcher  <[email protected]>
 
         Add support for knowing when a TreeElement is added or changed anywhere in a TreeOutline.

Modified: trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp (101316 => 101317)


--- trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-11-29 03:01:00 UTC (rev 101316)
+++ trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp	2011-11-29 03:24:41 UTC (rev 101317)
@@ -756,6 +756,147 @@
     }
 };
 
+class ApplyPropertyPageSize {
+private:
+    static Length mmLength(double mm) { return CSSPrimitiveValue::create(mm, CSSPrimitiveValue::CSS_MM)->computeLength<Length>(0, 0); }
+    static Length inchLength(double inch) { return CSSPrimitiveValue::create(inch, CSSPrimitiveValue::CSS_IN)->computeLength<Length>(0, 0); }
+    static bool getPageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrimitiveValue* pageOrientation, Length& width, Length& height)
+    {
+        static const Length a5Width = mmLength(148), a5Height = mmLength(210);
+        static const Length a4Width = mmLength(210), a4Height = mmLength(297);
+        static const Length a3Width = mmLength(297), a3Height = mmLength(420);
+        static const Length b5Width = mmLength(176), b5Height = mmLength(250);
+        static const Length b4Width = mmLength(250), b4Height = mmLength(353);
+        static const Length letterWidth = inchLength(8.5), letterHeight = inchLength(11);
+        static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14);
+        static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17);
+
+        if (!pageSizeName)
+            return false;
+
+        switch (pageSizeName->getIdent()) {
+        case CSSValueA5:
+            width = a5Width;
+            height = a5Height;
+            break;
+        case CSSValueA4:
+            width = a4Width;
+            height = a4Height;
+            break;
+        case CSSValueA3:
+            width = a3Width;
+            height = a3Height;
+            break;
+        case CSSValueB5:
+            width = b5Width;
+            height = b5Height;
+            break;
+        case CSSValueB4:
+            width = b4Width;
+            height = b4Height;
+            break;
+        case CSSValueLetter:
+            width = letterWidth;
+            height = letterHeight;
+            break;
+        case CSSValueLegal:
+            width = legalWidth;
+            height = legalHeight;
+            break;
+        case CSSValueLedger:
+            width = ledgerWidth;
+            height = ledgerHeight;
+            break;
+        default:
+            return false;
+        }
+
+        if (pageOrientation) {
+            switch (pageOrientation->getIdent()) {
+            case CSSValueLandscape:
+                std::swap(width, height);
+                break;
+            case CSSValuePortrait:
+                // Nothing to do.
+                break;
+            default:
+                return false;
+            }
+        }
+        return true;
+    }
+public:
+    static void applyInheritValue(CSSStyleSelector*) { }
+    static void applyInitialValue(CSSStyleSelector*) { }
+    static void applyValue(CSSStyleSelector* selector, CSSValue* value)
+    {
+        selector->style()->resetPageSizeType();
+        Length width;
+        Length height;
+        PageSizeType pageSizeType = PAGE_SIZE_AUTO;
+        CSSValueListInspector inspector(value);
+        switch (inspector.length()) {
+        case 2: {
+            // <length>{2} | <page-size> <orientation>
+            if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
+                return;
+            CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(inspector.first());
+            CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(inspector.second());
+            if (first->isLength()) {
+                // <length>{2}
+                if (!second->isLength())
+                    return;
+                width = first->computeLength<Length>(selector->style(), selector->rootElementStyle());
+                height = second->computeLength<Length>(selector->style(), selector->rootElementStyle());
+            } else {
+                // <page-size> <orientation>
+                // The value order is guaranteed. See CSSParser::parseSizeParameter.
+                if (!getPageSizeFromName(first, second, width, height))
+                    return;
+            }
+            pageSizeType = PAGE_SIZE_RESOLVED;
+            break;
+        }
+        case 1: {
+            // <length> | auto | <page-size> | [ portrait | landscape]
+            if (!inspector.first()->isPrimitiveValue())
+                return;
+            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(inspector.first());
+            if (primitiveValue->isLength()) {
+                // <length>
+                pageSizeType = PAGE_SIZE_RESOLVED;
+                width = height = primitiveValue->computeLength<Length>(selector->style(), selector->rootElementStyle());
+            } else {
+                if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
+                    return;
+                switch (primitiveValue->getIdent()) {
+                case CSSValueAuto:
+                    pageSizeType = PAGE_SIZE_AUTO;
+                    break;
+                case CSSValuePortrait:
+                    pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
+                    break;
+                case CSSValueLandscape:
+                    pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
+                    break;
+                default:
+                    // <page-size>
+                    pageSizeType = PAGE_SIZE_RESOLVED;
+                    if (!getPageSizeFromName(primitiveValue, 0, width, height))
+                        return;
+                }
+            }
+            break;
+        }
+        default:
+            return;
+        }
+        selector->style()->setPageSizeType(pageSizeType);
+        selector->style()->setPageSize(LengthSize(width, height));
+    }
+    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
+};
+
 class ApplyPropertyTextEmphasisStyle {
 public:
     static void applyInheritValue(CSSStyleSelector* selector)
@@ -1176,6 +1317,8 @@
 
     setPropertyHandler(CSSPropertyVerticalAlign, ApplyPropertyVerticalAlign::createHandler());
 
+    setPropertyHandler(CSSPropertySize, ApplyPropertyPageSize::createHandler());
+
     setPropertyHandler(CSSPropertyWebkitPerspectiveOriginX, ApplyPropertyLength<&RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX, &RenderStyle::initialPerspectiveOriginX>::createHandler());
     setPropertyHandler(CSSPropertyWebkitPerspectiveOriginY, ApplyPropertyLength<&RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY, &RenderStyle::initialPerspectiveOriginY>::createHandler());
     setPropertyHandler(CSSPropertyWebkitPerspectiveOrigin, ApplyPropertyExpanding<SuppressValue, CSSPropertyWebkitPerspectiveOriginX, CSSPropertyWebkitPerspectiveOriginY>::createHandler());

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (101316 => 101317)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-11-29 03:01:00 UTC (rev 101316)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2011-11-29 03:24:41 UTC (rev 101317)
@@ -3626,9 +3626,6 @@
     case CSSPropertyWebkitColorCorrection:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(colorSpace, ColorSpace);
         return;
-    case CSSPropertySize:
-        applyPageSizeProperty(value);
-        return;
     case CSSPropertySpeak:
         HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(speak, Speak);
         return;
@@ -3899,6 +3896,7 @@
     case CSSPropertyPaddingBottom:
     case CSSPropertyPaddingLeft:
     case CSSPropertyPadding:
+    case CSSPropertySize:
     case CSSPropertyTextAlign:
     case CSSPropertyTextIndent:
     case CSSPropertyMaxHeight:
@@ -3956,152 +3954,6 @@
     }
 }
 
-void CSSStyleSelector::applyPageSizeProperty(CSSValue* value)
-{
-    m_style->resetPageSizeType();
-    Length width;
-    Length height;
-    PageSizeType pageSizeType = PAGE_SIZE_AUTO;
-    CSSValueListInspector inspector = value;
-    switch (inspector.length()) {
-    case 2: {
-        // <length>{2} | <page-size> <orientation>
-        pageSizeType = PAGE_SIZE_RESOLVED;
-        if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
-            return;
-        CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(inspector.first());
-        CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(inspector.second());
-        if (first->isLength()) {
-            // <length>{2}
-            if (!second->isLength())
-                return;
-            width = first->computeLength<Length>(style(), m_rootElementStyle);
-            height = second->computeLength<Length>(style(), m_rootElementStyle);
-        } else {
-            // <page-size> <orientation>
-            // The value order is guaranteed. See CSSParser::parseSizeParameter.
-            if (!pageSizeFromName(first, second, width, height))
-                return;
-        }
-        break;
-    }
-    case 1: {
-        // <length> | auto | <page-size> | [ portrait | landscape]
-        if (!inspector.first()->isPrimitiveValue())
-            return;
-        CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(inspector.first());
-        if (primitiveValue->isLength()) {
-            // <length>
-            pageSizeType = PAGE_SIZE_RESOLVED;
-            width = height = primitiveValue->computeLength<Length>(style(), m_rootElementStyle);
-        } else {
-            if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
-                return;
-            switch (primitiveValue->getIdent()) {
-            case CSSValueAuto:
-                pageSizeType = PAGE_SIZE_AUTO;
-                break;
-            case CSSValuePortrait:
-                pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
-                break;
-            case CSSValueLandscape:
-                pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
-                break;
-            default:
-                // <page-size>
-                pageSizeType = PAGE_SIZE_RESOLVED;
-                if (!pageSizeFromName(primitiveValue, 0, width, height))
-                    return;
-            }
-        }
-        break;
-    }
-    default:
-        return;
-    }
-    m_style->setPageSizeType(pageSizeType);
-    m_style->setPageSize(LengthSize(width, height));
-    return;
-}
-
-bool CSSStyleSelector::pageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrimitiveValue* pageOrientation, Length& width, Length& height)
-{
-    static const Length a5Width = mmLength(148), a5Height = mmLength(210);
-    static const Length a4Width = mmLength(210), a4Height = mmLength(297);
-    static const Length a3Width = mmLength(297), a3Height = mmLength(420);
-    static const Length b5Width = mmLength(176), b5Height = mmLength(250);
-    static const Length b4Width = mmLength(250), b4Height = mmLength(353);
-    static const Length letterWidth = inchLength(8.5), letterHeight = inchLength(11);
-    static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14);
-    static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17);
-
-    if (!pageSizeName || pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
-        return false;
-
-    switch (pageSizeName->getIdent()) {
-    case CSSValueA5:
-        width = a5Width;
-        height = a5Height;
-        break;
-    case CSSValueA4:
-        width = a4Width;
-        height = a4Height;
-        break;
-    case CSSValueA3:
-        width = a3Width;
-        height = a3Height;
-        break;
-    case CSSValueB5:
-        width = b5Width;
-        height = b5Height;
-        break;
-    case CSSValueB4:
-        width = b4Width;
-        height = b4Height;
-        break;
-    case CSSValueLetter:
-        width = letterWidth;
-        height = letterHeight;
-        break;
-    case CSSValueLegal:
-        width = legalWidth;
-        height = legalHeight;
-        break;
-    case CSSValueLedger:
-        width = ledgerWidth;
-        height = ledgerHeight;
-        break;
-    default:
-        return false;
-    }
-
-    if (pageOrientation) {
-        if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
-            return false;
-        switch (pageOrientation->getIdent()) {
-        case CSSValueLandscape:
-            std::swap(width, height);
-            break;
-        case CSSValuePortrait:
-            // Nothing to do.
-            break;
-        default:
-            return false;
-        }
-    }
-    return true;
-}
-
-Length CSSStyleSelector::mmLength(double mm) const
-{
-    return CSSPrimitiveValue::create(mm, CSSPrimitiveValue::CSS_MM)->computeLength<Length>(style(), m_rootElementStyle);
-}
-
-Length CSSStyleSelector::inchLength(double inch) const
-{
-    return CSSPrimitiveValue::create(inch, CSSPrimitiveValue::CSS_IN)->computeLength<Length>(style(), m_rootElementStyle);
-}
-
 void CSSStyleSelector::mapFillAttachment(CSSPropertyID, FillLayer* layer, CSSValue* value)
 {
     if (value->isInitialValue()) {

Modified: trunk/Source/WebCore/css/CSSStyleSelector.h (101316 => 101317)


--- trunk/Source/WebCore/css/CSSStyleSelector.h	2011-11-29 03:01:00 UTC (rev 101316)
+++ trunk/Source/WebCore/css/CSSStyleSelector.h	2011-11-29 03:24:41 UTC (rev 101317)
@@ -335,10 +335,6 @@
     bool canShareStyleWithControl(StyledElement*) const;
 
     void applyProperty(int id, CSSValue*);
-    void applyPageSizeProperty(CSSValue*);
-    bool pageSizeFromName(CSSPrimitiveValue*, CSSPrimitiveValue*, Length& width, Length& height);
-    Length mmLength(double mm) const;
-    Length inchLength(double inch) const;
 #if ENABLE(SVG)
     void applySVGProperty(int id, CSSValue*);
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to