| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 93 |
| 94 // Returns |PositionIsAnchor| type |Position| which is compatible with | 94 // Returns |PositionIsAnchor| type |Position| which is compatible with |
| 95 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value | 95 // |RangeBoundaryPoint| as safe to pass |Range| constructor. Return value |
| 96 // of this function is different from |parentAnchoredEquivalent()| which | 96 // of this function is different from |parentAnchoredEquivalent()| which |
| 97 // returns editing specific position. | 97 // returns editing specific position. |
| 98 PositionTemplate<Strategy> toOffsetInAnchor() const; | 98 PositionTemplate<Strategy> toOffsetInAnchor() const; |
| 99 | 99 |
| 100 // Inline O(1) access for Positions which callers know to be parent-anchored | 100 // Inline O(1) access for Positions which callers know to be parent-anchored |
| 101 int offsetInContainerNode() const | 101 int offsetInContainerNode() const |
| 102 { | 102 { |
| 103 ASSERT(isOffsetInAnchor()); | 103 DCHECK(isOffsetInAnchor()); |
| 104 return m_offset; | 104 return m_offset; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Returns an offset for editing based on anchor type for using with | 107 // Returns an offset for editing based on anchor type for using with |
| 108 // |anchorNode()| function: | 108 // |anchorNode()| function: |
| 109 // - OffsetInAnchor m_offset | 109 // - OffsetInAnchor m_offset |
| 110 // - BeforeChildren 0 | 110 // - BeforeChildren 0 |
| 111 // - BeforeAnchor 0 | 111 // - BeforeAnchor 0 |
| 112 // - AfterChildren last editing offset in anchor node | 112 // - AfterChildren last editing offset in anchor node |
| 113 // - AfterAnchor last editing offset in anchor node | 113 // - AfterAnchor last editing offset in anchor node |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return !(a == b); | 233 return !(a == b); |
| 234 } | 234 } |
| 235 | 235 |
| 236 // We define position creation functions to make callsites more readable. | 236 // We define position creation functions to make callsites more readable. |
| 237 // These are inline to prevent ref-churn when returning a Position object. | 237 // These are inline to prevent ref-churn when returning a Position object. |
| 238 // If we ever add a PassPosition we can make these non-inline. | 238 // If we ever add a PassPosition we can make these non-inline. |
| 239 | 239 |
| 240 template <typename Strategy> | 240 template <typename Strategy> |
| 241 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentBeforeNode(const
Node& node) | 241 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentBeforeNode(const
Node& node) |
| 242 { | 242 { |
| 243 // FIXME: This should ASSERT(node.parentNode()) | 243 // FIXME: This should DCHECK(node.parentNode()) |
| 244 // At least one caller currently hits this ASSERT though, which indicates | 244 // At least one caller currently hits this ASSERT though, which indicates |
| 245 // that the caller is trying to make a position relative to a disconnected n
ode (which is likely an error) | 245 // that the caller is trying to make a position relative to a disconnected n
ode (which is likely an error) |
| 246 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE
RT(node->parentNode()) | 246 // Specifically, editing/deleting/delete-ligature-001.html crashes with DCHE
CK(node->parentNode()) |
| 247 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no
de)); | 247 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no
de)); |
| 248 } | 248 } |
| 249 | 249 |
| 250 inline Position positionInParentBeforeNode(const Node& node) | 250 inline Position positionInParentBeforeNode(const Node& node) |
| 251 { | 251 { |
| 252 return Position::inParentBeforeNode(node); | 252 return Position::inParentBeforeNode(node); |
| 253 } | 253 } |
| 254 | 254 |
| 255 template <typename Strategy> | 255 template <typename Strategy> |
| 256 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentAfterNode(const N
ode& node) | 256 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentAfterNode(const N
ode& node) |
| 257 { | 257 { |
| 258 ASSERT(node.parentNode()); | 258 DCHECK(node.parentNode()) << node; |
| 259 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no
de) + 1); | 259 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no
de) + 1); |
| 260 } | 260 } |
| 261 | 261 |
| 262 inline Position positionInParentAfterNode(const Node& node) | 262 inline Position positionInParentAfterNode(const Node& node) |
| 263 { | 263 { |
| 264 return Position::inParentAfterNode(node); | 264 return Position::inParentAfterNode(node); |
| 265 } | 265 } |
| 266 | 266 |
| 267 // positionBeforeNode and positionAfterNode return neighbor-anchored positions,
construction is O(1) | 267 // positionBeforeNode and positionAfterNode return neighbor-anchored positions,
construction is O(1) |
| 268 template <typename Strategy> | 268 template <typename Strategy> |
| 269 PositionTemplate<Strategy> PositionTemplate<Strategy>::beforeNode(Node* anchorNo
de) | 269 PositionTemplate<Strategy> PositionTemplate<Strategy>::beforeNode(Node* anchorNo
de) |
| 270 { | 270 { |
| 271 ASSERT(anchorNode); | 271 DCHECK(anchorNode); |
| 272 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeAnch
or); | 272 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeAnch
or); |
| 273 } | 273 } |
| 274 | 274 |
| 275 inline Position positionBeforeNode(Node* anchorNode) | 275 inline Position positionBeforeNode(Node* anchorNode) |
| 276 { | 276 { |
| 277 return Position::beforeNode(anchorNode); | 277 return Position::beforeNode(anchorNode); |
| 278 } | 278 } |
| 279 | 279 |
| 280 template <typename Strategy> | 280 template <typename Strategy> |
| 281 PositionTemplate<Strategy> PositionTemplate<Strategy>::afterNode(Node* anchorNod
e) | 281 PositionTemplate<Strategy> PositionTemplate<Strategy>::afterNode(Node* anchorNod
e) |
| 282 { | 282 { |
| 283 ASSERT(anchorNode); | 283 DCHECK(anchorNode); |
| 284 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho
r); | 284 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho
r); |
| 285 } | 285 } |
| 286 | 286 |
| 287 inline Position positionAfterNode(Node* anchorNode) | 287 inline Position positionAfterNode(Node* anchorNode) |
| 288 { | 288 { |
| 289 return Position::afterNode(anchorNode); | 289 return Position::afterNode(anchorNode); |
| 290 } | 290 } |
| 291 | 291 |
| 292 template <typename Strategy> | 292 template <typename Strategy> |
| 293 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node) | 293 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 } // namespace blink | 405 } // namespace blink |
| 406 | 406 |
| 407 #ifndef NDEBUG | 407 #ifndef NDEBUG |
| 408 // Outside the WebCore namespace for ease of invocation from gdb. | 408 // Outside the WebCore namespace for ease of invocation from gdb. |
| 409 void showTree(const blink::Position&); | 409 void showTree(const blink::Position&); |
| 410 void showTree(const blink::Position*); | 410 void showTree(const blink::Position*); |
| 411 #endif | 411 #endif |
| 412 | 412 |
| 413 #endif // Position_h | 413 #endif // Position_h |
| OLD | NEW |