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 | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 8 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
9 * | 9 * |
10 * This library is free software; you can redistribute it and/or | 10 * This library is free software; you can redistribute it and/or |
11 * modify it under the terms of the GNU Library General Public | 11 * modify it under the terms of the GNU Library General Public |
12 * License as published by the Free Software Foundation; either | 12 * License as published by the Free Software Foundation; either |
13 * version 2 of the License, or (at your option) any later version. | 13 * version 2 of the License, or (at your option) any later version. |
14 * | 14 * |
15 * This library is distributed in the hope that it will be useful, | 15 * This library is distributed in the hope that it will be useful, |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18 * Library General Public License for more details. | 18 * Library General Public License for more details. |
19 * | 19 * |
20 * You should have received a copy of the GNU Library General Public License | 20 * You should have received a copy of the GNU Library General Public License |
21 * along with this library; see the file COPYING.LIB. If not, write to | 21 * along with this library; see the file COPYING.LIB. If not, write to |
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 * Boston, MA 02110-1301, USA. | 23 * Boston, MA 02110-1301, USA. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/dom/Range.h" | 26 #include "core/dom/Range.h" |
27 | 27 |
28 #include "bindings/core/v8/ExceptionState.h" | 28 #include "bindings/core/v8/ExceptionState.h" |
| 29 #include "core/dom/CharacterData.h" |
29 #include "core/dom/ClientRect.h" | 30 #include "core/dom/ClientRect.h" |
30 #include "core/dom/ClientRectList.h" | 31 #include "core/dom/ClientRectList.h" |
| 32 #include "core/dom/ContainerNode.h" |
31 #include "core/dom/DocumentFragment.h" | 33 #include "core/dom/DocumentFragment.h" |
32 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
33 #include "core/dom/Node.h" | 35 #include "core/dom/Node.h" |
34 #include "core/dom/NodeTraversal.h" | 36 #include "core/dom/NodeTraversal.h" |
35 #include "core/dom/NodeWithIndex.h" | 37 #include "core/dom/NodeWithIndex.h" |
36 #include "core/dom/ProcessingInstruction.h" | 38 #include "core/dom/ProcessingInstruction.h" |
37 #include "core/dom/Text.h" | 39 #include "core/dom/Text.h" |
38 #include "core/editing/EditingUtilities.h" | 40 #include "core/editing/EditingUtilities.h" |
39 #include "core/editing/EphemeralRange.h" | 41 #include "core/editing/EphemeralRange.h" |
40 #include "core/editing/FrameSelection.h" | 42 #include "core/editing/FrameSelection.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 for (unsigned i = 0; container && i < offset; i++) | 523 for (unsigned i = 0; container && i < offset; i++) |
522 container = container->nextSibling(); | 524 container = container->nextSibling(); |
523 } else { | 525 } else { |
524 while (container->parentNode() != commonRoot) | 526 while (container->parentNode() != commonRoot) |
525 container = container->parentNode(); | 527 container = container->parentNode(); |
526 } | 528 } |
527 | 529 |
528 return container; | 530 return container; |
529 } | 531 } |
530 | 532 |
| 533 static unsigned lengthOfContents(const Node* node) { |
| 534 // This switch statement must be consistent with that of |
| 535 // Range::processContentsBetweenOffsets. |
| 536 switch (node->getNodeType()) { |
| 537 case Node::kTextNode: |
| 538 case Node::kCdataSectionNode: |
| 539 case Node::kCommentNode: |
| 540 case Node::kProcessingInstructionNode: |
| 541 return toCharacterData(node)->length(); |
| 542 case Node::kElementNode: |
| 543 case Node::kDocumentNode: |
| 544 case Node::kDocumentFragmentNode: |
| 545 return toContainerNode(node)->countChildren(); |
| 546 case Node::kAttributeNode: |
| 547 case Node::kDocumentTypeNode: |
| 548 return 0; |
| 549 } |
| 550 NOTREACHED(); |
| 551 return 0; |
| 552 } |
| 553 |
531 DocumentFragment* Range::processContents(ActionType action, | 554 DocumentFragment* Range::processContents(ActionType action, |
532 ExceptionState& exceptionState) { | 555 ExceptionState& exceptionState) { |
533 typedef HeapVector<Member<Node>> NodeVector; | 556 typedef HeapVector<Member<Node>> NodeVector; |
534 | 557 |
535 DocumentFragment* fragment = nullptr; | 558 DocumentFragment* fragment = nullptr; |
536 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) | 559 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) |
537 fragment = DocumentFragment::create(*m_ownerDocument.get()); | 560 fragment = DocumentFragment::create(*m_ownerDocument.get()); |
538 | 561 |
539 if (collapsed()) | 562 if (collapsed()) |
540 return fragment; | 563 return fragment; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 | 603 |
581 // Note that we are verifying that our common root hierarchy is still intact | 604 // Note that we are verifying that our common root hierarchy is still intact |
582 // after any DOM mutation event, at various stages below. See webkit bug | 605 // after any DOM mutation event, at various stages below. See webkit bug |
583 // 60350. | 606 // 60350. |
584 | 607 |
585 Node* leftContents = nullptr; | 608 Node* leftContents = nullptr; |
586 if (originalStart.container() != commonRoot && | 609 if (originalStart.container() != commonRoot && |
587 commonRoot->contains(originalStart.container())) { | 610 commonRoot->contains(originalStart.container())) { |
588 leftContents = processContentsBetweenOffsets( | 611 leftContents = processContentsBetweenOffsets( |
589 action, nullptr, originalStart.container(), originalStart.offset(), | 612 action, nullptr, originalStart.container(), originalStart.offset(), |
590 originalStart.container()->lengthOfContents(), exceptionState); | 613 lengthOfContents(originalStart.container()), exceptionState); |
591 leftContents = processAncestorsAndTheirSiblings( | 614 leftContents = processAncestorsAndTheirSiblings( |
592 action, originalStart.container(), ProcessContentsForward, leftContents, | 615 action, originalStart.container(), ProcessContentsForward, leftContents, |
593 commonRoot, exceptionState); | 616 commonRoot, exceptionState); |
594 } | 617 } |
595 | 618 |
596 Node* rightContents = nullptr; | 619 Node* rightContents = nullptr; |
597 if (m_end.container() != commonRoot && | 620 if (m_end.container() != commonRoot && |
598 commonRoot->contains(originalEnd.container())) { | 621 commonRoot->contains(originalEnd.container())) { |
599 rightContents = | 622 rightContents = |
600 processContentsBetweenOffsets(action, nullptr, originalEnd.container(), | 623 processContentsBetweenOffsets(action, nullptr, originalEnd.container(), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 Node* Range::processContentsBetweenOffsets(ActionType action, | 691 Node* Range::processContentsBetweenOffsets(ActionType action, |
669 DocumentFragment* fragment, | 692 DocumentFragment* fragment, |
670 Node* container, | 693 Node* container, |
671 unsigned startOffset, | 694 unsigned startOffset, |
672 unsigned endOffset, | 695 unsigned endOffset, |
673 ExceptionState& exceptionState) { | 696 ExceptionState& exceptionState) { |
674 DCHECK(container); | 697 DCHECK(container); |
675 DCHECK_LE(startOffset, endOffset); | 698 DCHECK_LE(startOffset, endOffset); |
676 | 699 |
677 // This switch statement must be consistent with that of | 700 // This switch statement must be consistent with that of |
678 // Node::lengthOfContents. | 701 // lengthOfContents. |
679 Node* result = nullptr; | 702 Node* result = nullptr; |
680 switch (container->getNodeType()) { | 703 switch (container->getNodeType()) { |
681 case Node::kTextNode: | 704 case Node::kTextNode: |
682 case Node::kCdataSectionNode: | 705 case Node::kCdataSectionNode: |
683 case Node::kCommentNode: | 706 case Node::kCommentNode: |
684 case Node::kProcessingInstructionNode: | 707 case Node::kProcessingInstructionNode: |
685 endOffset = std::min(endOffset, toCharacterData(container)->length()); | 708 endOffset = std::min(endOffset, toCharacterData(container)->length()); |
686 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 709 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
687 CharacterData* c = | 710 CharacterData* c = |
688 static_cast<CharacterData*>(container->cloneNode(true)); | 711 static_cast<CharacterData*>(container->cloneNode(true)); |
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1802 .data() | 1825 .data() |
1803 << "start offset: " << range->startOffset() | 1826 << "start offset: " << range->startOffset() |
1804 << ", end offset: " << range->endOffset(); | 1827 << ", end offset: " << range->endOffset(); |
1805 } else { | 1828 } else { |
1806 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " | 1829 LOG(INFO) << "Cannot show tree if range is null, or if boundary points are " |
1807 "invalid."; | 1830 "invalid."; |
1808 } | 1831 } |
1809 } | 1832 } |
1810 | 1833 |
1811 #endif | 1834 #endif |
OLD | NEW |