OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 enum PositionMoveType { | 50 enum PositionMoveType { |
51 CodePoint, // Move by a single code point. | 51 CodePoint, // Move by a single code point. |
52 Character, // Move to the next Unicode character break. | 52 Character, // Move to the next Unicode character break. |
53 BackwardDeletion // Subject to platform conventions. | 53 BackwardDeletion // Subject to platform conventions. |
54 }; | 54 }; |
55 | 55 |
56 template <typename Strategy> | 56 template <typename Strategy> |
57 class CORE_TEMPLATE_CLASS_EXPORT PositionAlgorithm { | 57 class CORE_TEMPLATE_CLASS_EXPORT PositionAlgorithm { |
58 DISALLOW_ALLOCATION(); | 58 DISALLOW_ALLOCATION(); |
59 public: | 59 public: |
60 using PositionType = typename Strategy::PositionType; | |
61 using StrategyType = Strategy; | 60 using StrategyType = Strategy; |
62 | 61 |
63 enum AnchorType : unsigned char { | 62 enum AnchorType : unsigned char { |
64 PositionIsOffsetInAnchor, | 63 PositionIsOffsetInAnchor, |
65 PositionIsBeforeAnchor, | 64 PositionIsBeforeAnchor, |
66 PositionIsAfterAnchor, | 65 PositionIsAfterAnchor, |
67 PositionIsBeforeChildren, | 66 PositionIsBeforeChildren, |
68 PositionIsAfterChildren, | 67 PositionIsAfterChildren, |
69 }; | 68 }; |
70 | 69 |
71 PositionAlgorithm() | 70 PositionAlgorithm() |
72 : m_offset(0) | 71 : m_offset(0) |
73 , m_anchorType(PositionIsOffsetInAnchor) | 72 , m_anchorType(PositionIsOffsetInAnchor) |
74 , m_isLegacyEditingPosition(false) | 73 , m_isLegacyEditingPosition(false) |
75 { | 74 { |
76 } | 75 } |
77 | 76 |
78 // For creating legacy editing positions: (Anchor type will be determined fr om editingIgnoresContent(node)) | 77 // For creating legacy editing positions: (Anchor type will be determined fr om editingIgnoresContent(node)) |
79 class LegacyEditingOffset { | 78 class LegacyEditingOffset { |
80 public: | 79 public: |
81 int value() const { return m_offset; } | 80 int value() const { return m_offset; } |
82 | 81 |
83 explicit LegacyEditingOffset(int offset) : m_offset(offset) { } | 82 explicit LegacyEditingOffset(int offset) : m_offset(offset) { } |
84 | 83 |
85 private: | 84 private: |
86 int m_offset; | 85 int m_offset; |
87 }; | 86 }; |
88 | 87 |
89 static const TreeScope* commonAncestorTreeScope(const PositionType&, const P ositionType& b); | 88 static const TreeScope* commonAncestorTreeScope(const PositionAlgorithm<Stra tegy>&, const PositionAlgorithm<Strategy>& b); |
90 static PositionType createLegacyEditingPosition(PassRefPtrWillBeRawPtr<Node> anchorNode, int offset); | 89 static PositionAlgorithm<Strategy> createLegacyEditingPosition(PassRefPtrWil lBeRawPtr<Node> anchorNode, int offset); |
91 | 90 |
92 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, LegacyEditingOffs et); | 91 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, LegacyEditingOffs et); |
93 | 92 |
94 // For creating before/after positions: | 93 // For creating before/after positions: |
95 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, AnchorType); | 94 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, AnchorType); |
96 PositionAlgorithm(PassRefPtrWillBeRawPtr<Text> textNode, unsigned offset); | 95 PositionAlgorithm(PassRefPtrWillBeRawPtr<Text> textNode, unsigned offset); |
97 | 96 |
98 // For creating offset positions: | 97 // For creating offset positions: |
99 // FIXME: This constructor should eventually go away. See bug 63040. | 98 // FIXME: This constructor should eventually go away. See bug 63040. |
100 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, int offset, Ancho rType); | 99 PositionAlgorithm(PassRefPtrWillBeRawPtr<Node> anchorNode, int offset, Ancho rType); |
101 | 100 |
102 PositionAlgorithm(const PositionAlgorithm&); | 101 PositionAlgorithm(const PositionAlgorithm&); |
103 | 102 |
104 AnchorType anchorType() const { return m_anchorType; } | 103 AnchorType anchorType() const { return m_anchorType; } |
105 | 104 |
106 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs OffsetInAnchor; m_isLegacyEditingPosition = false; } | 105 void clear() { m_anchorNode.clear(); m_offset = 0; m_anchorType = PositionIs OffsetInAnchor; m_isLegacyEditingPosition = false; } |
107 | 106 |
108 // These are always DOM compliant values. Editing positions like [img, 0] ( aka [img, before]) | 107 // These are always DOM compliant values. Editing positions like [img, 0] ( aka [img, before]) |
109 // will return img->parentNode() and img->nodeIndex() from these functions. | 108 // will return img->parentNode() and img->nodeIndex() from these functions. |
110 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent | 109 Node* containerNode() const; // NULL for a before/after position anchored to a node with no parent |
111 Text* containerText() const; | 110 Text* containerText() const; |
112 | 111 |
113 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions | 112 int computeOffsetInContainerNode() const; // O(n) for before/after-anchored positions, O(1) for parent-anchored positions |
114 PositionType parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing | 113 PositionAlgorithm<Strategy> parentAnchoredEquivalent() const; // Convenience method for DOM positions that also fixes up some positions for editing |
115 | 114 |
116 // Returns |PositionIsAnchor| type |Position| which is compatible with | 115 // Returns |PositionIsAnchor| type |Position| which is compatible with |
117 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value | 116 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value |
118 // of this function is different from |parentAnchoredEquivalent()| which | 117 // of this function is different from |parentAnchoredEquivalent()| which |
119 // returns editing specific position. | 118 // returns editing specific position. |
120 PositionType toOffsetInAnchor() const; | 119 PositionAlgorithm<Strategy> toOffsetInAnchor() const; |
121 | 120 |
122 // Inline O(1) access for Positions which callers know to be parent-anchored | 121 // Inline O(1) access for Positions which callers know to be parent-anchored |
123 int offsetInContainerNode() const | 122 int offsetInContainerNode() const |
124 { | 123 { |
125 ASSERT(anchorType() == PositionIsOffsetInAnchor); | 124 ASSERT(anchorType() == PositionIsOffsetInAnchor); |
126 return m_offset; | 125 return m_offset; |
127 } | 126 } |
128 | 127 |
129 // New code should not use this function. | 128 // New code should not use this function. |
130 int deprecatedEditingOffset() const | 129 int deprecatedEditingOffset() const |
(...skipping 13 matching lines...) Expand all Loading... | |
144 | 143 |
145 // Similar to |nodeAsRangeLastNode()|, but returns a node in a range. | 144 // Similar to |nodeAsRangeLastNode()|, but returns a node in a range. |
146 Node* nodeAsRangeLastNode() const; | 145 Node* nodeAsRangeLastNode() const; |
147 | 146 |
148 // Returns a node as past last as same as |Range::pastLastNode()|. This | 147 // Returns a node as past last as same as |Range::pastLastNode()|. This |
149 // function is supposed to used in HTML serialization and plain text | 148 // function is supposed to used in HTML serialization and plain text |
150 // iterator. This position must be a |PositionIs::OffsetInAhcor| to | 149 // iterator. This position must be a |PositionIs::OffsetInAhcor| to |
151 // behave as |Range| boundary point. | 150 // behave as |Range| boundary point. |
152 Node* nodeAsRangePastLastNode() const; | 151 Node* nodeAsRangePastLastNode() const; |
153 | 152 |
154 Node* commonAncestorContainer(const PositionType&) const; | 153 Node* commonAncestorContainer(const PositionAlgorithm<Strategy>&) const; |
155 | 154 |
156 Node* anchorNode() const { return m_anchorNode.get(); } | 155 Node* anchorNode() const { return m_anchorNode.get(); } |
157 | 156 |
158 // FIXME: Callers should be moved off of node(), node() is not always the co ntainer for this position. | 157 // FIXME: Callers should be moved off of node(), node() is not always the co ntainer for this position. |
159 // For nodes which editingIgnoresContent(node()) returns true, positions lik e [ignoredNode, 0] | 158 // For nodes which editingIgnoresContent(node()) returns true, positions lik e [ignoredNode, 0] |
160 // will be treated as before ignoredNode (thus node() is really after the po sition, not containing it). | 159 // will be treated as before ignoredNode (thus node() is really after the po sition, not containing it). |
161 Node* deprecatedNode() const { return m_anchorNode.get(); } | 160 Node* deprecatedNode() const { return m_anchorNode.get(); } |
162 | 161 |
163 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; } | 162 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; } |
164 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); } | 163 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); } |
(...skipping 11 matching lines...) Expand all Loading... | |
176 bool isNull() const { return !m_anchorNode; } | 175 bool isNull() const { return !m_anchorNode; } |
177 bool isNotNull() const { return m_anchorNode; } | 176 bool isNotNull() const { return m_anchorNode; } |
178 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); } | 177 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); } |
179 | 178 |
180 Element* element() const; | 179 Element* element() const; |
181 PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ensureComputedStyle() co nst; | 180 PassRefPtrWillBeRawPtr<CSSComputedStyleDeclaration> ensureComputedStyle() co nst; |
182 | 181 |
183 // Move up or down the DOM by one position. | 182 // Move up or down the DOM by one position. |
184 // Offsets are computed using layout text for nodes that have layoutObjects - but note that even when | 183 // Offsets are computed using layout text for nodes that have layoutObjects - but note that even when |
185 // using composed characters, the result may be inside a single user-visible character if a ligature is formed. | 184 // using composed characters, the result may be inside a single user-visible character if a ligature is formed. |
186 PositionType previous(PositionMoveType = CodePoint) const; | 185 PositionAlgorithm<Strategy> previous(PositionMoveType = CodePoint) const; |
187 PositionType next(PositionMoveType = CodePoint) const; | 186 PositionAlgorithm<Strategy> next(PositionMoveType = CodePoint) const; |
188 static int uncheckedPreviousOffset(const Node*, int current); | 187 static int uncheckedPreviousOffset(const Node*, int current); |
189 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int curre nt); | 188 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int curre nt); |
190 static int uncheckedNextOffset(const Node*, int current); | 189 static int uncheckedNextOffset(const Node*, int current); |
191 | 190 |
192 int compareTo(const PositionType&) const; | 191 int compareTo(const PositionAlgorithm<Strategy>&) const; |
193 | 192 |
194 // These can be either inside or just before/after the node, depending on | 193 // These can be either inside or just before/after the node, depending on |
195 // if the node is ignored by editing or not. | 194 // if the node is ignored by editing or not. |
196 // FIXME: These should go away. They only make sense for legacy positions. | 195 // FIXME: These should go away. They only make sense for legacy positions. |
197 bool atFirstEditingPositionForNode() const; | 196 bool atFirstEditingPositionForNode() const; |
198 bool atLastEditingPositionForNode() const; | 197 bool atLastEditingPositionForNode() const; |
199 | 198 |
200 // Returns true if the visually equivalent positions around have different e ditability | 199 // Returns true if the visually equivalent positions around have different e ditability |
201 bool atEditingBoundary() const; | 200 bool atEditingBoundary() const; |
202 Node* parentEditingBoundary() const; | 201 Node* parentEditingBoundary() const; |
203 | 202 |
204 bool atStartOfTree() const; | 203 bool atStartOfTree() const; |
205 bool atEndOfTree() const; | 204 bool atEndOfTree() const; |
206 | 205 |
207 // These return useful visually equivalent positions. | 206 // These return useful visually equivalent positions. |
208 PositionType upstream(EditingBoundaryCrossingRule = CannotCrossEditingBounda ry) const; | 207 PositionAlgorithm<Strategy> upstream(EditingBoundaryCrossingRule = CannotCro ssEditingBoundary) const; |
209 PositionType downstream(EditingBoundaryCrossingRule = CannotCrossEditingBoun dary) const; | 208 PositionAlgorithm<Strategy> downstream(EditingBoundaryCrossingRule = CannotC rossEditingBoundary) const; |
210 | 209 |
211 bool isCandidate() const; | 210 bool isCandidate() const; |
212 bool inRenderedText() const; | 211 bool inRenderedText() const; |
213 bool isRenderedCharacter() const; | 212 bool isRenderedCharacter() const; |
214 bool rendersInDifferentPosition(const PositionType&) const; | 213 bool rendersInDifferentPosition(const PositionAlgorithm<Strategy>&) const; |
215 | 214 |
216 void getInlineBoxAndOffset(EAffinity, InlineBox*&, int& caretOffset) const; | 215 void getInlineBoxAndOffset(EAffinity, InlineBox*&, int& caretOffset) const; |
217 void getInlineBoxAndOffset(EAffinity, TextDirection primaryDirection, Inline Box*&, int& caretOffset) const; | 216 void getInlineBoxAndOffset(EAffinity, TextDirection primaryDirection, Inline Box*&, int& caretOffset) const; |
218 | 217 |
219 TextDirection primaryDirection() const; | 218 TextDirection primaryDirection() const; |
220 | 219 |
221 static bool hasRenderedNonAnonymousDescendantsWithHeight(LayoutObject*); | 220 static bool hasRenderedNonAnonymousDescendantsWithHeight(LayoutObject*); |
222 static bool nodeIsUserSelectNone(Node*); | 221 static bool nodeIsUserSelectNone(Node*); |
223 static bool nodeIsUserSelectAll(const Node*); | 222 static bool nodeIsUserSelectAll(const Node*); |
224 static Node* rootUserSelectAllForNode(Node*); | 223 static Node* rootUserSelectAllForNode(Node*); |
225 static PositionType beforeNode(Node* anchorNode); | 224 static PositionAlgorithm<Strategy> beforeNode(Node* anchorNode); |
226 static PositionType afterNode(Node* anchorNode); | 225 static PositionAlgorithm<Strategy> afterNode(Node* anchorNode); |
227 static PositionType inParentBeforeNode(const Node& anchorNode); | 226 static PositionAlgorithm<Strategy> inParentBeforeNode(const Node& anchorNode ); |
228 static PositionType inParentAfterNode(const Node& anchorNode); | 227 static PositionAlgorithm<Strategy> inParentAfterNode(const Node& anchorNode) ; |
229 static int lastOffsetInNode(Node* anchorNode); | 228 static int lastOffsetInNode(Node* anchorNode); |
230 static PositionType firstPositionInNode(Node* anchorNode); | 229 static PositionAlgorithm<Strategy> firstPositionInNode(Node* anchorNode); |
231 static PositionType lastPositionInNode(Node* anchorNode); | 230 static PositionAlgorithm<Strategy> lastPositionInNode(Node* anchorNode); |
232 static int minOffsetForNode(Node* anchorNode, int offset); | 231 static int minOffsetForNode(Node* anchorNode, int offset); |
233 static bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode); | 232 static bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode); |
234 static PositionType firstPositionInOrBeforeNode(Node* anchorNode); | 233 static PositionAlgorithm<Strategy> firstPositionInOrBeforeNode(Node* anchorN ode); |
235 static PositionType lastPositionInOrAfterNode(Node* anchorNode); | 234 static PositionAlgorithm<Strategy> lastPositionInOrAfterNode(Node* anchorNod e); |
236 | 235 |
237 void debugPosition(const char* msg = "") const; | 236 void debugPosition(const char* msg = "") const; |
238 | 237 |
239 #ifndef NDEBUG | 238 #ifndef NDEBUG |
240 void formatForDebugger(char* buffer, unsigned length) const; | 239 void formatForDebugger(char* buffer, unsigned length) const; |
241 void showAnchorTypeAndOffset() const; | 240 void showAnchorTypeAndOffset() const; |
242 void showTreeForThis() const; | 241 void showTreeForThis() const; |
243 void showTreeForThisInComposedTree() const; | 242 void showTreeForThisInComposedTree() const; |
244 #endif | 243 #endif |
245 | 244 |
(...skipping 18 matching lines...) Expand all Loading... | |
264 bool m_isLegacyEditingPosition; | 263 bool m_isLegacyEditingPosition; |
265 }; | 264 }; |
266 | 265 |
267 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingStrat egy>; | 266 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingStrat egy>; |
268 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingInCom posedTreeStrategy>; | 267 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionAlgorithm<EditingInCom posedTreeStrategy>; |
269 | 268 |
270 using Position = PositionAlgorithm<EditingStrategy>; | 269 using Position = PositionAlgorithm<EditingStrategy>; |
271 using PositionInComposedTree = PositionAlgorithm<EditingInComposedTreeStrategy>; | 270 using PositionInComposedTree = PositionAlgorithm<EditingInComposedTreeStrategy>; |
272 | 271 |
273 template <typename Strategy> | 272 template <typename Strategy> |
274 typename Strategy::PositionType PositionAlgorithm<Strategy>::createLegacyEditing Position(PassRefPtrWillBeRawPtr<Node> node, int offset) | 273 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::createLegacyEd itingPosition(PassRefPtrWillBeRawPtr<Node> node, int offset) |
yosin_UTC9
2015/06/26 08:39:24
We don't need to have |typename|.
Apply this comme
yoichio
2015/06/29 06:00:33
Done.
| |
275 { | 274 { |
276 return PositionType(node, PositionAlgorithm::LegacyEditingOffset(offset)); | 275 return PositionAlgorithm<Strategy>(node, PositionAlgorithm::LegacyEditingOff set(offset)); |
277 } | 276 } |
278 | 277 |
279 inline Position createLegacyEditingPosition(PassRefPtrWillBeRawPtr<Node> node, i nt offset) | 278 inline Position createLegacyEditingPosition(PassRefPtrWillBeRawPtr<Node> node, i nt offset) |
280 { | 279 { |
281 return Position::createLegacyEditingPosition(node, offset); | 280 return Position::createLegacyEditingPosition(node, offset); |
282 } | 281 } |
283 | 282 |
284 template <typename Strategy> | 283 template <typename Strategy> |
285 bool operator==(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<St rategy>& b) | 284 bool operator==(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<St rategy>& b) |
286 { | 285 { |
(...skipping 17 matching lines...) Expand all Loading... | |
304 bool operator!=(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<St rategy>& b) | 303 bool operator!=(const PositionAlgorithm<Strategy>& a, const PositionAlgorithm<St rategy>& b) |
305 { | 304 { |
306 return !(a == b); | 305 return !(a == b); |
307 } | 306 } |
308 | 307 |
309 // We define position creation functions to make callsites more readable. | 308 // We define position creation functions to make callsites more readable. |
310 // These are inline to prevent ref-churn when returning a Position object. | 309 // These are inline to prevent ref-churn when returning a Position object. |
311 // If we ever add a PassPosition we can make these non-inline. | 310 // If we ever add a PassPosition we can make these non-inline. |
312 | 311 |
313 template <typename Strategy> | 312 template <typename Strategy> |
314 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentBeforeNode( const Node& node) | 313 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::inParentBefore Node(const Node& node) |
315 { | 314 { |
316 // FIXME: This should ASSERT(node.parentNode()) | 315 // FIXME: This should ASSERT(node.parentNode()) |
317 // At least one caller currently hits this ASSERT though, which indicates | 316 // At least one caller currently hits this ASSERT though, which indicates |
318 // that the caller is trying to make a position relative to a disconnected n ode (which is likely an error) | 317 // that the caller is trying to make a position relative to a disconnected n ode (which is likely an error) |
319 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE RT(node->parentNode()) | 318 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE RT(node->parentNode()) |
320 return PositionType(Strategy::parent(node), Strategy::index(node), PositionI sOffsetInAnchor); | 319 return PositionAlgorithm<Strategy>(Strategy::parent(node), Strategy::index(n ode), PositionIsOffsetInAnchor); |
321 } | 320 } |
322 | 321 |
323 inline Position positionInParentBeforeNode(const Node& node) | 322 inline Position positionInParentBeforeNode(const Node& node) |
324 { | 323 { |
325 return Position::inParentBeforeNode(node); | 324 return Position::inParentBeforeNode(node); |
326 } | 325 } |
327 | 326 |
328 template <typename Strategy> | 327 template <typename Strategy> |
329 typename Strategy::PositionType PositionAlgorithm<Strategy>::inParentAfterNode(c onst Node& node) | 328 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::inParentAfterN ode(const Node& node) |
330 { | 329 { |
331 ASSERT(node.parentNode()); | 330 ASSERT(node.parentNode()); |
332 return PositionType(Strategy::parent(node), Strategy::index(node) + 1, Posit ionIsOffsetInAnchor); | 331 return PositionAlgorithm<Strategy>(Strategy::parent(node), Strategy::index(n ode) + 1, PositionIsOffsetInAnchor); |
333 } | 332 } |
334 | 333 |
335 inline Position positionInParentAfterNode(const Node& node) | 334 inline Position positionInParentAfterNode(const Node& node) |
336 { | 335 { |
337 return Position::inParentAfterNode(node); | 336 return Position::inParentAfterNode(node); |
338 } | 337 } |
339 | 338 |
340 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) | 339 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) |
341 template <typename Strategy> | 340 template <typename Strategy> |
342 typename Strategy::PositionType PositionAlgorithm<Strategy>::beforeNode(Node* an chorNode) | 341 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::beforeNode(Nod e* anchorNode) |
343 { | 342 { |
344 ASSERT(anchorNode); | 343 ASSERT(anchorNode); |
345 return PositionType(anchorNode, PositionIsBeforeAnchor); | 344 return PositionAlgorithm<Strategy>(anchorNode, PositionIsBeforeAnchor); |
346 } | 345 } |
347 | 346 |
348 inline Position positionBeforeNode(Node* anchorNode) | 347 inline Position positionBeforeNode(Node* anchorNode) |
349 { | 348 { |
350 return Position::beforeNode(anchorNode); | 349 return Position::beforeNode(anchorNode); |
351 } | 350 } |
352 | 351 |
353 template <typename Strategy> | 352 template <typename Strategy> |
354 typename Strategy::PositionType PositionAlgorithm<Strategy>::afterNode(Node* anc horNode) | 353 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::afterNode(Node * anchorNode) |
355 { | 354 { |
356 ASSERT(anchorNode); | 355 ASSERT(anchorNode); |
357 return PositionType(anchorNode, PositionIsAfterAnchor); | 356 return PositionAlgorithm<Strategy>(anchorNode, PositionIsAfterAnchor); |
358 } | 357 } |
359 | 358 |
360 inline Position positionAfterNode(Node* anchorNode) | 359 inline Position positionAfterNode(Node* anchorNode) |
361 { | 360 { |
362 return Position::afterNode(anchorNode); | 361 return Position::afterNode(anchorNode); |
363 } | 362 } |
364 | 363 |
365 template <typename Strategy> | 364 template <typename Strategy> |
366 int PositionAlgorithm<Strategy>::lastOffsetInNode(Node* node) | 365 int PositionAlgorithm<Strategy>::lastOffsetInNode(Node* node) |
367 { | 366 { |
368 return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast <int>(Strategy::countChildren(*node)); | 367 return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast <int>(Strategy::countChildren(*node)); |
369 } | 368 } |
370 | 369 |
371 inline int lastOffsetInNode(Node* node) | 370 inline int lastOffsetInNode(Node* node) |
372 { | 371 { |
373 return Position::lastOffsetInNode(node); | 372 return Position::lastOffsetInNode(node); |
374 } | 373 } |
375 | 374 |
376 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildren() | 375 // firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to countChildren() |
377 template <typename Strategy> | 376 template <typename Strategy> |
378 typename Strategy::PositionType PositionAlgorithm<Strategy>::firstPositionInNode (Node* anchorNode) | 377 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::firstPositionI nNode(Node* anchorNode) |
379 { | 378 { |
380 if (anchorNode->isTextNode()) | 379 if (anchorNode->isTextNode()) |
381 return PositionType(anchorNode, 0, PositionIsOffsetInAnchor); | 380 return PositionAlgorithm<Strategy>(anchorNode, 0, PositionIsOffsetInAnch or); |
382 return PositionType(anchorNode, PositionIsBeforeChildren); | 381 return PositionAlgorithm<Strategy>(anchorNode, PositionIsBeforeChildren); |
383 } | 382 } |
384 | 383 |
385 inline Position firstPositionInNode(Node* anchorNode) | 384 inline Position firstPositionInNode(Node* anchorNode) |
386 { | 385 { |
387 return Position::firstPositionInNode(anchorNode); | 386 return Position::firstPositionInNode(anchorNode); |
388 } | 387 } |
389 | 388 |
390 template <typename Strategy> | 389 template <typename Strategy> |
391 typename Strategy::PositionType PositionAlgorithm<Strategy>::lastPositionInNode( Node* anchorNode) | 390 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::lastPositionIn Node(Node* anchorNode) |
392 { | 391 { |
393 if (anchorNode->isTextNode()) | 392 if (anchorNode->isTextNode()) |
394 return PositionType(anchorNode, lastOffsetInNode(anchorNode), PositionIs OffsetInAnchor); | 393 return PositionAlgorithm<Strategy>(anchorNode, lastOffsetInNode(anchorNo de), PositionIsOffsetInAnchor); |
395 return PositionType(anchorNode, PositionIsAfterChildren); | 394 return PositionAlgorithm<Strategy>(anchorNode, PositionIsAfterChildren); |
396 } | 395 } |
397 | 396 |
398 inline Position lastPositionInNode(Node* anchorNode) | 397 inline Position lastPositionInNode(Node* anchorNode) |
399 { | 398 { |
400 return Position::lastPositionInNode(anchorNode); | 399 return Position::lastPositionInNode(anchorNode); |
401 } | 400 } |
402 | 401 |
403 template <typename Strategy> | 402 template <typename Strategy> |
404 int PositionAlgorithm<Strategy>::minOffsetForNode(Node* anchorNode, int offset) | 403 int PositionAlgorithm<Strategy>::minOffsetForNode(Node* anchorNode, int offset) |
405 { | 404 { |
(...skipping 24 matching lines...) Expand all Loading... | |
430 | 429 |
431 return offset < currentOffset; | 430 return offset < currentOffset; |
432 } | 431 } |
433 | 432 |
434 inline bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode) | 433 inline bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode) |
435 { | 434 { |
436 return Position::offsetIsBeforeLastNodeOffset(offset, anchorNode); | 435 return Position::offsetIsBeforeLastNodeOffset(offset, anchorNode); |
437 } | 436 } |
438 | 437 |
439 template <typename Strategy> | 438 template <typename Strategy> |
440 typename Strategy::PositionType PositionAlgorithm<Strategy>::firstPositionInOrBe foreNode(Node* node) | 439 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::firstPositionI nOrBeforeNode(Node* node) |
441 { | 440 { |
442 if (!node) | 441 if (!node) |
443 return PositionType(); | 442 return PositionAlgorithm<Strategy>(); |
444 return Strategy::editingIgnoresContent(node) ? beforeNode(node) : firstPosit ionInNode(node); | 443 return Strategy::editingIgnoresContent(node) ? beforeNode(node) : firstPosit ionInNode(node); |
445 } | 444 } |
446 | 445 |
447 template <typename Strategy> | 446 template <typename Strategy> |
448 typename Strategy::PositionType PositionAlgorithm<Strategy>::lastPositionInOrAft erNode(Node* node) | 447 typename PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::lastPositionIn OrAfterNode(Node* node) |
449 { | 448 { |
450 if (!node) | 449 if (!node) |
451 return PositionType(); | 450 return PositionAlgorithm<Strategy>(); |
452 return Strategy::editingIgnoresContent(node) ? afterNode(node) : lastPositio nInNode(node); | 451 return Strategy::editingIgnoresContent(node) ? afterNode(node) : lastPositio nInNode(node); |
453 } | 452 } |
454 | 453 |
455 PositionInComposedTree toPositionInComposedTree(const Position&); | 454 PositionInComposedTree toPositionInComposedTree(const Position&); |
456 Position toPositionInDOMTree(const PositionInComposedTree&); | 455 Position toPositionInDOMTree(const PositionInComposedTree&); |
457 | 456 |
458 } // namespace blink | 457 } // namespace blink |
459 | 458 |
460 #ifndef NDEBUG | 459 #ifndef NDEBUG |
461 // Outside the WebCore namespace for ease of invocation from gdb. | 460 // Outside the WebCore namespace for ease of invocation from gdb. |
462 void showTree(const blink::Position&); | 461 void showTree(const blink::Position&); |
463 void showTree(const blink::Position*); | 462 void showTree(const blink::Position*); |
464 #endif | 463 #endif |
465 | 464 |
466 #endif // Position_h | 465 #endif // Position_h |
OLD | NEW |