| 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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 case Node::TEXT_NODE: | 651 case Node::TEXT_NODE: |
| 652 case Node::CDATA_SECTION_NODE: | 652 case Node::CDATA_SECTION_NODE: |
| 653 case Node::COMMENT_NODE: | 653 case Node::COMMENT_NODE: |
| 654 return toCharacterData(node)->length(); | 654 return toCharacterData(node)->length(); |
| 655 case Node::PROCESSING_INSTRUCTION_NODE: | 655 case Node::PROCESSING_INSTRUCTION_NODE: |
| 656 return toProcessingInstruction(node)->data().length(); | 656 return toProcessingInstruction(node)->data().length(); |
| 657 case Node::ELEMENT_NODE: | 657 case Node::ELEMENT_NODE: |
| 658 case Node::ATTRIBUTE_NODE: | 658 case Node::ATTRIBUTE_NODE: |
| 659 case Node::DOCUMENT_NODE: | 659 case Node::DOCUMENT_NODE: |
| 660 case Node::DOCUMENT_FRAGMENT_NODE: | 660 case Node::DOCUMENT_FRAGMENT_NODE: |
| 661 return toContainerNode(node)->childNodeCount(); | 661 return toContainerNode(node)->countChildren(); |
| 662 case Node::DOCUMENT_TYPE_NODE: | 662 case Node::DOCUMENT_TYPE_NODE: |
| 663 return 0; | 663 return 0; |
| 664 } | 664 } |
| 665 ASSERT_NOT_REACHED(); | 665 ASSERT_NOT_REACHED(); |
| 666 return 0; | 666 return 0; |
| 667 } | 667 } |
| 668 | 668 |
| 669 PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception
State& exceptionState) | 669 PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception
State& exceptionState) |
| 670 { | 670 { |
| 671 typedef Vector<RefPtr<Node> > NodeVector; | 671 typedef Vector<RefPtr<Node> > NodeVector; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 if (lastChild && lastChild == m_start.childBefore()) { | 1036 if (lastChild && lastChild == m_start.childBefore()) { |
| 1037 // The insertion will do nothing, but we need to extend the range to
include | 1037 // The insertion will do nothing, but we need to extend the range to
include |
| 1038 // the inserted nodes. | 1038 // the inserted nodes. |
| 1039 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? n
ewNode->firstChild() : newNode.get(); | 1039 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? n
ewNode->firstChild() : newNode.get(); |
| 1040 ASSERT(firstChild); | 1040 ASSERT(firstChild); |
| 1041 m_start.setToBeforeChild(*firstChild); | 1041 m_start.setToBeforeChild(*firstChild); |
| 1042 return; | 1042 return; |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 container = m_start.container(); | 1045 container = m_start.container(); |
| 1046 container->insertBefore(newNode.release(), container->childNode(m_start.
offset()), exceptionState); | 1046 container->insertBefore(newNode.release(), container->traverseToChildAt(
m_start.offset()), exceptionState); |
| 1047 if (exceptionState.hadException()) | 1047 if (exceptionState.hadException()) |
| 1048 return; | 1048 return; |
| 1049 | 1049 |
| 1050 // Note that m_start.offset() may have changed as a result of container-
>insertBefore, | 1050 // Note that m_start.offset() may have changed as a result of container-
>insertBefore, |
| 1051 // when the node we are inserting comes before the range in the same con
tainer. | 1051 // when the node we are inserting comes before the range in the same con
tainer. |
| 1052 if (collapsed && numNewChildren) | 1052 if (collapsed && numNewChildren) |
| 1053 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la
stChild.get()); | 1053 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la
stChild.get()); |
| 1054 } | 1054 } |
| 1055 } | 1055 } |
| 1056 | 1056 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 case Node::PROCESSING_INSTRUCTION_NODE: | 1144 case Node::PROCESSING_INSTRUCTION_NODE: |
| 1145 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data
().length()) | 1145 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data
().length()) |
| 1146 exceptionState.throwDOMException(IndexSizeError, "The offset " +
String::number(offset) + " is larger than or equal to than the node's length ("
+ String::number(toProcessingInstruction(n)->data().length()) + ")."); | 1146 exceptionState.throwDOMException(IndexSizeError, "The offset " +
String::number(offset) + " is larger than or equal to than the node's length ("
+ String::number(toProcessingInstruction(n)->data().length()) + ")."); |
| 1147 return 0; | 1147 return 0; |
| 1148 case Node::ATTRIBUTE_NODE: | 1148 case Node::ATTRIBUTE_NODE: |
| 1149 case Node::DOCUMENT_FRAGMENT_NODE: | 1149 case Node::DOCUMENT_FRAGMENT_NODE: |
| 1150 case Node::DOCUMENT_NODE: | 1150 case Node::DOCUMENT_NODE: |
| 1151 case Node::ELEMENT_NODE: { | 1151 case Node::ELEMENT_NODE: { |
| 1152 if (!offset) | 1152 if (!offset) |
| 1153 return 0; | 1153 return 0; |
| 1154 Node* childBefore = n->childNode(offset - 1); | 1154 Node* childBefore = n->traverseToChildAt(offset - 1); |
| 1155 if (!childBefore) | 1155 if (!childBefore) |
| 1156 exceptionState.throwDOMException(IndexSizeError, "There is no ch
ild at offset " + String::number(offset) + "."); | 1156 exceptionState.throwDOMException(IndexSizeError, "There is no ch
ild at offset " + String::number(offset) + "."); |
| 1157 return childBefore; | 1157 return childBefore; |
| 1158 } | 1158 } |
| 1159 } | 1159 } |
| 1160 ASSERT_NOT_REACHED(); | 1160 ASSERT_NOT_REACHED(); |
| 1161 return 0; | 1161 return 0; |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const | 1164 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 } | 1465 } |
| 1466 } | 1466 } |
| 1467 } | 1467 } |
| 1468 | 1468 |
| 1469 Node* Range::firstNode() const | 1469 Node* Range::firstNode() const |
| 1470 { | 1470 { |
| 1471 if (!m_start.container()) | 1471 if (!m_start.container()) |
| 1472 return 0; | 1472 return 0; |
| 1473 if (m_start.container()->offsetInCharacters()) | 1473 if (m_start.container()->offsetInCharacters()) |
| 1474 return m_start.container(); | 1474 return m_start.container(); |
| 1475 if (Node* child = m_start.container()->childNode(m_start.offset())) | 1475 if (Node* child = m_start.container()->traverseToChildAt(m_start.offset())) |
| 1476 return child; | 1476 return child; |
| 1477 if (!m_start.offset()) | 1477 if (!m_start.offset()) |
| 1478 return m_start.container(); | 1478 return m_start.container(); |
| 1479 return NodeTraversal::nextSkippingChildren(*m_start.container()); | 1479 return NodeTraversal::nextSkippingChildren(*m_start.container()); |
| 1480 } | 1480 } |
| 1481 | 1481 |
| 1482 ShadowRoot* Range::shadowRoot() const | 1482 ShadowRoot* Range::shadowRoot() const |
| 1483 { | 1483 { |
| 1484 return startContainer() ? startContainer()->containingShadowRoot() : 0; | 1484 return startContainer() ? startContainer()->containingShadowRoot() : 0; |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 Node* Range::pastLastNode() const | 1487 Node* Range::pastLastNode() const |
| 1488 { | 1488 { |
| 1489 if (!m_start.container() || !m_end.container()) | 1489 if (!m_start.container() || !m_end.container()) |
| 1490 return 0; | 1490 return 0; |
| 1491 if (m_end.container()->offsetInCharacters()) | 1491 if (m_end.container()->offsetInCharacters()) |
| 1492 return NodeTraversal::nextSkippingChildren(*m_end.container()); | 1492 return NodeTraversal::nextSkippingChildren(*m_end.container()); |
| 1493 if (Node* child = m_end.container()->childNode(m_end.offset())) | 1493 if (Node* child = m_end.container()->traverseToChildAt(m_end.offset())) |
| 1494 return child; | 1494 return child; |
| 1495 return NodeTraversal::nextSkippingChildren(*m_end.container()); | 1495 return NodeTraversal::nextSkippingChildren(*m_end.container()); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 IntRect Range::boundingBox() const | 1498 IntRect Range::boundingBox() const |
| 1499 { | 1499 { |
| 1500 IntRect result; | 1500 IntRect result; |
| 1501 Vector<IntRect> rects; | 1501 Vector<IntRect> rects; |
| 1502 textRects(rects); | 1502 textRects(rects); |
| 1503 const size_t n = rects.size(); | 1503 const size_t n = rects.size(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 RefPtr<Range> range = Range::create(node->document()); | 1612 RefPtr<Range> range = Range::create(node->document()); |
| 1613 range->selectNodeContents(node, IGNORE_EXCEPTION); | 1613 range->selectNodeContents(node, IGNORE_EXCEPTION); |
| 1614 return range.release(); | 1614 return range.release(); |
| 1615 } | 1615 } |
| 1616 | 1616 |
| 1617 int Range::maxStartOffset() const | 1617 int Range::maxStartOffset() const |
| 1618 { | 1618 { |
| 1619 if (!m_start.container()) | 1619 if (!m_start.container()) |
| 1620 return 0; | 1620 return 0; |
| 1621 if (!m_start.container()->offsetInCharacters()) | 1621 if (!m_start.container()->offsetInCharacters()) |
| 1622 return m_start.container()->childNodeCount(); | 1622 return m_start.container()->countChildren(); |
| 1623 return m_start.container()->maxCharacterOffset(); | 1623 return m_start.container()->maxCharacterOffset(); |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 int Range::maxEndOffset() const | 1626 int Range::maxEndOffset() const |
| 1627 { | 1627 { |
| 1628 if (!m_end.container()) | 1628 if (!m_end.container()) |
| 1629 return 0; | 1629 return 0; |
| 1630 if (!m_end.container()->offsetInCharacters()) | 1630 if (!m_end.container()->offsetInCharacters()) |
| 1631 return m_end.container()->childNodeCount(); | 1631 return m_end.container()->countChildren(); |
| 1632 return m_end.container()->maxCharacterOffset(); | 1632 return m_end.container()->maxCharacterOffset(); |
| 1633 } | 1633 } |
| 1634 | 1634 |
| 1635 static inline void boundaryNodeChildrenChanged(RangeBoundaryPoint& boundary, Con
tainerNode* container) | 1635 static inline void boundaryNodeChildrenChanged(RangeBoundaryPoint& boundary, Con
tainerNode* container) |
| 1636 { | 1636 { |
| 1637 if (!boundary.childBefore()) | 1637 if (!boundary.childBefore()) |
| 1638 return; | 1638 return; |
| 1639 if (boundary.container() != container) | 1639 if (boundary.container() != container) |
| 1640 return; | 1640 return; |
| 1641 boundary.invalidateOffset(); | 1641 boundary.invalidateOffset(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1887 | 1887 |
| 1888 void showTree(const WebCore::Range* range) | 1888 void showTree(const WebCore::Range* range) |
| 1889 { | 1889 { |
| 1890 if (range && range->boundaryPointsValid()) { | 1890 if (range && range->boundaryPointsValid()) { |
| 1891 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1891 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1892 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1892 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1893 } | 1893 } |
| 1894 } | 1894 } |
| 1895 | 1895 |
| 1896 #endif | 1896 #endif |
| OLD | NEW |