Title: [121603] trunk/Source/WebCore
Revision
121603
Author
[email protected]
Date
2012-06-29 16:56:42 -0700 (Fri, 29 Jun 2012)

Log Message

HTMLCollection's caches should be owned by either ElementRareData or Document
https://bugs.webkit.org/show_bug.cgi?id=90322

Reviewed by Anders Carlsson.

Removed all instances of OwnPtr<HTMLCollection> except ones on ElementRareData and Document.
ElementRareData::ensureCachedHTMLCollection then polymorphically creates HTMLCollection or
its subclass as deemed necessary.

This refactoring allows us to move HTMLCollection to use the same invalidation model as
DynamicNodeList (invalidated during DOM mutations) in a follow up.

* dom/Document.cpp:
(WebCore::Document::all):
* dom/Document.h:
(Document):
* dom/Element.cpp:
(WebCore::ElementRareData::ensureCachedHTMLCollection):
(WebCore):
(WebCore::Element::cachedHTMLCollection):
* dom/Element.h:
(Element):
* dom/ElementRareData.h:
(WebCore):
(ElementRareData):
(WebCore::ElementRareData::cachedHTMLCollection):
* dom/Node.cpp:
(WebCore):
* dom/Node.h:
(Node):
* dom/NodeRareData.h:
(WebCore::NodeRareData::setItemType):
(NodeRareData):
* html/CollectionType.h:
* html/HTMLCollection.cpp:
(WebCore::shouldIncludeChildren):
(WebCore::HTMLCollection::isAcceptableElement):
* html/HTMLElement.cpp:
(WebCore):
(WebCore::HTMLElement::properties):
* html/HTMLElement.h:
(HTMLElement):
* html/HTMLFieldSetElement.cpp:
(WebCore::HTMLFieldSetElement::elements):
* html/HTMLFieldSetElement.h:
(HTMLFieldSetElement):
* html/HTMLFormCollection.cpp:
(WebCore::HTMLFormCollection::HTMLFormCollection):
(WebCore::HTMLFormCollection::create):
* html/HTMLFormCollection.h:
(HTMLFormCollection):
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::elements):
* html/HTMLFormElement.h:
* html/HTMLOptionsCollection.cpp:
(WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
(WebCore::HTMLOptionsCollection::create):
* html/HTMLOptionsCollection.h:
(HTMLOptionsCollection):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::selectedOptions):
(WebCore::HTMLSelectElement::options):
(WebCore::HTMLSelectElement::invalidateSelectedItems):
(WebCore::HTMLSelectElement::setRecalcListItems):
* html/HTMLSelectElement.h:
* html/HTMLTableElement.cpp:
(WebCore::HTMLTableElement::rows):
* html/HTMLTableElement.h:
* html/HTMLTableRowsCollection.cpp:
(WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
(WebCore::HTMLTableRowsCollection::create):
* html/HTMLTableRowsCollection.h:
(HTMLTableRowsCollection):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121602 => 121603)


