本文整理汇总了C++中VisiblePosition::previous方法的典型用法代码示例。如果您正苦于以下问题:C++ VisiblePosition::previous方法的具体用法?C++ VisiblePosition::previous怎么用?C++ VisiblePosition::previous使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisiblePosition
的用法示例。
在下文中一共展示了VisiblePosition::previous方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: leftLineVisiblePositionRange
VisiblePositionRange AccessibilityObject::leftLineVisiblePositionRange(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull())
return VisiblePositionRange();
// make a caret selection for the position before marker position (to make sure
// we move off of a line start)
VisiblePosition prevVisiblePos = visiblePos.previous();
if (prevVisiblePos.isNull())
return VisiblePositionRange();
VisiblePosition startPosition = startOfLine(prevVisiblePos);
// keep searching for a valid line start position. Unless the VisiblePosition is at the very beginning, there should
// always be a valid line range. However, startOfLine will return null for position next to a floating object,
// since floating object doesn't really belong to any line.
// This check will reposition the marker before the floating object, to ensure we get a line start.
if (startPosition.isNull()) {
while (startPosition.isNull() && prevVisiblePos.isNotNull()) {
prevVisiblePos = prevVisiblePos.previous();
startPosition = startOfLine(prevVisiblePos);
}
} else
startPosition = updateAXLineStartForVisiblePosition(startPosition);
VisiblePosition endPosition = endOfLine(prevVisiblePos);
return VisiblePositionRange(startPosition, endPosition);
}
示例2: doApply
void IndentOutdentCommand::doApply()
{
if (endingSelection().isNone())
return;
if (!endingSelection().rootEditableElement())
return;
VisiblePosition visibleEnd = endingSelection().visibleEnd();
VisiblePosition visibleStart = endingSelection().visibleStart();
// When a selection ends at the start of a paragraph, we rarely paint
// the selection gap before that paragraph, because there often is no gap.
// In a case like this, it's not obvious to the user that the selection
// ends "inside" that paragraph, so it would be confusing if Indent/Outdent
// operated on that paragraph.
// FIXME: We paint the gap before some paragraphs that are indented with left
// margin/padding, but not others. We should make the gap painting more consistent and
// then use a left margin/padding rule here.
if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd))
setEndingSelection(Selection(visibleStart, visibleEnd.previous(true)));
if (m_typeOfAction == Indent)
indentRegion();
else
outdentRegion();
}
示例3: visiblePositionForPoint
RefPtr<Range> Frame::rangeForPoint(const IntPoint& framePoint)
{
VisiblePosition position = visiblePositionForPoint(framePoint);
if (position.isNull())
return nullptr;
Position deepPosition = position.deepEquivalent();
Text* containerText = deepPosition.containerText();
if (!containerText || !containerText->renderer() || containerText->renderer()->style().userSelect() == SELECT_NONE)
return nullptr;
VisiblePosition previous = position.previous();
if (previous.isNotNull()) {
RefPtr<Range> previousCharacterRange = makeRange(previous, position);
LayoutRect rect = editor().firstRectForRange(previousCharacterRange.get());
if (rect.contains(framePoint))
return previousCharacterRange;
}
VisiblePosition next = position.next();
if (RefPtr<Range> nextCharacterRange = makeRange(position, next)) {
LayoutRect rect = editor().firstRectForRange(nextCharacterRange.get());
if (rect.contains(framePoint))
return nextCharacterRange;
}
return nullptr;
}
示例4: updateAXLineStartForVisiblePosition
static VisiblePosition updateAXLineStartForVisiblePosition(const VisiblePosition& visiblePosition)
{
// A line in the accessibility sense should include floating objects, such as aligned image, as part of a line.
// So let's update the position to include that.
VisiblePosition tempPosition;
VisiblePosition startPosition = visiblePosition;
Position p;
RenderObject* renderer;
while (true) {
tempPosition = startPosition.previous();
if (tempPosition.isNull())
break;
p = tempPosition.deepEquivalent();
if (!p.node())
break;
renderer = p.node()->renderer();
if (!renderer || renderer->isRenderBlock() && !p.offset())
break;
InlineBox* box;
int ignoredCaretOffset;
p.getInlineBoxAndOffset(tempPosition.affinity(), box, ignoredCaretOffset);
if (box)
break;
startPosition = tempPosition;
}
return startPosition;
}
示例5: unlistifyParagraph
void InsertListCommand::unlistifyParagraph(const VisiblePosition& originalStart, HTMLElement* listNode, Node* listChildNode)
{
Node* nextListChild;
Node* previousListChild;
VisiblePosition start;
VisiblePosition end;
if (listChildNode->hasTagName(liTag)) {
start = firstDeepEditingPositionForNode(listChildNode);
end = lastDeepEditingPositionForNode(listChildNode);
nextListChild = listChildNode->nextSibling();
previousListChild = listChildNode->previousSibling();
} else {
// A paragraph is visually a list item minus a list marker. The paragraph will be moved.
start = startOfParagraph(originalStart);
end = endOfParagraph(start);
nextListChild = enclosingListChild(end.next().deepEquivalent().node());
ASSERT(nextListChild != listChildNode);
if (enclosingList(nextListChild) != listNode)
nextListChild = 0;
previousListChild = enclosingListChild(start.previous().deepEquivalent().node());
ASSERT(previousListChild != listChildNode);
if (enclosingList(previousListChild) != listNode)
previousListChild = 0;
}
// When removing a list, we must always create a placeholder to act as a point of insertion
// for the list content being removed.
RefPtr<Element> placeholder = createBreakElement(document());
RefPtr<Element> nodeToInsert = placeholder;
// If the content of the list item will be moved into another list, put it in a list item
// so that we don't create an orphaned list child.
if (enclosingList(listNode)) {
nodeToInsert = createListItemElement(document());
appendNode(placeholder, nodeToInsert);
}
if (nextListChild && previousListChild) {
// We want to pull listChildNode out of listNode, and place it before nextListChild
// and after previousListChild, so we split listNode and insert it between the two lists.
// But to split listNode, we must first split ancestors of listChildNode between it and listNode,
// if any exist.
// FIXME: We appear to split at nextListChild as opposed to listChildNode so that when we remove
// listChildNode below in moveParagraphs, previousListChild will be removed along with it if it is
// unrendered. But we ought to remove nextListChild too, if it is unrendered.
splitElement(listNode, splitTreeToNode(nextListChild, listNode));
insertNodeBefore(nodeToInsert, listNode);
} else if (nextListChild || listChildNode->parentNode() != listNode) {
// Just because listChildNode has no previousListChild doesn't mean there isn't any content
// in listNode that comes before listChildNode, as listChildNode could have ancestors
// between it and listNode. So, we split up to listNode before inserting the placeholder
// where we're about to move listChildNode to.
if (listChildNode->parentNode() != listNode)
splitElement(listNode, splitTreeToNode(listChildNode, listNode).get());
insertNodeBefore(nodeToInsert, listNode);
} else
insertNodeAfter(nodeToInsert, listNode);
VisiblePosition insertionPoint = VisiblePosition(Position(placeholder.get(), 0));
moveParagraphs(start, end, insertionPoint, true);
}
示例6: isFirstVisiblePositionInNode
bool isFirstVisiblePositionInNode(const VisiblePosition &pos, const NodeImpl *node)
{
if (pos.isNull())
return false;
VisiblePosition previous = pos.previous();
return previous.isNull() || !previous.deepEquivalent().node()->isAncestor(node);
}
示例7: formatSelection
void BlockCommand::formatSelection(const VisiblePosition& startOfSelection, const VisiblePosition& endOfSelection)
{
// might be null if the recursion below goes awry
if (startOfSelection.isNull() || endOfSelection.isNull())
return;
Node* startEnclosingCell = enclosingNodeOfType(startOfSelection.deepEquivalent(), &isTableCell);
Node* endEnclosingCell = enclosingNodeOfType(endOfSelection.deepEquivalent(), &isTableCell);
if (startEnclosingCell != endEnclosingCell) {
if (startEnclosingCell && (!endEnclosingCell || !endEnclosingCell->isDescendantOf(startEnclosingCell))) {
VisiblePosition newEnd = lastPositionInNode(startEnclosingCell);
VisiblePosition nextStart = newEnd.next();
while (isTableElement(nextStart.deepEquivalent().anchorNode()))
nextStart = nextStart.next();
// TODO: fix recursion!
formatSelection(startOfSelection, newEnd);
formatSelection(nextStart, endOfSelection);
return;
}
ASSERT(endEnclosingCell);
VisiblePosition nextStart = firstPositionInNode(endEnclosingCell);
VisiblePosition newEnd = nextStart.previous();
while (isTableElement(newEnd.deepEquivalent().anchorNode()))
newEnd = newEnd.previous();
// TODO: fix recursion!
formatSelection(startOfSelection, newEnd);
formatSelection(nextStart, endOfSelection);
return;
}
Node* root = enclosingNodeOfType(startOfSelection.deepEquivalent(), &isTableCellOrRootEditable);
if (!root || root == startOfSelection.deepEquivalent().anchorNode())
return;
RefPtr<Node> currentNode = blockExtentStart(startOfSelection.deepEquivalent().anchorNode(), root);
RefPtr<Node> endNode = blockExtentEnd(endOfSelection.deepEquivalent().anchorNode(), root);
while (currentNode->isDescendantOf(endNode.get()))
endNode = endNode->lastChild();
formatBlockExtent(currentNode, endNode, root);
}
示例8: isFirstVisiblePositionOnLine
bool isFirstVisiblePositionOnLine(const VisiblePosition &pos)
{
if (pos.isNull())
return false;
VisiblePosition previous = pos.previous();
return previous.isNull() || visiblePositionsOnDifferentLines(pos, previous);
}
示例9: positionAvoidingFirstPositionInTable
static VisiblePosition positionAvoidingFirstPositionInTable(const VisiblePosition& c)
{
// return table offset 0 instead of the first VisiblePosition inside the table
VisiblePosition previous = c.previous();
if (isLastPositionBeforeTable(previous))
return previous;
return c;
}
示例10: doApply
void FormatBlockCommand::doApply()
{
if (endingSelection().isNone())
return;
if (!endingSelection().rootEditableElement())
return;
VisiblePosition visibleEnd = endingSelection().visibleEnd();
VisiblePosition visibleStart = endingSelection().visibleStart();
// When a selection ends at the start of a paragraph, we rarely paint
// the selection gap before that paragraph, because there often is no gap.
// In a case like this, it's not obvious to the user that the selection
// ends "inside" that paragraph, so it would be confusing if FormatBlock
// operated on that paragraph.
// FIXME: We paint the gap before some paragraphs that are indented with left
// margin/padding, but not others. We should make the gap painting more consistent and
// then use a left margin/padding rule here.
if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd))
setEndingSelection(Selection(visibleStart, visibleEnd.previous(true)));
if (endingSelection().isRange() && modifyRange())
return;
String localName, prefix;
if (!Document::parseQualifiedName(m_tagName, prefix, localName))
return;
QualifiedName qTypeOfBlock = QualifiedName(AtomicString(prefix), AtomicString(localName), xhtmlNamespaceURI);
Node* refNode = enclosingBlockFlowElement(endingSelection().visibleStart());
if (refNode->hasTagName(qTypeOfBlock))
// We're already in a block with the format we want, so we don't have to do anything
return;
VisiblePosition paragraphStart = startOfParagraph(endingSelection().visibleStart());
VisiblePosition paragraphEnd = endOfParagraph(endingSelection().visibleStart());
VisiblePosition blockStart = startOfBlock(endingSelection().visibleStart());
VisiblePosition blockEnd = endOfBlock(endingSelection().visibleStart());
RefPtr<Node> blockNode = createElement(document(), m_tagName);
RefPtr<Node> placeholder = createBreakElement(document());
Node* root = endingSelection().start().node()->rootEditableElement();
if (refNode == root || root->isDescendantOf(refNode))
refNode = paragraphStart.deepEquivalent().node();
Position upstreamStart = paragraphStart.deepEquivalent().upstream();
if ((validBlockTag(refNode->nodeName().lower()) && paragraphStart == blockStart && paragraphEnd == blockEnd) ||
!upstreamStart.node()->isDescendantOf(root))
// Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag
insertNodeBefore(blockNode.get(), refNode);
else {
insertNodeAt(blockNode.get(), upstreamStart.node(), upstreamStart.offset());
}
appendNode(placeholder.get(), blockNode.get());
moveParagraph(paragraphStart, paragraphEnd, VisiblePosition(Position(placeholder.get(), 0)), true, false);
}
示例11: isFirstVisiblePositionInNode
bool isFirstVisiblePositionInNode(const VisiblePosition &visiblePosition, const Node *node)
{
if (visiblePosition.isNull())
return false;
if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
return false;
VisiblePosition previous = visiblePosition.previous();
return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isDescendantOf(node);
}
示例12: isFirstVisiblePositionInNode
bool isFirstVisiblePositionInNode(const VisiblePosition &visiblePosition, const Node *node)
{
if (visiblePosition.isNull())
return false;
if (!visiblePosition.deepEquivalent().node()->isAncestor(node))
return false;
VisiblePosition previous = visiblePosition.previous();
return previous.isNull() || !previous.deepEquivalent().node()->isAncestor(node);
}
示例13: previousWordStart
VisiblePosition AccessibilityObject::previousWordStart(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull())
return VisiblePosition();
// make sure we move off of a word start
VisiblePosition prevVisiblePos = visiblePos.previous();
if (prevVisiblePos.isNull())
return VisiblePosition();
return startOfWord(prevVisiblePos, RightWordIfOnBoundary);
}
示例14: previousParagraphStartPosition
VisiblePosition AccessibilityObject::previousParagraphStartPosition(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull())
return VisiblePosition();
// make sure we move off of a paragraph start
VisiblePosition previousPos = visiblePos.previous();
if (previousPos.isNull())
return VisiblePosition();
return startOfParagraph(previousPos);
}
示例15: makeRange
PassRefPtr<Range> trimWhitespaceFromRange(VisiblePosition startPosition, VisiblePosition endPosition)
{
if (startPosition == endPosition || isRangeTextAllWhitespace(startPosition, endPosition))
return 0;
while (isWhitespace(startPosition.characterAfter()))
startPosition = startPosition.next();
while (isWhitespace(endPosition.characterBefore()))
endPosition = endPosition.previous();
return makeRange(startPosition, endPosition);
}