本文整理汇总了C++中ContainerNode::insertBefore方法的典型用法代码示例。如果您正苦于以下问题:C++ ContainerNode::insertBefore方法的具体用法?C++ ContainerNode::insertBefore怎么用?C++ ContainerNode::insertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerNode
的用法示例。
在下文中一共展示了ContainerNode::insertBefore方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: insertAdjacent
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;
}
示例2: executeApply
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);
}
示例3: doUnapply
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);
}
示例4: executeApply
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);
}
示例5: doApply
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);
}
示例6: doApply
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);
}
示例7: doApply
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);
}
示例8: doApply
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());
}
示例9: insertRow
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;
}
示例10: doApply
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));
}
}
示例11: doUnapply
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);
}
示例12: swapInNodePreservingAttributesAndChildren
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);
}
示例13: doUnapply
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);
}
示例14: doUnapply
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);
}