--- trunk/Source/WebCore/ChangeLog	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/ChangeLog	2012-06-29 23:56:42 UTC (rev 121603)
@@ -1,3 +1,79 @@
+2012-06-29  Ryosuke Niwa  <[email protected]>
+
+        HTMLCollection's caches should be owned by either ElementRareData or Document
+        https://bugs.webkit.org/show_bug.cgi?id=90322
+
+        Reviewed by Anders Carlsson.
+
+        Removed all instances of OwnPtr<HTMLCollection> except ones on ElementRareData and Document.
+        ElementRareData::ensureCachedHTMLCollection then polymorphically creates HTMLCollection or
+        its subclass as deemed necessary.
+
+        This refactoring allows us to move HTMLCollection to use the same invalidation model as
+        DynamicNodeList (invalidated during DOM mutations) in a follow up.
+
+        * dom/Document.cpp:
+        (WebCore::Document::all):
+        * dom/Document.h:
+        (Document):
+        * dom/Element.cpp:
+        (WebCore::ElementRareData::ensureCachedHTMLCollection):
+        (WebCore):
+        (WebCore::Element::cachedHTMLCollection):
+        * dom/Element.h:
+        (Element):
+        * dom/ElementRareData.h:
+        (WebCore):
+        (ElementRareData):
+        (WebCore::ElementRareData::cachedHTMLCollection):
+        * dom/Node.cpp:
+        (WebCore):
+        * dom/Node.h:
+        (Node):
+        * dom/NodeRareData.h:
+        (WebCore::NodeRareData::setItemType):
+        (NodeRareData):
+        * html/CollectionType.h:
+        * html/HTMLCollection.cpp:
+        (WebCore::shouldIncludeChildren):
+        (WebCore::HTMLCollection::isAcceptableElement):
+        * html/HTMLElement.cpp:
+        (WebCore):
+        (WebCore::HTMLElement::properties):
+        * html/HTMLElement.h:
+        (HTMLElement):
+        * html/HTMLFieldSetElement.cpp:
+        (WebCore::HTMLFieldSetElement::elements):
+        * html/HTMLFieldSetElement.h:
+        (HTMLFieldSetElement):
+        * html/HTMLFormCollection.cpp:
+        (WebCore::HTMLFormCollection::HTMLFormCollection):
+        (WebCore::HTMLFormCollection::create):
+        * html/HTMLFormCollection.h:
+        (HTMLFormCollection):
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::elements):
+        * html/HTMLFormElement.h:
+        * html/HTMLOptionsCollection.cpp:
+        (WebCore::HTMLOptionsCollection::HTMLOptionsCollection):
+        (WebCore::HTMLOptionsCollection::create):
+        * html/HTMLOptionsCollection.h:
+        (HTMLOptionsCollection):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::selectedOptions):
+        (WebCore::HTMLSelectElement::options):
+        (WebCore::HTMLSelectElement::invalidateSelectedItems):
+        (WebCore::HTMLSelectElement::setRecalcListItems):
+        * html/HTMLSelectElement.h:
+        * html/HTMLTableElement.cpp:
+        (WebCore::HTMLTableElement::rows):
+        * html/HTMLTableElement.h:
+        * html/HTMLTableRowsCollection.cpp:
+        (WebCore::HTMLTableRowsCollection::HTMLTableRowsCollection):
+        (WebCore::HTMLTableRowsCollection::create):
+        * html/HTMLTableRowsCollection.h:
+        (HTMLTableRowsCollection):
+
 2012-06-29  Ojan Vafai  <[email protected]>
 
         Add FIXMEs for vertical writing mode and override sizes.

Modified: trunk/Source/WebCore/dom/Document.cpp (121602 => 121603)


--- trunk/Source/WebCore/dom/Document.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -4745,9 +4745,9 @@
 
 HTMLAllCollection* Document::all()
 {
-    if (!m_allCollection)
-        m_allCollection = HTMLAllCollection::create(this);
-    return m_allCollection.get();
+    if (!m_collections[DocAll])
+        m_collections[DocAll] = HTMLAllCollection::create(this);
+    return static_cast<HTMLAllCollection*>(m_collections[DocAll].get());
 }
 
 HTMLCollection* Document::windowNamedItems(const AtomicString& name)

Modified: trunk/Source/WebCore/dom/Document.h (121602 => 121603)


--- trunk/Source/WebCore/dom/Document.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Document.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -1396,7 +1396,6 @@
     InheritedBool m_designMode;
     
     OwnPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];
-    OwnPtr<HTMLAllCollection> m_allCollection;
     HashSet<DynamicSubtreeNodeList*> m_listsInvalidatedAtDocument;
 
     typedef HashMap<AtomicStringImpl*, OwnPtr<HTMLNameCollection> > NamedCollectionMap;

Modified: trunk/Source/WebCore/dom/Element.cpp (121602 => 121603)


--- trunk/Source/WebCore/dom/Element.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -46,9 +46,12 @@
 #include "HTMLCollection.h"
 #include "HTMLDocument.h"
 #include "HTMLElement.h"
+#include "HTMLFormCollection.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLNames.h"
+#include "HTMLOptionsCollection.h"
 #include "HTMLParserIdioms.h"
+#include "HTMLTableRowsCollection.h"
 #include "InspectorInstrumentation.h"
 #include "MutationObserverInterestGroup.h"
 #include "MutationRecord.h"
