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

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

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: Rebase on https://codereview.chromium.org/2755013004 Created 3 years, 9 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
Index: third_party/WebKit/Source/core/editing/markers/DocumentMarkerList.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarkerList.cpp b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerList.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5ac3d21ae153cb4460680f09281b360e27fd8d4f
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarkerList.cpp
@@ -0,0 +1,74 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/markers/DocumentMarkerList.h"
+
+#include "core/editing/markers/DocumentMarkerController.h"
+
+namespace blink {
+
+DocumentMarkerList::DocumentMarkerList(
+ DocumentMarkerController* documentMarkerController)
+ : m_documentMarkerController(documentMarkerController) {}
+
+bool DocumentMarkerList::endsBefore(size_t startOffset,
+ const Member<DocumentMarker>& rhv) {
+ return startOffset < rhv->endOffset();
+}
+
+bool DocumentMarkerList::compareByStart(const Member<DocumentMarker>& lhv,
+ const Member<DocumentMarker>& rhv) {
+ return lhv->startOffset() < rhv->startOffset();
+}
+
+DocumentMarkerList::ShiftMarkerResult
+DocumentMarkerList::getShiftedMarkerPosition(const DocumentMarker& marker,
+ unsigned offset,
+ unsigned oldLength,
+ unsigned newLength) {
+ ShiftMarkerResult result;
+ result.newStartOffset = marker.startOffset();
+ result.newEndOffset = marker.endOffset();
+ result.shouldRemoveMarker = false;
+
+ // 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)
+ result.newStartOffset = offset + newLength;
+ } else {
+ // Marker start was after the replaced text. Shift by length
+ // difference
+ result.newStartOffset = marker.startOffset() + 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
+ result.newEndOffset = offset;
+ } else {
+ // Marker end was after the replaced text. Shift by length difference
+ result.newEndOffset = marker.endOffset() + newLength - oldLength;
+ }
+ }
+
+ if (result.newStartOffset >= result.newEndOffset)
+ result.shouldRemoveMarker = true;
+
+ return result;
+}
+
+DEFINE_TRACE(DocumentMarkerList) {
+ visitor->trace(m_documentMarkerController);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698