本文整理汇总了C++中setEndingSelection函数的典型用法代码示例。如果您正苦于以下问题:C++ setEndingSelection函数的具体用法?C++ setEndingSelection怎么用?C++ setEndingSelection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setEndingSelection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: endingSelection
// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
// from text removal.
bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
{
if (!endingSelection().isRange())
return false;
if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
return false;
Position start = endingSelection().start();
Position end = endingSelection().end();
if (start.node() != end.node() || !start.node()->isTextNode() || isTabSpanTextNode(start.node()))
return false;
replaceTextInNode(static_cast<Text*>(start.node()), start.offset(), end.offset() - start.offset(), text);
Position endPosition(start.node(), start.offset() + text.length());
// We could have inserted a part of composed character sequence,
// so we are basically treating ending selection as a range to avoid validation.
// <http://bugs.webkit.org/show_bug.cgi?id=15781>
Selection forcedEndingSelection;
forcedEndingSelection.setWithoutValidation(start, endPosition);
setEndingSelection(forcedEndingSelection);
if (!selectInsertedText)
setEndingSelection(Selection(endingSelection().visibleEnd()));
return true;
}
示例2: endingSelection
// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
// from text removal.
bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
{
if (!endingSelection().isRange())
return false;
if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
return false;
Position start = endingSelection().start();
Position endPosition = replaceSelectedTextInNode(text);
if (endPosition.isNull())
return false;
// We could have inserted a part of composed character sequence,
// so we are basically treating ending selection as a range to avoid validation.
// <http://bugs.webkit.org/show_bug.cgi?id=15781>
VisibleSelection forcedEndingSelection;
forcedEndingSelection.setWithoutValidation(start, endPosition);
forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
setEndingSelection(forcedEndingSelection);
if (!selectInsertedText)
setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
return true;
}
示例3: assert
void InsertTextCommand::input(const String &text, bool selectInsertedText)
{
assert(text.find('\n') == -1);
if (endingSelection().isNone())
return;
// Delete the current selection.
if (endingSelection().isRange())
deleteSelection(false, true, true);
// Insert the character at the leftmost candidate.
Position startPosition = endingSelection().start().upstream();
deleteInsignificantText(startPosition.upstream(), startPosition.downstream());
if (!startPosition.inRenderedContent())
startPosition = startPosition.downstream();
startPosition = positionAvoidingSpecialElementBoundary(startPosition);
Position endPosition;
if (text == "\t") {
endPosition = insertTab(startPosition);
startPosition = endPosition.previous();
removeBlockPlaceholder(VisiblePosition(startPosition));
m_charactersAdded += 1;
} else {
// Make sure the document is set up to receive text
startPosition = prepareForTextInsertion(startPosition);
removeBlockPlaceholder(VisiblePosition(startPosition));
Text *textNode = static_cast<Text *>(startPosition.node());
int offset = startPosition.offset();
insertTextIntoNode(textNode, offset, text);
endPosition = Position(textNode, offset + text.length());
// The insertion may require adjusting adjacent whitespace, if it is present.
rebalanceWhitespaceAt(endPosition);
// Rebalancing on both sides isn't necessary if we've inserted a space.
if (text != " ")
rebalanceWhitespaceAt(startPosition);
m_charactersAdded += text.length();
}
setEndingSelection(Selection(startPosition, endPosition, DOWNSTREAM));
// Handle the case where there is a typing style.
// FIXME: Improve typing style.
// See this bug: <rdar://problem/3769899> Implementation of typing style needs improvement
CSSMutableStyleDeclaration* typingStyle = document()->frame()->typingStyle();
RefPtr<CSSComputedStyleDeclaration> endingStyle = endPosition.computedStyle();
endingStyle->diff(typingStyle);
if (typingStyle && typingStyle->length() > 0)
applyStyle(typingStyle);
if (!selectInsertedText)
setEndingSelection(endingSelection().end(), endingSelection().affinity());
}
示例4: endingSelection
void MoveSelectionCommand::doApply()
{
Selection selection = endingSelection();
ASSERT(selection.isRange());
Position pos = m_position;
if (pos.isNull())
return;
// Update the position otherwise it may become invalid after the selection is deleted.
Node *positionNode = m_position.node();
int positionOffset = m_position.offset();
Position selectionEnd = selection.end();
int selectionEndOffset = selectionEnd.offset();
if (selectionEnd.node() == positionNode && selectionEndOffset < positionOffset) {
positionOffset -= selectionEndOffset;
Position selectionStart = selection.start();
if (selectionStart.node() == positionNode) {
positionOffset += selectionStart.offset();
}
pos = Position(positionNode, positionOffset);
}
deleteSelection(m_smartMove);
// If the node for the destination has been removed as a result of the deletion,
// 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.node()->inDocument())
pos = endingSelection().start();
setEndingSelection(Selection(pos, endingSelection().affinity()));
applyCommandToComposite(ReplaceSelectionCommand::create(positionNode->document(), m_fragment, true, m_smartMove));
}
示例5: applyStyledElement
void CreateLinkCommand::doApply(EditingState* editingState) {
if (endingSelection().isNone())
return;
HTMLAnchorElement* anchorElement = HTMLAnchorElement::create(document());
anchorElement->setHref(AtomicString(m_url));
if (endingSelection().isRange()) {
applyStyledElement(anchorElement, editingState);
if (editingState->isAborted())
return;
} else {
insertNodeAt(anchorElement, endingSelection().start(), editingState);
if (editingState->isAborted())
return;
Text* textNode = Text::create(document(), m_url);
appendNode(textNode, anchorElement, editingState);
if (editingState->isAborted())
return;
document().updateStyleAndLayoutIgnorePendingStylesheets();
setEndingSelection(createVisibleSelection(
Position::inParentBeforeNode(*anchorElement),
Position::inParentAfterNode(*anchorElement), TextAffinity::Downstream,
endingSelection().isDirectional()));
}
}
示例6: m_document
EditCommand::EditCommand(Document& document, const VisibleSelection& startingSelection, const VisibleSelection& endingSelection)
: m_document(document)
{
ASSERT(document.frame());
setStartingSelection(startingSelection);
setEndingSelection(endingSelection);
}
示例7: m_document
EditCommand::EditCommand(Document* document)
: m_document(document)
, m_parent(0)
{
ASSERT(m_document);
ASSERT(m_document->frame());
setStartingSelection(avoidIntersectionWithNode(m_document->frame()->selection()->selection(), m_document->frame()->editor()->deleteButtonController()->containerElement()));
setEndingSelection(m_startingSelection);
}
示例8: m_document
EditCommand::EditCommand(Document& document)
: m_document(&document)
, m_parent(nullptr)
{
ASSERT(m_document);
ASSERT(m_document->frame());
setStartingSelection(m_document->frame()->selection().selection());
setEndingSelection(m_startingSelection);
}
示例9: setEndingSelection
void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition)
{
// We could have inserted a part of composed character sequence,
// so we are basically treating ending selection as a range to avoid validation.
// <http://bugs.webkit.org/show_bug.cgi?id=15781>
VisibleSelection forcedEndingSelection;
forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
setEndingSelection(forcedEndingSelection);
}
示例10: ASSERT
void MoveSelectionCommand::doApply()
{
ASSERT(endingSelection().isNonOrphanedRange());
Position pos = m_position;
if (pos.isNull())
return;
// Update the position otherwise it may become invalid after the selection is deleted.
Position selectionEnd = endingSelection().end();
if (pos.anchorType() == Position::PositionIsOffsetInAnchor && selectionEnd.anchorType() == Position::PositionIsOffsetInAnchor
&& selectionEnd.containerNode() == pos.containerNode() && selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) {
pos.moveToOffset(pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode());
Position selectionStart = endingSelection().start();
if (selectionStart.anchorType() == Position::PositionIsOffsetInAnchor && selectionStart.containerNode() == pos.containerNode())
pos.moveToOffset(pos.offsetInContainerNode() + selectionStart.offsetInContainerNode());
}
{
auto deleteSelection = DeleteSelectionCommand::create(document(), m_smartDelete, true, false, true, true, EditActionDeleteByDrag);
deleteSelection->setParent(this);
deleteSelection->apply();
m_commands.append(WTFMove(deleteSelection));
}
// If the node for the destination has been removed as a result of the deletion,
// 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())
pos = endingSelection().start();
cleanupAfterDeletion(pos);
setEndingSelection(VisibleSelection(pos, endingSelection().affinity(), endingSelection().isDirectional()));
setStartingSelection(endingSelection());
if (!pos.anchorNode()->inDocument()) {
// Document was modified out from under us.
return;
}
ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
if (m_smartInsert)
options |= ReplaceSelectionCommand::SmartReplace;
{
auto replaceSelection = ReplaceSelectionCommand::create(document(), WTFMove(m_fragment), options, EditActionInsertFromDrop);
replaceSelection->setParent(this);
replaceSelection->apply();
m_commands.append(WTFMove(replaceSelection));
}
}
示例11: applyStyledElement
void CreateLinkCommand::doApply()
{
if (endingSelection().isNone())
return;
RefPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document());
anchorElement->setHref(m_url);
if (endingSelection().isRange())
applyStyledElement(anchorElement.get());
else {
insertNodeAt(anchorElement.get(), endingSelection().start());
RefPtr<Text> textNode = Text::create(document(), m_url);
appendNode(textNode.get(), anchorElement.get());
setEndingSelection(VisibleSelection(positionInParentBeforeNode(anchorElement.get()), positionInParentAfterNode(anchorElement.get()), DOWNSTREAM));
}
}
示例12: applyStyledElement
void CreateLinkCommand::doApply()
{
if (endingSelection().isNone())
return;
RefPtrWillBeRawPtr<HTMLAnchorElement> anchorElement = HTMLAnchorElement::create(document());
anchorElement->setHref(AtomicString(m_url));
if (endingSelection().isRange()) {
applyStyledElement(anchorElement.get());
} else {
insertNodeAt(anchorElement.get(), endingSelection().start());
RefPtrWillBeRawPtr<Text> textNode = Text::create(document(), m_url);
appendNode(textNode.get(), anchorElement.get());
setEndingSelection(VisibleSelection(positionInParentBeforeNode(*anchorElement), positionInParentAfterNode(*anchorElement), TextAffinity::Downstream, endingSelection().isDirectional()));
}
}
示例13: HTMLAnchorElement
void CreateLinkCommand::doApply()
{
if (endingSelection().isNone())
return;
RefPtr<HTMLAnchorElement> anchorElement = new HTMLAnchorElement(document());
anchorElement->setHref(m_url);
if (endingSelection().isRange()) {
pushPartiallySelectedAnchorElementsDown();
applyStyledElement(anchorElement.get());
} else {
insertNodeAt(anchorElement.get(), endingSelection().start());
RefPtr<Text> textNode = new Text(document(), m_url);
appendNode(textNode.get(), anchorElement.get());
setEndingSelection(Selection(positionBeforeNode(anchorElement.get()), positionAfterNode(anchorElement.get()), DOWNSTREAM));
}
}
示例14: endingSelection
// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
// from text removal.
bool InsertTextCommand::performTrivialReplace(const String& text, bool selectInsertedText)
{
if (!endingSelection().isRange())
return false;
if (text.contains('\t') || text.contains(' ') || text.contains('\n'))
return false;
Position start = endingSelection().start();
Position endPosition = replaceSelectedTextInNode(text);
if (endPosition.isNull())
return false;
setEndingSelectionWithoutValidation(start, endPosition);
if (!selectInsertedText)
setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
return true;
}
示例15: ASSERT
void MoveSelectionCommand::doApply()
{
ASSERT(endingSelection().isNonOrphanedRange());
Position pos = m_position;
if (pos.isNull())
return;
// Update the position otherwise it may become invalid after the selection is deleted.
Position selectionEnd = endingSelection().end();
if (pos.isOffsetInAnchor() && selectionEnd.isOffsetInAnchor()
&& selectionEnd.computeContainerNode() == pos.computeContainerNode() && selectionEnd.offsetInContainerNode() < pos.offsetInContainerNode()) {
pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode() - selectionEnd.offsetInContainerNode());
Position selectionStart = endingSelection().start();
if (selectionStart.isOffsetInAnchor() && selectionStart.computeContainerNode() == pos.computeContainerNode())
pos = Position(pos.computeContainerNode(), pos.offsetInContainerNode() + selectionStart.offsetInContainerNode());
}
deleteSelection(m_smartDelete);
// If the node for the destination has been removed as a result of the deletion,
// 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.inDocument())
pos = endingSelection().start();
cleanupAfterDeletion(VisiblePosition(pos));
setEndingSelection(VisibleSelection(pos, endingSelection().affinity(), endingSelection().isDirectional()));
if (!pos.inDocument()) {
// Document was modified out from under us.
return;
}
ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
if (m_smartInsert)
options |= ReplaceSelectionCommand::SmartReplace;
applyCommandToComposite(ReplaceSelectionCommand::create(document(), m_fragment, options));
}