2013-11-03 Antti Koivisto <antti@apple.com>
+ LiveNodeLists should have non-null ContainerNode as root
+ https://bugs.webkit.org/show_bug.cgi?id=123709
+
+ Reviewed by Andreas Kling.
+
+ After moving ChildNodeList off from LiveNodeList the root is now always at least a ContainerNode.
+
+ * dom/ContainerNode.cpp:
+ (WebCore::ContainerNode::getElementsByTagName):
+ (WebCore::ContainerNode::getElementsByTagNameNS):
+ (WebCore::ContainerNode::getElementsByName):
+ (WebCore::ContainerNode::getElementsByClassName):
+ (WebCore::ContainerNode::radioNodeList):
+
+ Also these move from Node to ContainerNode to make tighter typing work.
+
+2013-11-03 Antti Koivisto <antti@apple.com>
+
Switch createContextualFragment to element iterator
https://bugs.webkit.org/show_bug.cgi?id=123704
namespace WebCore {
-ClassNodeList::ClassNodeList(Node& rootNode, const String& classNames)
+ClassNodeList::ClassNodeList(ContainerNode& rootNode, const String& classNames)
: LiveNodeList(rootNode, ClassNodeListType, InvalidateOnClassAttrChange)
, m_classNames(classNames, document().inQuirksMode())
, m_originalClassNames(classNames)
class ClassNodeList : public LiveNodeList {
public:
- static PassRefPtr<ClassNodeList> create(Node& rootNode, const String& classNames)
+ static PassRefPtr<ClassNodeList> create(ContainerNode& rootNode, const String& classNames)
{
return adoptRef(new ClassNodeList(rootNode, classNames));
}
bool nodeMatchesInlined(Element*) const;
private:
- ClassNodeList(Node& rootNode, const String& classNames);
+ ClassNodeList(ContainerNode& rootNode, const String& classNames);
virtual bool nodeMatches(Element*) const;
#include "ChildListMutationScope.h"
#include "Chrome.h"
#include "ChromeClient.h"
+#include "ClassNodeList.h"
#include "ContainerNodeAlgorithms.h"
#include "Editor.h"
#include "ElementTraversal.h"
#include "InspectorInstrumentation.h"
#include "JSLazyEventListener.h"
#include "JSNode.h"
+#include "LabelsNodeList.h"
+#include "LiveNodeList.h"
#include "LoaderStrategy.h"
#include "MemoryCache.h"
#include "MutationEvent.h"
+#include "NameNodeList.h"
+#include "NodeRareData.h"
#include "NodeRenderStyle.h"
#include "NodeTraversal.h"
#include "Page.h"
#include "PlatformStrategies.h"
+#include "RadioNodeList.h"
#include "RenderBox.h"
#include "RenderTheme.h"
#include "RenderWidget.h"
#include "ResourceLoadScheduler.h"
#include "RootInlineBox.h"
#include "SelectorQuery.h"
+#include "TagNodeList.h"
#include "TemplateContentDocumentFragment.h"
#include "Text.h"
#include <wtf/CurrentTime.h>
return selectorQuery->queryAll(*this);
}
+PassRefPtr<NodeList> ContainerNode::getElementsByTagName(const AtomicString& localName)
+{
+ if (localName.isNull())
+ return 0;
+
+ if (document().isHTMLDocument())
+ return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, HTMLTagNodeListType, localName);
+ return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, TagNodeListType, localName);
+}
+
+PassRefPtr<NodeList> ContainerNode::getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName)
+{
+ if (localName.isNull())
+ return 0;
+
+ if (namespaceURI == starAtom)
+ return getElementsByTagName(localName);
+
+ return ensureRareData().ensureNodeLists().addCacheWithQualifiedName(*this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localName);
+}
+
+PassRefPtr<NodeList> ContainerNode::getElementsByName(const String& elementName)
+{
+ return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, NameNodeListType, elementName);
+}
+
+PassRefPtr<NodeList> ContainerNode::getElementsByClassName(const String& classNames)
+{
+ return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, ClassNodeListType, classNames);
+}
+
+PassRefPtr<RadioNodeList> ContainerNode::radioNodeList(const AtomicString& name)
+{
+ ASSERT(hasTagName(HTMLNames::formTag) || hasTagName(HTMLNames::fieldsetTag));
+ return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, RadioNodeListType, name);
+}
+
} // namespace WebCore
Element* querySelector(const AtomicString& selectors, ExceptionCode&);
RefPtr<NodeList> querySelectorAll(const AtomicString& selectors, ExceptionCode&);
+ PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
+ PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
+ PassRefPtr<NodeList> getElementsByName(const String& elementName);
+ PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
+ PassRefPtr<RadioNodeList> radioNodeList(const AtomicString&);
+
protected:
explicit ContainerNode(Document*, ConstructionType = CreateContainer);
namespace WebCore {
-Node& LiveNodeListBase::rootNode() const
+ContainerNode& LiveNodeListBase::rootNode() const
{
if (isRootedAtDocument() && ownerNode().inDocument())
return ownerNode().document();
return ownerNode();
}
-ContainerNode* LiveNodeListBase::rootContainerNode() const
-{
- Node& rootNode = this->rootNode();
- if (!rootNode.isContainerNode())
- return 0;
- return &toContainerNode(rootNode);
-}
-
void LiveNodeListBase::invalidateCache() const
{
m_cachedItem = 0;
DoesNotOverrideItemAfter,
};
- LiveNodeListBase(Node& ownerNode, NodeListRootType rootType, NodeListInvalidationType invalidationType,
+ LiveNodeListBase(ContainerNode& ownerNode, NodeListRootType rootType, NodeListInvalidationType invalidationType,
bool shouldOnlyIncludeDirectChildren, CollectionType collectionType, ItemAfterOverrideType itemAfterOverrideType)
: m_ownerNode(ownerNode)
, m_cachedItem(0)
ALWAYS_INLINE bool isRootedAtDocument() const { return m_rootType == NodeListIsRootedAtDocument || m_rootType == NodeListIsRootedAtDocumentIfOwnerHasItemrefAttr; }
ALWAYS_INLINE NodeListInvalidationType invalidationType() const { return static_cast<NodeListInvalidationType>(m_invalidationType); }
ALWAYS_INLINE CollectionType type() const { return static_cast<CollectionType>(m_collectionType); }
- Node& ownerNode() const { return const_cast<Node&>(m_ownerNode.get()); }
+ ContainerNode& ownerNode() const { return const_cast<ContainerNode&>(m_ownerNode.get()); }
ALWAYS_INLINE void invalidateCache(const QualifiedName* attrName) const
{
if (!attrName || shouldInvalidateTypeOnAttributeChange(invalidationType(), *attrName))
protected:
Document& document() const { return m_ownerNode->document(); }
- Node& rootNode() const;
- ContainerNode* rootContainerNode() const;
+ ContainerNode& rootNode() const;
bool overridesItemAfter() const { return m_overridesItemAfter; }
ALWAYS_INLINE bool isItemCacheValid() const { return m_isItemCacheValid; }
Node* iterateForPreviousNode(Node* current) const;
Node* itemBefore(Node* previousItem) const;
- Ref<Node> m_ownerNode;
+ Ref<ContainerNode> m_ownerNode;
mutable Node* m_cachedItem;
mutable unsigned m_cachedLength;
mutable unsigned m_cachedItemOffset;
class LiveNodeList : public LiveNodeListBase {
public:
- LiveNodeList(Node& ownerNode, CollectionType collectionType, NodeListInvalidationType invalidationType, NodeListRootType rootType = NodeListIsRootedAtNode)
+ LiveNodeList(ContainerNode& ownerNode, CollectionType collectionType, NodeListInvalidationType invalidationType, NodeListRootType rootType = NodeListIsRootedAtNode)
: LiveNodeListBase(ownerNode, rootType, invalidationType, /*shouldOnlyIncludeDirectChildren*/ false, collectionType, DoesNotOverrideItemAfter)
{ }
using namespace HTMLNames;
-NameNodeList::NameNodeList(Node& rootNode, const AtomicString& name)
+NameNodeList::NameNodeList(ContainerNode& rootNode, const AtomicString& name)
: LiveNodeList(rootNode, NameNodeListType, InvalidateOnNameAttrChange)
, m_name(name)
{
// NodeList which lists all Nodes in a Element with a given "name" attribute
class NameNodeList : public LiveNodeList {
public:
- static PassRefPtr<NameNodeList> create(Node& rootNode, CollectionType type, const AtomicString& name)
+ static PassRefPtr<NameNodeList> create(ContainerNode& rootNode, CollectionType type, const AtomicString& name)
{
ASSERT_UNUSED(type, type == NameNodeListType);
return adoptRef(new NameNodeList(rootNode, name));
virtual ~NameNodeList();
private:
- NameNodeList(Node& rootNode, const AtomicString& name);
+ NameNodeList(ContainerNode& rootNode, const AtomicString& name);
virtual bool nodeMatches(Element*) const;
#include "CSSStyleRule.h"
#include "CSSStyleSheet.h"
#include "ChildNodeList.h"
-#include "ClassNodeList.h"
#include "ContainerNodeAlgorithms.h"
#include "ContextMenuController.h"
#include "DOMImplementation.h"
#include "InsertionPoint.h"
#include "InspectorCounters.h"
#include "KeyboardEvent.h"
-#include "LabelsNodeList.h"
-#include "LiveNodeList.h"
#include "Logging.h"
#include "MouseEvent.h"
#include "MutationEvent.h"
-#include "NameNodeList.h"
#include "NamedNodeMap.h"
#include "NodeRareData.h"
#include "NodeTraversal.h"
#include "PlatformWheelEvent.h"
#include "ProcessingInstruction.h"
#include "ProgressEvent.h"
-#include "RadioNodeList.h"
#include "RegisteredEventListener.h"
#include "RenderBlock.h"
#include "RenderBox.h"
#include "ShadowRoot.h"
#include "StorageEvent.h"
#include "StyleResolver.h"
-#include "TagNodeList.h"
#include "TemplateContentDocumentFragment.h"
#include "Text.h"
#include "TextEvent.h"
// FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node.
-PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName)
-{
- if (localName.isNull())
- return 0;
-
- if (document().isHTMLDocument())
- return ensureRareData().ensureNodeLists().addCacheWithAtomicName<HTMLTagNodeList>(*this, HTMLTagNodeListType, localName);
- return ensureRareData().ensureNodeLists().addCacheWithAtomicName<TagNodeList>(*this, TagNodeListType, localName);
-}
-
-PassRefPtr<NodeList> Node::getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName)
-{
- if (localName.isNull())
- return 0;
-
- if (namespaceURI == starAtom)
- return getElementsByTagName(localName);
-
- return ensureRareData().ensureNodeLists().addCacheWithQualifiedName(*this, namespaceURI.isEmpty() ? nullAtom : namespaceURI, localName);
-}
-
-PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
-{
- return ensureRareData().ensureNodeLists().addCacheWithAtomicName<NameNodeList>(*this, NameNodeListType, elementName);
-}
-
-PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
-{
- return ensureRareData().ensureNodeLists().addCacheWithName<ClassNodeList>(*this, ClassNodeListType, classNames);
-}
-
-PassRefPtr<RadioNodeList> Node::radioNodeList(const AtomicString& name)
-{
- ASSERT(hasTagName(formTag) || hasTagName(fieldsetTag));
- return ensureRareData().ensureNodeLists().addCacheWithAtomicName<RadioNodeList>(*this, RadioNodeListType, name);
-}
-
Document* Node::ownerDocument() const
{
Document* document = &this->document();
NodeListsNodeData* nodeLists();
void clearNodeLists();
- PassRefPtr<NodeList> getElementsByTagName(const AtomicString&);
- PassRefPtr<NodeList> getElementsByTagNameNS(const AtomicString& namespaceURI, const AtomicString& localName);
- PassRefPtr<NodeList> getElementsByName(const String& elementName);
- PassRefPtr<NodeList> getElementsByClassName(const String& classNames);
- PassRefPtr<RadioNodeList> radioNodeList(const AtomicString&);
-
virtual bool willRespondToMouseMoveEvents();
virtual bool willRespondToMouseClickEvents();
virtual bool willRespondToTouchEvents();
typedef HashMap<QualifiedName, TagNodeList*> TagNodeListCacheNS;
template<typename T>
- PassRefPtr<T> addCacheWithAtomicName(Node& node, CollectionType collectionType, const AtomicString& name)
+ PassRefPtr<T> addCacheWithAtomicName(ContainerNode& node, CollectionType collectionType, const AtomicString& name)
{
NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, name), nullptr);
if (!result.isNewEntry)
// FIXME: This function should be renamed since it doesn't have an atomic name.
template<typename T>
- PassRefPtr<T> addCacheWithAtomicName(Node& node, CollectionType collectionType)
+ PassRefPtr<T> addCacheWithAtomicName(ContainerNode& node, CollectionType collectionType)
{
NodeListAtomicNameCacheMap::AddResult result = m_atomicNameCaches.add(namedNodeListKey(collectionType, starAtom), nullptr);
if (!result.isNewEntry)
}
template<typename T>
- PassRefPtr<T> addCacheWithName(Node& node, CollectionType collectionType, const String& name)
+ PassRefPtr<T> addCacheWithName(ContainerNode& node, CollectionType collectionType, const String& name)
{
NodeListNameCacheMap::AddResult result = m_nameCaches.add(namedNodeListKey(collectionType, name), nullptr);
if (!result.isNewEntry)
return list.release();
}
- PassRefPtr<TagNodeList> addCacheWithQualifiedName(Node& node, const AtomicString& namespaceURI, const AtomicString& localName)
+ PassRefPtr<TagNodeList> addCacheWithQualifiedName(ContainerNode& node, const AtomicString& namespaceURI, const AtomicString& localName)
{
QualifiedName name(nullAtom, localName, namespaceURI);
TagNodeListCacheNS::AddResult result = m_tagNodeListCacheNS.add(name, nullptr);
namespace WebCore {
-TagNodeList::TagNodeList(Node& rootNode, CollectionType type, const AtomicString& namespaceURI, const AtomicString& localName)
+TagNodeList::TagNodeList(ContainerNode& rootNode, CollectionType type, const AtomicString& namespaceURI, const AtomicString& localName)
: LiveNodeList(rootNode, type, DoNotInvalidateOnAttributeChanges)
, m_namespaceURI(namespaceURI)
, m_localName(localName)
return m_namespaceURI == starAtom || m_namespaceURI == testNode->namespaceURI();
}
-HTMLTagNodeList::HTMLTagNodeList(Node& rootNode, const AtomicString& localName)
+HTMLTagNodeList::HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName)
: TagNodeList(rootNode, HTMLTagNodeListType, starAtom, localName)
, m_loweredLocalName(localName.lower())
{
// NodeList that limits to a particular tag.
class TagNodeList : public LiveNodeList {
public:
- static PassRefPtr<TagNodeList> create(Node& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
+ static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, const AtomicString& namespaceURI, const AtomicString& localName)
{
ASSERT(namespaceURI != starAtom);
return adoptRef(new TagNodeList(rootNode, TagNodeListType, namespaceURI, localName));
}
- static PassRefPtr<TagNodeList> create(Node& rootNode, CollectionType type, const AtomicString& localName)
+ static PassRefPtr<TagNodeList> create(ContainerNode& rootNode, CollectionType type, const AtomicString& localName)
{
ASSERT_UNUSED(type, type == TagNodeListType);
return adoptRef(new TagNodeList(rootNode, TagNodeListType, starAtom, localName));
virtual ~TagNodeList();
protected:
- TagNodeList(Node& rootNode, CollectionType, const AtomicString& namespaceURI, const AtomicString& localName);
+ TagNodeList(ContainerNode& rootNode, CollectionType, const AtomicString& namespaceURI, const AtomicString& localName);
virtual bool nodeMatches(Element*) const OVERRIDE;
class HTMLTagNodeList : public TagNodeList {
public:
- static PassRefPtr<HTMLTagNodeList> create(Node& rootNode, CollectionType type, const AtomicString& localName)
+ static PassRefPtr<HTMLTagNodeList> create(ContainerNode& rootNode, CollectionType type, const AtomicString& localName)
{
ASSERT_UNUSED(type, type == HTMLTagNodeListType);
return adoptRef(new HTMLTagNodeList(rootNode, localName));
bool nodeMatchesInlined(Element*) const;
private:
- HTMLTagNodeList(Node& rootNode, const AtomicString& localName);
+ HTMLTagNodeList(ContainerNode& rootNode, const AtomicString& localName);
virtual bool nodeMatches(Element*) const OVERRIDE;
namespace WebCore {
-PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(Node& node, CollectionType type)
+PassRefPtr<HTMLAllCollection> HTMLAllCollection::create(ContainerNode& node, CollectionType type)
{
return adoptRef(new HTMLAllCollection(node, type));
}
-HTMLAllCollection::HTMLAllCollection(Node& node, CollectionType type)
+HTMLAllCollection::HTMLAllCollection(ContainerNode& node, CollectionType type)
: HTMLCollection(node, type, DoesNotOverrideItemAfter)
{
}
class HTMLAllCollection : public HTMLCollection {
public:
- static PassRefPtr<HTMLAllCollection> create(Node&, CollectionType);
+ static PassRefPtr<HTMLAllCollection> create(ContainerNode&, CollectionType);
virtual ~HTMLAllCollection();
Node* namedItemWithIndex(const AtomicString& name, unsigned index) const;
private:
- HTMLAllCollection(Node&, CollectionType);
+ HTMLAllCollection(ContainerNode&, CollectionType);
};
} // namespace WebCore
return DoNotInvalidateOnAttributeChanges;
}
-HTMLCollection::HTMLCollection(Node& ownerNode, CollectionType type, ItemAfterOverrideType itemAfterOverrideType)
+HTMLCollection::HTMLCollection(ContainerNode& ownerNode, CollectionType type, ItemAfterOverrideType itemAfterOverrideType)
: LiveNodeListBase(ownerNode, rootTypeFromCollectionType(type), invalidationTypeExcludingIdAndNameAttributes(type),
WebCore::shouldOnlyIncludeDirectChildren(type), type, itemAfterOverrideType)
{
}
-PassRefPtr<HTMLCollection> HTMLCollection::create(Node& base, CollectionType type)
+PassRefPtr<HTMLCollection> HTMLCollection::create(ContainerNode& base, CollectionType type)
{
return adoptRef(new HTMLCollection(base, type, DoesNotOverrideItemAfter));
}
if (isLengthCacheValid() && cachedLength() <= offset)
return 0;
- ContainerNode* root = rootContainerNode();
- if (!root) {
- // FIMXE: In someTextNode.childNodes case the root is Text. We shouldn't even make a LiveNodeList for that.
- setLengthCache(0);
- return 0;
- }
+ ContainerNode& root = rootNode();
if (isLengthCacheValid() && !overridesItemAfter() && isLastItemCloserThanLastOrCachedItem(offset)) {
Node* lastItem = itemBefore(0);
unsigned offsetInArray = 0;
Node* firstItem;
if (isNodeList(type()))
- firstItem = traverseLiveNodeListFirstElement(root);
+ firstItem = traverseLiveNodeListFirstElement(&root);
else
- firstItem = static_cast<const HTMLCollection*>(this)->traverseFirstElement(offsetInArray, root);
+ firstItem = static_cast<const HTMLCollection*>(this)->traverseFirstElement(offsetInArray, &root);
if (!firstItem) {
setLengthCache(0);
if (cachedItemOffset() == offset)
return cachedItem();
- return itemBeforeOrAfterCachedItem(offset, root);
+ return itemBeforeOrAfterCachedItem(offset, &root);
}
inline Node* LiveNodeListBase::itemBeforeOrAfterCachedItem(unsigned offset, ContainerNode* root) const
// object with a matching name attribute, but only on those elements
// that are allowed a name attribute.
- ContainerNode* root = rootContainerNode();
- if (name.isEmpty() || !root)
+ if (name.isEmpty())
return 0;
- if (!overridesItemAfter() && root->isInTreeScope()) {
- TreeScope& treeScope = root->treeScope();
+ ContainerNode& root = rootNode();
+ if (!overridesItemAfter() && root.isInTreeScope()) {
+ TreeScope& treeScope = root.treeScope();
Element* candidate = 0;
if (treeScope.hasElementWithId(*name.impl())) {
if (!treeScope.containsMultipleElementsWithId(name))
if (candidate
&& isMatchingElement(this, candidate)
- && (shouldOnlyIncludeDirectChildren() ? candidate->parentNode() == root : candidate->isDescendantOf(root)))
+ && (shouldOnlyIncludeDirectChildren() ? candidate->parentNode() == &root : candidate->isDescendantOf(&root)))
return candidate;
}
if (hasNameCache())
return;
- ContainerNode* root = rootContainerNode();
- if (!root)
- return;
+ ContainerNode& root = rootNode();
unsigned arrayOffset = 0;
- for (Element* element = traverseFirstElement(arrayOffset, root); element; element = traverseNextElement(arrayOffset, element, root)) {
+ for (Element* element = traverseFirstElement(arrayOffset, &root); element; element = traverseNextElement(arrayOffset, element, &root)) {
const AtomicString& idAttrVal = element->getIdAttribute();
if (!idAttrVal.isEmpty())
appendIdCache(idAttrVal, element);
class HTMLCollection : public LiveNodeListBase {
public:
- static PassRefPtr<HTMLCollection> create(Node& base, CollectionType);
+ static PassRefPtr<HTMLCollection> create(ContainerNode& base, CollectionType);
virtual ~HTMLCollection();
// DOM API
Element* traverseForwardToOffset(unsigned offset, Element* currentElement, unsigned& currentOffset, unsigned& offsetInArray, ContainerNode* root) const;
protected:
- HTMLCollection(Node& base, CollectionType, ItemAfterOverrideType);
+ HTMLCollection(ContainerNode& base, CollectionType, ItemAfterOverrideType);
virtual void updateNameCache() const;
// Since the collections are to be "live", we have to do the
// calculation every time if anything has changed.
-HTMLFormControlsCollection::HTMLFormControlsCollection(Node& ownerNode)
+HTMLFormControlsCollection::HTMLFormControlsCollection(ContainerNode& ownerNode)
: HTMLCollection(ownerNode, FormControls, OverridesItemAfter)
{
ASSERT(isHTMLFormElement(ownerNode) || isHTMLFieldSetElement(ownerNode));
}
-PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(Node& ownerNode, CollectionType)
+PassRefPtr<HTMLFormControlsCollection> HTMLFormControlsCollection::create(ContainerNode& ownerNode, CollectionType)
{
return adoptRef(new HTMLFormControlsCollection(ownerNode));
}
class HTMLFormControlsCollection : public HTMLCollection {
public:
- static PassRefPtr<HTMLFormControlsCollection> create(Node&, CollectionType);
+ static PassRefPtr<HTMLFormControlsCollection> create(ContainerNode&, CollectionType);
virtual ~HTMLFormControlsCollection();
virtual Node* namedItem(const AtomicString& name) const;
private:
- explicit HTMLFormControlsCollection(Node&);
+ explicit HTMLFormControlsCollection(ContainerNode&);
virtual void updateNameCache() const;
using namespace HTMLNames;
-HTMLNameCollection::HTMLNameCollection(Node& document, CollectionType type, const AtomicString& name)
+HTMLNameCollection::HTMLNameCollection(ContainerNode& document, CollectionType type, const AtomicString& name)
: HTMLCollection(document, type, DoesNotOverrideItemAfter)
, m_name(name)
{
~HTMLNameCollection();
protected:
- HTMLNameCollection(Node&, CollectionType, const AtomicString& name);
+ HTMLNameCollection(ContainerNode&, CollectionType, const AtomicString& name);
AtomicString m_name;
};
class WindowNameCollection : public HTMLNameCollection {
public:
- static PassRefPtr<WindowNameCollection> create(Node& document, CollectionType type, const AtomicString& name)
+ static PassRefPtr<WindowNameCollection> create(ContainerNode& document, CollectionType type, const AtomicString& name)
{
return adoptRef(new WindowNameCollection(document, type, name));
}
static bool nodeMatches(Element*, const AtomicStringImpl*);
private:
- WindowNameCollection(Node& document, CollectionType type, const AtomicString& name)
+ WindowNameCollection(ContainerNode& document, CollectionType type, const AtomicString& name)
: HTMLNameCollection(document, type, name)
{
ASSERT(type == WindowNamedItems);
class DocumentNameCollection : public HTMLNameCollection {
public:
- static PassRefPtr<DocumentNameCollection> create(Node& document, CollectionType type, const AtomicString& name)
+ static PassRefPtr<DocumentNameCollection> create(ContainerNode& document, CollectionType type, const AtomicString& name)
{
return adoptRef(new DocumentNameCollection(document, type, name));
}
static bool nodeMatches(Element*, const AtomicStringImpl*);
private:
- DocumentNameCollection(Node& document, CollectionType type, const AtomicString& name)
+ DocumentNameCollection(ContainerNode& document, CollectionType type, const AtomicString& name)
: HTMLNameCollection(document, type, name)
{
ASSERT(type == DocumentNamedItems);
namespace WebCore {
-HTMLOptionsCollection::HTMLOptionsCollection(Node& select)
+HTMLOptionsCollection::HTMLOptionsCollection(ContainerNode& select)
: HTMLCollection(select, SelectOptions, DoesNotOverrideItemAfter)
{
ASSERT(isHTMLSelectElement(select));
}
-PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(Node& select, CollectionType)
+PassRefPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(ContainerNode& select, CollectionType)
{
return adoptRef(new HTMLOptionsCollection(select));
}
class HTMLOptionsCollection : public HTMLCollection {
public:
- static PassRefPtr<HTMLOptionsCollection> create(Node&, CollectionType);
+ static PassRefPtr<HTMLOptionsCollection> create(ContainerNode&, CollectionType);
void add(PassRefPtr<HTMLOptionElement>, ExceptionCode&);
void add(PassRefPtr<HTMLOptionElement>, int index, ExceptionCode&);
void setLength(unsigned, ExceptionCode&);
private:
- explicit HTMLOptionsCollection(Node&);
+ explicit HTMLOptionsCollection(ContainerNode&);
};
} //namespace
using namespace HTMLNames;
-LabelsNodeList::LabelsNodeList(Node& forNode)
+LabelsNodeList::LabelsNodeList(ContainerNode& forNode)
: LiveNodeList(forNode, LabelsNodeListType, InvalidateOnForAttrChange, NodeListIsRootedAtDocument)
{
}
class LabelsNodeList : public LiveNodeList {
public:
- static PassRefPtr<LabelsNodeList> create(Node& forNode, CollectionType type, const AtomicString&)
+ static PassRefPtr<LabelsNodeList> create(ContainerNode& forNode, CollectionType type, const AtomicString&)
{
ASSERT_UNUSED(type, type == LabelsNodeListType);
return adoptRef(new LabelsNodeList(forNode));
~LabelsNodeList();
protected:
- explicit LabelsNodeList(Node& forNode);
+ explicit LabelsNodeList(ContainerNode& forNode);
virtual bool nodeMatches(Element*) const;
};
return MediaDocumentParser::create(*this);
}
-static inline HTMLVideoElement* descendentVideoElement(Node* node)
+static inline HTMLVideoElement* descendentVideoElement(ContainerNode& node)
{
- ASSERT(node);
+ if (isHTMLVideoElement(node))
+ return toHTMLVideoElement(&node);
- if (node->hasTagName(videoTag))
- return toHTMLVideoElement(node);
-
- RefPtr<NodeList> nodeList = node->getElementsByTagNameNS(videoTag.namespaceURI(), videoTag.localName());
+ RefPtr<NodeList> nodeList = node.getElementsByTagNameNS(videoTag.namespaceURI(), videoTag.localName());
if (nodeList.get()->length() > 0)
return toHTMLVideoElement(nodeList.get()->item(0));
}
}
+ if (!targetNode->isContainerNode())
+ return;
+ ContainerNode& targetContainer = toContainerNode(*targetNode);
if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent()) {
- HTMLVideoElement* video = descendentVideoElement(targetNode);
+ HTMLVideoElement* video = descendentVideoElement(targetContainer);
if (!video)
return;
htmlBody->setAttribute(marginwidthAttr, "0");
htmlBody->setAttribute(marginheightAttr, "0");
- if (HTMLVideoElement* videoElement = descendentVideoElement(htmlBody)) {
+ if (HTMLVideoElement* videoElement = descendentVideoElement(*htmlBody)) {
RefPtr<Element> element = Document::createElement(embedTag, false);
HTMLEmbedElement* embedElement = static_cast<HTMLEmbedElement*>(element.get());
using namespace HTMLNames;
-RadioNodeList::RadioNodeList(Node& rootNode, const AtomicString& name)
+RadioNodeList::RadioNodeList(ContainerNode& rootNode, const AtomicString& name)
: LiveNodeList(rootNode, RadioNodeListType, InvalidateForFormControls, isHTMLFormElement(rootNode) ? NodeListIsRootedAtDocument : NodeListIsRootedAtNode)
, m_name(name)
{
class RadioNodeList : public LiveNodeList {
public:
- static PassRefPtr<RadioNodeList> create(Node& rootNode, CollectionType type, const AtomicString& name)
+ static PassRefPtr<RadioNodeList> create(ContainerNode& rootNode, CollectionType type, const AtomicString& name)
{
ASSERT_UNUSED(type, type == RadioNodeListType);
return adoptRef(new RadioNodeList(rootNode, name));
virtual bool nodeMatches(Element*) const;
private:
- RadioNodeList(Node&, const AtomicString& name);
+ RadioNodeList(ContainerNode&, const AtomicString& name);
bool checkElementMatchesRadioNodeListFilter(Element*) const;
AtomicString m_name;