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

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

Issue 2723663002: Refactor DocumentMarkerController (Closed)
Patch Set: 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
Index: third_party/WebKit/Source/core/editing/markers/SpellingMarkerList.cpp
diff --git a/third_party/WebKit/Source/core/editing/markers/SpellingMarkerList.cpp b/third_party/WebKit/Source/core/editing/markers/SpellingMarkerList.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..20744a880562b542e4888b9ae433f7d605c0c70b
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/markers/SpellingMarkerList.cpp
@@ -0,0 +1,37 @@
+// 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/SpellingMarkerList.h"
+
+#include <utility>
+#include "core/dom/Text.h"
+
+namespace blink {
+
+SpellingMarkerList::SpellingMarkerList(
+ DocumentMarkerController* documentMarkerController)
+ : EditingMarkerListThatMergesTouchingMarkers(documentMarkerController) {}
+
+DocumentMarker::MarkerType SpellingMarkerList::allowedMarkerType() const {
+ return DocumentMarker::Spelling;
+}
+
+void SpellingMarkerList::removeMarkersForWords(const Text& textNode,
+ const Vector<String>& words) {
+ // Build a second vector and swap with m_markers to avoid O(n^2) performance
Xiaocheng 2017/03/01 22:24:48 Nice!
+ HeapVector<Member<DocumentMarker>> newMarkerList;
+
+ for (Member<DocumentMarker> marker : m_markers) {
+ unsigned start = marker->startOffset();
+ unsigned length = marker->endOffset() - marker->startOffset();
+
+ String markerText = textNode.data().substring(start, length);
+ if (!words.contains(markerText))
+ newMarkerList.push_back(marker);
+ }
+
+ std::swap(m_markers, newMarkerList);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698