⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 101317 in webkit


Ignore:
Timestamp:
Nov 28, 2011, 7:24:41 PM (15 years ago)
Author:
macpherson@chromium.org
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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r101315 r101317  
     12011-11-28  Luke Macpherson   <macpherson@chromium.org>
     2
     3        Implement CSSPropertySize in CSSStyleApplyProperty.
     4        https://bugs.webkit.org/show_bug.cgi?id=73000
     5
     6        Reviewed by Andreas Kling.
     7
     8        This refactoring moves the implementation of the page size calculation into CSSStyleApplyProperty
     9        and removes the existing code from CSSStyleSelector.
     10
     11        No new tests / refactoring only.
     12
     13        * css/CSSStyleApplyProperty.cpp:
     14        (WebCore::ApplyPropertyPageSize::mmLength):
     15        (WebCore::ApplyPropertyPageSize::inchLength):
     16        (WebCore::ApplyPropertyPageSize::pageSizeFromName):
     17        (WebCore::ApplyPropertyPageSize::applyInheritValue):
     18        (WebCore::ApplyPropertyPageSize::applyInitialValue):
     19        (WebCore::ApplyPropertyPageSize::applyValue):
     20        (WebCore::ApplyPropertyPageSize::createHandler):
     21        (WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
     22        * css/CSSStyleSelector.cpp:
     23        (WebCore::CSSStyleSelector::applyProperty):
     24        * css/CSSStyleSelector.h:
     25
    1262011-11-28  Timothy Hatcher  <timothy@apple.com>
    227
  • trunk/Source/WebCore/css/CSSStyleApplyProperty.cpp

    r101288 r101317  
    757757};
    758758
     759class ApplyPropertyPageSize {
     760private:
     761    static Length mmLength(double mm) { return CSSPrimitiveValue::create(mm, CSSPrimitiveValue::CSS_MM)->computeLength<Length>(0, 0); }
     762    static Length inchLength(double inch) { return CSSPrimitiveValue::create(inch, CSSPrimitiveValue::CSS_IN)->computeLength<Length>(0, 0); }
     763    static bool getPageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrimitiveValue* pageOrientation, Length& width, Length& height)
     764    {
     765        static const Length a5Width = mmLength(148), a5Height = mmLength(210);
     766        static const Length a4Width = mmLength(210), a4Height = mmLength(297);
     767        static const Length a3Width = mmLength(297), a3Height = mmLength(420);
     768        static const Length b5Width = mmLength(176), b5Height = mmLength(250);
     769        static const Length b4Width = mmLength(250), b4Height = mmLength(353);
     770        static const Length letterWidth = inchLength(8.5), letterHeight = inchLength(11);
     771        static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14);
     772        static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17);
     773
     774        if (!pageSizeName)
     775            return false;
     776
     777        switch (pageSizeName->getIdent()) {
     778        case CSSValueA5:
     779            width = a5Width;
     780            height = a5Height;
     781            break;
     782        case CSSValueA4:
     783            width = a4Width;
     784            height = a4Height;
     785            break;
     786        case CSSValueA3:
     787            width = a3Width;
     788            height = a3Height;
     789            break;
     790        case CSSValueB5:
     791            width = b5Width;
     792            height = b5Height;
     793            break;
     794        case CSSValueB4:
     795            width = b4Width;
     796            height = b4Height;
     797            break;
     798        case CSSValueLetter:
     799            width = letterWidth;
     800            height = letterHeight;
     801            break;
     802        case CSSValueLegal:
     803            width = legalWidth;
     804            height = legalHeight;
     805            break;
     806        case CSSValueLedger:
     807            width = ledgerWidth;
     808            height = ledgerHeight;
     809            break;
     810        default:
     811            return false;
     812        }
     813
     814        if (pageOrientation) {
     815            switch (pageOrientation->getIdent()) {
     816            case CSSValueLandscape:
     817                std::swap(width, height);
     818                break;
     819            case CSSValuePortrait:
     820                // Nothing to do.
     821                break;
     822            default:
     823                return false;
     824            }
     825        }
     826        return true;
     827    }
     828public:
     829    static void applyInheritValue(CSSStyleSelector*) { }
     830    static void applyInitialValue(CSSStyleSelector*) { }
     831    static void applyValue(CSSStyleSelector* selector, CSSValue* value)
     832    {
     833        selector->style()->resetPageSizeType();
     834        Length width;
     835        Length height;
     836        PageSizeType pageSizeType = PAGE_SIZE_AUTO;
     837        CSSValueListInspector inspector(value);
     838        switch (inspector.length()) {
     839        case 2: {
     840            // <length>{2} | <page-size> <orientation>
     841            if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
     842                return;
     843            CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(inspector.first());
     844            CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(inspector.second());
     845            if (first->isLength()) {
     846                // <length>{2}
     847                if (!second->isLength())
     848                    return;
     849                width = first->computeLength<Length>(selector->style(), selector->rootElementStyle());
     850                height = second->computeLength<Length>(selector->style(), selector->rootElementStyle());
     851            } else {
     852                // <page-size> <orientation>
     853                // The value order is guaranteed. See CSSParser::parseSizeParameter.
     854                if (!getPageSizeFromName(first, second, width, height))
     855                    return;
     856            }
     857            pageSizeType = PAGE_SIZE_RESOLVED;
     858            break;
     859        }
     860        case 1: {
     861            // <length> | auto | <page-size> | [ portrait | landscape]
     862            if (!inspector.first()->isPrimitiveValue())
     863                return;
     864            CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(inspector.first());
     865            if (primitiveValue->isLength()) {
     866                // <length>
     867                pageSizeType = PAGE_SIZE_RESOLVED;
     868                width = height = primitiveValue->computeLength<Length>(selector->style(), selector->rootElementStyle());
     869            } else {
     870                if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
     871                    return;
     872                switch (primitiveValue->getIdent()) {
     873                case CSSValueAuto:
     874                    pageSizeType = PAGE_SIZE_AUTO;
     875                    break;
     876                case CSSValuePortrait:
     877                    pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
     878                    break;
     879                case CSSValueLandscape:
     880                    pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
     881                    break;
     882                default:
     883                    // <page-size>
     884                    pageSizeType = PAGE_SIZE_RESOLVED;
     885                    if (!getPageSizeFromName(primitiveValue, 0, width, height))
     886                        return;
     887                }
     888            }
     889            break;
     890        }
     891        default:
     892            return;
     893        }
     894        selector->style()->setPageSizeType(pageSizeType);
     895        selector->style()->setPageSize(LengthSize(width, height));
     896    }
     897    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
     898};
     899
    759900class ApplyPropertyTextEmphasisStyle {
    760901public:
     
    11771318    setPropertyHandler(CSSPropertyVerticalAlign, ApplyPropertyVerticalAlign::createHandler());
    11781319
     1320    setPropertyHandler(CSSPropertySize, ApplyPropertyPageSize::createHandler());
     1321
    11791322    setPropertyHandler(CSSPropertyWebkitPerspectiveOriginX, ApplyPropertyLength<&RenderStyle::perspectiveOriginX, &RenderStyle::setPerspectiveOriginX, &RenderStyle::initialPerspectiveOriginX>::createHandler());
    11801323    setPropertyHandler(CSSPropertyWebkitPerspectiveOriginY, ApplyPropertyLength<&RenderStyle::perspectiveOriginY, &RenderStyle::setPerspectiveOriginY, &RenderStyle::initialPerspectiveOriginY>::createHandler());
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r101288 r101317  
    36263626    case CSSPropertyWebkitColorCorrection:
    36273627        HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(colorSpace, ColorSpace);
    3628         return;
    3629     case CSSPropertySize:
    3630         applyPageSizeProperty(value);
    36313628        return;
    36323629    case CSSPropertySpeak:
     
    39003897    case CSSPropertyPaddingLeft:
    39013898    case CSSPropertyPadding:
     3899    case CSSPropertySize:
    39023900    case CSSPropertyTextAlign:
    39033901    case CSSPropertyTextIndent:
     
    39553953#endif
    39563954    }
    3957 }
    3958 
    3959 void CSSStyleSelector::applyPageSizeProperty(CSSValue* value)
    3960 {
    3961     m_style->resetPageSizeType();
    3962     Length width;
    3963     Length height;
    3964     PageSizeType pageSizeType = PAGE_SIZE_AUTO;
    3965     CSSValueListInspector inspector = value;
    3966     switch (inspector.length()) {
    3967     case 2: {
    3968         // <length>{2} | <page-size> <orientation>
    3969         pageSizeType = PAGE_SIZE_RESOLVED;
    3970         if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
    3971             return;
    3972         CSSPrimitiveValue* first = static_cast<CSSPrimitiveValue*>(inspector.first());
    3973         CSSPrimitiveValue* second = static_cast<CSSPrimitiveValue*>(inspector.second());
    3974         if (first->isLength()) {
    3975             // <length>{2}
    3976             if (!second->isLength())
    3977                 return;
    3978             width = first->computeLength<Length>(style(), m_rootElementStyle);
    3979             height = second->computeLength<Length>(style(), m_rootElementStyle);
    3980         } else {
    3981             // <page-size> <orientation>
    3982             // The value order is guaranteed. See CSSParser::parseSizeParameter.
    3983             if (!pageSizeFromName(first, second, width, height))
    3984                 return;
    3985         }
    3986         break;
    3987     }
    3988     case 1: {
    3989         // <length> | auto | <page-size> | [ portrait | landscape]
    3990         if (!inspector.first()->isPrimitiveValue())
    3991             return;
    3992         CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(inspector.first());
    3993         if (primitiveValue->isLength()) {
    3994             // <length>
    3995             pageSizeType = PAGE_SIZE_RESOLVED;
    3996             width = height = primitiveValue->computeLength<Length>(style(), m_rootElementStyle);
    3997         } else {
    3998             if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
    3999                 return;
    4000             switch (primitiveValue->getIdent()) {
    4001             case CSSValueAuto:
    4002                 pageSizeType = PAGE_SIZE_AUTO;
    4003                 break;
    4004             case CSSValuePortrait:
    4005                 pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
    4006                 break;
    4007             case CSSValueLandscape:
    4008                 pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
    4009                 break;
    4010             default:
    4011                 // <page-size>
    4012                 pageSizeType = PAGE_SIZE_RESOLVED;
    4013                 if (!pageSizeFromName(primitiveValue, 0, width, height))
    4014                     return;
    4015             }
    4016         }
    4017         break;
    4018     }
    4019     default:
    4020         return;
    4021     }
    4022     m_style->setPageSizeType(pageSizeType);
    4023     m_style->setPageSize(LengthSize(width, height));
    4024     return;
    4025 }
    4026 
    4027 bool CSSStyleSelector::pageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrimitiveValue* pageOrientation, Length& width, Length& height)
    4028 {
    4029     static const Length a5Width = mmLength(148), a5Height = mmLength(210);
    4030     static const Length a4Width = mmLength(210), a4Height = mmLength(297);
    4031     static const Length a3Width = mmLength(297), a3Height = mmLength(420);
    4032     static const Length b5Width = mmLength(176), b5Height = mmLength(250);
    4033     static const Length b4Width = mmLength(250), b4Height = mmLength(353);
    4034     static const Length letterWidth = inchLength(8.5), letterHeight = inchLength(11);
    4035     static const Length legalWidth = inchLength(8.5), legalHeight = inchLength(14);
    4036     static const Length ledgerWidth = inchLength(11), ledgerHeight = inchLength(17);
    4037 
    4038     if (!pageSizeName || pageSizeName->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
    4039         return false;
    4040 
    4041     switch (pageSizeName->getIdent()) {
    4042     case CSSValueA5:
    4043         width = a5Width;
    4044         height = a5Height;
    4045         break;
    4046     case CSSValueA4:
    4047         width = a4Width;
    4048         height = a4Height;
    4049         break;
    4050     case CSSValueA3:
    4051         width = a3Width;
    4052         height = a3Height;
    4053         break;
    4054     case CSSValueB5:
    4055         width = b5Width;
    4056         height = b5Height;
    4057         break;
    4058     case CSSValueB4:
    4059         width = b4Width;
    4060         height = b4Height;
    4061         break;
    4062     case CSSValueLetter:
    4063         width = letterWidth;
    4064         height = letterHeight;
    4065         break;
    4066     case CSSValueLegal:
    4067         width = legalWidth;
    4068         height = legalHeight;
    4069         break;
    4070     case CSSValueLedger:
    4071         width = ledgerWidth;
    4072         height = ledgerHeight;
    4073         break;
    4074     default:
    4075         return false;
    4076     }
    4077 
    4078     if (pageOrientation) {
    4079         if (pageOrientation->primitiveType() != CSSPrimitiveValue::CSS_IDENT)
    4080             return false;
    4081         switch (pageOrientation->getIdent()) {
    4082         case CSSValueLandscape:
    4083             std::swap(width, height);
    4084             break;
    4085         case CSSValuePortrait:
    4086             // Nothing to do.
    4087             break;
    4088         default:
    4089             return false;
    4090         }
    4091     }
    4092     return true;
    4093 }
    4094 
    4095 Length CSSStyleSelector::mmLength(double mm) const
    4096 {
    4097     return CSSPrimitiveValue::create(mm, CSSPrimitiveValue::CSS_MM)->computeLength<Length>(style(), m_rootElementStyle);
    4098 }
    4099 
    4100 Length CSSStyleSelector::inchLength(double inch) const
    4101 {
    4102     return CSSPrimitiveValue::create(inch, CSSPrimitiveValue::CSS_IN)->computeLength<Length>(style(), m_rootElementStyle);
    41033955}
    41043956
  • trunk/Source/WebCore/css/CSSStyleSelector.h

    r101177 r101317  
    336336
    337337    void applyProperty(int id, CSSValue*);
    338     void applyPageSizeProperty(CSSValue*);
    339     bool pageSizeFromName(CSSPrimitiveValue*, CSSPrimitiveValue*, Length& width, Length& height);
    340     Length mmLength(double mm) const;
    341     Length inchLength(double inch) const;
    342338#if ENABLE(SVG)
    343339    void applySVGProperty(int id, CSSValue*);
Note: See TracChangeset for help on using the changeset viewer.