本文整理汇总了C++中VisibleSelection::start方法的典型用法代码示例。如果您正苦于以下问题:C++ VisibleSelection::start方法的具体用法?C++ VisibleSelection::start怎么用?C++ VisibleSelection::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisibleSelection
的用法示例。
在下文中一共展示了VisibleSelection::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expandSelectionToGranularity
static void expandSelectionToGranularity(Frame* frame, int x, int y, TextGranularity granularity, bool isInputMode)
{
ASSERT(frame);
ASSERT(frame->selection());
VisibleSelection selection;
if (x < 0 || y < 0) {
if (!isInputMode)
return; // Invalid request
// Input mode based selection, use the current selection as the selection point.
ASSERT(frame->selection()->selectionType() != VisibleSelection::NoSelection);
selection = frame->selection()->selection();
} else {
VisiblePosition pointLocation(frame->visiblePositionForPoint(WebCore::IntPoint(x, y)));
selection = VisibleSelection(pointLocation, pointLocation);
}
if (!(selection.start().anchorNode() && selection.start().anchorNode()->isTextNode()))
return;
selection.expandUsingGranularity(granularity);
RefPtr<Range> newRange = selection.toNormalizedRange();
if (!newRange)
return;
ExceptionCode ec = 0;
if (newRange->collapsed(ec))
return;
RefPtr<Range> oldRange = frame->selection()->selection().toNormalizedRange();
EAffinity affinity = frame->selection()->affinity();
if (isInputMode && !frame->editor()->client()->shouldChangeSelectedRange(oldRange.get(), newRange.get(), affinity, false))
return;
frame->selection()->setSelectedRange(newRange.get(), affinity, true);
}
示例2: surroundingText
TEST_F(SurroundingTextTest, TreeCaretSelection)
{
setHTML(String("<div>This is outside of <p id='selection'>foo bar</p> the selected node</div>"));
{
VisibleSelection selection = select(0);
SurroundingText surroundingText(selection.start(), 1);
EXPECT_EQ("f", surroundingText.content());
EXPECT_EQ(0u, surroundingText.startOffsetInContent());
EXPECT_EQ(0u, surroundingText.endOffsetInContent());
}
{
VisibleSelection selection = select(0);
SurroundingText surroundingText(selection.start(), 5);
EXPECT_EQ("foo", surroundingText.content().simplifyWhiteSpace());
EXPECT_EQ(1u, surroundingText.startOffsetInContent());
EXPECT_EQ(1u, surroundingText.endOffsetInContent());
}
{
VisibleSelection selection = select(0);
SurroundingText surroundingText(selection.start(), 1337);
EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
EXPECT_EQ(20u, surroundingText.startOffsetInContent());
EXPECT_EQ(20u, surroundingText.endOffsetInContent());
}
{
VisibleSelection selection = select(6);
SurroundingText surroundingText(selection.start(), 2);
EXPECT_EQ("ar", surroundingText.content());
EXPECT_EQ(1u, surroundingText.startOffsetInContent());
EXPECT_EQ(1u, surroundingText.endOffsetInContent());
}
{
VisibleSelection selection = select(6);
SurroundingText surroundingText(selection.start(), 1337);
EXPECT_EQ("This is outside of foo bar the selected node", surroundingText.content().simplifyWhiteSpace());
EXPECT_EQ(26u, surroundingText.startOffsetInContent());
EXPECT_EQ(26u, surroundingText.endOffsetInContent());
}
}
示例3: webkitAccessibleTextGetWordForBoundary
static char* webkitAccessibleTextGetWordForBoundary(AtkText* text, int offset, AtkTextBoundary boundaryType, GetTextRelativePosition textPosition, int* startOffset, int* endOffset)
{
AccessibilityObject* coreObject = core(text);
Document* document = coreObject->document();
if (!document)
return emptyTextSelectionAtOffset(0, startOffset, endOffset);
Node* node = getNodeForAccessibilityObject(coreObject);
if (!node)
return emptyTextSelectionAtOffset(0, startOffset, endOffset);
int actualOffset = atkOffsetToWebCoreOffset(text, offset);
// Besides of the usual conversion from ATK offsets to WebCore offsets,
// we need to consider the potential embedded objects that might have been
// inserted in the text exposed through AtkText when calculating the offset.
actualOffset -= numberOfReplacedElementsBeforeOffset(text, actualOffset);
VisiblePosition caretPosition = coreObject->visiblePositionForIndex(actualOffset);
VisibleSelection currentWord = wordAtPositionForAtkBoundary(coreObject, caretPosition, boundaryType);
// Take into account other relative positions, if needed, by
// calculating the new position that we would need to consider.
VisiblePosition newPosition = caretPosition;
switch (textPosition) {
case GetTextPositionAt:
break;
case GetTextPositionBefore:
// Early return if asking for the previous word while already at the beginning.
if (isFirstVisiblePositionInNode(currentWord.visibleStart(), node))
return emptyTextSelectionAtOffset(0, startOffset, endOffset);
if (isStartOfLine(currentWord.end()))
newPosition = currentWord.visibleStart().previous();
else
newPosition = startOfWord(currentWord.start(), LeftWordIfOnBoundary);
break;
case GetTextPositionAfter:
// Early return if asking for the following word while already at the end.
if (isLastVisiblePositionInNode(currentWord.visibleEnd(), node))
return emptyTextSelectionAtOffset(accessibilityObjectLength(coreObject), startOffset, endOffset);
if (isEndOfLine(currentWord.end()))
newPosition = currentWord.visibleEnd().next();
else
newPosition = endOfWord(currentWord.end(), RightWordIfOnBoundary);
break;
default:
ASSERT_NOT_REACHED();
}
// Determine the relevant word we are actually interested in
// and calculate the ATK offsets for it, then return everything.
VisibleSelection selectedWord = newPosition != caretPosition ? wordAtPositionForAtkBoundary(coreObject, newPosition, boundaryType) : currentWord;
getSelectionOffsetsForObject(coreObject, selectedWord, *startOffset, *endOffset);
return webkitAccessibleTextGetText(text, *startOffset, *endOffset);
}
示例4: adjustSelectionInFlatTree
// Updates |selectionInFlatTree| to match with |selection|.
void SelectionAdjuster::adjustSelectionInFlatTree(
VisibleSelectionInFlatTree* selectionInFlatTree,
const VisibleSelection& selection) {
if (selection.isNone()) {
*selectionInFlatTree = VisibleSelectionInFlatTree();
return;
}
const PositionInFlatTree& base = toPositionInFlatTree(selection.base());
const PositionInFlatTree& extent = toPositionInFlatTree(selection.extent());
const PositionInFlatTree& position1 = toPositionInFlatTree(selection.start());
const PositionInFlatTree& position2 = toPositionInFlatTree(selection.end());
position1.anchorNode()->updateDistribution();
position2.anchorNode()->updateDistribution();
selectionInFlatTree->m_base = base;
selectionInFlatTree->m_extent = extent;
selectionInFlatTree->m_affinity = selection.m_affinity;
selectionInFlatTree->m_isDirectional = selection.m_isDirectional;
selectionInFlatTree->m_granularity = selection.m_granularity;
selectionInFlatTree->m_hasTrailingWhitespace =
selection.m_hasTrailingWhitespace;
selectionInFlatTree->m_baseIsFirst =
base.isNull() || base.compareTo(extent) <= 0;
if (position1.compareTo(position2) <= 0) {
selectionInFlatTree->m_start = position1;
selectionInFlatTree->m_end = position2;
} else {
selectionInFlatTree->m_start = position2;
selectionInFlatTree->m_end = position1;
}
selectionInFlatTree->updateSelectionType();
}
示例5: insertTextWithoutSendingTextEvent
bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectInsertedText, TextEvent* triggeringEvent)
{
if (text.isEmpty())
return false;
VisibleSelection selection = selectionForCommand(triggeringEvent);
if (!selection.isContentEditable())
return false;
spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
// Get the selection to use for the event that triggered this insertText.
// If the event handler changed the selection, we may want to use a different selection
// that is contained in the event target.
selection = selectionForCommand(triggeringEvent);
if (selection.isContentEditable()) {
if (Node* selectionStart = selection.start().deprecatedNode()) {
RefPtr<Document> document(selectionStart->document());
// Insert the text
TypingCommand::Options options = 0;
if (selectInsertedText)
options |= TypingCommand::SelectInsertedText;
TypingCommand::insertText(*document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompositionConfirm : TypingCommand::TextCompositionNone);
// Reveal the current selection
if (LocalFrame* editedFrame = document->frame()) {
if (Page* page = editedFrame->page())
page->focusController().focusedOrMainFrame()->selection().revealSelection(ScrollAlignment::alignCenterIfNeeded);
}
}
}
return true;
}
示例6: selectionIsContainedByAnchorNode
bool static selectionIsContainedByAnchorNode(const VisibleSelection& selection)
{
// Check whether the start or end of the selection is outside of the selections
// anchor node.
return (selection.start().anchorType() == WebCore::Position::PositionIsOffsetInAnchor
&& selection.end().anchorType() == WebCore::Position::PositionIsOffsetInAnchor);
}
示例7: postTextStateChangeNotificationForDeletion
void TypingCommand::postTextStateChangeNotificationForDeletion(const VisibleSelection& selection)
{
if (!AXObjectCache::accessibilityEnabled())
return;
postTextStateChangeNotification(AXTextEditTypeDelete, AccessibilityObject::stringForVisiblePositionRange(selection), selection.start());
VisiblePositionIndexRange range;
range.startIndex.value = indexForVisiblePosition(selection.start(), range.startIndex.scope);
range.endIndex.value = indexForVisiblePosition(selection.end(), range.endIndex.scope);
composition()->setTextInsertedByUnapplyRange(range);
}
示例8: insertText
// FIXME: We shouldn't need to take selectionForInsertion. It should be identical to SelectionController's current selection.
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, bool selectInsertedText, TextCompositionType compositionType)
{
#if REMOVE_MARKERS_UPON_EDITING
if (!text.isEmpty())
document->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToBeEdited(isSpaceOrNewline(text.characters()[0]));
#endif
ASSERT(document);
RefPtr<Frame> frame = document->frame();
ASSERT(frame);
VisibleSelection currentSelection = frame->selection()->selection();
bool changeSelection = currentSelection != selectionForInsertion;
String newText = text;
Node* startNode = selectionForInsertion.start().node();
if (startNode && startNode->rootEditableElement() && compositionType != TextCompositionUpdate) {
// Send BeforeTextInsertedEvent. The event handler will update text if necessary.
ExceptionCode ec = 0;
RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
startNode->rootEditableElement()->dispatchEvent(evt, ec);
newText = evt->text();
}
if (newText.isEmpty())
return;
// Set the starting and ending selection appropriately if we are using a selection
// that is different from the current selection. In the future, we should change EditCommand
// to deal with custom selections in a general way that can be used by all of the commands.
RefPtr<EditCommand> lastEditCommand = frame->editor()->lastEditCommand();
if (isOpenForMoreTypingCommand(lastEditCommand.get())) {
TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand.get());
if (lastTypingCommand->endingSelection() != selectionForInsertion) {
lastTypingCommand->setStartingSelection(selectionForInsertion);
lastTypingCommand->setEndingSelection(selectionForInsertion);
}
lastTypingCommand->setCompositionType(compositionType);
lastTypingCommand->insertText(newText, selectInsertedText);
return;
}
RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, selectInsertedText, compositionType);
if (changeSelection) {
cmd->setStartingSelection(selectionForInsertion);
cmd->setEndingSelection(selectionForInsertion);
}
applyCommand(cmd);
if (changeSelection) {
cmd->setEndingSelection(currentSelection);
frame->selection()->setSelection(currentSelection);
}
}
示例9: visibleSelectionForClosestActualWordStart
VisibleSelection visibleSelectionForClosestActualWordStart(const VisibleSelection& selection)
{
// VisibleSelection validation has a special case when the caret is at the end of a paragraph where
// it selects the paragraph marker. As well, if the position is at the end of a word, it will select
// only the space between words. We want to select an actual word so we move the selection to
// the start of the leftmost word if the character after the selection point is whitespace.
if (selection.selectionType() != VisibleSelection::RangeSelection) {
int leftDistance = 0;
int rightDistance = 0;
VisibleSelection leftSelection(previousWordPosition(selection.start()));
bool leftSelectionIsOnWord = !isWhitespace(leftSelection.visibleStart().characterAfter()) && leftSelection.start().containerNode() == selection.start().containerNode();
if (leftSelectionIsOnWord) {
VisibleSelection rangeSelection(endOfWord(leftSelection.start()), selection.visibleStart());
leftDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
}
VisibleSelection rightSelection = previousWordPosition(nextWordPosition(selection.start()));
bool rightSelectionIsOnWord = !isWhitespace(rightSelection.visibleStart().characterAfter()) && rightSelection.start().containerNode() == selection.start().containerNode();
if (rightSelectionIsOnWord) {
VisibleSelection rangeSelection = VisibleSelection(rightSelection.visibleStart(), selection.visibleStart());
rightDistance = TextIterator::rangeLength(rangeSelection.toNormalizedRange().get());
}
// Make sure we found an actual word. If not, return the original selection.
if (!leftSelectionIsOnWord && !rightSelectionIsOnWord)
return selection;
if (!rightSelectionIsOnWord || (leftSelectionIsOnWord && leftDistance <= rightDistance)) {
// Left is closer or right is invalid.
return leftSelection;
}
// Right is closer or equal, or left was invalid.
return rightSelection;
}
// No adjustment required.
return selection;
}
示例10: writeSelection
static void writeSelection(TextStream& ts, const RenderObject* o)
{
Node* n = o->node();
if (!n || !n->isDocumentNode())
return;
Document* doc = static_cast<Document*>(n);
Frame* frame = doc->frame();
if (!frame)
return;
VisibleSelection selection = frame->selection()->selection();
if (selection.isCaret()) {
ts << "caret: position " << selection.start().deprecatedEditingOffset() << " of " << nodePosition(selection.start().node());
if (selection.affinity() == UPSTREAM)
ts << " (upstream affinity)";
ts << "\n";
} else if (selection.isRange())
ts << "selection start: position " << selection.start().deprecatedEditingOffset() << " of " << nodePosition(selection.start().node()) << "\n"
<< "selection end: position " << selection.end().deprecatedEditingOffset() << " of " << nodePosition(selection.end().node()) << "\n";
}
示例11: visibleTextQuads
void visibleTextQuads(const VisibleSelection& selection, Vector<FloatQuad>& quads)
{
if (!selection.isRange())
return;
// Make sure that both start and end have valid nodes associated otherwise
// this can crash. See PR 220628.
if (!selection.start().anchorNode() || !selection.end().anchorNode())
return;
visibleTextQuads(*(selection.firstRange()), quads, true /* useSelectionHeight */);
}
示例12: insertText
// FIXME: We shouldn't need to take selectionForInsertion. It should be identical to SelectionController's current selection.
void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
{
ASSERT(document);
RefPtr<Frame> frame = document->frame();
ASSERT(frame);
VisibleSelection currentSelection = frame->selection()->selection();
bool changeSelection = currentSelection != selectionForInsertion;
String newText = text;
Node* startNode = selectionForInsertion.start().deprecatedNode();
if (startNode && startNode->rootEditableElement() && compositionType != TextCompositionUpdate) {
// Send BeforeTextInsertedEvent. The event handler will update text if necessary.
ExceptionCode ec = 0;
RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
startNode->rootEditableElement()->dispatchEvent(evt, ec);
newText = evt->text();
}
if (newText.isEmpty())
return;
// Set the starting and ending selection appropriately if we are using a selection
// that is different from the current selection. In the future, we should change EditCommand
// to deal with custom selections in a general way that can be used by all of the commands.
RefPtr<EditCommand> lastEditCommand = frame->editor()->lastEditCommand();
if (isOpenForMoreTypingCommand(lastEditCommand.get())) {
TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand.get());
if (lastTypingCommand->endingSelection() != selectionForInsertion) {
lastTypingCommand->setStartingSelection(selectionForInsertion);
lastTypingCommand->setEndingSelection(selectionForInsertion);
}
lastTypingCommand->setCompositionType(compositionType);
lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
lastTypingCommand->insertText(newText, options & SelectInsertedText);
return;
}
RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newText, options, compositionType);
if (changeSelection) {
cmd->setStartingSelection(selectionForInsertion);
cmd->setEndingSelection(selectionForInsertion);
}
applyCommand(cmd);
if (changeSelection) {
cmd->setEndingSelection(currentSelection);
frame->selection()->setSelection(currentSelection);
}
}
示例13: respondToChangedSelection
void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions options)
{
bool closeTyping = options & FrameSelection::CloseTyping;
bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabled();
bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled && isGrammarCheckingEnabled();
if (isContinuousSpellCheckingEnabled) {
VisibleSelection newAdjacentWords;
VisibleSelection newSelectedSentence;
const VisibleSelection newSelection = m_frame.selection().selection();
VisiblePosition newStart(newSelection.visibleStart());
newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary));
if (isContinuousGrammarCheckingEnabled)
newSelectedSentence = VisibleSelection(startOfSentence(newStart), endOfSentence(newStart));
// Don't check spelling and grammar if the change of selection is triggered by spelling correction itself.
bool shouldCheckSpellingAndGrammar = !(options & FrameSelection::SpellCorrectionTriggered);
// 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.
// FIXME(http://crbug.com/382809): if oldSelection is on a textarea
// element, we cause synchronous layout.
if (shouldCheckSpellingAndGrammar
&& closeTyping
&& !isSelectionInTextField(oldSelection)
&& (isSelectionInTextArea(oldSelection) || oldSelection.isContentEditable())
&& oldSelection.start().inDocument()) {
spellCheckOldSelection(oldSelection, newAdjacentWords);
}
// FIXME(http://crbug.com/382809):
// shouldEraseMarkersAfterChangeSelection is true, we cause synchronous
// layout.
if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTypeSpelling)) {
if (RefPtr<Range> wordRange = newAdjacentWords.toNormalizedRange())
m_frame.document()->markers().removeMarkers(wordRange.get(), DocumentMarker::Spelling);
}
if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTypeGrammar)) {
if (RefPtr<Range> sentenceRange = newSelectedSentence.toNormalizedRange())
m_frame.document()->markers().removeMarkers(sentenceRange.get(), DocumentMarker::Grammar);
}
}
// When continuous spell checking is off, existing markers disappear after the selection changes.
if (!isContinuousSpellCheckingEnabled)
m_frame.document()->markers().removeMarkers(DocumentMarker::Spelling);
if (!isContinuousGrammarCheckingEnabled)
m_frame.document()->markers().removeMarkers(DocumentMarker::Grammar);
}
示例14: dispatchBeforeTextInsertedEvent
String dispatchBeforeTextInsertedEvent(const String& text, const VisibleSelection& selectionForInsertion, bool insertionIsForUpdatingComposition)
{
if (insertionIsForUpdatingComposition)
return text;
String newText = text;
if (Node* startNode = selectionForInsertion.start().containerNode()) {
if (startNode->rootEditableElement()) {
// Send BeforeTextInsertedEvent. The event handler will update text if necessary.
RefPtr<BeforeTextInsertedEvent> evt = BeforeTextInsertedEvent::create(text);
startNode->rootEditableElement()->dispatchEvent(evt, IGNORE_EXCEPTION);
newText = evt->text();
}
}
return newText;
}
示例15: CompositeEditCommand
DeleteSelectionCommand::DeleteSelectionCommand(const VisibleSelection& selection, bool smartDelete, bool mergeBlocksAfterDelete, bool replace, bool expandForSpecialElements)
: CompositeEditCommand(selection.start().anchorNode()->document())
, m_hasSelectionToDelete(true)
, m_smartDelete(smartDelete)
, m_mergeBlocksAfterDelete(mergeBlocksAfterDelete)
, m_needPlaceholder(false)
, m_replace(replace)
, m_expandForSpecialElements(expandForSpecialElements)
, m_pruneStartBlockIfNecessary(false)
, m_startsAtEmptyLine(false)
, m_selectionToDelete(selection)
, m_startBlock(0)
, m_endBlock(0)
, m_typingStyle(0)
, m_deleteIntoBlockquoteStyle(0)
{
}