summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/TreeScope.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-11-29 12:18:48 +0100
committerSimon Hausmann <simon.hausmann@digia.com>2012-11-29 12:18:57 +0100
commit4c01d0526ba4dd8cff0c0ff22a6f0ab5eb973064 (patch)
treebed2fe914fe0f7ec70abfb47d2d84af8a3604d09 /Source/WebCore/dom/TreeScope.cpp
parent01485457c9a5da3f1121015afd25bb53af77662e (diff)
downloadqtwebkit-4c01d0526ba4dd8cff0c0ff22a6f0ab5eb973064.tar.gz
Imported WebKit commit c60cfe0fc09efd257aa0111d7b133b02deb8a63e (http://svn.webkit.org/repository/webkit/trunk@136119)
New snapshot that includes the fix for installing the QtWebProcess into libexec Change-Id: I01344e079cbdac5678c4cba6ffcc05f4597cf0d7 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'Source/WebCore/dom/TreeScope.cpp')
-rw-r--r--Source/WebCore/dom/TreeScope.cpp54
1 files changed, 38 insertions, 16 deletions
diff --git a/Source/WebCore/dom/TreeScope.cpp b/Source/WebCore/dom/TreeScope.cpp
index cc593c620..6b2fb30d9 100644
--- a/Source/WebCore/dom/TreeScope.cpp
+++ b/Source/WebCore/dom/TreeScope.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Google Inc. All Rights Reserved.
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -51,12 +52,18 @@
namespace WebCore {
+struct SameSizeAsTreeScope {
+ virtual ~SameSizeAsTreeScope();
+ void* pointers[7];
+};
+
+COMPILE_ASSERT(sizeof(TreeScope) == sizeof(SameSizeAsTreeScope), treescope_should_stay_small);
+
using namespace HTMLNames;
TreeScope::TreeScope(ContainerNode* rootNode)
: m_rootNode(rootNode)
, m_parentTreeScope(0)
- , m_shouldCacheLabelsByForAttribute(false)
, m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
{
ASSERT(rootNode);
@@ -91,18 +98,24 @@ Element* TreeScope::getElementById(const AtomicString& elementId) const
{
if (elementId.isEmpty())
return 0;
- return m_elementsById.getElementById(elementId.impl(), this);
+ if (!m_elementsById)
+ return 0;
+ return m_elementsById->getElementById(elementId.impl(), this);
}
void TreeScope::addElementById(const AtomicString& elementId, Element* element)
{
- m_elementsById.add(elementId.impl(), element);
+ if (!m_elementsById)
+ m_elementsById = adoptPtr(new DocumentOrderedMap);
+ m_elementsById->add(elementId.impl(), element);
m_idTargetObserverRegistry->notifyObservers(elementId);
}
void TreeScope::removeElementById(const AtomicString& elementId, Element* element)
{
- m_elementsById.remove(elementId.impl(), element);
+ if (!m_elementsById)
+ return;
+ m_elementsById->remove(elementId.impl(), element);
m_idTargetObserverRegistry->notifyObservers(elementId);
}
@@ -125,42 +138,54 @@ void TreeScope::addImageMap(HTMLMapElement* imageMap)
AtomicStringImpl* name = imageMap->getName().impl();
if (!name)
return;
- m_imageMapsByName.add(name, imageMap);
+ if (!m_imageMapsByName)
+ m_imageMapsByName = adoptPtr(new DocumentOrderedMap);
+ m_imageMapsByName->add(name, imageMap);
}
void TreeScope::removeImageMap(HTMLMapElement* imageMap)
{
+ if (!m_imageMapsByName)
+ return;
AtomicStringImpl* name = imageMap->getName().impl();
if (!name)
return;
- m_imageMapsByName.remove(name, imageMap);
+ m_imageMapsByName->remove(name, imageMap);
}
HTMLMapElement* TreeScope::getImageMap(const String& url) const
{
if (url.isNull())
return 0;
+ if (!m_imageMapsByName)
+ return 0;
size_t hashPos = url.find('#');
String name = (hashPos == notFound ? url : url.substring(hashPos + 1)).impl();
if (rootNode()->document()->isHTMLDocument())
- return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
- return static_cast<HTMLMapElement*>(m_imageMapsByName.getElementByMapName(AtomicString(name).impl(), this));
+ return static_cast<HTMLMapElement*>(m_imageMapsByName->getElementByLowercasedMapName(AtomicString(name.lower()).impl(), this));
+ return static_cast<HTMLMapElement*>(m_imageMapsByName->getElementByMapName(AtomicString(name).impl(), this));
}
void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
{
- m_labelsByForAttribute.add(forAttributeValue.impl(), element);
+ ASSERT(m_labelsByForAttribute);
+ m_labelsByForAttribute->add(forAttributeValue.impl(), element);
}
void TreeScope::removeLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
{
- m_labelsByForAttribute.remove(forAttributeValue.impl(), element);
+ ASSERT(m_labelsByForAttribute);
+ m_labelsByForAttribute->remove(forAttributeValue.impl(), element);
}
HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeValue)
{
- if (!m_shouldCacheLabelsByForAttribute) {
- m_shouldCacheLabelsByForAttribute = true;
+ if (forAttributeValue.isEmpty())
+ return 0;
+
+ if (!m_labelsByForAttribute) {
+ // Populate the map on first access.
+ m_labelsByForAttribute = adoptPtr(new DocumentOrderedMap);
for (Node* node = rootNode(); node; node = node->traverseNextNode()) {
if (node->hasTagName(labelTag)) {
HTMLLabelElement* label = static_cast<HTMLLabelElement*>(node);
@@ -171,10 +196,7 @@ HTMLLabelElement* TreeScope::labelElementForId(const AtomicString& forAttributeV
}
}
- if (forAttributeValue.isEmpty())
- return 0;
-
- return static_cast<HTMLLabelElement*>(m_labelsByForAttribute.getElementByLabelForAttribute(forAttributeValue.impl(), this));
+ return static_cast<HTMLLabelElement*>(m_labelsByForAttribute->getElementByLabelForAttribute(forAttributeValue.impl(), this));
}
DOMSelection* TreeScope::getSelection() const