| Index: third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerList.cpp
|
| diff --git a/third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerList.cpp b/third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerList.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..58342b4fe8de9e21c45e1ad81b694254e88dfc75
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/editing/markers/SpellCheckMarkerList.cpp
|
| @@ -0,0 +1,64 @@
|
| +// 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/SpellCheckMarkerList.h"
|
| +
|
| +#include <algorithm>
|
| +#include "core/dom/Text.h"
|
| +
|
| +namespace blink {
|
| +
|
| +SpellCheckMarkerList::SpellCheckMarkerList(
|
| + DocumentMarkerController* documentMarkerController,
|
| + DocumentMarker::MarkerType type)
|
| + : EditingMarkerList(documentMarkerController), m_type(type) {}
|
| +
|
| +static bool doesNotOverlap(const Member<DocumentMarker>& lhv,
|
| + const DocumentMarker* rhv) {
|
| + return lhv->endOffset() < rhv->startOffset();
|
| +}
|
| +
|
| +DocumentMarker::MarkerType SpellCheckMarkerList::allowedMarkerType() const {
|
| + return m_type;
|
| +}
|
| +
|
| +void SpellCheckMarkerList::insert(DocumentMarker* marker) {
|
| + if (!m_markersAreSorted)
|
| + sortMarkerList();
|
| +
|
| + auto firstOverlappingIt = std::lower_bound(m_markers.begin(), m_markers.end(),
|
| + marker, doesNotOverlap);
|
| + size_t index = firstOverlappingIt - m_markers.begin();
|
| + m_markers.insert(index, marker);
|
| + auto insertedIt = m_markers.begin() + index;
|
| + for (auto it = insertedIt + 1;
|
| + it != m_markers.end() &&
|
| + (*it)->startOffset() <= (*insertedIt)->endOffset();) {
|
| + (*insertedIt)
|
| + ->setStartOffset(
|
| + std::min((*insertedIt)->startOffset(), (*it)->startOffset()));
|
| + (*insertedIt)
|
| + ->setEndOffset(
|
| + std::max((*insertedIt)->endOffset(), (*it)->endOffset()));
|
| + m_markers.remove(it - m_markers.begin());
|
| + }
|
| +}
|
| +
|
| +void SpellCheckMarkerList::removeMarkersForWords(const Text& textNode,
|
| + const Vector<String>& words) {
|
| + // Build a second vector and swap with m_markers to avoid O(n^2) performance
|
| + 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
|
|
|