@@ -2044,6 +2047,37 @@
     return ensureElementRareData()->ensureCachedHTMLCollection(this, type);
 }
 
+HTMLCollection* ElementRareData::ensureCachedHTMLCollection(Element* element, CollectionType type)
+{
+    if (!m_cachedCollections)
+        m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
+    
+    OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
+    if (!collection) {
+        if (type == TableRows) {
+            ASSERT(element->hasTagName(tableTag));
+            collection = HTMLTableRowsCollection::create(element);
+        } else if (type == SelectOptions) {
+            ASSERT(element->hasTagName(selectTag));
+            collection = HTMLOptionsCollection::create(element);
+        } else if (type == FormControls) {
+            ASSERT(element->hasTagName(formTag) || element->hasTagName(fieldsetTag));
+            collection = HTMLFormCollection::create(element);
+#if ENABLE(MICRODATA)
+        } else if (type == ItemProperties) {
+            collection = HTMLPropertiesCollection::create(element);
+#endif
+        } else
+            collection = HTMLCollection::create(element, type);
+    }
+    return collection.get();
+}
+
+HTMLCollection* Element::cachedHTMLCollection(CollectionType type)
+{
+    return hasRareData() ? elementRareData()->cachedHTMLCollection(type) : 0;
+}
+
 IntSize Element::savedLayerScrollOffset() const
 {
     return hasRareData() ? elementRareData()->m_savedLayerScrollOffset : IntSize();

Modified: trunk/Source/WebCore/dom/Element.h (121602 => 121603)


--- trunk/Source/WebCore/dom/Element.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Element.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -448,6 +448,7 @@
     virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
 
     HTMLCollection* ensureCachedHTMLCollection(CollectionType);
+    HTMLCollection* cachedHTMLCollection(CollectionType);
 
 private:
     void updateInvalidAttributes() const;

Modified: trunk/Source/WebCore/dom/ElementRareData.h (121602 => 121603)


--- trunk/Source/WebCore/dom/ElementRareData.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/ElementRareData.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -26,13 +26,14 @@
 #include "DatasetDOMStringMap.h"
 #include "Element.h"
 #include "ElementShadow.h"
-#include "HTMLCollection.h"
 #include "NamedNodeMap.h"
 #include "NodeRareData.h"
 #include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
+class HTMLCollection;
+
 class ElementRareData : public NodeRareData {
 public:
     ElementRareData();
@@ -50,15 +51,13 @@
         return m_cachedCollections;
     }
 
-    HTMLCollection* ensureCachedHTMLCollection(Element* element, CollectionType type)
+    HTMLCollection* ensureCachedHTMLCollection(Element*, CollectionType);
+    HTMLCollection* cachedHTMLCollection(CollectionType type)
     {
         if (!m_cachedCollections)
-            m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray);
+            return 0;
 
-        OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];
-        if (!collection)
-            collection = HTMLCollection::create(element, type);
-        return collection.get();
+        return (*m_cachedCollections)[type - FirstNodeCollectionType].get();
     }
 
     OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;

Modified: trunk/Source/WebCore/dom/Node.cpp (121602 => 121603)


--- trunk/Source/WebCore/dom/Node.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Node.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -2778,10 +2778,6 @@
     ensureRareData()->setItemType(value);
 }
 
-HTMLPropertiesCollection* Node::properties()
-{
-    return ensureRareData()->properties(this);
-}
 #endif
 
 void NodeRareData::createNodeLists(Node* node)

Modified: trunk/Source/WebCore/dom/Node.h (121602 => 121603)


--- trunk/Source/WebCore/dom/Node.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/Node.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -630,7 +630,6 @@
     DOMSettableTokenList* itemProp();
     DOMSettableTokenList* itemRef();
     DOMSettableTokenList* itemType();
-    HTMLPropertiesCollection* properties();
 #endif
 
 #if ENABLE(MUTATION_OBSERVERS)

Modified: trunk/Source/WebCore/dom/NodeRareData.h (121602 => 121603)


