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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.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
(...skipping 11 matching lines...) Expand all
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 FrameSelection_h 27 #ifndef FrameSelection_h
28 #define FrameSelection_h 28 #define FrameSelection_h
29 29
30 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
31 #include "core/dom/Range.h" 31 #include "core/dom/Range.h"
32 #include "core/dom/SynchronousMutationObserver.h"
32 #include "core/editing/EditingStyle.h" 33 #include "core/editing/EditingStyle.h"
33 #include "core/editing/EphemeralRange.h" 34 #include "core/editing/EphemeralRange.h"
35 #include "core/editing/SelectionTemplate.h"
34 #include "core/editing/VisiblePosition.h" 36 #include "core/editing/VisiblePosition.h"
35 #include "core/editing/VisibleSelection.h" 37 #include "core/editing/VisibleSelection.h"
36 #include "core/editing/iterators/TextIteratorFlags.h" 38 #include "core/editing/iterators/TextIteratorFlags.h"
37 #include "core/layout/ScrollAlignment.h" 39 #include "core/layout/ScrollAlignment.h"
38 #include "platform/Timer.h" 40 #include "platform/Timer.h"
39 #include "platform/geometry/IntRect.h" 41 #include "platform/geometry/IntRect.h"
40 #include "platform/geometry/LayoutRect.h" 42 #include "platform/geometry/LayoutRect.h"
41 #include "platform/heap/Handle.h" 43 #include "platform/heap/Handle.h"
42 #include "wtf/Noncopyable.h" 44 #include "wtf/Noncopyable.h"
43 #include <memory> 45 #include <memory>
44 46
45 namespace blink { 47 namespace blink {
46 48
47 class CharacterData;
48 class DisplayItemClient; 49 class DisplayItemClient;
49 class LayoutBlock; 50 class LayoutBlock;
50 class LocalFrame; 51 class LocalFrame;
51 class FrameCaret; 52 class FrameCaret;
52 class GranularityStrategy; 53 class GranularityStrategy;
53 class GraphicsContext; 54 class GraphicsContext;
54 class HTMLFormElement; 55 class HTMLFormElement;
55 class SelectionEditor; 56 class SelectionEditor;
56 class PendingSelection; 57 class PendingSelection;
57 class Text;
58 58
59 enum class CursorAlignOnScroll { IfNeeded, Always }; 59 enum class CursorAlignOnScroll { IfNeeded, Always };
60 60
61 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; 61 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 };
62 62
63 enum RevealExtentOption { RevealExtent, DoNotRevealExtent }; 63 enum RevealExtentOption { RevealExtent, DoNotRevealExtent };
64 64
65 enum class SelectionDirectionalMode { NonDirectional, Directional }; 65 enum class SelectionDirectionalMode { NonDirectional, Directional };
66 66
67 enum class CaretVisibility; 67 enum class CaretVisibility;
68 68
69 class CORE_EXPORT FrameSelection final 69 class CORE_EXPORT FrameSelection final
70 : public GarbageCollectedFinalized<FrameSelection> { 70 : public GarbageCollectedFinalized<FrameSelection>,
71 public SynchronousMutationObserver {
71 WTF_MAKE_NONCOPYABLE(FrameSelection); 72 WTF_MAKE_NONCOPYABLE(FrameSelection);
73 USING_GARBAGE_COLLECTED_MIXIN(FrameSelection);
72 74
73 public: 75 public:
74 static FrameSelection* create(LocalFrame& frame) { 76 static FrameSelection* create(LocalFrame&);
75 return new FrameSelection(frame);
76 }
77 ~FrameSelection(); 77 ~FrameSelection();
78 78
79 enum EAlteration { AlterationMove, AlterationExtend }; 79 enum EAlteration { AlterationMove, AlterationExtend };
80 enum SetSelectionOption { 80 enum SetSelectionOption {
81 // 1 << 0 is reserved for EUserTriggered 81 // 1 << 0 is reserved for EUserTriggered
82 CloseTyping = 1 << 1, 82 CloseTyping = 1 << 1,
83 ClearTypingStyle = 1 << 2, 83 ClearTypingStyle = 1 << 2,
84 DoNotSetFocus = 1 << 3, 84 DoNotSetFocus = 1 << 3,
85 DoNotUpdateAppearance = 1 << 4, 85 DoNotUpdateAppearance = 1 << 4,
86 DoNotClearStrategy = 1 << 5, 86 DoNotClearStrategy = 1 << 5,
87 // TODO(yosin): We should get rid of |DoNotAdjustInFlatTree|.
87 DoNotAdjustInFlatTree = 1 << 6, 88 DoNotAdjustInFlatTree = 1 << 6,
88 }; 89 };
89 // Union of values in SetSelectionOption and EUserTriggered 90 // Union of values in SetSelectionOption and EUserTriggered
90 typedef unsigned SetSelectionOptions; 91 typedef unsigned SetSelectionOptions;
91 static inline EUserTriggered selectionOptionsToUserTriggered( 92 static inline EUserTriggered selectionOptionsToUserTriggered(
92 SetSelectionOptions options) { 93 SetSelectionOptions options) {
93 return static_cast<EUserTriggered>(options & UserTriggered); 94 return static_cast<EUserTriggered>(options & UserTriggered);
94 } 95 }
95 96
96 bool isAvailable() const { return m_document; } 97 bool isAvailable() const { return lifecycleContext(); }
97 // You should not call |document()| when |!isAvailable()|. 98 Document& document() const;
98 const Document& document() const;
99 Document& document();
100 LocalFrame* frame() const { return m_frame; } 99 LocalFrame* frame() const { return m_frame; }
101 Element* rootEditableElement() const { 100 Element* rootEditableElement() const {
102 return selection().rootEditableElement(); 101 return selection().rootEditableElement();
103 } 102 }
104 Element* rootEditableElementOrDocumentElement() const; 103 Element* rootEditableElementOrDocumentElement() const;
105 ContainerNode* rootEditableElementOrTreeScopeRootNode() const; 104 ContainerNode* rootEditableElementOrTreeScopeRootNode() const;
106 105
107 bool hasEditableStyle() const { return selection().hasEditableStyle(); } 106 bool hasEditableStyle() const { return selection().hasEditableStyle(); }
108 bool isContentEditable() const { return selection().isContentEditable(); } 107 bool isContentEditable() const { return selection().isContentEditable(); }
109 bool isContentRichlyEditable() const { 108 bool isContentRichlyEditable() const {
110 return selection().isContentRichlyEditable(); 109 return selection().isContentRichlyEditable();
111 } 110 }
112 111
113 // An implementation of |WebFrame::moveCaretSelection()| 112 // An implementation of |WebFrame::moveCaretSelection()|
114 void moveCaretSelection(const IntPoint&); 113 void moveCaretSelection(const IntPoint&);
115 114
116 template <typename Strategy> 115 const VisibleSelection& computeVisibleSelectionInDOMTree() const;
117 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; 116 const VisibleSelectionInFlatTree& computeVisibleSelectionInFlatTree() const;
118 117
119 const VisibleSelection& selection() const; 118 const VisibleSelection& selection() const;
120 119
121 void setSelection(const SelectionInDOMTree&, 120 void setSelection(const SelectionInDOMTree&,
122 SetSelectionOptions = CloseTyping | ClearTypingStyle, 121 SetSelectionOptions = CloseTyping | ClearTypingStyle,
123 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded, 122 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded,
124 TextGranularity = CharacterGranularity); 123 TextGranularity = CharacterGranularity);
125 124
126 void setSelection(const SelectionInFlatTree&, 125 void setSelection(const SelectionInFlatTree&,
127 SetSelectionOptions = CloseTyping | ClearTypingStyle, 126 SetSelectionOptions = CloseTyping | ClearTypingStyle,
128 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded, 127 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded,
129 TextGranularity = CharacterGranularity); 128 TextGranularity = CharacterGranularity);
130 129
131 // TODO(yosin): We should use |SelectionInDOMTree| version instead of 130 // TODO(yosin): Get rid of |granularity| parameter from |setSelection()|.
132 // |VisibleSelection| version.
133 void setSelection(const VisibleSelection&, 131 void setSelection(const VisibleSelection&,
134 SetSelectionOptions = CloseTyping | ClearTypingStyle, 132 SetSelectionOptions = CloseTyping | ClearTypingStyle,
135 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded, 133 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded,
136 TextGranularity = CharacterGranularity); 134 TextGranularity = CharacterGranularity);
137 // TODO(yosin): We should use |SelectionInFlatTree| version instead of
138 // |VisibleSelectionInFlatTree| version.
139 void setSelection(const VisibleSelectionInFlatTree&, 135 void setSelection(const VisibleSelectionInFlatTree&,
140 SetSelectionOptions = CloseTyping | ClearTypingStyle, 136 SetSelectionOptions = CloseTyping | ClearTypingStyle,
141 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded, 137 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded,
142 TextGranularity = CharacterGranularity); 138 TextGranularity = CharacterGranularity);
139 // TODO(yosin) We should get rid of |Range| version of |setSelectedRagne()|
140 // for Oilpan.
141 bool setSelectedRange(
142 Range*,
143 TextAffinity,
144 SelectionDirectionalMode = SelectionDirectionalMode::NonDirectional,
145 SetSelectionOptions = CloseTyping | ClearTypingStyle);
143 bool setSelectedRange( 146 bool setSelectedRange(
144 const EphemeralRange&, 147 const EphemeralRange&,
145 TextAffinity, 148 TextAffinity,
146 SelectionDirectionalMode = SelectionDirectionalMode::NonDirectional, 149 SelectionDirectionalMode = SelectionDirectionalMode::NonDirectional,
147 FrameSelection::SetSelectionOptions = CloseTyping | ClearTypingStyle); 150 FrameSelection::SetSelectionOptions = CloseTyping | ClearTypingStyle);
148 void selectAll(); 151 void selectAll();
149 void clear(); 152 void clear();
150 153
151 // Call this after doing user-triggered selections to make it easy to delete 154 // Call this after doing user-triggered selections to make it easy to delete
152 // the frame you entirely selected. 155 // the frame you entirely selected.
(...skipping 16 matching lines...) Expand all
169 172
170 // Moves the selection extent based on the selection granularity strategy. 173 // Moves the selection extent based on the selection granularity strategy.
171 // This function does not allow the selection to collapse. If the new 174 // This function does not allow the selection to collapse. If the new
172 // extent is resolved to the same position as the current base, this 175 // extent is resolved to the same position as the current base, this
173 // function will do nothing. 176 // function will do nothing.
174 void moveRangeSelectionExtent(const IntPoint&); 177 void moveRangeSelectionExtent(const IntPoint&);
175 void moveRangeSelection(const VisiblePosition& base, 178 void moveRangeSelection(const VisiblePosition& base,
176 const VisiblePosition& extent, 179 const VisiblePosition& extent,
177 TextGranularity); 180 TextGranularity);
178 181
182 // TODO(yosin): We should use |selection().granularity()|.
179 TextGranularity granularity() const { return m_granularity; } 183 TextGranularity granularity() const { return m_granularity; }
180 184
181 Position base() const { return selection().base(); } 185 Position base() const { return selection().base(); }
182 Position extent() const { return selection().extent(); } 186 Position extent() const { return selection().extent(); }
183 Position start() const { return selection().start(); } 187 Position start() const { return selection().start(); }
184 Position end() const { return selection().end(); } 188 Position end() const { return selection().end(); }
185 189
186 // Return the layoutObject that is responsible for painting the caret (in the 190 // Return the layoutObject that is responsible for painting the caret (in the
187 // selection start node) 191 // selection start node)
188 LayoutBlock* caretLayoutObject() const; 192 LayoutBlock* caretLayoutObject() const;
189 193
190 // Bounds of (possibly transformed) caret in absolute coords 194 // Bounds of (possibly transformed) caret in absolute coords
191 IntRect absoluteCaretBounds(); 195 IntRect absoluteCaretBounds();
192 196
193 void didChangeFocus(); 197 void didChangeFocus();
194 198
199 const SelectionInDOMTree& selectionInDOMTree() const;
200 // TODO(yosin): We should rename |isNone()| to |isVisibleNone()|.
195 bool isNone() const { return selection().isNone(); } 201 bool isNone() const { return selection().isNone(); }
196 bool isCaret() const { return selection().isCaret(); } 202 bool isCaret() const { return selection().isCaret(); }
197 bool isRange() const { return selection().isRange(); } 203 bool isRange() const { return selection().isRange(); }
198 bool isInPasswordField() const; 204 bool isInPasswordField() const;
199 bool isDirectional() const { return selection().isDirectional(); } 205 bool isDirectional() const { return selectionInDOMTree().isDirectional(); }
200 206
201 // If this FrameSelection has a logical range which is still valid, this 207 // If this FrameSelection has a logical range which is still valid, this
202 // function return its clone. Otherwise, the return value from underlying 208 // function return its clone. Otherwise, the return value from underlying
203 // VisibleSelection's firstRange() is returned. 209 // VisibleSelection's firstRange() is returned.
204 Range* firstRange() const; 210 Range* firstRange() const;
205 211
212 // Called after layout finished.
213 void didLayout();
214
206 void documentAttached(Document*); 215 void documentAttached(Document*);
207 void documentDetached(const Document&);
208 void nodeChildrenWillBeRemoved(ContainerNode&);
209 void nodeWillBeRemoved(Node&);
210 void dataWillChange(const CharacterData& node);
211 void didUpdateCharacterData(CharacterData*,
212 unsigned offset,
213 unsigned oldLength,
214 unsigned newLength);
215 void didMergeTextNodes(const Text& oldNode, unsigned offset);
216 void didSplitTextNode(const Text& oldNode);
217 216
218 bool isAppearanceDirty() const; 217 bool isAppearanceDirty() const;
219 void commitAppearanceIfNeeded(LayoutView&); 218 void commitAppearanceIfNeeded(LayoutView&);
220 void updateAppearance(); 219 void updateAppearance();
221 void setCaretVisible(bool caretIsVisible); 220 void setCaretVisible(bool caretIsVisible);
222 bool isCaretBoundsDirty() const; 221 bool isCaretBoundsDirty() const;
223 void setCaretRectNeedsUpdate(); 222 void setCaretRectNeedsUpdate();
224 void scheduleVisualUpdate() const; 223 void scheduleVisualUpdate() const;
225 void invalidateCaretRect(bool forceInvalidation = false); 224 void invalidateCaretRect(bool forceInvalidation = false);
226 void paintCaret(GraphicsContext&, const LayoutPoint&); 225 void paintCaret(GraphicsContext&, const LayoutPoint&);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 // |FrameSelection::selection()| to make sure we use updated selection, 275 // |FrameSelection::selection()| to make sure we use updated selection,
277 // rather than having |updateIfNeeded()|. Once, we update all layout tests 276 // rather than having |updateIfNeeded()|. Once, we update all layout tests
278 // to use updated selection, we should make |updateIfNeeded()| private. 277 // to use updated selection, we should make |updateIfNeeded()| private.
279 void updateIfNeeded(); 278 void updateIfNeeded();
280 279
281 DECLARE_TRACE(); 280 DECLARE_TRACE();
282 281
283 private: 282 private:
284 friend class FrameSelectionTest; 283 friend class FrameSelectionTest;
285 friend class PaintControllerPaintTestForSlimmingPaintV1AndV2; 284 friend class PaintControllerPaintTestForSlimmingPaintV1AndV2;
286 friend class SelectionControllerTest;
287 FRIEND_TEST_ALL_PREFIXES(PaintControllerPaintTestForSlimmingPaintV1AndV2, 285 FRIEND_TEST_ALL_PREFIXES(PaintControllerPaintTestForSlimmingPaintV1AndV2,
288 FullDocumentPaintingWithCaret); 286 FullDocumentPaintingWithCaret);
289 287
290 explicit FrameSelection(LocalFrame&); 288 explicit FrameSelection(LocalFrame&);
291 289
292 // For |PaintControllerPaintTestForSlimmingPaintV1AndV2|. 290 // For |PaintControllerPaintTestForSlimmingPaintV1AndV2|.
293 const DisplayItemClient& caretDisplayItemClientForTesting() const; 291 const DisplayItemClient& caretDisplayItemClientForTesting() const;
294 292
295 // Note: We have |selectionInFlatTree()| for unit tests, we should
296 // use |visibleSelection<EditingInFlatTreeStrategy>()|.
297 const VisibleSelectionInFlatTree& selectionInFlatTree() const;
298
299 template <typename Strategy>
300 void setSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>&,
301 SetSelectionOptions,
302 CursorAlignOnScroll,
303 TextGranularity);
304
305 void respondToNodeModification(Node&, 293 void respondToNodeModification(Node&,
306 bool baseRemoved, 294 bool baseRemoved,
307 bool extentRemoved, 295 bool extentRemoved,
308 bool startRemoved, 296 bool startRemoved,
309 bool endRemoved); 297 bool endRemoved);
310 298
311 void notifyAccessibilityForSelectionChange(); 299 void notifyAccessibilityForSelectionChange();
312 void notifyCompositorForSelectionChange(); 300 void notifyCompositorForSelectionChange();
313 void notifyEventHandlerForSelectionChange(); 301 void notifyEventHandlerForSelectionChange();
314 302
315 void focusedOrActiveStateChanged(); 303 void focusedOrActiveStateChanged();
316 304
317 void setUseSecureKeyboardEntry(bool); 305 void setUseSecureKeyboardEntry(bool);
318 306
319 void updateSelectionIfNeeded(const Position& base, 307 void updateSelectionIfNeeded(const Position& base,
320 const Position& extent, 308 const Position& extent,
321 const Position& start, 309 const Position& start,
322 const Position& end); 310 const Position& end);
323 311
312 template <typename Strategy>
313 VisibleSelectionTemplate<Strategy> validateSelection(
314 const VisibleSelectionTemplate<Strategy>&);
315
324 GranularityStrategy* granularityStrategy(); 316 GranularityStrategy* granularityStrategy();
325 317
318 // Implementation of |SynchronousMutationObserver| member functions.
319 void contextDestroyed(Document*) final;
320 void nodeChildrenWillBeRemoved(ContainerNode&) final;
321 void nodeWillBeRemoved(Node&) final;
322
326 // For unittests 323 // For unittests
327 bool shouldPaintCaretForTesting() const; 324 bool shouldPaintCaretForTesting() const;
328 bool isPreviousCaretDirtyForTesting() const; 325 bool isPreviousCaretDirtyForTesting() const;
329 326
330 Member<Document> m_document;
331 Member<LocalFrame> m_frame; 327 Member<LocalFrame> m_frame;
332 const Member<PendingSelection> m_pendingSelection; 328 const Member<PendingSelection> m_pendingSelection;
333 const Member<SelectionEditor> m_selectionEditor; 329 const Member<SelectionEditor> m_selectionEditor;
334 330
335 TextGranularity m_granularity; 331 TextGranularity m_granularity;
336 LayoutUnit m_xPosForVerticalArrowNavigation; 332 LayoutUnit m_xPosForVerticalArrowNavigation;
337 333
338 Member<EditingStyle> m_typingStyle; 334 Member<EditingStyle> m_typingStyle;
339 335
340 bool m_focused : 1; 336 bool m_focused : 1;
(...skipping 19 matching lines...) Expand all
360 } 356 }
361 } // namespace blink 357 } // namespace blink
362 358
363 #ifndef NDEBUG 359 #ifndef NDEBUG
364 // Outside the WebCore namespace for ease of invocation from gdb. 360 // Outside the WebCore namespace for ease of invocation from gdb.
365 void showTree(const blink::FrameSelection&); 361 void showTree(const blink::FrameSelection&);
366 void showTree(const blink::FrameSelection*); 362 void showTree(const blink::FrameSelection*);
367 #endif 363 #endif
368 364
369 #endif // FrameSelection_h 365 #endif // FrameSelection_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.cpp ('k') | third_party/WebKit/Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698