OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #define FrameSelection_h | 27 #define FrameSelection_h |
28 | 28 |
29 #include "core/dom/Range.h" | 29 #include "core/dom/Range.h" |
30 #include "core/editing/Caret.h" | 30 #include "core/editing/Caret.h" |
31 #include "core/editing/EditingStyle.h" | 31 #include "core/editing/EditingStyle.h" |
32 #include "core/editing/VisibleSelection.h" | 32 #include "core/editing/VisibleSelection.h" |
33 #include "core/rendering/ScrollAlignment.h" | 33 #include "core/rendering/ScrollAlignment.h" |
34 #include "platform/Timer.h" | 34 #include "platform/Timer.h" |
35 #include "platform/geometry/IntRect.h" | 35 #include "platform/geometry/IntRect.h" |
36 #include "platform/geometry/LayoutRect.h" | 36 #include "platform/geometry/LayoutRect.h" |
37 #include "platform/heap/Handle.h" | |
37 #include "wtf/Noncopyable.h" | 38 #include "wtf/Noncopyable.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 class CharacterData; | 42 class CharacterData; |
42 class LocalFrame; | 43 class LocalFrame; |
43 class GraphicsContext; | 44 class GraphicsContext; |
44 class HTMLFormElement; | 45 class HTMLFormElement; |
45 class MutableStylePropertySet; | 46 class MutableStylePropertySet; |
46 class RenderObject; | 47 class RenderObject; |
47 class RenderView; | 48 class RenderView; |
48 class Settings; | 49 class Settings; |
49 class Text; | 50 class Text; |
50 class VisiblePosition; | 51 class VisiblePosition; |
51 | 52 |
52 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; | 53 enum EUserTriggered { NotUserTriggered = 0, UserTriggered = 1 }; |
53 | 54 |
54 enum RevealExtentOption { | 55 enum RevealExtentOption { |
55 RevealExtent, | 56 RevealExtent, |
56 DoNotRevealExtent | 57 DoNotRevealExtent |
57 }; | 58 }; |
58 | 59 |
59 class FrameSelection FINAL : public VisibleSelection::ChangeObserver, private Ca retBase { | 60 class FrameSelection FINAL : public NoBaseWillBeGarbageCollectedFinalized<FrameS election>, public VisibleSelection::ChangeObserver, private CaretBase { |
60 WTF_MAKE_NONCOPYABLE(FrameSelection); | 61 WTF_MAKE_NONCOPYABLE(FrameSelection); |
61 WTF_MAKE_FAST_ALLOCATED; | 62 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; |
62 public: | 63 public: |
64 static PassOwnPtrWillBeRawPtr<FrameSelection> create(LocalFrame* frame = 0) | |
65 { | |
66 return adoptPtrWillBeNoop(new FrameSelection(frame)); | |
67 } | |
68 virtual ~FrameSelection(); | |
69 | |
63 enum EAlteration { AlterationMove, AlterationExtend }; | 70 enum EAlteration { AlterationMove, AlterationExtend }; |
64 enum CursorAlignOnScroll { AlignCursorOnScrollIfNeeded, | 71 enum CursorAlignOnScroll { AlignCursorOnScrollIfNeeded, |
65 AlignCursorOnScrollAlways }; | 72 AlignCursorOnScrollAlways }; |
66 enum SetSelectionOption { | 73 enum SetSelectionOption { |
67 // 1 << 0 is reserved for EUserTriggered | 74 // 1 << 0 is reserved for EUserTriggered |
68 CloseTyping = 1 << 1, | 75 CloseTyping = 1 << 1, |
69 ClearTypingStyle = 1 << 2, | 76 ClearTypingStyle = 1 << 2, |
70 SpellCorrectionTriggered = 1 << 3, | 77 SpellCorrectionTriggered = 1 << 3, |
71 DoNotSetFocus = 1 << 4, | 78 DoNotSetFocus = 1 << 4, |
72 DoNotUpdateAppearance = 1 << 5, | 79 DoNotUpdateAppearance = 1 << 5, |
73 }; | 80 }; |
74 typedef unsigned SetSelectionOptions; // Union of values in SetSelectionOpti on and EUserTriggered | 81 typedef unsigned SetSelectionOptions; // Union of values in SetSelectionOpti on and EUserTriggered |
75 static inline EUserTriggered selectionOptionsToUserTriggered(SetSelectionOpt ions options) | 82 static inline EUserTriggered selectionOptionsToUserTriggered(SetSelectionOpt ions options) |
76 { | 83 { |
77 return static_cast<EUserTriggered>(options & UserTriggered); | 84 return static_cast<EUserTriggered>(options & UserTriggered); |
78 } | 85 } |
79 | 86 |
80 explicit FrameSelection(LocalFrame* = 0); | |
81 virtual ~FrameSelection(); | |
82 | |
83 Element* rootEditableElement() const { return m_selection.rootEditableElemen t(); } | 87 Element* rootEditableElement() const { return m_selection.rootEditableElemen t(); } |
84 Element* rootEditableElementOrDocumentElement() const; | 88 Element* rootEditableElementOrDocumentElement() const; |
85 Node* rootEditableElementOrTreeScopeRootNode() const; | 89 Node* rootEditableElementOrTreeScopeRootNode() const; |
86 | 90 |
87 bool rendererIsEditable() const { return m_selection.rendererIsEditable(); } | 91 bool rendererIsEditable() const { return m_selection.rendererIsEditable(); } |
88 bool isContentEditable() const { return m_selection.isContentEditable(); } | 92 bool isContentEditable() const { return m_selection.isContentEditable(); } |
89 bool isContentRichlyEditable() const { return m_selection.isContentRichlyEdi table(); } | 93 bool isContentRichlyEditable() const { return m_selection.isContentRichlyEdi table(); } |
90 | 94 |
91 void moveTo(const VisiblePosition&, EUserTriggered = NotUserTriggered, Curso rAlignOnScroll = AlignCursorOnScrollIfNeeded); | 95 void moveTo(const VisiblePosition&, EUserTriggered = NotUserTriggered, Curso rAlignOnScroll = AlignCursorOnScrollIfNeeded); |
92 void moveTo(const VisiblePosition&, const VisiblePosition&, EUserTriggered = NotUserTriggered); | 96 void moveTo(const VisiblePosition&, const VisiblePosition&, EUserTriggered = NotUserTriggered); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 void formatForDebugger(char* buffer, unsigned length) const; | 184 void formatForDebugger(char* buffer, unsigned length) const; |
181 void showTreeForThis() const; | 185 void showTreeForThis() const; |
182 #endif | 186 #endif |
183 | 187 |
184 enum EndPointsAdjustmentMode { AdjustEndpointsAtBidiBoundary, DoNotAdjsutEnd points }; | 188 enum EndPointsAdjustmentMode { AdjustEndpointsAtBidiBoundary, DoNotAdjsutEnd points }; |
185 void setNonDirectionalSelectionIfNeeded(const VisibleSelection&, TextGranula rity, EndPointsAdjustmentMode = DoNotAdjsutEndpoints); | 189 void setNonDirectionalSelectionIfNeeded(const VisibleSelection&, TextGranula rity, EndPointsAdjustmentMode = DoNotAdjsutEndpoints); |
186 void setFocusedNodeIfNeeded(); | 190 void setFocusedNodeIfNeeded(); |
187 void notifyRendererOfSelectionChange(EUserTriggered); | 191 void notifyRendererOfSelectionChange(EUserTriggered); |
188 | 192 |
189 EditingStyle* typingStyle() const; | 193 EditingStyle* typingStyle() const; |
190 void setTypingStyle(PassRefPtr<EditingStyle>); | 194 void setTypingStyle(PassRefPtrWillBeRawPtr<EditingStyle>); |
191 void clearTypingStyle(); | 195 void clearTypingStyle(); |
192 | 196 |
193 String selectedText() const; | 197 String selectedText() const; |
194 String selectedTextForClipboard() const; | 198 String selectedTextForClipboard() const; |
195 | 199 |
196 FloatRect bounds(bool clipToVisibleContent = true) const; | 200 FloatRect bounds(bool clipToVisibleContent = true) const; |
197 | 201 |
198 HTMLFormElement* currentForm() const; | 202 HTMLFormElement* currentForm() const; |
199 | 203 |
200 void revealSelection(const ScrollAlignment& = ScrollAlignment::alignCenterIf Needed, RevealExtentOption = DoNotRevealExtent); | 204 void revealSelection(const ScrollAlignment& = ScrollAlignment::alignCenterIf Needed, RevealExtentOption = DoNotRevealExtent); |
201 void setSelectionFromNone(); | 205 void setSelectionFromNone(); |
202 | 206 |
203 void setShouldShowBlockCursor(bool); | 207 void setShouldShowBlockCursor(bool); |
204 | 208 |
205 // VisibleSelection::ChangeObserver interface. | 209 // VisibleSelection::ChangeObserver interface. |
206 virtual void didChangeVisibleSelection() OVERRIDE; | 210 virtual void didChangeVisibleSelection() OVERRIDE; |
207 | 211 |
212 void trace(Visitor*); | |
213 | |
208 private: | 214 private: |
215 explicit FrameSelection(LocalFrame*); | |
216 | |
209 enum EPositionType { START, END, BASE, EXTENT }; | 217 enum EPositionType { START, END, BASE, EXTENT }; |
210 | 218 |
211 void respondToNodeModification(Node&, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved); | 219 void respondToNodeModification(Node&, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved); |
212 TextDirection directionOfEnclosingBlock(); | 220 TextDirection directionOfEnclosingBlock(); |
213 TextDirection directionOfSelection(); | 221 TextDirection directionOfSelection(); |
214 | 222 |
215 VisiblePosition positionForPlatform(bool isGetStart) const; | 223 VisiblePosition positionForPlatform(bool isGetStart) const; |
216 VisiblePosition startForPlatform() const; | 224 VisiblePosition startForPlatform() const; |
217 VisiblePosition endForPlatform() const; | 225 VisiblePosition endForPlatform() const; |
218 VisiblePosition nextWordPositionForPlatform(const VisiblePosition&); | 226 VisiblePosition nextWordPositionForPlatform(const VisiblePosition&); |
(...skipping 20 matching lines...) Expand all Loading... | |
239 void setCaretVisibility(CaretVisibility); | 247 void setCaretVisibility(CaretVisibility); |
240 bool shouldBlinkCaret() const; | 248 bool shouldBlinkCaret() const; |
241 | 249 |
242 bool dispatchSelectStart(); | 250 bool dispatchSelectStart(); |
243 | 251 |
244 void updateSelectionIfNeeded(const Position& base, const Position& extent, c onst Position& start, const Position& end); | 252 void updateSelectionIfNeeded(const Position& base, const Position& extent, c onst Position& start, const Position& end); |
245 | 253 |
246 void startObservingVisibleSelectionChange(); | 254 void startObservingVisibleSelectionChange(); |
247 void stopObservingVisibleSelectionChangeIfNecessary(); | 255 void stopObservingVisibleSelectionChangeIfNecessary(); |
248 | 256 |
249 LocalFrame* m_frame; | 257 LocalFrame* m_frame; |
haraken
2014/05/26 02:36:12
This raw pointer looks safe because the FrameSelec
yosin_UTC9
2014/05/26 07:06:42
FYI: m_frame can be null when FrameSelection is al
| |
250 | 258 |
251 LayoutUnit m_xPosForVerticalArrowNavigation; | 259 LayoutUnit m_xPosForVerticalArrowNavigation; |
252 | 260 |
253 VisibleSelection m_selection; | 261 VisibleSelection m_selection; |
254 bool m_observingVisibleSelection; | 262 bool m_observingVisibleSelection; |
255 VisiblePosition m_originalBase; // Used to store base before the adjustment at bidi boundary | 263 VisiblePosition m_originalBase; // Used to store base before the adjustment at bidi boundary |
256 TextGranularity m_granularity; | 264 TextGranularity m_granularity; |
257 | 265 |
258 // The range specified by the user, which may not be visually canonicalized (hence "logical"). | 266 // The range specified by the user, which may not be visually canonicalized (hence "logical"). |
259 // This will be invalidated if the underlying VisibleSelection changes. If t hat happens, this variable will | 267 // This will be invalidated if the underlying VisibleSelection changes. If t hat happens, this variable will |
260 // become null, in which case logical positions == visible positions. | 268 // become null, in which case logical positions == visible positions. |
261 RefPtrWillBePersistent<Range> m_logicalRange; | 269 RefPtrWillBeMember<Range> m_logicalRange; |
262 | 270 |
263 RefPtr<Node> m_previousCaretNode; // The last node which painted the caret. Retained for clearing the old caret when it moves. | 271 RefPtrWillBeMember<Node> m_previousCaretNode; // The last node which painted the caret. Retained for clearing the old caret when it moves. |
264 | 272 |
265 RefPtr<EditingStyle> m_typingStyle; | 273 RefPtrWillBeMember<EditingStyle> m_typingStyle; |
266 | 274 |
267 Timer<FrameSelection> m_caretBlinkTimer; | 275 Timer<FrameSelection> m_caretBlinkTimer; |
268 // The painted bounds of the caret in absolute coordinates | 276 // The painted bounds of the caret in absolute coordinates |
269 IntRect m_absCaretBounds; | 277 IntRect m_absCaretBounds; |
270 bool m_absCaretBoundsDirty : 1; | 278 bool m_absCaretBoundsDirty : 1; |
271 bool m_caretPaint : 1; | 279 bool m_caretPaint : 1; |
272 bool m_isCaretBlinkingSuspended : 1; | 280 bool m_isCaretBlinkingSuspended : 1; |
273 bool m_focused : 1; | 281 bool m_focused : 1; |
274 bool m_shouldShowBlockCursor : 1; | 282 bool m_shouldShowBlockCursor : 1; |
275 }; | 283 }; |
276 | 284 |
277 inline EditingStyle* FrameSelection::typingStyle() const | 285 inline EditingStyle* FrameSelection::typingStyle() const |
278 { | 286 { |
279 return m_typingStyle.get(); | 287 return m_typingStyle.get(); |
280 } | 288 } |
281 | 289 |
282 inline void FrameSelection::clearTypingStyle() | 290 inline void FrameSelection::clearTypingStyle() |
283 { | 291 { |
284 m_typingStyle.clear(); | 292 m_typingStyle.clear(); |
285 } | 293 } |
286 | 294 |
287 inline void FrameSelection::setTypingStyle(PassRefPtr<EditingStyle> style) | 295 inline void FrameSelection::setTypingStyle(PassRefPtrWillBeRawPtr<EditingStyle> style) |
288 { | 296 { |
289 m_typingStyle = style; | 297 m_typingStyle = style; |
290 } | 298 } |
291 } // namespace WebCore | 299 } // namespace WebCore |
292 | 300 |
293 #ifndef NDEBUG | 301 #ifndef NDEBUG |
294 // Outside the WebCore namespace for ease of invocation from gdb. | 302 // Outside the WebCore namespace for ease of invocation from gdb. |
295 void showTree(const WebCore::FrameSelection&); | 303 void showTree(const WebCore::FrameSelection&); |
296 void showTree(const WebCore::FrameSelection*); | 304 void showTree(const WebCore::FrameSelection*); |
297 #endif | 305 #endif |
298 | 306 |
299 #endif // FrameSelection_h | 307 #endif // FrameSelection_h |
OLD | NEW |