本文整理汇总了C++中EphemeralRange::startPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ EphemeralRange::startPosition方法的具体用法?C++ EphemeralRange::startPosition怎么用?C++ EphemeralRange::startPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EphemeralRange
的用法示例。
在下文中一共展示了EphemeralRange::startPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initialize
void SurroundingText::initialize(const Position& startPosition, const Position& endPosition, unsigned maxLength)
{
ASSERT(startPosition.document() == endPosition.document());
const unsigned halfMaxLength = maxLength / 2;
Document* document = startPosition.document();
// The position will have no document if it is null (as in no position).
if (!document || !document->documentElement())
return;
// The forward range starts at the selection end and ends at the document's
// end. It will then be updated to only contain the text in the text in the
// right range around the selection.
CharacterIterator forwardIterator(endPosition, lastPositionInNode(document->documentElement()).parentAnchoredEquivalent(), TextIteratorStopsOnFormControls);
// FIXME: why do we stop going trough the text if we were not able to select something on the right?
if (!forwardIterator.atEnd())
forwardIterator.advance(maxLength - halfMaxLength);
EphemeralRange forwardRange = forwardIterator.range();
if (forwardRange.isNull() || !Range::create(*document, endPosition, forwardRange.startPosition())->text().length())
return;
// Same as with the forward range but with the backward range. The range
// starts at the document's start and ends at the selection start and will
// be updated.
BackwardsCharacterIterator backwardsIterator(firstPositionInNode(document->documentElement()).parentAnchoredEquivalent(), startPosition, TextIteratorStopsOnFormControls);
if (!backwardsIterator.atEnd())
backwardsIterator.advance(halfMaxLength);
m_startOffsetInContent = Range::create(*document, backwardsIterator.endPosition(), startPosition)->text().length();
m_endOffsetInContent = Range::create(*document, backwardsIterator.endPosition(), endPosition)->text().length();
m_contentRange = Range::create(*document, backwardsIterator.endPosition(), forwardRange.startPosition());
ASSERT(m_contentRange);
}
示例2: setCompositionFromExistingText
void InputMethodController::setCompositionFromExistingText(const Vector<CompositionUnderline>& underlines, unsigned compositionStart, unsigned compositionEnd)
{
Element* editable = frame().selection().rootEditableElement();
if (!editable)
return;
const EphemeralRange range = PlainTextRange(compositionStart, compositionEnd).createRange(*editable);
if (range.isNull())
return;
const Position start = range.startPosition();
if (editableRootForPosition(start) != editable)
return;
const Position end = range.endPosition();
if (editableRootForPosition(end) != editable)
return;
clear();
for (const auto& underline : underlines) {
unsigned underlineStart = compositionStart + underline.startOffset;
unsigned underlineEnd = compositionStart + underline.endOffset;
EphemeralRange ephemeralLineRange = PlainTextRange(underlineStart, underlineEnd).createRange(*editable);
if (ephemeralLineRange.isNull())
continue;
frame().document()->markers().addCompositionMarker(ephemeralLineRange.startPosition(), ephemeralLineRange.endPosition(), underline.color, underline.thick, underline.backgroundColor);
}
m_hasComposition = true;
if (!m_compositionRange)
m_compositionRange = Range::create(range.document());
m_compositionRange->setStart(range.startPosition());
m_compositionRange->setEnd(range.endPosition());
}
示例3: findFirstGrammarDetail
int TextCheckingHelper::findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool markAll) const
{
// Found some bad grammar. Find the earliest detail range that starts in our search range (if any).
// Optionally add a DocumentMarker for each detail in the range.
int earliestDetailLocationSoFar = -1;
int earliestDetailIndex = -1;
for (unsigned i = 0; i < grammarDetails.size(); i++) {
const GrammarDetail* detail = &grammarDetails[i];
ASSERT(detail->length > 0 && detail->location >= 0);
int detailStartOffsetInParagraph = badGrammarPhraseLocation + detail->location;
// Skip this detail if it starts before the original search range
if (detailStartOffsetInParagraph < startOffset)
continue;
// Skip this detail if it starts after the original search range
if (detailStartOffsetInParagraph >= endOffset)
continue;
if (markAll) {
const EphemeralRange badGrammarRange = calculateCharacterSubrange(EphemeralRange(m_start, m_end), badGrammarPhraseLocation - startOffset + detail->location, detail->length);
badGrammarRange.document().markers().addMarker(badGrammarRange.startPosition(), badGrammarRange.endPosition(), DocumentMarker::Grammar, detail->userDescription);
}
// Remember this detail only if it's earlier than our current candidate (the details aren't in a guaranteed order)
if (earliestDetailIndex < 0 || earliestDetailLocationSoFar > detail->location) {
earliestDetailIndex = i;
earliestDetailLocationSoFar = detail->location;
}
}
return earliestDetailIndex;
}
示例4: adoptRefWillBeNoop
// static
PassRefPtrWillBeRawPtr<SpellCheckRequest> SpellCheckRequest::create(TextCheckingTypeMask textCheckingOptions, TextCheckingProcessType processType, const EphemeralRange& checkingRange, const EphemeralRange& paragraphRange, int requestNumber)
{
if (checkingRange.isNull())
return nullptr;
if (!checkingRange.startPosition().computeContainerNode()->rootEditableElement())
return nullptr;
String text = plainText(checkingRange, TextIteratorEmitsObjectReplacementCharacter);
if (text.isEmpty())
return nullptr;
RefPtrWillBeRawPtr<Range> checkingRangeObject = createRange(checkingRange);
RefPtrWillBeRawPtr<Range> paragraphRangeObject = nullptr;
// Share identical Range objects.
if (checkingRange == paragraphRange)
paragraphRangeObject = checkingRangeObject;
else
paragraphRangeObject = createRange(paragraphRange);
const DocumentMarkerVector& markers = checkingRangeObject->ownerDocument().markers().markersInRange(checkingRange, DocumentMarker::SpellCheckClientMarkers());
Vector<uint32_t> hashes(markers.size());
Vector<unsigned> offsets(markers.size());
for (size_t i = 0; i < markers.size(); ++i) {
hashes[i] = markers[i]->hash();
offsets[i] = markers[i]->startOffset();
}
return adoptRefWillBeNoop(new SpellCheckRequest(checkingRangeObject, paragraphRangeObject, text, textCheckingOptions, processType, hashes, offsets, requestNumber));
}
示例5: expandRangeToSentenceBoundary
static EphemeralRange expandRangeToSentenceBoundary(
const EphemeralRange& range) {
DCHECK(range.isNotNull());
const VisiblePosition& visibleStart =
createVisiblePosition(range.startPosition());
DCHECK(visibleStart.isNotNull());
const Position& sentenceStart =
startOfSentence(visibleStart).deepEquivalent();
// TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible,
// which would trigger a DCHECK in EphemeralRange's constructor if we return
// it directly. However, this shouldn't happen and needs to be fixed.
return expandEndToSentenceBoundary(EphemeralRange(
sentenceStart.isNotNull() && sentenceStart < range.startPosition()
? sentenceStart
: range.startPosition(),
range.endPosition()));
}
示例6: containsNode
bool DOMSelection::containsNode(const Node* n, bool allowPartial) const {
DCHECK(n);
if (!isAvailable())
return false;
FrameSelection& selection = frame()->selection();
if (frame()->document() != n->document() || selection.isNone())
return false;
unsigned nodeIndex = n->nodeIndex();
// TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
// |VisibleSelection::toNormalizedEphemeralRange| requires clean layout.
frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
const EphemeralRange selectedRange =
selection.selection().toNormalizedEphemeralRange();
ContainerNode* parentNode = n->parentNode();
if (!parentNode)
return false;
const Position startPosition =
selectedRange.startPosition().toOffsetInAnchor();
const Position endPosition = selectedRange.endPosition().toOffsetInAnchor();
TrackExceptionState exceptionState;
bool nodeFullySelected =
Range::compareBoundaryPoints(
parentNode, nodeIndex, startPosition.computeContainerNode(),
startPosition.offsetInContainerNode(), exceptionState) >= 0 &&
!exceptionState.hadException() &&
Range::compareBoundaryPoints(
parentNode, nodeIndex + 1, endPosition.computeContainerNode(),
endPosition.offsetInContainerNode(), exceptionState) <= 0 &&
!exceptionState.hadException();
if (exceptionState.hadException())
return false;
if (nodeFullySelected)
return true;
bool nodeFullyUnselected =
(Range::compareBoundaryPoints(
parentNode, nodeIndex, endPosition.computeContainerNode(),
endPosition.offsetInContainerNode(), exceptionState) > 0 &&
!exceptionState.hadException()) ||
(Range::compareBoundaryPoints(
parentNode, nodeIndex + 1, startPosition.computeContainerNode(),
startPosition.offsetInContainerNode(), exceptionState) < 0 &&
!exceptionState.hadException());
DCHECK(!exceptionState.hadException());
if (nodeFullyUnselected)
return false;
return allowPartial || n->isTextNode();
}
示例7: frameContentAsPlainText
static void frameContentAsPlainText(size_t maxChars, LocalFrame* frame, StringBuilder& output)
{
Document* document = frame->document();
if (!document)
return;
if (!frame->view())
return;
// Select the document body.
if (document->body()) {
const EphemeralRange range = EphemeralRange::rangeOfContents(*document->body());
// The text iterator will walk nodes giving us text. This is similar to
// the plainText() function in core/editing/TextIterator.h, but we implement the maximum
// size and also copy the results directly into a wstring, avoiding the
// string conversion.
for (TextIterator it(range.startPosition(), range.endPosition()); !it.atEnd(); it.advance()) {
it.text().appendTextToStringBuilder(output, 0, maxChars - output.length());
if (output.length() >= maxChars)
return; // Filled up the buffer.
}
}
// The separator between frames when the frames are converted to plain text.
const LChar frameSeparator[] = { '\n', '\n' };
const size_t frameSeparatorLength = WTF_ARRAY_LENGTH(frameSeparator);
// Recursively walk the children.
const FrameTree& frameTree = frame->tree();
for (Frame* curChild = frameTree.firstChild(); curChild; curChild = curChild->tree().nextSibling()) {
if (!curChild->isLocalFrame())
continue;
LocalFrame* curLocalChild = toLocalFrame(curChild);
// Ignore the text of non-visible frames.
LayoutView* contentLayoutObject = curLocalChild->contentLayoutObject();
LayoutPart* ownerLayoutObject = curLocalChild->ownerLayoutObject();
if (!contentLayoutObject || !contentLayoutObject->size().width() || !contentLayoutObject->size().height()
|| (contentLayoutObject->location().x() + contentLayoutObject->size().width() <= 0) || (contentLayoutObject->location().y() + contentLayoutObject->size().height() <= 0)
|| (ownerLayoutObject && ownerLayoutObject->style() && ownerLayoutObject->style()->visibility() != VISIBLE)) {
continue;
}
// Make sure the frame separator won't fill up the buffer, and give up if
// it will. The danger is if the separator will make the buffer longer than
// maxChars. This will cause the computation above:
// maxChars - output->size()
// to be a negative number which will crash when the subframe is added.
if (output.length() >= maxChars - frameSeparatorLength)
return;
output.append(frameSeparator, frameSeparatorLength);
frameContentAsPlainText(maxChars, curLocalChild, output);
if (output.length() >= maxChars)
return; // Filled up the buffer.
}
}
示例8: fromDocumentRange
// static
WebRange WebRange::fromDocumentRange(WebLocalFrame* frame, int start, int length)
{
LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame();
Element* selectionRoot = webFrame->selection().rootEditableElement();
ContainerNode* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement();
const EphemeralRange range = PlainTextRange(start, start + length).createRange(*scope);
if (range.isNull())
return WebRange();
return Range::create(range.document(), range.startPosition(), range.endPosition());
}
示例9: findFirstMisspelling
String TextCheckingHelper::findFirstMisspelling(int& firstMisspellingOffset, bool markAll)
{
WordAwareIterator it(m_start, m_end);
firstMisspellingOffset = 0;
String firstMisspelling;
int currentChunkOffset = 0;
while (!it.atEnd()) {
int length = it.length();
// Skip some work for one-space-char hunks
if (!(length == 1 && it.characterAt(0) == ' ')) {
int misspellingLocation = -1;
int misspellingLength = 0;
m_client->textChecker().checkSpellingOfString(it.substring(0, length), &misspellingLocation, &misspellingLength);
// 5490627 shows that there was some code path here where the String constructor below crashes.
// We don't know exactly what combination of bad input caused this, so we're making this much
// more robust against bad input on release builds.
ASSERT(misspellingLength >= 0);
ASSERT(misspellingLocation >= -1);
ASSERT(!misspellingLength || misspellingLocation >= 0);
ASSERT(misspellingLocation < length);
ASSERT(misspellingLength <= length);
ASSERT(misspellingLocation + misspellingLength <= length);
if (misspellingLocation >= 0 && misspellingLength > 0 && misspellingLocation < length && misspellingLength <= length && misspellingLocation + misspellingLength <= length) {
// Compute range of misspelled word
const EphemeralRange misspellingRange = calculateCharacterSubrange(EphemeralRange(m_start, m_end), currentChunkOffset + misspellingLocation, misspellingLength);
// Remember first-encountered misspelling and its offset.
if (!firstMisspelling) {
firstMisspellingOffset = currentChunkOffset + misspellingLocation;
firstMisspelling = it.substring(misspellingLocation, misspellingLength);
}
// Store marker for misspelled word.
misspellingRange.document().markers().addMarker(misspellingRange.startPosition(), misspellingRange.endPosition(), DocumentMarker::Spelling);
// Bail out if we're marking only the first misspelling, and not all instances.
if (!markAll)
break;
}
}
currentChunkOffset += length;
it.advance();
}
return firstMisspelling;
}
示例10: selectComposition
void InputMethodController::selectComposition() const
{
const EphemeralRange range = compositionEphemeralRange();
if (range.isNull())
return;
// The composition can start inside a composed character sequence, so we have to override checks.
// See <http://bugs.webkit.org/show_bug.cgi?id=15781>
VisibleSelection selection;
selection.setWithoutValidation(range.startPosition(), range.endPosition());
frame().selection().setSelection(selection, 0);
}
示例11: setBodyContent
TEST_F(CharacterIteratorTest, SubrangeWithReplacedElements) {
static const char* bodyContent =
"<div id='div' contenteditable='true'>1<img src='foo.png'>345</div>";
setBodyContent(bodyContent);
document().view()->updateAllLifecyclePhases();
Node* divNode = document().getElementById("div");
Range* entireRange = Range::create(document(), divNode, 0, divNode, 3);
EphemeralRange result =
calculateCharacterSubrange(EphemeralRange(entireRange), 2, 3);
Node* textNode = divNode->lastChild();
EXPECT_EQ(Position(textNode, 0), result.startPosition());
EXPECT_EQ(Position(textNode, 3), result.endPosition());
}
示例12: setBodyInnerHTML
TEST_F(DocumentMarkerControllerTest, SetMarkerActiveTest)
{
setBodyInnerHTML("<b>foo</b>");
Element* bElement = toElement(document().body()->firstChild());
EphemeralRange ephemeralRange = EphemeralRange::rangeOfContents(*bElement);
Position startBElement = toPositionInDOMTree(ephemeralRange.startPosition());
Position endBElement = toPositionInDOMTree(ephemeralRange.endPosition());
Range* range = Range::create(document(), startBElement, endBElement);
// Try to make active a marker that doesn't exist.
EXPECT_FALSE(markerController().setMarkersActive(range, true));
// Add a marker and try it once more.
markerController().addTextMatchMarker(range, false);
EXPECT_EQ(1u, markerController().markers().size());
EXPECT_TRUE(markerController().setMarkersActive(range, true));
}
示例13: setSelectedRange
bool SelectionEditor::setSelectedRange(const EphemeralRange& range, TextAffinity affinity, SelectionDirectionalMode directional, FrameSelection::SetSelectionOptions options)
{
if (range.isNull())
return false;
// Non-collapsed ranges are not allowed to start at the end of a line that is wrapped,
// they start at the beginning of the next line instead
m_logicalRange = nullptr;
stopObservingVisibleSelectionChangeIfNecessary();
// Since |FrameSeleciton::setSelection()| dispatches events and DOM tree
// can be modified by event handlers, we should create |Range| object before
// calling it.
m_logicalRange = createRange(range);
VisibleSelection newSelection(range.startPosition(), range.endPosition(), affinity, directional == SelectionDirectionalMode::Directional);
m_frameSelection->setSelection(newSelection, options);
startObservingVisibleSelectionChange();
return true;
}
示例14: create
PlainTextRange PlainTextRange::create(const ContainerNode& scope, const EphemeralRange& range)
{
if (range.isNull())
return PlainTextRange();
// The critical assumption is that this only gets called with ranges that
// concentrate on a given area containing the selection root. This is done
// because of text fields and textareas. The DOM for those is not
// directly in the document DOM, so ensure that the range does not cross a
// boundary of one of those.
Node* startContainer = range.startPosition().computeContainerNode();
if (startContainer != &scope && !startContainer->isDescendantOf(&scope))
return PlainTextRange();
Node* endContainer = range.endPosition().computeContainerNode();
if (endContainer != scope && !endContainer->isDescendantOf(&scope))
return PlainTextRange();
size_t start = TextIterator::rangeLength(Position(&const_cast<ContainerNode&>(scope), 0), range.startPosition());
size_t end = TextIterator::rangeLength(Position(&const_cast<ContainerNode&>(scope), 0), range.endPosition());
return PlainTextRange(start, end);
}
示例15: containsNode
bool DOMSelection::containsNode(const Node* n, bool allowPartial) const
{
ASSERT(n);
if (!m_frame)
return false;
FrameSelection& selection = m_frame->selection();
if (m_frame->document() != n->document() || selection.isNone())
return false;
unsigned nodeIndex = n->nodeIndex();
const EphemeralRange selectedRange = selection.selection().toNormalizedEphemeralRange();
ContainerNode* parentNode = n->parentNode();
if (!parentNode)
return false;
const Position startPosition = selectedRange.startPosition().toOffsetInAnchor();
const Position endPosition = selectedRange.endPosition().toOffsetInAnchor();
TrackExceptionState exceptionState;
bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, startPosition.computeContainerNode(), startPosition.offsetInContainerNode(), exceptionState) >= 0 && !exceptionState.hadException()
&& Range::compareBoundaryPoints(parentNode, nodeIndex + 1, endPosition.computeContainerNode(), endPosition.offsetInContainerNode(), exceptionState) <= 0 && !exceptionState.hadException();
if (exceptionState.hadException())
return false;
if (nodeFullySelected)
return true;
bool nodeFullyUnselected = (Range::compareBoundaryPoints(parentNode, nodeIndex, endPosition.computeContainerNode(), endPosition.offsetInContainerNode(), exceptionState) > 0 && !exceptionState.hadException())
|| (Range::compareBoundaryPoints(parentNode, nodeIndex + 1, startPosition.computeContainerNode(), startPosition.offsetInContainerNode(), exceptionState) < 0 && !exceptionState.hadException());
ASSERT(!exceptionState.hadException());
if (nodeFullyUnselected)
return false;
return allowPartial || n->isTextNode();
}