Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp

Issue 2665923002: Modify DocumentMarkerController to support overlapping and nested DocumentMarkers (Closed)
Patch Set: Use range-for statement in setMarkersActive() Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
index 41afe11c85185d22f509ddc551141887d1ae33c5..a1f5347ef5846bf767f43d8431cd13436f949d78 100644
--- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp
@@ -183,11 +183,6 @@ static bool startsAfter(const Member<RenderedDocumentMarker>& marker,
return marker->startOffset() < startOffset;
}
-static bool endsBefore(size_t startOffset,
- const Member<RenderedDocumentMarker>& rhv) {
- return startOffset < rhv->endOffset();
-}
-
static bool compareByStart(const Member<DocumentMarker>& lhv,
const Member<DocumentMarker>& rhv) {
return lhv->startOffset() < rhv->startOffset();
@@ -225,7 +220,6 @@ static void updateMarkerRenderedRect(const Node& node,
}
// Markers are stored in order sorted by their start offset.
-// Markers of the same type do not overlap each other.
void DocumentMarkerController::addMarker(Node* node,
const DocumentMarker& newMarker) {
@@ -375,21 +369,21 @@ void DocumentMarkerController::removeMarkers(
if (!markerTypes.contains((*list->begin())->type()))
continue;
unsigned endOffset = startOffset + length;
- MarkerList::iterator startPos =
- std::upper_bound(list->begin(), list->end(), startOffset, endsBefore);
- for (MarkerList::iterator i = startPos; i != list->end();) {
- DocumentMarker marker(*i->get());
- // markers are returned in order, so stop if we are now past the specified
- // range
- if (marker.startOffset() >= endOffset)
- break;
+ for (size_t markerIndex = 0; markerIndex < list->size();) {
+ DocumentMarker marker(*(list->at(markerIndex).get()));
+
+ if (marker.startOffset() >= endOffset ||
+ marker.endOffset() <= startOffset) {
+ ++markerIndex;
+ continue;
+ }
// at this point we know that marker and target intersect in some way
docDirty = true;
// pitch the old marker
- list->remove(i - list->begin());
+ list->remove(markerIndex);
if (shouldRemovePartiallyOverlappingMarker) {
// Stop here. Don't add resulting slices back.
@@ -400,18 +394,20 @@ void DocumentMarkerController::removeMarkers(
if (startOffset > marker.startOffset()) {
DocumentMarker newLeft = marker;
newLeft.setEndOffset(startOffset);
- size_t insertIndex = i - list->begin();
- list->insert(insertIndex, RenderedDocumentMarker::create(newLeft));
- // Move to the marker after the inserted one.
- i = list->begin() + insertIndex + 1;
+
+ MarkerList::iterator pos = std::lower_bound(list->begin(), list->end(),
+ &newLeft, startsFurther);
+ list->insert(pos - list->begin(),
+ RenderedDocumentMarker::create(newLeft));
}
if (marker.endOffset() > endOffset) {
DocumentMarker newRight = marker;
newRight.setStartOffset(endOffset);
- size_t insertIndex = i - list->begin();
- list->insert(insertIndex, RenderedDocumentMarker::create(newRight));
- // Move to the marker after the inserted one.
- i = list->begin() + insertIndex + 1;
+
+ MarkerList::iterator pos = std::lower_bound(list->begin(), list->end(),
+ &newRight, startsFurther);
+ list->insert(pos - list->begin(),
+ RenderedDocumentMarker::create(newRight));
}
}
@@ -805,16 +801,13 @@ bool DocumentMarkerController::setMarkersActive(Node* node,
(*markers)[MarkerTypeToMarkerIndex(DocumentMarker::TextMatch)];
if (!list)
return false;
- MarkerList::iterator startPos =
- std::upper_bound(list->begin(), list->end(), startOffset, endsBefore);
- for (MarkerList::iterator marker = startPos; marker != list->end();
- ++marker) {
- // Markers are returned in order, so stop if we are now past the specified
- // range.
- if ((*marker)->startOffset() >= endOffset)
- break;
-
- (*marker)->setActiveMatch(active);
+
+ for (Member<RenderedDocumentMarker>& marker : *list) {
+ if ((*marker).endOffset() <= startOffset ||
+ (*marker).startOffset() >= endOffset)
+ continue;
+
+ (*marker).setActiveMatch(active);
docDirty = true;
}
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698