本文整理汇总了C++中VisiblePosition::rootEditableElement方法的典型用法代码示例。如果您正苦于以下问题:C++ VisiblePosition::rootEditableElement方法的具体用法?C++ VisiblePosition::rootEditableElement怎么用?C++ VisiblePosition::rootEditableElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisiblePosition
的用法示例。
在下文中一共展示了VisiblePosition::rootEditableElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doApply
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 != visibleStart && isStartOfParagraph(visibleEnd, CanSkipOverEditingBoundary)) {
setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(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 = endingSelection().firstRange();
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) != startOfLastParagraph) {
forceListCreation = !selectionHasListOfType(selection, listTag);
VisiblePosition startOfCurrentParagraph = startOfSelection;
while (startOfCurrentParagraph.isNotNull() && !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.
doApplyForSingleParagraph(forceListCreation, listTag, *currentSelection);
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() || !endOfSelection.rootEditableElement())
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(endingSelection().firstRange());
doApplyForSingleParagraph(false, listTag, *endingSelection().firstRange());
}