OLD | NEW |
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 Loading... |
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; |
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; |
| 58 class Text; |
57 class TextIteratorBehavior; | 59 class TextIteratorBehavior; |
58 struct PaintInvalidatorContext; | 60 struct PaintInvalidatorContext; |
59 | 61 |
60 enum class CursorAlignOnScroll { IfNeeded, Always }; | 62 enum class CursorAlignOnScroll { IfNeeded, Always }; |
61 | 63 |
62 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; | 64 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; |
63 | 65 |
64 enum RevealExtentOption { RevealExtent, DoNotRevealExtent }; | 66 enum RevealExtentOption { RevealExtent, DoNotRevealExtent }; |
65 | 67 |
66 enum class SelectionDirectionalMode { NonDirectional, Directional }; | 68 enum class SelectionDirectionalMode { NonDirectional, Directional }; |
(...skipping 15 matching lines...) Expand all Loading... |
82 ~FrameSelection(); | 84 ~FrameSelection(); |
83 | 85 |
84 enum EAlteration { AlterationMove, AlterationExtend }; | 86 enum EAlteration { AlterationMove, AlterationExtend }; |
85 enum SetSelectionOption { | 87 enum SetSelectionOption { |
86 // 1 << 0 is reserved for EUserTriggered | 88 // 1 << 0 is reserved for EUserTriggered |
87 CloseTyping = 1 << 1, | 89 CloseTyping = 1 << 1, |
88 ClearTypingStyle = 1 << 2, | 90 ClearTypingStyle = 1 << 2, |
89 DoNotSetFocus = 1 << 3, | 91 DoNotSetFocus = 1 << 3, |
90 DoNotUpdateAppearance = 1 << 4, | 92 DoNotUpdateAppearance = 1 << 4, |
91 DoNotClearStrategy = 1 << 5, | 93 DoNotClearStrategy = 1 << 5, |
92 // TODO(yosin): We should get rid of |DoNotAdjustInFlatTree|. | |
93 DoNotAdjustInFlatTree = 1 << 6, | 94 DoNotAdjustInFlatTree = 1 << 6, |
94 }; | 95 }; |
95 // Union of values in SetSelectionOption and EUserTriggered | 96 // Union of values in SetSelectionOption and EUserTriggered |
96 typedef unsigned SetSelectionOptions; | 97 typedef unsigned SetSelectionOptions; |
97 static inline EUserTriggered selectionOptionsToUserTriggered( | 98 static inline EUserTriggered selectionOptionsToUserTriggered( |
98 SetSelectionOptions options) { | 99 SetSelectionOptions options) { |
99 return static_cast<EUserTriggered>(options & UserTriggered); | 100 return static_cast<EUserTriggered>(options & UserTriggered); |
100 } | 101 } |
101 | 102 |
102 bool isAvailable() const { return lifecycleContext(); } | 103 bool isAvailable() const { return lifecycleContext(); } |
103 // You should not call |document()| when |!isAvailable()|. | 104 // You should not call |document()| when |!isAvailable()|. |
104 Document& document() const; | 105 const Document& document() const; |
| 106 Document& document(); |
105 LocalFrame* frame() const { return m_frame; } | 107 LocalFrame* frame() const { return m_frame; } |
106 Element* rootEditableElement() const { | 108 Element* rootEditableElement() const { |
107 return selection().rootEditableElement(); | 109 return selection().rootEditableElement(); |
108 } | 110 } |
109 Element* rootEditableElementOrDocumentElement() const; | 111 Element* rootEditableElementOrDocumentElement() const; |
110 ContainerNode* rootEditableElementOrTreeScopeRootNode() const; | 112 ContainerNode* rootEditableElementOrTreeScopeRootNode() const; |
111 | 113 |
112 bool hasEditableStyle() const { return selection().hasEditableStyle(); } | 114 bool hasEditableStyle() const { return selection().hasEditableStyle(); } |
113 bool isContentEditable() const { return selection().isContentEditable(); } | 115 bool isContentEditable() const { return selection().isContentEditable(); } |
114 bool isContentRichlyEditable() const { | 116 bool isContentRichlyEditable() const { |
115 return selection().isContentRichlyEditable(); | 117 return selection().isContentRichlyEditable(); |
116 } | 118 } |
117 | 119 |
118 // An implementation of |WebFrame::moveCaretSelection()| | 120 // An implementation of |WebFrame::moveCaretSelection()| |
119 void moveCaretSelection(const IntPoint&); | 121 void moveCaretSelection(const IntPoint&); |
120 | 122 |
121 template <typename Strategy> | 123 template <typename Strategy> |
122 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; | 124 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 Loading... |
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()|. | |
208 bool isNone() const { return selection().isNone(); } | 206 bool isNone() const { return selection().isNone(); } |
209 bool isCaret() const { return selection().isCaret(); } | 207 bool isCaret() const { return selection().isCaret(); } |
210 bool isRange() const { return selection().isRange(); } | 208 bool isRange() const { return selection().isRange(); } |
211 bool isInPasswordField() const; | 209 bool isInPasswordField() const; |
212 bool isDirectional() const { return selectionInDOMTree().isDirectional(); } | 210 bool isDirectional() const { return selection().isDirectional(); } |
213 | 211 |
214 // If this FrameSelection has a logical range which is still valid, this | 212 // If this FrameSelection has a logical range which is still valid, this |
215 // function return its clone. Otherwise, the return value from underlying | 213 // function return its clone. Otherwise, the return value from underlying |
216 // VisibleSelection's firstRange() is returned. | 214 // VisibleSelection's firstRange() is returned. |
217 Range* firstRange() const; | 215 Range* firstRange() const; |
218 | 216 |
219 void documentAttached(Document*); | 217 void documentAttached(Document*); |
220 | 218 |
221 void didLayout(); | 219 void didLayout(); |
222 bool isAppearanceDirty() const; | 220 bool isAppearanceDirty() const; |
(...skipping 17 matching lines...) Expand all Loading... |
240 bool isCaretBlinkingSuspended() const; | 238 bool isCaretBlinkingSuspended() const; |
241 | 239 |
242 // Focus | 240 // Focus |
243 void setFocused(bool); | 241 void setFocused(bool); |
244 bool isFocused() const { return m_focused; } | 242 bool isFocused() const { return m_focused; } |
245 bool isFocusedAndActive() const; | 243 bool isFocusedAndActive() const; |
246 void pageActivationChanged(); | 244 void pageActivationChanged(); |
247 | 245 |
248 void setUseSecureKeyboardEntryWhenActive(bool); | 246 void setUseSecureKeyboardEntryWhenActive(bool); |
249 | 247 |
250 bool isHandleVisible() const; | 248 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 FullDocumentPaintingWithCaret); | 304 FullDocumentPaintingWithCaret); |
305 | 305 |
306 explicit FrameSelection(LocalFrame&); | 306 explicit FrameSelection(LocalFrame&); |
307 | 307 |
308 const DisplayItemClient& caretDisplayItemClientForTesting() const; | 308 const DisplayItemClient& caretDisplayItemClientForTesting() const; |
309 | 309 |
310 // Note: We have |selectionInFlatTree()| for unit tests, we should | 310 // Note: We have |selectionInFlatTree()| for unit tests, we should |
311 // use |visibleSelection<EditingInFlatTreeStrategy>()|. | 311 // use |visibleSelection<EditingInFlatTreeStrategy>()|. |
312 const VisibleSelectionInFlatTree& selectionInFlatTree() const; | 312 const VisibleSelectionInFlatTree& selectionInFlatTree() const; |
313 | 313 |
| 314 template <typename Strategy> |
| 315 void setSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>&, |
| 316 HandleVisibility, |
| 317 SetSelectionOptions, |
| 318 CursorAlignOnScroll, |
| 319 TextGranularity); |
| 320 |
| 321 void respondToNodeModification(Node&, |
| 322 bool baseRemoved, |
| 323 bool extentRemoved, |
| 324 bool startRemoved, |
| 325 bool endRemoved); |
| 326 |
314 void notifyAccessibilityForSelectionChange(); | 327 void notifyAccessibilityForSelectionChange(); |
315 void notifyCompositorForSelectionChange(); | 328 void notifyCompositorForSelectionChange(); |
316 void notifyEventHandlerForSelectionChange(); | 329 void notifyEventHandlerForSelectionChange(); |
317 | 330 |
318 void focusedOrActiveStateChanged(); | 331 void focusedOrActiveStateChanged(); |
319 | 332 |
320 void setUseSecureKeyboardEntry(bool); | 333 void setUseSecureKeyboardEntry(bool); |
321 | 334 |
322 void updateSelectionIfNeeded(const Position& base, | 335 void updateSelectionIfNeeded(const Position& base, |
323 const Position& extent, | 336 const Position& extent, |
324 const Position& start, | 337 const Position& start, |
325 const Position& end); | 338 const Position& end); |
326 | 339 |
327 GranularityStrategy* granularityStrategy(); | 340 GranularityStrategy* granularityStrategy(); |
328 | 341 |
329 // Implementation of |SynchronousMutationObserver| member functions. | 342 // Implementation of |SynchronousMutationObserver| member functions. |
330 void contextDestroyed(Document*) final; | 343 void contextDestroyed(Document*) final; |
331 void nodeChildrenWillBeRemoved(ContainerNode&) final; | 344 void nodeChildrenWillBeRemoved(ContainerNode&) final; |
332 void nodeWillBeRemoved(Node&) final; | 345 void nodeWillBeRemoved(Node&) final; |
| 346 void didUpdateCharacterData(CharacterData*, |
| 347 unsigned offset, |
| 348 unsigned oldLength, |
| 349 unsigned newLength) final; |
| 350 void didMergeTextNodes(const Text& mergedNode, |
| 351 const NodeWithIndex& nodeToBeRemovedWithIndex, |
| 352 unsigned oldLength) final; |
| 353 void didSplitTextNode(const Text& oldNode) final; |
333 | 354 |
334 Member<LocalFrame> m_frame; | 355 Member<LocalFrame> m_frame; |
335 const Member<PendingSelection> m_pendingSelection; | 356 const Member<PendingSelection> m_pendingSelection; |
336 const Member<SelectionEditor> m_selectionEditor; | 357 const Member<SelectionEditor> m_selectionEditor; |
337 | 358 |
338 TextGranularity m_granularity; | 359 TextGranularity m_granularity; |
339 LayoutUnit m_xPosForVerticalArrowNavigation; | 360 LayoutUnit m_xPosForVerticalArrowNavigation; |
340 | 361 |
341 bool m_focused : 1; | 362 bool m_focused : 1; |
342 | 363 |
| 364 HandleVisibility m_handleVisibility = HandleVisibility::NotVisible; |
| 365 |
343 // Controls text granularity used to adjust the selection's extent in | 366 // Controls text granularity used to adjust the selection's extent in |
344 // moveRangeSelectionExtent. | 367 // moveRangeSelectionExtent. |
345 std::unique_ptr<GranularityStrategy> m_granularityStrategy; | 368 std::unique_ptr<GranularityStrategy> m_granularityStrategy; |
346 | 369 |
347 const Member<FrameCaret> m_frameCaret; | 370 const Member<FrameCaret> m_frameCaret; |
348 bool m_useSecureKeyboardEntryWhenActive = false; | 371 bool m_useSecureKeyboardEntryWhenActive = false; |
349 }; | 372 }; |
350 | 373 |
351 } // namespace blink | 374 } // namespace blink |
352 | 375 |
353 #ifndef NDEBUG | 376 #ifndef NDEBUG |
354 // Outside the WebCore namespace for ease of invocation from gdb. | 377 // Outside the WebCore namespace for ease of invocation from gdb. |
355 void showTree(const blink::FrameSelection&); | 378 void showTree(const blink::FrameSelection&); |
356 void showTree(const blink::FrameSelection*); | 379 void showTree(const blink::FrameSelection*); |
357 #endif | 380 #endif |
358 | 381 |
359 #endif // FrameSelection_h | 382 #endif // FrameSelection_h |
OLD | NEW |