Changeset 150901 in webkit


Ignore:
Timestamp:
May 29, 2013 9:30:49 AM (11 years ago)
Author:
akling@apple.com
Message:

Move computed style extraction out of CSSComputedStyleDeclaration.
<http://webkit.org/b/116965>

Reviewed by Antti Koivisto.

Make it possible to get computed CSSValues from a Node without creating a CSSOM
style declaration object.

The bulk of the logic moves to a new class; ComputedStyleExtractor, which can be created
on the stack, and takes the same setup variables as CSSComputedStyleDeclaration.

This is prep to enable futuristic optimizations in editing and elsewhere.

  • css/CSSComputedStyleDeclaration.h:
  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):

Create a ComputedStyleExtractor to do the work!

(WebCore::ComputedStyleExtractor::currentColorOrValidColor):
(WebCore::ComputedStyleExtractor::valueForFilter):
(WebCore::ComputedStyleExtractor::ComputedStyleExtractor):
(WebCore::ComputedStyleExtractor::valueForShadow):
(WebCore::ComputedStyleExtractor::styledNode):
(WebCore::ComputedStyleExtractor::propertyValue):
(WebCore::ComputedStyleExtractor::getCSSPropertyValuesForShorthandProperties):
(WebCore::ComputedStyleExtractor::getCSSPropertyValuesForSidesShorthand):
(WebCore::ComputedStyleExtractor::getCSSPropertyValuesForGridShorthand):
(WebCore::ComputedStyleExtractor::getBackgroundShorthandValue):

  • css/SVGCSSComputedStyleDeclaration.cpp:

(WebCore::ComputedStyleExtractor::adjustSVGPaintForCurrentColor):
(WebCore::ComputedStyleExtractor::svgPropertyValue):

Moved all of these from CSSComputedStyleDeclaration to the new class.

  • rendering/style/RenderStyle.h:
  • svg/SVGPaint.h:

