Home | History | Annotate | Download | only in resolver
      1 /*
      2  * Copyright (C) 2013 Google Inc. All rights reserved.
      3  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      4  *           (C) 2004-2005 Allan Sandfeld Jensen (kde (at) carewolf.com)
      5  * Copyright (C) 2006, 2007 Nicholas Shanks (webkit (at) nickshanks.com)
      6  * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
      7  * Copyright (C) 2007 Alexey Proskuryakov <ap (at) webkit.org>
      8  * Copyright (C) 2007, 2008 Eric Seidel <eric (at) webkit.org>
      9  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
     10  * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
     11  * Copyright (C) Research In Motion Limited 2011. All rights reserved.
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions are
     14  * met:
     15  *
     16  *     * Redistributions of source code must retain the above copyright
     17  * notice, this list of conditions and the following disclaimer.
     18  *     * Redistributions in binary form must reproduce the above
     19  * copyright notice, this list of conditions and the following disclaimer
     20  * in the documentation and/or other materials provided with the
     21  * distribution.
     22  *     * Neither the name of Google Inc. nor the names of its
     23  * contributors may be used to endorse or promote products derived from
     24  * this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include "config.h"
     40 #include "StyleBuilderFunctions.h"
     41 
     42 #include "CSSPropertyNames.h"
     43 #include "CSSValueKeywords.h"
     44 #include "StylePropertyShorthand.h"
     45 #include "core/css/BasicShapeFunctions.h"
     46 #include "core/css/CSSAspectRatioValue.h"
     47 #include "core/css/CSSCursorImageValue.h"
     48 #include "core/css/CSSFontValue.h"
     49 #include "core/css/CSSFunctionValue.h"
     50 #include "core/css/CSSGradientValue.h"
     51 #include "core/css/CSSGridLineNamesValue.h"
     52 #include "core/css/CSSGridTemplateValue.h"
     53 #include "core/css/CSSHelper.h"
     54 #include "core/css/CSSImageSetValue.h"
     55 #include "core/css/CSSLineBoxContainValue.h"
     56 #include "core/css/CSSParser.h"
     57 #include "core/css/CSSPrimitiveValueMappings.h"
     58 #include "core/css/CSSProperty.h"
     59 #include "core/css/CSSReflectValue.h"
     60 #include "core/css/CSSVariableValue.h"
     61 #include "core/css/Counter.h"
     62 #include "core/css/Rect.h"
     63 #include "core/css/StylePropertySet.h"
     64 #include "core/css/StyleRule.h"
     65 #include "core/css/resolver/ElementStyleResources.h"
     66 #include "core/css/resolver/FilterOperationResolver.h"
     67 #include "core/css/resolver/FontBuilder.h"
     68 #include "core/css/resolver/StyleBuilder.h"
     69 #include "core/css/resolver/TransformBuilder.h"
     70 #include "core/frame/Frame.h"
     71 #include "core/frame/Settings.h"
     72 #include "core/rendering/style/CounterContent.h"
     73 #include "core/rendering/style/CursorList.h"
     74 #include "core/rendering/style/QuotesData.h"
     75 #include "core/rendering/style/RenderStyle.h"
     76 #include "core/rendering/style/RenderStyleConstants.h"
     77 #include "core/rendering/style/SVGRenderStyle.h"
     78 #include "core/rendering/style/SVGRenderStyleDefs.h"
     79 #include "core/rendering/style/StyleGeneratedImage.h"
     80 #include "core/svg/SVGColor.h"
     81 #include "core/svg/SVGPaint.h"
     82 #include "platform/fonts/FontDescription.h"
     83 #include "wtf/MathExtras.h"
     84 #include "wtf/StdLibExtras.h"
     85 #include "wtf/Vector.h"
     86 
     87 namespace WebCore {
     88 
     89 static Length clipConvertToLength(StyleResolverState& state, CSSPrimitiveValue* value)
     90 {
     91     return value->convertToLength<FixedConversion | PercentConversion | AutoConversion>(state.cssToLengthConversionData());
     92 }
     93 
     94 void StyleBuilderFunctions::applyInitialCSSPropertyClip(StyleResolverState& state)
     95 {
     96     state.style()->setClip(Length(), Length(), Length(), Length());
     97     state.style()->setHasClip(false);
     98 }
     99 
    100 void StyleBuilderFunctions::applyInheritCSSPropertyClip(StyleResolverState& state)
    101 {
    102     RenderStyle* parentStyle = state.parentStyle();
    103     if (!parentStyle->hasClip())
    104         return applyInitialCSSPropertyClip(state);
    105     state.style()->setClip(parentStyle->clipTop(), parentStyle->clipRight(), parentStyle->clipBottom(), parentStyle->clipLeft());
    106     state.style()->setHasClip(true);
    107 }
    108 
    109 void StyleBuilderFunctions::applyValueCSSPropertyClip(StyleResolverState& state, CSSValue* value)
    110 {
    111     if (!value->isPrimitiveValue())
    112         return;
    113 
    114     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    115 
    116     if (Rect* rect = primitiveValue->getRectValue()) {
    117         Length top = clipConvertToLength(state, rect->top());
    118         Length right = clipConvertToLength(state, rect->right());
    119         Length bottom = clipConvertToLength(state, rect->bottom());
    120         Length left = clipConvertToLength(state, rect->left());
    121         state.style()->setClip(top, right, bottom, left);
    122         state.style()->setHasClip(true);
    123     } else if (primitiveValue->getValueID() == CSSValueAuto) {
    124         state.style()->setClip(Length(), Length(), Length(), Length());
    125         state.style()->setHasClip(false);
    126     }
    127 }
    128 
    129 void StyleBuilderFunctions::applyInitialCSSPropertyCursor(StyleResolverState& state)
    130 {
    131     state.style()->clearCursorList();
    132     state.style()->setCursor(RenderStyle::initialCursor());
    133 }
    134 
    135 void StyleBuilderFunctions::applyInheritCSSPropertyCursor(StyleResolverState& state)
    136 {
    137     state.style()->setCursor(state.parentStyle()->cursor());
    138     state.style()->setCursorList(state.parentStyle()->cursors());
    139 }
    140 
    141 void StyleBuilderFunctions::applyValueCSSPropertyCursor(StyleResolverState& state, CSSValue* value)
    142 {
    143     state.style()->clearCursorList();
    144     if (value->isValueList()) {
    145         CSSValueList* list = toCSSValueList(value);
    146         int len = list->length();
    147         state.style()->setCursor(CURSOR_AUTO);
    148         for (int i = 0; i < len; i++) {
    149             CSSValue* item = list->itemWithoutBoundsCheck(i);
    150             if (item->isCursorImageValue()) {
    151                 CSSCursorImageValue* image = toCSSCursorImageValue(item);
    152                 if (image->updateIfSVGCursorIsUsed(state.element())) // Elements with SVG cursors are not allowed to share style.
    153                     state.style()->setUnique();
    154                 state.style()->addCursor(state.styleImage(CSSPropertyCursor, image), image->hotSpot());
    155             } else if (item->isPrimitiveValue()) {
    156                 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(item);
    157                 if (primitiveValue->isValueID())
    158                     state.style()->setCursor(*primitiveValue);
    159             }
    160         }
    161     } else if (value->isPrimitiveValue()) {
    162         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    163         if (primitiveValue->isValueID() && state.style()->cursor() != ECursor(*primitiveValue))
    164             state.style()->setCursor(*primitiveValue);
    165     }
    166 }
    167 
    168 void StyleBuilderFunctions::applyValueCSSPropertyDirection(StyleResolverState& state, CSSValue* value)
    169 {
    170     state.style()->setDirection(*toCSSPrimitiveValue(value));
    171     Element* element = state.element();
    172     if (element && element == element->document().documentElement())
    173         element->document().setDirectionSetOnDocumentElement(true);
    174 }
    175 
    176 static inline bool isValidDisplayValue(StyleResolverState& state, EDisplay displayPropertyValue)
    177 {
    178     if (state.element() && state.element()->isSVGElement() && state.style()->styleType() == NOPSEUDO)
    179         return (displayPropertyValue == INLINE || displayPropertyValue == BLOCK || displayPropertyValue == NONE);
    180     return true;
    181 }
    182 
    183 void StyleBuilderFunctions::applyInheritCSSPropertyDisplay(StyleResolverState& state)
    184 {
    185     EDisplay display = state.parentStyle()->display();
    186     if (!isValidDisplayValue(state, display))
    187         return;
    188     state.style()->setDisplay(display);
    189 }
    190 
    191 void StyleBuilderFunctions::applyValueCSSPropertyDisplay(StyleResolverState& state, CSSValue* value)
    192 {
    193     if (!value->isPrimitiveValue())
    194         return;
    195 
    196     EDisplay display = *toCSSPrimitiveValue(value);
    197 
    198     if (!isValidDisplayValue(state, display))
    199         return;
    200 
    201     state.style()->setDisplay(display);
    202 }
    203 
    204 void StyleBuilderFunctions::applyInitialCSSPropertyFontFamily(StyleResolverState& state)
    205 {
    206     state.fontBuilder().setFontFamilyInitial(state.style()->effectiveZoom());
    207 }
    208 
    209 void StyleBuilderFunctions::applyInheritCSSPropertyFontFamily(StyleResolverState& state)
    210 {
    211     state.fontBuilder().setFontFamilyInherit(state.parentFontDescription());
    212 }
    213 
    214 void StyleBuilderFunctions::applyValueCSSPropertyFontFamily(StyleResolverState& state, CSSValue* value)
    215 {
    216     state.fontBuilder().setFontFamilyValue(value, state.style()->effectiveZoom());
    217 }
    218 
    219 void StyleBuilderFunctions::applyInitialCSSPropertyFontSize(StyleResolverState& state)
    220 {
    221     state.fontBuilder().setFontSizeInitial(state.style()->effectiveZoom());
    222 }
    223 
    224 void StyleBuilderFunctions::applyInheritCSSPropertyFontSize(StyleResolverState& state)
    225 {
    226     state.fontBuilder().setFontSizeInherit(state.parentFontDescription(), state.style()->effectiveZoom());
    227 }
    228 
    229 void StyleBuilderFunctions::applyValueCSSPropertyFontSize(StyleResolverState& state, CSSValue* value)
    230 {
    231     state.fontBuilder().setFontSizeValue(value, state.parentStyle(), state.rootElementStyle(), state.style()->effectiveZoom());
    232 }
    233 
    234 void StyleBuilderFunctions::applyInitialCSSPropertyFontWeight(StyleResolverState& state)
    235 {
    236     state.fontBuilder().setWeight(FontWeightNormal);
    237 }
    238 
    239 void StyleBuilderFunctions::applyInheritCSSPropertyFontWeight(StyleResolverState& state)
    240 {
    241     state.fontBuilder().setWeight(state.parentFontDescription().weight());
    242 }
    243 
    244 void StyleBuilderFunctions::applyValueCSSPropertyFontWeight(StyleResolverState& state, CSSValue* value)
    245 {
    246     if (!value->isPrimitiveValue())
    247         return;
    248     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    249     switch (primitiveValue->getValueID()) {
    250     case CSSValueInvalid:
    251         ASSERT_NOT_REACHED();
    252         break;
    253     case CSSValueBolder:
    254         state.fontBuilder().setWeightBolder();
    255         break;
    256     case CSSValueLighter:
    257         state.fontBuilder().setWeightLighter();
    258         break;
    259     default:
    260         state.fontBuilder().setWeight(*primitiveValue);
    261     }
    262 }
    263 
    264 void StyleBuilderFunctions::applyValueCSSPropertyLineHeight(StyleResolverState& state, CSSValue* value)
    265 {
    266     if (!value->isPrimitiveValue())
    267         return;
    268 
    269     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    270     Length lineHeight;
    271 
    272     if (primitiveValue->getValueID() == CSSValueNormal) {
    273         lineHeight = RenderStyle::initialLineHeight();
    274     } else if (primitiveValue->isLength()) {
    275         float multiplier = state.style()->effectiveZoom();
    276         if (Frame* frame = state.document().frame())
    277             multiplier *= frame->textZoomFactor();
    278         lineHeight = primitiveValue->computeLength<Length>(state.cssToLengthConversionData().copyWithAdjustedZoom(multiplier));
    279     } else if (primitiveValue->isPercentage()) {
    280         lineHeight = Length((state.style()->computedFontSize() * primitiveValue->getIntValue()) / 100.0, Fixed);
    281     } else if (primitiveValue->isNumber()) {
    282         lineHeight = Length(primitiveValue->getDoubleValue() * 100.0, Percent);
    283     } else if (primitiveValue->isViewportPercentageLength()) {
    284         lineHeight = primitiveValue->viewportPercentageLength();
    285     } else if (primitiveValue->isCalculated()) {
    286         double multiplier = state.style()->effectiveZoom();
    287         if (Frame* frame = state.document().frame())
    288             multiplier *= frame->textZoomFactor();
    289         Length zoomedLength = Length(primitiveValue->cssCalcValue()->toCalcValue(state.cssToLengthConversionData().copyWithAdjustedZoom(multiplier)));
    290         lineHeight = Length(valueForLength(zoomedLength, state.style()->fontSize()), Fixed);
    291     } else {
    292         return;
    293     }
    294     state.style()->setLineHeight(lineHeight);
    295 }
    296 
    297 void StyleBuilderFunctions::applyValueCSSPropertyListStyleImage(StyleResolverState& state, CSSValue* value)
    298 {
    299     state.style()->setListStyleImage(state.styleImage(CSSPropertyListStyleImage, value));
    300 }
    301 
    302 void StyleBuilderFunctions::applyInitialCSSPropertyOutlineStyle(StyleResolverState& state)
    303 {
    304     state.style()->setOutlineStyleIsAuto(RenderStyle::initialOutlineStyleIsAuto());
    305     state.style()->setOutlineStyle(RenderStyle::initialBorderStyle());
    306 }
    307 
    308 void StyleBuilderFunctions::applyInheritCSSPropertyOutlineStyle(StyleResolverState& state)
    309 {
    310     state.style()->setOutlineStyleIsAuto(state.parentStyle()->outlineStyleIsAuto());
    311     state.style()->setOutlineStyle(state.parentStyle()->outlineStyle());
    312 }
    313 
    314 void StyleBuilderFunctions::applyValueCSSPropertyOutlineStyle(StyleResolverState& state, CSSValue* value)
    315 {
    316     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    317     state.style()->setOutlineStyleIsAuto(*primitiveValue);
    318     state.style()->setOutlineStyle(*primitiveValue);
    319 }
    320 
    321 void StyleBuilderFunctions::applyValueCSSPropertyResize(StyleResolverState& state, CSSValue* value)
    322 {
    323     if (!value->isPrimitiveValue())
    324         return;
    325 
    326     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    327 
    328     EResize r = RESIZE_NONE;
    329     switch (primitiveValue->getValueID()) {
    330     case 0:
    331         return;
    332     case CSSValueAuto:
    333         if (Settings* settings = state.document().settings())
    334             r = settings->textAreasAreResizable() ? RESIZE_BOTH : RESIZE_NONE;
    335         break;
    336     default:
    337         r = *primitiveValue;
    338     }
    339     state.style()->setResize(r);
    340 }
    341 
    342 static Length mmLength(double mm) { return Length(mm * cssPixelsPerMillimeter, Fixed); }
    343 static Length inchLength(double inch) { return Length(inch * cssPixelsPerInch, Fixed); }
    344 static bool getPageSizeFromName(CSSPrimitiveValue* pageSizeName, CSSPrimitiveValue* pageOrientation, Length& width, Length& height)
    345 {
    346     DEFINE_STATIC_LOCAL(Length, a5Width, (mmLength(148)));
    347     DEFINE_STATIC_LOCAL(Length, a5Height, (mmLength(210)));
    348     DEFINE_STATIC_LOCAL(Length, a4Width, (mmLength(210)));
    349     DEFINE_STATIC_LOCAL(Length, a4Height, (mmLength(297)));
    350     DEFINE_STATIC_LOCAL(Length, a3Width, (mmLength(297)));
    351     DEFINE_STATIC_LOCAL(Length, a3Height, (mmLength(420)));
    352     DEFINE_STATIC_LOCAL(Length, b5Width, (mmLength(176)));
    353     DEFINE_STATIC_LOCAL(Length, b5Height, (mmLength(250)));
    354     DEFINE_STATIC_LOCAL(Length, b4Width, (mmLength(250)));
    355     DEFINE_STATIC_LOCAL(Length, b4Height, (mmLength(353)));
    356     DEFINE_STATIC_LOCAL(Length, letterWidth, (inchLength(8.5)));
    357     DEFINE_STATIC_LOCAL(Length, letterHeight, (inchLength(11)));
    358     DEFINE_STATIC_LOCAL(Length, legalWidth, (inchLength(8.5)));
    359     DEFINE_STATIC_LOCAL(Length, legalHeight, (inchLength(14)));
    360     DEFINE_STATIC_LOCAL(Length, ledgerWidth, (inchLength(11)));
    361     DEFINE_STATIC_LOCAL(Length, ledgerHeight, (inchLength(17)));
    362 
    363     if (!pageSizeName)
    364         return false;
    365 
    366     switch (pageSizeName->getValueID()) {
    367     case CSSValueA5:
    368         width = a5Width;
    369         height = a5Height;
    370         break;
    371     case CSSValueA4:
    372         width = a4Width;
    373         height = a4Height;
    374         break;
    375     case CSSValueA3:
    376         width = a3Width;
    377         height = a3Height;
    378         break;
    379     case CSSValueB5:
    380         width = b5Width;
    381         height = b5Height;
    382         break;
    383     case CSSValueB4:
    384         width = b4Width;
    385         height = b4Height;
    386         break;
    387     case CSSValueLetter:
    388         width = letterWidth;
    389         height = letterHeight;
    390         break;
    391     case CSSValueLegal:
    392         width = legalWidth;
    393         height = legalHeight;
    394         break;
    395     case CSSValueLedger:
    396         width = ledgerWidth;
    397         height = ledgerHeight;
    398         break;
    399     default:
    400         return false;
    401     }
    402 
    403     if (pageOrientation) {
    404         switch (pageOrientation->getValueID()) {
    405         case CSSValueLandscape:
    406             std::swap(width, height);
    407             break;
    408         case CSSValuePortrait:
    409             // Nothing to do.
    410             break;
    411         default:
    412             return false;
    413         }
    414     }
    415     return true;
    416 }
    417 
    418 void StyleBuilderFunctions::applyInitialCSSPropertySize(StyleResolverState&) { }
    419 void StyleBuilderFunctions::applyInheritCSSPropertySize(StyleResolverState&) { }
    420 void StyleBuilderFunctions::applyValueCSSPropertySize(StyleResolverState& state, CSSValue* value)
    421 {
    422     state.style()->resetPageSizeType();
    423     Length width;
    424     Length height;
    425     PageSizeType pageSizeType = PAGE_SIZE_AUTO;
    426     CSSValueListInspector inspector(value);
    427     switch (inspector.length()) {
    428     case 2: {
    429         // <length>{2} | <page-size> <orientation>
    430         if (!inspector.first()->isPrimitiveValue() || !inspector.second()->isPrimitiveValue())
    431             return;
    432         CSSPrimitiveValue* first = toCSSPrimitiveValue(inspector.first());
    433         CSSPrimitiveValue* second = toCSSPrimitiveValue(inspector.second());
    434         if (first->isLength()) {
    435             // <length>{2}
    436             if (!second->isLength())
    437                 return;
    438             width = first->computeLength<Length>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
    439             height = second->computeLength<Length>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
    440         } else {
    441             // <page-size> <orientation>
    442             // The value order is guaranteed. See CSSParser::parseSizeParameter.
    443             if (!getPageSizeFromName(first, second, width, height))
    444                 return;
    445         }
    446         pageSizeType = PAGE_SIZE_RESOLVED;
    447         break;
    448     }
    449     case 1: {
    450         // <length> | auto | <page-size> | [ portrait | landscape]
    451         if (!inspector.first()->isPrimitiveValue())
    452             return;
    453         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(inspector.first());
    454         if (primitiveValue->isLength()) {
    455             // <length>
    456             pageSizeType = PAGE_SIZE_RESOLVED;
    457             width = height = primitiveValue->computeLength<Length>(state.cssToLengthConversionData().copyWithAdjustedZoom(1.0));
    458         } else {
    459             switch (primitiveValue->getValueID()) {
    460             case 0:
    461                 return;
    462             case CSSValueAuto:
    463                 pageSizeType = PAGE_SIZE_AUTO;
    464                 break;
    465             case CSSValuePortrait:
    466                 pageSizeType = PAGE_SIZE_AUTO_PORTRAIT;
    467                 break;
    468             case CSSValueLandscape:
    469                 pageSizeType = PAGE_SIZE_AUTO_LANDSCAPE;
    470                 break;
    471             default:
    472                 // <page-size>
    473                 pageSizeType = PAGE_SIZE_RESOLVED;
    474                 if (!getPageSizeFromName(primitiveValue, 0, width, height))
    475                     return;
    476             }
    477         }
    478         break;
    479     }
    480     default:
    481         return;
    482     }
    483     state.style()->setPageSizeType(pageSizeType);
    484     state.style()->setPageSize(LengthSize(width, height));
    485 }
    486 
    487 void StyleBuilderFunctions::applyValueCSSPropertyTextAlign(StyleResolverState& state, CSSValue* value)
    488 {
    489     if (!value->isPrimitiveValue())
    490         return;
    491 
    492     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    493     // FIXME : Per http://www.w3.org/TR/css3-text/#text-align0 can now take <string> but this is not implemented in the
    494     // rendering code.
    495     if (primitiveValue->isString())
    496         return;
    497 
    498     if (primitiveValue->isValueID() && primitiveValue->getValueID() != CSSValueWebkitMatchParent)
    499         state.style()->setTextAlign(*primitiveValue);
    500     else if (state.parentStyle()->textAlign() == TASTART)
    501         state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? LEFT : RIGHT);
    502     else if (state.parentStyle()->textAlign() == TAEND)
    503         state.style()->setTextAlign(state.parentStyle()->isLeftToRightDirection() ? RIGHT : LEFT);
    504     else
    505         state.style()->setTextAlign(state.parentStyle()->textAlign());
    506 }
    507 
    508 void StyleBuilderFunctions::applyValueCSSPropertyTextDecoration(StyleResolverState& state, CSSValue* value)
    509 {
    510     TextDecoration t = RenderStyle::initialTextDecoration();
    511     for (CSSValueListIterator i(value); i.hasMore(); i.advance()) {
    512         CSSValue* item = i.value();
    513         t |= *toCSSPrimitiveValue(item);
    514     }
    515     state.style()->setTextDecoration(t);
    516 }
    517 
    518 void StyleBuilderFunctions::applyInheritCSSPropertyTextIndent(StyleResolverState& state)
    519 {
    520     state.style()->setTextIndent(state.parentStyle()->textIndent());
    521     state.style()->setTextIndentLine(state.parentStyle()->textIndentLine());
    522 }
    523 
    524 void StyleBuilderFunctions::applyInitialCSSPropertyTextIndent(StyleResolverState& state)
    525 {
    526     state.style()->setTextIndent(RenderStyle::initialTextIndent());
    527     state.style()->setTextIndentLine(RenderStyle::initialTextIndentLine());
    528 }
    529 
    530 void StyleBuilderFunctions::applyValueCSSPropertyTextIndent(StyleResolverState& state, CSSValue* value)
    531 {
    532     if (!value->isValueList())
    533         return;
    534 
    535     // [ <length> | <percentage> ] each-line
    536     // The order is guaranteed. See CSSParser::parseTextIndent.
    537     // The second value, each-line is handled only when css3TextEnabled() returns true.
    538 
    539     CSSValueList* valueList = toCSSValueList(value);
    540     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(valueList->itemWithoutBoundsCheck(0));
    541     Length lengthOrPercentageValue = primitiveValue->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData());
    542     ASSERT(!lengthOrPercentageValue.isUndefined());
    543     state.style()->setTextIndent(lengthOrPercentageValue);
    544 
    545     ASSERT(valueList->length() <= 2);
    546     CSSPrimitiveValue* eachLineValue = toCSSPrimitiveValue(valueList->item(1));
    547     if (eachLineValue) {
    548         ASSERT(eachLineValue->getValueID() == CSSValueEachLine);
    549         state.style()->setTextIndentLine(TextIndentEachLine);
    550     } else
    551         state.style()->setTextIndentLine(TextIndentFirstLine);
    552 }
    553 
    554 void StyleBuilderFunctions::applyValueCSSPropertyVerticalAlign(StyleResolverState& state, CSSValue* value)
    555 {
    556     if (!value->isPrimitiveValue())
    557         return;
    558 
    559     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    560 
    561     if (primitiveValue->getValueID())
    562         return state.style()->setVerticalAlign(*primitiveValue);
    563 
    564     state.style()->setVerticalAlignLength(primitiveValue->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()));
    565 }
    566 
    567 void StyleBuilderFunctions::applyValueCSSPropertyTouchAction(StyleResolverState& state, CSSValue* value)
    568 {
    569     TouchAction action = RenderStyle::initialTouchAction();
    570     for (CSSValueListIterator i(value); i.hasMore(); i.advance())
    571         action |= *toCSSPrimitiveValue(i.value());
    572 
    573     state.style()->setTouchAction(action);
    574 }
    575 
    576 static void resetEffectiveZoom(StyleResolverState& state)
    577 {
    578     // Reset the zoom in effect. This allows the setZoom method to accurately compute a new zoom in effect.
    579     state.setEffectiveZoom(state.parentStyle() ? state.parentStyle()->effectiveZoom() : RenderStyle::initialZoom());
    580 }
    581 
    582 void StyleBuilderFunctions::applyInitialCSSPropertyZoom(StyleResolverState& state)
    583 {
    584     resetEffectiveZoom(state);
    585     state.setZoom(RenderStyle::initialZoom());
    586 }
    587 
    588 void StyleBuilderFunctions::applyInheritCSSPropertyZoom(StyleResolverState& state)
    589 {
    590     resetEffectiveZoom(state);
    591     state.setZoom(state.parentStyle()->zoom());
    592 }
    593 
    594 void StyleBuilderFunctions::applyValueCSSPropertyZoom(StyleResolverState& state, CSSValue* value)
    595 {
    596     ASSERT_WITH_SECURITY_IMPLICATION(value->isPrimitiveValue());
    597     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    598 
    599     if (primitiveValue->getValueID() == CSSValueNormal) {
    600         resetEffectiveZoom(state);
    601         state.setZoom(RenderStyle::initialZoom());
    602     } else if (primitiveValue->getValueID() == CSSValueReset) {
    603         state.setEffectiveZoom(RenderStyle::initialZoom());
    604         state.setZoom(RenderStyle::initialZoom());
    605     } else if (primitiveValue->getValueID() == CSSValueDocument) {
    606         float docZoom = state.rootElementStyle() ? state.rootElementStyle()->zoom() : RenderStyle::initialZoom();
    607         state.setEffectiveZoom(docZoom);
    608         state.setZoom(docZoom);
    609     } else if (primitiveValue->isPercentage()) {
    610         resetEffectiveZoom(state);
    611         if (float percent = primitiveValue->getFloatValue())
    612             state.setZoom(percent / 100.0f);
    613     } else if (primitiveValue->isNumber()) {
    614         resetEffectiveZoom(state);
    615         if (float number = primitiveValue->getFloatValue())
    616             state.setZoom(number);
    617     }
    618 }
    619 
    620 void StyleBuilderFunctions::applyInitialCSSPropertyWebkitAspectRatio(StyleResolverState& state)
    621 {
    622     state.style()->setHasAspectRatio(RenderStyle::initialHasAspectRatio());
    623     state.style()->setAspectRatioDenominator(RenderStyle::initialAspectRatioDenominator());
    624     state.style()->setAspectRatioNumerator(RenderStyle::initialAspectRatioNumerator());
    625 }
    626 
    627 void StyleBuilderFunctions::applyInheritCSSPropertyWebkitAspectRatio(StyleResolverState& state)
    628 {
    629     if (!state.parentStyle()->hasAspectRatio())
    630         return;
    631     state.style()->setHasAspectRatio(true);
    632     state.style()->setAspectRatioDenominator(state.parentStyle()->aspectRatioDenominator());
    633     state.style()->setAspectRatioNumerator(state.parentStyle()->aspectRatioNumerator());
    634 }
    635 
    636 void StyleBuilderFunctions::applyValueCSSPropertyWebkitAspectRatio(StyleResolverState& state, CSSValue* value)
    637 {
    638     if (!value->isAspectRatioValue()) {
    639         state.style()->setHasAspectRatio(false);
    640         return;
    641     }
    642     CSSAspectRatioValue* aspectRatioValue = toCSSAspectRatioValue(value);
    643     state.style()->setHasAspectRatio(true);
    644     state.style()->setAspectRatioDenominator(aspectRatioValue->denominatorValue());
    645     state.style()->setAspectRatioNumerator(aspectRatioValue->numeratorValue());
    646 }
    647 
    648 void StyleBuilderFunctions::applyValueCSSPropertyWebkitBorderImage(StyleResolverState& state, CSSValue* value)
    649 {
    650     NinePieceImage image;
    651     state.styleMap().mapNinePieceImage(state.style(), CSSPropertyWebkitBorderImage, value, image);
    652     state.style()->setBorderImage(image);
    653 }
    654 
    655 void StyleBuilderFunctions::applyValueCSSPropertyWebkitClipPath(StyleResolverState& state, CSSValue* value)
    656 {
    657     if (value->isPrimitiveValue()) {
    658         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    659         if (primitiveValue->getValueID() == CSSValueNone) {
    660             state.style()->setClipPath(0);
    661         } else if (primitiveValue->isShape()) {
    662             state.style()->setClipPath(ShapeClipPathOperation::create(basicShapeForValue(state, primitiveValue->getShapeValue())));
    663         } else if (primitiveValue->primitiveType() == CSSPrimitiveValue::CSS_URI) {
    664             String cssURLValue = primitiveValue->getStringValue();
    665             KURL url = state.document().completeURL(cssURLValue);
    666             // FIXME: It doesn't work with forward or external SVG references (see https://bugs.webkit.org/show_bug.cgi?id=90405)
    667             state.style()->setClipPath(ReferenceClipPathOperation::create(cssURLValue, url.fragmentIdentifier()));
    668         }
    669     }
    670 }
    671 
    672 void StyleBuilderFunctions::applyInitialCSSPropertyWebkitFontVariantLigatures(StyleResolverState& state)
    673 {
    674     state.fontBuilder().setFontVariantLigaturesInitial();
    675 }
    676 
    677 void StyleBuilderFunctions::applyInheritCSSPropertyWebkitFontVariantLigatures(StyleResolverState& state)
    678 {
    679     state.fontBuilder().setFontVariantLigaturesInherit(state.parentFontDescription());
    680 }
    681 
    682 void StyleBuilderFunctions::applyValueCSSPropertyWebkitFontVariantLigatures(StyleResolverState& state, CSSValue* value)
    683 {
    684     state.fontBuilder().setFontVariantLigaturesValue(value);
    685 }
    686 
    687 void StyleBuilderFunctions::applyValueCSSPropertyInternalMarqueeIncrement(StyleResolverState& state, CSSValue* value)
    688 {
    689     if (!value->isPrimitiveValue())
    690         return;
    691 
    692     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    693     if (primitiveValue->getValueID()) {
    694         switch (primitiveValue->getValueID()) {
    695         case CSSValueSmall:
    696             state.style()->setMarqueeIncrement(Length(1, Fixed)); // 1px.
    697             break;
    698         case CSSValueNormal:
    699             state.style()->setMarqueeIncrement(Length(6, Fixed)); // 6px. The WinIE default.
    700             break;
    701         case CSSValueLarge:
    702             state.style()->setMarqueeIncrement(Length(36, Fixed)); // 36px.
    703             break;
    704         default:
    705             break;
    706         }
    707     } else {
    708         Length marqueeLength = primitiveValue ? primitiveValue->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()) : Length(Undefined);
    709         if (!marqueeLength.isUndefined())
    710             state.style()->setMarqueeIncrement(marqueeLength);
    711     }
    712 }
    713 
    714 void StyleBuilderFunctions::applyValueCSSPropertyInternalMarqueeSpeed(StyleResolverState& state, CSSValue* value)
    715 {
    716     if (!value->isPrimitiveValue())
    717         return;
    718 
    719     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    720     if (CSSValueID valueID = primitiveValue->getValueID()) {
    721         switch (valueID) {
    722         case CSSValueSlow:
    723             state.style()->setMarqueeSpeed(500); // 500 msec.
    724             break;
    725         case CSSValueNormal:
    726             state.style()->setMarqueeSpeed(85); // 85msec. The WinIE default.
    727             break;
    728         case CSSValueFast:
    729             state.style()->setMarqueeSpeed(10); // 10msec. Super fast.
    730             break;
    731         default:
    732             break;
    733         }
    734     } else if (primitiveValue->isTime()) {
    735         state.style()->setMarqueeSpeed(primitiveValue->computeTime<int, CSSPrimitiveValue::Milliseconds>());
    736     } else if (primitiveValue->isNumber()) { // For scrollamount support.
    737         state.style()->setMarqueeSpeed(primitiveValue->getIntValue());
    738     }
    739 }
    740 
    741 // FIXME: We should use the same system for this as the rest of the pseudo-shorthands (e.g. background-position)
    742 void StyleBuilderFunctions::applyInitialCSSPropertyWebkitPerspectiveOrigin(StyleResolverState& state)
    743 {
    744     applyInitialCSSPropertyWebkitPerspectiveOriginX(state);
    745     applyInitialCSSPropertyWebkitPerspectiveOriginY(state);
    746 }
    747 
    748 void StyleBuilderFunctions::applyInheritCSSPropertyWebkitPerspectiveOrigin(StyleResolverState& state)
    749 {
    750     applyInheritCSSPropertyWebkitPerspectiveOriginX(state);
    751     applyInheritCSSPropertyWebkitPerspectiveOriginY(state);
    752 }
    753 
    754 void StyleBuilderFunctions::applyValueCSSPropertyWebkitPerspectiveOrigin(StyleResolverState&, CSSValue* value)
    755 {
    756     // This is expanded in the parser
    757     ASSERT_NOT_REACHED();
    758 }
    759 
    760 void StyleBuilderFunctions::applyInitialCSSPropertyWebkitTextEmphasisStyle(StyleResolverState& state)
    761 {
    762     state.style()->setTextEmphasisFill(RenderStyle::initialTextEmphasisFill());
    763     state.style()->setTextEmphasisMark(RenderStyle::initialTextEmphasisMark());
    764     state.style()->setTextEmphasisCustomMark(RenderStyle::initialTextEmphasisCustomMark());
    765 }
    766 
    767 void StyleBuilderFunctions::applyInheritCSSPropertyWebkitTextEmphasisStyle(StyleResolverState& state)
    768 {
    769     state.style()->setTextEmphasisFill(state.parentStyle()->textEmphasisFill());
    770     state.style()->setTextEmphasisMark(state.parentStyle()->textEmphasisMark());
    771     state.style()->setTextEmphasisCustomMark(state.parentStyle()->textEmphasisCustomMark());
    772 }
    773 
    774 void StyleBuilderFunctions::applyValueCSSPropertyWebkitTextEmphasisStyle(StyleResolverState& state, CSSValue* value)
    775 {
    776     if (value->isValueList()) {
    777         CSSValueList* list = toCSSValueList(value);
    778         ASSERT(list->length() == 2);
    779         if (list->length() != 2)
    780             return;
    781         for (unsigned i = 0; i < 2; ++i) {
    782             CSSValue* item = list->itemWithoutBoundsCheck(i);
    783             if (!item->isPrimitiveValue())
    784                 continue;
    785 
    786             CSSPrimitiveValue* value = toCSSPrimitiveValue(item);
    787             if (value->getValueID() == CSSValueFilled || value->getValueID() == CSSValueOpen)
    788                 state.style()->setTextEmphasisFill(*value);
    789             else
    790                 state.style()->setTextEmphasisMark(*value);
    791         }
    792         state.style()->setTextEmphasisCustomMark(nullAtom);
    793         return;
    794     }
    795 
    796     if (!value->isPrimitiveValue())
    797         return;
    798     CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    799 
    800     if (primitiveValue->isString()) {
    801         state.style()->setTextEmphasisFill(TextEmphasisFillFilled);
    802         state.style()->setTextEmphasisMark(TextEmphasisMarkCustom);
    803         state.style()->setTextEmphasisCustomMark(AtomicString(primitiveValue->getStringValue()));
    804         return;
    805     }
    806 
    807     state.style()->setTextEmphasisCustomMark(nullAtom);
    808 
    809     if (primitiveValue->getValueID() == CSSValueFilled || primitiveValue->getValueID() == CSSValueOpen) {
    810         state.style()->setTextEmphasisFill(*primitiveValue);
    811         state.style()->setTextEmphasisMark(TextEmphasisMarkAuto);
    812     } else {
    813         state.style()->setTextEmphasisFill(TextEmphasisFillFilled);
    814         state.style()->setTextEmphasisMark(*primitiveValue);
    815     }
    816 }
    817 
    818 void StyleBuilderFunctions::applyValueCSSPropertyTextUnderlinePosition(StyleResolverState& state, CSSValue* value)
    819 {
    820     // This is true if value is 'auto' or 'alphabetic'.
    821     if (value->isPrimitiveValue()) {
    822         TextUnderlinePosition t = *toCSSPrimitiveValue(value);
    823         state.style()->setTextUnderlinePosition(t);
    824         return;
    825     }
    826 
    827     unsigned t = 0;
    828     for (CSSValueListIterator i(value); i.hasMore(); i.advance()) {
    829         CSSValue* item = i.value();
    830         TextUnderlinePosition t2 = *toCSSPrimitiveValue(item);
    831         t |= t2;
    832     }
    833     state.style()->setTextUnderlinePosition(static_cast<TextUnderlinePosition>(t));
    834 }
    835 
    836 // Everything below this line is from the old StyleResolver::applyProperty
    837 // and eventually needs to move into new StyleBuilderFunctions calls intead.
    838 
    839 #define HANDLE_INHERIT(prop, Prop) \
    840 if (isInherit) { \
    841     state.style()->set##Prop(state.parentStyle()->prop()); \
    842     return; \
    843 }
    844 
    845 #define HANDLE_INHERIT_AND_INITIAL(prop, Prop) \
    846 HANDLE_INHERIT(prop, Prop) \
    847 if (isInitial) { \
    848     state.style()->set##Prop(RenderStyle::initial##Prop()); \
    849     return; \
    850 }
    851 
    852 #define HANDLE_SVG_INHERIT(prop, Prop) \
    853 if (isInherit) { \
    854     state.style()->accessSVGStyle()->set##Prop(state.parentStyle()->svgStyle()->prop()); \
    855     return; \
    856 }
    857 
    858 #define HANDLE_SVG_INHERIT_AND_INITIAL(prop, Prop) \
    859 HANDLE_SVG_INHERIT(prop, Prop) \
    860 if (isInitial) { \
    861     state.style()->accessSVGStyle()->set##Prop(SVGRenderStyle::initial##Prop()); \
    862     return; \
    863 }
    864 
    865 static bool createGridTrackBreadth(CSSPrimitiveValue* primitiveValue, const StyleResolverState& state, GridLength& workingLength)
    866 {
    867     if (primitiveValue->getValueID() == CSSValueMinContent) {
    868         workingLength = Length(MinContent);
    869         return true;
    870     }
    871 
    872     if (primitiveValue->getValueID() == CSSValueMaxContent) {
    873         workingLength = Length(MaxContent);
    874         return true;
    875     }
    876 
    877     if (primitiveValue->isFlex()) {
    878         // Fractional unit.
    879         workingLength.setFlex(primitiveValue->getDoubleValue());
    880         return true;
    881     }
    882 
    883     workingLength = primitiveValue->convertToLength<FixedConversion | PercentConversion | AutoConversion>(state.cssToLengthConversionData());
    884     if (workingLength.length().isUndefined())
    885         return false;
    886 
    887     if (primitiveValue->isLength())
    888         workingLength.length().setQuirk(primitiveValue->isQuirkValue());
    889 
    890     return true;
    891 }
    892 
    893 static bool createGridTrackSize(CSSValue* value, GridTrackSize& trackSize, const StyleResolverState& state)
    894 {
    895     if (value->isPrimitiveValue()) {
    896         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    897         GridLength workingLength;
    898         if (!createGridTrackBreadth(primitiveValue, state, workingLength))
    899             return false;
    900 
    901         trackSize.setLength(workingLength);
    902         return true;
    903     }
    904 
    905     CSSFunctionValue* minmaxFunction = toCSSFunctionValue(value);
    906     CSSValueList* arguments = minmaxFunction->arguments();
    907     ASSERT_WITH_SECURITY_IMPLICATION(arguments->length() == 2);
    908     GridLength minTrackBreadth;
    909     GridLength maxTrackBreadth;
    910     if (!createGridTrackBreadth(toCSSPrimitiveValue(arguments->itemWithoutBoundsCheck(0)), state, minTrackBreadth) || !createGridTrackBreadth(toCSSPrimitiveValue(arguments->itemWithoutBoundsCheck(1)), state, maxTrackBreadth))
    911         return false;
    912 
    913     trackSize.setMinMax(minTrackBreadth, maxTrackBreadth);
    914     return true;
    915 }
    916 
    917 static bool createGridTrackList(CSSValue* value, Vector<GridTrackSize>& trackSizes, NamedGridLinesMap& namedGridLines, OrderedNamedGridLines& orderedNamedGridLines, const StyleResolverState& state)
    918 {
    919     // Handle 'none'.
    920     if (value->isPrimitiveValue()) {
    921         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    922         return primitiveValue->getValueID() == CSSValueNone;
    923     }
    924 
    925     if (!value->isValueList())
    926         return false;
    927 
    928     size_t currentNamedGridLine = 0;
    929     for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
    930         CSSValue* currValue = i.value();
    931         if (currValue->isGridLineNamesValue()) {
    932             CSSGridLineNamesValue* lineNamesValue = toCSSGridLineNamesValue(currValue);
    933             for (CSSValueListIterator j = lineNamesValue; j.hasMore(); j.advance()) {
    934                 String namedGridLine = toCSSPrimitiveValue(j.value())->getStringValue();
    935                 NamedGridLinesMap::AddResult result = namedGridLines.add(namedGridLine, Vector<size_t>());
    936                 result.iterator->value.append(currentNamedGridLine);
    937                 OrderedNamedGridLines::AddResult orderedInsertionResult = orderedNamedGridLines.add(currentNamedGridLine, Vector<String>());
    938                 orderedInsertionResult.iterator->value.append(namedGridLine);
    939             }
    940             continue;
    941         }
    942 
    943         ++currentNamedGridLine;
    944         GridTrackSize trackSize;
    945         if (!createGridTrackSize(currValue, trackSize, state))
    946             return false;
    947 
    948         trackSizes.append(trackSize);
    949     }
    950 
    951     // The parser should have rejected any <track-list> without any <track-size> as
    952     // this is not conformant to the syntax.
    953     ASSERT(!trackSizes.isEmpty());
    954     return true;
    955 }
    956 
    957 static bool createGridPosition(CSSValue* value, GridPosition& position)
    958 {
    959     // We accept the specification's grammar:
    960     // 'auto' | [ <integer> || <string> ] | [ span && [ <integer> || string ] ] | <ident>
    961 
    962     if (value->isPrimitiveValue()) {
    963         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
    964         // We translate <ident> to <string> during parsing as it
    965         // makes handling it more simple.
    966         if (primitiveValue->isString()) {
    967             position.setNamedGridArea(primitiveValue->getStringValue());
    968             return true;
    969         }
    970 
    971         ASSERT(primitiveValue->getValueID() == CSSValueAuto);
    972         return true;
    973     }
    974 
    975     CSSValueList* values = toCSSValueList(value);
    976     ASSERT(values->length());
    977 
    978     bool isSpanPosition = false;
    979     // The specification makes the <integer> optional, in which case it default to '1'.
    980     int gridLineNumber = 1;
    981     String gridLineName;
    982 
    983     CSSValueListIterator it = values;
    984     CSSPrimitiveValue* currentValue = toCSSPrimitiveValue(it.value());
    985     if (currentValue->getValueID() == CSSValueSpan) {
    986         isSpanPosition = true;
    987         it.advance();
    988         currentValue = it.hasMore() ? toCSSPrimitiveValue(it.value()) : 0;
    989     }
    990 
    991     if (currentValue && currentValue->isNumber()) {
    992         gridLineNumber = currentValue->getIntValue();
    993         it.advance();
    994         currentValue = it.hasMore() ? toCSSPrimitiveValue(it.value()) : 0;
    995     }
    996 
    997     if (currentValue && currentValue->isString()) {
    998         gridLineName = currentValue->getStringValue();
    999         it.advance();
   1000     }
   1001 
   1002     ASSERT(!it.hasMore());
   1003     if (isSpanPosition)
   1004         position.setSpanPosition(gridLineNumber, gridLineName);
   1005     else
   1006         position.setExplicitPosition(gridLineNumber, gridLineName);
   1007 
   1008     return true;
   1009 }
   1010 
   1011 static bool degreeToGlyphOrientation(CSSPrimitiveValue* primitiveValue, EGlyphOrientation& orientation)
   1012 {
   1013     if (!primitiveValue)
   1014         return false;
   1015 
   1016     if (primitiveValue->primitiveType() != CSSPrimitiveValue::CSS_DEG)
   1017         return false;
   1018 
   1019     float angle = fabsf(fmodf(primitiveValue->getFloatValue(), 360.0f));
   1020 
   1021     if (angle <= 45.0f || angle > 315.0f) {
   1022         orientation = GO_0DEG;
   1023         return true;
   1024     }
   1025     if (angle > 45.0f && angle <= 135.0f) {
   1026         orientation = GO_90DEG;
   1027         return true;
   1028     }
   1029     if (angle > 135.0f && angle <= 225.0f) {
   1030         orientation = GO_180DEG;
   1031         return true;
   1032     }
   1033     orientation = GO_270DEG;
   1034     return true;
   1035 }
   1036 
   1037 static Color colorFromSVGColorCSSValue(SVGColor* svgColor, const Color& fgColor)
   1038 {
   1039     Color color;
   1040     if (svgColor->colorType() == SVGColor::SVG_COLORTYPE_CURRENTCOLOR)
   1041         color = fgColor;
   1042     else
   1043         color = svgColor->color();
   1044     return color;
   1045 }
   1046 
   1047 static EPaintOrder paintOrderFlattened(CSSValue* cssPaintOrder)
   1048 {
   1049     if (cssPaintOrder->isValueList()) {
   1050         int paintOrder = 0;
   1051         CSSValueListInspector iter(cssPaintOrder);
   1052         for (size_t i = 0; i < iter.length(); i++) {
   1053             CSSPrimitiveValue* value = toCSSPrimitiveValue(iter.item(i));
   1054 
   1055             EPaintOrderType paintOrderType = PT_NONE;
   1056             switch (value->getValueID()) {
   1057             case CSSValueFill:
   1058                 paintOrderType = PT_FILL;
   1059                 break;
   1060             case CSSValueStroke:
   1061                 paintOrderType = PT_STROKE;
   1062                 break;
   1063             case CSSValueMarkers:
   1064                 paintOrderType = PT_MARKERS;
   1065                 break;
   1066             default:
   1067                 ASSERT_NOT_REACHED();
   1068                 break;
   1069             }
   1070 
   1071             paintOrder |= (paintOrderType << kPaintOrderBitwidth*i);
   1072         }
   1073         return (EPaintOrder)paintOrder;
   1074     }
   1075 
   1076     return PO_NORMAL;
   1077 }
   1078 
   1079 static inline bool isValidVisitedLinkProperty(CSSPropertyID id)
   1080 {
   1081     switch (id) {
   1082     case CSSPropertyBackgroundColor:
   1083     case CSSPropertyBorderLeftColor:
   1084     case CSSPropertyBorderRightColor:
   1085     case CSSPropertyBorderTopColor:
   1086     case CSSPropertyBorderBottomColor:
   1087     case CSSPropertyColor:
   1088     case CSSPropertyFill:
   1089     case CSSPropertyOutlineColor:
   1090     case CSSPropertyStroke:
   1091     case CSSPropertyTextDecorationColor:
   1092     case CSSPropertyWebkitColumnRuleColor:
   1093     case CSSPropertyWebkitTextEmphasisColor:
   1094     case CSSPropertyWebkitTextFillColor:
   1095     case CSSPropertyWebkitTextStrokeColor:
   1096         return true;
   1097     default:
   1098         break;
   1099     }
   1100 
   1101     return false;
   1102 }
   1103 
   1104 static bool hasVariableReference(CSSValue* value)
   1105 {
   1106     if (value->isPrimitiveValue()) {
   1107         CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
   1108         return primitiveValue->hasVariableReference();
   1109     }
   1110 
   1111     if (value->isCalcValue())
   1112         return toCSSCalcValue(value)->hasVariableReference();
   1113 
   1114     if (value->isReflectValue()) {
   1115         CSSReflectValue* reflectValue = toCSSReflectValue(value);
   1116         CSSPrimitiveValue* direction = reflectValue->direction();
   1117         CSSPrimitiveValue* offset = reflectValue->offset();
   1118         CSSValue* mask = reflectValue->mask();
   1119         return (direction && hasVariableReference(direction)) || (offset && hasVariableReference(offset)) || (mask && hasVariableReference(mask));
   1120     }
   1121 
   1122     for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
   1123         if (hasVariableReference(i.value()))
   1124             return true;
   1125     }
   1126 
   1127     return false;
   1128 }
   1129 
   1130 // FIXME: Resolving variables should be factored better. Maybe a resover-style class?
   1131 static void resolveVariables(StyleResolverState& state, CSSPropertyID id, CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
   1132 {
   1133     std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVariables(*state.style()->variables()));
   1134 
   1135     if (knownExpressions.contains(expression))
   1136         return; // cycle detected.
   1137 
   1138     knownExpressions.append(expression);
   1139 
   1140     // FIXME: It would be faster not to re-parse from strings, but for now CSS property validation lives inside the parser so we do it there.
   1141     RefPtr<MutableStylePropertySet> resultSet = MutableStylePropertySet::create();
   1142     if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, state.document()))
   1143         return; // expression failed to parse.
   1144 
   1145     for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
   1146         StylePropertySet::PropertyReference property = resultSet->propertyAt(i);
   1147         if (property.id() != CSSPropertyVariable && hasVariableReference(property.value())) {
   1148             resolveVariables(state, property.id(), property.value(), knownExpressions);
   1149         } else {
   1150             StyleBuilder::applyProperty(property.id(), state, property.value());
   1151             // All properties become dependent on their parent style when they use variables.
   1152             state.style()->setHasExplicitlyInheritedProperties();
   1153         }
   1154     }
   1155 }
   1156 
   1157 void StyleBuilder::applyProperty(CSSPropertyID id, StyleResolverState& state, CSSValue* value)
   1158 {
   1159     if (RuntimeEnabledFeatures::cssVariablesEnabled() && id != CSSPropertyVariable && hasVariableReference(value)) {
   1160         Vector<std::pair<CSSPropertyID, String> > knownExpressions;
   1161         resolveVariables(state, id, value, knownExpressions);
   1162         return;
   1163     }
   1164 
   1165     // CSS variables don't resolve shorthands at parsing time, so this should be *after* handling variables.
   1166     ASSERT_WITH_MESSAGE(!isExpandedShorthand(id), "Shorthand property id = %d wasn't expanded at parsing time", id);
   1167 
   1168     bool isInherit = state.parentNode() && value->isInheritedValue();
   1169     bool isInitial = value->isInitialValue() || (!state.parentNode() && value->isInheritedValue());
   1170 
   1171     ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
   1172     ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInherit -> (state.parentNode() && state.parentStyle())
   1173 
   1174     if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLinkStyle() || !isValidVisitedLinkProperty(id))) {
   1175         // Limit the properties that can be applied to only the ones honored by :visited.
   1176         return;
   1177     }
   1178 
   1179     CSSPrimitiveValue* primitiveValue = value->isPrimitiveValue() ? toCSSPrimitiveValue(value) : 0;
   1180     if (primitiveValue && primitiveValue->getValueID() == CSSValueCurrentcolor)
   1181         state.style()->setHasCurrentColor();
   1182 
   1183     if (isInherit && !state.parentStyle()->hasExplicitlyInheritedProperties() && !CSSProperty::isInheritedProperty(id))
   1184         state.parentStyle()->setHasExplicitlyInheritedProperties();
   1185 
   1186     if (id == CSSPropertyVariable) {
   1187         ASSERT_WITH_SECURITY_IMPLICATION(value->isVariableValue());
   1188         CSSVariableValue* variable = toCSSVariableValue(value);
   1189         ASSERT(!variable->name().isEmpty());
   1190         ASSERT(!variable->value().isEmpty());
   1191         state.style()->setVariable(variable->name(), variable->value());
   1192         return;
   1193     }
   1194 
   1195     if (StyleBuilder::applyProperty(id, state, value, isInitial, isInherit))
   1196         return;
   1197 
   1198     // Fall back to the old switch statement, which is now in StyleBuilderCustom.cpp
   1199     StyleBuilder::oldApplyProperty(id, state, value, isInitial, isInherit);
   1200 }
   1201 
   1202 
   1203 void StyleBuilder::oldApplyProperty(CSSPropertyID id, StyleResolverState& state, CSSValue* value, bool isInitial, bool isInherit)
   1204 {
   1205     CSSPrimitiveValue* primitiveValue = value->isPrimitiveValue() ? toCSSPrimitiveValue(value) : 0;
   1206 
   1207     // What follows is a list that maps the CSS properties into their corresponding front-end
   1208     // RenderStyle values.
   1209     switch (id) {
   1210     case CSSPropertyContent:
   1211         // list of string, uri, counter, attr, i
   1212         {
   1213             // FIXME: In CSS3, it will be possible to inherit content. In CSS2 it is not. This
   1214             // note is a reminder that eventually "inherit" needs to be supported.
   1215 
   1216             if (isInitial) {
   1217                 state.style()->clearContent();
   1218                 return;
   1219             }
   1220 
   1221             if (!value->isValueList())
   1222                 return;
   1223 
   1224             bool didSet = false;
   1225             for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
   1226                 CSSValue* item = i.value();
   1227                 if (item->isImageGeneratorValue()) {
   1228                     if (item->isGradientValue())
   1229                         state.style()->setContent(StyleGeneratedImage::create(toCSSGradientValue(item)->gradientWithStylesResolved(state.document().textLinkColors(), state.style()->color()).get()), didSet);
   1230                     else
   1231                         state.style()->setContent(StyleGeneratedImage::create(toCSSImageGeneratorValue(item)), didSet);
   1232                     didSet = true;
   1233                 } else if (item->isImageSetValue()) {
   1234                     state.style()->setContent(state.elementStyleResources().setOrPendingFromValue(CSSPropertyContent, toCSSImageSetValue(item)), didSet);
   1235                     didSet = true;
   1236                 }
   1237 
   1238                 if (item->isImageValue()) {
   1239                     state.style()->setContent(state.elementStyleResources().cachedOrPendingFromValue(CSSPropertyContent, toCSSImageValue(item)), didSet);
   1240                     didSet = true;
   1241                     continue;
   1242                 }
   1243 
   1244                 if (!item->isPrimitiveValue())
   1245                     continue;
   1246 
   1247                 CSSPrimitiveValue* contentValue = toCSSPrimitiveValue(item);
   1248 
   1249                 if (contentValue->isString()) {
   1250                     state.style()->setContent(contentValue->getStringValue().impl(), didSet);
   1251                     didSet = true;
   1252                 } else if (contentValue->isAttr()) {
   1253                     // FIXME: Can a namespace be specified for an attr(foo)?
   1254                     if (state.style()->styleType() == NOPSEUDO)
   1255                         state.style()->setUnique();
   1256                     else
   1257                         state.parentStyle()->setUnique();
   1258                     QualifiedName attr(nullAtom, AtomicString(contentValue->getStringValue()), nullAtom);
   1259                     const AtomicString& value = state.element()->getAttribute(attr);
   1260                     state.style()->setContent(value.isNull() ? emptyString() : value.string(), didSet);
   1261                     didSet = true;
   1262                     // register the fact that the attribute value affects the style
   1263                     state.contentAttrValues().append(attr.localName());
   1264                 } else if (contentValue->isCounter()) {
   1265                     Counter* counterValue = contentValue->getCounterValue();
   1266                     EListStyleType listStyleType = NoneListStyle;
   1267                     CSSValueID listStyleIdent = counterValue->listStyleIdent();
   1268                     if (listStyleIdent != CSSValueNone)
   1269                         listStyleType = static_cast<EListStyleType>(listStyleIdent - CSSValueDisc);
   1270                     OwnPtr<CounterContent> counter = adoptPtr(new CounterContent(AtomicString(counterValue->identifier()), listStyleType, AtomicString(counterValue->separator())));
   1271                     state.style()->setContent(counter.release(), didSet);
   1272                     didSet = true;
   1273                 } else {
   1274                     switch (contentValue->getValueID()) {
   1275                     case CSSValueOpenQuote:
   1276                         state.style()->setContent(OPEN_QUOTE, didSet);
   1277                         didSet = true;
   1278                         break;
   1279                     case CSSValueCloseQuote:
   1280                         state.style()->setContent(CLOSE_QUOTE, didSet);
   1281                         didSet = true;
   1282                         break;
   1283                     case CSSValueNoOpenQuote:
   1284                         state.style()->setContent(NO_OPEN_QUOTE, didSet);
   1285                         didSet = true;
   1286                         break;
   1287                     case CSSValueNoCloseQuote:
   1288                         state.style()->setContent(NO_CLOSE_QUOTE, didSet);
   1289                         didSet = true;
   1290                         break;
   1291                     default:
   1292                         // normal and none do not have any effect.
   1293                         { }
   1294                     }
   1295                 }
   1296             }
   1297             if (!didSet)
   1298                 state.style()->clearContent();
   1299             return;
   1300         }
   1301     case CSSPropertyQuotes:
   1302         HANDLE_INHERIT_AND_INITIAL(quotes, Quotes);
   1303         if (value->isValueList()) {
   1304             CSSValueList* list = toCSSValueList(value);
   1305             RefPtr<QuotesData> quotes = QuotesData::create();
   1306             for (size_t i = 0; i < list->length(); i += 2) {
   1307                 CSSValue* first = list->itemWithoutBoundsCheck(i);
   1308                 // item() returns null if out of bounds so this is safe.
   1309                 CSSValue* second = list->item(i + 1);
   1310                 if (!second)
   1311                     continue;
   1312                 String startQuote = toCSSPrimitiveValue(first)->getStringValue();
   1313                 String endQuote = toCSSPrimitiveValue(second)->getStringValue();
   1314                 quotes->addPair(std::make_pair(startQuote, endQuote));
   1315             }
   1316             state.style()->setQuotes(quotes);
   1317             return;
   1318         }
   1319         if (primitiveValue) {
   1320             if (primitiveValue->getValueID() == CSSValueNone)
   1321                 state.style()->setQuotes(QuotesData::create());
   1322         }
   1323         return;
   1324     // Shorthand properties.
   1325     case CSSPropertyFont:
   1326         // Only System Font identifiers should come through this method
   1327         // all other values should have been handled when the shorthand
   1328         // was expanded by the parser.
   1329         // FIXME: System Font identifiers should not hijack this
   1330         // short-hand CSSProperty like this.
   1331         ASSERT(!isInitial);
   1332         ASSERT(!isInherit);
   1333         ASSERT(primitiveValue);
   1334         state.style()->setLineHeight(RenderStyle::initialLineHeight());
   1335         state.setLineHeightValue(0);
   1336         state.fontBuilder().fromSystemFont(primitiveValue->getValueID(), state.style()->effectiveZoom());
   1337         return;
   1338     case CSSPropertyAnimation:
   1339     case CSSPropertyBackground:
   1340     case CSSPropertyBackgroundPosition:
   1341     case CSSPropertyBackgroundRepeat:
   1342     case CSSPropertyBorder:
   1343     case CSSPropertyBorderBottom:
   1344     case CSSPropertyBorderColor:
   1345     case CSSPropertyBorderImage:
   1346     case CSSPropertyBorderLeft:
   1347     case CSSPropertyBorderRadius:
   1348     case CSSPropertyBorderRight:
   1349     case CSSPropertyBorderSpacing:
   1350     case CSSPropertyBorderStyle:
   1351     case CSSPropertyBorderTop:
   1352     case CSSPropertyBorderWidth:
   1353     case CSSPropertyListStyle:
   1354     case CSSPropertyMargin:
   1355     case CSSPropertyObjectPosition:
   1356     case CSSPropertyOutline:
   1357     case CSSPropertyOverflow:
   1358     case CSSPropertyPadding:
   1359     case CSSPropertyTransition:
   1360     case CSSPropertyWebkitAnimation:
   1361     case CSSPropertyWebkitBorderAfter:
   1362     case CSSPropertyWebkitBorderBefore:
   1363     case CSSPropertyWebkitBorderEnd:
   1364     case CSSPropertyWebkitBorderStart:
   1365     case CSSPropertyWebkitBorderRadius:
   1366     case CSSPropertyWebkitColumns:
   1367     case CSSPropertyWebkitColumnRule:
   1368     case CSSPropertyFlex:
   1369     case CSSPropertyFlexFlow:
   1370     case CSSPropertyGridColumn:
   1371     case CSSPropertyGridRow:
   1372     case CSSPropertyGridArea:
   1373     case CSSPropertyWebkitMarginCollapse:
   1374     case CSSPropertyWebkitMask:
   1375     case CSSPropertyWebkitMaskPosition:
   1376     case CSSPropertyWebkitMaskRepeat:
   1377     case CSSPropertyWebkitTextEmphasis:
   1378     case CSSPropertyWebkitTextStroke:
   1379     case CSSPropertyWebkitTransition:
   1380     case CSSPropertyWebkitTransformOrigin:
   1381         ASSERT(isExpandedShorthand(id));
   1382         ASSERT_NOT_REACHED();
   1383         break;
   1384 
   1385     // CSS3 Properties
   1386     case CSSPropertyWebkitBoxReflect: {
   1387         HANDLE_INHERIT_AND_INITIAL(boxReflect, BoxReflect)
   1388         if (primitiveValue) {
   1389             state.style()->setBoxReflect(RenderStyle::initialBoxReflect());
   1390             return;
   1391         }
   1392 
   1393         if (!value->isReflectValue())
   1394             return;
   1395 
   1396         CSSReflectValue* reflectValue = toCSSReflectValue(value);
   1397         RefPtr<StyleReflection> reflection = StyleReflection::create();
   1398         reflection->setDirection(*reflectValue->direction());
   1399         if (reflectValue->offset())
   1400             reflection->setOffset(reflectValue->offset()->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData()));
   1401         NinePieceImage mask;
   1402         mask.setMaskDefaults();
   1403         state.styleMap().mapNinePieceImage(state.style(), id, reflectValue->mask(), mask);
   1404         reflection->setMask(mask);
   1405 
   1406         state.style()->setBoxReflect(reflection.release());
   1407         return;
   1408     }
   1409     case CSSPropertySrc: // Only used in @font-face rules.
   1410         return;
   1411     case CSSPropertyUnicodeRange: // Only used in @font-face rules.
   1412         return;
   1413     case CSSPropertyWebkitLocale: {
   1414         HANDLE_INHERIT_AND_INITIAL(locale, Locale);
   1415         if (!primitiveValue)
   1416             return;
   1417         if (primitiveValue->getValueID() == CSSValueAuto)
   1418             state.style()->setLocale(nullAtom);
   1419         else
   1420             state.style()->setLocale(AtomicString(primitiveValue->getStringValue()));
   1421         state.fontBuilder().setScript(state.style()->locale());
   1422         return;
   1423     }
   1424     case CSSPropertyWebkitAppRegion: {
   1425         if (!primitiveValue || !primitiveValue->getValueID())
   1426             return;
   1427         state.style()->setDraggableRegionMode(primitiveValue->getValueID() == CSSValueDrag ? DraggableRegionDrag : DraggableRegionNoDrag);
   1428         state.document().setHasAnnotatedRegions(true);
   1429         return;
   1430     }
   1431     case CSSPropertyWebkitTextStrokeWidth: {
   1432         HANDLE_INHERIT_AND_INITIAL(textStrokeWidth, TextStrokeWidth)
   1433         float width = 0;
   1434         switch (primitiveValue->getValueID()) {
   1435         case CSSValueThin:
   1436         case CSSValueMedium:
   1437         case CSSValueThick: {
   1438             double result = 1.0 / 48;
   1439             if (primitiveValue->getValueID() == CSSValueMedium)
   1440                 result *= 3;
   1441             else if (primitiveValue->getValueID() == CSSValueThick)
   1442                 result *= 5;
   1443             width = CSSPrimitiveValue::create(result, CSSPrimitiveValue::CSS_EMS)->computeLength<float>(state.cssToLengthConversionData());
   1444             break;
   1445         }
   1446         default:
   1447             width = primitiveValue->computeLength<float>(state.cssToLengthConversionData());
   1448             break;
   1449         }
   1450         state.style()->setTextStrokeWidth(width);
   1451         return;
   1452     }
   1453     case CSSPropertyWebkitTransform: {
   1454         HANDLE_INHERIT_AND_INITIAL(transform, Transform);
   1455         TransformOperations operations;
   1456         TransformBuilder::createTransformOperations(value, state.cssToLengthConversionData(), operations);
   1457         state.style()->setTransform(operations);
   1458         return;
   1459     }
   1460     case CSSPropertyWebkitPerspective: {
   1461         HANDLE_INHERIT_AND_INITIAL(perspective, Perspective)
   1462 
   1463         if (!primitiveValue)
   1464             return;
   1465 
   1466         if (primitiveValue->getValueID() == CSSValueNone) {
   1467             state.style()->setPerspective(0);
   1468             return;
   1469         }
   1470 
   1471         float perspectiveValue;
   1472         if (primitiveValue->isLength()) {
   1473             perspectiveValue = primitiveValue->computeLength<float>(state.cssToLengthConversionData());
   1474         } else if (primitiveValue->isNumber()) {
   1475             // For backward compatibility, treat valueless numbers as px.
   1476             perspectiveValue = CSSPrimitiveValue::create(primitiveValue->getDoubleValue(), CSSPrimitiveValue::CSS_PX)->computeLength<float>(state.cssToLengthConversionData());
   1477         } else {
   1478             return;
   1479         }
   1480 
   1481         if (perspectiveValue >= 0.0f)
   1482             state.style()->setPerspective(perspectiveValue);
   1483         return;
   1484     }
   1485     case CSSPropertyWebkitTapHighlightColor: {
   1486         HANDLE_INHERIT_AND_INITIAL(tapHighlightColor, TapHighlightColor);
   1487         if (!primitiveValue)
   1488             break;
   1489 
   1490         Color col = state.document().textLinkColors().colorFromPrimitiveValue(primitiveValue, state.style()->color());
   1491         state.style()->setTapHighlightColor(col);
   1492         return;
   1493     }
   1494     case CSSPropertyInternalCallback: {
   1495         if (isInherit || isInitial)
   1496             return;
   1497         if (primitiveValue && primitiveValue->getValueID() == CSSValueInternalPresence) {
   1498             state.style()->addCallbackSelector(state.currentRule()->selectorList().selectorsText());
   1499             return;
   1500         }
   1501         break;
   1502     }
   1503     case CSSPropertyInvalid:
   1504         return;
   1505     // Directional properties are resolved by resolveDirectionAwareProperty() before the switch.
   1506     case CSSPropertyWebkitBorderEndColor:
   1507     case CSSPropertyWebkitBorderEndStyle:
   1508     case CSSPropertyWebkitBorderEndWidth:
   1509     case CSSPropertyWebkitBorderStartColor:
   1510     case CSSPropertyWebkitBorderStartStyle:
   1511     case CSSPropertyWebkitBorderStartWidth:
   1512     case CSSPropertyWebkitBorderBeforeColor:
   1513     case CSSPropertyWebkitBorderBeforeStyle:
   1514     case CSSPropertyWebkitBorderBeforeWidth:
   1515     case CSSPropertyWebkitBorderAfterColor:
   1516     case CSSPropertyWebkitBorderAfterStyle:
   1517     case CSSPropertyWebkitBorderAfterWidth:
   1518     case CSSPropertyWebkitMarginEnd:
   1519     case CSSPropertyWebkitMarginStart:
   1520     case CSSPropertyWebkitMarginBefore:
   1521     case CSSPropertyWebkitMarginAfter:
   1522     case CSSPropertyWebkitMarginBeforeCollapse:
   1523     case CSSPropertyWebkitMarginTopCollapse:
   1524     case CSSPropertyWebkitMarginAfterCollapse:
   1525     case CSSPropertyWebkitMarginBottomCollapse:
   1526     case CSSPropertyWebkitPaddingEnd:
   1527     case CSSPropertyWebkitPaddingStart:
   1528     case CSSPropertyWebkitPaddingBefore:
   1529     case CSSPropertyWebkitPaddingAfter:
   1530     case CSSPropertyWebkitLogicalWidth:
   1531     case CSSPropertyWebkitLogicalHeight:
   1532     case CSSPropertyWebkitMinLogicalWidth:
   1533     case CSSPropertyWebkitMinLogicalHeight:
   1534     case CSSPropertyWebkitMaxLogicalWidth:
   1535     case CSSPropertyWebkitMaxLogicalHeight:
   1536     {
   1537         CSSPropertyID newId = CSSProperty::resolveDirectionAwareProperty(id, state.style()->direction(), state.style()->writingMode());
   1538         ASSERT(newId != id);
   1539         return applyProperty(newId, state, value);
   1540     }
   1541     case CSSPropertyFontStretch:
   1542     case CSSPropertyPage:
   1543     case CSSPropertyTextLineThroughColor:
   1544     case CSSPropertyTextLineThroughMode:
   1545     case CSSPropertyTextLineThroughStyle:
   1546     case CSSPropertyTextLineThroughWidth:
   1547     case CSSPropertyTextOverlineColor:
   1548     case CSSPropertyTextOverlineMode:
   1549     case CSSPropertyTextOverlineStyle:
   1550     case CSSPropertyTextOverlineWidth:
   1551     case CSSPropertyTextUnderlineColor:
   1552     case CSSPropertyTextUnderlineMode:
   1553     case CSSPropertyTextUnderlineStyle:
   1554     case CSSPropertyTextUnderlineWidth:
   1555     case CSSPropertyWebkitFontSizeDelta:
   1556     case CSSPropertyWebkitTextDecorationsInEffect:
   1557         return;
   1558 
   1559     // CSS Text Layout Module Level 3: Vertical writing support
   1560     case CSSPropertyWebkitWritingMode: {
   1561         HANDLE_INHERIT_AND_INITIAL(writingMode, WritingMode);
   1562 
   1563         if (primitiveValue)
   1564             state.setWritingMode(*primitiveValue);
   1565 
   1566         // FIXME: It is not ok to modify document state while applying style.
   1567         if (state.element() && state.element() == state.document().documentElement())
   1568             state.document().setWritingModeSetOnDocumentElement(true);
   1569         return;
   1570     }
   1571 
   1572     case CSSPropertyWebkitTextOrientation: {
   1573         HANDLE_INHERIT_AND_INITIAL(textOrientation, TextOrientation);
   1574 
   1575         if (primitiveValue)
   1576             state.setTextOrientation(*primitiveValue);
   1577 
   1578         return;
   1579     }
   1580 
   1581     case CSSPropertyWebkitLineBoxContain: {
   1582         HANDLE_INHERIT_AND_INITIAL(lineBoxContain, LineBoxContain)
   1583         if (primitiveValue && primitiveValue->getValueID() == CSSValueNone) {
   1584             state.style()->setLineBoxContain(LineBoxContainNone);
   1585             return;
   1586         }
   1587 
   1588         if (!value->isLineBoxContainValue())
   1589             return;
   1590 
   1591         state.style()->setLineBoxContain(toCSSLineBoxContainValue(value)->value());
   1592         return;
   1593     }
   1594 
   1595     // CSS Fonts Module Level 3
   1596     case CSSPropertyWebkitFontFeatureSettings: {
   1597         if (primitiveValue && primitiveValue->getValueID() == CSSValueNormal) {
   1598             state.fontBuilder().setFeatureSettingsNormal();
   1599             return;
   1600         }
   1601 
   1602         if (!value->isValueList())
   1603             return;
   1604 
   1605         state.fontBuilder().setFeatureSettingsValue(value);
   1606         return;
   1607     }
   1608 
   1609     case CSSPropertyWebkitFilter: {
   1610         HANDLE_INHERIT_AND_INITIAL(filter, Filter);
   1611         FilterOperations operations;
   1612         if (FilterOperationResolver::createFilterOperations(value, state.cssToLengthConversionData(), operations, state))
   1613             state.style()->setFilter(operations);
   1614         return;
   1615     }
   1616     case CSSPropertyGridAutoColumns: {
   1617         HANDLE_INHERIT_AND_INITIAL(gridAutoColumns, GridAutoColumns);
   1618         GridTrackSize trackSize;
   1619         if (!createGridTrackSize(value, trackSize, state))
   1620             return;
   1621         state.style()->setGridAutoColumns(trackSize);
   1622         return;
   1623     }
   1624     case CSSPropertyGridAutoRows: {
   1625         HANDLE_INHERIT_AND_INITIAL(gridAutoRows, GridAutoRows);
   1626         GridTrackSize trackSize;
   1627         if (!createGridTrackSize(value, trackSize, state))
   1628             return;
   1629         state.style()->setGridAutoRows(trackSize);
   1630         return;
   1631     }
   1632     case CSSPropertyGridDefinitionColumns: {
   1633         if (isInherit) {
   1634             state.style()->setGridDefinitionColumns(state.parentStyle()->gridDefinitionColumns());
   1635             state.style()->setNamedGridColumnLines(state.parentStyle()->namedGridColumnLines());
   1636             state.style()->setOrderedNamedGridColumnLines(state.parentStyle()->orderedNamedGridColumnLines());
   1637             return;
   1638         }
   1639         if (isInitial) {
   1640             state.style()->setGridDefinitionColumns(RenderStyle::initialGridDefinitionColumns());
   1641             state.style()->setNamedGridColumnLines(RenderStyle::initialNamedGridColumnLines());
   1642             state.style()->setOrderedNamedGridColumnLines(RenderStyle::initialOrderedNamedGridColumnLines());
   1643             return;
   1644         }
   1645 
   1646         Vector<GridTrackSize> trackSizes;
   1647         NamedGridLinesMap namedGridLines;
   1648         OrderedNamedGridLines orderedNamedGridLines;
   1649         if (!createGridTrackList(value, trackSizes, namedGridLines, orderedNamedGridLines, state))
   1650             return;
   1651         state.style()->setGridDefinitionColumns(trackSizes);
   1652         state.style()->setNamedGridColumnLines(namedGridLines);
   1653         state.style()->setOrderedNamedGridColumnLines(orderedNamedGridLines);
   1654         return;
   1655     }
   1656     case CSSPropertyGridDefinitionRows: {
   1657         if (isInherit) {
   1658             state.style()->setGridDefinitionRows(state.parentStyle()->gridDefinitionRows());
   1659             state.style()->setNamedGridRowLines(state.parentStyle()->namedGridRowLines());
   1660             state.style()->setOrderedNamedGridRowLines(state.parentStyle()->orderedNamedGridRowLines());
   1661             return;
   1662         }
   1663         if (isInitial) {
   1664             state.style()->setGridDefinitionRows(RenderStyle::initialGridDefinitionRows());
   1665             state.style()->setNamedGridRowLines(RenderStyle::initialNamedGridRowLines());
   1666             state.style()->setOrderedNamedGridRowLines(RenderStyle::initialOrderedNamedGridRowLines());
   1667             return;
   1668         }
   1669 
   1670         Vector<GridTrackSize> trackSizes;
   1671         NamedGridLinesMap namedGridLines;
   1672         OrderedNamedGridLines orderedNamedGridLines;
   1673         if (!createGridTrackList(value, trackSizes, namedGridLines, orderedNamedGridLines, state))
   1674             return;
   1675         state.style()->setGridDefinitionRows(trackSizes);
   1676         state.style()->setNamedGridRowLines(namedGridLines);
   1677         state.style()->setOrderedNamedGridRowLines(orderedNamedGridLines);
   1678         return;
   1679     }
   1680 
   1681     case CSSPropertyGridColumnStart: {
   1682         HANDLE_INHERIT_AND_INITIAL(gridColumnStart, GridColumnStart);
   1683         GridPosition startPosition;
   1684         if (!createGridPosition(value, startPosition))
   1685             return;
   1686         state.style()->setGridColumnStart(startPosition);
   1687         return;
   1688     }
   1689     case CSSPropertyGridColumnEnd: {
   1690         HANDLE_INHERIT_AND_INITIAL(gridColumnEnd, GridColumnEnd);
   1691         GridPosition endPosition;
   1692         if (!createGridPosition(value, endPosition))
   1693             return;
   1694         state.style()->setGridColumnEnd(endPosition);
   1695         return;
   1696     }
   1697 
   1698     case CSSPropertyGridRowStart: {
   1699         HANDLE_INHERIT_AND_INITIAL(gridRowStart, GridRowStart);
   1700         GridPosition beforePosition;
   1701         if (!createGridPosition(value, beforePosition))
   1702             return;
   1703         state.style()->setGridRowStart(beforePosition);
   1704         return;
   1705     }
   1706     case CSSPropertyGridRowEnd: {
   1707         HANDLE_INHERIT_AND_INITIAL(gridRowEnd, GridRowEnd);
   1708         GridPosition afterPosition;
   1709         if (!createGridPosition(value, afterPosition))
   1710             return;
   1711         state.style()->setGridRowEnd(afterPosition);
   1712         return;
   1713     }
   1714 
   1715     case CSSPropertyGridTemplate: {
   1716         if (isInherit) {
   1717             state.style()->setNamedGridArea(state.parentStyle()->namedGridArea());
   1718             state.style()->setNamedGridAreaRowCount(state.parentStyle()->namedGridAreaRowCount());
   1719             state.style()->setNamedGridAreaColumnCount(state.parentStyle()->namedGridAreaColumnCount());
   1720             return;
   1721         }
   1722         if (isInitial) {
   1723             state.style()->setNamedGridArea(RenderStyle::initialNamedGridArea());
   1724             state.style()->setNamedGridAreaRowCount(RenderStyle::initialNamedGridAreaCount());
   1725             state.style()->setNamedGridAreaColumnCount(RenderStyle::initialNamedGridAreaCount());
   1726             return;
   1727         }
   1728 
   1729         if (value->isPrimitiveValue()) {
   1730             ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone);
   1731             return;
   1732         }
   1733 
   1734         CSSGridTemplateValue* gridTemplateValue = toCSSGridTemplateValue(value);
   1735         state.style()->setNamedGridArea(gridTemplateValue->gridAreaMap());
   1736         state.style()->setNamedGridAreaRowCount(gridTemplateValue->rowCount());
   1737         state.style()->setNamedGridAreaColumnCount(gridTemplateValue->columnCount());
   1738         return;
   1739     }
   1740 
   1741     // These properties are aliased and we already applied the property on the prefixed version.
   1742     case CSSPropertyAnimationDelay:
   1743     case CSSPropertyAnimationDirection:
   1744     case CSSPropertyAnimationDuration:
   1745     case CSSPropertyAnimationFillMode:
   1746     case CSSPropertyAnimationIterationCount:
   1747     case CSSPropertyAnimationName:
   1748     case CSSPropertyAnimationPlayState:
   1749     case CSSPropertyAnimationTimingFunction:
   1750     case CSSPropertyTransitionDelay:
   1751     case CSSPropertyTransitionDuration:
   1752     case CSSPropertyTransitionProperty:
   1753     case CSSPropertyTransitionTimingFunction:
   1754         return;
   1755     // These properties are implemented in StyleBuilder::applyProperty.
   1756     case CSSPropertyBackgroundAttachment:
   1757     case CSSPropertyBackgroundBlendMode:
   1758     case CSSPropertyBackgroundClip:
   1759     case CSSPropertyBackgroundColor:
   1760     case CSSPropertyBackgroundImage:
   1761     case CSSPropertyBackgroundOrigin:
   1762     case CSSPropertyBackgroundPositionX:
   1763     case CSSPropertyBackgroundPositionY:
   1764     case CSSPropertyBackgroundRepeatX:
   1765     case CSSPropertyBackgroundRepeatY:
   1766     case CSSPropertyBackgroundSize:
   1767     case CSSPropertyBorderBottomColor:
   1768     case CSSPropertyBorderBottomLeftRadius:
   1769     case CSSPropertyBorderBottomRightRadius:
   1770     case CSSPropertyBorderBottomStyle:
   1771     case CSSPropertyBorderBottomWidth:
   1772     case CSSPropertyBorderCollapse:
   1773     case CSSPropertyBorderImageOutset:
   1774     case CSSPropertyBorderImageRepeat:
   1775     case CSSPropertyBorderImageSlice:
   1776     case CSSPropertyBorderImageSource:
   1777     case CSSPropertyBorderImageWidth:
   1778     case CSSPropertyBorderLeftColor:
   1779     case CSSPropertyBorderLeftStyle:
   1780     case CSSPropertyBorderLeftWidth:
   1781     case CSSPropertyBorderRightColor:
   1782     case CSSPropertyBorderRightStyle:
   1783     case CSSPropertyBorderRightWidth:
   1784     case CSSPropertyBorderTopColor:
   1785     case CSSPropertyBorderTopLeftRadius:
   1786     case CSSPropertyBorderTopRightRadius:
   1787     case CSSPropertyBorderTopStyle:
   1788     case CSSPropertyBorderTopWidth:
   1789     case CSSPropertyBottom:
   1790     case CSSPropertyBoxShadow:
   1791     case CSSPropertyBoxSizing:
   1792     case CSSPropertyCaptionSide:
   1793     case CSSPropertyClear:
   1794     case CSSPropertyClip:
   1795     case CSSPropertyColor:
   1796     case CSSPropertyCounterIncrement:
   1797     case CSSPropertyCounterReset:
   1798     case CSSPropertyCursor:
   1799     case CSSPropertyDirection:
   1800     case CSSPropertyDisplay:
   1801     case CSSPropertyEmptyCells:
   1802     case CSSPropertyFloat:
   1803     case CSSPropertyFontKerning:
   1804     case CSSPropertyFontSize:
   1805     case CSSPropertyFontStyle:
   1806     case CSSPropertyFontVariant:
   1807     case CSSPropertyFontWeight:
   1808     case CSSPropertyHeight:
   1809     case CSSPropertyImageRendering:
   1810     case CSSPropertyIsolation:
   1811     case CSSPropertyLeft:
   1812     case CSSPropertyLetterSpacing:
   1813     case CSSPropertyLineHeight:
   1814     case CSSPropertyListStyleImage:
   1815     case CSSPropertyListStylePosition:
   1816     case CSSPropertyListStyleType:
   1817     case CSSPropertyMarginBottom:
   1818     case CSSPropertyMarginLeft:
   1819     case CSSPropertyMarginRight:
   1820     case CSSPropertyMarginTop:
   1821     case CSSPropertyMaxHeight:
   1822     case CSSPropertyMaxWidth:
   1823     case CSSPropertyMinHeight:
   1824     case CSSPropertyMixBlendMode:
   1825     case CSSPropertyMinWidth:
   1826     case CSSPropertyObjectFit:
   1827     case CSSPropertyOpacity:
   1828     case CSSPropertyOrphans:
   1829     case CSSPropertyOutlineColor:
   1830     case CSSPropertyOutlineOffset:
   1831     case CSSPropertyOutlineStyle:
   1832     case CSSPropertyOutlineWidth:
   1833     case CSSPropertyOverflowWrap:
   1834     case CSSPropertyOverflowX:
   1835     case CSSPropertyOverflowY:
   1836     case CSSPropertyPaddingBottom:
   1837     case CSSPropertyPaddingLeft:
   1838     case CSSPropertyPaddingRight:
   1839     case CSSPropertyPaddingTop:
   1840     case CSSPropertyPageBreakAfter:
   1841     case CSSPropertyPageBreakBefore:
   1842     case CSSPropertyPageBreakInside:
   1843     case CSSPropertyPointerEvents:
   1844     case CSSPropertyPosition:
   1845     case CSSPropertyResize:
   1846     case CSSPropertyRight:
   1847     case CSSPropertySize:
   1848     case CSSPropertySpeak:
   1849     case CSSPropertyTabSize:
   1850     case CSSPropertyTableLayout:
   1851     case CSSPropertyTextAlign:
   1852     case CSSPropertyTextAlignLast:
   1853     case CSSPropertyTextDecoration:
   1854     case CSSPropertyTextDecorationLine:
   1855     case CSSPropertyTextDecorationStyle:
   1856     case CSSPropertyTextDecorationColor:
   1857     case CSSPropertyTextIndent:
   1858     case CSSPropertyTextJustify:
   1859     case CSSPropertyTextOverflow:
   1860     case CSSPropertyTextRendering:
   1861     case CSSPropertyTextShadow:
   1862     case CSSPropertyTextTransform:
   1863     case CSSPropertyTop:
   1864     case CSSPropertyTouchAction:
   1865     case CSSPropertyTouchActionDelay:
   1866     case CSSPropertyUnicodeBidi:
   1867     case CSSPropertyVariable:
   1868     case CSSPropertyVerticalAlign:
   1869     case CSSPropertyVisibility:
   1870     case CSSPropertyWebkitAnimationDelay:
   1871     case CSSPropertyWebkitAnimationDirection:
   1872     case CSSPropertyWebkitAnimationDuration:
   1873     case CSSPropertyWebkitAnimationFillMode:
   1874     case CSSPropertyWebkitAnimationIterationCount:
   1875     case CSSPropertyWebkitAnimationName:
   1876     case CSSPropertyWebkitAnimationPlayState:
   1877     case CSSPropertyWebkitAnimationTimingFunction:
   1878     case CSSPropertyWebkitAppearance:
   1879     case CSSPropertyWebkitAspectRatio:
   1880     case CSSPropertyWebkitBackfaceVisibility:
   1881     case CSSPropertyWebkitBackgroundClip:
   1882     case CSSPropertyWebkitBackgroundComposite:
   1883     case CSSPropertyWebkitBackgroundOrigin:
   1884     case CSSPropertyWebkitBackgroundSize:
   1885     case CSSPropertyWebkitBorderFit:
   1886     case CSSPropertyWebkitBorderHorizontalSpacing:
   1887     case CSSPropertyWebkitBorderImage:
   1888     case CSSPropertyWebkitBorderVerticalSpacing:
   1889     case CSSPropertyWebkitBoxAlign:
   1890     case CSSPropertyWebkitBoxDecorationBreak:
   1891     case CSSPropertyWebkitBoxDirection:
   1892     case CSSPropertyWebkitBoxFlex:
   1893     case CSSPropertyWebkitBoxFlexGroup:
   1894     case CSSPropertyWebkitBoxLines:
   1895     case CSSPropertyWebkitBoxOrdinalGroup:
   1896     case CSSPropertyWebkitBoxOrient:
   1897     case CSSPropertyWebkitBoxPack:
   1898     case CSSPropertyWebkitBoxShadow:
   1899     case CSSPropertyWebkitColumnAxis:
   1900     case CSSPropertyWebkitColumnBreakAfter:
   1901     case CSSPropertyWebkitColumnBreakBefore:
   1902     case CSSPropertyWebkitColumnBreakInside:
   1903     case CSSPropertyWebkitColumnCount:
   1904     case CSSPropertyColumnFill:
   1905     case CSSPropertyWebkitColumnGap:
   1906     case CSSPropertyWebkitColumnProgression:
   1907     case CSSPropertyWebkitColumnRuleColor:
   1908     case CSSPropertyWebkitColumnRuleStyle:
   1909     case CSSPropertyWebkitColumnRuleWidth:
   1910     case CSSPropertyWebkitColumnSpan:
   1911     case CSSPropertyWebkitColumnWidth:
   1912     case CSSPropertyAlignContent:
   1913     case CSSPropertyAlignItems:
   1914     case CSSPropertyAlignSelf:
   1915     case CSSPropertyFlexBasis:
   1916     case CSSPropertyFlexDirection:
   1917     case CSSPropertyFlexGrow:
   1918     case CSSPropertyFlexShrink:
   1919     case CSSPropertyFlexWrap:
   1920     case CSSPropertyJustifyContent:
   1921     case CSSPropertyOrder:
   1922     case CSSPropertyWebkitFlowFrom:
   1923     case CSSPropertyWebkitFlowInto:
   1924     case CSSPropertyWebkitFontSmoothing:
   1925     case CSSPropertyWebkitFontVariantLigatures:
   1926     case CSSPropertyWebkitHighlight:
   1927     case CSSPropertyWebkitHyphenateCharacter:
   1928     case CSSPropertyWebkitLineAlign:
   1929     case CSSPropertyWebkitLineBreak:
   1930     case CSSPropertyWebkitLineClamp:
   1931     case CSSPropertyWebkitLineGrid:
   1932     case CSSPropertyWebkitLineSnap:
   1933     case CSSPropertyInternalMarqueeDirection:
   1934     case CSSPropertyInternalMarqueeIncrement:
   1935     case CSSPropertyInternalMarqueeRepetition:
   1936     case CSSPropertyInternalMarqueeSpeed:
   1937     case CSSPropertyInternalMarqueeStyle:
   1938     case CSSPropertyWebkitMaskBoxImage:
   1939     case CSSPropertyWebkitMaskBoxImageOutset:
   1940     case CSSPropertyWebkitMaskBoxImageRepeat:
   1941     case CSSPropertyWebkitMaskBoxImageSlice:
   1942     case CSSPropertyWebkitMaskBoxImageSource:
   1943     case CSSPropertyWebkitMaskBoxImageWidth:
   1944     case CSSPropertyWebkitMaskClip:
   1945     case CSSPropertyWebkitMaskComposite:
   1946     case CSSPropertyWebkitMaskImage:
   1947     case CSSPropertyWebkitMaskOrigin:
   1948     case CSSPropertyWebkitMaskPositionX:
   1949     case CSSPropertyWebkitMaskPositionY:
   1950     case CSSPropertyWebkitMaskRepeatX:
   1951     case CSSPropertyWebkitMaskRepeatY:
   1952     case CSSPropertyWebkitMaskSize:
   1953     case CSSPropertyWebkitPerspectiveOrigin:
   1954     case CSSPropertyWebkitPerspectiveOriginX:
   1955     case CSSPropertyWebkitPerspectiveOriginY:
   1956     case CSSPropertyWebkitPrintColorAdjust:
   1957     case CSSPropertyWebkitRegionBreakAfter:
   1958     case CSSPropertyWebkitRegionBreakBefore:
   1959     case CSSPropertyWebkitRegionBreakInside:
   1960     case CSSPropertyWebkitRegionFragment:
   1961     case CSSPropertyWebkitRtlOrdering:
   1962     case CSSPropertyWebkitRubyPosition:
   1963     case CSSPropertyWebkitTextCombine:
   1964     case CSSPropertyTextUnderlinePosition:
   1965     case CSSPropertyWebkitTextEmphasisColor:
   1966     case CSSPropertyWebkitTextEmphasisPosition:
   1967     case CSSPropertyWebkitTextEmphasisStyle:
   1968     case CSSPropertyWebkitTextFillColor:
   1969     case CSSPropertyWebkitTextSecurity:
   1970     case CSSPropertyWebkitTextStrokeColor:
   1971     case CSSPropertyWebkitTransformOriginX:
   1972     case CSSPropertyWebkitTransformOriginY:
   1973     case CSSPropertyWebkitTransformOriginZ:
   1974     case CSSPropertyWebkitTransformStyle:
   1975     case CSSPropertyWebkitTransitionDelay:
   1976     case CSSPropertyWebkitTransitionDuration:
   1977     case CSSPropertyWebkitTransitionProperty:
   1978     case CSSPropertyWebkitTransitionTimingFunction:
   1979     case CSSPropertyWebkitUserDrag:
   1980     case CSSPropertyWebkitUserModify:
   1981     case CSSPropertyWebkitUserSelect:
   1982     case CSSPropertyWebkitClipPath:
   1983     case CSSPropertyWebkitWrapFlow:
   1984     case CSSPropertyShapeMargin:
   1985     case CSSPropertyShapePadding:
   1986     case CSSPropertyShapeImageThreshold:
   1987     case CSSPropertyWebkitWrapThrough:
   1988     case CSSPropertyShapeInside:
   1989     case CSSPropertyShapeOutside:
   1990     case CSSPropertyWhiteSpace:
   1991     case CSSPropertyWidows:
   1992     case CSSPropertyWidth:
   1993     case CSSPropertyWordBreak:
   1994     case CSSPropertyWordSpacing:
   1995     case CSSPropertyWordWrap:
   1996     case CSSPropertyZIndex:
   1997     case CSSPropertyZoom:
   1998     case CSSPropertyFontFamily:
   1999     case CSSPropertyGridAutoFlow:
   2000     case CSSPropertyMarker:
   2001     case CSSPropertyAlignmentBaseline:
   2002     case CSSPropertyBufferedRendering:
   2003     case CSSPropertyClipRule:
   2004     case CSSPropertyColorInterpolation:
   2005     case CSSPropertyColorInterpolationFilters:
   2006     case CSSPropertyColorRendering:
   2007     case CSSPropertyDominantBaseline:
   2008     case CSSPropertyFillRule:
   2009     case CSSPropertyMaskSourceType:
   2010     case CSSPropertyMaskType:
   2011     case CSSPropertyShapeRendering:
   2012     case CSSPropertyStrokeLinecap:
   2013     case CSSPropertyStrokeLinejoin:
   2014     case CSSPropertyTextAnchor:
   2015     case CSSPropertyVectorEffect:
   2016     case CSSPropertyWritingMode:
   2017     case CSSPropertyClipPath:
   2018     case CSSPropertyFillOpacity:
   2019     case CSSPropertyFilter:
   2020     case CSSPropertyFloodOpacity:
   2021     case CSSPropertyKerning:
   2022     case CSSPropertyMarkerEnd:
   2023     case CSSPropertyMarkerMid:
   2024     case CSSPropertyMarkerStart:
   2025     case CSSPropertyMask:
   2026     case CSSPropertyStopOpacity:
   2027     case CSSPropertyStrokeDashoffset:
   2028     case CSSPropertyStrokeMiterlimit:
   2029     case CSSPropertyStrokeOpacity:
   2030     case CSSPropertyStrokeWidth:
   2031         ASSERT_NOT_REACHED();
   2032         return;
   2033     // Only used in @viewport rules
   2034     case CSSPropertyMaxZoom:
   2035     case CSSPropertyMinZoom:
   2036     case CSSPropertyOrientation:
   2037     case CSSPropertyUserZoom:
   2038         return;
   2039 
   2040     case CSSPropertyBaselineShift:
   2041     {
   2042         HANDLE_SVG_INHERIT_AND_INITIAL(baselineShift, BaselineShift);
   2043         if (!primitiveValue)
   2044             break;
   2045 
   2046         SVGRenderStyle* svgStyle = state.style()->accessSVGStyle();
   2047         if (primitiveValue->getValueID()) {
   2048             switch (primitiveValue->getValueID()) {
   2049             case CSSValueBaseline:
   2050                 svgStyle->setBaselineShift(BS_BASELINE);
   2051                 break;
   2052             case CSSValueSub:
   2053                 svgStyle->setBaselineShift(BS_SUB);
   2054                 break;
   2055             case CSSValueSuper:
   2056                 svgStyle->setBaselineShift(BS_SUPER);
   2057                 break;
   2058             default:
   2059                 break;
   2060             }
   2061         } else {
   2062             svgStyle->setBaselineShift(BS_LENGTH);
   2063             svgStyle->setBaselineShiftValue(SVGLength::fromCSSPrimitiveValue(primitiveValue));
   2064         }
   2065 
   2066         break;
   2067     }
   2068     case CSSPropertyColorProfile:
   2069     {
   2070         // Not implemented.
   2071         break;
   2072     }
   2073     // end of ident only properties
   2074     case CSSPropertyFill:
   2075     {
   2076         SVGRenderStyle* svgStyle = state.style()->accessSVGStyle();
   2077         if (isInherit) {
   2078             const SVGRenderStyle* svgParentStyle = state.parentStyle()->svgStyle();
   2079             svgStyle->setFillPaint(svgParentStyle->fillPaintType(), svgParentStyle->fillPaintColor(), svgParentStyle->fillPaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2080             return;
   2081         }
   2082         if (isInitial) {
   2083             svgStyle->setFillPaint(SVGRenderStyle::initialFillPaintType(), SVGRenderStyle::initialFillPaintColor(), SVGRenderStyle::initialFillPaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2084             return;
   2085         }
   2086         if (value->isSVGPaint()) {
   2087             SVGPaint* svgPaint = toSVGPaint(value);
   2088             svgStyle->setFillPaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2089         }
   2090         break;
   2091     }
   2092     case CSSPropertyStroke:
   2093     {
   2094         SVGRenderStyle* svgStyle = state.style()->accessSVGStyle();
   2095         if (isInherit) {
   2096             const SVGRenderStyle* svgParentStyle = state.parentStyle()->svgStyle();
   2097             svgStyle->setStrokePaint(svgParentStyle->strokePaintType(), svgParentStyle->strokePaintColor(), svgParentStyle->strokePaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2098             return;
   2099         }
   2100         if (isInitial) {
   2101             svgStyle->setStrokePaint(SVGRenderStyle::initialStrokePaintType(), SVGRenderStyle::initialStrokePaintColor(), SVGRenderStyle::initialStrokePaintUri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2102             return;
   2103         }
   2104         if (value->isSVGPaint()) {
   2105             SVGPaint* svgPaint = toSVGPaint(value);
   2106             svgStyle->setStrokePaint(svgPaint->paintType(), colorFromSVGColorCSSValue(svgPaint, state.style()->color()), svgPaint->uri(), state.applyPropertyToRegularStyle(), state.applyPropertyToVisitedLinkStyle());
   2107         }
   2108         break;
   2109     }
   2110     case CSSPropertyStrokeDasharray:
   2111     {
   2112         HANDLE_SVG_INHERIT_AND_INITIAL(strokeDashArray, StrokeDashArray)
   2113         if (!value->isValueList()) {
   2114             state.style()->accessSVGStyle()->setStrokeDashArray(SVGRenderStyle::initialStrokeDashArray());
   2115             break;
   2116         }
   2117 
   2118         CSSValueList* dashes = toCSSValueList(value);
   2119 
   2120         Vector<SVGLength> array;
   2121         size_t length = dashes->length();
   2122         for (size_t i = 0; i < length; ++i) {
   2123             CSSValue* currValue = dashes->itemWithoutBoundsCheck(i);
   2124             if (!currValue->isPrimitiveValue())
   2125                 continue;
   2126 
   2127             CSSPrimitiveValue* dash = toCSSPrimitiveValue(dashes->itemWithoutBoundsCheck(i));
   2128             array.append(SVGLength::fromCSSPrimitiveValue(dash));
   2129         }
   2130 
   2131         state.style()->accessSVGStyle()->setStrokeDashArray(array);
   2132         break;
   2133     }
   2134     case CSSPropertyStopColor:
   2135     {
   2136         HANDLE_SVG_INHERIT_AND_INITIAL(stopColor, StopColor);
   2137         if (value->isSVGColor())
   2138             state.style()->accessSVGStyle()->setStopColor(colorFromSVGColorCSSValue(toSVGColor(value), state.style()->color()));
   2139         break;
   2140     }
   2141     case CSSPropertyLightingColor:
   2142     {
   2143         HANDLE_SVG_INHERIT_AND_INITIAL(lightingColor, LightingColor);
   2144         if (value->isSVGColor())
   2145             state.style()->accessSVGStyle()->setLightingColor(colorFromSVGColorCSSValue(toSVGColor(value), state.style()->color()));
   2146         break;
   2147     }
   2148     case CSSPropertyFloodColor:
   2149     {
   2150         HANDLE_SVG_INHERIT_AND_INITIAL(floodColor, FloodColor);
   2151         if (value->isSVGColor())
   2152             state.style()->accessSVGStyle()->setFloodColor(colorFromSVGColorCSSValue(toSVGColor(value), state.style()->color()));
   2153         break;
   2154     }
   2155     case CSSPropertyGlyphOrientationHorizontal:
   2156     {
   2157         HANDLE_SVG_INHERIT_AND_INITIAL(glyphOrientationHorizontal, GlyphOrientationHorizontal)
   2158         EGlyphOrientation orientation;
   2159         if (degreeToGlyphOrientation(primitiveValue, orientation))
   2160             state.style()->accessSVGStyle()->setGlyphOrientationHorizontal(orientation);
   2161         break;
   2162     }
   2163     case CSSPropertyPaintOrder: {
   2164         HANDLE_SVG_INHERIT_AND_INITIAL(paintOrder, PaintOrder)
   2165         if (value->isValueList())
   2166             state.style()->accessSVGStyle()->setPaintOrder(paintOrderFlattened(value));
   2167         break;
   2168     }
   2169     case CSSPropertyGlyphOrientationVertical:
   2170     {
   2171         HANDLE_SVG_INHERIT_AND_INITIAL(glyphOrientationVertical, GlyphOrientationVertical)
   2172         if (primitiveValue->getValueID() == CSSValueAuto) {
   2173             state.style()->accessSVGStyle()->setGlyphOrientationVertical(GO_AUTO);
   2174             break;
   2175         }
   2176         EGlyphOrientation orientation;
   2177         if (degreeToGlyphOrientation(primitiveValue, orientation))
   2178             state.style()->accessSVGStyle()->setGlyphOrientationVertical(orientation);
   2179         break;
   2180     }
   2181     case CSSPropertyEnableBackground:
   2182         // Silently ignoring this property for now
   2183         // http://bugs.webkit.org/show_bug.cgi?id=6022
   2184         break;
   2185     }
   2186 }
   2187 
   2188 } // namespace WebCore
   2189