--- trunk/Source/WebCore/dom/NodeRareData.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/dom/NodeRareData.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -305,14 +305,6 @@
 
         m_itemType->setValue(value);
     }
-
-    HTMLPropertiesCollection* properties(Node* node)
-    {
-        if (!m_properties)
-            m_properties = HTMLPropertiesCollection::create(node);
-
-        return m_properties.get();
-    }
 #endif
 
 #if ENABLE(STYLE_SCOPED)
@@ -368,7 +360,6 @@
     mutable RefPtr<DOMSettableTokenList> m_itemProp;
     mutable RefPtr<DOMSettableTokenList> m_itemRef;
     mutable RefPtr<DOMSettableTokenList> m_itemType;
-    mutable OwnPtr<HTMLPropertiesCollection> m_properties;
 #endif
 
 #if ENABLE(STYLE_SCOPED)

Modified: trunk/Source/WebCore/html/CollectionType.h (121602 => 121603)


--- trunk/Source/WebCore/html/CollectionType.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/CollectionType.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -49,6 +49,7 @@
     NodeChildren, // first-level children (IE)
     TableTBodies, // all <tbody> elements in this table
     TSectionRows, // all row elements in this table section
+    TableRows,
     TRCells,      // all cells in this row
     SelectOptions,
     SelectedOptions,
@@ -59,15 +60,14 @@
     ItemProperties, // Microdata item properties in the document
 #endif
 
-    FormControls,
-    OtherCollection
+    FormControls
 };
 
 static const CollectionType FirstUnnamedDocumentCachedType = DocImages;
 static const unsigned NumUnnamedDocumentCachedTypes = WindowNamedItems - DocImages + 1;
 
 static const CollectionType FirstNodeCollectionType = NodeChildren;
-static const unsigned NumNodeCollectionTypes = OtherCollection - NodeChildren + 1;
+static const unsigned NumNodeCollectionTypes = FormControls - NodeChildren + 1;
 
 } // namespace
 

Modified: trunk/Source/WebCore/html/HTMLCollection.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLCollection.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLCollection.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -50,7 +50,7 @@
     case DocScripts:
     case DocumentNamedItems:
     case MapAreas:
-    case OtherCollection:
+    case TableRows:
     case SelectOptions:
     case SelectedOptions:
     case DataListOptions:
@@ -151,7 +151,7 @@
 #endif
     case FormControls:
     case DocumentNamedItems:
-    case OtherCollection:
+    case TableRows:
     case WindowNamedItems:
         ASSERT_NOT_REACHED();
     }

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -987,6 +987,11 @@
 {
     setTextContent(value, ec);
 }
+
+HTMLPropertiesCollection* HTMLElement::properties()
+{
+    return ensureCachedHTMLCollection(ItemProperties);
+}
 #endif
 
 void HTMLElement::addHTMLLengthToStyle(StylePropertySet* style, CSSPropertyID propertyID, const String& value)

Modified: trunk/Source/WebCore/html/HTMLElement.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLElement.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLElement.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -96,6 +96,7 @@
 #if ENABLE(MICRODATA)
     void setItemValue(const String&, ExceptionCode&);
     PassRefPtr<MicroDataItemValue> itemValue() const;
+    HTMLPropertiesCollection* properties();
 #endif
 
 #ifndef NDEBUG

Modified: trunk/Source/WebCore/html/HTMLFieldSetElement.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFieldSetElement.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFieldSetElement.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -99,9 +99,7 @@
 
 HTMLCollection* HTMLFieldSetElement::elements()
 {
-    if (!m_elementsCollection)
-        m_elementsCollection = HTMLFormCollection::create(this);
-    return m_elementsCollection.get();
+    return ensureCachedHTMLCollection(FormControls);
 }
 
 void HTMLFieldSetElement::refreshElementsIfNeeded() const

Modified: trunk/Source/WebCore/html/HTMLFieldSetElement.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFieldSetElement.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFieldSetElement.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -59,7 +59,6 @@
     static void invalidateDisabledStateUnder(Element*);
     void refreshElementsIfNeeded() const;
 
-    OwnPtr<HTMLFormCollection> m_elementsCollection;
     mutable Vector<FormAssociatedElement*> m_associatedElements;
     // When dom tree is modified, we have to refresh the m_associatedElements array.
     mutable uint64_t m_documentVersion;

