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

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

Issue 2680943004: Make FrameSelection to hold non-canonicalized positions (Closed)
Patch Set: 2017-02-09T15:13:43 Created 3 years, 10 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 27 matching lines...) Expand all
38 #include "core/layout/ScrollAlignment.h" 38 #include "core/layout/ScrollAlignment.h"
39 #include "platform/Timer.h" 39 #include "platform/Timer.h"
40 #include "platform/geometry/IntRect.h" 40 #include "platform/geometry/IntRect.h"
41 #include "platform/geometry/LayoutRect.h" 41 #include "platform/geometry/LayoutRect.h"
42 #include "platform/graphics/PaintInvalidationReason.h" 42 #include "platform/graphics/PaintInvalidationReason.h"
43 #include "platform/heap/Handle.h" 43 #include "platform/heap/Handle.h"
44 #include "wtf/Noncopyable.h" 44 #include "wtf/Noncopyable.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 class CharacterData;
49 class DisplayItemClient; 48 class DisplayItemClient;
50 class LayoutBlock; 49 class LayoutBlock;
51 class LocalFrame; 50 class LocalFrame;
52 class FrameCaret; 51 class FrameCaret;
53 class GranularityStrategy; 52 class GranularityStrategy;
54 class GraphicsContext; 53 class GraphicsContext;
55 class HTMLFormElement; 54 class HTMLFormElement;
56 class SelectionEditor; 55 class SelectionEditor;
57 class PendingSelection; 56 class PendingSelection;
58 class Text;
59 class TextIteratorBehavior; 57 class TextIteratorBehavior;
60 struct PaintInvalidatorContext; 58 struct PaintInvalidatorContext;
61 59
62 enum class CursorAlignOnScroll { IfNeeded, Always }; 60 enum class CursorAlignOnScroll { IfNeeded, Always };
63 61
64 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; 62 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 };
65 63
66 enum RevealExtentOption { RevealExtent, DoNotRevealExtent }; 64 enum RevealExtentOption { RevealExtent, DoNotRevealExtent };
67 65
68 enum class SelectionDirectionalMode { NonDirectional, Directional }; 66 enum class SelectionDirectionalMode { NonDirectional, Directional };
(...skipping 15 matching lines...) Expand all
84 ~FrameSelection(); 82 ~FrameSelection();
85 83
86 enum EAlteration { AlterationMove, AlterationExtend }; 84 enum EAlteration { AlterationMove, AlterationExtend };
87 enum SetSelectionOption { 85 enum SetSelectionOption {
88 // 1 << 0 is reserved for EUserTriggered 86 // 1 << 0 is reserved for EUserTriggered
89 CloseTyping = 1 << 1, 87 CloseTyping = 1 << 1,
90 ClearTypingStyle = 1 << 2, 88 ClearTypingStyle = 1 << 2,
91 DoNotSetFocus = 1 << 3, 89 DoNotSetFocus = 1 << 3,
92 DoNotUpdateAppearance = 1 << 4, 90 DoNotUpdateAppearance = 1 << 4,
93 DoNotClearStrategy = 1 << 5, 91 DoNotClearStrategy = 1 << 5,
92 // TODO(yosin): We should get rid of |DoNotAdjustInFlatTree|.
94 DoNotAdjustInFlatTree = 1 << 6, 93 DoNotAdjustInFlatTree = 1 << 6,
95 }; 94 };
96 // Union of values in SetSelectionOption and EUserTriggered 95 // Union of values in SetSelectionOption and EUserTriggered
97 typedef unsigned SetSelectionOptions; 96 typedef unsigned SetSelectionOptions;
98 static inline EUserTriggered selectionOptionsToUserTriggered( 97 static inline EUserTriggered selectionOptionsToUserTriggered(
99 SetSelectionOptions options) { 98 SetSelectionOptions options) {
100 return static_cast<EUserTriggered>(options & UserTriggered); 99 return static_cast<EUserTriggered>(options & UserTriggered);
101 } 100 }
102 101
103 bool isAvailable() const { return lifecycleContext(); } 102 bool isAvailable() const { return lifecycleContext(); }
104 // You should not call |document()| when |!isAvailable()|. 103 // You should not call |document()| when |!isAvailable()|.
105 const Document& document() const; 104 Document& document() const;
106 Document& document();
107 LocalFrame* frame() const { return m_frame; } 105 LocalFrame* frame() const { return m_frame; }
108 Element* rootEditableElement() const { 106 Element* rootEditableElement() const {
109 return selection().rootEditableElement(); 107 return selection().rootEditableElement();
110 } 108 }
111 Element* rootEditableElementOrDocumentElement() const; 109 Element* rootEditableElementOrDocumentElement() const;
112 ContainerNode* rootEditableElementOrTreeScopeRootNode() const; 110 ContainerNode* rootEditableElementOrTreeScopeRootNode() const;
113 111
114 bool hasEditableStyle() const { return selection().hasEditableStyle(); } 112 bool hasEditableStyle() const { return selection().hasEditableStyle(); }
115 bool isContentEditable() const { return selection().isContentEditable(); } 113 bool isContentEditable() const { return selection().isContentEditable(); }
116 bool isContentRichlyEditable() const { 114 bool isContentRichlyEditable() const {
117 return selection().isContentRichlyEditable(); 115 return selection().isContentRichlyEditable();
118 } 116 }
119 117
120 // An implementation of |WebFrame::moveCaretSelection()| 118 // An implementation of |WebFrame::moveCaretSelection()|
121 void moveCaretSelection(const IntPoint&); 119 void moveCaretSelection(const IntPoint&);
122 120
123 template <typename Strategy> 121 template <typename Strategy>
124 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; 122 const VisibleSelectionTemplate<Strategy>& visibleSelection() const;
123 const VisibleSelection& computeVisibleSelectionInDOMTree() const;
124 const VisibleSelectionInFlatTree& computeVisibleSelectionInFlatTree() const;
125 125
126 const VisibleSelection& selection() const; 126 const VisibleSelection& selection() const;
127 127
128 void setSelection(const SelectionInDOMTree&, 128 void setSelection(const SelectionInDOMTree&,
129 SetSelectionOptions = CloseTyping | ClearTypingStyle, 129 SetSelectionOptions = CloseTyping | ClearTypingStyle,
130 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded, 130 CursorAlignOnScroll = CursorAlignOnScroll::IfNeeded,
131 TextGranularity = CharacterGranularity); 131 TextGranularity = CharacterGranularity);
132 132
133 void setSelection(const SelectionInFlatTree&, 133 void setSelection(const SelectionInFlatTree&,
134 SetSelectionOptions = CloseTyping | ClearTypingStyle, 134 SetSelectionOptions = CloseTyping | ClearTypingStyle,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 // Returns true if specified layout block should paint caret. This function is 197 // Returns true if specified layout block should paint caret. This function is
198 // called during painting only. 198 // called during painting only.
199 bool shouldPaintCaret(const LayoutBlock&) const; 199 bool shouldPaintCaret(const LayoutBlock&) const;
200 200
201 // Bounds of (possibly transformed) caret in absolute coords 201 // Bounds of (possibly transformed) caret in absolute coords
202 IntRect absoluteCaretBounds(); 202 IntRect absoluteCaretBounds();
203 203
204 void didChangeFocus(); 204 void didChangeFocus();
205 205
206 const SelectionInDOMTree& selectionInDOMTree() const;
207 // TODO(yosin): We should rename |isNone()| to |isVisibleNone()|.
206 bool isNone() const { return selection().isNone(); } 208 bool isNone() const { return selection().isNone(); }
207 bool isCaret() const { return selection().isCaret(); } 209 bool isCaret() const { return selection().isCaret(); }
208 bool isRange() const { return selection().isRange(); } 210 bool isRange() const { return selection().isRange(); }
209 bool isInPasswordField() const; 211 bool isInPasswordField() const;
210 bool isDirectional() const { return selection().isDirectional(); } 212 bool isDirectional() const { return selectionInDOMTree().isDirectional(); }
211 213
212 // If this FrameSelection has a logical range which is still valid, this 214 // If this FrameSelection has a logical range which is still valid, this
213 // function return its clone. Otherwise, the return value from underlying 215 // function return its clone. Otherwise, the return value from underlying
214 // VisibleSelection's firstRange() is returned. 216 // VisibleSelection's firstRange() is returned.
215 Range* firstRange() const; 217 Range* firstRange() const;
216 218
217 void documentAttached(Document*); 219 void documentAttached(Document*);
218 220
219 void didLayout(); 221 void didLayout();
220 bool isAppearanceDirty() const; 222 bool isAppearanceDirty() const;
(...skipping 17 matching lines...) Expand all
238 bool isCaretBlinkingSuspended() const; 240 bool isCaretBlinkingSuspended() const;
239 241
240 // Focus 242 // Focus
241 void setFocused(bool); 243 void setFocused(bool);
242 bool isFocused() const { return m_focused; } 244 bool isFocused() const { return m_focused; }
243 bool isFocusedAndActive() const; 245 bool isFocusedAndActive() const;
244 void pageActivationChanged(); 246 void pageActivationChanged();
245 247
246 void setUseSecureKeyboardEntryWhenActive(bool); 248 void setUseSecureKeyboardEntryWhenActive(bool);
247 249
248 bool isHandleVisible() const { 250 bool isHandleVisible() const;
249 return m_handleVisibility == HandleVisibility::Visible;
250 }
251 251
252 void updateSecureKeyboardEntryIfActive(); 252 void updateSecureKeyboardEntryIfActive();
253 253
254 // Returns true if a word is selected. 254 // Returns true if a word is selected.
255 bool selectWordAroundPosition(const VisiblePosition&); 255 bool selectWordAroundPosition(const VisiblePosition&);
256 256
257 #ifndef NDEBUG 257 #ifndef NDEBUG
258 void showTreeForThis() const; 258 void showTreeForThis() const;
259 #endif 259 #endif
260 260
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 FullDocumentPaintingWithCaret); 300 FullDocumentPaintingWithCaret);
301 301
302 explicit FrameSelection(LocalFrame&); 302 explicit FrameSelection(LocalFrame&);
303 303
304 const DisplayItemClient& caretDisplayItemClientForTesting() const; 304 const DisplayItemClient& caretDisplayItemClientForTesting() const;
305 305
306 // Note: We have |selectionInFlatTree()| for unit tests, we should 306 // Note: We have |selectionInFlatTree()| for unit tests, we should
307 // use |visibleSelection<EditingInFlatTreeStrategy>()|. 307 // use |visibleSelection<EditingInFlatTreeStrategy>()|.
308 const VisibleSelectionInFlatTree& selectionInFlatTree() const; 308 const VisibleSelectionInFlatTree& selectionInFlatTree() const;
309 309
310 template <typename Strategy>
311 void setSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>&,
312 HandleVisibility,
313 SetSelectionOptions,
314 CursorAlignOnScroll,
315 TextGranularity);
316
317 void respondToNodeModification(Node&,
318 bool baseRemoved,
319 bool extentRemoved,
320 bool startRemoved,
321 bool endRemoved);
322
323 void notifyAccessibilityForSelectionChange(); 310 void notifyAccessibilityForSelectionChange();
324 void notifyCompositorForSelectionChange(); 311 void notifyCompositorForSelectionChange();
325 void notifyEventHandlerForSelectionChange(); 312 void notifyEventHandlerForSelectionChange();
326 313
327 void focusedOrActiveStateChanged(); 314 void focusedOrActiveStateChanged();
328 315
329 void setUseSecureKeyboardEntry(bool); 316 void setUseSecureKeyboardEntry(bool);
330 317
331 void updateSelectionIfNeeded(const Position& base, 318 void updateSelectionIfNeeded(const Position& base,
332 const Position& extent, 319 const Position& extent,
333 const Position& start, 320 const Position& start,
334 const Position& end); 321 const Position& end);
335 322
336 GranularityStrategy* granularityStrategy(); 323 GranularityStrategy* granularityStrategy();
337 324
338 // Implementation of |SynchronousMutationObserver| member functions. 325 // Implementation of |SynchronousMutationObserver| member functions.
339 void contextDestroyed(Document*) final; 326 void contextDestroyed(Document*) final;
340 void nodeChildrenWillBeRemoved(ContainerNode&) final; 327 void nodeChildrenWillBeRemoved(ContainerNode&) final;
341 void nodeWillBeRemoved(Node&) final; 328 void nodeWillBeRemoved(Node&) final;
342 void didUpdateCharacterData(CharacterData*,
343 unsigned offset,
344 unsigned oldLength,
345 unsigned newLength) final;
346 void didMergeTextNodes(const Text& mergedNode,
347 const NodeWithIndex& nodeToBeRemovedWithIndex,
348 unsigned oldLength) final;
349 void didSplitTextNode(const Text& oldNode) final;
350 329
351 Member<LocalFrame> m_frame; 330 Member<LocalFrame> m_frame;
352 const Member<PendingSelection> m_pendingSelection; 331 const Member<PendingSelection> m_pendingSelection;
353 const Member<SelectionEditor> m_selectionEditor; 332 const Member<SelectionEditor> m_selectionEditor;
354 333
355 TextGranularity m_granularity; 334 TextGranularity m_granularity;
356 LayoutUnit m_xPosForVerticalArrowNavigation; 335 LayoutUnit m_xPosForVerticalArrowNavigation;
357 336
358 bool m_focused : 1; 337 bool m_focused : 1;
359 338
360 HandleVisibility m_handleVisibility = HandleVisibility::NotVisible;
361
362 // Controls text granularity used to adjust the selection's extent in 339 // Controls text granularity used to adjust the selection's extent in
363 // moveRangeSelectionExtent. 340 // moveRangeSelectionExtent.
364 std::unique_ptr<GranularityStrategy> m_granularityStrategy; 341 std::unique_ptr<GranularityStrategy> m_granularityStrategy;
365 342
366 const Member<FrameCaret> m_frameCaret; 343 const Member<FrameCaret> m_frameCaret;
367 bool m_useSecureKeyboardEntryWhenActive = false; 344 bool m_useSecureKeyboardEntryWhenActive = false;
368 }; 345 };
369 346
370 } // namespace blink 347 } // namespace blink
371 348
372 #ifndef NDEBUG 349 #ifndef NDEBUG
373 // Outside the WebCore namespace for ease of invocation from gdb. 350 // Outside the WebCore namespace for ease of invocation from gdb.
374 void showTree(const blink::FrameSelection&); 351 void showTree(const blink::FrameSelection&);
375 void showTree(const blink::FrameSelection*); 352 void showTree(const blink::FrameSelection*);
376 #endif 353 #endif
377 354
378 #endif // FrameSelection_h 355 #endif // FrameSelection_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698