| 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 506 } |
| 507 | 507 |
| 508 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node
Name().utf8().data(), anchorNode(), anchorType, m_offset); | 508 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node
Name().utf8().data(), anchorNode(), anchorType, m_offset); |
| 509 } | 509 } |
| 510 | 510 |
| 511 PositionInFlatTree toPositionInFlatTree(const Position& pos) | 511 PositionInFlatTree toPositionInFlatTree(const Position& pos) |
| 512 { | 512 { |
| 513 if (pos.isNull()) | 513 if (pos.isNull()) |
| 514 return PositionInFlatTree(); | 514 return PositionInFlatTree(); |
| 515 | 515 |
| 516 Node* const anchor = pos.anchorNode(); |
| 516 if (pos.isOffsetInAnchor()) { | 517 if (pos.isOffsetInAnchor()) { |
| 517 Node* anchor = pos.anchorNode(); | |
| 518 if (anchor->isCharacterDataNode()) | 518 if (anchor->isCharacterDataNode()) |
| 519 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()
); | 519 return PositionInFlatTree(anchor, pos.computeOffsetInContainerNode()
); |
| 520 DCHECK(!anchor->isSlotOrActiveInsertionPoint()); | 520 DCHECK(!anchor->isSlotOrActiveInsertionPoint()); |
| 521 int offset = pos.computeOffsetInContainerNode(); | 521 int offset = pos.computeOffsetInContainerNode(); |
| 522 Node* child = NodeTraversal::childAt(*anchor, offset); | 522 Node* child = NodeTraversal::childAt(*anchor, offset); |
| 523 if (!child) { | 523 if (!child) { |
| 524 if (anchor->isShadowRoot()) | 524 if (anchor->isShadowRoot()) |
| 525 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy
pe::AfterChildren); | 525 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorTy
pe::AfterChildren); |
| 526 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren)
; | 526 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren)
; |
| 527 } | 527 } |
| 528 child->updateDistribution(); | 528 child->updateDistribution(); |
| 529 if (child->isSlotOrActiveInsertionPoint()) { | 529 if (child->isSlotOrActiveInsertionPoint()) { |
| 530 if (anchor->isShadowRoot()) | 530 if (anchor->isShadowRoot()) |
| 531 return PositionInFlatTree(anchor->shadowHost(), offset); | 531 return PositionInFlatTree(anchor->shadowHost(), offset); |
| 532 return PositionInFlatTree(anchor, offset); | 532 return PositionInFlatTree(anchor, offset); |
| 533 } | 533 } |
| 534 if (Node* parent = FlatTreeTraversal::parent(*child)) | 534 if (Node* parent = FlatTreeTraversal::parent(*child)) |
| 535 return PositionInFlatTree(parent, FlatTreeTraversal::index(*child)); | 535 return PositionInFlatTree(parent, FlatTreeTraversal::index(*child)); |
| 536 // When |pos| isn't appeared in flat tree, we map |pos| to after | 536 // When |pos| isn't appeared in flat tree, we map |pos| to after |
| 537 // children of shadow host. | 537 // children of shadow host. |
| 538 // e.g. "foo",0 in <progress>foo</progress> | 538 // e.g. "foo",0 in <progress>foo</progress> |
| 539 if (anchor->isShadowRoot()) | 539 if (anchor->isShadowRoot()) |
| 540 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorType::
AfterChildren); | 540 return PositionInFlatTree(anchor->shadowHost(), PositionAnchorType::
AfterChildren); |
| 541 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren); | 541 return PositionInFlatTree(anchor, PositionAnchorType::AfterChildren); |
| 542 } | 542 } |
| 543 | 543 |
| 544 return PositionInFlatTree(pos.anchorNode(), pos.anchorType()); | 544 if (anchor->isShadowRoot()) |
| 545 return PositionInFlatTree(anchor->shadowHost(), pos.anchorType()); |
| 546 // TODO(yosin): Once we have a test case for SLOT or active insertion point, |
| 547 // this function should handle it. |
| 548 return PositionInFlatTree(anchor, pos.anchorType()); |
| 545 } | 549 } |
| 546 | 550 |
| 547 Position toPositionInDOMTree(const Position& position) | 551 Position toPositionInDOMTree(const Position& position) |
| 548 { | 552 { |
| 549 return position; | 553 return position; |
| 550 } | 554 } |
| 551 | 555 |
| 552 Position toPositionInDOMTree(const PositionInFlatTree& position) | 556 Position toPositionInDOMTree(const PositionInFlatTree& position) |
| 553 { | 557 { |
| 554 if (position.isNull()) | 558 if (position.isNull()) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 | 707 |
| 704 void showTree(const blink::Position* pos) | 708 void showTree(const blink::Position* pos) |
| 705 { | 709 { |
| 706 if (pos) | 710 if (pos) |
| 707 pos->showTreeForThis(); | 711 pos->showTreeForThis(); |
| 708 else | 712 else |
| 709 fprintf(stderr, "Cannot showTree for (nil)\n"); | 713 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 710 } | 714 } |
| 711 | 715 |
| 712 #endif | 716 #endif |
| OLD | NEW |