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; | |
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 Loading... |
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 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()|. |
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 Loading... |
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 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 | |
327 void notifyAccessibilityForSelectionChange(); | 314 void notifyAccessibilityForSelectionChange(); |
328 void notifyCompositorForSelectionChange(); | 315 void notifyCompositorForSelectionChange(); |
329 void notifyEventHandlerForSelectionChange(); | 316 void notifyEventHandlerForSelectionChange(); |
330 | 317 |
331 void focusedOrActiveStateChanged(); | 318 void focusedOrActiveStateChanged(); |
332 | 319 |
333 void setUseSecureKeyboardEntry(bool); | 320 void setUseSecureKeyboardEntry(bool); |
334 | 321 |
335 void updateSelectionIfNeeded(const Position& base, | 322 void updateSelectionIfNeeded(const Position& base, |
336 const Position& extent, | 323 const Position& extent, |
337 const Position& start, | 324 const Position& start, |
338 const Position& end); | 325 const Position& end); |
339 | 326 |
340 GranularityStrategy* granularityStrategy(); | 327 GranularityStrategy* granularityStrategy(); |
341 | 328 |
342 // Implementation of |SynchronousMutationObserver| member functions. | 329 // Implementation of |SynchronousMutationObserver| member functions. |
343 void contextDestroyed(Document*) final; | 330 void contextDestroyed(Document*) final; |
344 void nodeChildrenWillBeRemoved(ContainerNode&) final; | 331 void nodeChildrenWillBeRemoved(ContainerNode&) final; |
345 void nodeWillBeRemoved(Node&) final; | 332 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; | |
354 | 333 |
355 Member<LocalFrame> m_frame; | 334 Member<LocalFrame> m_frame; |
356 const Member<PendingSelection> m_pendingSelection; | 335 const Member<PendingSelection> m_pendingSelection; |
357 const Member<SelectionEditor> m_selectionEditor; | 336 const Member<SelectionEditor> m_selectionEditor; |
358 | 337 |
359 TextGranularity m_granularity; | 338 TextGranularity m_granularity; |
360 LayoutUnit m_xPosForVerticalArrowNavigation; | 339 LayoutUnit m_xPosForVerticalArrowNavigation; |
361 | 340 |
362 bool m_focused : 1; | 341 bool m_focused : 1; |
363 | 342 |
364 HandleVisibility m_handleVisibility = HandleVisibility::NotVisible; | |
365 | |
366 // Controls text granularity used to adjust the selection's extent in | 343 // Controls text granularity used to adjust the selection's extent in |
367 // moveRangeSelectionExtent. | 344 // moveRangeSelectionExtent. |
368 std::unique_ptr<GranularityStrategy> m_granularityStrategy; | 345 std::unique_ptr<GranularityStrategy> m_granularityStrategy; |
369 | 346 |
370 const Member<FrameCaret> m_frameCaret; | 347 const Member<FrameCaret> m_frameCaret; |
371 bool m_useSecureKeyboardEntryWhenActive = false; | 348 bool m_useSecureKeyboardEntryWhenActive = false; |
372 }; | 349 }; |
373 | 350 |
374 } // namespace blink | 351 } // namespace blink |
375 | 352 |
376 #ifndef NDEBUG | 353 #ifndef NDEBUG |
377 // Outside the WebCore namespace for ease of invocation from gdb. | 354 // Outside the WebCore namespace for ease of invocation from gdb. |
378 void showTree(const blink::FrameSelection&); | 355 void showTree(const blink::FrameSelection&); |
379 void showTree(const blink::FrameSelection*); | 356 void showTree(const blink::FrameSelection*); |
380 #endif | 357 #endif |
381 | 358 |
382 #endif // FrameSelection_h | 359 #endif // FrameSelection_h |
OLD | NEW |