Changeset 207539 in webkit


Ignore:
Timestamp:
Oct 19, 2016 9:38:42 AM (8 years ago)
Author:
hyatt@apple.com
Message:

[CSS Parser] Fix named color parsing
https://bugs.webkit.org/show_bug.cgi?id=163662

Reviewed by Zalan Bujtas.

Named color parsing in the old parser for extended colors relied on constructing a Color with the
name and doing a lookup that way.

The new parser allows the back end to hold a primitive identifier value for extended colors.

StyleColor contains a helper function for looking up the correct color.

This patch switches both the old and the new parsers over to the new StyleColor function.

Also remove some asserts from the CSSSelectorList, since the new parser allows it to be empty and
detects parsing failure that way.

  • css/CSSSelectorList.cpp:

(WebCore::CSSSelectorList::CSSSelectorList):
(WebCore::CSSSelectorList::operator=):

  • css/StyleColor.cpp:

(WebCore::StyleColor::isColorKeyword):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::colorFromPrimitiveValue):
(WebCore::colorForCSSValue): Deleted.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207537 r207539  
     12016-10-19  Dave Hyatt  <hyatt@apple.com>
     2
     3        [CSS Parser] Fix named color parsing
     4        https://bugs.webkit.org/show_bug.cgi?id=163662
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Named color parsing in the old parser for extended colors relied on constructing a Color with the
     9        name and doing a lookup that way.
     10
     11        The new parser allows the back end to hold a primitive identifier value for extended colors.
     12
     13        StyleColor contains a helper function for looking up the correct color.
     14
     15        This patch switches both the old and the new parsers over to the new StyleColor function.
     16
     17        Also remove some asserts from the CSSSelectorList, since the new parser allows it to be empty and
     18        detects parsing failure that way.
     19
     20        * css/CSSSelectorList.cpp:
     21        (WebCore::CSSSelectorList::CSSSelectorList):
     22        (WebCore::CSSSelectorList::operator=):
     23        * css/StyleColor.cpp:
     24        (WebCore::StyleColor::isColorKeyword):
     25        * css/StyleResolver.cpp:
     26        (WebCore::StyleResolver::colorFromPrimitiveValue):
     27        (WebCore::colorForCSSValue): Deleted.
     28
    1292016-10-19  Youenn Fablet  <youenn@apple.com>
    230
  • trunk/Source/WebCore/css/CSSSelectorList.cpp

    r207536 r207539  
    4646    : m_selectorArray(other.m_selectorArray)
    4747{
    48     ASSERT_WITH_SECURITY_IMPLICATION(componentCount());
    4948    other.m_selectorArray = nullptr;
    5049}
     
    103102    other.m_selectorArray = nullptr;
    104103
    105     ASSERT_WITH_SECURITY_IMPLICATION(componentCount());
    106104    return *this;
    107105}
  • trunk/Source/WebCore/css/StyleColor.cpp

    r206007 r207539  
    4949bool StyleColor::isColorKeyword(CSSValueID id)
    5050{
    51     return (id >= CSSValueAlpha && id <= CSSValueWebkitText) || id == CSSValueMenu;
     51    return (id >= CSSValueAlpha && id <= CSSValueWebkitText)
     52        || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen)
     53        || id == CSSValueMenu;
    5254}
    5355
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r207396 r207539  
    121121#include "ShadowRoot.h"
    122122#include "StyleBuilder.h"
     123#include "StyleColor.h"
    123124#include "StyleCachedImage.h"
    124125#include "StyleFontSizeFunctions.h"
     
    17781779}
    17791780
    1780 static Color colorForCSSValue(CSSValueID cssValueId)
    1781 {
    1782     struct ColorValue {
    1783         CSSValueID cssValueId;
    1784         RGBA32 color;
    1785     };
    1786 
    1787     static const ColorValue colorValues[] = {
    1788         { CSSValueAqua, 0xFF00FFFF },
    1789         { CSSValueBlack, 0xFF000000 },
    1790         { CSSValueBlue, 0xFF0000FF },
    1791         { CSSValueFuchsia, 0xFFFF00FF },
    1792         { CSSValueGray, 0xFF808080 },
    1793         { CSSValueGreen, 0xFF008000  },
    1794         { CSSValueGrey, 0xFF808080 },
    1795         { CSSValueLime, 0xFF00FF00 },
    1796         { CSSValueMaroon, 0xFF800000 },
    1797         { CSSValueNavy, 0xFF000080 },
    1798         { CSSValueOlive, 0xFF808000  },
    1799         { CSSValueOrange, 0xFFFFA500 },
    1800         { CSSValuePurple, 0xFF800080 },
    1801         { CSSValueRed, 0xFFFF0000 },
    1802         { CSSValueSilver, 0xFFC0C0C0 },
    1803         { CSSValueTeal, 0xFF008080  },
    1804         { CSSValueTransparent, 0x00000000 },
    1805         { CSSValueWhite, 0xFFFFFFFF },
    1806         { CSSValueYellow, 0xFFFFFF00 },
    1807         { CSSValueInvalid, CSSValueInvalid }
    1808     };
    1809 
    1810     for (const ColorValue* col = colorValues; col->cssValueId; ++col) {
    1811         if (col->cssValueId == cssValueId)
    1812             return col->color;
    1813     }
    1814     return RenderTheme::defaultTheme()->systemColor(cssValueId);
    1815 }
    1816 
    18171781bool StyleResolver::colorFromPrimitiveValueIsDerivedFromElement(const CSSPrimitiveValue& value)
    18181782{
     
    18491813    case CSSValueCurrentcolor:
    18501814        return state.style()->color();
    1851     default:
    1852         return colorForCSSValue(ident);
     1815    default: {
     1816        return StyleColor::colorFromKeyword(ident);
     1817    }
    18531818    }
    18541819}
Note: See TracChangeset for help on using the changeset viewer.