Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, ExceptionCode& ec) { // In Internet Explorer if the element has no parent and where is "beforeBegin" or "afterEnd", // a document fragment is created and the elements appended in the correct order. This document // fragment isn't returned anywhere. // // This is impossible for us to implement as the DOM tree does not allow for such structures, // Opera also appears to disallow such usage. if (equalIgnoringCase(where, "beforeBegin")) { ContainerNode* parent = this->parentNode(); return (parent && parent->insertBefore(newChild, this, ec)) ? newChild : 0; } if (equalIgnoringCase(where, "afterBegin")) return insertBefore(newChild, firstChild(), ec) ? newChild : 0; if (equalIgnoringCase(where, "beforeEnd")) return appendChild(newChild, ec) ? newChild : 0; if (equalIgnoringCase(where, "afterEnd")) { ContainerNode* parent = this->parentNode(); return (parent && parent->insertBefore(newChild, nextSibling(), ec)) ? newChild : 0; } // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative. ec = NOT_SUPPORTED_ERR; return 0; }
void SplitElementCommand::executeApply() { if (m_atChild->parentNode() != m_element2) return; HeapVector<Member<Node>> children; for (Node* node = m_element2->firstChild(); node != m_atChild; node = node->nextSibling()) children.append(node); DummyExceptionStateForTesting exceptionState; ContainerNode* parent = m_element2->parentNode(); if (!parent || !hasEditableStyle(*parent)) return; parent->insertBefore(m_element1.get(), m_element2.get(), exceptionState); if (exceptionState.hadException()) return; // Delete id attribute from the second element because the same id cannot be // used for more than one element m_element2->removeAttribute(HTMLNames::idAttr); for (const auto& child : children) m_element1->appendChild(child, exceptionState); }
void MergeIdenticalElementsCommand::doUnapply() { ASSERT(m_element1); ASSERT(m_element2); RefPtr<Node> atChild = m_atChild.release(); ContainerNode* parent = m_element2->parentNode(); if (!parent || !parent->rendererIsEditable()) return; TrackExceptionState es; parent->insertBefore(m_element1.get(), m_element2.get(), es); if (es.hadException()) return; Vector<RefPtr<Node> > children; for (Node* child = m_element2->firstChild(); child && child != atChild; child = child->nextSibling()) children.append(child); size_t size = children.size(); for (size_t i = 0; i < size; ++i) m_element1->appendChild(children[i].release(), es); }
void SplitElementCommand::executeApply() { if (m_atChild->parentNode() != m_element2) return; Vector<RefPtr<Node>> children; for (Node* node = m_element2->firstChild(); node != m_atChild; node = node->nextSibling()) children.append(node); ExceptionCode ec = 0; ContainerNode* parent = m_element2->parentNode(); if (!parent || !parent->hasEditableStyle()) return; parent->insertBefore(m_element1.get(), m_element2.get(), ec); if (ec) return; // Delete id attribute from the second element because the same id cannot be used for more than one element m_element2->removeAttribute(HTMLNames::idAttr); size_t size = children.size(); for (size_t i = 0; i < size; ++i) m_element1->appendChild(children[i], ec); }
void InsertNodeBeforeCommand::doApply() { ContainerNode* parent = m_refChild->parentNode(); if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))) return; ASSERT(parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)); parent->insertBefore(m_insertChild.get(), m_refChild.get(), IGNORE_EXCEPTION); }
void InsertNodeBeforeCommand::doApply() { ContainerNode* parent = m_refChild->parentNode(); if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !isEditableNode(*parent))) return; ASSERT(isEditableNode(*parent)); parent->insertBefore(*m_insertChild, m_refChild.get(), IGNORE_EXCEPTION); }
void InsertNodeBeforeCommand::doApply(EditingState*) { ContainerNode* parent = m_refChild->parentNode(); document().updateStyleAndLayoutTree(); if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !hasEditableStyle(*parent))) return; DCHECK(hasEditableStyle(*parent)) << parent; parent->insertBefore(m_insertChild.get(), m_refChild.get(), IGNORE_EXCEPTION); }
void InsertNodeBeforeCommand::doApply() { ContainerNode* parent = m_refChild->parentNode(); if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))) return; ASSERT(parent->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)); parent->insertBefore(m_insertChild.get(), m_refChild.get(), IGNORE_EXCEPTION); if (AXObjectCache* cache = document().existingAXObjectCache()) cache->nodeTextChangeNotification(m_insertChild.get(), AXObjectCache::AXTextInserted, 0, m_insertChild->nodeValue()); }
HTMLTableRowElement* HTMLTableElement::insertRow( int index, ExceptionState& exceptionState) { if (index < -1) { exceptionState.throwDOMException( IndexSizeError, "The index provided (" + String::number(index) + ") is less than -1."); return nullptr; } HTMLTableRowElement* lastRow = nullptr; HTMLTableRowElement* row = nullptr; if (index == -1) { lastRow = HTMLTableRowsCollection::lastRow(*this); } else { for (int i = 0; i <= index; ++i) { row = HTMLTableRowsCollection::rowAfter(*this, lastRow); if (!row) { if (i != index) { exceptionState.throwDOMException( IndexSizeError, "The index provided (" + String::number(index) + ") is greater than the number of rows in the table (" + String::number(i) + ")."); return nullptr; } break; } lastRow = row; } } ContainerNode* parent; if (lastRow) { parent = row ? row->parentNode() : lastRow->parentNode(); } else { parent = lastBody(); if (!parent) { HTMLTableSectionElement* newBody = HTMLTableSectionElement::create(tbodyTag, document()); HTMLTableRowElement* newRow = HTMLTableRowElement::create(document()); newBody->appendChild(newRow, exceptionState); appendChild(newBody, exceptionState); return newRow; } } HTMLTableRowElement* newRow = HTMLTableRowElement::create(document()); parent->insertBefore(newRow, row, exceptionState); return newRow; }
void InsertNodeBeforeCommand::doApply() { ContainerNode* parent = m_refChild->parentNode(); if (!parent || (m_shouldAssumeContentIsAlwaysEditable == DoNotAssumeContentIsAlwaysEditable && !isEditableNode(*parent))) return; ASSERT(isEditableNode(*parent)); parent->insertBefore(*m_insertChild, m_refChild.get(), IGNORE_EXCEPTION); if (shouldPostAccessibilityNotification()) { Position position = is<Text>(m_insertChild.get()) ? Position(downcast<Text>(m_insertChild.get()), 0) : createLegacyEditingPosition(m_insertChild.get(), 0); notifyAccessibilityForTextChange(m_insertChild.get(), applyEditType(), m_insertChild->nodeValue(), VisiblePosition(position)); } }
void JoinTextNodesCommand::doUnapply() { if (m_text1->parentNode()) return; ContainerNode* parent = m_text2->parentNode(); if (!parent || !parent->rendererIsEditable()) return; ExceptionCode ec = 0; parent->insertBefore(m_text1.get(), m_text2.get(), ec); if (ec) return; m_text2->deleteData(0, m_text1->length(), ec); }
static void swapInNodePreservingAttributesAndChildren(HTMLElement* newNode, HTMLElement* nodeToReplace) { ASSERT(nodeToReplace->inDocument()); ExceptionCode ec = 0; ContainerNode* parentNode = nodeToReplace->parentNode(); parentNode->insertBefore(newNode, nodeToReplace, ec); ASSERT(!ec); RefPtr<Node> nextChild; for (Node* child = nodeToReplace->firstChild(); child; child = nextChild.get()) { nextChild = child->nextSibling(); newNode->appendChild(child, ec); ASSERT(!ec); } newNode->attributes()->setAttributes(*nodeToReplace->attributes()); parentNode->removeChild(nodeToReplace, ec); ASSERT(!ec); }
void MergeIdenticalElementsCommand::doUnapply() { ASSERT(m_element1); ASSERT(m_element2); RefPtrWillBeRawPtr<Node> atChild = m_atChild.release(); ContainerNode* parent = m_element2->parentNode(); if (!parent || !parent->hasEditableStyle()) return; TrackExceptionState exceptionState; parent->insertBefore(m_element1.get(), m_element2.get(), exceptionState); if (exceptionState.hadException()) return; WillBeHeapVector<RefPtrWillBeMember<Node>> children; for (Node* child = m_element2->firstChild(); child && child != atChild; child = child->nextSibling()) children.append(child); for (auto& child : children) m_element1->appendChild(child.release(), exceptionState); }
void MergeIdenticalElementsCommand::doUnapply() { ASSERT(m_element1); ASSERT(m_element2); RefPtr<Node> atChild = m_atChild.release(); ContainerNode* parent = m_element2->parentNode(); if (!parent || !parent->hasEditableStyle()) return; ExceptionCode ec = 0; parent->insertBefore(*m_element1, m_element2.get(), ec); if (ec) return; Vector<Ref<Node>> children; for (Node* child = m_element2->firstChild(); child && child != atChild; child = child->nextSibling()) children.append(*child); for (auto& child : children) m_element1->appendChild(WTF::move(child), ec); }