本文整理汇总了C++中VisiblePosition类的典型用法代码示例。如果您正苦于以下问题:C++ VisiblePosition类的具体用法?C++ VisiblePosition怎么用?C++ VisiblePosition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VisiblePosition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: isStartOfDocument
bool isStartOfDocument(const VisiblePosition &p)
{
return p.isNotNull() && p.previous().isNull();
}
开发者ID:Czerrr,项目名称:ISeeBrowser,代码行数:4,代码来源:visible_units.cpp
示例2: VisiblePositionRange
VisiblePositionRange AccessibilityObject::rightLineVisiblePositionRange(const VisiblePosition& visiblePos) const
{
if (visiblePos.isNull())
return VisiblePositionRange();
// make sure we move off of a line end
VisiblePosition nextVisiblePos = visiblePos.next();
if (nextVisiblePos.isNull())
return VisiblePositionRange();
VisiblePosition startPosition = startOfLine(nextVisiblePos);
// fetch for a valid line start position
if (startPosition.isNull()) {
startPosition = visiblePos;
nextVisiblePos = nextVisiblePos.next();
} else
startPosition = updateAXLineStartForVisiblePosition(startPosition);
VisiblePosition endPosition = endOfLine(nextVisiblePos);
// as long as the position hasn't reached the end of the doc, keep searching for a valid line end position
// Unless the VisiblePosition is at the very end, there should always be a valid line range. However, endOfLine will
// return null for position by a floating object, since floating object doesn't really belong to any line.
// This check will reposition the marker after the floating object, to ensure we get a line end.
while (endPosition.isNull() && nextVisiblePos.isNotNull()) {
nextVisiblePos = nextVisiblePos.next();
endPosition = endOfLine(nextVisiblePos);
}
return VisiblePositionRange(startPosition, endPosition);
}
开发者ID:sysrqb,项目名称:chromium-src,代码行数:32,代码来源:AccessibilityObject.cpp
示例3: endingSelection
void InsertListCommand::doApply()
{
if (!endingSelection().isNonOrphanedCaretOrRange())
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 InsertUn{Ordered}List
// 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.deepEquivalent() != visibleStart.deepEquivalent() && isStartOfParagraph(visibleEnd, CanSkipOverEditingBoundary)) {
setEndingSelection(VisibleSelection(visibleStart, previousPositionOf(visibleEnd, CannotCrossEditingBoundary), endingSelection().isDirectional()));
if (!endingSelection().rootEditableElement())
return;
}
const HTMLQualifiedName& listTag = (m_type == OrderedList) ? olTag : ulTag;
if (endingSelection().isRange()) {
bool forceListCreation = false;
VisibleSelection selection = selectionForParagraphIteration(endingSelection());
ASSERT(selection.isRange());
VisiblePosition startOfSelection = selection.visibleStart();
VisiblePosition endOfSelection = selection.visibleEnd();
VisiblePosition startOfLastParagraph = startOfParagraph(endOfSelection, CanSkipOverEditingBoundary);
RefPtrWillBeRawPtr<Range> currentSelection = firstRangeOf(endingSelection());
RefPtrWillBeRawPtr<ContainerNode> scopeForStartOfSelection = nullptr;
RefPtrWillBeRawPtr<ContainerNode> scopeForEndOfSelection = nullptr;
// FIXME: This is an inefficient way to keep selection alive because
// indexForVisiblePosition walks from the beginning of the document to the
// endOfSelection everytime this code is executed. But not using index is hard
// because there are so many ways we can los eselection inside doApplyForSingleParagraph.
int indexForStartOfSelection = indexForVisiblePosition(startOfSelection, scopeForStartOfSelection);
int indexForEndOfSelection = indexForVisiblePosition(endOfSelection, scopeForEndOfSelection);
if (startOfParagraph(startOfSelection, CanSkipOverEditingBoundary).deepEquivalent() != startOfLastParagraph.deepEquivalent()) {
forceListCreation = !selectionHasListOfType(selection, listTag);
VisiblePosition startOfCurrentParagraph = startOfSelection;
while (inSameTreeAndOrdered(startOfCurrentParagraph, startOfLastParagraph) && !inSameParagraph(startOfCurrentParagraph, startOfLastParagraph, CanCrossEditingBoundary)) {
// doApply() may operate on and remove the last paragraph of the selection from the document
// if it's in the same list item as startOfCurrentParagraph. Return early to avoid an
// infinite loop and because there is no more work to be done.
// FIXME(<rdar://problem/5983974>): The endingSelection() may be incorrect here. Compute
// the new location of endOfSelection and use it as the end of the new selection.
if (!startOfLastParagraph.deepEquivalent().inDocument())
return;
setEndingSelection(startOfCurrentParagraph);
// Save and restore endOfSelection and startOfLastParagraph when necessary
// since moveParagraph and movePragraphWithClones can remove nodes.
if (!doApplyForSingleParagraph(forceListCreation, listTag, *currentSelection))
break;
if (endOfSelection.isNull() || endOfSelection.isOrphan() || startOfLastParagraph.isNull() || startOfLastParagraph.isOrphan()) {
endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scopeForEndOfSelection.get());
// If endOfSelection is null, then some contents have been deleted from the document.
// This should never happen and if it did, exit early immediately because we've lost the loop invariant.
ASSERT(endOfSelection.isNotNull());
if (endOfSelection.isNull() || !rootEditableElementOf(endOfSelection))
return;
startOfLastParagraph = startOfParagraph(endOfSelection, CanSkipOverEditingBoundary);
}
startOfCurrentParagraph = startOfNextParagraph(endingSelection().visibleStart());
}
setEndingSelection(endOfSelection);
}
doApplyForSingleParagraph(forceListCreation, listTag, *currentSelection);
// Fetch the end of the selection, for the reason mentioned above.
if (endOfSelection.isNull() || endOfSelection.isOrphan()) {
endOfSelection = visiblePositionForIndex(indexForEndOfSelection, scopeForEndOfSelection.get());
if (endOfSelection.isNull())
return;
}
if (startOfSelection.isNull() || startOfSelection.isOrphan()) {
startOfSelection = visiblePositionForIndex(indexForStartOfSelection, scopeForStartOfSelection.get());
if (startOfSelection.isNull())
return;
}
setEndingSelection(VisibleSelection(startOfSelection, endOfSelection, endingSelection().isDirectional()));
return;
}
ASSERT(firstRangeOf(endingSelection()));
doApplyForSingleParagraph(false, listTag, *firstRangeOf(endingSelection()));
}
开发者ID:howardroark2018,项目名称:chromium,代码行数:94,代码来源:InsertListCommand.cpp
示例4: setBase
void Selection::setBase(const VisiblePosition& visiblePosition)
{
m_base = visiblePosition.deepEquivalent();
validate();
}
开发者ID:Crawping,项目名称:davinci,代码行数:5,代码来源:Selection.cpp
示例5: VisiblePosition
void Selection::validate()
{
// Move the selection to rendered positions, if possible.
bool baseAndExtentEqual = m_base == m_extent;
if (m_base.isNotNull()) {
m_base = VisiblePosition(m_base, m_affinity).deepEquivalent();
if (baseAndExtentEqual)
m_extent = m_base;
}
if (m_extent.isNotNull() && !baseAndExtentEqual)
m_extent = VisiblePosition(m_extent, m_affinity).deepEquivalent();
// Make sure we do not have a dangling base or extent.
if (m_base.isNull() && m_extent.isNull())
m_baseIsFirst = true;
else if (m_base.isNull()) {
m_base = m_extent;
m_baseIsFirst = true;
} else if (m_extent.isNull()) {
m_extent = m_base;
m_baseIsFirst = true;
} else {
m_baseIsFirst = comparePositions(m_base, m_extent) <= 0;
}
if (m_baseIsFirst) {
m_start = m_base;
m_end = m_extent;
} else {
m_start = m_extent;
m_end = m_base;
}
// Expand the selection if requested.
switch (m_granularity) {
case CharacterGranularity:
// Don't do any expansion.
break;
case WordGranularity: {
// General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
// Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
// the document, select that last word (LeftWordIfOnBoundary).
// Edge case: If the caret is after the last word in a paragraph, select from the the end of the
// last word to the line break (also RightWordIfOnBoundary);
VisiblePosition start = VisiblePosition(m_start, m_affinity);
VisiblePosition originalEnd(m_end, m_affinity);
EWordSide side = RightWordIfOnBoundary;
if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
side = LeftWordIfOnBoundary;
m_start = startOfWord(start, side).deepEquivalent();
side = RightWordIfOnBoundary;
if (isEndOfDocument(originalEnd) || (isEndOfLine(originalEnd) && !isStartOfLine(originalEnd) && !isEndOfParagraph(originalEnd)))
side = LeftWordIfOnBoundary;
VisiblePosition wordEnd(endOfWord(originalEnd, side));
VisiblePosition end(wordEnd);
if (isEndOfParagraph(originalEnd)) {
// Select the paragraph break (the space from the end of a paragraph to the start of
// the next one) to match TextEdit.
end = wordEnd.next();
if (Node* table = isFirstPositionAfterTable(end)) {
// The paragraph break after the last paragraph in the last cell of a block table ends
// at the start of the paragraph after the table.
if (isBlock(table))
end = end.next(true);
else
end = wordEnd;
}
if (end.isNull())
end = wordEnd;
}
m_end = end.deepEquivalent();
break;
}
case SentenceGranularity: {
m_start = startOfSentence(VisiblePosition(m_start, m_affinity)).deepEquivalent();
m_end = endOfSentence(VisiblePosition(m_end, m_affinity)).deepEquivalent();
break;
}
case LineGranularity: {
m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
VisiblePosition end = endOfLine(VisiblePosition(m_end, m_affinity));
// If the end of this line is at the end of a paragraph, include the space
// after the end of the line in the selection.
if (isEndOfParagraph(end)) {
VisiblePosition next = end.next();
if (next.isNotNull())
end = next;
}
m_end = end.deepEquivalent();
break;
}
case LineBoundary:
m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
m_end = endOfLine(VisiblePosition(m_end, m_affinity)).deepEquivalent();
//.........这里部分代码省略.........
开发者ID:Crawping,项目名称:davinci,代码行数:101,代码来源:Selection.cpp
示例6: prune
// If a selection starts in one block and ends in another, we have to merge to bring content before the
// start together with content after the end.
void DeleteSelectionCommand::mergeParagraphs()
{
if (!m_mergeBlocksAfterDelete) {
if (m_pruneStartBlockIfNecessary) {
// We aren't going to merge into the start block, so remove it if it's empty.
prune(m_startBlock);
// Removing the start block during a deletion is usually an indication that we need
// a placeholder, but not in this case.
m_needPlaceholder = false;
}
return;
}
// It shouldn't have been asked to both try and merge content into the start block and prune it.
ASSERT(!m_pruneStartBlockIfNecessary);
// FIXME: Deletion should adjust selection endpoints as it removes nodes so that we never get into this state (4099839).
if (!m_downstreamEnd.anchorNode()->inDocument() || !m_upstreamStart.anchorNode()->inDocument())
return;
// FIXME: The deletion algorithm shouldn't let this happen.
if (comparePositions(m_upstreamStart, m_downstreamEnd) > 0)
return;
// There's nothing to merge.
if (m_upstreamStart == m_downstreamEnd)
return;
VisiblePosition startOfParagraphToMove(m_downstreamEnd);
VisiblePosition mergeDestination(m_upstreamStart);
// m_downstreamEnd's block has been emptied out by deletion. There is no content inside of it to
// move, so just remove it.
Element* endBlock = static_cast<Element*>(enclosingBlock(m_downstreamEnd.deprecatedNode()));
if (!endBlock || !endBlock->contains(startOfParagraphToMove.deepEquivalent().deprecatedNode()) || !startOfParagraphToMove.deepEquivalent().deprecatedNode()) {
removeNode(enclosingBlock(m_downstreamEnd.deprecatedNode()));
return;
}
// We need to merge into m_upstreamStart's block, but it's been emptied out and collapsed by deletion.
if (!mergeDestination.deepEquivalent().deprecatedNode() || !mergeDestination.deepEquivalent().deprecatedNode()->isDescendantOf(enclosingBlock(m_upstreamStart.containerNode())) || m_startsAtEmptyLine) {
insertNodeAt(createBreakElement(document()).get(), m_upstreamStart);
mergeDestination = VisiblePosition(m_upstreamStart);
}
if (mergeDestination == startOfParagraphToMove)
return;
VisiblePosition endOfParagraphToMove = endOfParagraph(startOfParagraphToMove);
if (mergeDestination == endOfParagraphToMove)
return;
// The rule for merging into an empty block is: only do so if its farther to the right.
// FIXME: Consider RTL.
if (!m_startsAtEmptyLine && isStartOfParagraph(mergeDestination) && startOfParagraphToMove.absoluteCaretBounds().x() > mergeDestination.absoluteCaretBounds().x()) {
if (mergeDestination.deepEquivalent().downstream().deprecatedNode()->hasTagName(brTag)) {
removeNodeAndPruneAncestors(mergeDestination.deepEquivalent().downstream().deprecatedNode());
m_endingPosition = startOfParagraphToMove.deepEquivalent();
return;
}
}
// Block images, tables and horizontal rules cannot be made inline with content at mergeDestination. If there is
// any (!isStartOfParagraph(mergeDestination)), don't merge, just move the caret to just before the selection we deleted.
// See https://bugs.webkit.org/show_bug.cgi?id=25439
if (isRenderedAsNonInlineTableImageOrHR(startOfParagraphToMove.deepEquivalent().deprecatedNode()) && !isStartOfParagraph(mergeDestination)) {
m_endingPosition = m_upstreamStart;
return;
}
RefPtr<Range> range = Range::create(document(), startOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent(), endOfParagraphToMove.deepEquivalent().parentAnchoredEquivalent());
RefPtr<Range> rangeToBeReplaced = Range::create(document(), mergeDestination.deepEquivalent().parentAnchoredEquivalent(), mergeDestination.deepEquivalent().parentAnchoredEquivalent());
if (!document()->frame()->editor()->client()->shouldMoveRangeAfterDelete(range.get(), rangeToBeReplaced.get()))
return;
// moveParagraphs will insert placeholders if it removes blocks that would require their use, don't let block
// removals that it does cause the insertion of *another* placeholder.
bool needPlaceholder = m_needPlaceholder;
bool paragraphToMergeIsEmpty = (startOfParagraphToMove == endOfParagraphToMove);
moveParagraph(startOfParagraphToMove, endOfParagraphToMove, mergeDestination, false, !paragraphToMergeIsEmpty);
m_needPlaceholder = needPlaceholder;
// The endingPosition was likely clobbered by the move, so recompute it (moveParagraph selects the moved paragraph).
m_endingPosition = endingSelection().start();
}
开发者ID:Moondee,项目名称:Artemis,代码行数:87,代码来源:DeleteSelectionCommand.cpp
示例7: objectFocusedAndCaretOffsetUnignored
AccessibilityObject* objectFocusedAndCaretOffsetUnignored(AccessibilityObject* referenceObject, int& offset)
{
// Indication that something bogus has transpired.
offset = -1;
Document* document = referenceObject->document();
if (!document)
return 0;
Node* focusedNode = referenceObject->selection().end().containerNode();
if (!focusedNode)
return 0;
RenderObject* focusedRenderer = focusedNode->renderer();
if (!focusedRenderer)
return 0;
AccessibilityObject* focusedObject = document->axObjectCache()->getOrCreate(focusedRenderer);
if (!focusedObject)
return 0;
// Look for the actual (not ignoring accessibility) selected object.
AccessibilityObject* firstUnignoredParent = focusedObject;
if (firstUnignoredParent->accessibilityIsIgnored())
firstUnignoredParent = firstUnignoredParent->parentObjectUnignored();
if (!firstUnignoredParent)
return 0;
// Don't ignore links if the offset is being requested for a link.
if (!referenceObject->isLink() && firstUnignoredParent->isLink())
firstUnignoredParent = firstUnignoredParent->parentObjectUnignored();
if (!firstUnignoredParent)
return 0;
// The reference object must either coincide with the focused
// object being considered, or be a descendant of it.
if (referenceObject->isDescendantOfObject(firstUnignoredParent))
referenceObject = firstUnignoredParent;
Node* startNode = 0;
if (firstUnignoredParent != referenceObject || firstUnignoredParent->isTextControl()) {
// We need to use the first child's node of the reference
// object as the start point to calculate the caret offset
// because we want it to be relative to the object of
// reference, not just to the focused object (which could have
// previous siblings which should be taken into account too).
AccessibilityObject* axFirstChild = referenceObject->firstChild();
if (axFirstChild)
startNode = axFirstChild->node();
}
if (!startNode)
startNode = firstUnignoredParent->node();
// Check if the node for the first parent object not ignoring
// accessibility is null again before using it. This might happen
// with certain kind of accessibility objects, such as the root
// one (the scroller containing the webArea object).
if (!startNode)
return 0;
VisiblePosition startPosition = VisiblePosition(positionBeforeNode(startNode), DOWNSTREAM);
VisiblePosition endPosition = firstUnignoredParent->selection().visibleEnd();
if (startPosition == endPosition)
offset = 0;
else if (!isStartOfLine(endPosition)) {
RefPtr<Range> range = makeRange(startPosition, endPosition.previous());
offset = TextIterator::rangeLength(range.get(), true) + 1;
} else {
RefPtr<Range> range = makeRange(startPosition, endPosition);
offset = TextIterator::rangeLength(range.get(), true);
}
return firstUnignoredParent;
}
开发者ID:conioh,项目名称:os-design,代码行数:75,代码来源:WebKitAccessibleWrapperAtk.cpp
示例8: endOfParagraph
// FIXME: We should merge this function with ApplyBlockElementCommand::formatSelection
void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection, const VisiblePosition& endOfSelection)
{
VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection);
VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection);
if (endOfCurrentParagraph == endOfLastParagraph) {
outdentParagraph();
return;
}
Position originalSelectionEnd = endingSelection().end();
VisiblePosition endAfterSelection = endOfParagraph(endOfLastParagraph.next());
while (endOfCurrentParagraph != endAfterSelection) {
VisiblePosition endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.next());
if (endOfCurrentParagraph == endOfLastParagraph)
setEndingSelection(VisibleSelection(originalSelectionEnd, DOWNSTREAM));
else
setEndingSelection(endOfCurrentParagraph);
outdentParagraph();
// outdentParagraph could move more than one paragraph if the paragraph
// is in a list item. As a result, endAfterSelection and endOfNextParagraph
// could refer to positions no longer in the document.
if (endAfterSelection.isNotNull() && !endAfterSelection.deepEquivalent().inDocument())
break;
if (endOfNextParagraph.isNotNull() && !endOfNextParagraph.deepEquivalent().inDocument()) {
endOfCurrentParagraph = VisiblePosition(endingSelection().end());
endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.next());
}
endOfCurrentParagraph = endOfNextParagraph;
}
}
开发者ID:alexanderbill,项目名称:blink-crosswalk,代码行数:36,代码来源:IndentOutdentCommand.cpp
示例9: endingSelection
void ApplyBlockElementCommand::doApply()
{
if (!endingSelection().rootEditableElement())
return;
VisiblePosition visibleEnd = endingSelection().visibleEnd();
VisiblePosition visibleStart = endingSelection().visibleStart();
if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull() || visibleEnd.isOrphan())
return;
// 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(VisibleSelection(visibleStart, visibleEnd.previous(CannotCrossEditingBoundary), endingSelection().isDirectional()));
VisibleSelection selection = selectionForParagraphIteration(endingSelection());
VisiblePosition startOfSelection = selection.visibleStart();
VisiblePosition endOfSelection = selection.visibleEnd();
ASSERT(!startOfSelection.isNull());
ASSERT(!endOfSelection.isNull());
RefPtr<ContainerNode> startScope;
int startIndex = indexForVisiblePosition(startOfSelection, startScope);
RefPtr<ContainerNode> endScope;
int endIndex = indexForVisiblePosition(endOfSelection, endScope);
formatSelection(startOfSelection, endOfSelection);
document()->updateLayoutIgnorePendingStylesheets();
ASSERT(startScope == endScope);
ASSERT(startIndex >= 0);
ASSERT(startIndex <= endIndex);
if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) {
VisiblePosition start(visiblePositionForIndex(startIndex, startScope.get()));
VisiblePosition end(visiblePositionForIndex(endIndex, endScope.get()));
if (start.isNotNull() && end.isNotNull())
setEndingSelection(VisibleSelection(start, end, endingSelection().isDirectional()));
}
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_WebKit,代码行数:45,代码来源:ApplyBlockElementCommand.cpp
示例10: endingSelection
void FormatBlockCommand::doApply()
{
if (!endingSelection().isNonOrphanedCaretOrRange())
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(VisibleSelection(visibleStart, visibleEnd.previous(true)));
if (endingSelection().isRange() && modifyRange())
return;
ExceptionCode ec;
String localName, prefix;
if (!Document::parseQualifiedName(m_tagName, prefix, localName, ec))
return;
QualifiedName qTypeOfBlock(prefix, 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<Element> blockNode = createHTMLElement(document(), m_tagName);
RefPtr<Element> placeholder = createBreakElement(document());
Node* root = endingSelection().start().node()->rootEditableElement();
if (validBlockTag(refNode->nodeName().lower()) &&
paragraphStart == blockStart && paragraphEnd == blockEnd &&
refNode != root && !root->isDescendantOf(refNode))
// Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag
insertNodeBefore(blockNode, refNode);
else {
// Avoid inserting inside inline elements that surround paragraphStart with upstream().
// This is only to avoid creating bloated markup.
insertNodeAt(blockNode, paragraphStart.deepEquivalent().upstream());
}
appendNode(placeholder, blockNode);
VisiblePosition destination(Position(placeholder.get(), 0));
if (paragraphStart == paragraphEnd && !lineBreakExistsAtVisiblePosition(paragraphStart)) {
setEndingSelection(destination);
return;
}
moveParagraph(paragraphStart, paragraphEnd, destination, true, false);
}
开发者ID:azrul2202,项目名称:WebKit-Smartphone,代码行数:62,代码来源:FormatBlockCommand.cpp
示例11: startOfParagraph
void IndentOutdentCommand::outdentParagraph()
{
VisiblePosition visibleStartOfParagraph = startOfParagraph(endingSelection().visibleStart());
VisiblePosition visibleEndOfParagraph = endOfParagraph(visibleStartOfParagraph);
HTMLElement* enclosingElement = toHTMLElement(enclosingNodeOfType(visibleStartOfParagraph.deepEquivalent(), &isHTMLListOrBlockquoteElement));
if (!enclosingElement || !enclosingElement->parentNode()->hasEditableStyle()) // We can't outdent if there is no place to go!
return;
// Use InsertListCommand to remove the selection from the list
if (isHTMLOListElement(*enclosingElement)) {
applyCommandToComposite(InsertListCommand::create(document(), InsertListCommand::OrderedList));
return;
}
if (isHTMLUListElement(*enclosingElement)) {
applyCommandToComposite(InsertListCommand::create(document(), InsertListCommand::UnorderedList));
return;
}
// The selection is inside a blockquote i.e. enclosingNode is a blockquote
VisiblePosition positionInEnclosingBlock = VisiblePosition(firstPositionInNode(enclosingElement));
// If the blockquote is inline, the start of the enclosing block coincides with
// positionInEnclosingBlock.
VisiblePosition startOfEnclosingBlock = (enclosingElement->layoutObject() && enclosingElement->layoutObject()->isInline()) ? positionInEnclosingBlock : startOfBlock(positionInEnclosingBlock);
VisiblePosition lastPositionInEnclosingBlock = VisiblePosition(lastPositionInNode(enclosingElement));
VisiblePosition endOfEnclosingBlock = endOfBlock(lastPositionInEnclosingBlock);
if (visibleStartOfParagraph == startOfEnclosingBlock &&
visibleEndOfParagraph == endOfEnclosingBlock) {
// The blockquote doesn't contain anything outside the paragraph, so it can be totally removed.
Node* splitPoint = enclosingElement->nextSibling();
removeNodePreservingChildren(enclosingElement);
// outdentRegion() assumes it is operating on the first paragraph of an enclosing blockquote, but if there are multiply nested blockquotes and we've
// just removed one, then this assumption isn't true. By splitting the next containing blockquote after this node, we keep this assumption true
if (splitPoint) {
if (Element* splitPointParent = splitPoint->parentElement()) {
if (splitPointParent->hasTagName(blockquoteTag)
&& !splitPoint->hasTagName(blockquoteTag)
&& splitPointParent->parentNode()->hasEditableStyle()) // We can't outdent if there is no place to go!
splitElement(splitPointParent, splitPoint);
}
}
document().updateLayoutIgnorePendingStylesheets();
visibleStartOfParagraph = VisiblePosition(visibleStartOfParagraph.deepEquivalent());
visibleEndOfParagraph = VisiblePosition(visibleEndOfParagraph.deepEquivalent());
if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleStartOfParagraph))
insertNodeAt(createBreakElement(document()), visibleStartOfParagraph.deepEquivalent());
if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfParagraph))
insertNodeAt(createBreakElement(document()), visibleEndOfParagraph.deepEquivalent());
return;
}
RefPtrWillBeRawPtr<Node> splitBlockquoteNode = enclosingElement;
if (Element* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.deepEquivalent().deprecatedNode())) {
if (enclosingBlockFlow != enclosingElement) {
splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingElement, true);
} else {
// We split the blockquote at where we start outdenting.
Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfParagraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockFlow);
splitElement(enclosingElement, highestInlineNode ? highestInlineNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode());
}
}
VisiblePosition startOfParagraphToMove(startOfParagraph(visibleStartOfParagraph));
VisiblePosition endOfParagraphToMove(endOfParagraph(visibleEndOfParagraph));
if (startOfParagraphToMove.isNull() || endOfParagraphToMove.isNull())
return;
RefPtrWillBeRawPtr<HTMLBRElement> placeholder = createBreakElement(document());
insertNodeBefore(placeholder, splitBlockquoteNode);
moveParagraph(startOfParagraphToMove, endOfParagraphToMove, VisiblePosition(positionBeforeNode(placeholder.get())), true);
}
开发者ID:alexanderbill,项目名称:blink-crosswalk,代码行数:70,代码来源:IndentOutdentCommand.cpp
示例12: DCHECK
bool SelectionModifier::modifyWithPageGranularity(EAlteration alter,
unsigned verticalDistance,
VerticalDirection direction) {
if (!verticalDistance)
return false;
DCHECK(!frame()->document()->needsLayoutTreeUpdate());
DocumentLifecycle::DisallowTransitionScope disallowTransition(
frame()->document()->lifecycle());
willBeModified(alter, direction == FrameSelection::DirectionUp
? DirectionBackward
: DirectionForward);
VisiblePosition pos;
LayoutUnit xPos;
switch (alter) {
case FrameSelection::AlterationMove:
pos = createVisiblePosition(direction == FrameSelection::DirectionUp
? m_selection.start()
: m_selection.end(),
m_selection.affinity());
xPos = lineDirectionPointForBlockDirectionNavigation(
direction == FrameSelection::DirectionUp ? START : END);
m_selection.setAffinity(direction == FrameSelection::DirectionUp
? TextAffinity::Upstream
: TextAffinity::Downstream);
break;
case FrameSelection::AlterationExtend:
pos = createVisiblePosition(m_selection.extent(), m_selection.affinity());
xPos = lineDirectionPointForBlockDirectionNavigation(EXTENT);
m_selection.setAffinity(TextAffinity::Downstream);
break;
}
int startY;
if (!absoluteCaretY(pos, startY))
return false;
if (direction == FrameSelection::DirectionUp)
startY = -startY;
int lastY = startY;
VisiblePosition result;
VisiblePosition next;
for (VisiblePosition p = pos;; p = next) {
if (direction == FrameSelection::DirectionUp)
next = previousLinePosition(p, xPos);
else
next = nextLinePosition(p, xPos);
if (next.isNull() || next.deepEquivalent() == p.deepEquivalent())
break;
int nextY;
if (!absoluteCaretY(next, nextY))
break;
if (direction == FrameSelection::DirectionUp)
nextY = -nextY;
if (nextY - startY > static_cast<int>(verticalDistance))
break;
if (nextY >= lastY) {
lastY = nextY;
result = next;
}
}
if (result.isNull())
return false;
switch (alter) {
case FrameSelection::AlterationMove:
m_selection = createVisibleSelection(
SelectionInDOMTree::Builder()
.collapse(result.toPositionWithAffinity())
.setIsDirectional(m_selection.isDirectional())
.build());
break;
case FrameSelection::AlterationExtend:
m_selection.setExtent(result);
break;
}
m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(frame()) ||
alter == FrameSelection::AlterationExtend);
return true;
}
开发者ID:mirror,项目名称:chromium,代码行数:86,代码来源:SelectionModifier.cpp
示例13: isEndOfDocument
bool isEndOfDocument(const VisiblePosition &p)
{
return p.isNotNull() && p.next().isNull();
}
开发者ID:Czerrr,项目名称:ISeeBrowser,代码行数:4,代码来源:visible_units.cpp
示例14: document
void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool killRing)
{
LocalFrame* frame = document().frame();
if (!frame)
return;
frame->spellChecker().updateMarkersForWordsAffectedByEditing(false);
VisibleSelection selectionToDelete;
VisibleSelection selectionAfterUndo;
switch (endingSelection().selectionType()) {
case RangeSelection:
selectionToDelete = endingSelection();
selectionAfterUndo = selectionToDelete;
break;
case CaretSelection: {
m_smartDelete = false;
// Handle delete at beginning-of-block case.
// Do nothing in the case that the caret is at the start of a
// root editable element or at the start of a document.
OwnPtrWillBeRawPtr<FrameSelection> selection = FrameSelection::create();
selection->setSelection(endingSelection());
selection->modify(FrameSelection::AlterationExtend, DirectionForward, granularity);
if (killRing && selection->isCaret() && granularity != CharacterGranularity)
selection->modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
Position downstreamEnd = endingSelection().end().downstream();
VisiblePosition visibleEnd = endingSelection().visibleEnd();
Node* enclosingTableCell = enclosingNodeOfType(visibleEnd.deepEquivalent(), &isTableCell);
if (enclosingTableCell && visibleEnd == VisiblePosition(lastPositionInNode(enclosingTableCell)))
return;
if (visibleEnd == endOfParagraph(visibleEnd))
downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEquivalent().downstream();
// When deleting tables: Select the table first, then perform the deletion
if (isRenderedTableElement(downstreamEnd.containerNode()) && downstreamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.containerNode())) {
setEndingSelection(VisibleSelection(endingSelection().end(), positionAfterNode(downstreamEnd.containerNode()), DOWNSTREAM, endingSelection().isDirectional()));
typingAddedToOpenCommand(ForwardDeleteKey);
return;
}
// deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any)
if (granularity == ParagraphBoundary && selection->selection().isCaret() && isEndOfParagraph(selection->selection().visibleEnd()))
selection->modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
selectionToDelete = selection->selection();
if (!startingSelection().isRange() || selectionToDelete.base() != startingSelection().start())
selectionAfterUndo = selectionToDelete;
else {
// It's a little tricky to compute what the starting selection would have been in the original document.
// We can't let the VisibleSelection class's validation kick in or it'll adjust for us based on
// the current state of the document and we'll get the wrong result.
Position extent = startingSelection().end();
if (extent.containerNode() != selectionToDelete.end().containerNode())
extent = selectionToDelete.extent();
else {
int extraCharacters;
if (selectionToDelete.start().containerNode() == selectionToDelete.end().containerNode())
extraCharacters = selectionToDelete.end().computeOffsetInContainerNode() - selectionToDelete.start().computeOffsetInContainerNode();
else
extraCharacters = selectionToDelete.end().computeOffsetInContainerNode();
extent = Position(extent.containerNode(), extent.computeOffsetInContainerNode() + extraCharacters, Position::PositionIsOffsetInAnchor);
}
selectionAfterUndo.setWithoutValidation(startingSelection().start(), extent);
}
break;
}
case NoSelection:
ASSERT_NOT_REACHED();
break;
}
ASSERT(!selectionToDelete.isNone());
if (selectionToDelete.isNone())
return;
if (selectionToDelete.isCaret())
return;
if (killRing)
frame->editor().addToKillRing(selectionToDelete.toNormalizedRange().get(), false);
// Make undo select what was deleted on Mac alone
if (frame->editor().behavior().shouldUndoOfDeleteSelectText())
setStartingSelection(selectionAfterUndo);
CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete);
setSmartDelete(false);
typingAddedToOpenCommand(ForwardDeleteKey);
}
开发者ID:darktears,项目名称:blink-crosswalk,代码行数:89,代码来源:TypingCommand.cpp
示例15: switch
void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing)
{
Frame& frame = this->frame();
frame.editor().updateMarkersForWordsAffectedByEditing(false);
VisibleSelection selectionToDelete;
VisibleSelection selectionAfterUndo;
switch (endingSelection().selectionType()) {
case VisibleSelection::RangeSelection:
selectionToDelete = endingSelection();
selectionAfterUndo = selectionToDelete;
break;
case VisibleSelection::CaretSelection: {
m_smartDelete = false;
// Handle delete at beginning-of-block case.
// Do nothing in the case that the caret is at the start of a
// root editable element or at the start of a document.
FrameSelection selection;
selection.setSelection(endingSelection());
selection.modify(FrameSelection::AlterationExtend, DirectionForward, granularity);
if (shouldAddToKillRing && selection.isCaret() && granularity != CharacterGranularity)
selection.modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
Position downstreamEnd = endingSelection().end().downstream();
VisiblePosition visibleEnd = endingSelection().visibleEnd();
Node* enclosingTableCell = enclosingNodeOfType(visibleEnd.deepEquivalent(), &isTableCell);
if (enclosingTableCell && visibleEnd == lastPositionInNode(enclosingTableCell))
return;
if (visibleEnd == endOfParagraph(visibleEnd))
downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEquivalent().downstream();
// When deleting tables: Select the table first, then perform the deletion
if (downstreamEnd.containerNode() && downstreamEnd.containerNode()->renderer() && downstreamEnd.containerNode()->renderer()->isTable()
&& downstreamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.containerNode())) {
setEndingSelection(VisibleSelection(endingSelection().end(), positionAfterNode(downstreamEnd.containerNode()), DOWNSTREAM, endingSelection().isDirectional()));
typingAddedToOpenCommand(ForwardDeleteKey);
return;
}
// deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any)
if (granularity == ParagraphBoundary && selection.selection().isCaret() && isEndOfParagraph(selection.selection().visibleEnd()))
selection.modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity);
selectionToDelete = selection.selection();
if (!startingSelection().isRange() || selectionToDelete.base() != startingSelection().start())
selectionAfterUndo = selectionToDelete;
else {
// It's a little tricky to compute what the starting selection would have been in the original document.
// We can't let the VisibleSelection class's validation kick in or it'll adjust for us based on
// the current state of the document and we'll get the wrong result.
Position extent = startingSelection().end();
if (extent.containerNode() != selectionToDelete.end().containerNode())
extent = selectionToDelete.extent();
|
请发表评论