Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: Source/core/dom/Element.cpp

Issue 119533003: Clear mutable inline style when it is empty. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed typo. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound; 917 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound;
918 setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute ); 918 setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute );
919 } 919 }
920 920
921 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const Atom icString& value) 921 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const Atom icString& value)
922 { 922 {
923 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound; 923 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound;
924 setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute); 924 setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute);
925 } 925 }
926 926
927 void Element::removeSynchronizedLazyAttribute(const QualifiedName& name)
928 {
929 size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : kNotFound;
930 if (index == kNotFound)
931 return;
932 removeAttributeInternal(index, InSynchronizationOfLazyAttribute);
933 }
934
927 ALWAYS_INLINE void Element::setAttributeInternal(size_t index, const QualifiedNa me& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchro nizationOfLazyAttribute) 935 ALWAYS_INLINE void Element::setAttributeInternal(size_t index, const QualifiedNa me& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchro nizationOfLazyAttribute)
928 { 936 {
929 if (newValue.isNull()) { 937 if (newValue.isNull()) {
930 if (index != kNotFound) 938 if (index != kNotFound)
931 removeAttributeInternal(index, inSynchronizationOfLazyAttribute); 939 removeAttributeInternal(index, inSynchronizationOfLazyAttribute);
932 return; 940 return;
933 } 941 }
934 942
935 if (index == kNotFound) { 943 if (index == kNotFound) {
936 addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute); 944 addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute);
(...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 } 3435 }
3428 3436
3429 void Element::synchronizeStyleAttributeInternal() const 3437 void Element::synchronizeStyleAttributeInternal() const
3430 { 3438 {
3431 ASSERT(isStyledElement()); 3439 ASSERT(isStyledElement());
3432 ASSERT(elementData()); 3440 ASSERT(elementData());
3433 ASSERT(elementData()->m_styleAttributeIsDirty); 3441 ASSERT(elementData()->m_styleAttributeIsDirty);
3434 elementData()->m_styleAttributeIsDirty = false; 3442 elementData()->m_styleAttributeIsDirty = false;
3435 if (const StylePropertySet* inlineStyle = this->inlineStyle()) 3443 if (const StylePropertySet* inlineStyle = this->inlineStyle())
3436 const_cast<Element*>(this)->setSynchronizedLazyAttribute(styleAttr, inli neStyle->asText()); 3444 const_cast<Element*>(this)->setSynchronizedLazyAttribute(styleAttr, inli neStyle->asText());
3445 else
3446 const_cast<Element*>(this)->removeSynchronizedLazyAttribute(styleAttr);
eseidel 2013/12/23 21:30:23 I remember being in this code for the hasAttribute
chrishtr 2013/12/23 22:06:46 Will adjust this method to use setSynchronizedLazy
3437 } 3447 }
3438 3448
3439 CSSStyleDeclaration* Element::style() 3449 CSSStyleDeclaration* Element::style()
3440 { 3450 {
3441 if (!isStyledElement()) 3451 if (!isStyledElement())
3442 return 0; 3452 return 0;
3443 return ensureElementRareData().ensureInlineCSSStyleDeclaration(this); 3453 return ensureElementRareData().ensureInlineCSSStyleDeclaration(this);
3444 } 3454 }
3445 3455
3446 MutableStylePropertySet* Element::ensureMutableInlineStyle() 3456 MutableStylePropertySet* Element::ensureMutableInlineStyle()
3447 { 3457 {
3448 ASSERT(isStyledElement()); 3458 ASSERT(isStyledElement());
3449 RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData()->m_inlineS tyle; 3459 RefPtr<StylePropertySet>& inlineStyle = ensureUniqueElementData()->m_inlineS tyle;
3450 if (!inlineStyle) { 3460 if (!inlineStyle) {
3451 CSSParserMode mode = (!isHTMLElement() || document().inQuirksMode()) ? H TMLQuirksMode : HTMLStandardMode; 3461 CSSParserMode mode = (!isHTMLElement() || document().inQuirksMode()) ? H TMLQuirksMode : HTMLStandardMode;
3452 inlineStyle = MutableStylePropertySet::create(mode); 3462 inlineStyle = MutableStylePropertySet::create(mode);
3453 } else if (!inlineStyle->isMutable()) { 3463 } else if (!inlineStyle->isMutable()) {
3454 inlineStyle = inlineStyle->mutableCopy(); 3464 inlineStyle = inlineStyle->mutableCopy();
3455 } 3465 }
3456 return toMutableStylePropertySet(inlineStyle); 3466 return toMutableStylePropertySet(inlineStyle);
3457 } 3467 }
3458 3468
3469 void Element::clearMutableInlineStyleIfEmpty()
3470 {
3471 if (ensureMutableInlineStyle()->isEmpty()) {
3472 ensureUniqueElementData()->m_inlineStyle.clear();
3473 }
3474 }
3475
3459 PropertySetCSSStyleDeclaration* Element::inlineStyleCSSOMWrapper() 3476 PropertySetCSSStyleDeclaration* Element::inlineStyleCSSOMWrapper()
3460 { 3477 {
3461 if (!inlineStyle() || !inlineStyle()->hasCSSOMWrapper()) 3478 if (!inlineStyle() || !inlineStyle()->hasCSSOMWrapper())
3462 return 0; 3479 return 0;
3463 PropertySetCSSStyleDeclaration* cssomWrapper = ensureMutableInlineStyle()->c ssStyleDeclaration(); 3480 PropertySetCSSStyleDeclaration* cssomWrapper = ensureMutableInlineStyle()->c ssStyleDeclaration();
3464 ASSERT(cssomWrapper && cssomWrapper->parentElement() == this); 3481 ASSERT(cssomWrapper && cssomWrapper->parentElement() == this);
3465 return cssomWrapper; 3482 return cssomWrapper;
3466 } 3483 }
3467 3484
3468 inline void Element::setInlineStyleFromString(const AtomicString& newStyleString ) 3485 inline void Element::setInlineStyleFromString(const AtomicString& newStyleString )
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 return false; 3574 return false;
3558 bool changes = ensureMutableInlineStyle()->removeProperty(propertyID); 3575 bool changes = ensureMutableInlineStyle()->removeProperty(propertyID);
3559 if (changes) 3576 if (changes)
3560 inlineStyleChanged(); 3577 inlineStyleChanged();
3561 return changes; 3578 return changes;
3562 } 3579 }
3563 3580
3564 void Element::removeAllInlineStyleProperties() 3581 void Element::removeAllInlineStyleProperties()
3565 { 3582 {
3566 ASSERT(isStyledElement()); 3583 ASSERT(isStyledElement());
3567 if (!inlineStyle() || inlineStyle()->isEmpty()) 3584 if (!inlineStyle())
3568 return; 3585 return;
3569 ensureMutableInlineStyle()->clear(); 3586 ensureMutableInlineStyle()->clear();
3570 inlineStyleChanged(); 3587 inlineStyleChanged();
3571 } 3588 }
3572 3589
3573 void Element::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const 3590 void Element::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
3574 { 3591 {
3575 ASSERT(isStyledElement()); 3592 ASSERT(isStyledElement());
3576 if (const StylePropertySet* inlineStyle = elementData() ? elementData()->inl ineStyle() : 0) 3593 if (const StylePropertySet* inlineStyle = elementData() ? elementData()->inl ineStyle() : 0)
3577 inlineStyle->addSubresourceStyleURLs(urls, document().elementSheet()->co ntents()); 3594 inlineStyle->addSubresourceStyleURLs(urls, document().elementSheet()->co ntents());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3649 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3666 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3650 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3667 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3651 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3668 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3652 return false; 3669 return false;
3653 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3670 if (FullscreenElementStack::isActiveFullScreenElement(this))
3654 return false; 3671 return false;
3655 return true; 3672 return true;
3656 } 3673 }
3657 3674
3658 } // namespace WebCore 3675 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698