OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) | 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) |
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) | 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
5 * (C) 2001 Peter Kelly (pmk@post.com) | 5 * (C) 2001 Peter Kelly (pmk@post.com) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r
ights reserved. |
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 for (unsigned i = 0; container && i < offset; i++) | 541 for (unsigned i = 0; container && i < offset; i++) |
542 container = container->nextSibling(); | 542 container = container->nextSibling(); |
543 } else { | 543 } else { |
544 while (container->parentNode() != commonRoot) | 544 while (container->parentNode() != commonRoot) |
545 container = container->parentNode(); | 545 container = container->parentNode(); |
546 } | 546 } |
547 | 547 |
548 return container; | 548 return container; |
549 } | 549 } |
550 | 550 |
551 static inline unsigned lengthOfContentsInNode(Node* node) | |
552 { | |
553 // This switch statement must be consistent with that of Range::processConte
ntsBetweenOffsets. | |
554 switch (node->nodeType()) { | |
555 case Node::TEXT_NODE: | |
556 case Node::CDATA_SECTION_NODE: | |
557 case Node::COMMENT_NODE: | |
558 return toCharacterData(node)->length(); | |
559 case Node::PROCESSING_INSTRUCTION_NODE: | |
560 return toProcessingInstruction(node)->data().length(); | |
561 case Node::ELEMENT_NODE: | |
562 case Node::ATTRIBUTE_NODE: | |
563 case Node::DOCUMENT_NODE: | |
564 case Node::DOCUMENT_FRAGMENT_NODE: | |
565 return toContainerNode(node)->countChildren(); | |
566 case Node::DOCUMENT_TYPE_NODE: | |
567 return 0; | |
568 } | |
569 ASSERT_NOT_REACHED(); | |
570 return 0; | |
571 } | |
572 | |
573 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio
n, ExceptionState& exceptionState) | 551 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio
n, ExceptionState& exceptionState) |
574 { | 552 { |
575 typedef WillBeHeapVector<RefPtrWillBeMember<Node> > NodeVector; | 553 typedef WillBeHeapVector<RefPtrWillBeMember<Node> > NodeVector; |
576 | 554 |
577 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; | 555 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; |
578 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) | 556 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) |
579 fragment = DocumentFragment::create(*m_ownerDocument.get()); | 557 fragment = DocumentFragment::create(*m_ownerDocument.get()); |
580 | 558 |
581 if (collapsed()) | 559 if (collapsed()) |
582 return fragment.release(); | 560 return fragment.release(); |
(...skipping 29 matching lines...) Expand all Loading... |
612 // in which case the last lot of nodes either goes from the first or last | 590 // in which case the last lot of nodes either goes from the first or last |
613 // child of commonRoot. | 591 // child of commonRoot. |
614 // | 592 // |
615 // These are deleted, cloned, or extracted (i.e. both) depending on action. | 593 // These are deleted, cloned, or extracted (i.e. both) depending on action. |
616 | 594 |
617 // Note that we are verifying that our common root hierarchy is still intact | 595 // Note that we are verifying that our common root hierarchy is still intact |
618 // after any DOM mutation event, at various stages below. See webkit bug 603
50. | 596 // after any DOM mutation event, at various stages below. See webkit bug 603
50. |
619 | 597 |
620 RefPtrWillBeRawPtr<Node> leftContents = nullptr; | 598 RefPtrWillBeRawPtr<Node> leftContents = nullptr; |
621 if (originalStart.container() != commonRoot && commonRoot->contains(original
Start.container())) { | 599 if (originalStart.container() != commonRoot && commonRoot->contains(original
Start.container())) { |
622 leftContents = processContentsBetweenOffsets(action, nullptr, originalSt
art.container(), originalStart.offset(), lengthOfContentsInNode(originalStart.co
ntainer()), exceptionState); | 600 leftContents = processContentsBetweenOffsets(action, nullptr, originalSt
art.container(), originalStart.offset(), originalStart.container()->lengthOfCont
ents(), exceptionState); |
623 leftContents = processAncestorsAndTheirSiblings(action, originalStart.co
ntainer(), ProcessContentsForward, leftContents, commonRoot.get(), exceptionStat
e); | 601 leftContents = processAncestorsAndTheirSiblings(action, originalStart.co
ntainer(), ProcessContentsForward, leftContents, commonRoot.get(), exceptionStat
e); |
624 } | 602 } |
625 | 603 |
626 RefPtrWillBeRawPtr<Node> rightContents = nullptr; | 604 RefPtrWillBeRawPtr<Node> rightContents = nullptr; |
627 if (m_end.container() != commonRoot && commonRoot->contains(originalEnd.cont
ainer())) { | 605 if (m_end.container() != commonRoot && commonRoot->contains(originalEnd.cont
ainer())) { |
628 rightContents = processContentsBetweenOffsets(action, nullptr, originalE
nd.container(), 0, originalEnd.offset(), exceptionState); | 606 rightContents = processContentsBetweenOffsets(action, nullptr, originalE
nd.container(), 0, originalEnd.offset(), exceptionState); |
629 rightContents = processAncestorsAndTheirSiblings(action, originalEnd.con
tainer(), ProcessContentsBackward, rightContents, commonRoot.get(), exceptionSta
te); | 607 rightContents = processAncestorsAndTheirSiblings(action, originalEnd.con
tainer(), ProcessContentsBackward, rightContents, commonRoot.get(), exceptionSta
te); |
630 } | 608 } |
631 | 609 |
632 // delete all children of commonRoot between the start and end container | 610 // delete all children of commonRoot between the start and end container |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 if (startOffset) | 658 if (startOffset) |
681 data->deleteData(0, startOffset, exceptionState); | 659 data->deleteData(0, startOffset, exceptionState); |
682 } | 660 } |
683 | 661 |
684 PassRefPtrWillBeRawPtr<Node> Range::processContentsBetweenOffsets(ActionType act
ion, PassRefPtrWillBeRawPtr<DocumentFragment> fragment, | 662 PassRefPtrWillBeRawPtr<Node> Range::processContentsBetweenOffsets(ActionType act
ion, PassRefPtrWillBeRawPtr<DocumentFragment> fragment, |
685 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e
xceptionState) | 663 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e
xceptionState) |
686 { | 664 { |
687 ASSERT(container); | 665 ASSERT(container); |
688 ASSERT(startOffset <= endOffset); | 666 ASSERT(startOffset <= endOffset); |
689 | 667 |
690 // This switch statement must be consistent with that of lengthOfContentsInN
ode. | 668 // This switch statement must be consistent with that of Node::lengthOfConte
nts. |
691 RefPtrWillBeRawPtr<Node> result = nullptr; | 669 RefPtrWillBeRawPtr<Node> result = nullptr; |
692 switch (container->nodeType()) { | 670 switch (container->nodeType()) { |
693 case Node::TEXT_NODE: | 671 case Node::TEXT_NODE: |
694 case Node::CDATA_SECTION_NODE: | 672 case Node::CDATA_SECTION_NODE: |
695 case Node::COMMENT_NODE: | 673 case Node::COMMENT_NODE: |
696 endOffset = std::min(endOffset, toCharacterData(container)->length()); | 674 endOffset = std::min(endOffset, toCharacterData(container)->length()); |
697 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 675 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
698 RefPtrWillBeRawPtr<CharacterData> c = static_pointer_cast<CharacterD
ata>(container->cloneNode(true)); | 676 RefPtrWillBeRawPtr<CharacterData> c = static_pointer_cast<CharacterD
ata>(container->cloneNode(true)); |
699 deleteCharacterData(c, startOffset, endOffset, exceptionState); | 677 deleteCharacterData(c, startOffset, endOffset, exceptionState); |
700 if (fragment) { | 678 if (fragment) { |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 | 1672 |
1695 void showTree(const WebCore::Range* range) | 1673 void showTree(const WebCore::Range* range) |
1696 { | 1674 { |
1697 if (range && range->boundaryPointsValid()) { | 1675 if (range && range->boundaryPointsValid()) { |
1698 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1676 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
1699 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1677 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
1700 } | 1678 } |
1701 } | 1679 } |
1702 | 1680 |
1703 #endif | 1681 #endif |
OLD | NEW |