Modified: trunk/Source/WebCore/html/HTMLFormCollection.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFormCollection.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -36,12 +36,13 @@
 // Since the collections are to be "live", we have to do the
 // calculation every time if anything has changed.
 
-HTMLFormCollection::HTMLFormCollection(HTMLElement* base)
+HTMLFormCollection::HTMLFormCollection(Element* base)
     : HTMLCollection(base, FormControls)
 {
+    ASSERT(base->hasTagName(formTag) || base->hasTagName(fieldsetTag));
 }
 
-PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLElement* base)
+PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(Element* base)
 {
     return adoptPtr(new HTMLFormCollection(base));
 }

Modified: trunk/Source/WebCore/html/HTMLFormCollection.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFormCollection.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFormCollection.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -36,7 +36,7 @@
 
 class HTMLFormCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLFormCollection> create(HTMLElement*);
+    static PassOwnPtr<HTMLFormCollection> create(Element*);
 
     virtual ~HTMLFormCollection();
 
@@ -44,7 +44,7 @@
     virtual Node* namedItem(const AtomicString& name) const;
 
 private:
-    HTMLFormCollection(HTMLElement*);
+    HTMLFormCollection(Element*);
 
     virtual void updateNameCache() const;
     virtual unsigned calcLength() const;

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -537,9 +537,7 @@
 
 HTMLCollection* HTMLFormElement::elements()
 {
-    if (!m_elementsCollection)
-        m_elementsCollection = HTMLFormCollection::create(this);
-    return m_elementsCollection.get();
+    return ensureCachedHTMLCollection(FormControls);
 }
 
 String HTMLFormElement::name() const

Modified: trunk/Source/WebCore/html/HTMLFormElement.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLFormElement.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLFormElement.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -150,7 +150,6 @@
 
     FormSubmission::Attributes m_attributes;
     OwnPtr<AliasMap> m_elementAliases;
-    OwnPtr<HTMLFormCollection> m_elementsCollection;
 
     CheckedRadioButtons m_checkedRadioButtons;
 

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -27,12 +27,13 @@
 
 namespace WebCore {
 
-HTMLOptionsCollection::HTMLOptionsCollection(HTMLSelectElement* select)
+HTMLOptionsCollection::HTMLOptionsCollection(Element* select)
     : HTMLCollection(select, SelectOptions)
 {
+    ASSERT(select->hasTagName(HTMLNames::selectTag));
 }
 
-PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)
+PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(Element* select)
 {
     return adoptPtr(new HTMLOptionsCollection(select));
 }

Modified: trunk/Source/WebCore/html/HTMLOptionsCollection.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLOptionsCollection.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLOptionsCollection.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -35,7 +35,7 @@
 
 class HTMLOptionsCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLOptionsCollection> create(HTMLSelectElement*);
+    static PassOwnPtr<HTMLOptionsCollection> create(Element*);
 
     void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
     void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
@@ -49,7 +49,7 @@
     using HTMLCollection::invalidateCacheIfNeeded;
 
 private:
-    HTMLOptionsCollection(HTMLSelectElement*);
+    HTMLOptionsCollection(Element*);
 };
 
 } //namespace

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -352,16 +352,12 @@
 
 HTMLCollection* HTMLSelectElement::selectedOptions()
 {
-    if (!m_selectedOptionsCollection)
-        m_selectedOptionsCollection = HTMLCollection::create(this, SelectedOptions);
-    return m_selectedOptionsCollection.get();
+    return ensureCachedHTMLCollection(SelectedOptions);
 }
 
 HTMLOptionsCollection* HTMLSelectElement::options()
 {
-    if (!m_optionsCollection)
-        m_optionsCollection = HTMLOptionsCollection::create(this);
-    return m_optionsCollection.get();
+    return static_cast<HTMLOptionsCollection*>(ensureCachedHTMLCollection(SelectOptions));
 }
 
 void HTMLSelectElement::updateListItemSelectedStates()
