Chromium Code Reviews| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 return !(a == b); | 225 return !(a == b); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // We define position creation functions to make callsites more readable. | 228 // We define position creation functions to make callsites more readable. |
| 229 // These are inline to prevent ref-churn when returning a Position object. | 229 // These are inline to prevent ref-churn when returning a Position object. |
| 230 // If we ever add a PassPosition we can make these non-inline. | 230 // If we ever add a PassPosition we can make these non-inline. |
| 231 | 231 |
| 232 template <typename Strategy> | 232 template <typename Strategy> |
| 233 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentBeforeNode(const Node& node) | 233 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentBeforeNode(const Node& node) |
| 234 { | 234 { |
| 235 // FIXME: This should ASSERT(node.parentNode()) | 235 // FIXME: This should DCHECK(node.parentNode()) |
| 236 // At least one caller currently hits this ASSERT though, which indicates | 236 // At least one caller currently hits this ASSERT though, which indicates |
| 237 // that the caller is trying to make a position relative to a disconnected n ode (which is likely an error) | 237 // that the caller is trying to make a position relative to a disconnected n ode (which is likely an error) |
| 238 // Specifically, editing/deleting/delete-ligature-001.html crashes with ASSE RT(node->parentNode()) | 238 // Specifically, editing/deleting/delete-ligature-001.html crashes with DCHE CK(node->parentNode()) |
| 239 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no de)); | 239 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no de)); |
| 240 } | 240 } |
| 241 | 241 |
| 242 inline Position positionInParentBeforeNode(const Node& node) | 242 inline Position positionInParentBeforeNode(const Node& node) |
| 243 { | 243 { |
| 244 return Position::inParentBeforeNode(node); | 244 return Position::inParentBeforeNode(node); |
| 245 } | 245 } |
| 246 | 246 |
| 247 template <typename Strategy> | 247 template <typename Strategy> |
| 248 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentAfterNode(const N ode& node) | 248 PositionTemplate<Strategy> PositionTemplate<Strategy>::inParentAfterNode(const N ode& node) |
| 249 { | 249 { |
| 250 ASSERT(node.parentNode()); | 250 DCHECK(node.parentNode()); |
|
yosin_UTC9
2016/04/14 04:35:00
How about adding |<< node|?
| |
| 251 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no de) + 1); | 251 return PositionTemplate<Strategy>(Strategy::parent(node), Strategy::index(no de) + 1); |
| 252 } | 252 } |
| 253 | 253 |
| 254 inline Position positionInParentAfterNode(const Node& node) | 254 inline Position positionInParentAfterNode(const Node& node) |
| 255 { | 255 { |
| 256 return Position::inParentAfterNode(node); | 256 return Position::inParentAfterNode(node); |
| 257 } | 257 } |
| 258 | 258 |
| 259 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) | 259 // positionBeforeNode and positionAfterNode return neighbor-anchored positions, construction is O(1) |
| 260 template <typename Strategy> | 260 template <typename Strategy> |
| 261 PositionTemplate<Strategy> PositionTemplate<Strategy>::beforeNode(Node* anchorNo de) | 261 PositionTemplate<Strategy> PositionTemplate<Strategy>::beforeNode(Node* anchorNo de) |
| 262 { | 262 { |
| 263 ASSERT(anchorNode); | 263 DCHECK(anchorNode); |
| 264 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeAnch or); | 264 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::BeforeAnch or); |
| 265 } | 265 } |
| 266 | 266 |
| 267 inline Position positionBeforeNode(Node* anchorNode) | 267 inline Position positionBeforeNode(Node* anchorNode) |
| 268 { | 268 { |
| 269 return Position::beforeNode(anchorNode); | 269 return Position::beforeNode(anchorNode); |
| 270 } | 270 } |
| 271 | 271 |
| 272 template <typename Strategy> | 272 template <typename Strategy> |
| 273 PositionTemplate<Strategy> PositionTemplate<Strategy>::afterNode(Node* anchorNod e) | 273 PositionTemplate<Strategy> PositionTemplate<Strategy>::afterNode(Node* anchorNod e) |
| 274 { | 274 { |
| 275 ASSERT(anchorNode); | 275 DCHECK(anchorNode); |
| 276 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho r); | 276 return PositionTemplate<Strategy>(anchorNode, PositionAnchorType::AfterAncho r); |
| 277 } | 277 } |
| 278 | 278 |
| 279 inline Position positionAfterNode(Node* anchorNode) | 279 inline Position positionAfterNode(Node* anchorNode) |
| 280 { | 280 { |
| 281 return Position::afterNode(anchorNode); | 281 return Position::afterNode(anchorNode); |
| 282 } | 282 } |
| 283 | 283 |
| 284 template <typename Strategy> | 284 template <typename Strategy> |
| 285 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node) | 285 int PositionTemplate<Strategy>::lastOffsetInNode(Node* node) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 | 396 |
| 397 } // namespace blink | 397 } // namespace blink |
| 398 | 398 |
| 399 #ifndef NDEBUG | 399 #ifndef NDEBUG |
| 400 // Outside the WebCore namespace for ease of invocation from gdb. | 400 // Outside the WebCore namespace for ease of invocation from gdb. |
| 401 void showTree(const blink::Position&); | 401 void showTree(const blink::Position&); |
| 402 void showTree(const blink::Position*); | 402 void showTree(const blink::Position*); |
| 403 #endif | 403 #endif |
| 404 | 404 |
| 405 #endif // Position_h | 405 #endif // Position_h |
| OLD | NEW |