本文整理汇总了C++中EphemeralRange类的典型用法代码示例。如果您正苦于以下问题:C++ EphemeralRange类的具体用法?C++ EphemeralRange怎么用?C++ EphemeralRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EphemeralRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
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: ASSERT
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;
}
示例3: 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));
}
示例4: frame
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());
}
示例5: positionForPoint
EphemeralRange LocalFrame::rangeForPoint(const IntPoint& framePoint) {
const PositionWithAffinity positionWithAffinity =
positionForPoint(framePoint);
if (positionWithAffinity.isNull())
return EphemeralRange();
VisiblePosition position = createVisiblePosition(positionWithAffinity);
VisiblePosition previous = previousPositionOf(position);
if (previous.isNotNull()) {
const EphemeralRange previousCharacterRange = makeRange(previous, position);
IntRect rect = editor().firstRectForRange(previousCharacterRange);
if (rect.contains(framePoint))
return EphemeralRange(previousCharacterRange);
}
VisiblePosition next = nextPositionOf(position);
const EphemeralRange nextCharacterRange = makeRange(position, next);
if (nextCharacterRange.isNotNull()) {
IntRect rect = editor().firstRectForRange(nextCharacterRange);
if (rect.contains(framePoint))
return EphemeralRange(nextCharacterRange);
}
return EphemeralRange();
}
示例6: DCHECK
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: firstEphemeralRangeOf
PlainTextRange InputMethodController::getSelectionOffsets() const
{
EphemeralRange range = firstEphemeralRangeOf(frame().selection().selection());
if (range.isNull())
return PlainTextRange();
ContainerNode* editable = frame().selection().rootEditableElementOrTreeScopeRootNode();
ASSERT(editable);
return PlainTextRange::create(*editable, range);
}
示例8: 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.
}
}
示例9: toWebLocalFrameImpl
// 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());
}
示例10: it
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;
}
示例11: compositionEphemeralRange
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);
}
示例12: expandEndToSentenceBoundary
static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) {
DCHECK(range.isNotNull());
const VisiblePosition& visibleEnd =
createVisiblePosition(range.endPosition());
DCHECK(visibleEnd.isNotNull());
const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent();
// TODO(xiaochengh): |sentenceEnd < range.endPosition()| 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 EphemeralRange(
range.startPosition(),
sentenceEnd.isNotNull() && sentenceEnd > range.endPosition()
? sentenceEnd
: range.endPosition());
}
示例13: TEST_F
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());
}
示例14: TEST_F
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));
}
示例15: 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;
}