+2013-10-05 Andreas Kling <akling@apple.com>
+
+ CTTE: Node::treeScope() should return a reference.
+ <https://webkit.org/b/122399>
+
+ Reviewed by Superlative Sam.
+
+ Every Node belongs to a TreeScope. To enforce this, I've made
+ treeScope() return a TreeScope&, and setTreeScope() now takes a
+ TreeScope& so there is no way to clear it.
+
2013-10-05 Sam Weinig <sam@webkit.org>
CTTE: Use references more for the Document parser
const AtomicString& id = element->getIdAttribute();
if (!id.isEmpty()) {
- if (HTMLLabelElement* label = element->treeScope()->labelElementForId(id))
+ if (HTMLLabelElement* label = element->treeScope().labelElementForId(id))
return label;
}
if (!node || !node->isElementNode())
return;
- TreeScope* scope = node->treeScope();
- if (!scope)
- return;
+ TreeScope& treeScope = node->treeScope();
String idList = getAttribute(attribute).string();
if (idList.isEmpty())
unsigned size = idVector.size();
for (unsigned i = 0; i < size; ++i) {
AtomicString idName(idVector[i]);
- Element* idElement = scope->getElementById(idName);
+ Element* idElement = treeScope.getElementById(idName);
if (idElement)
elements.append(idElement);
}
if (activeDescendantAttrStr.isNull() || activeDescendantAttrStr.isEmpty())
return 0;
- Element* target = element->treeScope()->getElementById(activeDescendantAttrStr);
+ Element* target = element->treeScope().getElementById(activeDescendantAttrStr);
if (!target)
return 0;
// a) it's a UA rule
// b) the tree scope allows author rules
// c) the rules comes from a scoped style sheet within the same tree scope
- TreeScope* treeScope = element->treeScope();
if (!MatchingUARulesScope::isMatchingUARules()
- && !treeScope->applyAuthorStyles())
+ && !element->treeScope().applyAuthorStyles())
return;
// We need to collect the rules for id, class, tag, and everything else into a buffer and
// FIXME: Together with adoptNode above, the tree scope might get updated recursively twice
// (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree).
// Can we do better?
- treeScope()->adoptIfNeeded(adoptedChild.get());
+ treeScope().adoptIfNeeded(adoptedChild.get());
if (attached() && !adoptedChild->attached())
attachChild(*adoptedChild.get());
}
if (child.parentNode())
break;
- treeScope()->adoptIfNeeded(&child);
+ treeScope().adoptIfNeeded(&child);
insertBeforeCommon(next.get(), child);
if (child.parentNode())
break;
- treeScope()->adoptIfNeeded(&child);
+ treeScope().adoptIfNeeded(&child);
// Add child before "next".
{
if (child.parentNode())
break;
- treeScope()->adoptIfNeeded(&child);
+ treeScope().adoptIfNeeded(&child);
// Append child to the end of the list
{
NoEventDispatchAssertion assertNoEventDispatch;
// FIXME: This method should take a PassRefPtr.
appendChildToContainer(newChild.get(), *this);
- treeScope()->adoptIfNeeded(newChild.get());
+ treeScope().adoptIfNeeded(newChild.get());
}
newChild->updateAncestorConnectedSubframeCountForInsertion();
inline bool Node::isTreeScope() const
{
- return treeScope()->rootNode() == this;
+ return treeScope().rootNode() == this;
}
// This constant controls how much buffer is initially allocated
if (!m_focusedElement || this->inPageCache()) // If the document is in the page cache, then we don't need to clear out the focused node.
return;
- Element* focusedElement = node->treeScope()->focusedElement();
+ Element* focusedElement = node->treeScope().focusedElement();
if (!focusedElement)
return;
inline Node::Node(Document* document, ConstructionType type)
: m_nodeFlags(type)
, m_parentNode(0)
- , m_treeScope(document ? document : TreeScope::noDocumentInstance())
+ , m_treeScope(document ? document : &TreeScope::noDocumentInstance())
, m_previous(0)
, m_next(0)
{
if (hasRareData())
elementRareData()->clearClassListValueForQuirksMode();
- TreeScope* newScope = insertionPoint.treeScope();
+ TreeScope* newScope = &insertionPoint.treeScope();
HTMLDocument* newDocument = !wasInDocument && inDocument() && newScope->documentScope()->isHTMLDocument() ? toHTMLDocument(newScope->documentScope()) : 0;
- if (newScope != treeScope())
+ if (newScope != &treeScope())
newScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (newScope)
- updateIdForTreeScope(newScope, nullAtom, idValue);
+ updateIdForTreeScope(*newScope, nullAtom, idValue);
if (newDocument)
updateIdForDocument(*newDocument, nullAtom, idValue, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (newScope)
- updateNameForTreeScope(newScope, nullAtom, nameValue);
+ updateNameForTreeScope(*newScope, nullAtom, nameValue);
if (newDocument)
updateNameForDocument(*newDocument, nullAtom, nameValue);
}
if (newScope && hasTagName(labelTag)) {
if (newScope->shouldCacheLabelsByForAttribute())
- updateLabel(newScope, nullAtom, fastGetAttribute(forAttr));
+ updateLabel(*newScope, nullAtom, fastGetAttribute(forAttr));
}
return InsertionDone;
setSavedLayerScrollOffset(IntSize());
if (insertionPoint.isInTreeScope()) {
- TreeScope* oldScope = insertionPoint.treeScope();
+ TreeScope* oldScope = &insertionPoint.treeScope();
HTMLDocument* oldDocument = inDocument() && oldScope->documentScope()->isHTMLDocument() ? toHTMLDocument(oldScope->documentScope()) : 0;
- if (oldScope != treeScope())
+ if (oldScope != &treeScope())
oldScope = 0;
const AtomicString& idValue = getIdAttribute();
if (!idValue.isNull()) {
if (oldScope)
- updateIdForTreeScope(oldScope, idValue, nullAtom);
+ updateIdForTreeScope(*oldScope, idValue, nullAtom);
if (oldDocument)
updateIdForDocument(*oldDocument, idValue, nullAtom, AlwaysUpdateHTMLDocumentNamedItemMaps);
}
const AtomicString& nameValue = getNameAttribute();
if (!nameValue.isNull()) {
if (oldScope)
- updateNameForTreeScope(oldScope, nameValue, nullAtom);
+ updateNameForTreeScope(*oldScope, nameValue, nullAtom);
if (oldDocument)
updateNameForDocument(*oldDocument, nameValue, nullAtom);
}
if (oldScope && hasTagName(labelTag)) {
if (oldScope->shouldCacheLabelsByForAttribute())
- updateLabel(oldScope, fastGetAttribute(forAttr), nullAtom);
+ updateLabel(*oldScope, fastGetAttribute(forAttr), nullAtom);
}
}
ensureElementRareData().setShadowRoot(newShadowRoot);
shadowRoot->setHostElement(this);
- shadowRoot->setParentTreeScope(treeScope());
+ shadowRoot->setParentTreeScope(&treeScope());
shadowRoot->distributor().didShadowBoundaryChange(this);
ChildNodeInsertionNotifier(*this).notify(*shadowRoot);
setAttributeInternal(index, attrNode->qualifiedName(), attrNode->value(), NotInSynchronizationOfLazyAttribute);
attrNode->attachToElement(this);
- treeScope()->adoptIfNeeded(attrNode);
+ treeScope().adoptIfNeeded(attrNode);
ensureAttrNodeListForElement(this).append(attrNode);
return oldAttrNode.release();
void Element::blur()
{
cancelFocusAppearanceUpdate();
- if (treeScope()->focusedElement() == this) {
+ if (treeScope().focusedElement() == this) {
if (Frame* frame = document().frame())
frame->page()->focusController().setFocusedElement(0, frame);
else
updateNameForDocument(toHTMLDocument(document()), oldName, newName);
}
-void Element::updateNameForTreeScope(TreeScope* scope, const AtomicString& oldName, const AtomicString& newName)
+void Element::updateNameForTreeScope(TreeScope& scope, const AtomicString& oldName, const AtomicString& newName)
{
ASSERT(isInTreeScope());
ASSERT(oldName != newName);
if (!oldName.isEmpty())
- scope->removeElementByName(*oldName.impl(), *this);
+ scope.removeElementByName(*oldName.impl(), *this);
if (!newName.isEmpty())
- scope->addElementByName(*newName.impl(), *this);
+ scope.addElementByName(*newName.impl(), *this);
}
void Element::updateNameForDocument(HTMLDocument& document, const AtomicString& oldName, const AtomicString& newName)
updateIdForDocument(toHTMLDocument(document()), oldId, newId, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute);
}
-void Element::updateIdForTreeScope(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
+void Element::updateIdForTreeScope(TreeScope& scope, const AtomicString& oldId, const AtomicString& newId)
{
ASSERT(isInTreeScope());
ASSERT(oldId != newId);
if (!oldId.isEmpty())
- scope->removeElementById(*oldId.impl(), *this);
+ scope.removeElementById(*oldId.impl(), *this);
if (!newId.isEmpty())
- scope->addElementById(*newId.impl(), *this);
+ scope.addElementById(*newId.impl(), *this);
}
void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition condition)
}
}
-void Element::updateLabel(TreeScope* scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
+void Element::updateLabel(TreeScope& scope, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue)
{
ASSERT(hasTagName(labelTag));
return;
if (!oldForAttributeValue.isEmpty())
- scope->removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
+ scope.removeLabel(*oldForAttributeValue.impl(), *toHTMLLabelElement(this));
if (!newForAttributeValue.isEmpty())
- scope->addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
+ scope.addLabel(*newForAttributeValue.impl(), *toHTMLLabelElement(this));
}
void Element::willModifyAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue)
else if (name == HTMLNames::nameAttr)
updateName(oldValue, newValue);
else if (name == HTMLNames::forAttr && hasTagName(labelTag)) {
- TreeScope* scope = treeScope();
- if (scope->shouldCacheLabelsByForAttribute())
- updateLabel(scope, oldValue, newValue);
+ if (treeScope().shouldCacheLabelsByForAttribute())
+ updateLabel(treeScope(), oldValue, newValue);
}
if (oldValue != newValue) {
RefPtr<Attr> attrNode = findAttrNodeInList(attrNodeList, name);
if (!attrNode) {
attrNode = Attr::create(this, name);
- treeScope()->adoptIfNeeded(attrNode.get());
+ treeScope().adoptIfNeeded(attrNode.get());
attrNodeList.append(attrNode);
}
return attrNode.release();
void synchronizeAttribute(const AtomicString& localName) const;
void updateName(const AtomicString& oldName, const AtomicString& newName);
- void updateNameForTreeScope(TreeScope*, const AtomicString& oldName, const AtomicString& newName);
+ void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
void updateId(const AtomicString& oldId, const AtomicString& newId);
- void updateIdForTreeScope(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
+ void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId);
enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
- void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
+ void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
void scrollByUnits(int units, ScrollGranularity);
inline bool EventContext::isReachable(Node* target) const
{
ASSERT(target);
- TreeScope* targetScope = target->treeScope();
- for (TreeScope* scope = m_node->treeScope(); scope; scope = scope->parentTreeScope()) {
- if (scope == targetScope)
+ TreeScope& targetScope = target->treeScope();
+ for (TreeScope* scope = &m_node->treeScope(); scope; scope = scope->parentTreeScope()) {
+ if (scope == &targetScope)
return true;
}
return false;
static inline bool inTheSameScope(ShadowRoot* shadowRoot, EventTarget* target)
{
- return target->toNode() && target->toNode()->treeScope()->rootNode() == shadowRoot;
+ return target->toNode() && target->toNode()->treeScope().rootNode() == shadowRoot;
}
static inline EventDispatchBehavior determineDispatchBehavior(Event* event, ShadowRoot* shadowRoot, EventTarget* target)
TreeScope* lastTreeScope = 0;
Node* adjustedNode = 0;
for (EventPath::const_iterator iter = eventPath.begin(); iter < eventPath.end(); ++iter) {
- TreeScope* scope = (*iter)->node()->treeScope();
+ TreeScope* scope = &(*iter)->node()->treeScope();
if (scope == lastTreeScope) {
// Re-use the previous adjustedRelatedTarget if treeScope does not change. Just for the performance optimization.
adjustedNodes.append(adjustedNode);
if (eventWithRelatedTargetDispatchBehavior == DoesNotStopAtBoundary)
continue;
if (targetIsIdenticalToToRelatedTarget) {
- if (node->treeScope()->rootNode() == (*iter)->node()) {
+ if (node->treeScope().rootNode() == (*iter)->node()) {
eventPath.shrink(iter + 1 - eventPath.begin());
break;
}
for (Node* node = nodeOrHostIfPseudoElement(const_cast<Node*>(relatedNode)); node; node = node->parentOrShadowHostNode()) {
if (relatedNodeStack.isEmpty())
relatedNodeStack.append(node);
- TreeScope* scope = node->treeScope();
+ TreeScope* scope = &node->treeScope();
// Skips adding a node to the map if treeScope does not change. Just for the performance optimization.
if (scope != lastTreeScope)
relatedNodeMap.add(scope, relatedNodeStack.last());
// Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
// as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
- Node* rootNode = referenceNode->treeScope()->rootNode();
+ Node* rootNode = referenceNode->treeScope().rootNode();
Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
// At this time, SVG nodes are not supported in non-<use> shadow trees.
if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
Node* rootNode = this->rootNode();
if (rootNode->inDocument()) {
- Element* element = rootNode->treeScope()->getElementById(elementId);
+ Element* element = rootNode->treeScope().getElementById(elementId);
if (element && nodeMatches(element) && element->isDescendantOf(rootNode))
return element;
if (!element)
ShadowRoot* Node::containingShadowRoot() const
{
- ContainerNode* root = treeScope()->rootNode();
+ ContainerNode* root = treeScope().rootNode();
return root && root->isShadowRoot() ? toShadowRoot(root) : 0;
}
ASSERT(insertionPoint.inDocument() || isContainerNode());
if (insertionPoint.inDocument())
clearFlag(InDocumentFlag);
- if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
+ if (isInShadowTree() && !treeScope().rootNode()->isShadowRoot())
clearFlag(IsInShadowTreeFlag);
}
// If the nodes have different owning documents, they must be disconnected. Note that we avoid
// comparing Attr nodes here, since they return false from inDocument() all the time (which seems like a bug).
if (start1->inDocument() != start2->inDocument() ||
- start1->treeScope() != start2->treeScope())
+ &start1->treeScope() != &start2->treeScope())
return compareDetachedElementsPosition(this, otherNode);
// We need to find a common ancestor container, and then compare the indices of the two immediate children.
// faster for non-Document nodes, and because the call to removedLastRef that is inlined
// at all deref call sites is smaller if it's a non-virtual function.
if (isTreeScope()) {
- treeScope()->removedLastRefToScope();
+ treeScope().removedLastRefToScope();
return;
}
return *documentInternal();
}
- TreeScope* treeScope() const { return m_treeScope; }
+ TreeScope& treeScope() const
+ {
+ ASSERT(m_treeScope);
+ return *m_treeScope;
+ }
// Returns true if this node is associated with a document and is in its associated document's
// node tree, false otherwise.
void setNeedsNodeRenderingTraversalSlowPath(bool flag) { setFlag(flag, NeedsNodeRenderingTraversalSlowPathFlag); }
- Document* documentInternal() const { return treeScope()->documentScope(); }
- void setTreeScope(TreeScope* scope) { m_treeScope = scope; }
+ Document* documentInternal() const { return treeScope().documentScope(); }
+ void setTreeScope(TreeScope& scope) { m_treeScope = &scope; }
void setStyleChange(StyleChangeType changeType) { m_nodeFlags = (m_nodeFlags & ~StyleChangeMask) | changeType; }
ASSERT(idSelector);
const AtomicString& idToMatch = idSelector->value();
- if (UNLIKELY(rootNode->treeScope()->containsMultipleElementsWithId(idToMatch))) {
- const Vector<Element*>* elements = rootNode->treeScope()->getAllElementsById(idToMatch);
+ if (UNLIKELY(rootNode->treeScope().containsMultipleElementsWithId(idToMatch))) {
+ const Vector<Element*>* elements = rootNode->treeScope().getAllElementsById(idToMatch);
ASSERT(elements);
size_t count = elements->size();
bool rootNodeIsTreeScopeRoot = isTreeScopeRoot(rootNode);
return;
}
- Element* element = rootNode->treeScope()->getElementById(idToMatch);
+ Element* element = rootNode->treeScope().getElementById(idToMatch);
if (!element || !(isTreeScopeRoot(rootNode) || element->isDescendantOf(rootNode)))
return;
if (selectorMatches(selectorData, element, rootNode))
inline Element* ShadowRoot::activeElement() const
{
- return treeScope()->focusedElement();
+ return treeScope().focusedElement();
}
inline const ShadowRoot* toShadowRoot(const Node* node)
ASSERT(document);
ASSERT(rootNode != document);
m_parentTreeScope->selfOnlyRef();
- m_rootNode->setTreeScope(this);
+ m_rootNode->setTreeScope(*this);
}
TreeScope::TreeScope(Document* document)
, m_idTargetObserverRegistry(IdTargetObserverRegistry::create())
{
ASSERT(document);
- m_rootNode->setTreeScope(this);
+ m_rootNode->setTreeScope(*this);
}
TreeScope::TreeScope()
Node* TreeScope::ancestorInThisScope(Node* node) const
{
while (node) {
- if (node->treeScope() == this)
+ if (&node->treeScope() == this)
return node;
if (!node->isInShadowTree())
return 0;
ASSERT(node);
ASSERT(!node->isDocumentNode());
ASSERT(!node->m_deletionHasBegun);
- TreeScopeAdopter adopter(node, this);
+ TreeScopeAdopter adopter(node, *this);
if (adopter.needsScopeChange())
adopter.execute();
}
element = focusedFrameOwnerElement(document.page()->focusController().focusedFrame(), document.frame());
if (!element)
return 0;
- TreeScope* treeScope = element->treeScope();
+ TreeScope* treeScope = &element->treeScope();
while (treeScope != this && treeScope != &document) {
element = toShadowRoot(treeScope->rootNode())->hostElement();
- treeScope = element->treeScope();
+ treeScope = &element->treeScope();
}
if (this != treeScope)
return 0;
static void listTreeScopes(Node* node, Vector<TreeScope*, 5>& treeScopes)
{
while (true) {
- treeScopes.append(node->treeScope());
+ treeScopes.append(&node->treeScope());
Element* ancestor = node->shadowHost();
if (!ancestor)
break;
if (!nodeA || !nodeB)
return 0;
- if (nodeA->treeScope() == nodeB->treeScope())
- return nodeA->treeScope();
+ if (&nodeA->treeScope() == &nodeB->treeScope())
+ return &nodeA->treeScope();
Vector<TreeScope*, 5> treeScopesA;
listTreeScopes(nodeA, treeScopesA);
void TreeScope::beginDeletion()
{
- ASSERT(this != noDocumentInstance());
+ ASSERT(this != &noDocumentInstance());
rootNode()->m_deletionHasBegun = true;
}
#endif
IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
- static TreeScope* noDocumentInstance()
+ static TreeScope& noDocumentInstance()
{
DEFINE_STATIC_LOCAL(TreeScope, instance, ());
- return &instance;
+ return instance;
}
// Nodes belonging to this scope hold self-only references -
{
ASSERT(!deletionHasBegun());
--m_selfOnlyRefCount;
- if (!m_selfOnlyRefCount && !refCount() && this != noDocumentInstance()) {
+ if (!m_selfOnlyRefCount && !refCount() && this != &noDocumentInstance()) {
beginDeletion();
delete this;
}
void setDocumentScope(Document* document)
{
ASSERT(document);
- ASSERT(this != noDocumentInstance());
+ ASSERT(this != &noDocumentInstance());
m_documentScope = document;
}
{
ASSERT(needsScopeChange());
- m_oldScope->selfOnlyRef();
+ m_oldScope.selfOnlyRef();
// If an element is moved from a document and then eventually back again the collection cache for
// that element may contain stale data as changes made to it will have updated the DOMTreeVersion
// of the document it was moved to. By increasing the DOMTreeVersion of the donating document here
// we ensure that the collection cache will be invalidated as needed when the element is moved back.
- Document* oldDocument = m_oldScope->documentScope();
- Document* newDocument = m_newScope->documentScope();
+ Document* oldDocument = m_oldScope.documentScope();
+ Document* newDocument = m_newScope.documentScope();
bool willMoveToNewDocument = oldDocument != newDocument;
if (oldDocument && willMoveToNewDocument)
oldDocument->incDOMTreeVersion();
}
if (ShadowRoot* shadow = node->shadowRoot()) {
- shadow->setParentTreeScope(m_newScope);
+ shadow->setParentTreeScope(&m_newScope);
if (willMoveToNewDocument)
moveTreeToNewDocument(shadow, oldDocument, newDocument);
}
}
- m_oldScope->selfOnlyDeref();
+ m_oldScope.selfOnlyDeref();
}
void TreeScopeAdopter::moveTreeToNewDocument(Node* root, Document* oldDocument, Document* newDocument) const
inline void TreeScopeAdopter::updateTreeScope(Node* node) const
{
ASSERT(!node->isTreeScope());
- ASSERT(node->treeScope() == m_oldScope);
- m_newScope->selfOnlyRef();
- m_oldScope->selfOnlyDeref();
+ ASSERT(&node->treeScope() == &m_oldScope);
+ m_newScope.selfOnlyRef();
+ m_oldScope.selfOnlyDeref();
node->setTreeScope(m_newScope);
}
class TreeScopeAdopter {
public:
- explicit TreeScopeAdopter(Node* toAdopt, TreeScope* newScope);
+ explicit TreeScopeAdopter(Node* toAdopt, TreeScope& newScope);
void execute() const { moveTreeToNewScope(m_toAdopt); }
- bool needsScopeChange() const { return m_oldScope != m_newScope; }
+ bool needsScopeChange() const { return &m_oldScope != &m_newScope; }
#ifdef NDEBUG
static void ensureDidMoveToNewDocumentWasCalled(Document*) { }
void moveNodeToNewDocument(Node*, Document* oldDocument, Document* newDocument) const;
Node* m_toAdopt;
- TreeScope* m_newScope;
- TreeScope* m_oldScope;
+ TreeScope& m_newScope;
+ TreeScope& m_oldScope;
};
-inline TreeScopeAdopter::TreeScopeAdopter(Node* toAdopt, TreeScope* newScope)
+inline TreeScopeAdopter::TreeScopeAdopter(Node* toAdopt, TreeScope& newScope)
: m_toAdopt(toAdopt)
, m_newScope(newScope)
, m_oldScope(toAdopt->treeScope())
{
- ASSERT(newScope);
}
}
return selectionRoot;
Node* node = m_selection.base().containerNode();
- return node ? node->treeScope()->rootNode() : 0;
+ return node ? node->treeScope().rootNode() : 0;
}
Element* FrameSelection::rootEditableElementRespectingShadowTree() const
static Position adjustPositionForEnd(const Position& currentPosition, Node* startContainerNode)
{
- TreeScope* treeScope = startContainerNode->treeScope();
+ TreeScope& treeScope = startContainerNode->treeScope();
- ASSERT(currentPosition.containerNode()->treeScope() != treeScope);
+ ASSERT(¤tPosition.containerNode()->treeScope() != &treeScope);
- if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.containerNode())) {
+ if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.containerNode())) {
if (ancestor->contains(startContainerNode))
return positionAfterNode(ancestor);
return positionBeforeNode(ancestor);
}
- if (Node* lastChild = treeScope->rootNode()->lastChild())
+ if (Node* lastChild = treeScope.rootNode()->lastChild())
return positionAfterNode(lastChild);
return Position();
static Position adjustPositionForStart(const Position& currentPosition, Node* endContainerNode)
{
- TreeScope* treeScope = endContainerNode->treeScope();
+ TreeScope& treeScope = endContainerNode->treeScope();
- ASSERT(currentPosition.containerNode()->treeScope() != treeScope);
+ ASSERT(¤tPosition.containerNode()->treeScope() != &treeScope);
- if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.containerNode())) {
+ if (Node* ancestor = treeScope.ancestorInThisScope(currentPosition.containerNode())) {
if (ancestor->contains(endContainerNode))
return positionBeforeNode(ancestor);
return positionAfterNode(ancestor);
}
- if (Node* firstChild = treeScope->rootNode()->firstChild())
+ if (Node* firstChild = treeScope.rootNode()->firstChild())
return positionBeforeNode(firstChild);
return Position();
if (m_base.isNull() || m_start.isNull() || m_end.isNull())
return;
- if (m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope())
+ if (&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope())
return;
if (m_baseIsFirst) {
m_start = m_extent;
}
- ASSERT(m_start.anchorNode()->treeScope() == m_end.anchorNode()->treeScope());
+ ASSERT(&m_start.anchorNode()->treeScope() == &m_end.anchorNode()->treeScope());
}
void VisibleSelection::adjustSelectionToAvoidCrossingEditingBoundaries()
Position p = position;
- if (position.deprecatedNode()->treeScope() != highestRoot->treeScope()) {
- Node* shadowAncestor = highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode());
+ if (&position.deprecatedNode()->treeScope() != &highestRoot->treeScope()) {
+ Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(p.deprecatedNode());
if (!shadowAncestor)
return VisiblePosition();
Position p = position;
- if (position.deprecatedNode()->treeScope() != highestRoot->treeScope()) {
- Node* shadowAncestor = highestRoot->treeScope()->ancestorInThisScope(p.deprecatedNode());
+ if (&position.deprecatedNode()->treeScope() != &highestRoot->treeScope()) {
+ Node* shadowAncestor = highestRoot->treeScope().ancestorInThisScope(p.deprecatedNode());
if (!shadowAncestor)
return VisiblePosition();
// The HTML5 spec says that the element should be associated with
// the first element in the document to have an ID that equal to
// the value of form attribute, so we put the result of
- // treeScope()->getElementById() over the given element.
+ // treeScope().getElementById() over the given element.
HTMLFormElement* newForm = 0;
- Element* newFormCandidate = element->treeScope()->getElementById(formId);
+ Element* newFormCandidate = element->treeScope().getElementById(formId);
if (newFormCandidate && isHTMLFormElement(newFormCandidate))
newForm = toHTMLFormElement(newFormCandidate);
return newForm;
}
FormAttributeTargetObserver::FormAttributeTargetObserver(const AtomicString& id, FormAssociatedElement* element)
- : IdTargetObserver(toHTMLElement(element)->treeScope()->idTargetObserverRegistry(), id)
+ : IdTargetObserver(toHTMLElement(element)->treeScope().idTargetObserverRegistry(), id)
, m_element(element)
{
}
return 0;
if (!overridesItemAfter() && root->isInTreeScope()) {
- TreeScope* treeScope = root->treeScope();
+ TreeScope& treeScope = root->treeScope();
Element* candidate = 0;
- if (treeScope->hasElementWithId(*name.impl())) {
- if (!treeScope->containsMultipleElementsWithId(name))
- candidate = treeScope->getElementById(name);
- } else if (treeScope->hasElementWithName(*name.impl())) {
- if (!treeScope->containsMultipleElementsWithName(name)) {
- candidate = treeScope->getElementByName(name);
+ if (treeScope.hasElementWithId(*name.impl())) {
+ if (!treeScope.containsMultipleElementsWithId(name))
+ candidate = treeScope.getElementById(name);
+ } else if (treeScope.hasElementWithName(*name.impl())) {
+ if (!treeScope.containsMultipleElementsWithName(name)) {
+ candidate = treeScope.getElementByName(name);
if (candidate && type() == DocAll && (!candidate->isHTMLElement() || !nameShouldBeVisibleInDocumentAll(toHTMLElement(candidate))))
candidate = 0;
}
void HTMLDataListElement::optionElementChildrenChanged()
{
- treeScope()->idTargetObserverRegistry().notifyObservers(getIdAttribute());
+ treeScope().idTargetObserverRegistry().notifyObservers(getIdAttribute());
}
} // namespace WebCore
Element* HTMLDocument::activeElement()
{
- if (Element* element = treeScope()->focusedElement())
+ if (Element* element = treeScope().focusedElement())
return element;
return body();
}
if (!m_inputType->shouldRespectListAttribute())
return 0;
- Element* element = treeScope()->getElementById(fastGetAttribute(listAttr));
+ Element* element = treeScope().getElementById(fastGetAttribute(listAttr));
if (!element)
return 0;
if (!element->hasTagName(datalistTag))
}
ListAttributeTargetObserver::ListAttributeTargetObserver(const AtomicString& id, HTMLInputElement* element)
- : IdTargetObserver(element->treeScope()->idTargetObserverRegistry(), id)
+ : IdTargetObserver(element->treeScope().idTargetObserverRegistry(), id)
, m_element(element)
{
}
// Find the first element whose id is controlId. If it is found and it is a labelable form control,
// return it, otherwise return 0.
- return nodeAsSupportedLabelableElement(treeScope()->getElementById(controlId));
+ return nodeAsSupportedLabelableElement(treeScope().getElementById(controlId));
}
HTMLFormElement* HTMLLabelElement::form() const
return;
}
if (inDocument())
- treeScope()->removeImageMap(*this);
+ treeScope().removeImageMap(*this);
String mapName = value;
if (mapName[0] == '#')
mapName = mapName.substring(1);
m_name = document().isHTMLDocument() ? mapName.lower() : mapName;
if (inDocument())
- treeScope()->addImageMap(*this);
+ treeScope().addImageMap(*this);
return;
}
Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode& insertionPoint)
{
if (insertionPoint.inDocument())
- treeScope()->addImageMap(*this);
+ treeScope().addImageMap(*this);
return HTMLElement::insertedInto(insertionPoint);
}
void HTMLMapElement::removedFrom(ContainerNode& insertionPoint)
{
if (insertionPoint.inDocument())
- treeScope()->removeImageMap(*this);
+ treeScope().removeImageMap(*this);
HTMLElement::removedFrom(insertionPoint);
}
// be rendered. So this should return false for most of the children.
// One exception is a shadow tree built for rendering controls which should be visible.
// So we let them go here by comparing its subtree root with one of the controls.
- return mediaControls()->treeScope() == child->treeScope()
+ return &mediaControls()->treeScope() == &child->treeScope()
&& hasShadowRootParent(child)
&& HTMLElement::childShouldCreateRenderer(child);
#endif
{
if (validationMessageClient() || !m_bubble)
return false;
- return m_bubble->treeScope() == node->treeScope();
+ return &m_bubble->treeScope() == &node->treeScope();
}
void ValidationMessage::deleteBubbleTree(Timer<ValidationMessage>*)
HTMLInputElement* inputElement = node->toInputElement();
// If this is a button inside of the a file input, move up to the file input.
- if (inputElement && inputElement->isTextButton() && inputElement->treeScope()->rootNode()->isShadowRoot())
- inputElement = toShadowRoot(inputElement->treeScope()->rootNode())->hostElement()->toInputElement();
+ if (inputElement && inputElement->isTextButton() && inputElement->treeScope().rootNode()->isShadowRoot())
+ inputElement = toShadowRoot(inputElement->treeScope().rootNode())->hostElement()->toInputElement();
return inputElement && inputElement->isFileUpload() ? inputElement : 0;
}
root = n;
// The result is not always a ShadowRoot nor a DocumentNode since
// a starting node is in an orphaned tree in composed shadow tree.
- return FocusNavigationScope(root->treeScope());
+ return FocusNavigationScope(&root->treeScope());
}
FocusNavigationScope FocusNavigationScope::focusNavigationScopeOwnedByShadowHost(Node* node)
HTMLFrameOwnerElement* owner = document->ownerElement();
if (!owner)
return false;
- return owner->treeScope() == &scope;
+ return &owner->treeScope() == &scope;
}
inline Frame* FrameTree::scopedChild(unsigned index, TreeScope* scope) const
HTMLMapElement* RenderImage::imageMap() const
{
HTMLImageElement* i = element() && isHTMLImageElement(element()) ? toHTMLImageElement(element()) : 0;
- return i ? i->treeScope()->getImageMap(i->fastGetAttribute(usemapAttr)) : 0;
+ return i ? i->treeScope().getImageMap(i->fastGetAttribute(usemapAttr)) : 0;
}
bool RenderImage::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
String url = stripLeadingAndTrailingHTMLSpaces(href());
if (url[0] == '#') {
- Element* targetElement = treeScope()->getElementById(url.substring(1));
+ Element* targetElement = treeScope().getElementById(url.substring(1));
if (SVGSMILElement::isSMILElement(targetElement)) {
toSVGSMILElement(targetElement)->beginByLinkActivation();
event->setDefaultHandled();
// Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
if (isInShadowTree()) {
- Element* shadowHostElement = toShadowRoot(treeScope()->rootNode())->hostElement();
+ Element* shadowHostElement = toShadowRoot(treeScope().rootNode())->hostElement();
// At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
// have should be a use. The assert and following test is here to catch future shadow DOM changes
// that do enable SVG in a shadow tree.
// See http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGSVGElement
Element* SVGSVGElement::getElementById(const AtomicString& id)
{
- Element* element = treeScope()->getElementById(id);
+ Element* element = treeScope().getElementById(id);
if (element && element->isDescendantOf(this))
return element;
{
if (!m_contextElement)
return 0;
- Element* element = m_contextElement->treeScope()->getElementById(m_viewTargetString);
+ Element* element = m_contextElement->treeScope().getElementById(m_viewTargetString);
if (!element || !element->isSVGElement())
return 0;
return toSVGElement(element);
inline Element* SVGSMILElement::eventBaseFor(const Condition& condition)
{
- return condition.m_baseID.isEmpty() ? targetElement() : treeScope()->getElementById(condition.m_baseID);
+ return condition.m_baseID.isEmpty() ? targetElement() : treeScope().getElementById(condition.m_baseID);
}
void SVGSMILElement::connectConditions()
eventBase->addEventListener(condition.m_name, condition.m_eventListener, false);
} else if (condition.m_type == Condition::Syncbase) {
ASSERT(!condition.m_baseID.isEmpty());
- condition.m_syncbase = treeScope()->getElementById(condition.m_baseID);
+ condition.m_syncbase = treeScope().getElementById(condition.m_baseID);
if (!isSMILElement(condition.m_syncbase.get())) {
condition.m_syncbase = 0;
continue;
return 0;
}
- return node->treeScope()->rootNode();
+ return node->treeScope().rootNode();
}
Node* Internals::parentTreeScope(Node* node, ExceptionCode& ec)
ec = INVALID_ACCESS_ERR;
return 0;
}
- const TreeScope* parentTreeScope = node->treeScope()->parentTreeScope();
+ const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
return parentTreeScope ? parentTreeScope->rootNode() : 0;
}
idList.append(str);
}
- TreeScope* contextScope = evaluationContext().node->treeScope();
+ TreeScope& contextScope = evaluationContext().node->treeScope();
NodeSet result;
HashSet<Node*> resultSet;
// If there are several nodes with the same id, id() should return the first one.
// In WebKit, getElementById behaves so, too, although its behavior in this case is formally undefined.
- Node* node = contextScope->getElementById(String(idList.characters() + startPos, endPos - startPos));
+ Node* node = contextScope.getElementById(String(idList.characters() + startPos, endPos - startPos));
if (node && resultSet.add(node).isNewEntry)
result.append(node);