| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 static bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode); | 165 static bool offsetIsBeforeLastNodeOffset(int offset, Node* anchorNode); |
| 166 static PositionTemplate<Strategy> firstPositionInOrBeforeNode(Node* anchorNo
de); | 166 static PositionTemplate<Strategy> firstPositionInOrBeforeNode(Node* anchorNo
de); |
| 167 static PositionTemplate<Strategy> lastPositionInOrAfterNode(Node* anchorNode
); | 167 static PositionTemplate<Strategy> lastPositionInOrAfterNode(Node* anchorNode
); |
| 168 | 168 |
| 169 void debugPosition(const char* msg = "") const; | 169 void debugPosition(const char* msg = "") const; |
| 170 | 170 |
| 171 #ifndef NDEBUG | 171 #ifndef NDEBUG |
| 172 void formatForDebugger(char* buffer, unsigned length) const; | 172 void formatForDebugger(char* buffer, unsigned length) const; |
| 173 void showAnchorTypeAndOffset() const; | 173 void showAnchorTypeAndOffset() const; |
| 174 void showTreeForThis() const; | 174 void showTreeForThis() const; |
| 175 void showTreeForThisInComposedTree() const; | 175 void showTreeForThisInFlatTree() const; |
| 176 #endif | 176 #endif |
| 177 | 177 |
| 178 DEFINE_INLINE_TRACE() | 178 DEFINE_INLINE_TRACE() |
| 179 { | 179 { |
| 180 visitor->trace(m_anchorNode); | 180 visitor->trace(m_anchorNode); |
| 181 } | 181 } |
| 182 | 182 |
| 183 private: | 183 private: |
| 184 bool isAfterAnchorOrAfterChildren() const | 184 bool isAfterAnchorOrAfterChildren() const |
| 185 { | 185 { |
| 186 return isAfterAnchor() || isAfterChildren(); | 186 return isAfterAnchor() || isAfterChildren(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 RefPtrWillBeMember<Node> m_anchorNode; | 189 RefPtrWillBeMember<Node> m_anchorNode; |
| 190 // m_offset can be the offset inside m_anchorNode, or if editingIgnoresConte
nt(m_anchorNode) | 190 // m_offset can be the offset inside m_anchorNode, or if editingIgnoresConte
nt(m_anchorNode) |
| 191 // returns true, then other places in editing will treat m_offset == 0 as "b
efore the anchor" | 191 // returns true, then other places in editing will treat m_offset == 0 as "b
efore the anchor" |
| 192 // and m_offset > 0 as "after the anchor node". See parentAnchoredEquivalen
t for more info. | 192 // and m_offset > 0 as "after the anchor node". See parentAnchoredEquivalen
t for more info. |
| 193 int m_offset; | 193 int m_offset; |
| 194 PositionAnchorType m_anchorType; | 194 PositionAnchorType m_anchorType; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionTemplate<EditingStrate
gy>; | 197 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionTemplate<EditingStrate
gy>; |
| 198 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionTemplate<EditingInComp
osedTreeStrategy>; | 198 extern template class CORE_EXTERN_TEMPLATE_EXPORT PositionTemplate<EditingInFlat
TreeStrategy>; |
| 199 | 199 |
| 200 using Position = PositionTemplate<EditingStrategy>; | 200 using Position = PositionTemplate<EditingStrategy>; |
| 201 using PositionInComposedTree = PositionTemplate<EditingInComposedTreeStrategy>; | 201 using PositionInFlatTree = PositionTemplate<EditingInFlatTreeStrategy>; |
| 202 | 202 |
| 203 template <typename Strategy> | 203 template <typename Strategy> |
| 204 bool operator==(const PositionTemplate<Strategy>& a, const PositionTemplate<Stra
tegy>& b) | 204 bool operator==(const PositionTemplate<Strategy>& a, const PositionTemplate<Stra
tegy>& b) |
| 205 { | 205 { |
| 206 if (a.isNull()) | 206 if (a.isNull()) |
| 207 return b.isNull(); | 207 return b.isNull(); |
| 208 | 208 |
| 209 if (a.anchorNode() != b.anchorNode() || a.anchorType() != b.anchorType()) | 209 if (a.anchorNode() != b.anchorNode() || a.anchorType() != b.anchorType()) |
| 210 return false; | 210 return false; |
| 211 | 211 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 } | 364 } |
| 365 | 365 |
| 366 template <typename Strategy> | 366 template <typename Strategy> |
| 367 PositionTemplate<Strategy> PositionTemplate<Strategy>::lastPositionInOrAfterNode
(Node* node) | 367 PositionTemplate<Strategy> PositionTemplate<Strategy>::lastPositionInOrAfterNode
(Node* node) |
| 368 { | 368 { |
| 369 if (!node) | 369 if (!node) |
| 370 return PositionTemplate<Strategy>(); | 370 return PositionTemplate<Strategy>(); |
| 371 return Strategy::editingIgnoresContent(node) ? afterNode(node) : lastPositio
nInNode(node); | 371 return Strategy::editingIgnoresContent(node) ? afterNode(node) : lastPositio
nInNode(node); |
| 372 } | 372 } |
| 373 | 373 |
| 374 CORE_EXPORT PositionInComposedTree toPositionInComposedTree(const Position&); | 374 CORE_EXPORT PositionInFlatTree toPositionInFlatTree(const Position&); |
| 375 CORE_EXPORT Position toPositionInDOMTree(const Position&); | 375 CORE_EXPORT Position toPositionInDOMTree(const Position&); |
| 376 CORE_EXPORT Position toPositionInDOMTree(const PositionInComposedTree&); | 376 CORE_EXPORT Position toPositionInDOMTree(const PositionInFlatTree&); |
| 377 | 377 |
| 378 template <typename Strategy> | 378 template <typename Strategy> |
| 379 PositionTemplate<Strategy> fromPositionInDOMTree(const Position&); | 379 PositionTemplate<Strategy> fromPositionInDOMTree(const Position&); |
| 380 | 380 |
| 381 template <> | 381 template <> |
| 382 inline Position fromPositionInDOMTree<EditingStrategy>(const Position& position) | 382 inline Position fromPositionInDOMTree<EditingStrategy>(const Position& position) |
| 383 { | 383 { |
| 384 return position; | 384 return position; |
| 385 } | 385 } |
| 386 | 386 |
| 387 template <> | 387 template <> |
| 388 inline PositionInComposedTree fromPositionInDOMTree<EditingInComposedTreeStrateg
y>(const Position& position) | 388 inline PositionInFlatTree fromPositionInDOMTree<EditingInFlatTreeStrategy>(const
Position& position) |
| 389 { | 389 { |
| 390 return toPositionInComposedTree(position); | 390 return toPositionInFlatTree(position); |
| 391 } | 391 } |
| 392 | 392 |
| 393 // These printers are available only for testing in "webkit_unit_tests", and | 393 // These printers are available only for testing in "webkit_unit_tests", and |
| 394 // implemented in "core/testing/CoreTestPrinters.cpp". | 394 // implemented in "core/testing/CoreTestPrinters.cpp". |
| 395 std::ostream& operator<<(std::ostream&, const Node&); | 395 std::ostream& operator<<(std::ostream&, const Node&); |
| 396 std::ostream& operator<<(std::ostream&, const Node*); | 396 std::ostream& operator<<(std::ostream&, const Node*); |
| 397 | 397 |
| 398 std::ostream& operator<<(std::ostream&, PositionAnchorType); | 398 std::ostream& operator<<(std::ostream&, PositionAnchorType); |
| 399 std::ostream& operator<<(std::ostream&, const Position&); | 399 std::ostream& operator<<(std::ostream&, const Position&); |
| 400 std::ostream& operator<<(std::ostream&, const PositionInComposedTree&); | 400 std::ostream& operator<<(std::ostream&, const PositionInFlatTree&); |
| 401 | 401 |
| 402 } // namespace blink | 402 } // namespace blink |
| 403 | 403 |
| 404 #ifndef NDEBUG | 404 #ifndef NDEBUG |
| 405 // Outside the WebCore namespace for ease of invocation from gdb. | 405 // Outside the WebCore namespace for ease of invocation from gdb. |
| 406 void showTree(const blink::Position&); | 406 void showTree(const blink::Position&); |
| 407 void showTree(const blink::Position*); | 407 void showTree(const blink::Position*); |
| 408 #endif | 408 #endif |
| 409 | 409 |
| 410 #endif // Position_h | 410 #endif // Position_h |
| OLD | NEW |