Index: third_party/WebKit/Source/core/editing/SelectionEditor.h |
diff --git a/third_party/WebKit/Source/core/editing/SelectionEditor.h b/third_party/WebKit/Source/core/editing/SelectionEditor.h |
index eb4a2019db6f8b41196f83fd80f0fbad3a1de3eb..e2f7f6ea0a0c1fb20bfb3e609dbbe9dc20c89db0 100644 |
--- a/third_party/WebKit/Source/core/editing/SelectionEditor.h |
+++ b/third_party/WebKit/Source/core/editing/SelectionEditor.h |
@@ -27,7 +27,9 @@ |
#ifndef SelectionEditor_h |
#define SelectionEditor_h |
+#include "core/dom/SynchronousMutationObserver.h" |
#include "core/editing/FrameSelection.h" |
+#include "core/editing/SelectionTemplate.h" |
#include "core/events/EventDispatchResult.h" |
namespace blink { |
@@ -35,9 +37,10 @@ namespace blink { |
// TODO(yosin): We will rename |SelectionEditor| to appropriate name since |
// it is no longer have a changing selection functionality, it was moved to |
// |SelectionModifier| class. |
-class SelectionEditor final |
- : public GarbageCollectedFinalized<SelectionEditor> { |
+class SelectionEditor final : public GarbageCollectedFinalized<SelectionEditor>, |
+ public SynchronousMutationObserver { |
WTF_MAKE_NONCOPYABLE(SelectionEditor); |
+ USING_GARBAGE_COLLECTED_MIXIN(SelectionEditor); |
public: |
static SelectionEditor* create(LocalFrame& frame) { |
@@ -46,28 +49,19 @@ class SelectionEditor final |
virtual ~SelectionEditor(); |
void dispose(); |
- bool hasEditableStyle() const { return m_selection.hasEditableStyle(); } |
- bool isContentEditable() const { return m_selection.isContentEditable(); } |
- bool isContentRichlyEditable() const { |
- return m_selection.isContentRichlyEditable(); |
- } |
- |
- bool setSelectedRange(const EphemeralRange&, |
- TextAffinity, |
- SelectionDirectionalMode, |
- FrameSelection::SetSelectionOptions); |
+ bool hasEditableStyle() const; |
+ bool isContentEditable() const; |
+ bool isContentRichlyEditable() const; |
template <typename Strategy> |
const VisibleSelectionTemplate<Strategy>& visibleSelection() const; |
- void setVisibleSelection(const VisibleSelection&, |
- FrameSelection::SetSelectionOptions); |
- void setVisibleSelection(const VisibleSelectionInFlatTree&, |
- FrameSelection::SetSelectionOptions); |
+ const SelectionInDOMTree& selectionInDOMTree() const; |
- void setWithoutValidation(const Position& base, const Position& extent); |
+ const VisibleSelection& computeVisibleSelectionInDOMTree() const; |
+ const VisibleSelectionInFlatTree& computeVisibleSelectionInFlatTree() const; |
+ void setSelection(const SelectionInDOMTree&); |
void documentAttached(Document*); |
- void documentDetached(const Document&); |
// If this FrameSelection has a logical range which is still valid, this |
// function return its clone. Otherwise, the return value from underlying |
@@ -91,18 +85,38 @@ class SelectionEditor final |
private: |
explicit SelectionEditor(LocalFrame&); |
- const Document& document() const; |
+ Document& document() const; |
LocalFrame* frame() const { return m_frame.get(); } |
+ void assertSelectionValid() const; |
void clearVisibleSelection(); |
+ void markCacheDirty(); |
bool shouldAlwaysUseDirectionalSelection() const; |
- Member<Document> m_document; |
+ // VisibleSelection cache related |
+ bool needsUpdateVisibleSelection() const; |
+ void updateCachedVisibleSelectionIfNeeded() const; |
+ |
+ void didFinishTextChange(const Position& base, const Position& extent); |
+ void didFinishDOMMutation(); |
+ |
+ // Implementation of |SynchronousMutationObsderver| member functions. |
+ void contextDestroyed(Document*) final; |
+ void didChangeChildren(const ContainerNode&) final; |
+ void didMergeTextNodes(const Text& mergedNode, |
+ const NodeWithIndex& nodeToBeRemovedWithIndex, |
+ unsigned oldLength) final; |
+ void didSplitTextNode(const Text&) final; |
+ void didUpdateCharacterData(CharacterData*, |
+ unsigned offset, |
+ unsigned oldLength, |
+ unsigned newLength) final; |
+ void nodeChildrenWillBeRemoved(ContainerNode&) final; |
+ void nodeWillBeRemoved(Node&) final; |
+ |
Member<LocalFrame> m_frame; |
- VisibleSelection m_selection; |
- VisibleSelectionInFlatTree m_selectionInFlatTree; |
- bool m_observingVisibleSelection; |
+ SelectionInDOMTree m_selection; |
// TODO(editing-dev): Removing |m_logicalRange| |
// The range specified by the user, which may not be visually canonicalized |
@@ -110,9 +124,15 @@ class SelectionEditor final |
// |VisibleSelection| changes. If that happens, this variable will |
// become |nullptr|, in which case logical positions == visible positions. |
Member<Range> m_logicalRange; |
+ |
// If document is root, document.getSelection().addRange(range) is cached on |
// this. |
Member<Range> m_cachedRange; |
+ |
+ mutable VisibleSelection m_cachedVisibleSelectionInDOMTree; |
+ mutable VisibleSelectionInFlatTree m_cachedVisibleSelectionInFlatTree; |
+ mutable uint64_t m_styleVersion = static_cast<uint64_t>(-1); |
+ mutable bool m_cacheIsDirty = false; |
}; |
} // namespace blink |