Commit 1ca795d4 authored by iceman's avatar iceman Committed by Commit bot

Use EphemeralRange instead of Range* in DocumentMarkerController class.

No behavior changes.

BUG=388681

Review-Url: https://codereview.chromium.org/2246143004
Cr-Commit-Position: refs/heads/master@{#413384}
parent e17fd235
......@@ -104,14 +104,14 @@ void DocumentMarkerController::addMarker(const Position& start, const Position&
}
}
void DocumentMarkerController::addTextMatchMarker(const Range* range, bool activeMatch)
void DocumentMarkerController::addTextMatchMarker(const EphemeralRange& range, bool activeMatch)
{
// TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets needs to be audited.
// see http://crbug.com/590369 for more details.
range->startPosition().document()->updateStyleAndLayoutIgnorePendingStylesheets();
range.startPosition().document()->updateStyleAndLayoutIgnorePendingStylesheets();
// Use a TextIterator to visit the potentially multiple nodes the range covers.
for (TextIterator markedText(range->startPosition(), range->endPosition()); !markedText.atEnd(); markedText.advance())
for (TextIterator markedText(range.startPosition(), range.endPosition()); !markedText.atEnd(); markedText.advance())
addMarker(markedText.currentContainer(), DocumentMarker(markedText.startOffsetInCurrentContainer(), markedText.endOffsetInCurrentContainer(), activeMatch));
// Don't invalidate tickmarks here. TextFinder invalidates tickmarks using a throttling algorithm. crbug.com/6819.
}
......@@ -713,19 +713,25 @@ void DocumentMarkerController::shiftMarkers(Node* node, unsigned startOffset, in
}
}
bool DocumentMarkerController::setMarkersActive(Range* range, bool active)
bool DocumentMarkerController::setMarkersActive(const EphemeralRange& range, bool active)
{
if (!possiblyHasMarkers(DocumentMarker::AllMarkers()))
return false;
DCHECK(!m_markers.isEmpty());
Node* startContainer = range->startContainer();
Node* endContainer = range->endContainer();
Node* const startContainer = range.startPosition().computeContainerNode();
DCHECK(startContainer);
Node* const endContainer = range.endPosition().computeContainerNode();
DCHECK(endContainer);
const unsigned containerStartOffset = range.startPosition().computeOffsetInContainerNode();
const unsigned containerEndOffset = range.endPosition().computeOffsetInContainerNode();
bool markerFound = false;
for (Node& node : EphemeralRange(range).nodes()) {
int startOffset = node == startContainer ? range->startOffset() : 0;
int endOffset = node == endContainer ? range->endOffset() : INT_MAX;
for (Node& node : range.nodes()) {
int startOffset = node == startContainer ? containerStartOffset : 0;
int endOffset = node == endContainer ? containerEndOffset : INT_MAX;
markerFound |= setMarkersActive(&node, startOffset, endOffset, active);
}
return markerFound;
......
......@@ -61,7 +61,7 @@ public:
void clear();
void addMarker(const Position& start, const Position& end, DocumentMarker::MarkerType, const String& description = emptyString(), uint32_t hash = 0);
void addTextMatchMarker(const Range*, bool activeMatch);
void addTextMatchMarker(const EphemeralRange&, bool activeMatch);
void addCompositionMarker(const Position& start, const Position& end, Color underlineColor, bool thick, Color backgroundColor);
void copyMarkers(Node* srcNode, unsigned startOffset, int length, Node* dstNode, int delta);
......@@ -80,7 +80,7 @@ public:
void repaintMarkers(DocumentMarker::MarkerTypes = DocumentMarker::AllMarkers());
void shiftMarkers(Node*, unsigned startOffset, int delta);
// Returns true if markers within a range are found.
bool setMarkersActive(Range*, bool);
bool setMarkersActive(const EphemeralRange&, bool);
// Returns true if markers within a range defined by a node, |startOffset| and |endOffset| are found.
bool setMarkersActive(Node*, unsigned startOffset, unsigned endOffset, bool);
bool hasMarkers(Node* node) const { return m_markers.contains(node); }
......
......@@ -252,7 +252,7 @@ TEST_F(DocumentMarkerControllerTest, SetMarkerActiveTest)
EphemeralRange ephemeralRange = EphemeralRange::rangeOfContents(*bElement);
Position startBElement = toPositionInDOMTree(ephemeralRange.startPosition());
Position endBElement = toPositionInDOMTree(ephemeralRange.endPosition());
Range* range = Range::create(document(), startBElement, endBElement);
const EphemeralRange range(startBElement, endBElement);
// Try to make active a marker that doesn't exist.
EXPECT_FALSE(markerController().setMarkersActive(range, true));
......
......@@ -902,7 +902,7 @@ void Internals::addTextMatchMarker(const Range* range, bool isActive)
{
ASSERT(range);
range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
range->ownerDocument().markers().addTextMatchMarker(range, isActive);
range->ownerDocument().markers().addTextMatchMarker(EphemeralRange(range), isActive);
}
void Internals::setMarkersActive(Node* node, unsigned startOffset, unsigned endOffset, bool active)
......
......@@ -366,7 +366,7 @@ void TextFinder::scopeStringMatches(int identifier, const WebString& searchText,
identifier);
}
ownerFrame().frame()->document()->markers().addTextMatchMarker(resultRange, foundActiveMatch);
ownerFrame().frame()->document()->markers().addTextMatchMarker(EphemeralRange(resultRange), foundActiveMatch);
m_findMatchesCache.append(FindMatch(resultRange, m_lastMatchCount + matchCount));
......@@ -662,7 +662,7 @@ bool TextFinder::setMarkerActive(Range* range, bool active)
{
if (!range || range->collapsed())
return false;
return ownerFrame().frame()->document()->markers().setMarkersActive(range, active);
return ownerFrame().frame()->document()->markers().setMarkersActive(EphemeralRange(range), active);
}
void TextFinder::unmarkAllTextMatches()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment