Commit c84b714f authored by rlanday's avatar rlanday Committed by Commit bot

Add DocumentMarkerList interface and GenericDocumentMarkerListImpl

Based on step 3 of yosin's plan:
https://codereview.chromium.org/2812423002#msg7

This CL does the following:

- Introduces a DocumentMarkerList interface

- Introduces GenericDocumentMarkerListImpl, an implementation
  of DocumentMarkerList that works for all marker types and is implemented on top
  of DocumentMarkerListEditor

- Refactors DocumentMarkerController to use GenericDocumentMarkerListImpl instead
  of using DocumentMarkerListEditor directly

BUG=707867

Review-Url: https://codereview.chromium.org/2820633002
Cr-Commit-Position: refs/heads/master@{#467549}
parent c1063580
......@@ -193,8 +193,12 @@ blink_core_sources("editing") {
"markers/DocumentMarker.h",
"markers/DocumentMarkerController.cpp",
"markers/DocumentMarkerController.h",
"markers/DocumentMarkerList.cpp",
"markers/DocumentMarkerList.h",
"markers/DocumentMarkerListEditor.cpp",
"markers/DocumentMarkerListEditor.h",
"markers/GenericDocumentMarkerListImpl.cpp",
"markers/GenericDocumentMarkerListImpl.h",
"markers/RenderedDocumentMarker.h",
"serializers/HTMLInterchange.cpp",
"serializers/HTMLInterchange.h",
......
......@@ -40,6 +40,7 @@
namespace blink {
class DocumentMarkerList;
class Node;
class RenderedDocumentMarker;
......@@ -111,12 +112,11 @@ class CORE_EXPORT DocumentMarkerController final
private:
void AddMarker(Node*, DocumentMarker*);
using MarkerList = HeapVector<Member<RenderedDocumentMarker>>;
using MarkerLists =
HeapVector<Member<MarkerList>, DocumentMarker::kMarkerTypeIndexesCount>;
using MarkerLists = HeapVector<Member<DocumentMarkerList>,
DocumentMarker::kMarkerTypeIndexesCount>;
using MarkerMap = HeapHashMap<WeakMember<const Node>, Member<MarkerLists>>;
static Member<MarkerList>& ListForType(MarkerLists*,
DocumentMarker::MarkerType);
static Member<DocumentMarkerList>& ListForType(MarkerLists*,
DocumentMarker::MarkerType);
bool PossiblyHasMarkers(DocumentMarker::MarkerTypes);
void RemoveMarkersFromList(MarkerMap::iterator, DocumentMarker::MarkerTypes);
void RemoveMarkers(TextIterator&, DocumentMarker::MarkerTypes);
......
// 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"
namespace blink {
DocumentMarkerList::DocumentMarkerList() = default;
DocumentMarkerList::~DocumentMarkerList() = default;
} // namespace blink
// 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.
#ifndef DocumentMarkerList_h
#define DocumentMarkerList_h
#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
namespace blink {
class DocumentMarker;
class RenderedDocumentMarker;
// This is an interface implemented by classes that DocumentMarkerController
// uses to store DocumentMarkers. Different implementations can be written
// to handle different MarkerTypes (e.g. to provide more optimized handling of
// MarkerTypes with different insertion/retrieval patterns, or to provide
// different behavior for certain MarkerTypes).
class CORE_EXPORT DocumentMarkerList
: public GarbageCollectedFinalized<DocumentMarkerList> {
public:
virtual ~DocumentMarkerList();
virtual bool IsEmpty() const = 0;
virtual void Add(DocumentMarker*) = 0;
virtual void Clear() = 0;
virtual const HeapVector<Member<RenderedDocumentMarker>>& GetMarkers()
const = 0;
// Returns true if at least one marker is copied, false otherwise
virtual bool MoveMarkers(int length, DocumentMarkerList* dst_list) = 0;
// Returns true if at least one marker is removed, false otherwise
virtual bool RemoveMarkers(unsigned start_offset, int length) = 0;
// Returns true if a marker was removed, false otherwise.
// TODO(rlanday): remove this method from this interface once we have a
// Spelling/Grammar-specific marker list impl to put this on
virtual bool RemoveMarkersUnderWords(const String& node_text,
const Vector<String>& words) = 0;
// Returns true if at least one marker is shifted or removed, false otherwise
virtual bool ShiftMarkers(unsigned offset,
unsigned old_length,
unsigned new_length) = 0;
DEFINE_INLINE_VIRTUAL_TRACE() {}
protected:
DocumentMarkerList();
private:
DISALLOW_COPY_AND_ASSIGN(DocumentMarkerList);
};
} // namespace blink
#endif // DocumentMarkerList_h
......@@ -35,7 +35,7 @@ void DocumentMarkerListEditor::AddMarker(MarkerList* list,
bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list,
int length,
MarkerList* dst_list) {
DocumentMarkerList* dst_list) {
DCHECK_GT(length, 0);
bool didMoveMarker = false;
unsigned end_offset = length - 1;
......@@ -50,7 +50,7 @@ bool DocumentMarkerListEditor::MoveMarkers(MarkerList* src_list,
if (marker.EndOffset() > end_offset)
marker.SetEndOffset(end_offset);
DocumentMarkerListEditor::AddMarker(dst_list, &marker);
dst_list->Add(&marker);
didMoveMarker = true;
}
......
......@@ -5,6 +5,7 @@
#ifndef DocumentMarkerListEditor_h
#define DocumentMarkerListEditor_h
#include "core/editing/markers/DocumentMarkerList.h"
#include "platform/heap/Handle.h"
namespace blink {
......@@ -21,7 +22,7 @@ class DocumentMarkerListEditor {
// Returns true if a marker was moved, false otherwise.
static bool MoveMarkers(MarkerList* src_list,
int length,
MarkerList* dst_list);
DocumentMarkerList* dst_list);
// Returns true if a marker was removed, false otherwise.
static bool RemoveMarkers(MarkerList*, unsigned start_offset, int length);
......
// 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/GenericDocumentMarkerListImpl.h"
#include "core/editing/markers/DocumentMarkerListEditor.h"
#include "core/editing/markers/RenderedDocumentMarker.h"
namespace blink {
bool GenericDocumentMarkerListImpl::IsEmpty() const {
return markers_.IsEmpty();
}
void GenericDocumentMarkerListImpl::Add(DocumentMarker* marker) {
DocumentMarkerListEditor::AddMarker(&markers_, marker);
}
void GenericDocumentMarkerListImpl::Clear() {
markers_.clear();
}
const HeapVector<Member<RenderedDocumentMarker>>&
GenericDocumentMarkerListImpl::GetMarkers() const {
return markers_;
}
bool GenericDocumentMarkerListImpl::MoveMarkers(int length,
DocumentMarkerList* dst_list) {
return DocumentMarkerListEditor::MoveMarkers(&markers_, length, dst_list);
}
bool GenericDocumentMarkerListImpl::RemoveMarkers(unsigned start_offset,
int length) {
return DocumentMarkerListEditor::RemoveMarkers(&markers_, start_offset,
length);
}
bool GenericDocumentMarkerListImpl::RemoveMarkersUnderWords(
const String& node_text,
const Vector<String>& words) {
return DocumentMarkerListEditor::RemoveMarkersUnderWords(&markers_, node_text,
words);
}
bool GenericDocumentMarkerListImpl::ShiftMarkers(unsigned offset,
unsigned old_length,
unsigned new_length) {
return DocumentMarkerListEditor::ShiftMarkers(&markers_, offset, old_length,
new_length);
}
DEFINE_TRACE(GenericDocumentMarkerListImpl) {
visitor->Trace(markers_);
DocumentMarkerList::Trace(visitor);
}
} // namespace blink
// 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.
#ifndef GenericDocumentMarkerListImpl_h
#define GenericDocumentMarkerListImpl_h
#include "core/editing/markers/DocumentMarkerList.h"
namespace blink {
class RenderedDocumentMarker;
// Temporary implementation of DocumentMarkerList that can handle
// DocumentMarkers of all MarkerTypes. This will be removed once we have
// specialized implementations for every MarkerType.
class GenericDocumentMarkerListImpl final : public DocumentMarkerList {
public:
GenericDocumentMarkerListImpl() = default;
// DocumentMarkerList implementations
bool IsEmpty() const final;
void Add(DocumentMarker*) final;
void Clear() final;
const HeapVector<Member<RenderedDocumentMarker>>& GetMarkers() const final;
bool MoveMarkers(int length, DocumentMarkerList* dst_list) final;
bool RemoveMarkers(unsigned start_offset, int length) final;
bool RemoveMarkersUnderWords(const String& node_text,
const Vector<String>& words) final;
bool ShiftMarkers(unsigned offset,
unsigned old_length,
unsigned new_length) final;
DECLARE_TRACE();
private:
HeapVector<Member<RenderedDocumentMarker>> markers_;
DISALLOW_COPY_AND_ASSIGN(GenericDocumentMarkerListImpl);
};
} // namespace blink
#endif // GenericDocumentMarkerListImpl_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment