Changeset 133451 in webkit


Ignore:
Timestamp:
Nov 5, 2012 2:47:35 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r133286, r133385, and r133394.
http://trac.webkit.org/changeset/133286
http://trac.webkit.org/changeset/133385
http://trac.webkit.org/changeset/133394
https://bugs.webkit.org/show_bug.cgi?id=101198

Broke image placement on some web sites. (Requested by kling
on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-11-05

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::sweepMatchedPropertiesCache):
(WebCore::StyleResolver::matchAllRules):
(WebCore::StyleResolver::canShareStyleWithElement):

  • dom/Attr.cpp:

(WebCore::Attr::detachFromElementWithValue):

  • dom/Element.cpp:

(WebCore::Element::~Element):
(WebCore::Element::detachAttribute):
(WebCore::Element::getAttribute):
(WebCore::Element::setAttributeNode):
(WebCore::Element::removeAttributeInternal):
(WebCore::Element::getAttributeNode):
(WebCore::Element::getAttributeNodeNS):
(WebCore::Element::normalizeAttributes):
(WebCore::Element::attrIfExists):
(WebCore::Element::ensureAttr):
(WebCore::Element::cloneAttributesFromElement):

  • dom/Element.h:

(Element):
(WebCore::Element::updateInvalidAttributes):

  • dom/ElementAttributeData.cpp:

(WebCore::MutableElementAttributeData::MutableElementAttributeData):
(WebCore):
(WebCore::attrListMap):
(WebCore::attrListForElement):
(WebCore::ensureAttrListForElement):
(WebCore::removeAttrListForElement):
(WebCore::findAttrInList):
(WebCore::ElementAttributeData::attrIfExists):
(WebCore::ElementAttributeData::ensureAttr):
(WebCore::ElementAttributeData::setAttr):
(WebCore::ElementAttributeData::removeAttr):
(WebCore::ElementAttributeData::detachAttrObjectsFromElement):
(WebCore::ElementAttributeData::reportMemoryUsage):
(WebCore::ElementAttributeData::cloneDataFrom):
(WebCore::ElementAttributeData::clearAttributes):
(WebCore::ElementAttributeData::getAttributeNode):

  • dom/ElementAttributeData.h:

(WebCore):
(WebCore::ElementAttributeData::attributeStyle):
(WebCore::ElementAttributeData::setAttributeStyle):
(ElementAttributeData):
(WebCore::ElementAttributeData::ElementAttributeData):

  • dom/Node.h:

(WebCore):
(WebCore::Node::hasAttrList):
(WebCore::Node::attributeStyleDirty):
(WebCore::Node::setAttributeStyleDirty):
(WebCore::Node::clearAttributeStyleDirty):
(Node):
(WebCore::Node::setHasAttrList):
(WebCore::Node::clearHasAttrList):
(WebCore::Node::isStyleAttributeValid):
(WebCore::Node::setIsStyleAttributeValid):
(WebCore::Node::clearIsStyleAttributeValid):

  • dom/StyledElement.cpp:

(WebCore::StyledElement::updateStyleAttribute):
(WebCore::StyledElement::attributeChanged):
(WebCore::StyledElement::styleAttributeChanged):
(WebCore::StyledElement::inlineStyleChanged):
(WebCore::StyledElement::updateAttributeStyle):

  • dom/StyledElement.h:

(StyledElement):
(WebCore::StyledElement::invalidateStyleAttribute):
(WebCore::StyledElement::attributeStyle):

  • inspector/InspectorCSSAgent.cpp:

(WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):

Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r133447 r133451  
     12012-11-05  Sheriff Bot  <webkit.review.bot@gmail.com>
     2
     3        Unreviewed, rolling out r133286, r133385, and r133394.
     4        http://trac.webkit.org/changeset/133286
     5        http://trac.webkit.org/changeset/133385
     6        http://trac.webkit.org/changeset/133394
     7        https://bugs.webkit.org/show_bug.cgi?id=101198
     8
     9        Broke image placement on some web sites. (Requested by kling
     10        on #webkit).
     11
     12        * css/StyleResolver.cpp:
     13        (WebCore::StyleResolver::sweepMatchedPropertiesCache):
     14        (WebCore::StyleResolver::matchAllRules):
     15        (WebCore::StyleResolver::canShareStyleWithElement):
     16        * dom/Attr.cpp:
     17        (WebCore::Attr::detachFromElementWithValue):
     18        * dom/Element.cpp:
     19        (WebCore::Element::~Element):
     20        (WebCore::Element::detachAttribute):
     21        (WebCore::Element::getAttribute):
     22        (WebCore::Element::setAttributeNode):
     23        (WebCore::Element::removeAttributeInternal):
     24        (WebCore::Element::getAttributeNode):
     25        (WebCore::Element::getAttributeNodeNS):
     26        (WebCore::Element::normalizeAttributes):
     27        (WebCore::Element::attrIfExists):
     28        (WebCore::Element::ensureAttr):
     29        (WebCore::Element::cloneAttributesFromElement):
     30        * dom/Element.h:
     31        (Element):
     32        (WebCore::Element::updateInvalidAttributes):
     33        * dom/ElementAttributeData.cpp:
     34        (WebCore::MutableElementAttributeData::MutableElementAttributeData):
     35        (WebCore):
     36        (WebCore::attrListMap):
     37        (WebCore::attrListForElement):
     38        (WebCore::ensureAttrListForElement):
     39        (WebCore::removeAttrListForElement):
     40        (WebCore::findAttrInList):
     41        (WebCore::ElementAttributeData::attrIfExists):
     42        (WebCore::ElementAttributeData::ensureAttr):
     43        (WebCore::ElementAttributeData::setAttr):
     44        (WebCore::ElementAttributeData::removeAttr):
     45        (WebCore::ElementAttributeData::detachAttrObjectsFromElement):
     46        (WebCore::ElementAttributeData::reportMemoryUsage):
     47        (WebCore::ElementAttributeData::cloneDataFrom):
     48        (WebCore::ElementAttributeData::clearAttributes):
     49        (WebCore::ElementAttributeData::getAttributeNode):
     50        * dom/ElementAttributeData.h:
     51        (WebCore):
     52        (WebCore::ElementAttributeData::attributeStyle):
     53        (WebCore::ElementAttributeData::setAttributeStyle):
     54        (ElementAttributeData):
     55        (WebCore::ElementAttributeData::ElementAttributeData):
     56        * dom/Node.h:
     57        (WebCore):
     58        (WebCore::Node::hasAttrList):
     59        (WebCore::Node::attributeStyleDirty):
     60        (WebCore::Node::setAttributeStyleDirty):
     61        (WebCore::Node::clearAttributeStyleDirty):
     62        (Node):
     63        (WebCore::Node::setHasAttrList):
     64        (WebCore::Node::clearHasAttrList):
     65        (WebCore::Node::isStyleAttributeValid):
     66        (WebCore::Node::setIsStyleAttributeValid):
     67        (WebCore::Node::clearIsStyleAttributeValid):
     68        * dom/StyledElement.cpp:
     69        (WebCore::StyledElement::updateStyleAttribute):
     70        (WebCore::StyledElement::attributeChanged):
     71        (WebCore::StyledElement::styleAttributeChanged):
     72        (WebCore::StyledElement::inlineStyleChanged):
     73        (WebCore::StyledElement::updateAttributeStyle):
     74        * dom/StyledElement.h:
     75        (StyledElement):
     76        (WebCore::StyledElement::invalidateStyleAttribute):
     77        (WebCore::StyledElement::attributeStyle):
     78        * inspector/InspectorCSSAgent.cpp:
     79        (WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):
     80
    1812012-11-05  Simon Hausmann  <simon.hausmann@digia.com>
    282
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r133324 r133451  
    479479{
    480480    // Look for cache entries containing a style declaration with a single ref and remove them.
    481     // This may happen when an element attribute mutation causes it to generate a new presentationAttributeStyle(),
     481    // This may happen when an element attribute mutation causes it to generate a new attributeStyle(),
    482482    // potentially leaving this cache with the last ref on the old one.
    483483    Vector<unsigned, 16> toRemove;
     
    928928    // Now check author rules, beginning first with presentational attributes mapped from HTML.
    929929    if (m_styledElement) {
    930         addElementStyleProperties(result, m_styledElement->presentationAttributeStyle());
     930        addElementStyleProperties(result, m_styledElement->attributeStyle());
    931931
    932932        // Now we check additional mapped declarations.
     
    11801180        return false;
    11811181#endif
    1182     if (!!element->presentationAttributeStyle() != !!m_styledElement->presentationAttributeStyle())
     1182    if (!!element->attributeStyle() != !!m_styledElement->attributeStyle())
    11831183        return false;
    11841184    const StylePropertySet* additionalAttributeStyleA = element->additionalAttributeStyle();
     
    12671267    }
    12681268
    1269     if (element->presentationAttributeStyle() && !attributeStylesEqual(element->presentationAttributeStyle(), m_styledElement->presentationAttributeStyle()))
     1269    if (element->attributeStyle() && !attributeStylesEqual(element->attributeStyle(), m_styledElement->attributeStyle()))
    12701270        return false;
    12711271
  • trunk/Source/WebCore/dom/Attr.cpp

    r133394 r133451  
    219219    ASSERT(m_element);
    220220    ASSERT(m_standaloneValue.isNull());
     221    m_element->attributeData()->removeAttr(m_element, qualifiedName());
    221222    m_standaloneValue = value;
    222223    m_element = 0;
  • trunk/Source/WebCore/dom/Element.cpp

    r133428 r133451  
    125125};
    126126
    127 typedef Vector<RefPtr<Attr> > AttrNodeList;
    128 typedef HashMap<Element*, OwnPtr<AttrNodeList> > AttrNodeListMap;
    129 
    130 static AttrNodeListMap& attrNodeListMap()
    131 {
    132     DEFINE_STATIC_LOCAL(AttrNodeListMap, map, ());
    133     return map;
    134 }
    135 
    136 static AttrNodeList* attrNodeListForElement(Element* element)
    137 {
    138     if (!element->hasSyntheticAttrChildNodes())
    139         return 0;
    140     ASSERT(attrNodeListMap().contains(element));
    141     return attrNodeListMap().get(element);
    142 }
    143 
    144 static AttrNodeList* ensureAttrNodeListForElement(Element* element)
    145 {
    146     if (element->hasSyntheticAttrChildNodes()) {
    147         ASSERT(attrNodeListMap().contains(element));
    148         return attrNodeListMap().get(element);
    149     }
    150     ASSERT(!attrNodeListMap().contains(element));
    151     element->setHasSyntheticAttrChildNodes(true);
    152     AttrNodeListMap::AddResult result = attrNodeListMap().add(element, adoptPtr(new AttrNodeList));
    153     return result.iterator->value.get();
    154 }
    155 
    156 static void removeAttrNodeListForElement(Element* element)
    157 {
    158     ASSERT(element->hasSyntheticAttrChildNodes());
    159     ASSERT(attrNodeListMap().contains(element));
    160     attrNodeListMap().remove(element);
    161     element->setHasSyntheticAttrChildNodes(false);
    162 }
    163 
    164 static Attr* findAttrNodeInList(AttrNodeList* attrNodeList, const QualifiedName& name)
    165 {
    166     for (unsigned i = 0; i < attrNodeList->size(); ++i) {
    167         if (attrNodeList->at(i)->qualifiedName() == name)
    168             return attrNodeList->at(i).get();
    169     }
    170     return 0;
    171 }
    172 
    173127PassRefPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
    174128{
     
    192146    }
    193147
    194     if (hasSyntheticAttrChildNodes())
    195         detachAllAttrNodesFromElement();
     148    if (hasAttrList()) {
     149        ASSERT(m_attributeData);
     150        m_attributeData->detachAttrObjectsFromElement(this);
     151    }
    196152}
    197153
     
    252208    ASSERT(attribute);
    253209
    254     RefPtr<Attr> attrNode = attrIfExists(attribute->name());
    255     if (attrNode)
    256         detachAttrNodeFromElementWithValue(attrNode.get(), attribute->value());
     210    RefPtr<Attr> attr = attrIfExists(attribute->name());
     211    if (attr)
     212        attr->detachFromElementWithValue(attribute->value());
    257213    else
    258         attrNode = Attr::create(document(), attribute->name(), attribute->value());
     214        attr = Attr::create(document(), attribute->name(), attribute->value());
    259215
    260216    removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
    261     return attrNode.release();
     217    return attr.release();
    262218}
    263219
     
    305261const AtomicString& Element::getAttribute(const QualifiedName& name) const
    306262{
    307     if (UNLIKELY(name == styleAttr) && styleAttributeIsDirty())
     263    if (UNLIKELY(name == styleAttr) && !isStyleAttributeValid())
    308264        updateStyleAttribute();
    309265
     
    663619
    664620    // Update the 'style' attribute if it's invalid and being requested:
    665     if (styleAttributeIsDirty() && equalPossiblyIgnoringCase(name, styleAttr.localName(), ignoreCase))
     621    if (!isStyleAttributeValid() && equalPossiblyIgnoringCase(name, styleAttr.localName(), ignoreCase))
    666622        updateStyleAttribute();
    667623
     
    15291485#endif
    15301486
    1531 PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
    1532 {
    1533     if (!attrNode) {
     1487PassRefPtr<Attr> Element::setAttributeNode(Attr* attr, ExceptionCode& ec)
     1488{
     1489    if (!attr) {
    15341490        ec = TYPE_MISMATCH_ERR;
    15351491        return 0;
    15361492    }
    15371493
    1538     RefPtr<Attr> oldAttrNode = attrIfExists(attrNode->qualifiedName());
    1539     if (oldAttrNode.get() == attrNode)
    1540         return attrNode; // This Attr is already attached to the element.
     1494    RefPtr<Attr> oldAttr = attrIfExists(attr->qualifiedName());
     1495    if (oldAttr.get() == attr)
     1496        return attr; // This Attr is already attached to the element.
    15411497
    15421498    // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object.
    15431499    // The DOM user must explicitly clone Attr nodes to re-use them in other elements.
    1544     if (attrNode->ownerElement()) {
     1500    if (attr->ownerElement()) {
    15451501        ec = INUSE_ATTRIBUTE_ERR;
    15461502        return 0;
     
    15501506    ElementAttributeData* attributeData = mutableAttributeData();
    15511507
    1552     size_t index = attributeData->getAttributeItemIndex(attrNode->qualifiedName());
     1508    size_t index = attributeData->getAttributeItemIndex(attr->qualifiedName());
    15531509    if (index != notFound) {
    1554         if (oldAttrNode)
    1555             detachAttrNodeFromElementWithValue(oldAttrNode.get(), attributeData->attributeItem(index)->value());
     1510        if (oldAttr)
     1511            oldAttr->detachFromElementWithValue(attributeData->attributeItem(index)->value());
    15561512        else
    1557             oldAttrNode = Attr::create(document(), attrNode->qualifiedName(), attributeData->attributeItem(index)->value());
    1558     }
    1559 
    1560     setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
    1561 
    1562     attrNode->attachToElement(this);
    1563     ensureAttrNodeListForElement(this)->append(attrNode);
    1564 
    1565     return oldAttrNode.release();
     1513            oldAttr = Attr::create(document(), attr->qualifiedName(), attributeData->attributeItem(index)->value());
     1514    }
     1515
     1516    setAttributeInternal(index, attr->qualifiedName(), attr->value(), NotInSynchronizationOfLazyAttribute);
     1517    attributeData->setAttr(this, attr->qualifiedName(), attr);
     1518    return oldAttr.release();
    15661519}
    15671520
     
    16361589    }
    16371590
    1638     if (RefPtr<Attr> attrNode = attrIfExists(name))
    1639         detachAttrNodeFromElementWithValue(attrNode.get(), attributeData->attributeItem(index)->value());
     1591    if (hasAttrList()) {
     1592        if (RefPtr<Attr> attr = attributeData->attrIfExists(this, name))
     1593            attr->detachFromElementWithValue(attributeData->attributeItem(index)->value());
     1594    }
    16401595
    16411596    attributeData->removeAttribute(index);
     
    16791634    if (!attributeData)
    16801635        return 0;
    1681     const Attribute* attribute = attributeData->getAttributeItem(name, shouldIgnoreAttributeCase(this));
    1682     if (!attribute)
    1683         return 0;
    1684     return ensureAttr(attribute->name());
     1636    return attributeData->getAttributeNode(name, shouldIgnoreAttributeCase(this), this);
    16851637}
    16861638
     
    16901642    if (!attributeData)
    16911643        return 0;
    1692     const Attribute* attribute = attributeData->getAttributeItem(QualifiedName(nullAtom, localName, namespaceURI));
    1693     if (!attribute)
    1694         return 0;
    1695     return ensureAttr(attribute->name());
     1644    return attributeData->getAttributeNode(QualifiedName(nullAtom, localName, namespaceURI), this);
    16961645}
    16971646
     
    19291878void Element::normalizeAttributes()
    19301879{
    1931     if (AttrNodeList* attrNodeList = attrNodeListForElement(this)) {
    1932         for (unsigned i = 0; i < attrNodeList->size(); ++i)
    1933             attrNodeList->at(i)->normalize();
     1880    if (!hasAttrList())
     1881        return;
     1882
     1883    const ElementAttributeData* attributeData = updatedAttributeData();
     1884    ASSERT(attributeData);
     1885
     1886    for (size_t i = 0; i < attributeData->length(); ++i) {
     1887        if (RefPtr<Attr> attr = attrIfExists(attributeData->attributeItem(i)->name()))
     1888            attr->normalize();
    19341889    }
    19351890}
     
    23812336PassRefPtr<Attr> Element::attrIfExists(const QualifiedName& name)
    23822337{
    2383     if (AttrNodeList* attrNodeList = attrNodeListForElement(this))
    2384         return findAttrNodeInList(attrNodeList, name);
    2385     return 0;
     2338    if (!hasAttrList())
     2339        return 0;
     2340    ASSERT(attributeData());
     2341    return attributeData()->attrIfExists(this, name);
    23862342}
    23872343
    23882344PassRefPtr<Attr> Element::ensureAttr(const QualifiedName& name)
    23892345{
    2390     AttrNodeList* attrNodeList = ensureAttrNodeListForElement(this);
    2391     RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name);
    2392     if (!attrNode) {
    2393         attrNode = Attr::create(this, name);
    2394         attrNodeList->append(attrNode);
    2395     }
    2396     return attrNode.release();
    2397 }
    2398 
    2399 void Element::detachAttrNodeFromElementWithValue(Attr* attrNode, const AtomicString& value)
    2400 {
    2401     ASSERT(hasSyntheticAttrChildNodes());
    2402     attrNode->detachFromElementWithValue(value);
    2403 
    2404     AttrNodeList* attrNodeList = attrNodeListForElement(this);
    2405     for (unsigned i = 0; i < attrNodeList->size(); ++i) {
    2406         if (attrNodeList->at(i)->qualifiedName() == attrNode->qualifiedName()) {
    2407             attrNodeList->remove(i);
    2408             if (attrNodeList->isEmpty())
    2409                 removeAttrNodeListForElement(this);
    2410             return;
    2411         }
    2412     }
    2413     ASSERT_NOT_REACHED();
    2414 }
    2415 
    2416 void Element::detachAllAttrNodesFromElement()
    2417 {
    2418     AttrNodeList* attrNodeList = attrNodeListForElement(this);
    2419     ASSERT(attrNodeList);
    2420 
    2421     for (unsigned i = 0; i < attributeCount(); ++i) {
    2422         const Attribute* attribute = attributeItem(i);
    2423         if (RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, attribute->name()))
    2424             attrNode->detachFromElementWithValue(attribute->value());
    2425     }
    2426 
    2427     removeAttrNodeListForElement(this);
     2346    ASSERT(attributeData());
     2347    return attributeData()->ensureAttr(this, name);
    24282348}
    24292349
     
    24492369void Element::cloneAttributesFromElement(const Element& other)
    24502370{
    2451     if (hasSyntheticAttrChildNodes())
    2452         detachAllAttrNodesFromElement();
    2453 
    24542371    if (const ElementAttributeData* attributeData = other.updatedAttributeData())
    24552372        mutableAttributeData()->cloneDataFrom(*attributeData, other, *this);
    24562373    else if (m_attributeData) {
    2457         m_attributeData->clearAttributes();
     2374        m_attributeData->clearAttributes(this);
    24582375        m_attributeData.clear();
    24592376    }
  • trunk/Source/WebCore/dom/Element.h

    r133394 r133451  
    44 *           (C) 2001 Peter Kelly (pmk@post.com)
    55 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    6  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
     6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    466466    void classAttributeChanged(const AtomicString& newClassString);
    467467
    468     bool styleAttributeIsDirty() const;
    469 
    470468private:
    471469    // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
     
    530528    ElementRareData* elementRareData() const;
    531529    ElementRareData* ensureElementRareData();
    532 
    533     void detachAllAttrNodesFromElement();
    534     void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
    535530
    536531    RefPtr<ElementAttributeData> m_attributeData;
     
    734729}
    735730
    736 inline bool Element::styleAttributeIsDirty() const
    737 {
    738     return m_attributeData && m_attributeData->styleAttributeIsDirty();
    739 }
    740 
    741731inline void Element::updateInvalidAttributes() const
    742732{
    743     if (styleAttributeIsDirty())
     733    if (!isStyleAttributeValid())
    744734        updateStyleAttribute();
    745735
  • trunk/Source/WebCore/dom/ElementAttributeData.cpp

    r133394 r133451  
    3636namespace WebCore {
    3737
    38 struct SameSizeAsElementAttributeData : public RefCounted<SameSizeAsElementAttributeData> {
    39     unsigned bitfield;
    40     void* pointers[4];
    41 };
    42 COMPILE_ASSERT(sizeof(ElementAttributeData) == sizeof(ElementAttributeData), element_attribute_data_should_stay_small);
    43 
    4438static size_t sizeForImmutableElementAttributeDataWithAttributeCount(unsigned count)
    4539{
     
    7064
    7165    m_inlineStyleDecl = baseOther.m_inlineStyleDecl;
    72     m_presentationAttributeStyle = baseOther.m_presentationAttributeStyle;
     66    m_attributeStyle = baseOther.m_attributeStyle;
    7367    m_classNames = baseOther.m_classNames;
    7468    m_idForStyleResolution = baseOther.m_idForStyleResolution;
     
    9286    ASSERT(!isMutable());
    9387    return adoptRef(new MutableElementAttributeData(static_cast<const ImmutableElementAttributeData&>(*this)));
     88}
     89
     90typedef Vector<RefPtr<Attr> > AttrList;
     91typedef HashMap<Element*, OwnPtr<AttrList> > AttrListMap;
     92
     93static AttrListMap& attrListMap()
     94{
     95    DEFINE_STATIC_LOCAL(AttrListMap, map, ());
     96    return map;
     97}
     98
     99static AttrList* attrListForElement(Element* element)
     100{
     101    ASSERT(element);
     102    if (!element->hasAttrList())
     103        return 0;
     104    ASSERT(attrListMap().contains(element));
     105    return attrListMap().get(element);
     106}
     107
     108static AttrList* ensureAttrListForElement(Element* element)
     109{
     110    ASSERT(element);
     111    if (element->hasAttrList()) {
     112        ASSERT(attrListMap().contains(element));
     113        return attrListMap().get(element);
     114    }
     115    ASSERT(!attrListMap().contains(element));
     116    element->setHasAttrList();
     117    AttrListMap::AddResult result = attrListMap().add(element, adoptPtr(new AttrList));
     118    return result.iterator->value.get();
     119}
     120
     121static void removeAttrListForElement(Element* element)
     122{
     123    ASSERT(element);
     124    ASSERT(element->hasAttrList());
     125    ASSERT(attrListMap().contains(element));
     126    attrListMap().remove(element);
     127    element->clearHasAttrList();
     128}
     129
     130static Attr* findAttrInList(AttrList* attrList, const QualifiedName& name)
     131{
     132    for (unsigned i = 0; i < attrList->size(); ++i) {
     133        if (attrList->at(i)->qualifiedName() == name)
     134            return attrList->at(i).get();
     135    }
     136    return 0;
     137}
     138
     139PassRefPtr<Attr> ElementAttributeData::attrIfExists(Element* element, const QualifiedName& name) const
     140{
     141    if (AttrList* attrList = attrListForElement(element))
     142        return findAttrInList(attrList, name);
     143    return 0;
     144}
     145
     146PassRefPtr<Attr> ElementAttributeData::ensureAttr(Element* element, const QualifiedName& name) const
     147{
     148    AttrList* attrList = ensureAttrListForElement(element);
     149    RefPtr<Attr> attr = findAttrInList(attrList, name);
     150    if (!attr) {
     151        attr = Attr::create(element, name);
     152        attrList->append(attr);
     153    }
     154    return attr.release();
     155}
     156
     157void ElementAttributeData::setAttr(Element* element, const QualifiedName& name, Attr* attr) const
     158{
     159    AttrList* attrList = ensureAttrListForElement(element);
     160
     161    if (findAttrInList(attrList, name))
     162        return;
     163
     164    attrList->append(attr);
     165    attr->attachToElement(element);
     166}
     167
     168void ElementAttributeData::removeAttr(Element* element, const QualifiedName& name) const
     169{
     170    AttrList* attrList = attrListForElement(element);
     171    ASSERT(attrList);
     172
     173    for (unsigned i = 0; i < attrList->size(); ++i) {
     174        if (attrList->at(i)->qualifiedName() == name) {
     175            attrList->remove(i);
     176            if (attrList->isEmpty())
     177                removeAttrListForElement(element);
     178            return;
     179        }
     180    }
     181
     182    ASSERT_NOT_REACHED();
    94183}
    95184
     
    170259}
    171260
     261void ElementAttributeData::detachAttrObjectsFromElement(Element* element) const
     262{
     263    ASSERT(element->hasAttrList());
     264
     265    for (unsigned i = 0; i < length(); ++i) {
     266        const Attribute* attribute = attributeItem(i);
     267        if (RefPtr<Attr> attr = attrIfExists(element, attribute->name()))
     268            attr->detachFromElementWithValue(attribute->value());
     269    }
     270
     271    // The loop above should have cleaned out this element's Attr map.
     272    ASSERT(!element->hasAttrList());
     273}
     274
    172275void ElementAttributeData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
    173276{
     
    175278    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM, actualSize);
    176279    info.addMember(m_inlineStyleDecl);
    177     info.addMember(m_presentationAttributeStyle);
     280    info.addMember(m_attributeStyle);
    178281    info.addMember(m_classNames);
    179282    info.addMember(m_idForStyleResolution);
     
    220323        targetElement.updateName(oldName, newName);
    221324
    222     clearAttributes();
     325    clearAttributes(&targetElement);
    223326
    224327    if (sourceData.isMutable())
     
    239342    }
    240343
    241     if (!targetElement.isStyledElement())
    242         return;
    243 
    244     m_styleAttributeIsDirty = sourceData.m_styleAttributeIsDirty;
    245     m_presentationAttributeStyleIsDirty = sourceData.m_presentationAttributeStyleIsDirty;
    246 
    247     // Clone the source element's inline style unless it's immutable.
    248     if (sourceData.m_inlineStyleDecl)
     344    if (targetElement.isStyledElement() && sourceData.m_inlineStyleDecl) {
    249345        m_inlineStyleDecl = sourceData.m_inlineStyleDecl->immutableCopyIfNeeded();
    250 
    251     // Share the presentation attribute style (no need for cloning since it's not accessible via CSSOM.)
    252     m_presentationAttributeStyle = sourceData.m_presentationAttributeStyle;
    253 }
    254 
    255 void ElementAttributeData::clearAttributes()
    256 {
    257     ASSERT(isMutable());
     346        targetElement.setIsStyleAttributeValid(sourceElement.isStyleAttributeValid());
     347    }
     348}
     349
     350void ElementAttributeData::clearAttributes(Element* element)
     351{
     352    ASSERT(isMutable());
     353
     354    if (element->hasAttrList())
     355        detachAttrObjectsFromElement(element);
     356
    258357    clearClass();
    259358    mutableAttributeVector().clear();
    260359}
    261360
    262 }
     361PassRefPtr<Attr> ElementAttributeData::getAttributeNode(const String& name, bool shouldIgnoreAttributeCase, Element* element) const
     362{
     363    ASSERT(element);
     364    const Attribute* attribute = getAttributeItem(name, shouldIgnoreAttributeCase);
     365    if (!attribute)
     366        return 0;
     367    return ensureAttr(element, attribute->name());
     368}
     369
     370PassRefPtr<Attr> ElementAttributeData::getAttributeNode(const QualifiedName& name, Element* element) const
     371{
     372    ASSERT(element);
     373    const Attribute* attribute = getAttributeItem(name);
     374    if (!attribute)
     375        return 0;
     376    return ensureAttr(element, attribute->name());
     377}
     378
     379}
  • trunk/Source/WebCore/dom/ElementAttributeData.h

    r133394 r133451  
    3434namespace WebCore {
    3535
     36class Attr;
    3637class Element;
    3738class ImmutableElementAttributeData;
     
    6364    void detachCSSOMWrapperIfNeeded(StyledElement*);
    6465
    65     const StylePropertySet* presentationAttributeStyle() const { return m_presentationAttributeStyle.get(); }
    66     void setPresentationAttributeStyle(PassRefPtr<StylePropertySet> style) const { m_presentationAttributeStyle= style; }
     66    const StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); }
     67    void setAttributeStyle(PassRefPtr<StylePropertySet> style) const { m_attributeStyle = style; }
    6768
    6869    size_t length() const;
    6970    bool isEmpty() const { return !length(); }
     71
     72    PassRefPtr<Attr> getAttributeNode(const String&, bool shouldIgnoreAttributeCase, Element*) const;
     73    PassRefPtr<Attr> getAttributeNode(const QualifiedName&, Element*) const;
    7074
    7175    // Internal interface.
     
    8690    bool isEquivalent(const ElementAttributeData* other) const;
    8791
    88     bool styleAttributeIsDirty() const { return m_styleAttributeIsDirty; }
    89     void setStyleAttributeIsDirty(bool f) const { m_styleAttributeIsDirty = f; }
    90     bool presentationAttributeStyleIsDirty() const { return m_presentationAttributeStyleIsDirty; }
    91     void setPresentationAttributeStyleIsDirty(bool f) const { m_presentationAttributeStyleIsDirty = f; }
     92    void setAttr(Element*, const QualifiedName&, Attr*) const;
     93    void removeAttr(Element*, const QualifiedName&) const;
     94    PassRefPtr<Attr> attrIfExists(Element*, const QualifiedName&) const;
     95    PassRefPtr<Attr> ensureAttr(Element*, const QualifiedName&) const;
     96    void detachAttrObjectsFromElement(Element*) const;
    9297
    9398    void reportMemoryUsage(MemoryObjectInfo*) const;
     
    99104    ElementAttributeData()
    100105        : m_isMutable(true)
    101         , m_styleAttributeIsDirty(false)
    102         , m_presentationAttributeStyleIsDirty(false)
    103106        , m_arraySize(0)
    104107    { }
     
    106109    ElementAttributeData(unsigned arraySize)
    107110        : m_isMutable(false)
    108         , m_styleAttributeIsDirty(false)
    109         , m_presentationAttributeStyleIsDirty(false)
    110111        , m_arraySize(arraySize)
    111112    { }
    112113
    113114    unsigned m_isMutable : 1;
    114     mutable unsigned m_styleAttributeIsDirty : 1;
    115     mutable unsigned m_presentationAttributeStyleIsDirty : 1;
    116     unsigned m_arraySize : 29;
     115    unsigned m_arraySize : 31;
    117116
    118117    mutable RefPtr<StylePropertySet> m_inlineStyleDecl;
    119     mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;
     118    mutable RefPtr<StylePropertySet> m_attributeStyle;
    120119    mutable SpaceSplitString m_classNames;
    121120    mutable AtomicString m_idForStyleResolution;
     
    131130    size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
    132131    void cloneDataFrom(const ElementAttributeData& sourceData, const Element& sourceElement, Element& targetElement);
    133     void clearAttributes();
     132    void clearAttributes(Element*);
    134133
    135134    PassRefPtr<ElementAttributeData> makeMutableCopy() const;
  • trunk/Source/WebCore/dom/Node.h

    r133394 r133451  
    100100typedef int ExceptionCode;
    101101
    102 const int nodeStyleChangeShift = 19;
     102const int nodeStyleChangeShift = 20;
    103103
    104104// SyntheticStyleChange means that we need to go through the entire style change logic even though
     
    238238    bool isShadowRoot() const { return getFlag(IsShadowRootFlag); }
    239239    bool inNamedFlow() const { return getFlag(InNamedFlowFlag); }
     240    bool hasAttrList() const { return getFlag(HasAttrListFlag); }
    240241    bool hasCustomCallbacks() const { return getFlag(HasCustomCallbacksFlag); }
    241 
    242     bool hasSyntheticAttrChildNodes() const { return getFlag(HasSyntheticAttrChildNodesFlag); }
    243     void setHasSyntheticAttrChildNodes(bool flag) { setFlag(flag, HasSyntheticAttrChildNodesFlag); }
    244242
    245243    // If this node is in a shadow tree, returns its shadow host. Otherwise, returns 0.
     
    321319    virtual void startLoadingDynamicSheet() { ASSERT_NOT_REACHED(); }
    322320
     321    bool attributeStyleDirty() const { return getFlag(AttributeStyleDirtyFlag); }
    323322    bool hasName() const { return getFlag(HasNameFlag); }
    324323    bool hasID() const;
     
    336335    bool isLink() const { return getFlag(IsLinkFlag); }
    337336
     337    void setAttributeStyleDirty() { setFlag(AttributeStyleDirtyFlag); }
     338    void clearAttributeStyleDirty() { clearFlag(AttributeStyleDirtyFlag); }
     339
    338340    void setHasName(bool f) { setFlag(f, HasNameFlag); }
    339341    void setChildNeedsStyleRecalc() { setFlag(ChildNeedsStyleRecalcFlag); }
     
    353355    void setInNamedFlow() { setFlag(InNamedFlowFlag); }
    354356    void clearInNamedFlow() { clearFlag(InNamedFlowFlag); }
     357
     358    void setHasAttrList() { setFlag(HasAttrListFlag); }
     359    void clearHasAttrList() { clearFlag(HasAttrListFlag); }
    355360
    356361    bool hasScopedHTMLStyleChild() const { return getFlag(HasScopedHTMLStyleChildFlag); }
     
    708713        // be stored in the same memory word as the Node bits above.
    709714        IsParsingChildrenFinishedFlag = 1 << 15, // Element
     715        IsStyleAttributeValidFlag = 1 << 16, // StyledElement
    710716#if ENABLE(SVG)
    711         AreSVGAttributesValidFlag = 1 << 16, // Element
    712         IsSynchronizingSVGAttributesFlag = 1 << 17, // SVGElement
    713         HasSVGRareDataFlag = 1 << 18, // SVGElement
     717        AreSVGAttributesValidFlag = 1 << 17, // Element
     718        IsSynchronizingSVGAttributesFlag = 1 << 18, // SVGElement
     719        HasSVGRareDataFlag = 1 << 19, // SVGElement
    714720#endif
    715721
    716722        StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
    717723
    718         SelfOrAncestorHasDirAutoFlag = 1 << 21,
    719 
    720         HasNameFlag = 1 << 22,
    721 
     724        SelfOrAncestorHasDirAutoFlag = 1 << 22,
     725
     726        HasNameFlag = 1 << 23,
     727
     728        AttributeStyleDirtyFlag = 1 << 24,
    722729
    723730#if ENABLE(SVG)
    724         DefaultNodeFlags = IsParsingChildrenFinishedFlag | AreSVGAttributesValidFlag,
     731        DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag,
    725732#else
    726         DefaultNodeFlags = IsParsingChildrenFinishedFlag,
    727 #endif
    728         InNamedFlowFlag = 1 << 23,
    729         HasSyntheticAttrChildNodesFlag = 1 << 24,
    730         HasCustomCallbacksFlag = 1 << 25,
    731         HasScopedHTMLStyleChildFlag = 1 << 26,
    732         HasEventTargetDataFlag = 1 << 27,
     733        DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag,
     734#endif
     735        InNamedFlowFlag = 1 << 26,
     736        HasAttrListFlag = 1 << 27,
     737        HasCustomCallbacksFlag = 1 << 28,
     738        HasScopedHTMLStyleChildFlag = 1 << 29,
     739        HasEventTargetDataFlag = 1 << 30,
    733740    };
    734741
    735     // 4 bits remaining
     742    // 2 bits remaining
    736743
    737744    bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
     
    834841    } m_data;
    835842
     843public:
     844    bool isStyleAttributeValid() const { return getFlag(IsStyleAttributeValidFlag); }
     845    void setIsStyleAttributeValid(bool f) { setFlag(f, IsStyleAttributeValidFlag); }
     846    void setIsStyleAttributeValid() const { setFlag(IsStyleAttributeValidFlag); }
     847    void clearIsStyleAttributeValid() { clearFlag(IsStyleAttributeValidFlag); }
     848
    836849protected:
    837850    bool isParsingChildrenFinished() const { return getFlag(IsParsingChildrenFinishedFlag); }
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r133286 r133451  
    127127void StyledElement::updateStyleAttribute() const
    128128{
    129     ASSERT(styleAttributeIsDirty());
    130     ASSERT(attributeData());
    131     attributeData()->setStyleAttributeIsDirty(false);
    132     if (inlineStyle())
    133         const_cast<StyledElement*>(this)->setSynchronizedLazyAttribute(styleAttr, inlineStyle()->asText());
     129    ASSERT(!isStyleAttributeValid());
     130    setIsStyleAttributeValid();
     131    if (const StylePropertySet* inlineStyle = this->inlineStyle())
     132        const_cast<StyledElement*>(this)->setSynchronizedLazyAttribute(styleAttr, inlineStyle->asText());
    134133}
    135134
     
    153152{
    154153    if (isPresentationAttribute(name)) {
    155         attributeData()->setPresentationAttributeStyleIsDirty(true);
     154        setAttributeStyleDirty();
    156155        setNeedsStyleRecalc(InlineStyleChange);
    157156    }
     
    170169        else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber))
    171170            ensureAttributeData()->updateInlineStyleAvoidingMutation(this, newStyleString);
    172 
    173         attributeData()->setStyleAttributeIsDirty(false);
     171        setIsStyleAttributeValid();
    174172    }
    175173    setNeedsStyleRecalc();
     
    188186{
    189187    setNeedsStyleRecalc(InlineStyleChange);
    190     attributeData()->setStyleAttributeIsDirty(true);
     188    setIsStyleAttributeValid(false);
    191189    InspectorInstrumentation::didInvalidateStyleAttr(document(), this);
    192190}
     
    273271}
    274272
    275 void StyledElement::rebuildPresentationAttributeStyle()
     273void StyledElement::updateAttributeStyle()
    276274{
    277275    PresentationAttributeCacheKey cacheKey;
     
    300298        }
    301299    }
    302 
    303     attributeData()->setPresentationAttributeStyleIsDirty(false);
    304     attributeData()->setPresentationAttributeStyle(style->isEmpty() ? 0 : style);
     300    clearAttributeStyleDirty();
     301
     302    attributeData()->setAttributeStyle(style->isEmpty() ? 0 : style);
    305303
    306304    if (!cacheHash || cacheIterator->value)
  • trunk/Source/WebCore/dom/StyledElement.h

    r133286 r133451  
    5252    virtual CSSStyleDeclaration* style() OVERRIDE;
    5353
    54     const StylePropertySet* presentationAttributeStyle();
     54    const StylePropertySet* attributeStyle();
    5555
    5656    virtual void collectStyleForAttribute(const Attribute&, StylePropertySet*) { }
     
    7979
    8080    void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const;
    81     void rebuildPresentationAttributeStyle();
     81    void updateAttributeStyle();
    8282};
    8383
    8484inline void StyledElement::invalidateStyleAttribute()
    8585{
    86     ASSERT(attributeData());
    87     attributeData()->setStyleAttributeIsDirty(true);
     86    clearIsStyleAttributeValid();
    8887}
    8988
    90 inline const StylePropertySet* StyledElement::presentationAttributeStyle()
     89inline const StylePropertySet* StyledElement::attributeStyle()
    9190{
    92     if (!attributeData())
    93         return 0;
    94     if (attributeData()->presentationAttributeStyleIsDirty())
    95         rebuildPresentationAttributeStyle();
    96     return attributeData()->presentationAttributeStyle();
     91    if (attributeStyleDirty())
     92        updateAttributeStyle();
     93    return attributeData() ? attributeData()->attributeStyle() : 0;
    9794}
    9895
  • trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp

    r133286 r133451  
    11851185        return 0;
    11861186
    1187     const StylePropertySet* presentationAttributeStyle = static_cast<StyledElement*>(element)->presentationAttributeStyle();
    1188     if (!presentationAttributeStyle)
     1187    const StylePropertySet* attributeStyle = static_cast<StyledElement*>(element)->attributeStyle();
     1188    if (!attributeStyle)
    11891189        return 0;
    11901190
    1191     RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), const_cast<StylePropertySet*>(presentationAttributeStyle)->ensureCSSStyleDeclaration(), 0);
     1191    RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), const_cast<StylePropertySet*>(attributeStyle)->ensureCSSStyleDeclaration(), 0);
    11921192    return inspectorStyle->buildObjectForStyle();
    11931193}
Note: See TracChangeset for help on using the changeset viewer.