Changeset 104383 in webkit
- Timestamp:
- Jan 7, 2012 1:35:21 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r104381 r104383 1 2012-01-07 Andreas Kling <awesomekling@apple.com> 2 3 Simplify HTMLCollection ownership model. 4 <http://webkit.org/b/75437> 5 6 Reviewed by Sam Weinig. 7 8 - Removed fast/dom/htmlcollection-zombies.html since it was testing bogus behavior. 9 - Added a test to verify that HTMLCollection protects its base node from GC. 10 11 * fast/dom/htmlcollection-protects-base-expected.txt: Added. 12 * fast/dom/htmlcollection-protects-base.html: Added. 13 * fast/dom/htmlcollection-zombies-expected.txt: Removed. 14 * fast/dom/htmlcollection-zombies.html: Removed. 15 1 16 2012-01-06 Ryosuke Niwa <rniwa@webkit.org> 2 17 -
trunk/Source/WebCore/ChangeLog
r104382 r104383 1 2012-01-07 Andreas Kling <awesomekling@apple.com> 2 3 Simplify HTMLCollection ownership model. 4 <http://webkit.org/b/75437> 5 6 Reviewed by Sam Weinig. 7 8 Remove HTMLCollection's inheritance from RefCounted and use OwnPtr to store it. 9 Added ref()/deref() methods that forward to the collection's base node, these 10 are only ever used by DOM wrappers. 11 12 This is a behavior change, HTMLCollection wrappers now keep the base node alive. 13 14 Test: fast/dom/htmlcollection-protects-base.html 15 16 * html/HTMLCollection.h: 17 (WebCore::HTMLCollection::ref): 18 (WebCore::HTMLCollection::deref): 19 20 Removed inheritance from RefCounted. Added ref/deref that forward the refs 21 to the collection's base Node. 22 23 * dom/Element.cpp: 24 (WebCore::Element::~Element): 25 * dom/Document.h: 26 * dom/Document.cpp: 27 (WebCore::Document::~Document): 28 * html/HTMLFormElement.cpp: 29 (WebCore::HTMLFormElement::~HTMLFormElement): 30 * html/HTMLSelectElement.h: 31 * html/HTMLSelectElement.cpp: 32 33 Remove HTMLCollection::detachFromNode() and call sites. 34 35 * html/HTMLAllCollection.cpp: 36 (WebCore::HTMLAllCollection::namedItemWithIndex): 37 * html/HTMLCollection.cpp: 38 (WebCore::HTMLCollection::HTMLCollection): 39 (WebCore::HTMLCollection::invalidateCacheIfNeeded): 40 (WebCore::HTMLCollection::itemAfter): 41 (WebCore::HTMLCollection::calcLength): 42 (WebCore::HTMLCollection::length): 43 (WebCore::HTMLCollection::item): 44 (WebCore::HTMLCollection::nextItem): 45 (WebCore::HTMLCollection::namedItem): 46 (WebCore::HTMLCollection::updateNameCache): 47 (WebCore::HTMLCollection::hasNamedItem): 48 (WebCore::HTMLCollection::namedItems): 49 (WebCore::HTMLCollection::tags): 50 * html/HTMLFormCollection.cpp: 51 (WebCore::HTMLFormCollection::calcLength): 52 (WebCore::HTMLFormCollection::item): 53 (WebCore::HTMLFormCollection::getNamedItem): 54 (WebCore::HTMLFormCollection::namedItem): 55 (WebCore::HTMLFormCollection::updateNameCache): 56 * html/HTMLNameCollection.cpp: 57 (WebCore::HTMLNameCollection::itemAfter): 58 * html/HTMLOptionsCollection.cpp: 59 (WebCore::HTMLOptionsCollection::add): 60 (WebCore::HTMLOptionsCollection::remove): 61 (WebCore::HTMLOptionsCollection::selectedIndex): 62 (WebCore::HTMLOptionsCollection::setSelectedIndex): 63 (WebCore::HTMLOptionsCollection::setLength): 64 * html/HTMLPropertiesCollection.cpp: 65 (WebCore::HTMLPropertiesCollection::length): 66 (WebCore::HTMLPropertiesCollection::item): 67 (WebCore::HTMLPropertiesCollection::names): 68 69 Removed base node null-checks and assertions. Added one assertion to 70 the HTMLCollection constructor (that m_base is non-null.) 71 72 * dom/Document.h: 73 * dom/Document.cpp: 74 (WebCore::Document::openSearchDescriptionURL): 75 (WebCore::Document::cachedCollection): 76 (WebCore::Document::images): 77 (WebCore::Document::applets): 78 (WebCore::Document::embeds): 79 (WebCore::Document::plugins): 80 (WebCore::Document::objects): 81 (WebCore::Document::scripts): 82 (WebCore::Document::links): 83 (WebCore::Document::forms): 84 (WebCore::Document::anchors): 85 (WebCore::Document::all): 86 (WebCore::Document::windowNamedItems): 87 (WebCore::Document::documentNamedItems): 88 * bindings/js/JSDOMWindowCustom.cpp: 89 (WebCore::namedItemGetter): 90 * bindings/js/JSHTMLDocumentCustom.cpp: 91 (WebCore::JSHTMLDocument::nameGetter): 92 (WebCore::JSHTMLDocument::all): 93 * bindings/v8/custom/V8DOMWindowCustom.cpp: 94 (WebCore::V8DOMWindow::namedPropertyGetter): 95 * bindings/v8/custom/V8HTMLDocumentCustom.cpp: 96 (WebCore::V8HTMLDocument::GetNamedProperty): 97 * dom/ElementRareData.h: 98 (WebCore::ElementRareData::ensureCachedHTMLCollection): 99 * dom/NodeRareData.h: 100 (WebCore::NodeRareData::properties): 101 * html/HTMLAllCollection.h: 102 * html/HTMLAllCollection.cpp: 103 (WebCore::HTMLAllCollection::create): 104 * html/HTMLCollection.h: 105 * html/HTMLCollection.cpp: 106 (WebCore::HTMLCollection::create): 107 (WebCore::HTMLCollection::HTMLCollection): 108 * html/HTMLDataListElement.cpp: 109 (WebCore::HTMLDataListElement::options): 110 * html/HTMLDataListElement.h: 111 * html/HTMLElement.cpp: 112 (WebCore::HTMLElement::children): 113 * html/HTMLElement.h: 114 * html/HTMLSelectElement.h: 115 (WebCore::HTMLSelectElement::options): 116 * html/HTMLFormCollection.h: 117 * html/HTMLFormElement.h: 118 * html/HTMLFormElement.cpp: 119 (WebCore::HTMLFormElement::elements): 120 * html/HTMLNameCollection.h: 121 (WebCore::HTMLNameCollection::create): 122 * html/HTMLFormCollection.cpp: 123 (WebCore::HTMLFormCollection::create): 124 * html/HTMLMapElement.cpp: 125 (WebCore::HTMLMapElement::imageElement): 126 (WebCore::HTMLMapElement::areas): 127 * html/HTMLMapElement.h: 128 * html/HTMLPropertiesCollection.h: 129 * html/HTMLTableElement.cpp: 130 (WebCore::HTMLTableElement::rows): 131 (WebCore::HTMLTableElement::tBodies): 132 * html/HTMLTableElement.h: 133 * html/HTMLTableRowElement.cpp: 134 (WebCore::HTMLTableRowElement::insertCell): 135 (WebCore::HTMLTableRowElement::deleteCell): 136 (WebCore::HTMLTableRowElement::cells): 137 * html/HTMLTableRowElement.h: 138 * html/HTMLTableRowsCollection.cpp: 139 (WebCore::HTMLTableRowsCollection::create): 140 (WebCore::HTMLTableRowsCollection::itemAfter): 141 * html/HTMLTableRowsCollection.h: 142 * html/HTMLTableSectionElement.h: 143 * html/HTMLTableSectionElement.cpp: 144 (WebCore::HTMLTableSectionElement::insertRow): 145 (WebCore::HTMLTableSectionElement::deleteRow): 146 (WebCore::HTMLTableSectionElement::rows): 147 * html/HTMLInputElement.cpp: 148 (WebCore::HTMLInputElement::selectedOption): 149 * html/HTMLOptionsCollection.h: 150 * html/HTMLOptionsCollection.cpp: 151 (WebCore::HTMLOptionsCollection::create): 152 * html/HTMLPropertiesCollection.cpp: 153 (WebCore::HTMLPropertiesCollection::create): 154 * Source/WebCore/accessibility/AccessibilityRenderObject.cpp: 155 (WebCore::AccessibilityRenderObject::getDocumentLinks): 156 157 Store cached HTMLCollections in OwnPtrs. Methods that used to return 158 PassRefPtr<HTMLCollection> now simply return HTMLCollection*. 159 Updated call sites as appropriate. 160 1 161 2012-01-07 Adam Barth <abarth@webkit.org> 2 162 -
trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp
r104276 r104383 2401 2401 { 2402 2402 Document* document = m_renderer->document(); 2403 RefPtr<HTMLCollection>coll = document->links();2403 HTMLCollection* coll = document->links(); 2404 2404 Node* curr = coll->firstItem(); 2405 2405 while (curr) { -
trunk/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp
r104376 r104383 116 116 ASSERT(document->isHTMLDocument()); 117 117 118 RefPtr<HTMLCollection>collection = document->windowNamedItems(identifierToAtomicString(propertyName));118 HTMLCollection* collection = document->windowNamedItems(identifierToAtomicString(propertyName)); 119 119 if (collection->length() == 1) 120 120 return toJS(exec, thisObj, collection->firstItem()); 121 return toJS(exec, thisObj, collection .get());121 return toJS(exec, thisObj, collection); 122 122 } 123 123 -
trunk/Source/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
r104376 r104383 62 62 HTMLDocument* document = static_cast<HTMLDocument*>(thisObj->impl()); 63 63 64 RefPtr<HTMLCollection>collection = document->documentNamedItems(identifierToAtomicString(propertyName));64 HTMLCollection* collection = document->documentNamedItems(identifierToAtomicString(propertyName)); 65 65 66 66 unsigned length = collection->length(); … … 78 78 } 79 79 80 return toJS(exec, thisObj->globalObject(), collection .get());80 return toJS(exec, thisObj->globalObject(), collection); 81 81 } 82 82 … … 90 90 return v; 91 91 92 return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all() .get());92 return toJS(exec, globalObject(), static_cast<HTMLDocument*>(impl())->all()); 93 93 } 94 94 -
trunk/Source/WebCore/bindings/v8/custom/V8DOMWindowCustom.cpp
r104376 r104383 513 513 if (doc && doc->isHTMLDocument()) { 514 514 if (static_cast<HTMLDocument*>(doc)->hasNamedItem(propName.impl()) || doc->hasElementWithId(propName.impl())) { 515 RefPtr<HTMLCollection>items = doc->windowNamedItems(propName);515 HTMLCollection* items = doc->windowNamedItems(propName); 516 516 if (items->length() >= 1) { 517 517 if (items->length() == 1) 518 518 return toV8(items->firstItem()); 519 return toV8(items .release());519 return toV8(items); 520 520 } 521 521 } -
trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp
r104376 r104383 80 80 return v8::Handle<v8::Value>(); 81 81 82 RefPtr<HTMLCollection>items = htmlDocument->documentNamedItems(key);82 HTMLCollection* items = htmlDocument->documentNamedItems(key); 83 83 if (!items->length()) 84 84 return v8::Handle<v8::Value>(); … … 93 93 } 94 94 95 return toV8(items .release());95 return toV8(items); 96 96 } 97 97 -
trunk/Source/WebCore/dom/Document.cpp
r104376 r104383 568 568 if (m_mediaQueryMatcher) 569 569 m_mediaQueryMatcher->documentDestroyed(); 570 571 for (unsigned i = 0; i < NumUnnamedDocumentCachedTypes; ++i) {572 if (m_collections[i])573 m_collections[i]->detachFromNode();574 }575 576 if (m_allCollection)577 m_allCollection->detachFromNode();578 570 } 579 571 … … 4177 4169 return KURL(); 4178 4170 4179 RefPtr<HTMLCollection>children = head()->children();4171 HTMLCollection* children = head()->children(); 4180 4172 for (Node* child = children->firstItem(); child; child = children->nextItem()) { 4181 4173 if (!child->hasTagName(linkTag)) … … 4302 4294 #endif 4303 4295 4304 const RefPtr<HTMLCollection>&Document::cachedCollection(CollectionType type)4296 HTMLCollection* Document::cachedCollection(CollectionType type) 4305 4297 { 4306 4298 ASSERT(static_cast<unsigned>(type) < NumUnnamedDocumentCachedTypes); 4307 4299 if (!m_collections[type]) 4308 4300 m_collections[type] = HTMLCollection::create(this, type); 4309 return m_collections[type] ;4310 } 4311 4312 PassRefPtr<HTMLCollection>Document::images()4301 return m_collections[type].get(); 4302 } 4303 4304 HTMLCollection* Document::images() 4313 4305 { 4314 4306 return cachedCollection(DocImages); 4315 4307 } 4316 4308 4317 PassRefPtr<HTMLCollection>Document::applets()4309 HTMLCollection* Document::applets() 4318 4310 { 4319 4311 return cachedCollection(DocApplets); 4320 4312 } 4321 4313 4322 PassRefPtr<HTMLCollection>Document::embeds()4314 HTMLCollection* Document::embeds() 4323 4315 { 4324 4316 return cachedCollection(DocEmbeds); 4325 4317 } 4326 4318 4327 PassRefPtr<HTMLCollection>Document::plugins()4319 HTMLCollection* Document::plugins() 4328 4320 { 4329 4321 // This is an alias for embeds() required for the JS DOM bindings. … … 4331 4323 } 4332 4324 4333 PassRefPtr<HTMLCollection>Document::objects()4325 HTMLCollection* Document::objects() 4334 4326 { 4335 4327 return cachedCollection(DocObjects); 4336 4328 } 4337 4329 4338 PassRefPtr<HTMLCollection>Document::scripts()4330 HTMLCollection* Document::scripts() 4339 4331 { 4340 4332 return cachedCollection(DocScripts); 4341 4333 } 4342 4334 4343 PassRefPtr<HTMLCollection>Document::links()4335 HTMLCollection* Document::links() 4344 4336 { 4345 4337 return cachedCollection(DocLinks); 4346 4338 } 4347 4339 4348 PassRefPtr<HTMLCollection>Document::forms()4340 HTMLCollection* Document::forms() 4349 4341 { 4350 4342 return cachedCollection(DocForms); 4351 4343 } 4352 4344 4353 PassRefPtr<HTMLCollection>Document::anchors()4345 HTMLCollection* Document::anchors() 4354 4346 { 4355 4347 return cachedCollection(DocAnchors); 4356 4348 } 4357 4349 4358 PassRefPtr<HTMLAllCollection>Document::all()4350 HTMLAllCollection* Document::all() 4359 4351 { 4360 4352 if (!m_allCollection) 4361 4353 m_allCollection = HTMLAllCollection::create(this); 4362 return m_allCollection ;4363 } 4364 4365 PassRefPtr<HTMLCollection>Document::windowNamedItems(const AtomicString& name)4366 { 4367 RefPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), 0).first->second;4354 return m_allCollection.get(); 4355 } 4356 4357 HTMLCollection* Document::windowNamedItems(const AtomicString& name) 4358 { 4359 OwnPtr<HTMLNameCollection>& collection = m_windowNamedItemCollections.add(name.impl(), nullptr).first->second; 4368 4360 if (!collection) 4369 4361 collection = HTMLNameCollection::create(this, WindowNamedItems, name); 4370 return collection ;4371 } 4372 4373 PassRefPtr<HTMLCollection>Document::documentNamedItems(const AtomicString& name)4374 { 4375 RefPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), 0).first->second;4362 return collection.get(); 4363 } 4364 4365 HTMLCollection* Document::documentNamedItems(const AtomicString& name) 4366 { 4367 OwnPtr<HTMLNameCollection>& collection = m_documentNamedItemCollections.add(name.impl(), nullptr).first->second; 4376 4368 if (!collection) 4377 4369 collection = HTMLNameCollection::create(this, DocumentNamedItems, name); 4378 return collection ;4370 return collection.get(); 4379 4371 } 4380 4372 -
trunk/Source/WebCore/dom/Document.h
r104376 r104383 411 411 PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&); 412 412 413 PassRefPtr<HTMLCollection>images();414 PassRefPtr<HTMLCollection>embeds();415 PassRefPtr<HTMLCollection>plugins(); // an alias for embeds() required for the JS DOM bindings.416 PassRefPtr<HTMLCollection>applets();417 PassRefPtr<HTMLCollection>links();418 PassRefPtr<HTMLCollection>forms();419 PassRefPtr<HTMLCollection>anchors();420 PassRefPtr<HTMLCollection>objects();421 PassRefPtr<HTMLCollection>scripts();422 PassRefPtr<HTMLCollection>windowNamedItems(const AtomicString& name);423 PassRefPtr<HTMLCollection>documentNamedItems(const AtomicString& name);424 425 PassRefPtr<HTMLAllCollection>all();413 HTMLCollection* images(); 414 HTMLCollection* embeds(); 415 HTMLCollection* plugins(); // an alias for embeds() required for the JS DOM bindings. 416 HTMLCollection* applets(); 417 HTMLCollection* links(); 418 HTMLCollection* forms(); 419 HTMLCollection* anchors(); 420 HTMLCollection* objects(); 421 HTMLCollection* scripts(); 422 HTMLCollection* windowNamedItems(const AtomicString& name); 423 HTMLCollection* documentNamedItems(const AtomicString& name); 424 425 HTMLAllCollection* all(); 426 426 427 427 // Other methods (not part of DOM) … … 1183 1183 #endif 1184 1184 1185 const RefPtr<HTMLCollection>&cachedCollection(CollectionType);1185 HTMLCollection* cachedCollection(CollectionType); 1186 1186 1187 1187 int m_guardRefCount; … … 1366 1366 CheckedRadioButtons m_checkedRadioButtons; 1367 1367 1368 RefPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes];1369 RefPtr<HTMLAllCollection> m_allCollection;1370 1371 typedef HashMap<AtomicStringImpl*, RefPtr<HTMLNameCollection> > NamedCollectionMap;1368 OwnPtr<HTMLCollection> m_collections[NumUnnamedDocumentCachedTypes]; 1369 OwnPtr<HTMLAllCollection> m_allCollection; 1370 1371 typedef HashMap<AtomicStringImpl*, OwnPtr<HTMLNameCollection> > NamedCollectionMap; 1372 1372 NamedCollectionMap m_documentNamedItemCollections; 1373 1373 NamedCollectionMap m_windowNamedItemCollections; -
trunk/Source/WebCore/dom/Element.cpp
r104376 r104383 124 124 if (m_attributeMap) 125 125 m_attributeMap->detachFromElement(); 126 127 if (hasRareData()) {128 ElementRareData* elementRareData = rareData();129 if (elementRareData->hasCachedHTMLCollections()) {130 for (unsigned type = 0; type < NumNodeCollectionTypes; ++type) {131 if (HTMLCollection* collection = elementRareData->cachedHTMLCollection(static_cast<CollectionType>(FirstNodeCollectionType + type)))132 collection->detachFromNode();133 }134 }135 }136 126 } 137 127 -
trunk/Source/WebCore/dom/ElementRareData.h
r104376 r104383 44 44 using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach; 45 45 46 typedef FixedArray< RefPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray;46 typedef FixedArray<OwnPtr<HTMLCollection>, NumNodeCollectionTypes> CachedHTMLCollectionArray; 47 47 48 48 bool hasCachedHTMLCollections() const 49 49 { 50 50 return m_cachedCollections; 51 }52 53 HTMLCollection* cachedHTMLCollection(CollectionType type) const54 {55 ASSERT(m_cachedCollections);56 return (*m_cachedCollections)[type - FirstNodeCollectionType].get();57 51 } 58 52 … … 62 56 m_cachedCollections = adoptPtr(new CachedHTMLCollectionArray); 63 57 64 RefPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType];58 OwnPtr<HTMLCollection>& collection = (*m_cachedCollections)[type - FirstNodeCollectionType]; 65 59 if (!collection) 66 60 collection = HTMLCollection::create(element, type); -
trunk/Source/WebCore/dom/NodeRareData.h
r104376 r104383 222 222 { 223 223 if (!m_properties) 224 m_properties = HTMLPropertiesCollection::create(node);224 m_properties = adoptPtr(HTMLPropertiesCollection::create(node)); 225 225 226 226 return m_properties.get(); … … 257 257 mutable RefPtr<DOMSettableTokenList> m_itemRef; 258 258 mutable RefPtr<DOMSettableTokenList> m_itemType; 259 mutable RefPtr<HTMLPropertiesCollection> m_properties;259 mutable OwnPtr<HTMLPropertiesCollection> m_properties; 260 260 #endif 261 261 }; -
trunk/Source/WebCore/html/HTMLAllCollection.cpp
r104376 r104383 31 31 namespace WebCore { 32 32 33 Pass RefPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document)33 PassOwnPtr<HTMLAllCollection> HTMLAllCollection::create(Document* document) 34 34 { 35 return adopt Ref(new HTMLAllCollection(document));35 return adoptPtr(new HTMLAllCollection(document)); 36 36 } 37 37 … … 47 47 Node* HTMLAllCollection::namedItemWithIndex(const AtomicString& name, unsigned index) const 48 48 { 49 if (!base())50 return 0;51 52 49 invalidateCacheIfNeeded(); 53 50 updateNameCache(); -
trunk/Source/WebCore/html/HTMLAllCollection.h
r104376 r104383 33 33 class HTMLAllCollection : public HTMLCollection { 34 34 public: 35 static Pass RefPtr<HTMLAllCollection> create(Document*);35 static PassOwnPtr<HTMLAllCollection> create(Document*); 36 36 virtual ~HTMLAllCollection(); 37 37 -
trunk/Source/WebCore/html/HTMLCollection.cpp
r104376 r104383 42 42 , m_base(base) 43 43 { 44 ASSERT(m_base); 44 45 m_cache.clear(); 45 46 } … … 77 78 } 78 79 79 Pass RefPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type)80 { 81 return adopt Ref(new HTMLCollection(base, type));80 PassOwnPtr<HTMLCollection> HTMLCollection::create(Node* base, CollectionType type) 81 { 82 return adoptPtr(new HTMLCollection(base, type)); 82 83 } 83 84 … … 86 87 } 87 88 88 void HTMLCollection::detachFromNode()89 {90 m_base = 0;91 }92 93 89 void HTMLCollection::invalidateCacheIfNeeded() const 94 90 { 95 ASSERT(m_base);96 97 91 uint64_t docversion = static_cast<HTMLDocument*>(m_base->document())->domTreeVersion(); 98 92 … … 162 156 Element* HTMLCollection::itemAfter(Element* previous) const 163 157 { 164 ASSERT(m_base);165 166 158 Node* current; 167 159 if (!previous) … … 183 175 unsigned HTMLCollection::calcLength() const 184 176 { 185 ASSERT(m_base);186 187 177 unsigned len = 0; 188 178 for (Element* current = itemAfter(0); current; current = itemAfter(current)) … … 195 185 unsigned HTMLCollection::length() const 196 186 { 197 if (!m_base)198 return 0;199 200 187 invalidateCacheIfNeeded(); 201 188 if (!m_cache.hasLength) { … … 208 195 Node* HTMLCollection::item(unsigned index) const 209 196 { 210 if (!m_base)211 return 0;212 213 197 invalidateCacheIfNeeded(); 214 198 if (m_cache.current && m_cache.position == index) … … 237 221 Node* HTMLCollection::nextItem() const 238 222 { 239 ASSERT(m_base);240 223 invalidateCacheIfNeeded(); 241 224 … … 277 260 Node* HTMLCollection::namedItem(const AtomicString& name) const 278 261 { 279 if (!m_base)280 return 0;281 282 262 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp 283 263 // This method first searches for an object with a matching id … … 307 287 void HTMLCollection::updateNameCache() const 308 288 { 309 ASSERT(m_base);310 311 289 if (m_cache.hasNameCache) 312 290 return; … … 329 307 bool HTMLCollection::hasNamedItem(const AtomicString& name) const 330 308 { 331 if (!m_base)332 return false;333 334 309 if (name.isEmpty()) 335 310 return false; … … 353 328 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Node> >& result) const 354 329 { 355 if (!m_base)356 return;357 358 330 ASSERT(result.isEmpty()); 359 331 if (name.isEmpty()) … … 375 347 PassRefPtr<NodeList> HTMLCollection::tags(const String& name) 376 348 { 377 if (!m_base)378 return 0;379 380 349 return m_base->getElementsByTagName(name); 381 350 } -
trunk/Source/WebCore/html/HTMLCollection.h
r104376 r104383 24 24 #define HTMLCollection_h 25 25 26 #include "Node.h" 26 27 #include "CollectionType.h" 27 #include <wtf/RefCounted.h>28 28 #include <wtf/Forward.h> 29 29 #include <wtf/HashMap.h> 30 #include <wtf/PassOwnPtr.h> 30 31 #include <wtf/Vector.h> 31 32 … … 34 35 class Document; 35 36 class Element; 36 class Node;37 37 class NodeList; 38 38 39 class HTMLCollection : public RefCounted<HTMLCollection>{39 class HTMLCollection { 40 40 public: 41 static Pass RefPtr<HTMLCollection> create(Node* base, CollectionType);41 static PassOwnPtr<HTMLCollection> create(Node* base, CollectionType); 42 42 virtual ~HTMLCollection(); 43 44 void ref() { m_base->ref(); } 45 void deref() { m_base->deref(); } 43 46 44 47 unsigned length() const; … … 58 61 Node* base() const { return m_base; } 59 62 CollectionType type() const { return static_cast<CollectionType>(m_type); } 60 61 void detachFromNode();62 63 63 64 protected: -
trunk/Source/WebCore/html/HTMLDataListElement.cpp
r104376 r104383 48 48 } 49 49 50 PassRefPtr<HTMLCollection>HTMLDataListElement::options()50 HTMLCollection* HTMLDataListElement::options() 51 51 { 52 52 return ensureCachedHTMLCollection(DataListOptions); -
trunk/Source/WebCore/html/HTMLDataListElement.h
r104376 r104383 44 44 static PassRefPtr<HTMLDataListElement> create(const QualifiedName&, Document*); 45 45 46 PassRefPtr<HTMLCollection>options();46 HTMLCollection* options(); 47 47 48 48 private: -
trunk/Source/WebCore/html/HTMLElement.cpp
r104376 r104383 825 825 } 826 826 827 PassRefPtr<HTMLCollection>HTMLElement::children()827 HTMLCollection* HTMLElement::children() 828 828 { 829 829 return ensureCachedHTMLCollection(NodeChildren); -
trunk/Source/WebCore/html/HTMLElement.h
r104376 r104383 40 40 static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*); 41 41 42 PassRefPtr<HTMLCollection>children();43 42 HTMLCollection* children(); 43 44 44 virtual String title() const; 45 45 -
trunk/Source/WebCore/html/HTMLFormCollection.cpp
r104376 r104383 41 41 } 42 42 43 Pass RefPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form)43 PassOwnPtr<HTMLFormCollection> HTMLFormCollection::create(HTMLFormElement* form) 44 44 { 45 return adopt Ref(new HTMLFormCollection(form));45 return adoptPtr(new HTMLFormCollection(form)); 46 46 } 47 47 … … 52 52 unsigned HTMLFormCollection::calcLength() const 53 53 { 54 ASSERT(base());55 54 return static_cast<HTMLFormElement*>(base())->length(); 56 55 } … … 58 57 Node* HTMLFormCollection::item(unsigned index) const 59 58 { 60 if (!base())61 return 0;62 63 59 invalidateCacheIfNeeded(); 64 60 … … 97 93 Element* HTMLFormCollection::getNamedItem(const QualifiedName& attrName, const AtomicString& name) const 98 94 { 99 if (!base())100 return 0;101 102 95 m_cache.position = 0; 103 96 return getNamedFormItem(attrName, name, 0); … … 144 137 Node* HTMLFormCollection::namedItem(const AtomicString& name) const 145 138 { 146 if (!base())147 return 0;148 149 139 // http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/nameditem.asp 150 140 // This method first searches for an object with a matching id … … 162 152 void HTMLFormCollection::updateNameCache() const 163 153 { 164 if (!base())165 return;166 167 154 if (m_cache.hasNameCache) 168 155 return; -
trunk/Source/WebCore/html/HTMLFormCollection.h
r104376 r104383 36 36 class HTMLFormCollection : public HTMLCollection { 37 37 public: 38 static Pass RefPtr<HTMLFormCollection> create(HTMLFormElement*);38 static PassOwnPtr<HTMLFormCollection> create(HTMLFormElement*); 39 39 40 40 virtual ~HTMLFormCollection(); -
trunk/Source/WebCore/html/HTMLFormElement.cpp
r104376 r104383 92 92 HTMLFormElement::~HTMLFormElement() 93 93 { 94 if (m_elementsCollection)95 m_elementsCollection->detachFromNode();96 97 94 if (!shouldAutocomplete()) 98 95 document()->unregisterForPageCacheSuspensionCallbacks(this); … … 502 499 } 503 500 504 PassRefPtr<HTMLCollection>HTMLFormElement::elements()501 HTMLCollection* HTMLFormElement::elements() 505 502 { 506 503 if (!m_elementsCollection) 507 504 m_elementsCollection = HTMLFormCollection::create(this); 508 return m_elementsCollection ;505 return m_elementsCollection.get(); 509 506 } 510 507 -
trunk/Source/WebCore/html/HTMLFormElement.h
r104376 r104383 48 48 virtual ~HTMLFormElement(); 49 49 50 PassRefPtr<HTMLCollection>elements();50 HTMLCollection* elements(); 51 51 void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&); 52 52 … … 150 150 FormSubmission::Attributes m_attributes; 151 151 OwnPtr<AliasMap> m_elementAliases; 152 RefPtr<HTMLFormCollection> m_elementsCollection;152 OwnPtr<HTMLFormCollection> m_elementsCollection; 153 153 154 154 CheckedRadioButtons m_checkedRadioButtons; -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r104376 r104383 1577 1577 if (!sourceElement) 1578 1578 return 0; 1579 RefPtr<HTMLCollection>options = sourceElement->options();1579 HTMLCollection* options = sourceElement->options(); 1580 1580 if (!options) 1581 1581 return 0; -
trunk/Source/WebCore/html/HTMLMapElement.cpp
r104376 r104383 83 83 HTMLImageElement* HTMLMapElement::imageElement() 84 84 { 85 RefPtr<HTMLCollection>coll = document()->images();85 HTMLCollection* coll = document()->images(); 86 86 for (Node* curr = coll->firstItem(); curr; curr = coll->nextItem()) { 87 87 if (!curr->hasTagName(imgTag)) … … 127 127 } 128 128 129 PassRefPtr<HTMLCollection>HTMLMapElement::areas()129 HTMLCollection* HTMLMapElement::areas() 130 130 { 131 131 return ensureCachedHTMLCollection(MapAreas); -
trunk/Source/WebCore/html/HTMLMapElement.h
r104376 r104383 42 42 43 43 HTMLImageElement* imageElement(); 44 PassRefPtr<HTMLCollection>areas();44 HTMLCollection* areas(); 45 45 46 46 private: -
trunk/Source/WebCore/html/HTMLNameCollection.cpp
r104376 r104383 41 41 Element* HTMLNameCollection::itemAfter(Element* previous) const 42 42 { 43 if (!base())44 return 0;45 46 43 ASSERT(previous != base()); 47 44 -
trunk/Source/WebCore/html/HTMLNameCollection.h
r104376 r104383 34 34 class HTMLNameCollection : public HTMLCollection { 35 35 public: 36 static Pass RefPtr<HTMLNameCollection> create(Document* document, CollectionType type, const AtomicString& name)36 static PassOwnPtr<HTMLNameCollection> create(Document* document, CollectionType type, const AtomicString& name) 37 37 { 38 return adopt Ref(new HTMLNameCollection(document, type, name));38 return adoptPtr(new HTMLNameCollection(document, type, name)); 39 39 } 40 40 -
trunk/Source/WebCore/html/HTMLOptionsCollection.cpp
r104376 r104383 33 33 } 34 34 35 Pass RefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select)35 PassOwnPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(HTMLSelectElement* select) 36 36 { 37 return adopt Ref(new HTMLOptionsCollection(select));37 return adoptPtr(new HTMLOptionsCollection(select)); 38 38 } 39 39 … … 60 60 HTMLSelectElement* select = toHTMLSelectElement(base()); 61 61 62 if (!select)63 return;64 65 62 if (index == -1 || unsigned(index) >= length()) 66 63 select->add(newOption, 0, ec); … … 73 70 void HTMLOptionsCollection::remove(int index) 74 71 { 75 if (!base())76 return;77 72 toHTMLSelectElement(base())->remove(index); 78 73 } … … 80 75 int HTMLOptionsCollection::selectedIndex() const 81 76 { 82 if (!base())83 return -1;84 77 return toHTMLSelectElement(base())->selectedIndex(); 85 78 } … … 87 80 void HTMLOptionsCollection::setSelectedIndex(int index) 88 81 { 89 if (!base())90 return;91 82 toHTMLSelectElement(base())->setSelectedIndex(index); 92 83 } … … 94 85 void HTMLOptionsCollection::setLength(unsigned length, ExceptionCode& ec) 95 86 { 96 if (!base())97 return;98 87 toHTMLSelectElement(base())->setLength(length, ec); 99 88 } -
trunk/Source/WebCore/html/HTMLOptionsCollection.h
r104376 r104383 36 36 class HTMLOptionsCollection : public HTMLCollection { 37 37 public: 38 static Pass RefPtr<HTMLOptionsCollection> create(HTMLSelectElement*);38 static PassOwnPtr<HTMLOptionsCollection> create(HTMLSelectElement*); 39 39 40 40 void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&); -
trunk/Source/WebCore/html/HTMLPropertiesCollection.cpp
r104376 r104383 50 50 } 51 51 52 Pass RefPtr<HTMLPropertiesCollection> HTMLPropertiesCollection::create(PassRefPtr<Node> itemNode)52 PassOwnPtr<HTMLPropertiesCollection> HTMLPropertiesCollection::create(PassRefPtr<Node> itemNode) 53 53 { 54 return adopt Ref(new HTMLPropertiesCollection(itemNode));54 return adoptPtr(new HTMLPropertiesCollection(itemNode)); 55 55 } 56 56 … … 124 124 unsigned HTMLPropertiesCollection::length() const 125 125 { 126 if (!base())127 return 0;128 129 126 if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr)) 130 127 return 0; … … 137 134 Node* HTMLPropertiesCollection::item(unsigned index) const 138 135 { 139 if (!base())140 return 0;141 142 136 if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr)) 143 137 return 0; … … 157 151 m_properties.clear(); 158 152 m_propertyNames->clear(); 159 160 if (!base())161 return 0;162 153 163 154 if (!base()->isHTMLElement() || !toHTMLElement(base())->fastHasAttribute(itemscopeAttr)) -
trunk/Source/WebCore/html/HTMLPropertiesCollection.h
r104376 r104383 42 42 class HTMLPropertiesCollection : public HTMLCollection { 43 43 public: 44 static Pass RefPtr<HTMLPropertiesCollection> create(PassRefPtr<Node>);44 static PassOwnPtr<HTMLPropertiesCollection> create(PassRefPtr<Node>); 45 45 virtual ~HTMLPropertiesCollection(); 46 46 -
trunk/Source/WebCore/html/HTMLSelectElement.cpp
r104376 r104383 93 93 } 94 94 95 HTMLSelectElement::~HTMLSelectElement()96 {97 if (m_optionsCollection)98 m_optionsCollection->detachFromNode();99 }100 101 95 PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) 102 96 { … … 332 326 } 333 327 334 PassRefPtr<HTMLOptionsCollection>HTMLSelectElement::options()328 HTMLOptionsCollection* HTMLSelectElement::options() 335 329 { 336 330 if (!m_optionsCollection) 337 331 m_optionsCollection = HTMLOptionsCollection::create(this); 338 return m_optionsCollection ;332 return m_optionsCollection.get(); 339 333 } 340 334 -
trunk/Source/WebCore/html/HTMLSelectElement.h
r104376 r104383 29 29 #include "Event.h" 30 30 #include "HTMLFormControlElementWithState.h" 31 #include "HTMLOptionsCollection.h" 31 32 #include <wtf/Vector.h> 32 33 … … 40 41 static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*); 41 42 42 virtual ~HTMLSelectElement();43 44 43 int selectedIndex() const; 45 44 void setSelectedIndex(int); … … 64 63 void setValue(const String&); 65 64 66 PassRefPtr<HTMLOptionsCollection>options();65 HTMLOptionsCollection* options(); 67 66 68 67 void optionElementChildrenChanged(); … … 176 175 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 177 176 178 RefPtr<HTMLOptionsCollection> m_optionsCollection;177 OwnPtr<HTMLOptionsCollection> m_optionsCollection; 179 178 180 179 // m_listItems contains HTMLOptionElement, HTMLOptGroupElement, and HTMLHRElement objects. -
trunk/Source/WebCore/html/HTMLTableElement.cpp
r104376 r104383 53 53 { 54 54 ASSERT(hasTagName(tableTag)); 55 }56 57 HTMLTableElement::~HTMLTableElement()58 {59 if (m_rowsCollection)60 m_rowsCollection->detachFromNode();61 55 } 62 56 … … 625 619 } 626 620 627 PassRefPtr<HTMLCollection>HTMLTableElement::rows()621 HTMLCollection* HTMLTableElement::rows() 628 622 { 629 623 if (!m_rowsCollection) 630 624 m_rowsCollection = HTMLTableRowsCollection::create(this); 631 return m_rowsCollection ;632 } 633 634 PassRefPtr<HTMLCollection>HTMLTableElement::tBodies()625 return m_rowsCollection.get(); 626 } 627 628 HTMLCollection* HTMLTableElement::tBodies() 635 629 { 636 630 return ensureCachedHTMLCollection(TableTBodies); -
trunk/Source/WebCore/html/HTMLTableElement.h
r103873 r104383 41 41 static PassRefPtr<HTMLTableElement> create(const QualifiedName&, Document*); 42 42 43 virtual ~HTMLTableElement();44 45 43 HTMLTableCaptionElement* caption() const; 46 44 void setCaption(PassRefPtr<HTMLTableCaptionElement>, ExceptionCode&); … … 61 59 void deleteRow(int index, ExceptionCode&); 62 60 63 PassRefPtr<HTMLCollection>rows();64 PassRefPtr<HTMLCollection>tBodies();61 HTMLCollection* rows(); 62 HTMLCollection* tBodies(); 65 63 66 64 String rules() const; … … 104 102 unsigned short m_padding; 105 103 RefPtr<CSSMappedAttributeDeclaration> m_paddingDecl; 106 RefPtr<HTMLTableRowsCollection> m_rowsCollection;104 OwnPtr<HTMLTableRowsCollection> m_rowsCollection; 107 105 }; 108 106 -
trunk/Source/WebCore/html/HTMLTableRowElement.cpp
r103883 r104383 121 121 PassRefPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionCode& ec) 122 122 { 123 RefPtr<HTMLCollection>children = cells();123 HTMLCollection* children = cells(); 124 124 int numCells = children ? children->length() : 0; 125 125 if (index < -1 || index > numCells) { … … 144 144 void HTMLTableRowElement::deleteCell(int index, ExceptionCode& ec) 145 145 { 146 RefPtr<HTMLCollection>children = cells();146 HTMLCollection* children = cells(); 147 147 int numCells = children ? children->length() : 0; 148 148 if (index == -1) … … 155 155 } 156 156 157 PassRefPtr<HTMLCollection>HTMLTableRowElement::cells()157 HTMLCollection* HTMLTableRowElement::cells() 158 158 { 159 159 return ensureCachedHTMLCollection(TRCells); -
trunk/Source/WebCore/html/HTMLTableRowElement.h
r66057 r104383 45 45 void deleteCell(int index, ExceptionCode&); 46 46 47 PassRefPtr<HTMLCollection>cells();47 HTMLCollection* cells(); 48 48 void setCells(HTMLCollection *, ExceptionCode&); 49 49 -
trunk/Source/WebCore/html/HTMLTableRowsCollection.cpp
r103883 r104383 157 157 } 158 158 159 Pass RefPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement* table)159 PassOwnPtr<HTMLTableRowsCollection> HTMLTableRowsCollection::create(HTMLTableElement* table) 160 160 { 161 return adopt Ref(new HTMLTableRowsCollection(table));161 return adoptPtr(new HTMLTableRowsCollection(table)); 162 162 } 163 163 164 164 Element* HTMLTableRowsCollection::itemAfter(Element* previous) const 165 165 { 166 ASSERT(base());167 166 ASSERT(!previous || previous->hasLocalName(trTag)); 168 167 return rowAfter(static_cast<HTMLTableElement*>(base()), static_cast<HTMLTableRowElement*>(previous)); -
trunk/Source/WebCore/html/HTMLTableRowsCollection.h
r103856 r104383 39 39 class HTMLTableRowsCollection : public HTMLCollection { 40 40 public: 41 static Pass RefPtr<HTMLTableRowsCollection> create(HTMLTableElement*);41 static PassOwnPtr<HTMLTableRowsCollection> create(HTMLTableElement*); 42 42 43 43 static HTMLTableRowElement* rowAfter(HTMLTableElement*, HTMLTableRowElement*); -
trunk/Source/WebCore/html/HTMLTableSectionElement.cpp
r103883 r104383 64 64 { 65 65 RefPtr<HTMLTableRowElement> row; 66 RefPtr<HTMLCollection>children = rows();66 HTMLCollection* children = rows(); 67 67 int numRows = children ? (int)children->length() : 0; 68 68 if (index < -1 || index > numRows) … … 86 86 void HTMLTableSectionElement::deleteRow(int index, ExceptionCode& ec) 87 87 { 88 RefPtr<HTMLCollection>children = rows();88 HTMLCollection* children = rows(); 89 89 int numRows = children ? (int)children->length() : 0; 90 90 if (index == -1) … … 150 150 } 151 151 152 PassRefPtr<HTMLCollection>HTMLTableSectionElement::rows()152 HTMLCollection* HTMLTableSectionElement::rows() 153 153 { 154 154 return ensureCachedHTMLCollection(TSectionRows); -
trunk/Source/WebCore/html/HTMLTableSectionElement.h
r66057 r104383 52 52 void setVAlign(const String&); 53 53 54 PassRefPtr<HTMLCollection>rows();54 HTMLCollection* rows(); 55 55 56 56 private:
Note: See TracChangeset
for help on using the changeset viewer.