| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 181 |
| 182 template <typename Strategy> | 182 template <typename Strategy> |
| 183 int PositionTemplate<Strategy>::ComputeOffsetInContainerNode() const { | 183 int PositionTemplate<Strategy>::ComputeOffsetInContainerNode() const { |
| 184 if (!anchor_node_) | 184 if (!anchor_node_) |
| 185 return 0; | 185 return 0; |
| 186 | 186 |
| 187 switch (AnchorType()) { | 187 switch (AnchorType()) { |
| 188 case PositionAnchorType::kBeforeChildren: | 188 case PositionAnchorType::kBeforeChildren: |
| 189 return 0; | 189 return 0; |
| 190 case PositionAnchorType::kAfterChildren: | 190 case PositionAnchorType::kAfterChildren: |
| 191 return LastOffsetInNode(anchor_node_.Get()); | 191 return LastOffsetInNode(*anchor_node_); |
| 192 case PositionAnchorType::kOffsetInAnchor: | 192 case PositionAnchorType::kOffsetInAnchor: |
| 193 return MinOffsetForNode<Strategy>(anchor_node_.Get(), offset_); | 193 return MinOffsetForNode<Strategy>(anchor_node_.Get(), offset_); |
| 194 case PositionAnchorType::kBeforeAnchor: | 194 case PositionAnchorType::kBeforeAnchor: |
| 195 return Strategy::Index(*anchor_node_); | 195 return Strategy::Index(*anchor_node_); |
| 196 case PositionAnchorType::kAfterAnchor: | 196 case PositionAnchorType::kAfterAnchor: |
| 197 return Strategy::Index(*anchor_node_) + 1; | 197 return Strategy::Index(*anchor_node_) + 1; |
| 198 } | 198 } |
| 199 NOTREACHED(); | 199 NOTREACHED(); |
| 200 return 0; | 200 return 0; |
| 201 } | 201 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // static | 474 // static |
| 475 template <typename Strategy> | 475 template <typename Strategy> |
| 476 PositionTemplate<Strategy> PositionTemplate<Strategy>::AfterNode( | 476 PositionTemplate<Strategy> PositionTemplate<Strategy>::AfterNode( |
| 477 const Node& anchor_node) { | 477 const Node& anchor_node) { |
| 478 return PositionTemplate<Strategy>(&anchor_node, | 478 return PositionTemplate<Strategy>(&anchor_node, |
| 479 PositionAnchorType::kAfterAnchor); | 479 PositionAnchorType::kAfterAnchor); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // static | 482 // static |
| 483 template <typename Strategy> | 483 template <typename Strategy> |
| 484 int PositionTemplate<Strategy>::LastOffsetInNode(Node* node) { | 484 int PositionTemplate<Strategy>::LastOffsetInNode(const Node& node) { |
| 485 return node->IsCharacterDataNode() | 485 return node.IsCharacterDataNode() |
| 486 ? node->MaxCharacterOffset() | 486 ? node.MaxCharacterOffset() |
| 487 : static_cast<int>(Strategy::CountChildren(*node)); | 487 : static_cast<int>(Strategy::CountChildren(node)); |
| 488 } | 488 } |
| 489 | 489 |
| 490 // static | 490 // static |
| 491 template <typename Strategy> | 491 template <typename Strategy> |
| 492 PositionTemplate<Strategy> PositionTemplate<Strategy>::FirstPositionInNode( | 492 PositionTemplate<Strategy> PositionTemplate<Strategy>::FirstPositionInNode( |
| 493 const Node& anchor_node) { | 493 const Node& anchor_node) { |
| 494 if (anchor_node.IsTextNode()) | 494 if (anchor_node.IsTextNode()) |
| 495 return PositionTemplate<Strategy>(anchor_node, 0); | 495 return PositionTemplate<Strategy>(anchor_node, 0); |
| 496 return PositionTemplate<Strategy>(&anchor_node, | 496 return PositionTemplate<Strategy>(&anchor_node, |
| 497 PositionAnchorType::kBeforeChildren); | 497 PositionAnchorType::kBeforeChildren); |
| 498 } | 498 } |
| 499 | 499 |
| 500 // static | 500 // static |
| 501 template <typename Strategy> | 501 template <typename Strategy> |
| 502 PositionTemplate<Strategy> PositionTemplate<Strategy>::LastPositionInNode( | 502 PositionTemplate<Strategy> PositionTemplate<Strategy>::LastPositionInNode( |
| 503 Node* anchor_node) { | 503 Node* anchor_node) { |
| 504 if (anchor_node->IsTextNode()) | 504 if (anchor_node->IsTextNode()) { |
| 505 return PositionTemplate<Strategy>(anchor_node, | 505 return PositionTemplate<Strategy>(anchor_node, |
| 506 LastOffsetInNode(anchor_node)); | 506 LastOffsetInNode(*anchor_node)); |
| 507 } |
| 507 return PositionTemplate<Strategy>(anchor_node, | 508 return PositionTemplate<Strategy>(anchor_node, |
| 508 PositionAnchorType::kAfterChildren); | 509 PositionAnchorType::kAfterChildren); |
| 509 } | 510 } |
| 510 | 511 |
| 511 // static | 512 // static |
| 512 template <typename Strategy> | 513 template <typename Strategy> |
| 513 PositionTemplate<Strategy> | 514 PositionTemplate<Strategy> |
| 514 PositionTemplate<Strategy>::FirstPositionInOrBeforeNode(Node* node) { | 515 PositionTemplate<Strategy>::FirstPositionInOrBeforeNode(Node* node) { |
| 515 if (!node) | 516 if (!node) |
| 516 return PositionTemplate<Strategy>(); | 517 return PositionTemplate<Strategy>(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } | 715 } |
| 715 | 716 |
| 716 void showTree(const blink::Position* pos) { | 717 void showTree(const blink::Position* pos) { |
| 717 if (pos) | 718 if (pos) |
| 718 pos->ShowTreeForThis(); | 719 pos->ShowTreeForThis(); |
| 719 else | 720 else |
| 720 LOG(INFO) << "Cannot showTree for <null>"; | 721 LOG(INFO) << "Cannot showTree for <null>"; |
| 721 } | 722 } |
| 722 | 723 |
| 723 #endif | 724 #endif |
| OLD | NEW |