+2017-02-02 Chris Dumez <cdumez@apple.com>
+
+ Rename Node::inDocument() to isConnected()
+ https://bugs.webkit.org/show_bug.cgi?id=167743
+
+ Reviewed by Sam Weinig.
+
+ Rename Node::inDocument() to isConnected() to match the DOM specification more closely:
+ - https://dom.spec.whatwg.org/#connected
+
2017-02-02 Antoine Quint <graouts@apple.com>
[Modern Media Controls] Provide a compact mode for when the controls are small
// Check each node to see if it's inside the document being deleted, of if it no longer belongs to a document.
HashSet<Node*> nodesToDelete;
for (const auto& node : m_textMarkerNodes) {
- if (!node->inDocument() || &(node)->document() == document)
+ if (!node->isConnected() || &(node)->document() == document)
nodesToDelete.add(node);
}
static inline bool isReachableFromDOM(Node* node, SlotVisitor& visitor)
{
- if (!node->inDocument()) {
+ if (!node->isConnected()) {
if (is<Element>(*node)) {
auto& element = downcast<Element>(*node);
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedEvent, true, c->parentNode()));
// dispatch the DOMNodeInsertedIntoDocument event to all descendants
- if (c->inDocument() && document->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) {
+ if (c->isConnected() && document->hasListenerType(Document::DOMNODEINSERTEDINTODOCUMENT_LISTENER)) {
for (; c; c = NodeTraversal::next(*c, &child))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeInsertedIntoDocumentEvent, false));
}
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemovedEvent, true, c->parentNode()));
// dispatch the DOMNodeRemovedFromDocument event to all descendants
- if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {
+ if (c->isConnected() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {
for (; c; c = NodeTraversal::next(*c, &child))
c->dispatchScopedEvent(MutationEvent::create(eventNames().DOMNodeRemovedFromDocumentEvent, false));
}
// If we have been removed from the document during this loop, then
// we don't want to tell the rest of our children that they've been
// inserted into the document because they haven't.
- if (node.inDocument() && child->parentNode() == &node)
+ if (node.isConnected() && child->parentNode() == &node)
notifyNodeInsertedIntoDocument(insertionPoint, *child, postInsertionNotificationTargets);
}
return;
if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot()) {
- if (node.inDocument() && root->host() == &node)
+ if (node.isConnected() && root->host() == &node)
notifyNodeInsertedIntoDocument(insertionPoint, *root, postInsertionNotificationTargets);
}
}
void notifyNodeInsertedIntoDocument(ContainerNode& insertionPoint, Node& node, NodeVector& postInsertionNotificationTargets)
{
- ASSERT(insertionPoint.inDocument());
+ ASSERT(insertionPoint.isConnected());
if (node.insertedInto(insertionPoint) == Node::InsertionShouldCallFinishedInsertingSubtree)
postInsertionNotificationTargets.append(node);
if (is<ContainerNode>(node))
void notifyNodeInsertedIntoTree(ContainerNode& insertionPoint, ContainerNode& node, NodeVector& postInsertionNotificationTargets)
{
NoEventDispatchAssertion assertNoEventDispatch;
- ASSERT(!insertionPoint.inDocument());
+ ASSERT(!insertionPoint.isConnected());
if (node.insertedInto(insertionPoint) == Node::InsertionShouldCallFinishedInsertingSubtree)
postInsertionNotificationTargets.append(node);
Ref<Document> protectDocument(node.document());
Ref<Node> protectNode(node);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
notifyNodeInsertedIntoDocument(insertionPoint, node, postInsertionNotificationTargets);
else if (is<ContainerNode>(node))
notifyNodeInsertedIntoTree(insertionPoint, downcast<ContainerNode>(node), postInsertionNotificationTargets);
void notifyNodeRemovedFromDocument(ContainerNode& insertionPoint, Node& node)
{
- ASSERT(insertionPoint.inDocument());
+ ASSERT(insertionPoint.isConnected());
node.removedFrom(insertionPoint);
if (!is<ContainerNode>(node))
// If we have been added to the document during this loop, then we
// don't want to tell the rest of our children that they've been
// removed from the document because they haven't.
- if (!node.inDocument() && child->parentNode() == &node)
+ if (!node.isConnected() && child->parentNode() == &node)
notifyNodeRemovedFromDocument(insertionPoint, *child.get());
}
node.document().setCSSTarget(nullptr);
if (RefPtr<ShadowRoot> root = downcast<Element>(node).shadowRoot()) {
- if (!node.inDocument() && root->host() == &node)
+ if (!node.isConnected() && root->host() == &node)
notifyNodeRemovedFromDocument(insertionPoint, *root.get());
}
}
void notifyNodeRemovedFromTree(ContainerNode& insertionPoint, ContainerNode& node)
{
NoEventDispatchAssertion assertNoEventDispatch;
- ASSERT(!insertionPoint.inDocument());
+ ASSERT(!insertionPoint.isConnected());
node.removedFrom(insertionPoint);
void notifyChildNodeRemoved(ContainerNode& insertionPoint, Node& child)
{
- if (!child.inDocument()) {
+ if (!child.isConnected()) {
if (is<ContainerNode>(child))
notifyNodeRemovedFromTree(insertionPoint, downcast<ContainerNode>(child));
return;
void CustomElementReactionQueue::enqueueElementUpgradeIfDefined(Element& element)
{
- ASSERT(element.inDocument());
+ ASSERT(element.isConnected());
ASSERT(element.isCustomElementUpgradeCandidate());
auto* window = element.document().domWindow();
if (!window)
void CustomElementReactionQueue::enqueuePostUpgradeReactions(Element& element)
{
ASSERT(element.isCustomElementUpgradeCandidate());
- if (!element.hasAttributes() && !element.inDocument())
+ if (!element.hasAttributes() && !element.isConnected())
return;
auto* queue = element.reactionQueue();
}
}
- if (element.inDocument() && queue->m_interface->hasConnectedCallback())
+ if (element.isConnected() && queue->m_interface->hasConnectedCallback())
queue->m_items.append({CustomElementReactionQueueItem::Type::Connected});
}
return;
CachedImage* image = nullptr;
- if (is<HTMLImageElement>(element) && !element->inDocument())
+ if (is<HTMLImageElement>(element) && !element->isConnected())
image = downcast<HTMLImageElement>(*element).cachedImage();
m_dragLocation = IntPoint(x, y);
// node document:
// The context object is not in a document.
- if (!element->inDocument())
+ if (!element->isConnected())
break;
// The context object's node document, or an ancestor browsing context's document does not have
// If doc's fullscreen element stack is non-empty and the element now at the top is either
// not in a document or its node document is not doc, repeat this substep.
newTop = currentDoc->webkitFullscreenElement();
- if (newTop && (!newTop->inDocument() || &newTop->document() != currentDoc))
+ if (newTop && (!newTop->isConnected() || &newTop->document() != currentDoc))
continue;
// 2. Queue a task to fire an event named fullscreenchange with its bubbles attribute set to true
// If the element was removed from our tree, also message the documentElement. Since we may
// have a document hierarchy, check that node isn't in another document.
- if (!node->inDocument())
+ if (!node->isConnected())
queue.append(documentElement());
#if ENABLE(VIDEO)
void Document::didInsertInDocumentShadowRoot(ShadowRoot& shadowRoot)
{
- ASSERT(shadowRoot.inDocument());
+ ASSERT(shadowRoot.isConnected());
ASSERT(!m_inDocumentShadowRoots.contains(&shadowRoot));
m_inDocumentShadowRoots.add(&shadowRoot);
}
bool Element::isFocusable() const
{
- if (!inDocument() || !supportsFocus())
+ if (!isConnected() || !supportsFocus())
return false;
if (!renderer()) {
void Element::parserSetAttributes(const Vector<Attribute>& attributeVector)
{
- ASSERT(!inDocument());
+ ASSERT(!isConnected());
ASSERT(!parentNode());
ASSERT(!m_elementData);
Node::InsertionNotificationRequest Element::insertedInto(ContainerNode& insertionPoint)
{
- bool wasInDocument = inDocument();
- // need to do superclass processing first so inDocument() is true
+ bool wasInDocument = isConnected();
+ // need to do superclass processing first so isConnected() is true
// by the time we reach updateId
ContainerNode::insertedInto(insertionPoint);
- ASSERT(!wasInDocument || inDocument());
+ ASSERT(!wasInDocument || isConnected());
#if ENABLE(FULLSCREEN_API)
if (containsFullScreenElement() && parentElement() && !parentElement()->containsFullScreenElement())
// This element is new to the shadow tree (and its tree scope) only if the parent into which this element
// or its ancestor is inserted belongs to the same tree scope as this element's.
TreeScope* newScope = &insertionPoint.treeScope();
- bool becomeConnected = !wasInDocument && inDocument();
+ bool becomeConnected = !wasInDocument && isConnected();
HTMLDocument* newDocument = becomeConnected && is<HTMLDocument>(newScope->documentScope()) ? &downcast<HTMLDocument>(newScope->documentScope()) : nullptr;
if (newScope != &treeScope())
newScope = nullptr;
if (insertionPoint.isInTreeScope()) {
TreeScope* oldScope = &insertionPoint.treeScope();
- bool becomeDisconnected = inDocument();
+ bool becomeDisconnected = isConnected();
HTMLDocument* oldDocument = becomeDisconnected && is<HTMLDocument>(oldScope->documentScope()) ? &downcast<HTMLDocument>(oldScope->documentScope()) : nullptr;
// ContainerNode::removeBetween always sets the removed chid's tree scope to Document's but InTreeScope flag is unset in Node::removedFrom.
void Element::focus(bool restorePreviousSelection, FocusDirection direction)
{
- if (!inDocument())
+ if (!isConnected())
return;
if (document().focusedElement() == this) {
const RenderStyle& Element::resolveComputedStyle()
{
- ASSERT(inDocument());
+ ASSERT(isConnected());
ASSERT(!existingComputedStyle());
Deque<Element*, 32> elementsRequiringComputedStyle({ this });
const RenderStyle* Element::computedStyle(PseudoId pseudoElementSpecifier)
{
- if (!inDocument())
+ if (!isConnected())
return nullptr;
if (PseudoElement* pseudoElement = beforeOrAfterPseudoElement(*this, pseudoElementSpecifier))
updateNameForTreeScope(treeScope(), oldName, newName);
- if (!inDocument())
+ if (!isConnected())
return;
if (!is<HTMLDocument>(document()))
return;
updateIdForTreeScope(treeScope(), oldId, newId, notifyObservers);
- if (!inDocument())
+ if (!isConnected())
return;
if (!is<HTMLDocument>(document()))
return;
void Element::updateIdForDocument(HTMLDocument& document, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition condition)
{
- ASSERT(inDocument());
+ ASSERT(isConnected());
ASSERT(oldId != newId);
if (isInShadowTree())
{
ASSERT(hasTagName(labelTag));
- if (!inDocument())
+ if (!isConnected())
return;
if (oldForAttributeValue == newForAttributeValue)
// We can't update window and document's named item maps since the presence of image and object elements depend on other attributes and children.
// Fortunately, those named item maps are only updated when this element is in the document, which should never be the case.
- ASSERT(!inDocument());
+ ASSERT(!isConnected());
const AtomicString& oldID = getIdAttribute();
const AtomicString& newID = other.getIdAttribute();
inline const Element* Element::rootElement() const
{
- if (inDocument())
+ if (isConnected())
return document().documentElement();
const Element* highest = this;
{
auto& targetTreeScope = target.treeScope();
TreeScope* currentTreeScope = &m_relatedNode.treeScope();
- if (LIKELY(currentTreeScope == &targetTreeScope && target.inDocument() && m_relatedNode.inDocument()))
+ if (LIKELY(currentTreeScope == &targetTreeScope && target.isConnected() && m_relatedNode.isConnected()))
return;
if (¤tTreeScope->documentScope() != &targetTreeScope.documentScope()) {
m_retargetedRelatedNode = nullptr;
return;
}
- if (relatedNode.inDocument() != target.inDocument()) {
+ if (relatedNode.isConnected() != target.isConnected()) {
m_hasDifferentTreeRoot = true;
m_retargetedRelatedNode = moveOutOfAllShadowRoots(relatedNode);
return;
}
bool lowestCommonAncestorIsDocumentScope = i + 1 == m_ancestorTreeScopes.size();
- if (lowestCommonAncestorIsDocumentScope && !relatedNode.inDocument() && !target.inDocument()) {
+ if (lowestCommonAncestorIsDocumentScope && !relatedNode.isConnected() && !target.isConnected()) {
Node& relatedNodeAncestorInDocumentScope = i ? *downcast<ShadowRoot>(m_ancestorTreeScopes[i - 1]->rootNode()).shadowHost() : relatedNode;
Node& targetAncestorInDocumentScope = j ? *downcast<ShadowRoot>(targetTreeScopeAncestors[j - 1]->rootNode()).shadowHost() : target;
if (&targetAncestorInDocumentScope.rootNode() != &relatedNodeAncestorInDocumentScope.rootNode()) {
{
if (m_isParsingChildren)
return;
- if (!element.inDocument())
+ if (!element.isConnected())
return;
createSheetFromTextContents(element);
}
void InlineStyleSheetOwner::finishParsingChildren(Element& element)
{
- if (element.inDocument())
+ if (element.isConnected())
createSheetFromTextContents(element);
m_isParsingChildren = false;
}
void InlineStyleSheetOwner::createSheet(Element& element, const String& text)
{
- ASSERT(element.inDocument());
+ ASSERT(element.isConnected());
Document& document = element.document();
if (m_sheet) {
if (m_sheet->isLoading() && m_styleScope)
ContainerNode& LiveNodeList::rootNode() const
{
- if (isRootedAtDocument() && ownerNode().inDocument())
+ if (isRootedAtDocument() && ownerNode().isConnected())
return ownerNode().document();
return ownerNode();
template <class NodeListType>
inline ContainerNode& CachedLiveNodeList<NodeListType>::rootNode() const
{
- if (nodeList().isRootedAtDocument() && ownerNode().inDocument())
+ if (nodeList().isRootedAtDocument() && ownerNode().isConnected())
return ownerNode().document();
return ownerNode();
bool Node::isDescendantOf(const Node& other) const
{
// Return true if other is an ancestor of this, otherwise false
- if (!other.hasChildNodes() || inDocument() != other.inDocument())
+ if (!other.hasChildNodes() || isConnected() != other.isConnected())
return false;
if (other.isDocumentNode())
- return &document() == &other && !isDocumentNode() && inDocument();
+ return &document() == &other && !isDocumentNode() && isConnected();
for (const auto* ancestor = parentNode(); ancestor; ancestor = ancestor->parentNode()) {
if (ancestor == &other)
return true;
Node::InsertionNotificationRequest Node::insertedInto(ContainerNode& insertionPoint)
{
- ASSERT(insertionPoint.inDocument() || isContainerNode());
- if (insertionPoint.inDocument())
- setFlag(InDocumentFlag);
+ ASSERT(insertionPoint.isConnected() || isContainerNode());
+ if (insertionPoint.isConnected())
+ setFlag(IsConnectedFlag);
if (parentOrShadowHostNode()->isInShadowTree())
setFlag(IsInShadowTreeFlag);
void Node::removedFrom(ContainerNode& insertionPoint)
{
- ASSERT(insertionPoint.inDocument() || isContainerNode());
- if (insertionPoint.inDocument())
- clearFlag(InDocumentFlag);
+ ASSERT(insertionPoint.isConnected() || isContainerNode());
+ if (insertionPoint.isConnected())
+ clearFlag(IsConnectedFlag);
if (isInShadowTree() && !treeScope().rootNode().isShadowRoot())
clearFlag(IsInShadowTreeFlag);
}
// If one node is in the document and the other is not, we must be disconnected.
// 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())
+ // comparing Attr nodes here, since they return false from isConnected() all the time (which seems like a bug).
+ if (start1->isConnected() != start2->isConnected() || &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.
bool Node::inRenderedDocument() const
{
- return inDocument() && document().hasLivingRenderTree();
+ return isConnected() && document().hasLivingRenderTree();
}
void* Node::opaqueRootSlow() const
static ptrdiff_t treeScopeMemoryOffset() { return OBJECT_OFFSETOF(Node, m_treeScope); }
// Returns true if this node is associated with a document and is in its associated document's
- // node tree, false otherwise.
- bool inDocument() const
+ // node tree, false otherwise (https://dom.spec.whatwg.org/#connected).
+ bool isConnected() const
{
- return getFlag(InDocumentFlag);
+ return getFlag(IsConnectedFlag);
}
bool isInUserAgentShadowTree() const;
bool isInShadowTree() const { return getFlag(IsInShadowTreeFlag); }
- bool isInTreeScope() const { return getFlag(static_cast<NodeFlags>(InDocumentFlag | IsInShadowTreeFlag)); }
+ bool isInTreeScope() const { return getFlag(static_cast<NodeFlags>(IsConnectedFlag | IsInShadowTreeFlag)); }
bool isDocumentTypeNode() const { return nodeType() == DOCUMENT_TYPE_NODE; }
virtual bool childTypeAllowed(NodeType) const { return false; }
// dispatching.
//
// WebKit notifies this callback regardless if the subtree of the node is a document tree or a floating subtree.
- // Implementation can determine the type of subtree by seeing insertionPoint->inDocument().
+ // Implementation can determine the type of subtree by seeing insertionPoint->isConnected().
// For a performance reason, notifications are delivered only to ContainerNode subclasses if the insertionPoint is out of document.
//
// There is another callback named finishedInsertingSubtree(), which is called after all descendants are notified.
IsHTMLFlag = 1 << 4,
IsSVGFlag = 1 << 5,
ChildNeedsStyleRecalcFlag = 1 << 7,
- InDocumentFlag = 1 << 8,
+ IsConnectedFlag = 1 << 8,
IsLinkFlag = 1 << 9,
IsUserActionElement = 1 << 10,
HasRareDataFlag = 1 << 11,
CreateText = DefaultNodeFlags | IsTextFlag,
CreateContainer = DefaultNodeFlags | IsContainerFlag,
CreateElement = CreateContainer | IsElementFlag,
- CreatePseudoElement = CreateElement | InDocumentFlag,
+ CreatePseudoElement = CreateElement | IsConnectedFlag,
CreateShadowRoot = CreateContainer | IsDocumentFragmentFlag | IsInShadowTreeFlag,
CreateDocumentFragment = CreateContainer | IsDocumentFragmentFlag,
CreateStyledElement = CreateElement | IsStyledElementFlag,
CreateHTMLElement = CreateStyledElement | IsHTMLFlag,
CreateSVGElement = CreateStyledElement | IsSVGFlag | HasCustomStyleResolveCallbacksFlag,
- CreateDocument = CreateContainer | InDocumentFlag,
+ CreateDocument = CreateContainer | IsConnectedFlag,
CreateEditingText = CreateText | IsEditingTextOrUndefinedCustomElementFlag,
CreateMathMLElement = CreateStyledElement | IsMathMLFlag
};
{
// FIXME: Possible race?
// https://bugs.webkit.org/show_bug.cgi?id=165713
- if (inDocument())
+ if (isConnected())
return &document();
return opaqueRootSlow();
}
boolean contains(Node? other);
[EnabledAtRuntime=ShadowDOM] Node getRootNode(optional GetRootNodeOptions options);
- [EnabledAtRuntime=ShadowDOM, ImplementedAs=inDocument] readonly attribute boolean isConnected;
+ [EnabledAtRuntime=ShadowDOM] readonly attribute boolean isConnected;
readonly attribute Element parentElement;
};
bool isNull() const { return !m_anchorNode; }
bool isNotNull() const { return m_anchorNode; }
- bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); }
+ bool isOrphan() const { return m_anchorNode && !m_anchorNode->isConnected(); }
Element* element() const;
if (m_cachedSheet)
m_cachedSheet->removeClient(*this);
- if (inDocument())
+ if (isConnected())
document().styleScope().removeStyleSheetCandidateNode(*this);
}
void ProcessingInstruction::setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
{
- if (!inDocument()) {
+ if (!isConnected()) {
ASSERT(!m_sheet);
return;
}
Node::InsertionNotificationRequest ProcessingInstruction::insertedInto(ContainerNode& insertionPoint)
{
CharacterData::insertedInto(insertionPoint);
- if (!insertionPoint.inDocument())
+ if (!insertionPoint.isConnected())
return InsertionDone;
document().styleScope().addStyleSheetCandidateNode(*this, m_createdByParser);
checkStyleSheet();
void ProcessingInstruction::removedFrom(ContainerNode& insertionPoint)
{
CharacterData::removedFrom(insertionPoint);
- if (!insertionPoint.inDocument())
+ if (!insertionPoint.isConnected())
return;
document().styleScope().removeStyleSheetCandidateNode(*this);
if (checkNodeResult.hasException()) {
// DOM4 spec requires us to check whether refNode and start container have the same root first
// but we do it in the reverse order to avoid O(n) operation here in common case.
- if (!refNode.inDocument() && !commonAncestorContainer(&refNode, &startContainer()))
+ if (!refNode.isConnected() && !commonAncestorContainer(&refNode, &startContainer()))
return Exception { WRONG_DOCUMENT_ERR };
return checkNodeResult.releaseException();
}
// This method returns 0, 1, 2, or 3 based on if the node is before, after,
// before and after(surrounds), or inside the range, respectively
- if (!refNode.inDocument()) {
+ if (!refNode.isConnected()) {
// Firefox doesn't throw an exception for this case; it returns 0.
return NODE_BEFORE;
}
ExceptionOr<bool> Range::intersectsNode(Node& refNode) const
{
- if (!refNode.inDocument() || &refNode.document() != &ownerDocument())
+ if (!refNode.isConnected() || &refNode.document() != &ownerDocument())
return false;
ContainerNode* parentNode = refNode.parentNode();
bool ScriptElement::shouldCallFinishedInsertingSubtree(ContainerNode& insertionPoint)
{
- return insertionPoint.inDocument() && !m_parserInserted;
+ return insertionPoint.isConnected() && !m_parserInserted;
}
void ScriptElement::finishedInsertingSubtree()
void ScriptElement::childrenChanged()
{
- if (!m_parserInserted && m_element.inDocument())
+ if (!m_parserInserted && m_element.isConnected())
prepareScript(); // FIXME: Provide a real starting line number here.
}
if (!hasSourceAttribute() && !m_element.firstChild())
return false;
- if (!m_element.inDocument())
+ if (!m_element.isConnected())
return false;
ScriptType scriptType = ScriptType::Classic;
Ref<Document> originalDocument(m_element.document());
if (!m_element.dispatchBeforeLoadEvent(sourceURL))
return false;
- bool didEventListenerDisconnectThisElement = !m_element.inDocument() || &m_element.document() != originalDocument.ptr();
+ bool didEventListenerDisconnectThisElement = !m_element.isConnected() || &m_element.document() != originalDocument.ptr();
if (didEventListenerDisconnectThisElement)
return false;
if (!m_element.dispatchBeforeLoadEvent(sourceURL))
return false;
- bool didEventListenerDisconnectThisElement = !m_element.inDocument() || &m_element.document() != originalDocument.ptr();
+ bool didEventListenerDisconnectThisElement = !m_element.isConnected() || &m_element.document() != originalDocument.ptr();
if (didEventListenerDisconnectThisElement)
return false;
bool ScriptElement::ignoresLoadRequest() const
{
- return m_alreadyStarted || m_isExternalScript || m_parserInserted || !m_element.inDocument();
+ return m_alreadyStarted || m_isExternalScript || m_parserInserted || !m_element.isConnected();
}
bool ScriptElement::isScriptForEventSupported() const
void ScriptRunner::queueScriptForExecution(ScriptElement& scriptElement, LoadableScript& loadableScript, ExecutionType executionType)
{
- ASSERT(scriptElement.element().inDocument());
+ ASSERT(scriptElement.element().isConnected());
m_document.incrementLoadEventDelayCount();
static const CSSSelector* selectorForIdLookup(const ContainerNode& rootNode, const CSSSelector& firstSelector)
{
- if (!rootNode.inDocument())
+ if (!rootNode.isConnected())
return nullptr;
if (rootNode.document().inQuirksMode())
return nullptr;
static ContainerNode& filterRootById(ContainerNode& rootNode, const CSSSelector& firstSelector)
{
- if (!rootNode.inDocument())
+ if (!rootNode.isConnected())
return rootNode;
if (rootNode.document().inQuirksMode())
return rootNode;
ShadowRoot::~ShadowRoot()
{
- if (inDocument())
+ if (isConnected())
document().didRemoveInDocumentShadowRoot(*this);
// We cannot let ContainerNode destructor call willBeDeletedFrom()
Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode& insertionPoint)
{
- bool wasInDocument = inDocument();
+ bool wasInDocument = isConnected();
DocumentFragment::insertedInto(insertionPoint);
- if (insertionPoint.inDocument() && !wasInDocument)
+ if (insertionPoint.isConnected() && !wasInDocument)
document().didInsertInDocumentShadowRoot(*this);
return InsertionDone;
}
void ShadowRoot::removedFrom(ContainerNode& insertionPoint)
{
DocumentFragment::removedFrom(insertionPoint);
- if (insertionPoint.inDocument() && !inDocument())
+ if (insertionPoint.isConnected() && !isConnected())
document().didRemoveInDocumentShadowRoot(*this);
}
inline void TreeScopeAdopter::moveNodeToNewDocument(Node& node, Document& oldDocument, Document& newDocument) const
{
- ASSERT(!node.inDocument() || &oldDocument != &newDocument);
+ ASSERT(!node.isConnected() || &oldDocument != &newDocument);
newDocument.incrementReferencingNodeCount();
oldDocument.decrementReferencingNodeCount();
// indentIntoBlockquote could move more than one paragraph if the paragraph
// is in a list item or a table. As a result, endAfterSelection could refer to a position
// no longer in the document.
- if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent().anchorNode()->inDocument())
+ if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent().anchorNode()->isConnected())
break;
// Sanity check: Make sure our moveParagraph calls didn't remove endOfNextParagraph.deepEquivalent().deprecatedNode()
// If somehow we did, return to prevent crashes.
- if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().anchorNode()->inDocument()) {
+ if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().anchorNode()->isConnected()) {
ASSERT_NOT_REACHED();
return;
}
bool startAndEndAreStillInDocument()
{
- return start && end && start->inDocument() && end->inDocument();
+ return start && end && start->isConnected() && end->isConnected();
}
RefPtr<Node> start;
{
ASSERT(runStart && runEnd);
RefPtr<Node> next = runStart;
- for (RefPtr<Node> node = next; node && node->inDocument() && node != pastEndNode; node = next) {
+ for (RefPtr<Node> node = next; node && node->isConnected() && node != pastEndNode; node = next) {
if (editingIgnoresContent(*node)) {
ASSERT(!node->contains(pastEndNode.get()));
next = NodeTraversal::nextSkippingChildren(*node);
RefPtr<Node> nextSibling = node->nextSibling();
RefPtr<ContainerNode> parent = node->parentNode();
removeInlineStyleFromElement(style, downcast<HTMLElement>(node.get()), RemoveAlways);
- if (!node->inDocument()) {
+ if (!node->isConnected()) {
// FIXME: We might need to update the start and the end of current selection here but need a test.
if (runStart == node)
runStart = previousSibling ? previousSibling->nextSibling() : parent->firstChild();
if (removeImplicitlyStyledElement(style, element.get(), mode, extractedStyle))
removed = true;
- if (!element->inDocument())
+ if (!element->isConnected())
return removed;
// If the node was converted to a span, the span may still contain relevant
removeNodePreservingChildren(elem);
else {
HTMLElement* newSpanElement = replaceElementWithSpanPreservingChildrenAndAttributes(elem);
- ASSERT(newSpanElement && newSpanElement->inDocument());
+ ASSERT(newSpanElement && newSpanElement->isConnected());
elem = newSpanElement;
}
}
{
ASSERT(start.isNotNull());
ASSERT(end.isNotNull());
- ASSERT(start.anchorNode()->inDocument());
- ASSERT(end.anchorNode()->inDocument());
+ ASSERT(start.anchorNode()->isConnected());
+ ASSERT(end.anchorNode()->isConnected());
ASSERT(comparePositions(start, end) <= 0);
// FIXME: We should assert that start/end are not in the middle of a text node.
}
removeInlineStyleFromElement(style, element.ptr(), RemoveIfNeeded, styleToPushDown.get());
- if (!element->inDocument()) {
+ if (!element->isConnected()) {
if (s.deprecatedNode() == element.ptr()) {
// Since elem must have been fully selected, and it is at the start
// of the selection, it is clear we can set the new s offset to 0.
void ApplyStyleCommand::addInlineStyleIfNeeded(EditingStyle* style, PassRefPtr<Node> passedStart, PassRefPtr<Node> passedEnd, EAddStyledElement addStyledElement)
{
- if (!passedStart || !passedEnd || !passedStart->inDocument() || !passedEnd->inDocument())
+ if (!passedStart || !passedEnd || !passedStart->isConnected() || !passedEnd->isConnected())
return;
RefPtr<Node> start = passedStart;
{
RefPtr<Node> startNode = passedStart;
RefPtr<Node> endNode = passedEnd;
- ASSERT(startNode->inDocument());
- ASSERT(endNode->inDocument());
+ ASSERT(startNode->isConnected());
+ ASSERT(endNode->isConnected());
// Find appropriate font and span elements top-down.
HTMLFontElement* fontContainer = nullptr;
splitTextNode(downcast<Text>(refChild), offset);
// Mutation events (bug 22634) from the text node insertion may have removed the refChild
- if (!refChild->inDocument())
+ if (!refChild->isConnected())
return;
insertNodeBefore(insertChild, refChild);
} else
// Returning a raw pointer here is OK because the command is retained by
// applyCommandToComposite (thus retaining the span), and the span is also
// in the DOM tree, and thus alive whie it has a parent.
- ASSERT(command->spanElement()->inDocument());
+ ASSERT(command->spanElement()->isConnected());
return command->spanElement();
}
setEndingSelection(VisibleSelection::selectionFromContentsOfNode(&anchorElement));
applyStyledElement(&anchorElement);
// Clones of anchorElement have been pushed down, now remove it.
- if (anchorElement.inDocument())
+ if (anchorElement.isConnected())
removeNodePreservingChildren(&anchorElement);
}
frame().editor().clearMisspellingsAndBadGrammar(endingSelection());
deleteSelection(false, false, false, false);
- ASSERT(destination.deepEquivalent().anchorNode()->inDocument());
+ ASSERT(destination.deepEquivalent().anchorNode()->isConnected());
cleanupAfterDeletion(destination);
- ASSERT(destination.deepEquivalent().anchorNode()->inDocument());
+ ASSERT(destination.deepEquivalent().anchorNode()->isConnected());
// Add a br if pruning an empty block level element caused a collapse. For example:
// foo^
}
}
- if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.deprecatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstreamEnd.anchorNode()->inDocument() && m_downstreamEnd.deprecatedEditingOffset() >= caretMinOffset(*m_downstreamEnd.deprecatedNode())) {
+ if (m_downstreamEnd.deprecatedNode() != startNode && !m_upstreamStart.deprecatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode()) && m_downstreamEnd.anchorNode()->isConnected() && m_downstreamEnd.deprecatedEditingOffset() >= caretMinOffset(*m_downstreamEnd.deprecatedNode())) {
if (m_downstreamEnd.atLastEditingPositionForNode() && !canHaveChildrenForEditing(*m_downstreamEnd.deprecatedNode())) {
// The node itself is fully selected, not just its contents. Delete it.
removeNode(m_downstreamEnd.deprecatedNode());
// know how many children to remove.
// FIXME: Make m_upstreamStart a position we update as we remove content, then we can
// always know which children to remove.
- } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart.anchorNode()->inDocument())) {
+ } else if (!(startNodeWasDescendantOfEndNode && !m_upstreamStart.anchorNode()->isConnected())) {
unsigned offset = 0;
if (m_upstreamStart.deprecatedNode()->isDescendantOf(m_downstreamEnd.deprecatedNode())) {
Node* n = m_upstreamStart.deprecatedNode();
ASSERT(!m_pruneStartBlockIfNecessary);
// FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839).
- if (!m_downstreamEnd.anchorNode()->inDocument() || !m_upstreamStart.anchorNode()->inDocument())
+ if (!m_downstreamEnd.anchorNode()->isConnected() || !m_upstreamStart.anchorNode()->isConnected())
return;
-
+
// FIXME: The deletion algorithm shouldn't let this happen.
if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0)
return;
void DeleteSelectionCommand::removePreviouslySelectedEmptyTableRows()
{
- if (m_endTableRow && m_endTableRow->inDocument() && m_endTableRow != m_startTableRow) {
+ if (m_endTableRow && m_endTableRow->isConnected() && m_endTableRow != m_startTableRow) {
Node* row = m_endTableRow->previousSibling();
while (row && row != m_startTableRow) {
RefPtr<Node> previousRow = row->previousSibling();
}
// Remove empty rows after the start row.
- if (m_startTableRow && m_startTableRow->inDocument() && m_startTableRow != m_endTableRow) {
+ if (m_startTableRow && m_startTableRow->isConnected() && m_startTableRow != m_endTableRow) {
Node* row = m_startTableRow->nextSibling();
while (row && row != m_endTableRow) {
RefPtr<Node> nextRow = row->nextSibling();
row = nextRow.get();
}
}
-
- if (m_endTableRow && m_endTableRow->inDocument() && m_endTableRow != m_startTableRow)
+
+ if (m_endTableRow && m_endTableRow->isConnected() && m_endTableRow != m_startTableRow) {
if (isTableRowEmpty(m_endTableRow.get())) {
// Don't remove m_endTableRow if it's where we're putting the ending selection.
if (!m_endingPosition.deprecatedNode()->isDescendantOf(*m_endTableRow)) {
CompositeEditCommand::removeNode(m_endTableRow.get());
}
}
+ }
}
void DeleteSelectionCommand::calculateTypingStyleAfterDelete()
// When typing we check spelling elsewhere, so don't redo it here.
// If this is a change in selection resulting from a delete operation,
// oldSelection may no longer be in the document.
- if (m_editorUIUpdateTimerShouldCheckSpellingAndGrammar && oldSelection.isContentEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().anchorNode()->inDocument()) {
+ if (m_editorUIUpdateTimerShouldCheckSpellingAndGrammar && oldSelection.isContentEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().anchorNode()->isConnected()) {
VisiblePosition oldStart(oldSelection.visibleStart());
VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
if (oldAdjacentWords != newAdjacentWords) {
void DragCaretController::nodeWillBeRemoved(Node& node)
{
- if (!hasCaret() || !node.inDocument())
+ if (!hasCaret() || !node.isConnected())
return;
if (!removingNodeRemovesPosition(node, m_position.deepEquivalent()))
{
// There can't be a selection inside a fragment, so if a fragment's node is being removed,
// the selection in the document that created the fragment needs no adjustment.
- if (isNone() || !node.inDocument())
+ if (isNone() || !node.isConnected())
return;
respondToNodeModification(node, removingNodeRemovesPosition(node, m_selection.base()), removingNodeRemovesPosition(node, m_selection.extent()),
void FrameSelection::textWasReplaced(CharacterData* node, unsigned offset, unsigned oldLength, unsigned newLength)
{
// The fragment check is a performance optimization. See http://trac.webkit.org/changeset/30062.
- if (isNone() || !node || !node->inDocument())
+ if (isNone() || !node || !node->isConnected())
return;
Position base = m_selection.base();
// outdentParagraph could move more than one paragraph if the paragraph
// is in a list item. As a result, endAfterSelection and endOfNextParagraph
// could refer to positions no longer in the document.
- if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent().anchorNode()->inDocument())
+ if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent().anchorNode()->isConnected())
break;
- if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().anchorNode()->inDocument()) {
+ if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().anchorNode()->isConnected()) {
endOfCurrentParagraph = endingSelection().end();
endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.next());
}
deleteInsignificantTextDownstream(endingPosition);
ASSERT(!textNode.renderer() || textNode.renderer()->style().collapseWhiteSpace());
// Deleting insignificant whitespace will remove textNode if it contains nothing but insignificant whitespace.
- if (textNode.inDocument())
+ if (textNode.isConnected())
insertTextIntoNode(&textNode, 0, nonBreakingSpaceString());
else {
RefPtr<Text> nbspNode = document().createTextNode(nonBreakingSpaceString());
// infinite loop and because there is no more work to be done.
// FIXME(<rdar://problem/5983974>): The endingSelection() may be incorrect here. Compute
// the new location of endOfSelection and use it as the end of the new selection.
- if (!startOfLastParagraph.deepEquivalent().anchorNode()->inDocument())
+ if (!startOfLastParagraph.deepEquivalent().anchorNode()->isConnected())
return;
setEndingSelection(startOfCurrentParagraph);
// Manually remove listNode because moveParagraphWithClones sometimes leaves it behind in the document.
// See the bug 33668 and editing/execCommand/insert-list-orphaned-item-with-nested-lists.html.
// FIXME: This might be a bug in moveParagraphWithClones or deleteSelection.
- if (listNode && listNode->inDocument())
+ if (listNode && listNode->isConnected())
removeNode(listNode);
newList = mergeWithNeighboringLists(newList);
// and so deleteInsignificantText could remove it. Save the position before the node in case that happens.
Position positionBeforeStartNode(positionInParentBeforeNode(startPosition.containerNode()));
deleteInsignificantText(startPosition.upstream(), startPosition.downstream());
- if (!startPosition.anchorNode()->inDocument())
+ if (!startPosition.anchorNode()->isConnected())
startPosition = positionBeforeStartNode;
if (!startPosition.isCandidate())
startPosition = startPosition.downstream();
// set the destination to the ending point after the deletion.
// Fixes: <rdar://problem/3910425> REGRESSION (Mail): Crash in ReplaceSelectionCommand;
// selection is empty, leading to null deref
- if (!pos.anchorNode()->inDocument())
+ if (!pos.anchorNode()->isConnected())
pos = endingSelection().start();
cleanupAfterDeletion(pos);
setEndingSelection(VisibleSelection(pos, endingSelection().affinity(), endingSelection().isDirectional()));
setStartingSelection(endingSelection());
- if (!pos.anchorNode()->inDocument()) {
+ if (!pos.anchorNode()->isConnected()) {
// Document was modified out from under us.
return;
}
static void swapInNodePreservingAttributesAndChildren(HTMLElement& newNode, HTMLElement& nodeToReplace)
{
- ASSERT(nodeToReplace.inDocument());
+ ASSERT(nodeToReplace.isConnected());
RefPtr<ContainerNode> parentNode = nodeToReplace.parentNode();
// FIXME: Fix this to send the proper MutationRecords when MutationObservers are present.
void ReplaceNodeWithSpanCommand::doApply()
{
- if (!m_elementToReplace->inDocument())
+ if (!m_elementToReplace->isConnected())
return;
if (!m_spanElement)
m_spanElement = HTMLSpanElement::create(m_elementToReplace->document());
void ReplaceNodeWithSpanCommand::doUnapply()
{
- if (!m_spanElement->inDocument())
+ if (!m_spanElement->isConnected())
return;
swapInNodePreservingAttributesAndChildren(*m_elementToReplace, *m_spanElement);
}
}
// Mutation events (bug 22634) may have already removed the inserted content
- if (!refNode->inDocument())
+ if (!refNode->isConnected())
return;
bool plainTextFragment = isPlainTextMarkup(refNode.get());
insertedNodes.respondToNodeInsertion(node.get());
// Mutation events (bug 22634) may have already removed the inserted content
- if (!node->inDocument())
+ if (!node->isConnected())
return;
refNode = node;
handleStyleSpans(insertedNodes);
// Mutation events (bug 20161) may have already removed the inserted content
- if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()->inDocument())
+ if (!insertedNodes.firstNodeInserted() || !insertedNodes.firstNodeInserted()->isConnected())
return;
VisiblePosition startOfInsertedContent = firstPositionInOrBeforeNode(insertedNodes.firstNodeInserted());
if (startOfParagraph(endOfInsertedContent) == startOfParagraphToMove) {
insertNodeAt(HTMLBRElement::create(document()), endOfInsertedContent.deepEquivalent());
// Mutation events (bug 22634) triggered by inserting the <br> might have removed the content we're about to move
- if (!startOfParagraphToMove.deepEquivalent().anchorNode()->inDocument())
+ if (!startOfParagraphToMove.deepEquivalent().anchorNode()->isConnected())
return;
}
bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePosition& originalVisPosBeforeEndBR)
{
- if (!endBR || !endBR->inDocument())
+ if (!endBR || !endBR->isConnected())
return false;
-
+
VisiblePosition visiblePos(positionBeforeNode(endBR));
// Don't remove the br if nothing was inserted.
if (m_form && element.rootElement() != m_form->rootElement())
setForm(nullptr);
- if (!insertionPoint.inDocument())
+ if (!insertionPoint.isConnected())
return;
if (element.hasAttributeWithoutSynchronization(formAttr))
}
// Compute the highest ancestor instead of calling Node::rootNode in removedFrom / formRemovedFromTree
-// since inDocument flag on some form associated elements may not have been updated yet.
+// since isConnected flag on some form associated elements may not have been updated yet.
static Node* computeRootNode(Node& node)
{
Node* current = &node;
void FormAssociatedElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement& element = asHTMLElement();
- if (insertionPoint.inDocument() && element.hasAttributeWithoutSynchronization(formAttr))
+ if (insertionPoint.isConnected() && element.hasAttributeWithoutSynchronization(formAttr))
m_formAttributeTargetObserver = nullptr;
// If the form and element are both in the same tree, preserve the connection to the form.
// Otherwise, null out our form and remove ourselves from the form's list of elements.
HTMLFormElement* FormAssociatedElement::findAssociatedForm(const HTMLElement* element, HTMLFormElement* currentAssociatedForm)
{
const AtomicString& formId(element->attributeWithoutSynchronization(formAttr));
- if (!formId.isNull() && element->inDocument()) {
+ if (!formId.isNull() && element->isConnected()) {
// 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
HTMLFormElement* originalForm = m_form;
setForm(findAssociatedForm(&asHTMLElement(), m_form));
HTMLElement& element = asHTMLElement();
- if (m_form && m_form != originalForm && m_form->inDocument())
+ if (m_form && m_form != originalForm && m_form->isConnected())
element.document().didAssociateFormControl(&element);
}
// The form attribute removed. We need to reset form owner here.
HTMLFormElement* originalForm = m_form;
setForm(HTMLFormElement::findClosestFormAncestor(element));
- if (m_form && m_form != originalForm && m_form->inDocument())
+ if (m_form && m_form != originalForm && m_form->isConnected())
element.document().didAssociateFormControl(&element);
m_formAttributeTargetObserver = nullptr;
} else {
resetFormOwner();
- if (element.inDocument())
+ if (element.isConnected())
resetFormAttributeTargetObserver();
}
}
Node::InsertionNotificationRequest HTMLBaseElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
document().processBaseElement();
return InsertionDone;
}
void HTMLBaseElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
document().processBaseElement();
}
Node::InsertionNotificationRequest HTMLBodyElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (!insertionPoint.inDocument())
+ if (!insertionPoint.isConnected())
return InsertionDone;
// FIXME: It's surprising this is web compatible since it means a marginwidth and marginheight attribute can
inline ContainerNode& HTMLCollection::rootNode() const
{
- if (isRootedAtDocument() && ownerNode().inDocument())
+ if (isRootedAtDocument() && ownerNode().isConnected())
return ownerNode().document();
return ownerNode();
// FIXME: Can the renderer be out of date here? Do we need to call updateStyleIfNeeded?
// For example, for the contents of textarea elements that are display:none?
auto* r = renderer();
- if ((r && r->style().preserveNewline()) || (inDocument() && isTextControlInnerTextElement())) {
+ if ((r && r->style().preserveNewline()) || (isConnected() && isTextControlInnerTextElement())) {
if (!text.contains('\r')) {
replaceAllChildren(document().createTextNode(text));
return { };
return false;
if (!element->hasAttributeWithoutSynchronization(autofocusAttr))
return false;
- if (!element->inDocument() || !element->document().renderView())
+ if (!element->isConnected() || !element->document().renderView())
return false;
if (element->document().isSandboxed(SandboxAutomaticFeatures)) {
// FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
Ref<HTMLFormControlElement> protectedThis(*this);
Ref<Document> originalDocument(document());
bool needsDefaultAction = dispatchEvent(Event::create(eventNames().invalidEvent, false, true));
- if (needsDefaultAction && unhandledInvalidControls && inDocument() && originalDocument.ptr() == &document())
+ if (needsDefaultAction && unhandledInvalidControls && isConnected() && originalDocument.ptr() == &document())
unhandledInvalidControls->append(this);
return false;
}
// has !renderer()->needsLayout() assertion.
document().updateLayoutIgnorePendingStylesheets();
- if (inDocument() && isFocusable()) {
+ if (isConnected() && isFocusable()) {
focusAndShowValidationMessage();
return false;
}
Node::InsertionNotificationRequest HTMLFormControlElementWithState::insertedInto(ContainerNode& insertionPoint)
{
- if (insertionPoint.inDocument() && !containingShadowRoot())
+ if (insertionPoint.isConnected() && !containingShadowRoot())
document().formController().registerFormElementWithState(this);
return HTMLFormControlElement::insertedInto(insertionPoint);
}
void HTMLFormControlElementWithState::removedFrom(ContainerNode& insertionPoint)
{
- if (insertionPoint.inDocument() && !containingShadowRoot() && !insertionPoint.containingShadowRoot())
+ if (insertionPoint.isConnected() && !containingShadowRoot() && !insertionPoint.containingShadowRoot())
document().formController().unregisterFormElementWithState(this);
HTMLFormControlElement::removedFrom(insertionPoint);
}
bool HTMLFormControlElementWithState::shouldSaveAndRestoreFormControlState() const
{
// We don't save/restore control state in a form with autocomplete=off.
- return inDocument() && shouldAutocomplete();
+ return isConnected() && shouldAutocomplete();
}
FormControlState HTMLFormControlElementWithState::saveFormControlState() const
Node::InsertionNotificationRequest HTMLFormElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
document().didAssociateFormControl(this);
return InsertionDone;
}
// Focus on the first focusable control and show a validation message.
for (auto& control : unhandledInvalidControls) {
- if (control->inDocument() && control->isFocusable()) {
+ if (control->isConnected() && control->isFocusable()) {
control->focusAndShowValidationMessage();
break;
}
// Warn about all of unfocusable controls.
if (document().frame()) {
for (auto& control : unhandledInvalidControls) {
- if (control->inDocument() && control->isFocusable())
+ if (control->isConnected() && control->isFocusable())
continue;
String message = makeString("An invalid form control with name='", control->name(), "' is not focusable.");
document().addConsoleMessage(MessageSource::Rendering, MessageLevel::Error, message);
Node::InsertionNotificationRequest HTMLFrameElementBase::insertedInto(ContainerNode& insertionPoint)
{
HTMLFrameOwnerElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
return InsertionShouldCallFinishedInsertingSubtree;
return InsertionDone;
}
void HTMLFrameElementBase::finishedInsertingSubtree()
{
- if (!inDocument())
+ if (!isConnected())
return;
// DocumentFragments don't kick of any loads.
m_URL = AtomicString(str);
- if (inDocument())
+ if (isConnected())
openURL(LockHistory::No, LockBackForwardList::No);
}
ASSERT(!m_contentFrame || m_contentFrame->ownerElement() != this);
ASSERT(frame);
// Disconnected frames should not be allowed to load.
- ASSERT(inDocument());
+ ASSERT(isConnected());
m_contentFrame = frame;
for (ContainerNode* node = this; node; node = node->parentOrShadowHostNode())
Node::InsertionNotificationRequest HTMLFrameSetElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument()) {
+ if (insertionPoint.isConnected()) {
if (Frame* frame = document().frame())
frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet());
}
void HTMLFrameSetElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
- if (insertionPoint.inDocument()) {
+ if (insertionPoint.isConnected()) {
if (Frame* frame = document().frame())
frame->loader().client().dispatchDidBecomeFrameset(document().isFrameSet());
}
} else if (name == srcAttr || name == srcsetAttr || name == sizesAttr)
selectImageSource();
else if (name == usemapAttr) {
- if (inDocument() && !m_parsedUsemap.isNull())
+ if (isConnected() && !m_parsedUsemap.isNull())
document().removeImageElementByUsemap(*m_parsedUsemap.impl(), *this);
m_parsedUsemap = parseHTMLHashNameReference(value);
- if (inDocument() && !m_parsedUsemap.isNull())
+ if (isConnected() && !m_parsedUsemap.isNull())
document().addImageElementByUsemap(*m_parsedUsemap.impl(), *this);
} else if (name == compositeAttr) {
// FIXME: images don't support blend modes in their compositing attribute.
} else {
if (name == nameAttr) {
bool willHaveName = !value.isNull();
- if (m_hadNameBeforeAttributeChanged != willHaveName && inDocument() && !isInShadowTree() && is<HTMLDocument>(document())) {
+ if (m_hadNameBeforeAttributeChanged != willHaveName && isConnected() && !isInShadowTree() && is<HTMLDocument>(document())) {
HTMLDocument& document = downcast<HTMLDocument>(this->document());
const AtomicString& id = getIdAttribute();
if (!id.isEmpty() && id != getNameAttribute()) {
// in callbacks back to this node.
Node::InsertionNotificationRequest insertNotificationRequest = HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument() && !m_parsedUsemap.isNull())
+ if (insertionPoint.isConnected() && !m_parsedUsemap.isNull())
document().addImageElementByUsemap(*m_parsedUsemap.impl(), *this);
if (is<HTMLPictureElement>(parentNode())) {
// If we have been inserted from a renderer-less document,
// our loader may have not fetched the image, so do it now.
- if (insertionPoint.inDocument() && !m_imageLoader.image())
+ if (insertionPoint.isConnected() && !m_imageLoader.image())
m_imageLoader.updateFromElement();
return insertNotificationRequest;
if (m_form)
m_form->removeImgElement(this);
- if (insertionPoint.inDocument() && !m_parsedUsemap.isNull())
+ if (insertionPoint.isConnected() && !m_parsedUsemap.isNull())
document().removeImageElementByUsemap(*m_parsedUsemap.impl(), *this);
if (is<HTMLPictureElement>(parentNode()))
bool loadError = cachedImage.errorOccurred() || cachedImage.response().httpStatusCode() >= 400;
if (!loadError) {
- if (!element().inDocument()) {
+ if (!element().isConnected()) {
JSC::VM& vm = commonVM();
JSC::JSLockHolder lock(vm);
// FIXME: Adopt reportExtraMemoryVisited, and switch to reportExtraMemoryAllocated.
// unchecked to match other browsers. DOM is not a useful standard for this
// because it says only to fire change events at "lose focus" time, which is
// definitely wrong in practice for these types of elements.
- if (eventBehavior != DispatchNoEvent && inDocument() && m_inputType->shouldSendChangeEventAfterCheckedChanged()) {
+ if (eventBehavior != DispatchNoEvent && isConnected() && m_inputType->shouldSendChangeEventAfterCheckedChanged()) {
setTextAsOfLastFormControlChangeEvent(String());
dispatchFormControlChangeEvent();
}
void HTMLInputElement::finishedInsertingSubtree()
{
HTMLTextFormControlElement::finishedInsertingSubtree();
- if (inDocument() && !form())
+ if (isConnected() && !form())
addToRadioButtonGroup();
}
void HTMLInputElement::removedFrom(ContainerNode& insertionPoint)
{
- if (insertionPoint.inDocument() && !form())
+ if (insertionPoint.isConnected() && !form())
removeFromRadioButtonGroup();
HTMLTextFormControlElement::removedFrom(insertionPoint);
- ASSERT(!inDocument());
+ ASSERT(!isConnected());
#if ENABLE(DATALIST_ELEMENT)
resetListAttributeTargetObserver();
#endif
void HTMLInputElement::resetListAttributeTargetObserver()
{
- if (inDocument())
+ if (isConnected())
m_listAttributeTargetObserver = std::make_unique<ListAttributeTargetObserver>(attributeWithoutSynchronization(listAttr), this);
else
m_listAttributeTargetObserver = nullptr;
return nullptr;
if (auto* formElement = form())
return &formElement->radioButtonGroups();
- if (inDocument())
+ if (isConnected())
return &document().formController().radioButtonGroups();
return nullptr;
}
}
return nullptr;
}
- return inDocument() ? firstElementWithIdIfLabelable(treeScope(), controlId) : nullptr;
+ return isConnected() ? firstElementWithIdIfLabelable(treeScope(), controlId) : nullptr;
}
HTMLFormElement* HTMLLabelElement::form() const
if (oldDisabledState == m_disabledState)
return;
- ASSERT(inDocument() || !styleSheetIsLoading());
- if (!inDocument())
+ ASSERT(isConnected() || !styleSheetIsLoading());
+ if (!isConnected())
return;
// If we change the disabled state while the sheet is still loading, then we have to
if (!dispatchBeforeLoadEvent(getNonEmptyURLAttribute(hrefAttr)))
return false;
// A beforeload handler might have removed us from the document or changed the document.
- if (!inDocument() || &document() != originalDocument.ptr())
+ if (!isConnected() || &document() != originalDocument.ptr())
return false;
return true;
}
void HTMLLinkElement::process()
{
- if (!inDocument()) {
+ if (!isConnected()) {
ASSERT(!m_sheet);
return;
}
Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode& insertionPoint)
{
- bool wasInDocument = inDocument();
+ bool wasInDocument = isConnected();
HTMLElement::insertedInto(insertionPoint);
- if (!insertionPoint.inDocument() || wasInDocument)
+ if (!insertionPoint.isConnected() || wasInDocument)
return InsertionDone;
m_styleScope = &Style::Scope::forNode(*this);
void HTMLLinkElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
- if (!insertionPoint.inDocument() || inDocument())
+ if (!insertionPoint.isConnected() || isConnected())
return;
if (m_sheet)
void HTMLLinkElement::setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* cachedStyleSheet)
{
- if (!inDocument()) {
+ if (!isConnected()) {
ASSERT(!m_sheet);
return;
}
if (document().isHTMLDocument())
return;
}
- if (inDocument())
+ if (isConnected())
treeScope().removeImageMap(*this);
String mapName = value;
if (mapName[0] == '#')
mapName = mapName.substring(1);
m_name = mapName;
- if (inDocument())
+ if (isConnected())
treeScope().addImageMap(*this);
return;
Node::InsertionNotificationRequest HTMLMapElement::insertedInto(ContainerNode& insertionPoint)
{
Node::InsertionNotificationRequest request = HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
treeScope().addImageMap(*this);
return request;
}
void HTMLMapElement::removedFrom(ContainerNode& insertionPoint)
{
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
treeScope().removeImageMap(*this);
HTMLElement::removedFrom(insertionPoint);
}
LOG(Media, "HTMLMediaElement::insertedInto(%p)", this);
HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument()) {
+ if (insertionPoint.isConnected()) {
m_inActiveDocument = true;
#if PLATFORM(IOS)
LOG(Media, "HTMLMediaElement::removedFrom(%p)", this);
m_inActiveDocument = false;
- if (insertionPoint.inDocument()) {
+ if (insertionPoint.isConnected()) {
// Pause asynchronously to let the operation that removed us finish, in case we get inserted back into a document.
m_pauseAfterDetachedTaskQueue.enqueueTask(std::bind(&HTMLMediaElement::pauseAfterDetachedTask, this));
}
ensureUserAgentShadowRoot().appendChild(mediaControls);
- if (!controls() || !inDocument())
+ if (!controls() || !isConnected())
mediaControls->hide();
return true;
#endif
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
- if (!requireControls || !inDocument() || !inActiveDocument())
+ if (!requireControls || !isConnected() || !inActiveDocument())
return;
ensureMediaControlsShadowRoot();
#else
- if (!requireControls || !inDocument() || !inActiveDocument()) {
+ if (!requireControls || !isConnected() || !inActiveDocument()) {
if (hasMediaControls())
mediaControls()->hide();
return;
Node::InsertionNotificationRequest HTMLMetaElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument())
+ if (insertionPoint.isConnected())
process();
return InsertionDone;
}
void HTMLMetaElement::process()
{
// Changing a meta tag while it's not in the tree shouldn't have any effect on the document.
- if (!inDocument())
+ if (!isConnected())
return;
const AtomicString& contentValue = attributeWithoutSynchronization(contentAttr);
} else
HTMLPlugInImageElement::parseAttribute(name, value);
- if (!invalidateRenderer || !inDocument() || !renderer())
+ if (!invalidateRenderer || !isConnected() || !renderer())
return;
clearUseFallbackContent();
void HTMLObjectElement::childrenChanged(const ChildChange& change)
{
updateDocNamedItem();
- if (inDocument() && !useFallbackContent()) {
+ if (isConnected() && !useFallbackContent()) {
setNeedsWidgetUpdate(true);
invalidateStyleForSubtree();
}
if (useFallbackContent())
return;
- if (!inDocument())
+ if (!isConnected())
return;
invalidateStyleAndRenderersForSubtree();
isNamedItem = false;
child = child->nextSibling();
}
- if (isNamedItem != wasNamedItem && inDocument() && !isInShadowTree() && is<HTMLDocument>(document())) {
+ if (isNamedItem != wasNamedItem && isConnected() && !isInShadowTree() && is<HTMLDocument>(document())) {
HTMLDocument& document = downcast<HTMLDocument>(this->document());
const AtomicString& id = getIdAttribute();
// HTMLObjectElement needs to delay widget updates until after all children are parsed,
// For HTMLEmbedElement this delay is unnecessary, but there is no harm in doing the same.
setNeedsWidgetUpdate(true);
- if (inDocument())
+ if (isConnected())
invalidateStyleForSubtree();
}
m_activeSelectionAnchorIndex = -1;
setOptionsChangedOnRenderer();
invalidateStyleForSubtree();
- if (!inDocument()) {
+ if (!isConnected()) {
if (HTMLCollection* collection = cachedHTMLCollection(SelectOptions))
collection->invalidateCache(document());
}
- if (!inDocument())
+ if (!isConnected())
invalidateSelectedItems();
if (auto* cache = document().existingAXObjectCache())
cache->childrenChanged(this);
Node::InsertionNotificationRequest HTMLStyleElement::insertedInto(ContainerNode& insertionPoint)
{
- bool wasInDocument = inDocument();
+ bool wasInDocument = isConnected();
auto result = HTMLElement::insertedInto(insertionPoint);
- if (insertionPoint.inDocument() && !wasInDocument)
+ if (insertionPoint.isConnected() && !wasInDocument)
m_styleSheetOwner.insertedIntoDocument(*this);
return result;
}
void HTMLStyleElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
- if (insertionPoint.inDocument() && !inDocument())
+ if (insertionPoint.isConnected() && !isConnected())
m_styleSheetOwner.removedFromDocument(*this);
}
Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(ContainerNode& insertionPoint)
{
InsertionNotificationRequest insertionNotificationRequest = HTMLFormControlElementWithState::insertedInto(insertionPoint);
- if (!insertionPoint.inDocument())
+ if (!insertionPoint.isConnected())
return insertionNotificationRequest;
String initialValue = value();
setTextAsOfLastFormControlChangeEvent(initialValue.isNull() ? emptyString() : initialValue);
Node::InsertionNotificationRequest HTMLTitleElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
- if (inDocument() && !isInShadowTree())
+ if (isConnected() && !isInShadowTree())
document().titleElementAdded(*this);
return InsertionDone;
}
void HTMLTitleElement::removedFrom(ContainerNode& insertionPoint)
{
HTMLElement::removedFrom(insertionPoint);
- if (insertionPoint.inDocument() && !insertionPoint.isInShadowTree())
+ if (insertionPoint.isConnected() && !insertionPoint.isInShadowTree())
document().titleElementRemoved(*this);
}
Color currentColor(HTMLCanvasElement* canvas)
{
- if (!canvas || !canvas->inDocument() || !canvas->inlineStyle())
+ if (!canvas || !canvas->isConnected() || !canvas->inlineStyle())
return Color::black;
Color color = CSSParser::parseColor(canvas->inlineStyle()->getPropertyValue(CSSPropertyColor));
if (!color.isValid())
auto selectedRange = selection.selection().toNormalizedRange();
ContainerNode* parentNode = node.parentNode();
- if (!parentNode || !parentNode->inDocument())
+ if (!parentNode || !parentNode->isConnected())
return false;
unsigned nodeIndex = node.computeNodeIndex();
void EventHandler::updateDragStateAfterEditDragIfNeeded(Element& rootEditableElement)
{
// If inserting the dragged contents removed the drag source, we still want to fire dragend at the root editable element.
- if (dragState().source && !dragState().source->inDocument())
+ if (dragState().source && !dragState().source->isConnected())
dragState().source = &rootEditableElement;
}
void PointerLockController::requestPointerLock(Element* target)
{
- if (!target || !target->inDocument() || m_documentOfRemovedElementWhileWaitingForUnlock) {
+ if (!target || !target->isConnected() || m_documentOfRemovedElementWhileWaitingForUnlock) {
enqueueEvent(eventNames().pointerlockerrorEvent, target);
return;
}
Node* node = innerNode();
if (!node)
return 0;
- if (node->inDocument())
+ if (node->isConnected())
return node;
Element* element = node->parentElement();
- if (element && element->inDocument())
+ if (element && element->isConnected())
return element;
return node;
RenderTextControlMultiLine::~RenderTextControlMultiLine()
{
- if (textAreaElement().inDocument())
+ if (textAreaElement().isConnected())
textAreaElement().rendererWillBeDestroyed();
}
LOG(WebReplay, "%-20s --->%s DOM event: type=%s, target=%u/node[%p] %s\n", "ReplayEvents",
(eventIsUnrelated) ? "Unrelated" : "Dispatching",
event.type().string().utf8().data(),
- frameIndexFromDocument((node->inDocument()) ? &node->document() : node->ownerDocument()),
+ frameIndexFromDocument((node->isConnected()) ? &node->document() : node->ownerDocument()),
node,
node->nodeName().utf8().data());
} else if (DOMWindow* window = target->toDOMWindow()) {
Document* document = frame ? frame->document() : nullptr;
// Fetch the document from the event target, because the target could be detached.
if (Node* node = target->toNode())
- document = node->inDocument() ? &node->document() : node->ownerDocument();
+ document = node->isConnected() ? &node->document() : node->ownerDocument();
else if (DOMWindow* window = target->toDOMWindow())
document = window->document();
Scope& Scope::forNode(Node& node)
{
- ASSERT(node.inDocument());
+ ASSERT(node.isConnected());
auto* shadowRoot = node.containingShadowRoot();
if (shadowRoot)
return shadowRoot->styleScope();
void Scope::addStyleSheetCandidateNode(Node& node, bool createdByParser)
{
- if (!node.inDocument())
+ if (!node.isConnected())
return;
// Until the <body> exists, we have no choice but to compare document positions,
auto& node = *it;
auto& parent = this->parent();
- ASSERT(node.inDocument());
+ ASSERT(node.isConnected());
ASSERT(node.containingShadowRoot() == scope().shadowRoot);
ASSERT(node.parentElement() == parent.element || is<ShadowRoot>(node.parentNode()) || node.parentElement()->shadowRoot());
static inline void applyCSSPropertyToTargetAndInstances(SVGElement& targetElement, const QualifiedName& attributeName, const String& valueAsString)
{
- // FIXME: Do we really need to check both inDocument and !parentNode?
- if (attributeName == anyQName() || !targetElement.inDocument() || !targetElement.parentNode())
+ // FIXME: Do we really need to check both isConnected and !parentNode?
+ if (attributeName == anyQName() || !targetElement.isConnected() || !targetElement.parentNode())
return;
CSSPropertyID id = cssPropertyID(attributeName.localName());
static inline void removeCSSPropertyFromTargetAndInstances(SVGElement& targetElement, const QualifiedName& attributeName)
{
- // FIXME: Do we really need to check both inDocument and !parentNode?
- if (attributeName == anyQName() || !targetElement.inDocument() || !targetElement.parentNode())
+ // FIXME: Do we really need to check both isConnected and !parentNode?
+ if (attributeName == anyQName() || !targetElement.isConnected() || !targetElement.parentNode())
return;
CSSPropertyID id = cssPropertyID(attributeName.localName());
static inline void notifyTargetAndInstancesAboutAnimValChange(SVGElement& targetElement, const QualifiedName& attributeName)
{
- if (attributeName == anyQName() || !targetElement.inDocument() || !targetElement.parentNode())
+ if (attributeName == anyQName() || !targetElement.isConnected() || !targetElement.parentNode())
return;
SVGElement::InstanceUpdateBlocker blocker(targetElement);
void SVGElement::removedFrom(ContainerNode& rootParent)
{
- bool wasInDocument = rootParent.inDocument();
+ bool wasInDocument = rootParent.isConnected();
if (wasInDocument)
updateRelativeLengthsInformation(false, this);
// Notify resources about id changes, this is important as we cache resources by id in SVGDocumentExtensions
if (is<RenderSVGResourceContainer>(renderer))
downcast<RenderSVGResourceContainer>(*renderer).idChanged();
- if (inDocument())
+ if (isConnected())
buildPendingResourcesIfNeeded();
invalidateInstances();
return;
void SVGElement::buildPendingResourcesIfNeeded()
{
- if (!needsPendingResourceHandling() || !inDocument() || isInShadowTree())
+ if (!needsPendingResourceHandling() || !isConnected() || isInShadowTree())
return;
SVGDocumentExtensions& extensions = document().accessSVGExtensions();
void SVGElement::updateRelativeLengthsInformation(bool hasRelativeLengths, SVGElement* element)
{
// If we're not yet in a document, this function will be called again from insertedInto(). Do nothing now.
- if (!inDocument())
+ if (!isConnected())
return;
// An element wants to notify us that its own relative lengths state changed.
ASSERT(targetElement);
if (!isKnownAttribute(attrName))
return false;
- if (!targetElement->inDocument())
+ if (!targetElement->isConnected())
return true;
// Handle dynamic updates of the 'externalResourcesRequired' attribute. Only possible case: changing from 'true' to 'false'
void SVGFEImageElement::buildPendingResource()
{
clearResourceReferences();
- if (!inDocument())
+ if (!isConnected())
return;
String id;
void SVGFEImageElement::removedFrom(ContainerNode& rootParent)
{
SVGFilterPrimitiveStandardAttributes::removedFrom(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
clearResourceReferences();
}
void SVGFEImageElement::notifyFinished(CachedResource&)
{
- if (!inDocument())
+ if (!isConnected())
return;
Element* parent = parentElement();
void SVGFontFaceElement::rebuildFontFace()
{
- if (!inDocument()) {
+ if (!isConnected()) {
ASSERT(!m_fontElement);
return;
}
Node::InsertionNotificationRequest SVGFontFaceElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (!rootParent.inDocument()) {
+ if (!rootParent.isConnected()) {
ASSERT(!m_fontElement);
return InsertionDone;
}
{
SVGElement::removedFrom(rootParent);
- if (rootParent.inDocument()) {
+ if (rootParent.isConnected()) {
m_fontElement = nullptr;
document().accessSVGExtensions().unregisterSVGFontFaceElement(this);
m_fontFaceRule->mutableProperties().clear();
Node::InsertionNotificationRequest SVGImageElement::insertedInto(ContainerNode& rootParent)
{
SVGGraphicsElement::insertedInto(rootParent);
- if (!rootParent.inDocument())
+ if (!rootParent.isConnected())
return InsertionDone;
// Update image loader, as soon as we're living in the tree.
// We can only resolve base URIs properly, after that!
void SVGMPathElement::buildPendingResource()
{
clearResourceReferences();
- if (!inDocument())
+ if (!isConnected())
return;
String id;
Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
return InsertionShouldCallFinishedInsertingSubtree;
return InsertionDone;
}
{
SVGElement::removedFrom(rootParent);
notifyParentOfPathChange(&rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
clearResourceReferences();
}
{
// The behavior of currentScale() is undefined when we're dealing with non-standalone SVG documents.
// If the document is embedded, the scaling is handled by the host renderer.
- if (!inDocument() || !isOutermostSVGSVGElement())
+ if (!isConnected() || !isOutermostSVGSVGElement())
return nullptr;
Frame* frame = document().frame();
return frame && frame->isMainFrame() ? frame : nullptr;
Node::InsertionNotificationRequest SVGSVGElement::insertedInto(ContainerNode& rootParent)
{
- if (rootParent.inDocument()) {
+ if (rootParent.isConnected()) {
document().accessSVGExtensions().addTimeContainer(this);
// Animations are started at the end of document parsing and after firing the load event,
void SVGSVGElement::removedFrom(ContainerNode& rootParent)
{
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
document().accessSVGExtensions().removeTimeContainer(this);
SVGGraphicsElement::removedFrom(rootParent);
}
Node::InsertionNotificationRequest SVGScriptElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
SVGExternalResourcesRequired::insertedIntoDocument(this);
return shouldCallFinishedInsertingSubtree(rootParent) ? InsertionShouldCallFinishedInsertingSubtree : InsertionDone;
}
Node::InsertionNotificationRequest SVGStyleElement::insertedInto(ContainerNode& rootParent)
{
- bool wasInDocument = inDocument();
+ bool wasInDocument = isConnected();
auto result = SVGElement::insertedInto(rootParent);
- if (rootParent.inDocument() && !wasInDocument)
+ if (rootParent.isConnected() && !wasInDocument)
m_styleSheetOwner.insertedIntoDocument(*this);
return result;
}
void SVGStyleElement::removedFrom(ContainerNode& rootParent)
{
SVGElement::removedFrom(rootParent);
- if (rootParent.inDocument() && !inDocument())
+ if (rootParent.isConnected() && !isConnected())
m_styleSheetOwner.removedFromDocument(*this);
}
{
ASSERT(!isAttached());
ASSERT(target.get());
- ASSERT(target->inDocument());
+ ASSERT(target->isConnected());
target->addEventListener(eventNames().DOMSubtreeModifiedEvent, *this, false);
target->addEventListener(eventNames().DOMNodeRemovedFromDocumentEvent, *this, false);
if (container)
container->setTextContent(emptyContent);
- if (!inDocument())
+ if (!isConnected())
return;
// Mark the referenced ID as pending.
m_targetListener->detach();
// If we're not yet in a document, this function will be called again from insertedInto().
- if (!inDocument())
+ if (!isConnected())
return;
String id;
Node::InsertionNotificationRequest SVGTRefElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
return InsertionShouldCallFinishedInsertingSubtree;
return InsertionDone;
}
void SVGTRefElement::removedFrom(ContainerNode& rootParent)
{
SVGElement::removedFrom(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
m_targetListener->detach();
}
ASSERT(targetElement);
if (!isKnownAttribute(attributeName))
return false;
- if (!targetElement->inDocument())
+ if (!targetElement->isConnected())
return true;
targetElement->invalidateStyleAndRenderersForSubtree();
return true;
void SVGTextPathElement::buildPendingResource()
{
clearResourceReferences();
- if (!inDocument())
+ if (!isConnected())
return;
String id;
void SVGTextPathElement::removedFrom(ContainerNode& rootParent)
{
SVGTextContentElement::removedFrom(rootParent);
- if (rootParent.inDocument())
+ if (rootParent.isConnected())
clearResourceReferences();
}
Node::InsertionNotificationRequest SVGTitleElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (!rootParent.inDocument())
+ if (!rootParent.isConnected())
return InsertionDone;
if (firstChild() && document().isSVGDocument())
void SVGTitleElement::removedFrom(ContainerNode& rootParent)
{
SVGElement::removedFrom(rootParent);
- if (rootParent.inDocument() && document().isSVGDocument())
+ if (rootParent.isConnected() && document().isSVGDocument())
document().titleElementRemoved(*this);
}
Node::InsertionNotificationRequest SVGUseElement::insertedInto(ContainerNode& rootParent)
{
SVGGraphicsElement::insertedInto(rootParent);
- if (inDocument()) {
+ if (isConnected()) {
SVGExternalResourcesRequired::insertedIntoDocument(this);
invalidateShadowTree();
updateExternalDocument();
// FIXME: It's expensive to re-clone the entire tree every time. We should find a more efficient way to handle this.
clearShadowTree();
- if (isInShadowTree() || !inDocument())
+ if (isInShadowTree() || !isConnected())
return;
String targetID;
// This function is used only on elements in subtrees that are not yet in documents, so
// mutation events are not a factor; there are no event listeners to handle those events.
// Assert that it's not in a document to make sure callers are still using it this way.
- ASSERT(!subtree.inDocument());
+ ASSERT(!subtree.isConnected());
Vector<Element*> disallowedElements;
auto descendants = descendantsOfType<Element>(subtree);
return nullptr;
auto& target = downcast<SVGElement>(*targetCandidate);
- if (!target.inDocument() || isDisallowedElement(target))
+ if (!target.isConnected() || isDisallowedElement(target))
return nullptr;
// Reject any target that has already been cloned to create one of the ancestors of this element,
void SVGUseElement::updateExternalDocument()
{
URL externalDocumentURL;
- if (inDocument() && isExternalURIReference(href(), document())) {
+ if (isConnected() && isExternalURIReference(href(), document())) {
externalDocumentURL = document().completeURL(href());
if (!externalDocumentURL.hasFragmentIdentifier())
externalDocumentURL = URL();
{
clearResourceReferences();
- if (!inDocument()) {
+ if (!isConnected()) {
// Reset the target element if we are no longer in the document.
setTargetElement(nullptr);
return;
target = SVGURIReference::targetElementFromIRIString(href, document(), &id);
SVGElement* svgTarget = is<SVGElement>(target) ? downcast<SVGElement>(target) : nullptr;
- if (svgTarget && !svgTarget->inDocument())
+ if (svgTarget && !svgTarget->isConnected())
svgTarget = nullptr;
if (svgTarget != targetElement())
Node::InsertionNotificationRequest SVGSMILElement::insertedInto(ContainerNode& rootParent)
{
SVGElement::insertedInto(rootParent);
- if (!rootParent.inDocument())
+ if (!rootParent.isConnected())
return InsertionDone;
// Verify we are not in <use> instance tree.
void SVGSMILElement::removedFrom(ContainerNode& rootParent)
{
- if (rootParent.inDocument()) {
+ if (rootParent.isConnected()) {
clearResourceReferences();
disconnectConditions();
setTargetElement(nullptr);
parseBeginOrEnd(attributeWithoutSynchronization(SVGNames::endAttr), End);
}
parseBeginOrEnd(value.string(), Begin);
- if (inDocument())
+ if (isConnected())
connectConditions();
} else if (name == SVGNames::endAttr) {
if (!m_conditions.isEmpty()) {
parseBeginOrEnd(attributeWithoutSynchronization(SVGNames::beginAttr), Begin);
}
parseBeginOrEnd(value.string(), End);
- if (inDocument())
+ if (isConnected())
connectConditions();
} else if (name == SVGNames::onendAttr)
setAttributeEventListener(eventNames().endEventEvent, name, value);
else if (attrName.matches(XLinkNames::hrefAttr)) {
InstanceInvalidationGuard guard(*this);
buildPendingResource();
- } else if (inDocument()) {
+ } else if (isConnected()) {
if (attrName == SVGNames::beginAttr)
beginListChanged(elapsed());
else if (attrName == SVGNames::endAttr)
{
if (is<Attr>(*node))
node = downcast<Attr>(*node).ownerElement();
- if (node->inDocument())
+ if (node->isConnected())
node = &node->document();
else {
while (Node* parent = node->parentNode())
// The element's parent may have already been removed from document.
// Parsing continues in this case, but scripts aren't executed.
- if (!element.inDocument()) {
+ if (!element.isConnected()) {
popCurrentNode();
return;
}
2017-02-02 Chris Dumez <cdumez@apple.com>
+ Rename Node::inDocument() to isConnected()
+ https://bugs.webkit.org/show_bug.cgi?id=167743
+
+ Reviewed by Sam Weinig.
+
+ Rename Node::inDocument() to isConnected() to match the DOM specification more closely:
+ - https://dom.spec.whatwg.org/#connected
+
+ * DOM/DOMNode.mm:
+ (-[DOMNode isConnected]):
+ * WebView/WebFrame.mm:
+ (-[WebFrame selectNSRange:onElement:]):
+
+2017-02-02 Chris Dumez <cdumez@apple.com>
+
[Crash] com.apple.WebKit.WebContent at WebKit: WebKit::WebPage::fromCorePage()
https://bugs.webkit.org/show_bug.cgi?id=167738
<rdar://problem/30229990>
- (BOOL)isConnected
{
JSMainThreadNullState state;
- return unwrap(*self).inDocument();
+ return unwrap(*self).isConnected();
}
- (DOMElement *)parentElement
return;
Node* node = core(element);
- if (!node->inDocument())
+ if (!node->isConnected())
return;
-
+
frame->selection().selectRangeOnElement(range.location, range.length, *node);
}