Changeset 150901 in webkit
- Timestamp:
- May 29, 2013 9:30:49 AM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r150900 r150901 1 2013-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 1 43 2013-05-29 Antti Koivisto <antti@apple.com> 2 44 -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r150716 r150901 690 690 } 691 691 692 PassRefPtr<CSSPrimitiveValue> C SSComputedStyleDeclaration::currentColorOrValidColor(RenderStyle* style, const Color& color) const692 PassRefPtr<CSSPrimitiveValue> ComputedStyleExtractor::currentColorOrValidColor(RenderStyle* style, const Color& color) const 693 693 { 694 694 // This function does NOT look at visited information, so that computed style doesn't expose that. … … 899 899 900 900 #if ENABLE(CSS_FILTERS) 901 PassRefPtr<CSSValue> C SSComputedStyleDeclaration::valueForFilter(const RenderObject* renderer, const RenderStyle* style) const901 PassRefPtr<CSSValue> ComputedStyleExtractor::valueForFilter(const RenderObject* renderer, const RenderStyle* style) const 902 902 { 903 903 #if !ENABLE(CSS_SHADERS) … … 1204 1204 } 1205 1205 1206 ComputedStyleExtractor::ComputedStyleExtractor(PassRefPtr<Node> node, bool allowVisitedStyle, PseudoId pseudoElementSpecifier) 1207 : m_node(node) 1208 , m_pseudoElementSpecifier(pseudoElementSpecifier) 1209 , m_allowVisitedStyle(allowVisitedStyle) 1210 { 1211 } 1212 1213 1206 1214 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(PassRefPtr<Node> n, bool allowVisitedStyle, const String& pseudoElementName) 1207 1215 : m_node(n) … … 1288 1296 } 1289 1297 1290 PassRefPtr<CSSValue> C SSComputedStyleDeclaration::valueForShadow(const ShadowData* shadow, CSSPropertyID propertyID, const RenderStyle* style) const1298 PassRefPtr<CSSValue> ComputedStyleExtractor::valueForShadow(const ShadowData* shadow, CSSPropertyID propertyID, const RenderStyle* style) const 1291 1299 { 1292 1300 if (!shadow) … … 1544 1552 } 1545 1553 1546 Node* C SSComputedStyleDeclaration::styledNode() const1554 Node* ComputedStyleExtractor::styledNode() const 1547 1555 { 1548 1556 if (!m_node) … … 1556 1564 1557 1565 PassRefPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const 1566 { 1567 return ComputedStyleExtractor(m_node, m_allowVisitedStyle, m_pseudoElementSpecifier).propertyValue(propertyID, updateLayout); 1568 } 1569 1570 PassRefPtr<CSSValue> ComputedStyleExtractor::propertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const 1558 1571 { 1559 1572 Node* styledNode = this->styledNode(); … … 2727 2740 return getBackgroundShorthandValue(); 2728 2741 case CSSPropertyBorder: { 2729 RefPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBorderTop, DoNotUpdateLayout);2742 RefPtr<CSSValue> value = propertyValue(CSSPropertyBorderTop, DoNotUpdateLayout); 2730 2743 const CSSPropertyID properties[3] = { CSSPropertyBorderRight, CSSPropertyBorderBottom, 2731 2744 CSSPropertyBorderLeft }; 2732 2745 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))) 2734 2747 return 0; 2735 2748 } … … 2911 2924 case CSSPropertyWritingMode: 2912 2925 case CSSPropertyWebkitSvgShadow: 2913 return getSVGPropertyCSSValue(propertyID, DoNotUpdateLayout);2926 return svgPropertyValue(propertyID, DoNotUpdateLayout); 2914 2927 #endif 2915 2928 } … … 2970 2983 } 2971 2984 2972 PassRefPtr<CSSValueList> C SSComputedStyleDeclaration::getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand& shorthand) const2985 PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand& shorthand) const 2973 2986 { 2974 2987 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2975 2988 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); 2977 2990 list->append(value); 2978 2991 } … … 2980 2993 } 2981 2994 2982 PassRefPtr<CSSValueList> C SSComputedStyleDeclaration::getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand& shorthand) const2995 PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand& shorthand) const 2983 2996 { 2984 2997 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2985 2998 // 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); 2990 3003 2991 3004 // All 4 properties must be specified. … … 3008 3021 } 3009 3022 3010 PassRefPtr<CSSValueList> C SSComputedStyleDeclaration::getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand& shorthand) const3023 PassRefPtr<CSSValueList> ComputedStyleExtractor::getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand& shorthand) const 3011 3024 { 3012 3025 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 3013 3026 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); 3015 3028 list->append(value.release()); 3016 3029 } … … 3094 3107 } 3095 3108 3096 PassRefPtr<CSSValueList> C SSComputedStyleDeclaration::getBackgroundShorthandValue() const3109 PassRefPtr<CSSValueList> ComputedStyleExtractor::getBackgroundShorthandValue() const 3097 3110 { 3098 3111 static const CSSPropertyID propertiesBeforeSlashSeperator[5] = { CSSPropertyBackgroundColor, CSSPropertyBackgroundImage, -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.h
r148921 r150901 1 1 /* 2 2 * 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. 4 4 * 5 5 * This library is free software; you can redistribute it and/or … … 48 48 enum EUpdateLayout { DoNotUpdateLayout = false, UpdateLayout = true }; 49 49 50 class ComputedStyleExtractor { 51 public: 52 ComputedStyleExtractor(PassRefPtr<Node>, bool allowVisitedStyle = false, PseudoId = NOPSEUDO); 53 54 PassRefPtr<CSSValue> propertyValue(CSSPropertyID, EUpdateLayout = UpdateLayout) const; 55 56 private: 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 50 85 class CSSComputedStyleDeclaration : public CSSStyleDeclaration { 51 86 public: … … 68 103 PassRefPtr<CSSValue> getFontSizeCSSValuePreferringKeyword() const; 69 104 bool useFixedFontDefaultSize() const; 70 #if ENABLE(SVG)71 PassRefPtr<CSSValue> getSVGPropertyCSSValue(CSSPropertyID, EUpdateLayout) const;72 #endif73 105 74 106 PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const; … … 76 108 private: 77 109 CSSComputedStyleDeclaration(PassRefPtr<Node>, bool allowVisitedStyle, const String&); 78 79 // The styled node is either the node passed into getComputedStyle, or the80 // PseudoElement for :before and :after if they exist.81 // FIXME: This should be styledElement since in JS getComputedStyle only works82 // on Elements, but right now editing creates these for text nodes. We should fix83 // that.84 Node* styledNode() const;85 110 86 111 // CSSOM functions. Don't make these public. … … 103 128 virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE; 104 129 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 #endif110 111 #if ENABLE(CSS_FILTERS)112 PassRefPtr<CSSValue> valueForFilter(const RenderObject*, const RenderStyle*) const;113 #endif114 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 120 130 RefPtr<Node> m_node; 121 131 PseudoId m_pseudoElementSpecifier; -
trunk/Source/WebCore/css/SVGCSSComputedStyleDeclaration.cpp
r147348 r150901 61 61 } 62 62 63 PassRefPtr<SVGPaint> C SSComputedStyleDeclaration::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const63 PassRefPtr<SVGPaint> ComputedStyleExtractor::adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint> newPaint, RenderStyle* style) const 64 64 { 65 65 RefPtr<SVGPaint> paint = newPaint; … … 69 69 } 70 70 71 PassRefPtr<CSSValue> C SSComputedStyleDeclaration::getSVGPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const71 PassRefPtr<CSSValue> ComputedStyleExtractor::svgPropertyValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const 72 72 { 73 73 Node* node = m_node.get(); -
trunk/Source/WebCore/rendering/style/RenderStyle.h
r150525 r150901 127 127 friend class DeprecatedStyleBuilder; // Sets members directly. 128 128 friend class EditingStyle; // Editing has to only reveal unvisited info. 129 friend class C SSComputedStyleDeclaration; // 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. 130 130 friend class PropertyWrapperMaybeInvalidColor; // Used by CSS animations. We can't allow them to animate based off visited colors. 131 131 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 99 99 100 100 private: 101 friend class C SSComputedStyleDeclaration;101 friend class ComputedStyleExtractor; 102 102 103 103 static PassRefPtr<SVGPaint> create(const SVGPaintType& type, const String& uri, const Color& color)
Note: See TracChangeset
for help on using the changeset viewer.