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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 bool isBeforeAnchor() const { | 87 bool isBeforeAnchor() const { |
88 return m_anchorType == PositionAnchorType::BeforeAnchor; | 88 return m_anchorType == PositionAnchorType::BeforeAnchor; |
89 } | 89 } |
90 bool isBeforeChildren() const { | 90 bool isBeforeChildren() const { |
91 return m_anchorType == PositionAnchorType::BeforeChildren; | 91 return m_anchorType == PositionAnchorType::BeforeChildren; |
92 } | 92 } |
93 bool isOffsetInAnchor() const { | 93 bool isOffsetInAnchor() const { |
94 return m_anchorType == PositionAnchorType::OffsetInAnchor; | 94 return m_anchorType == PositionAnchorType::OffsetInAnchor; |
95 } | 95 } |
96 | 96 |
97 // These are always DOM compliant values. Editing positions like [img, 0] (ak
a [img, before]) | 97 // These are always DOM compliant values. Editing positions like [img, 0] |
98 // will return img->parentNode() and img->nodeIndex() from these functions. | 98 // (aka [img, before]) will return img->parentNode() and img->nodeIndex() from |
99 Node* computeContainerNode() | 99 // these functions. |
100 const; // null for a before/after position anchored to a node with no par
ent | |
101 | 100 |
102 int computeOffsetInContainerNode() | 101 // null for a before/after position anchored to a node with no parent |
103 const; // O(n) for before/after-anchored positions, O(1) for parent-ancho
red positions | 102 Node* computeContainerNode() const; |
104 PositionTemplate<Strategy> parentAnchoredEquivalent() | 103 |
105 const; // Convenience method for DOM positions that also fixes up some po
sitions for editing | 104 // O(n) for before/after-anchored positions, O(1) for parent-anchored |
| 105 // positions |
| 106 int computeOffsetInContainerNode() const; |
| 107 |
| 108 // Convenience method for DOM positions that also fixes up some positions for |
| 109 // editing |
| 110 PositionTemplate<Strategy> parentAnchoredEquivalent() const; |
106 | 111 |
107 // Returns |PositionIsAnchor| type |Position| which is compatible with | 112 // Returns |PositionIsAnchor| type |Position| which is compatible with |
108 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value | 113 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value |
109 // of this function is different from |parentAnchoredEquivalent()| which | 114 // of this function is different from |parentAnchoredEquivalent()| which |
110 // returns editing specific position. | 115 // returns editing specific position. |
111 PositionTemplate<Strategy> toOffsetInAnchor() const; | 116 PositionTemplate<Strategy> toOffsetInAnchor() const; |
112 | 117 |
113 // Inline O(1) access for Positions which callers know to be parent-anchored | 118 // Inline O(1) access for Positions which callers know to be parent-anchored |
114 int offsetInContainerNode() const { | 119 int offsetInContainerNode() const { |
115 DCHECK(isOffsetInAnchor()); | 120 DCHECK(isOffsetInAnchor()); |
116 return m_offset; | 121 return m_offset; |
117 } | 122 } |
118 | 123 |
119 // Returns an offset for editing based on anchor type for using with | 124 // Returns an offset for editing based on anchor type for using with |
120 // |anchorNode()| function: | 125 // |anchorNode()| function: |
121 // - OffsetInAnchor m_offset | 126 // - OffsetInAnchor m_offset |
122 // - BeforeChildren 0 | 127 // - BeforeChildren 0 |
123 // - BeforeAnchor 0 | 128 // - BeforeAnchor 0 |
124 // - AfterChildren last editing offset in anchor node | 129 // - AfterChildren last editing offset in anchor node |
125 // - AfterAnchor last editing offset in anchor node | 130 // - AfterAnchor last editing offset in anchor node |
126 // Editing operations will change in anchor node rather than nodes around | 131 // Editing operations will change in anchor node rather than nodes around |
127 // anchor node. | 132 // anchor node. |
128 int computeEditingOffset() const; | 133 int computeEditingOffset() const; |
129 | 134 |
130 // These are convenience methods which are smart about whether the position is
neighbor anchored or parent anchored | 135 // These are convenience methods which are smart about whether the position is |
| 136 // neighbor anchored or parent anchored |
131 Node* computeNodeBeforePosition() const; | 137 Node* computeNodeBeforePosition() const; |
132 Node* computeNodeAfterPosition() const; | 138 Node* computeNodeAfterPosition() const; |
133 | 139 |
134 // Returns node as |Range::firstNode()|. This position must be a | 140 // Returns node as |Range::firstNode()|. This position must be a |
135 // |PositionAnchorType::OffsetInAhcor| to behave as |Range| boundary point. | 141 // |PositionAnchorType::OffsetInAhcor| to behave as |Range| boundary point. |
136 Node* nodeAsRangeFirstNode() const; | 142 Node* nodeAsRangeFirstNode() const; |
137 | 143 |
138 // Similar to |nodeAsRangeLastNode()|, but returns a node in a range. | 144 // Similar to |nodeAsRangeLastNode()|, but returns a node in a range. |
139 Node* nodeAsRangeLastNode() const; | 145 Node* nodeAsRangeLastNode() const; |
140 | 146 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 #endif | 203 #endif |
198 | 204 |
199 DEFINE_INLINE_TRACE() { visitor->trace(m_anchorNode); } | 205 DEFINE_INLINE_TRACE() { visitor->trace(m_anchorNode); } |
200 | 206 |
201 private: | 207 private: |
202 bool isAfterAnchorOrAfterChildren() const { | 208 bool isAfterAnchorOrAfterChildren() const { |
203 return isAfterAnchor() || isAfterChildren(); | 209 return isAfterAnchor() || isAfterChildren(); |
204 } | 210 } |
205 | 211 |
206 Member<Node> m_anchorNode; | 212 Member<Node> m_anchorNode; |
207 // m_offset can be the offset inside m_anchorNode, or if editingIgnoresContent
(m_anchorNode) | 213 // m_offset can be the offset inside m_anchorNode, or if |
208 // returns true, then other places in editing will treat m_offset == 0 as "bef
ore the anchor" | 214 // editingIgnoresContent(m_anchorNode) returns true, then other places in |
209 // and m_offset > 0 as "after the anchor node". See parentAnchoredEquivalent
for more info. | 215 // editing will treat m_offset == 0 as "before the anchor" and m_offset > 0 as |
| 216 // "after the anchor node". See parentAnchoredEquivalent for more info. |
210 int m_offset; | 217 int m_offset; |
211 PositionAnchorType m_anchorType; | 218 PositionAnchorType m_anchorType; |
212 }; | 219 }; |
213 | 220 |
214 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 221 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
215 PositionTemplate<EditingStrategy>; | 222 PositionTemplate<EditingStrategy>; |
216 extern template class CORE_EXTERN_TEMPLATE_EXPORT | 223 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
217 PositionTemplate<EditingInFlatTreeStrategy>; | 224 PositionTemplate<EditingInFlatTreeStrategy>; |
218 | 225 |
219 using Position = PositionTemplate<EditingStrategy>; | 226 using Position = PositionTemplate<EditingStrategy>; |
220 using PositionInFlatTree = PositionTemplate<EditingInFlatTreeStrategy>; | 227 using PositionInFlatTree = PositionTemplate<EditingInFlatTreeStrategy>; |
221 | 228 |
222 template <typename Strategy> | 229 template <typename Strategy> |
223 bool operator==(const PositionTemplate<Strategy>& a, | 230 bool operator==(const PositionTemplate<Strategy>& a, |
224 const PositionTemplate<Strategy>& b) { | 231 const PositionTemplate<Strategy>& b) { |
225 if (a.isNull()) | 232 if (a.isNull()) |
226 return b.isNull(); | 233 return b.isNull(); |
227 | 234 |
228 if (a.anchorNode() != b.anchorNode() || a.anchorType() != b.anchorType()) | 235 if (a.anchorNode() != b.anchorNode() || a.anchorType() != b.anchorType()) |
229 return false; | 236 return false; |
230 | 237 |
231 if (!a.isOffsetInAnchor()) { | 238 if (!a.isOffsetInAnchor()) { |
232 // Note: |m_offset| only has meaning when |PositionAnchorType::OffsetInAncho
r|. | 239 // Note: |m_offset| only has meaning when |
| 240 // |PositionAnchorType::OffsetInAnchor|. |
233 return true; | 241 return true; |
234 } | 242 } |
235 | 243 |
236 // FIXME: In <div><img></div> [div, 0] != [img, 0] even though most of the | 244 // FIXME: In <div><img></div> [div, 0] != [img, 0] even though most of the |
237 // editing code will treat them as identical. | 245 // editing code will treat them as identical. |
238 return a.offsetInContainerNode() == b.offsetInContainerNode(); | 246 return a.offsetInContainerNode() == b.offsetInContainerNode(); |
239 } | 247 } |
240 | 248 |
241 template <typename Strategy> | 249 template <typename Strategy> |
242 bool operator!=(const PositionTemplate<Strategy>& a, | 250 bool operator!=(const PositionTemplate<Strategy>& a, |
(...skipping 26 matching lines...) Expand all Loading... |
269 | 277 |
270 } // namespace blink | 278 } // namespace blink |
271 | 279 |
272 #ifndef NDEBUG | 280 #ifndef NDEBUG |
273 // Outside the WebCore namespace for ease of invocation from gdb. | 281 // Outside the WebCore namespace for ease of invocation from gdb. |
274 void showTree(const blink::Position&); | 282 void showTree(const blink::Position&); |
275 void showTree(const blink::Position*); | 283 void showTree(const blink::Position*); |
276 #endif | 284 #endif |
277 | 285 |
278 #endif // Position_h | 286 #endif // Position_h |
OLD | NEW |