Have these two befriend ComputedStyleExtractor.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r150900 r150901  
     12013-05-29  Andreas Kling  <akling@apple.com>
     2
     3        Move computed style extraction out of CSSComputedStyleDeclaration.
     4        <http://webkit.org/b/116965>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Make it possible to get computed CSSValues from a Node without creating a CSSOM
     9        style declaration object.
     10
     11        The bulk of the logic moves to a new class; ComputedStyleExtractor, which can be created
     12        on the stack, and takes the same setup variables as CSSComputedStyleDeclaration.
     13
     14        This is prep to enable futuristic optimizations in editing and elsewhere.
     15
     16        * css/CSSComputedStyleDeclaration.h:
     17        * css/CSSComputedStyleDeclaration.cpp:
     18        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
     19
     20            Create a ComputedStyleExtractor to do the work!
     21
     22        (WebCore::ComputedStyleExtractor::currentColorOrValidColor):
     23        (WebCore::ComputedStyleExtractor::valueForFilter):
     24        (WebCore::ComputedStyleExtractor::ComputedStyleExtractor):
     25        (WebCore::ComputedStyleExtractor::valueForShadow):
     26        (WebCore::ComputedStyleExtractor::styledNode):
     27        (WebCore::ComputedStyleExtractor::propertyValue):
     28        (WebCore::ComputedStyleExtractor::getCSSPropertyValuesForShorthandProperties):
     29        (WebCore::ComputedStyleExtractor::getCSSPropertyValuesForSidesShorthand):
     30        (WebCore::ComputedStyleExtractor::getCSSPropertyValuesForGridShorthand):
     31        (WebCore::ComputedStyleExtractor::getBackgroundShorthandValue):
     32        * css/SVGCSSComputedStyleDeclaration.cpp:
     33        (WebCore::ComputedStyleExtractor::adjustSVGPaintForCurrentColor):
     34        (WebCore::ComputedStyleExtractor::svgPropertyValue):
     35
     36            Moved all of these from CSSComputedStyleDeclaration to the new class.
     37
     38        * rendering/style/RenderStyle.h:
     39        * svg/SVGPaint.h:
     40
     41            Have these two befriend ComputedStyleExtractor.
     42
    1432013-05-29  Antti Koivisto  <antti@apple.com>
    244
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r150716 r150901  
    690690}
    691691
    692 PassRefPtr<CSSPrimitiveValue> CSSComputedStyleDeclaration::currentColorOrValidColor(RenderStyle* style, const Color& color) const
     692PassRefPtr<CSSPrimitiveValue> ComputedStyleExtractor::currentColorOrValidColor(RenderStyle* style, const Color& color) const
    693693{
    694694    // This function does NOT look at visited information, so that computed style doesn't expose that.
     
    899899
    900900#if ENABLE(CSS_FILTERS)
    901 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::valueForFilter(const RenderObject* renderer, const RenderStyle* style) const
     901PassRefPtr<CSSValue> ComputedStyleExtractor::valueForFilter(const RenderObject* renderer, const RenderStyle* style) const
    902902{
    903903#if !ENABLE(CSS_SHADERS)
     
    12041204}
    12051205
     1206ComputedStyleExtractor::ComputedStyleExtractor(PassRefPtr<Node> node, bool allowVisitedStyle, PseudoId pseudoElementSpecifier)
     1207    : m_node(node)
     1208    , m_pseudoElementSpecifier(pseudoElementSpecifier)
     1209    , m_allowVisitedStyle(allowVisitedStyle)
     1210{
     1211}
     1212
     1213
    12061214CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(PassRefPtr<Node> n, bool allowVisitedStyle, const String& pseudoElementName)
    12071215    : m_node(n)
     
    12881296}
    12891297
    1290 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::valueForShadow(const ShadowData* shadow, CSSPropertyID propertyID, const RenderStyle* style) const
     1298PassRefPtr<CSSValue> ComputedStyleExtractor::valueForShadow(const ShadowData* shadow, CSSPropertyID propertyID, const RenderStyle* style) const
    12911299{
    12921300    if (!shadow)
     
    15441552}
    15451553
    1546 Node* CSSComputedStyleDeclaration::styledNode() const
     1554Node* ComputedStyleExtractor::styledNode() const
    15471555{
    15481556    if (!m_node)
     
    15561564
    15571565PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
     1566{
     1567    return ComputedStyleExtractor(m_node, m_allowVisitedStyle, m_pseudoElementSpecifier).propertyValue(propertyID, updateLayout);
     1568}
     1569
     1570PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
    15581571{
    15591572    Node* styledNode = this->styledNode();
     
    27272740            return getBackgroundShorthandValue();
    27282741        case CSSPropertyBorder: {
    2729             RefPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBorderTop, DoNotUpdateLayout);
     2742            RefPtr<CSSValue> value = propertyValue(CSSPropertyBorderTop, DoNotUpdateLayout);
    27302743            const CSSPropertyID properties[3] = { CSSPropertyBorderRight, CSSPropertyBorderBottom,
    27312744                                        CSSPropertyBorderLeft };
    27322745            for (size_t i = 0; i < WTF_ARRAY_LENGTH(properties); ++i) {
    2733                 if (!compareCSSValuePtr<CSSValue>(value, getPropertyCSSValue(properties[i], DoNotUpdateLayout)))
     2746                if (!compareCSSValuePtr<CSSValue>(value, propertyValue(properties[i], DoNotUpdateLayout)))
    27342747                    return 0;
    27352748            }
     
    29112924        case CSSPropertyWritingMode:
    29122925        case CSSPropertyWebkitSvgShadow:
    2913             return getSVGPropertyCSSValue(propertyID, DoNotUpdateLayout);
     2926            return svgPropertyValue(propertyID, DoNotUpdateLayout);
    29142927#endif
    29152928    }
     
    29702983}
    29712984
    2972 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand& shorthand) const
     2985PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand& shorthand) const
    29732986{
    29742987    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    29752988    for (size_t i = 0; i < shorthand.length(); ++i) {
    2976         RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout);
     2989        RefPtr<CSSValue> value = propertyValue(shorthand.properties()[i], DoNotUpdateLayout);
    29772990        list->append(value);
    29782991    }
     
    29802993}
    29812994
    2982 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand& shorthand) const
     2995PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand& shorthand) const
    29832996{
    29842997    RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
    29852998    // Assume the properties are in the usual order top, right, bottom, left.
    2986     RefPtr<CSSValue> topValue = getPropertyCSSValue(shorthand.properties()[0], DoNotUpdateLayout);
    2987     RefPtr<CSSValue> rightValue = getPropertyCSSValue(shorthand.properties()[1], DoNotUpdateLayout);
    2988     RefPtr<CSSValue> bottomValue = getPropertyCSSValue(shorthand.properties()[2], DoNotUpdateLayout);
    2989     RefPtr<CSSValue> leftValue = getPropertyCSSValue(shorthand.properties()[3], DoNotUpdateLayout);
     2999    RefPtr<CSSValue> topValue = propertyValue(shorthand.properties()[0], DoNotUpdateLayout);
     3000    RefPtr<CSSValue> rightValue = propertyValue(shorthand.properties()[1], DoNotUpdateLayout);
     3001    RefPtr<CSSValue> bottomValue = propertyValue(shorthand.properties()[2], DoNotUpdateLayout);
     3002    RefPtr<CSSValue> leftValue = propertyValue(shorthand.properties()[3], DoNotUpdateLayout);
    29903003
    29913004    // All 4 properties must be specified.
     
    30083021}
    30093022
    3010 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand& shorthand) const
     3023PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand& shorthand) const
    30113024{
    30123025    RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated();
    30133026    for (size_t i = 0; i < shorthand.length(); ++i) {
    3014         RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout);
     3027        RefPtr<CSSValue> value = propertyValue(shorthand.properties()[i], DoNotUpdateLayout);
    30153028        list->append(value.release());
    30163029    }
     
    30943107}
    30953108
    3096 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getBackgroundShorthandValue() const
     3109PassRefPtr<CSSValueList> ComputedStyleExtractor::getBackgroundShorthandValue() const
    30973110{
    30983111    static const CSSPropertyID propertiesBeforeSlashSeperator[5] = { CSSPropertyBackgroundColor, CSSPropertyBackgroundImage,
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h

    r148921 r150901  
    11/*
    22 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
    3  * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
     3 * Copyright (C) 2004, 2005, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved.
    44 *
    55 * This library is free software; you can redistribute it and/or
     
    4848enum EUpdateLayout { DoNotUpdateLayout = false, UpdateLayout = true };
    4949
     50class ComputedStyleExtractor {
     51public:
     52    ComputedStyleExtractor(PassRefPtr<Node>, bool allowVisitedStyle = false, PseudoId = NOPSEUDO);
     53
     54    PassRefPtr<CSSValue> propertyValue(CSSPropertyID, EUpdateLayout = UpdateLayout) const;
     55
     56private:
     57    // The styled node is either the node passed into computedPropertyValue, or the
     58    // PseudoElement for :before and :after if they exist.
     59    // FIXME: This should be styledElement since in JS getComputedStyle only works
     60    // on Elements, but right now editing creates these for text nodes. We should fix that.
     61    Node* styledNode() const;
     62
     63#if ENABLE(SVG)
     64    PassRefPtr<CSSValue> svgPropertyValue(CSSPropertyID, EUpdateLayout) const;
     65    PassRefPtr<SVGPaint> adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint>, RenderStyle*) const;
     66#endif
     67
     68    PassRefPtr<CSSValue> valueForShadow(const ShadowData*, CSSPropertyID, const RenderStyle*) const;
     69    PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(RenderStyle*, const Color&) const;
     70
     71#if ENABLE(CSS_FILTERS)
     72    PassRefPtr<CSSValue> valueForFilter(const RenderObject*, const RenderStyle*) const;
     73#endif
     74
     75    PassRefPtr<CSSValueList> getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand&) const;
     76    PassRefPtr<CSSValueList> getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand&) const;
     77    PassRefPtr<CSSValueList> getBackgroundShorthandValue() const;
     78    PassRefPtr<CSSValueList> getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand&) const;
     79
     80    RefPtr<Node> m_node;
     81    PseudoId m_pseudoElementSpecifier;
     82    bool m_allowVisitedStyle;
     83};
     84
    5085class CSSComputedStyleDeclaration : public CSSStyleDeclaration {
    5186public:
     
    68103    PassRefPtr<CSSValue> getFontSizeCSSValuePreferringKeyword() const;
    69104    bool useFixedFontDefaultSize() const;
    70 #if ENABLE(SVG)
    71     PassRefPtr<CSSValue> getSVGPropertyCSSValue(CSSPropertyID, EUpdateLayout) const;
    72 #endif
    73105
    74106    PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const;
     
    76108private:
    77109    CSSComputedStyleDeclaration(PassRefPtr<Node>, bool allowVisitedStyle, const String&);
    78 
    79     // The styled node is either the node passed into getComputedStyle, or the
    80     // PseudoElement for :before and :after if they exist.
    81     // FIXME: This should be styledElement since in JS getComputedStyle only works
    82     // on Elements, but right now editing creates these for text nodes. We should fix
    83     // that.
    84     Node* styledNode() const;
    85110
    86111    // CSSOM functions. Don't make these public.
     
    103128    virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE;
    104129
    105     PassRefPtr<CSSValue> valueForShadow(const ShadowData*, CSSPropertyID, const RenderStyle*) const;
    106     PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(RenderStyle*, const Color&) const;
    107 #if ENABLE(SVG)
    108     PassRefPtr<SVGPaint> adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint>, RenderStyle*) const;
    109 #endif
    110 
    111 #if ENABLE(CSS_FILTERS)
    112     PassRefPtr<CSSValue> valueForFilter(const RenderObject*, const RenderStyle*) const;
    113 #endif
    114 
    115     PassRefPtr<CSSValueList> getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand&) const;
    116     PassRefPtr<CSSValueList> getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand&) const;
    117     PassRefPtr<CSSValueList> getBackgroundShorthandValue() const;
    118     PassRefPtr<CSSValueList> getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand&) const;
    119 
    120130    RefPtr<Node> m_node;
    121131    PseudoId m_pseudoElementSpecifier;
  • trunk/Source/WebCore/css/SVGCSSComputedStyleDeclaration.cpp

    r147348 r150901  
    6161}
    6262
    63 PassRefPtr<SVGPaint> CSSComputedStyleDeclaration::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const
     63PassRefPtr<SVGPaint> ComputedStyleExtractor::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const
    6464{
    6565    RefPtr<SVGPaint> paint = newPaint;
     
    6969}
    7070
    71 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getSVGPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
     71PassRefPtr<CSSValue> ComputedStyleExtractor::svgPropertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const
    7272{
    7373    Node* node = m_node.get();
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r150525 r150901  
    127127    friend class DeprecatedStyleBuilder; // Sets members directly.
    128128    friend class EditingStyle; // Editing has to only reveal unvisited info.
    129     friend class CSSComputedStyleDeclaration; // Ignores visited styles, so needs to be able to see unvisited info.
     129    friend class ComputedStyleExtractor; // Ignores visited styles, so needs to be able to see unvisited info.
    130130    friend class PropertyWrapperMaybeInvalidColor; // Used by CSS animations. We can't allow them to animate based off visited colors.
    131131    friend class RenderSVGResource; // FIXME: Needs to alter the visited state by hand. Should clean the SVG code up and move it into RenderStyle perhaps.
  • trunk/Source/WebCore/svg/SVGPaint.h

    r148921 r150901  
    9999
    100100private:
    101     friend class CSSComputedStyleDeclaration;
     101    friend class ComputedStyleExtractor;
    102102
    103103    static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color)
Note: See TracChangeset for help on using the changeset viewer.