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

Side by Side Diff: third_party/WebKit/Source/core/editing/SelectionEditor.h

Issue 1958093002: CONTINUED Make FrameSelection to hold non-canonicalized positions Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017-01-16T20:04:35 Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #ifndef SelectionEditor_h 27 #ifndef SelectionEditor_h
28 #define SelectionEditor_h 28 #define SelectionEditor_h
29 29
30 #include "core/dom/SynchronousMutationObserver.h"
30 #include "core/editing/FrameSelection.h" 31 #include "core/editing/FrameSelection.h"
32 #include "core/editing/SelectionTemplate.h"
31 #include "core/events/EventDispatchResult.h" 33 #include "core/events/EventDispatchResult.h"
32 34
33 namespace blink { 35 namespace blink {
34 36
35 // TODO(yosin): We will rename |SelectionEditor| to appropriate name since 37 // TODO(yosin): We will rename |SelectionEditor| to appropriate name since
36 // it is no longer have a changing selection functionality, it was moved to 38 // it is no longer have a changing selection functionality, it was moved to
37 // |SelectionModifier| class. 39 // |SelectionModifier| class.
38 class SelectionEditor final 40 class SelectionEditor final : public GarbageCollectedFinalized<SelectionEditor>,
39 : public GarbageCollectedFinalized<SelectionEditor> { 41 public SynchronousMutationObserver {
40 WTF_MAKE_NONCOPYABLE(SelectionEditor); 42 WTF_MAKE_NONCOPYABLE(SelectionEditor);
43 USING_GARBAGE_COLLECTED_MIXIN(SelectionEditor);
41 44
42 public: 45 public:
43 static SelectionEditor* create(LocalFrame& frame) { 46 static SelectionEditor* create(LocalFrame& frame) {
44 return new SelectionEditor(frame); 47 return new SelectionEditor(frame);
45 } 48 }
49
50 // Public for printer.
51 enum class CacheState;
52
46 virtual ~SelectionEditor(); 53 virtual ~SelectionEditor();
47 void dispose(); 54 void dispose();
48 55
49 bool hasEditableStyle() const { return m_selection.hasEditableStyle(); } 56 const SelectionInDOMTree& selectionInDOMTree() const;
50 bool isContentEditable() const { return m_selection.isContentEditable(); }
51 bool isContentRichlyEditable() const {
52 return m_selection.isContentRichlyEditable();
53 }
54 57
55 bool setSelectedRange(const EphemeralRange&, 58 bool hasEditableStyle() const;
56 TextAffinity, 59 bool isContentEditable() const;
57 SelectionDirectionalMode, 60 bool isContentRichlyEditable() const;
58 FrameSelection::SetSelectionOptions);
59 61
60 template <typename Strategy> 62 const VisibleSelection& computeVisibleSelectionInDOMTree() const;
61 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; 63 const VisibleSelectionInFlatTree& computeVisibleSelectionInFlatTree() const;
62 void setVisibleSelection(const VisibleSelection&, 64 void setSelection(const SelectionInDOMTree&);
63 FrameSelection::SetSelectionOptions);
64 void setVisibleSelection(const VisibleSelectionInFlatTree&,
65 FrameSelection::SetSelectionOptions);
66
67 void setWithoutValidation(const Position& base, const Position& extent);
68 65
69 void documentAttached(Document*); 66 void documentAttached(Document*);
70 void documentDetached(const Document&);
71 67
72 // If this FrameSelection has a logical range which is still valid, this 68 // If this FrameSelection has a logical range which is still valid, this
73 // function return its clone. Otherwise, the return value from underlying 69 // function return its clone. Otherwise, the return value from underlying
74 // |VisibleSelection|'s |firstRange()| is returned. 70 // |VisibleSelection|'s |firstRange()| is returned.
75 Range* firstRange() const; 71 Range* firstRange() const;
76 72
77 // There functions are exposed for |FrameSelection|. 73 // There functions are exposed for |FrameSelection|.
78 void resetLogicalRange(); 74 void resetLogicalRange();
79 void setLogicalRange(Range*); 75 void setLogicalRange(Range*);
80 76
81 // Updates |m_selection| and |m_selectionInFlatTree| with up-to-date 77 // Updates |m_selection| and |m_selectionInFlatTree| with up-to-date
82 // layout if needed. 78 // layout if needed.
83 void updateIfNeeded(); 79 void updateIfNeeded();
84 80
85 DECLARE_TRACE(); 81 DECLARE_TRACE();
86 82
87 private: 83 private:
84 class CacheUpdateScope;
85
88 explicit SelectionEditor(LocalFrame&); 86 explicit SelectionEditor(LocalFrame&);
89 87
90 const Document& document() const; 88 Document& document() const;
91 LocalFrame* frame() const { return m_frame.get(); } 89 LocalFrame* frame() const { return m_frame.get(); }
92 90
93 void clearVisibleSelection(); 91 void clearVisibleSelection();
94 bool shouldAlwaysUseDirectionalSelection() const; 92 bool shouldAlwaysUseDirectionalSelection() const;
95 93
96 Member<Document> m_document; 94 // VisibleSelection cache related
95 bool needsUpdateVisibleSelection() const;
96 void updateCachedVisibleSelectionIfNeeded();
97
98 void didFinishTextChange(const Position& base, const Position& extent);
99 void didFinishDOMMutation();
100
101 // Implementation of |SynchronousMutationObsderver| member functions.
102 void contextDestroyed(Document*) final;
103 void didChangeAttribute(const Element&) final;
104 void didChangeChildren(const ContainerNode&) final;
105 void didMergeTextNodes(const Text& mergedNode,
106 const NodeWithIndex& nodeToBeRemovedWithIndex,
107 unsigned oldLength) final;
108 void didMoveTreeToNewDocument() final;
109 void didSplitTextNode(const Text&) final;
110 void didUpdateCharacterData(CharacterData*,
111 unsigned offset,
112 unsigned oldLength,
113 unsigned newLength) final;
114 void nodeChildrenWillBeRemoved(ContainerNode&) final;
115 void nodeWillBeRemoved(Node&) final;
116
97 Member<LocalFrame> m_frame; 117 Member<LocalFrame> m_frame;
98 118
99 VisibleSelection m_selection; 119 SelectionInDOMTree m_selection;
100 VisibleSelectionInFlatTree m_selectionInFlatTree;
101 bool m_observingVisibleSelection;
102 120
103 // The range specified by the user, which may not be visually canonicalized 121 // The range specified by the user, which may not be visually canonicalized
104 // (hence "logical"). This will be invalidated if the underlying 122 // (hence "logical"). This will be invalidated if the underlying
105 // |VisibleSelection| changes. If that happens, this variable will 123 // |VisibleSelection| changes. If that happens, this variable will
106 // become |nullptr|, in which case logical positions == visible positions. 124 // become |nullptr|, in which case logical positions == visible positions.
107 Member<Range> m_logicalRange; 125 Member<Range> m_logicalRange;
126
127 mutable CacheState m_cacheState;
128 mutable bool m_isUpdatingCachedSelection = false;
129 mutable VisibleSelection m_cachedVisibleSelectionInDOMTree;
130 mutable VisibleSelectionInFlatTree m_cachedVisibleSelectionInFlatTree;
131 mutable uint64_t m_domTreeVersion = 0;
132 mutable uint64_t m_styleVersion = static_cast<uint64_t>(-1);
108 }; 133 };
109 134
110 } // namespace blink 135 } // namespace blink
111 136
112 #endif // SelectionEditor_h 137 #endif // SelectionEditor_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698