| 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 template <typename Strategy> | 467 template <typename Strategy> |
| 468 PositionTemplate<Strategy> PositionTemplate<Strategy>::BeforeNode( | 468 PositionTemplate<Strategy> PositionTemplate<Strategy>::BeforeNode( |
| 469 const Node& anchor_node) { | 469 const Node& anchor_node) { |
| 470 return PositionTemplate<Strategy>(&anchor_node, | 470 return PositionTemplate<Strategy>(&anchor_node, |
| 471 PositionAnchorType::kBeforeAnchor); | 471 PositionAnchorType::kBeforeAnchor); |
| 472 } | 472 } |
| 473 | 473 |
| 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 Node* anchor_node) { | 477 const Node& anchor_node) { |
| 478 DCHECK(anchor_node); | 478 return PositionTemplate<Strategy>(&anchor_node, |
| 479 return PositionTemplate<Strategy>(anchor_node, | |
| 480 PositionAnchorType::kAfterAnchor); | 479 PositionAnchorType::kAfterAnchor); |
| 481 } | 480 } |
| 482 | 481 |
| 483 // static | 482 // static |
| 484 template <typename Strategy> | 483 template <typename Strategy> |
| 485 int PositionTemplate<Strategy>::LastOffsetInNode(Node* node) { | 484 int PositionTemplate<Strategy>::LastOffsetInNode(Node* node) { |
| 486 return node->IsCharacterDataNode() | 485 return node->IsCharacterDataNode() |
| 487 ? node->MaxCharacterOffset() | 486 ? node->MaxCharacterOffset() |
| 488 : static_cast<int>(Strategy::CountChildren(*node)); | 487 : static_cast<int>(Strategy::CountChildren(*node)); |
| 489 } | 488 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 518 return EditingIgnoresContent(*node) ? BeforeNode(*node) | 517 return EditingIgnoresContent(*node) ? BeforeNode(*node) |
| 519 : FirstPositionInNode(node); | 518 : FirstPositionInNode(node); |
| 520 } | 519 } |
| 521 | 520 |
| 522 // static | 521 // static |
| 523 template <typename Strategy> | 522 template <typename Strategy> |
| 524 PositionTemplate<Strategy> | 523 PositionTemplate<Strategy> |
| 525 PositionTemplate<Strategy>::LastPositionInOrAfterNode(Node* node) { | 524 PositionTemplate<Strategy>::LastPositionInOrAfterNode(Node* node) { |
| 526 if (!node) | 525 if (!node) |
| 527 return PositionTemplate<Strategy>(); | 526 return PositionTemplate<Strategy>(); |
| 528 return EditingIgnoresContent(*node) ? AfterNode(node) | 527 return EditingIgnoresContent(*node) ? AfterNode(*node) |
| 529 : LastPositionInNode(node); | 528 : LastPositionInNode(node); |
| 530 } | 529 } |
| 531 | 530 |
| 532 PositionInFlatTree ToPositionInFlatTree(const Position& pos) { | 531 PositionInFlatTree ToPositionInFlatTree(const Position& pos) { |
| 533 if (pos.IsNull()) | 532 if (pos.IsNull()) |
| 534 return PositionInFlatTree(); | 533 return PositionInFlatTree(); |
| 535 | 534 |
| 536 Node* const anchor = pos.AnchorNode(); | 535 Node* const anchor = pos.AnchorNode(); |
| 537 if (pos.IsOffsetInAnchor()) { | 536 if (pos.IsOffsetInAnchor()) { |
| 538 if (anchor->IsCharacterDataNode()) | 537 if (anchor->IsCharacterDataNode()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 if (position.IsNull()) | 589 if (position.IsNull()) |
| 591 return Position(); | 590 return Position(); |
| 592 | 591 |
| 593 Node* anchor_node = position.AnchorNode(); | 592 Node* anchor_node = position.AnchorNode(); |
| 594 | 593 |
| 595 switch (position.AnchorType()) { | 594 switch (position.AnchorType()) { |
| 596 case PositionAnchorType::kAfterChildren: | 595 case PositionAnchorType::kAfterChildren: |
| 597 // FIXME: When anchorNode is <img>, assertion fails in the constructor. | 596 // FIXME: When anchorNode is <img>, assertion fails in the constructor. |
| 598 return Position(anchor_node, PositionAnchorType::kAfterChildren); | 597 return Position(anchor_node, PositionAnchorType::kAfterChildren); |
| 599 case PositionAnchorType::kAfterAnchor: | 598 case PositionAnchorType::kAfterAnchor: |
| 600 return Position::AfterNode(anchor_node); | 599 return Position::AfterNode(*anchor_node); |
| 601 case PositionAnchorType::kBeforeChildren: | 600 case PositionAnchorType::kBeforeChildren: |
| 602 return Position(anchor_node, PositionAnchorType::kBeforeChildren); | 601 return Position(anchor_node, PositionAnchorType::kBeforeChildren); |
| 603 case PositionAnchorType::kBeforeAnchor: | 602 case PositionAnchorType::kBeforeAnchor: |
| 604 return Position::BeforeNode(*anchor_node); | 603 return Position::BeforeNode(*anchor_node); |
| 605 case PositionAnchorType::kOffsetInAnchor: { | 604 case PositionAnchorType::kOffsetInAnchor: { |
| 606 int offset = position.OffsetInContainerNode(); | 605 int offset = position.OffsetInContainerNode(); |
| 607 if (anchor_node->IsCharacterDataNode()) | 606 if (anchor_node->IsCharacterDataNode()) |
| 608 return Position(anchor_node, offset); | 607 return Position(anchor_node, offset); |
| 609 Node* child = FlatTreeTraversal::ChildAt(*anchor_node, offset); | 608 Node* child = FlatTreeTraversal::ChildAt(*anchor_node, offset); |
| 610 if (child) | 609 if (child) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 714 } |
| 716 | 715 |
| 717 void showTree(const blink::Position* pos) { | 716 void showTree(const blink::Position* pos) { |
| 718 if (pos) | 717 if (pos) |
| 719 pos->ShowTreeForThis(); | 718 pos->ShowTreeForThis(); |
| 720 else | 719 else |
| 721 LOG(INFO) << "Cannot showTree for <null>"; | 720 LOG(INFO) << "Cannot showTree for <null>"; |
| 722 } | 721 } |
| 723 | 722 |
| 724 #endif | 723 #endif |
| OLD | NEW |