Changeset 121562 in webkit
- Timestamp:
- Jun 29, 2012 8:21:02 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r121560 r121562 1 2012-06-29 Andreas Kling <kling@webkit.org> 2 3 Separate mutating CSSStyleDeclaration operations. 4 <http://webkit.org/b/89945> 5 6 Reviewed by Antti Koivisto. 7 8 Use separate paths for mutating the StylePropertySet wrapped by a CSSStyleDeclaration. 9 PropertySetCSSStyleDeclaration now has: 10 11 - propertySet() const 12 - ensureMutablePropertySet() 13 14 This is prep work for supporting immutable ElementAttributeData objects, the idea being 15 that calling ensureMutablePropertySet() may cause the element to convert its internal 16 attribute storage (which also holds the inline StylePropertySet.) 17 18 To that end, also removed the weird logic that allowed you to kill the inline style object 19 by removing the 'style' attribute. We now simply clear out all the properties in that case 20 which saves us a bunch of hassle (no need for a ~StyledElement anymore.) 21 Note that InlineCSSStyleDeclaration now refs the element rather than the inline style. 22 23 There should be no web-facing behavior change from any of this. 24 25 * css/PropertySetCSSStyleDeclaration.cpp: 26 (WebCore::PropertySetCSSStyleDeclaration::length): 27 (WebCore::PropertySetCSSStyleDeclaration::item): 28 (WebCore::PropertySetCSSStyleDeclaration::cssText): 29 (WebCore::PropertySetCSSStyleDeclaration::setCssText): 30 (WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValue): 31 (WebCore::PropertySetCSSStyleDeclaration::getPropertyValue): 32 (WebCore::PropertySetCSSStyleDeclaration::getPropertyPriority): 33 (WebCore::PropertySetCSSStyleDeclaration::getPropertyShorthand): 34 (WebCore::PropertySetCSSStyleDeclaration::isPropertyImplicit): 35 (WebCore::PropertySetCSSStyleDeclaration::setProperty): 36 (WebCore::PropertySetCSSStyleDeclaration::removeProperty): 37 (WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal): 38 (WebCore::PropertySetCSSStyleDeclaration::getPropertyValueInternal): 39 (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal): 40 (WebCore::PropertySetCSSStyleDeclaration::copy): 41 (WebCore::PropertySetCSSStyleDeclaration::makeMutable): 42 (WebCore::PropertySetCSSStyleDeclaration::cssPropertyMatches): 43 (WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration): 44 (WebCore::InlineCSSStyleDeclaration::ref): 45 (WebCore::InlineCSSStyleDeclaration::deref): 46 (WebCore::InlineCSSStyleDeclaration::didMutate): 47 (WebCore::InlineCSSStyleDeclaration::parentStyleSheet): 48 (WebCore::InlineCSSStyleDeclaration::ensureMutablePropertySet): 49 * css/PropertySetCSSStyleDeclaration.h: 50 (PropertySetCSSStyleDeclaration): 51 (WebCore::PropertySetCSSStyleDeclaration::propertySet): 52 (WebCore::PropertySetCSSStyleDeclaration::ensureMutablePropertySet): 53 (InlineCSSStyleDeclaration): 54 * css/StylePropertySet.cpp: 55 (WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration): 56 * css/StylePropertySet.h: 57 (StylePropertySet): 58 * dom/ElementAttributeData.cpp: 59 * dom/ElementAttributeData.h: 60 (ElementAttributeData): 61 * dom/StyledElement.cpp: 62 (WebCore::StyledElement::styleAttributeChanged): 63 * dom/StyledElement.h: 64 (WebCore::StyledElement::~StyledElement): 65 (StyledElement): 66 1 67 2012-06-29 Kwang Yul Seo <skyul@company100.net> 2 68 -
trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
r118194 r121562 133 133 unsigned PropertySetCSSStyleDeclaration::length() const 134 134 { 135 return m_propertySet->propertyCount();135 return propertySet()->propertyCount(); 136 136 } 137 137 138 138 String PropertySetCSSStyleDeclaration::item(unsigned i) const 139 139 { 140 if (i >= m_propertySet->propertyCount())140 if (i >= propertySet()->propertyCount()) 141 141 return ""; 142 return getPropertyName( m_propertySet->propertyAt(i).id());142 return getPropertyName(propertySet()->propertyAt(i).id()); 143 143 } 144 144 145 145 String PropertySetCSSStyleDeclaration::cssText() const 146 146 { 147 return m_propertySet->asText();147 return propertySet()->asText(); 148 148 } 149 149 … … 157 157 ec = 0; 158 158 // FIXME: Detect syntax errors and set ec. 159 m_propertySet->parseDeclaration(text, contextStyleSheet());159 ensureMutablePropertySet()->parseDeclaration(text, contextStyleSheet()); 160 160 161 161 didMutate(PropertyChanged); … … 171 171 if (!propertyID) 172 172 return 0; 173 return cloneAndCacheForCSSOM( m_propertySet->getPropertyCSSValue(propertyID).get());173 return cloneAndCacheForCSSOM(propertySet()->getPropertyCSSValue(propertyID).get()); 174 174 } 175 175 … … 179 179 if (!propertyID) 180 180 return String(); 181 return m_propertySet->getPropertyValue(propertyID);181 return propertySet()->getPropertyValue(propertyID); 182 182 } 183 183 … … 187 187 if (!propertyID) 188 188 return String(); 189 return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";189 return propertySet()->propertyIsImportant(propertyID) ? "important" : ""; 190 190 } 191 191 … … 195 195 if (!propertyID) 196 196 return String(); 197 CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);197 CSSPropertyID shorthandID = propertySet()->getPropertyShorthand(propertyID); 198 198 if (!shorthandID) 199 199 return String(); … … 206 206 if (!propertyID) 207 207 return false; 208 return m_propertySet->isPropertyImplicit(propertyID);208 return propertySet()->isPropertyImplicit(propertyID); 209 209 } 210 210 … … 223 223 224 224 ec = 0; 225 bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());225 bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet()); 226 226 227 227 didMutate(changed ? PropertyChanged : NoChanges); … … 249 249 ec = 0; 250 250 String result; 251 bool changed = m_propertySet->removeProperty(propertyID, &result);251 bool changed = ensureMutablePropertySet()->removeProperty(propertyID, &result); 252 252 253 253 didMutate(changed ? PropertyChanged : NoChanges); … … 263 263 PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID) 264 264 { 265 return m_propertySet->getPropertyCSSValue(propertyID);265 return propertySet()->getPropertyCSSValue(propertyID); 266 266 } 267 267 268 268 String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID) 269 269 { 270 return m_propertySet->getPropertyValue(propertyID);270 return propertySet()->getPropertyValue(propertyID); 271 271 } 272 272 … … 279 279 280 280 ec = 0; 281 bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());281 bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet()); 282 282 283 283 didMutate(changed ? PropertyChanged : NoChanges); … … 314 314 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const 315 315 { 316 return m_propertySet->copy();316 return propertySet()->copy(); 317 317 } 318 318 319 319 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable() 320 320 { 321 return m_propertySet;321 return ensureMutablePropertySet(); 322 322 } 323 323 324 324 bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const 325 325 { 326 return m_propertySet->propertyMatches(property);326 return propertySet()->propertyMatches(property); 327 327 } 328 328 … … 381 381 } 382 382 383 InlineCSSStyleDeclaration::InlineCSSStyleDeclaration(StyledElement* parentElement) 384 : PropertySetCSSStyleDeclaration(const_cast<StylePropertySet*>(parentElement->inlineStyle())) 385 , m_parentElement(parentElement) 386 { 387 } 388 389 void InlineCSSStyleDeclaration::ref() 390 { 391 m_parentElement->ref(); 392 } 393 394 void InlineCSSStyleDeclaration::deref() 395 { 396 m_parentElement->deref(); 397 } 398 383 399 void InlineCSSStyleDeclaration::didMutate(MutationType type) 384 400 { … … 388 404 m_cssomCSSValueClones.clear(); 389 405 390 if (!m_parentElement)391 return;392 406 m_parentElement->setNeedsStyleRecalc(InlineStyleChange); 393 407 m_parentElement->invalidateStyleAttribute(); … … 397 411 CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const 398 412 { 399 return m_parentElement ? m_parentElement->document()->elementSheet() : 0; 413 return m_parentElement->document()->elementSheet(); 414 } 415 416 StylePropertySet* InlineCSSStyleDeclaration::ensureMutablePropertySet() 417 { 418 ASSERT(m_propertySet); 419 ASSERT(m_propertySet == m_parentElement->inlineStyle()); 420 return m_propertySet; 400 421 } 401 422 -
trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h
r118194 r121562 43 43 44 44 virtual StyledElement* parentElement() const { return 0; } 45 virtual void clearParentElement() { ASSERT_NOT_REACHED(); }46 45 StyleSheetContents* contextStyleSheet() const; 47 46 48 47 virtual void ref() OVERRIDE; 49 48 virtual void deref() OVERRIDE; 49 50 protected: 51 const StylePropertySet* propertySet() const { return m_propertySet; } 52 virtual StylePropertySet* ensureMutablePropertySet() { return m_propertySet; } 50 53 51 54 private: … … 107 110 virtual void didMutate(MutationType) OVERRIDE; 108 111 112 virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE { return m_propertySet; } 113 109 114 unsigned m_refCount; 110 115 CSSRule* m_parentRule; … … 114 119 { 115 120 public: 116 InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement) 117 : PropertySetCSSStyleDeclaration(propertySet) 118 , m_parentElement(parentElement) 119 { 120 } 121 InlineCSSStyleDeclaration(StyledElement*); 122 123 virtual void ref() OVERRIDE; 124 virtual void deref() OVERRIDE; 121 125 122 126 private: 123 127 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE; 124 128 virtual StyledElement* parentElement() const OVERRIDE { return m_parentElement; } 125 virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }126 129 127 130 virtual void didMutate(MutationType) OVERRIDE; 131 132 virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE; 128 133 129 134 StyledElement* m_parentElement; -
trunk/Source/WebCore/css/StylePropertySet.cpp
r121442 r121562 1052 1052 } 1053 1053 m_ownsCSSOMWrapper = true; 1054 PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<Style PropertySet*>(this), const_cast<StyledElement*>(parentElement));1054 PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StyledElement*>(parentElement)); 1055 1055 propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper)); 1056 1056 return cssomWrapper; 1057 }1058 1059 void StylePropertySet::clearParentElement(StyledElement* element)1060 {1061 if (!m_ownsCSSOMWrapper)1062 return;1063 ASSERT_UNUSED(element, propertySetCSSOMWrapperMap().get(this)->parentElement() == element);1064 propertySetCSSOMWrapperMap().get(this)->clearParentElement();1065 1057 } 1066 1058 -
trunk/Source/WebCore/css/StylePropertySet.h
r121022 r121562 104 104 String asText() const; 105 105 106 void clearParentElement(StyledElement*);107 108 106 CSSStyleDeclaration* ensureCSSStyleDeclaration() const; 109 107 CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const; -
trunk/Source/WebCore/dom/ElementAttributeData.cpp
r121539 r121562 162 162 } 163 163 164 void ElementAttributeData::destroyInlineStyle(StyledElement* element)165 {166 if (!m_inlineStyleDecl)167 return;168 m_inlineStyleDecl->clearParentElement(element);169 m_inlineStyleDecl = 0;170 }171 172 164 void ElementAttributeData::addAttribute(const Attribute& attribute, Element* element, EInUpdateStyleAttribute inUpdateStyleAttribute) 173 165 { -
trunk/Source/WebCore/dom/ElementAttributeData.h
r121539 r121562 68 68 StylePropertySet* ensureMutableInlineStyle(StyledElement*); 69 69 void updateInlineStyleAvoidingMutation(StyledElement*, const String& text); 70 void destroyInlineStyle(StyledElement*);71 70 72 71 StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); } -
trunk/Source/WebCore/dom/StyledElement.cpp
r119846 r121562 136 136 } 137 137 138 StyledElement::~StyledElement()139 {140 destroyInlineStyle();141 }142 143 138 CSSStyleDeclaration* StyledElement::style() 144 139 { … … 184 179 if (document() && document()->scriptableDocumentParser() && !document()->isInDocumentWrite()) 185 180 startLineNumber = document()->scriptableDocumentParser()->lineNumber(); 186 if (newStyleString.isNull()) 187 destroyInlineStyle(); 188 else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber)) 181 if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber)) 189 182 ensureAttributeData()->updateInlineStyleAvoidingMutation(this, newStyleString); 190 183 setIsStyleAttributeValid(); -
trunk/Source/WebCore/dom/StyledElement.h
r119776 r121562 36 36 class StyledElement : public Element { 37 37 public: 38 virtual ~StyledElement() ;38 virtual ~StyledElement() { } 39 39 40 40 virtual StylePropertySet* additionalAttributeStyle() { return 0; } … … 87 87 void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const; 88 88 void updateAttributeStyle(); 89 90 void destroyInlineStyle()91 {92 if (attributeData())93 attributeData()->destroyInlineStyle(this);94 }95 89 }; 96 90
Note: See TracChangeset
for help on using the changeset viewer.