Chromium Code Reviews| 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 a97614627ae121af6b9e57c7d8ff8be629450344..9e3aa247fa4b1065c29b8a05be33b3c9fff58985 100644 |
| --- a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp |
| +++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerController.cpp |
| @@ -84,8 +84,10 @@ inline bool DocumentMarkerController::possiblyHasMarkers( |
| return m_possiblyExistingMarkerTypes.intersects(types); |
| } |
| -DocumentMarkerController::DocumentMarkerController(const Document& document) |
| - : m_possiblyExistingMarkerTypes(0), m_document(&document) {} |
| +DocumentMarkerController::DocumentMarkerController(Document& document) |
| + : m_possiblyExistingMarkerTypes(0), m_document(&document) { |
| + setContext(&document); |
| +} |
| void DocumentMarkerController::clear() { |
| m_markers.clear(); |
| @@ -178,11 +180,6 @@ static bool startsFurther(const Member<RenderedDocumentMarker>& lhv, |
| return lhv->startOffset() < rhv->startOffset(); |
| } |
| -static bool startsAfter(const Member<RenderedDocumentMarker>& marker, |
| - size_t startOffset) { |
| - return marker->startOffset() < startOffset; |
| -} |
| - |
| static bool endsBefore(size_t startOffset, |
| const Member<RenderedDocumentMarker>& rhv) { |
| return startOffset < rhv->endOffset(); |
| @@ -265,8 +262,9 @@ void DocumentMarkerController::addMarker(Node* node, |
| } |
| // repaint the affected node |
| - if (node->layoutObject()) |
| + if (node->layoutObject()) { |
|
Xiaocheng
2017/02/23 18:58:35
nit: no need to add braces
|
| node->layoutObject()->setShouldDoFullPaintInvalidation(); |
| + } |
| } |
| void DocumentMarkerController::mergeOverlapping( |
| @@ -308,10 +306,7 @@ void DocumentMarkerController::copyMarkers(Node* srcNode, |
| return; |
| bool docDirty = false; |
| - for (size_t markerListIndex = 0; |
| - markerListIndex < DocumentMarker::MarkerTypeIndexesCount; |
| - ++markerListIndex) { |
| - Member<MarkerList>& list = (*markers)[markerListIndex]; |
| + for (Member<MarkerList> list : *markers) { |
| if (!list) |
| continue; |
| @@ -338,8 +333,9 @@ void DocumentMarkerController::copyMarkers(Node* srcNode, |
| } |
| // repaint the affected node |
| - if (docDirty && dstNode->layoutObject()) |
| + if (docDirty && dstNode->layoutObject()) { |
|
Xiaocheng
2017/02/23 18:58:35
nit: no need to add braces
|
| dstNode->layoutObject()->setShouldDoFullPaintInvalidation(); |
| + } |
| } |
| void DocumentMarkerController::removeMarkers( |
| @@ -428,8 +424,9 @@ void DocumentMarkerController::removeMarkers( |
| } |
| // repaint the affected node |
| - if (docDirty && node->layoutObject()) |
| + if (docDirty && node->layoutObject()) { |
|
Xiaocheng
2017/02/23 18:58:35
nit: no need to add braces
|
| node->layoutObject()->setShouldDoFullPaintInvalidation(); |
| + } |
| } |
| DocumentMarkerVector DocumentMarkerController::markersFor( |
| @@ -588,6 +585,7 @@ void DocumentMarkerController::invalidateRectsForAllMarkers() { |
| DEFINE_TRACE(DocumentMarkerController) { |
| visitor->trace(m_markers); |
| visitor->trace(m_document); |
| + SynchronousMutationObserver::trace(visitor); |
| } |
| void DocumentMarkerController::removeMarkers( |
| @@ -685,8 +683,9 @@ void DocumentMarkerController::removeMarkersFromList( |
| if (needsRepainting) { |
| const Node& node = *iterator->key; |
| - if (LayoutObject* layoutObject = node.layoutObject()) |
| + if (LayoutObject* layoutObject = node.layoutObject()) { |
|
Xiaocheng
2017/02/23 18:58:35
nit: no need to add braces
|
| layoutObject->setShouldDoFullPaintInvalidation(); |
| + } |
| invalidatePaintForTickmarks(node); |
| } |
| @@ -727,45 +726,6 @@ void DocumentMarkerController::repaintMarkers( |
| } |
| } |
| -void DocumentMarkerController::shiftMarkers(Node* node, |
| - unsigned startOffset, |
| - int delta) { |
| - if (!possiblyHasMarkers(DocumentMarker::AllMarkers())) |
| - return; |
| - DCHECK(!m_markers.isEmpty()); |
| - |
| - MarkerLists* markers = m_markers.at(node); |
| - if (!markers) |
| - return; |
| - |
| - bool didShiftMarker = false; |
| - for (size_t markerListIndex = 0; |
| - markerListIndex < DocumentMarker::MarkerTypeIndexesCount; |
| - ++markerListIndex) { |
| - Member<MarkerList>& list = (*markers)[markerListIndex]; |
| - if (!list) |
| - continue; |
| - MarkerList::iterator startPos = |
| - std::lower_bound(list->begin(), list->end(), startOffset, startsAfter); |
| - for (MarkerList::iterator marker = startPos; marker != list->end(); |
| - ++marker) { |
| -#if DCHECK_IS_ON() |
| - int startOffset = (*marker)->startOffset(); |
| - DCHECK_GE(startOffset + delta, 0); |
| -#endif |
| - (*marker)->shiftOffsets(delta); |
| - didShiftMarker = true; |
| - } |
| - } |
| - |
| - if (didShiftMarker) { |
| - invalidateRectsForMarkersInNode(*node); |
| - // repaint the affected node |
| - if (node->layoutObject()) |
| - node->layoutObject()->setShouldDoFullPaintInvalidation(); |
| - } |
| -} |
| - |
| bool DocumentMarkerController::setMarkersActive(const EphemeralRange& range, |
| bool active) { |
| if (!possiblyHasMarkers(DocumentMarker::AllMarkers())) |
| @@ -819,8 +779,9 @@ bool DocumentMarkerController::setMarkersActive(Node* node, |
| } |
| // repaint the affected node |
| - if (docDirty && node->layoutObject()) |
| + if (docDirty && node->layoutObject()) { |
|
Xiaocheng
2017/02/23 18:58:35
nit: no need to add braces.
|
| node->layoutObject()->setShouldDoFullPaintInvalidation(); |
| + } |
| return docDirty; |
| } |
| @@ -858,6 +819,82 @@ void DocumentMarkerController::showMarkers() const { |
| } |
| #endif |
| +// SynchronousMutationObserver |
| +void DocumentMarkerController::didUpdateCharacterData(CharacterData* node, |
| + unsigned offset, |
| + unsigned oldLength, |
| + unsigned newLength) { |
| + // If we're doing a pure remove operation, remove the markers in the range |
| + // being removed (markers containing, but larger than, the range, will be |
| + // split) |
| + if (newLength == 0) |
| + removeMarkers(node, offset, oldLength); |
| + |
| + if (!possiblyHasMarkers(DocumentMarker::AllMarkers())) |
| + return; |
| + DCHECK(!m_markers.isEmpty()); |
| + |
| + MarkerLists* markers = m_markers.at(node); |
| + if (!markers) |
| + return; |
| + |
| + bool didShiftMarker = false; |
| + for (MarkerList* list : *markers) { |
| + if (!list) |
| + continue; |
| + |
| + for (MarkerList::iterator marker = list->begin(); marker != list->end(); |
| + ++marker) { |
| + // algorithm inspired by https://dom.spec.whatwg.org/#concept-cd-replace |
| + // but with some changes |
| + if ((*marker)->startOffset() > offset) { |
| + // Deviation from the concept-cd-replace algorithm: < instead of <= in |
| + // the next line |
| + if ((*marker)->startOffset() < offset + oldLength) { |
| + // Marker start was in the replaced text. Move to end of new text |
| + // (Deviation from the concept-cd-replace algorithm: that algorithm |
| + // would move to the beginning of the new text here) |
| + (*marker)->setStartOffset(offset + newLength); |
| + } else { |
| + // Marker start was after the replaced text. Shift by length |
| + // difference |
| + unsigned oldStartOffset = (*marker)->startOffset(); |
| + (*marker)->setStartOffset(oldStartOffset + newLength - oldLength); |
| + } |
| + } |
| + |
| + if ((*marker)->endOffset() > offset) { |
| + // Deviation from the concept-cd-replace algorithm: < instead of <= in |
| + // the next line |
| + if ((*marker)->endOffset() < offset + oldLength) { |
| + // Marker end was in the replaced text. Move to beginning of new text |
| + (*marker)->setEndOffset(offset); |
| + } else { |
| + // Marker end was after the replaced text. Shift by length difference |
| + unsigned oldEndOffset = (*marker)->endOffset(); |
| + (*marker)->setEndOffset(oldEndOffset + newLength - oldLength); |
| + } |
| + } |
| + |
| + if ((*marker)->startOffset() >= (*marker)->endOffset()) { |
| + list->remove(marker - list->begin()); |
| + --marker; |
| + continue; |
| + } |
| + |
| + didShiftMarker = true; |
|
Xiaocheng
2017/02/23 18:58:35
didShiftMarker = true should be set after L863 and
|
| + } |
| + } |
| + |
| + if (didShiftMarker) { |
| + invalidateRectsForMarkersInNode(*node); |
| + // repaint the affected node |
| + if (node->layoutObject()) { |
| + node->layoutObject()->setShouldDoFullPaintInvalidation(); |
| + } |
| + } |
| +} |
| + |
| } // namespace blink |
| #ifndef NDEBUG |