@@ -709,8 +705,8 @@
 
 void HTMLSelectElement::invalidateSelectedItems()
 {
-    if (m_selectedOptionsCollection)
-        m_selectedOptionsCollection->invalidateCache();
+    if (HTMLCollection* collection = cachedHTMLCollection(SelectedOptions))
+        collection->invalidateCache();
 }
 
 void HTMLSelectElement::setRecalcListItems()
@@ -720,10 +716,12 @@
     m_activeSelectionAnchorIndex = -1;
     setOptionsChangedOnRenderer();
     setNeedsStyleRecalc();
-    if (!inDocument() && m_optionsCollection)
-        m_optionsCollection->invalidateCacheIfNeeded();
-    if (!inDocument() && m_selectedOptionsCollection)
-        m_selectedOptionsCollection->invalidateCacheIfNeeded();
+    if (!inDocument()) {
+        if (HTMLCollection* collection = cachedHTMLCollection(SelectOptions))
+            collection->invalidateCache();
+    }
+    if (!inDocument())
+        invalidateSelectedItems();
 }
 
 void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const

Modified: trunk/Source/WebCore/html/HTMLSelectElement.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLSelectElement.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLSelectElement.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -180,9 +180,6 @@
 
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
 
-    OwnPtr<HTMLOptionsCollection> m_optionsCollection;
-    OwnPtr<HTMLCollection> m_selectedOptionsCollection;
-
     // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects.
     mutable Vector<HTMLElement*> m_listItems;
     Vector<bool> m_lastOnChangeSelection;

Modified: trunk/Source/WebCore/html/HTMLTableElement.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLTableElement.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -562,9 +562,7 @@
 
 HTMLCollection* HTMLTableElement::rows()
 {
-    if (!m_rowsCollection)
-        m_rowsCollection = HTMLTableRowsCollection::create(this);
-    return m_rowsCollection.get();
+    return ensureCachedHTMLCollection(TableRows);
 }
 
 HTMLCollection* HTMLTableElement::tBodies()

Modified: trunk/Source/WebCore/html/HTMLTableElement.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLTableElement.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLTableElement.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -97,7 +97,6 @@
                                 // are present, to none otherwise).
 
     unsigned short m_padding;
-    OwnPtr<HTMLTableRowsCollection> m_rowsCollection;
     RefPtr<StylePropertySet> m_sharedCellStyle;
 };
 

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp	2012-06-29 23:56:42 UTC (rev 121603)
@@ -151,12 +151,13 @@
 // Must call get() on the table in case that argument is compiled before dereferencing the
 // table to get at the collection cache. Order of argument evaluation is undefined and can
 // differ between compilers.
-HTMLTableRowsCollection::HTMLTableRowsCollection(HTMLTableElement* table)
-    : HTMLCollection(table, OtherCollection)
+HTMLTableRowsCollection::HTMLTableRowsCollection(Element* table)
+    : HTMLCollection(table, TableRows)
 {
+    ASSERT(table->hasTagName(tableTag));
 }
 
-PassOwnPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement* table)
+PassOwnPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(Element* table)
 {
     return adoptPtr(new HTMLTableRowsCollection(table));
 }

Modified: trunk/Source/WebCore/html/HTMLTableRowsCollection.h (121602 => 121603)


--- trunk/Source/WebCore/html/HTMLTableRowsCollection.h	2012-06-29 23:49:22 UTC (rev 121602)
+++ trunk/Source/WebCore/html/HTMLTableRowsCollection.h	2012-06-29 23:56:42 UTC (rev 121603)
@@ -38,13 +38,13 @@
 
 class HTMLTableRowsCollection : public HTMLCollection {
 public:
-    static PassOwnPtr<HTMLTableRowsCollection> create(HTMLTableElement*);
+    static PassOwnPtr<HTMLTableRowsCollection> create(Element*);
 
     static HTMLTableRowElement* rowAfter(HTMLTableElement*, HTMLTableRowElement*);
     static HTMLTableRowElement* lastRow(HTMLTableElement*);
 
 private:
-    HTMLTableRowsCollection(HTMLTableElement*);
+    HTMLTableRowsCollection(Element*);
 
     virtual Element* itemAfter(Node*) const OVERRIDE;
 };
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to