| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 , m_start(m_ownerDocument) | 69 , m_start(m_ownerDocument) |
| 70 , m_end(m_ownerDocument) | 70 , m_end(m_ownerDocument) |
| 71 { | 71 { |
| 72 #ifndef NDEBUG | 72 #ifndef NDEBUG |
| 73 rangeCounter().increment(); | 73 rangeCounter().increment(); |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 m_ownerDocument->attachRange(this); | 76 m_ownerDocument->attachRange(this); |
| 77 } | 77 } |
| 78 | 78 |
| 79 PassRefPtrWillBeRawPtr<Range> Range::create(Document& ownerDocument) | 79 RawPtr<Range> Range::create(Document& ownerDocument) |
| 80 { | 80 { |
| 81 return adoptRefWillBeNoop(new Range(ownerDocument)); | 81 return new Range(ownerDocument); |
| 82 } | 82 } |
| 83 | 83 |
| 84 inline Range::Range(Document& ownerDocument, Node* startContainer, int startOffs
et, Node* endContainer, int endOffset) | 84 inline Range::Range(Document& ownerDocument, Node* startContainer, int startOffs
et, Node* endContainer, int endOffset) |
| 85 : m_ownerDocument(&ownerDocument) | 85 : m_ownerDocument(&ownerDocument) |
| 86 , m_start(m_ownerDocument) | 86 , m_start(m_ownerDocument) |
| 87 , m_end(m_ownerDocument) | 87 , m_end(m_ownerDocument) |
| 88 { | 88 { |
| 89 #ifndef NDEBUG | 89 #ifndef NDEBUG |
| 90 rangeCounter().increment(); | 90 rangeCounter().increment(); |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 m_ownerDocument->attachRange(this); | 93 m_ownerDocument->attachRange(this); |
| 94 | 94 |
| 95 // Simply setting the containers and offsets directly would not do any of th
e checking | 95 // Simply setting the containers and offsets directly would not do any of th
e checking |
| 96 // that setStart and setEnd do, so we call those functions. | 96 // that setStart and setEnd do, so we call those functions. |
| 97 setStart(startContainer, startOffset); | 97 setStart(startContainer, startOffset); |
| 98 setEnd(endContainer, endOffset); | 98 setEnd(endContainer, endOffset); |
| 99 } | 99 } |
| 100 | 100 |
| 101 PassRefPtrWillBeRawPtr<Range> Range::create(Document& ownerDocument, Node* start
Container, int startOffset, Node* endContainer, int endOffset) | 101 RawPtr<Range> Range::create(Document& ownerDocument, Node* startContainer, int s
tartOffset, Node* endContainer, int endOffset) |
| 102 { | 102 { |
| 103 return adoptRefWillBeNoop(new Range(ownerDocument, startContainer, startOffs
et, endContainer, endOffset)); | 103 return new Range(ownerDocument, startContainer, startOffset, endContainer, e
ndOffset); |
| 104 } | 104 } |
| 105 | 105 |
| 106 PassRefPtrWillBeRawPtr<Range> Range::create(Document& ownerDocument, const Posit
ion& start, const Position& end) | 106 RawPtr<Range> Range::create(Document& ownerDocument, const Position& start, cons
t Position& end) |
| 107 { | 107 { |
| 108 return adoptRefWillBeNoop(new Range(ownerDocument, start.computeContainerNod
e(), start.computeOffsetInContainerNode(), end.computeContainerNode(), end.compu
teOffsetInContainerNode())); | 108 return new Range(ownerDocument, start.computeContainerNode(), start.computeO
ffsetInContainerNode(), end.computeContainerNode(), end.computeOffsetInContainer
Node()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 PassRefPtrWillBeRawPtr<Range> Range::createAdjustedToTreeScope(const TreeScope&
treeScope, const Position& position) | 111 RawPtr<Range> Range::createAdjustedToTreeScope(const TreeScope& treeScope, const
Position& position) |
| 112 { | 112 { |
| 113 RefPtrWillBeRawPtr<Range> range = create(treeScope.document(), position, pos
ition); | 113 RawPtr<Range> range = create(treeScope.document(), position, position); |
| 114 | 114 |
| 115 // Make sure the range is in this scope. | 115 // Make sure the range is in this scope. |
| 116 Node* firstNode = range->firstNode(); | 116 Node* firstNode = range->firstNode(); |
| 117 ASSERT(firstNode); | 117 ASSERT(firstNode); |
| 118 Node* shadowHostInThisScopeOrFirstNode = treeScope.ancestorInThisScope(first
Node); | 118 Node* shadowHostInThisScopeOrFirstNode = treeScope.ancestorInThisScope(first
Node); |
| 119 ASSERT(shadowHostInThisScopeOrFirstNode); | 119 ASSERT(shadowHostInThisScopeOrFirstNode); |
| 120 if (shadowHostInThisScopeOrFirstNode == firstNode) | 120 if (shadowHostInThisScopeOrFirstNode == firstNode) |
| 121 return range.release(); | 121 return range.release(); |
| 122 | 122 |
| 123 // If not, create a range for the shadow host in this scope. | 123 // If not, create a range for the shadow host in this scope. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 Node* endRootContainer = end.container(); | 183 Node* endRootContainer = end.container(); |
| 184 while (endRootContainer->parentNode()) | 184 while (endRootContainer->parentNode()) |
| 185 endRootContainer = endRootContainer->parentNode(); | 185 endRootContainer = endRootContainer->parentNode(); |
| 186 Node* startRootContainer = start.container(); | 186 Node* startRootContainer = start.container(); |
| 187 while (startRootContainer->parentNode()) | 187 while (startRootContainer->parentNode()) |
| 188 startRootContainer = startRootContainer->parentNode(); | 188 startRootContainer = startRootContainer->parentNode(); |
| 189 | 189 |
| 190 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin
ts(start, end, ASSERT_NO_EXCEPTION) > 0); | 190 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin
ts(start, end, ASSERT_NO_EXCEPTION) > 0); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void Range::setStart(PassRefPtrWillBeRawPtr<Node> refNode, int offset, Exception
State& exceptionState) | 193 void Range::setStart(RawPtr<Node> refNode, int offset, ExceptionState& exception
State) |
| 194 { | 194 { |
| 195 if (!refNode) { | 195 if (!refNode) { |
| 196 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | 196 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! |
| 197 exceptionState.throwTypeError("The node provided is null."); | 197 exceptionState.throwTypeError("The node provided is null."); |
| 198 return; | 198 return; |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool didMoveDocument = false; | 201 bool didMoveDocument = false; |
| 202 if (refNode->document() != m_ownerDocument) { | 202 if (refNode->document() != m_ownerDocument) { |
| 203 setDocument(refNode->document()); | 203 setDocument(refNode->document()); |
| 204 didMoveDocument = true; | 204 didMoveDocument = true; |
| 205 } | 205 } |
| 206 | 206 |
| 207 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState); | 207 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState); |
| 208 if (exceptionState.hadException()) | 208 if (exceptionState.hadException()) |
| 209 return; | 209 return; |
| 210 | 210 |
| 211 m_start.set(refNode, offset, childNode); | 211 m_start.set(refNode, offset, childNode); |
| 212 | 212 |
| 213 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) | 213 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) |
| 214 collapse(true); | 214 collapse(true); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void Range::setEnd(PassRefPtrWillBeRawPtr<Node> refNode, int offset, ExceptionSt
ate& exceptionState) | 217 void Range::setEnd(RawPtr<Node> refNode, int offset, ExceptionState& exceptionSt
ate) |
| 218 { | 218 { |
| 219 if (!refNode) { | 219 if (!refNode) { |
| 220 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | 220 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! |
| 221 exceptionState.throwTypeError("The node provided is null."); | 221 exceptionState.throwTypeError("The node provided is null."); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool didMoveDocument = false; | 225 bool didMoveDocument = false; |
| 226 if (refNode->document() != m_ownerDocument) { | 226 if (refNode->document() != m_ownerDocument) { |
| 227 setDocument(refNode->document()); | 227 setDocument(refNode->document()); |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 for (unsigned i = 0; container && i < offset; i++) | 495 for (unsigned i = 0; container && i < offset; i++) |
| 496 container = container->nextSibling(); | 496 container = container->nextSibling(); |
| 497 } else { | 497 } else { |
| 498 while (container->parentNode() != commonRoot) | 498 while (container->parentNode() != commonRoot) |
| 499 container = container->parentNode(); | 499 container = container->parentNode(); |
| 500 } | 500 } |
| 501 | 501 |
| 502 return container; | 502 return container; |
| 503 } | 503 } |
| 504 | 504 |
| 505 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio
n, ExceptionState& exceptionState) | 505 RawPtr<DocumentFragment> Range::processContents(ActionType action, ExceptionStat
e& exceptionState) |
| 506 { | 506 { |
| 507 typedef WillBeHeapVector<RefPtrWillBeMember<Node>> NodeVector; | 507 typedef HeapVector<Member<Node>> NodeVector; |
| 508 | 508 |
| 509 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; | 509 RawPtr<DocumentFragment> fragment = nullptr; |
| 510 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) | 510 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) |
| 511 fragment = DocumentFragment::create(*m_ownerDocument.get()); | 511 fragment = DocumentFragment::create(*m_ownerDocument.get()); |
| 512 | 512 |
| 513 if (collapsed()) | 513 if (collapsed()) |
| 514 return fragment.release(); | 514 return fragment.release(); |
| 515 | 515 |
| 516 RefPtrWillBeRawPtr<Node> commonRoot = commonAncestorContainer(); | 516 RawPtr<Node> commonRoot = commonAncestorContainer(); |
| 517 ASSERT(commonRoot); | 517 ASSERT(commonRoot); |
| 518 | 518 |
| 519 if (m_start.container() == m_end.container()) { | 519 if (m_start.container() == m_end.container()) { |
| 520 processContentsBetweenOffsets(action, fragment, m_start.container(), m_s
tart.offset(), m_end.offset(), exceptionState); | 520 processContentsBetweenOffsets(action, fragment, m_start.container(), m_s
tart.offset(), m_end.offset(), exceptionState); |
| 521 return fragment; | 521 return fragment; |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Since mutation observers can modify the range during the process, the bou
ndary points need to be saved. | 524 // Since mutation observers can modify the range during the process, the bou
ndary points need to be saved. |
| 525 RangeBoundaryPoint originalStart(m_start); | 525 RangeBoundaryPoint originalStart(m_start); |
| 526 RangeBoundaryPoint originalEnd(m_end); | 526 RangeBoundaryPoint originalEnd(m_end); |
| 527 | 527 |
| 528 // what is the highest node that partially selects the start / end of the ra
nge? | 528 // what is the highest node that partially selects the start / end of the ra
nge? |
| 529 RefPtrWillBeRawPtr<Node> partialStart = highestAncestorUnderCommonRoot(origi
nalStart.container(), commonRoot.get()); | 529 RawPtr<Node> partialStart = highestAncestorUnderCommonRoot(originalStart.con
tainer(), commonRoot.get()); |
| 530 RefPtrWillBeRawPtr<Node> partialEnd = highestAncestorUnderCommonRoot(origina
lEnd.container(), commonRoot.get()); | 530 RawPtr<Node> partialEnd = highestAncestorUnderCommonRoot(originalEnd.contain
er(), commonRoot.get()); |
| 531 | 531 |
| 532 // Start and end containers are different. | 532 // Start and end containers are different. |
| 533 // There are three possibilities here: | 533 // There are three possibilities here: |
| 534 // 1. Start container == commonRoot (End container must be a descendant) | 534 // 1. Start container == commonRoot (End container must be a descendant) |
| 535 // 2. End container == commonRoot (Start container must be a descendant) | 535 // 2. End container == commonRoot (Start container must be a descendant) |
| 536 // 3. Neither is commonRoot, they are both descendants | 536 // 3. Neither is commonRoot, they are both descendants |
| 537 // | 537 // |
| 538 // In case 3, we grab everything after the start (up until a direct child | 538 // In case 3, we grab everything after the start (up until a direct child |
| 539 // of commonRoot) into leftContents, and everything before the end (up until | 539 // of commonRoot) into leftContents, and everything before the end (up until |
| 540 // a direct child of commonRoot) into rightContents. Then we process all | 540 // a direct child of commonRoot) into rightContents. Then we process all |
| 541 // commonRoot children between leftContents and rightContents | 541 // commonRoot children between leftContents and rightContents |
| 542 // | 542 // |
| 543 // In case 1 or 2, we skip either processing of leftContents or rightContent
s, | 543 // In case 1 or 2, we skip either processing of leftContents or rightContent
s, |
| 544 // in which case the last lot of nodes either goes from the first or last | 544 // in which case the last lot of nodes either goes from the first or last |
| 545 // child of commonRoot. | 545 // child of commonRoot. |
| 546 // | 546 // |
| 547 // These are deleted, cloned, or extracted (i.e. both) depending on action. | 547 // These are deleted, cloned, or extracted (i.e. both) depending on action. |
| 548 | 548 |
| 549 // Note that we are verifying that our common root hierarchy is still intact | 549 // Note that we are verifying that our common root hierarchy is still intact |
| 550 // after any DOM mutation event, at various stages below. See webkit bug 603
50. | 550 // after any DOM mutation event, at various stages below. See webkit bug 603
50. |
| 551 | 551 |
| 552 RefPtrWillBeRawPtr<Node> leftContents = nullptr; | 552 RawPtr<Node> leftContents = nullptr; |
| 553 if (originalStart.container() != commonRoot && commonRoot->contains(original
Start.container())) { | 553 if (originalStart.container() != commonRoot && commonRoot->contains(original
Start.container())) { |
| 554 leftContents = processContentsBetweenOffsets(action, nullptr, originalSt
art.container(), originalStart.offset(), originalStart.container()->lengthOfCont
ents(), exceptionState); | 554 leftContents = processContentsBetweenOffsets(action, nullptr, originalSt
art.container(), originalStart.offset(), originalStart.container()->lengthOfCont
ents(), exceptionState); |
| 555 leftContents = processAncestorsAndTheirSiblings(action, originalStart.co
ntainer(), ProcessContentsForward, leftContents, commonRoot.get(), exceptionStat
e); | 555 leftContents = processAncestorsAndTheirSiblings(action, originalStart.co
ntainer(), ProcessContentsForward, leftContents, commonRoot.get(), exceptionStat
e); |
| 556 } | 556 } |
| 557 | 557 |
| 558 RefPtrWillBeRawPtr<Node> rightContents = nullptr; | 558 RawPtr<Node> rightContents = nullptr; |
| 559 if (m_end.container() != commonRoot && commonRoot->contains(originalEnd.cont
ainer())) { | 559 if (m_end.container() != commonRoot && commonRoot->contains(originalEnd.cont
ainer())) { |
| 560 rightContents = processContentsBetweenOffsets(action, nullptr, originalE
nd.container(), 0, originalEnd.offset(), exceptionState); | 560 rightContents = processContentsBetweenOffsets(action, nullptr, originalE
nd.container(), 0, originalEnd.offset(), exceptionState); |
| 561 rightContents = processAncestorsAndTheirSiblings(action, originalEnd.con
tainer(), ProcessContentsBackward, rightContents, commonRoot.get(), exceptionSta
te); | 561 rightContents = processAncestorsAndTheirSiblings(action, originalEnd.con
tainer(), ProcessContentsBackward, rightContents, commonRoot.get(), exceptionSta
te); |
| 562 } | 562 } |
| 563 | 563 |
| 564 // delete all children of commonRoot between the start and end container | 564 // delete all children of commonRoot between the start and end container |
| 565 RefPtrWillBeRawPtr<Node> processStart = childOfCommonRootBeforeOffset(origin
alStart.container(), originalStart.offset(), commonRoot.get()); | 565 RawPtr<Node> processStart = childOfCommonRootBeforeOffset(originalStart.cont
ainer(), originalStart.offset(), commonRoot.get()); |
| 566 if (processStart && originalStart.container() != commonRoot) // processStart
contains nodes before m_start. | 566 if (processStart && originalStart.container() != commonRoot) // processStart
contains nodes before m_start. |
| 567 processStart = processStart->nextSibling(); | 567 processStart = processStart->nextSibling(); |
| 568 RefPtrWillBeRawPtr<Node> processEnd = childOfCommonRootBeforeOffset(original
End.container(), originalEnd.offset(), commonRoot.get()); | 568 RawPtr<Node> processEnd = childOfCommonRootBeforeOffset(originalEnd.containe
r(), originalEnd.offset(), commonRoot.get()); |
| 569 | 569 |
| 570 // Collapse the range, making sure that the result is not within a node that
was partially selected. | 570 // Collapse the range, making sure that the result is not within a node that
was partially selected. |
| 571 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) { | 571 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) { |
| 572 if (partialStart && commonRoot->contains(partialStart.get())) { | 572 if (partialStart && commonRoot->contains(partialStart.get())) { |
| 573 // FIXME: We should not continue if we have an earlier error. | 573 // FIXME: We should not continue if we have an earlier error. |
| 574 exceptionState.clearException(); | 574 exceptionState.clearException(); |
| 575 setStart(partialStart->parentNode(), partialStart->nodeIndex() + 1,
exceptionState); | 575 setStart(partialStart->parentNode(), partialStart->nodeIndex() + 1,
exceptionState); |
| 576 } else if (partialEnd && commonRoot->contains(partialEnd.get())) { | 576 } else if (partialEnd && commonRoot->contains(partialEnd.get())) { |
| 577 // FIXME: We should not continue if we have an earlier error. | 577 // FIXME: We should not continue if we have an earlier error. |
| 578 exceptionState.clearException(); | 578 exceptionState.clearException(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 598 nodes.append(n); | 598 nodes.append(n); |
| 599 processNodes(action, nodes, commonRoot, fragment, exceptionState); | 599 processNodes(action, nodes, commonRoot, fragment, exceptionState); |
| 600 } | 600 } |
| 601 | 601 |
| 602 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && rightContent
s) | 602 if ((action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) && rightContent
s) |
| 603 fragment->appendChild(rightContents, exceptionState); | 603 fragment->appendChild(rightContents, exceptionState); |
| 604 | 604 |
| 605 return fragment.release(); | 605 return fragment.release(); |
| 606 } | 606 } |
| 607 | 607 |
| 608 static inline void deleteCharacterData(PassRefPtrWillBeRawPtr<CharacterData> dat
a, unsigned startOffset, unsigned endOffset, ExceptionState& exceptionState) | 608 static inline void deleteCharacterData(RawPtr<CharacterData> data, unsigned star
tOffset, unsigned endOffset, ExceptionState& exceptionState) |
| 609 { | 609 { |
| 610 if (data->length() - endOffset) | 610 if (data->length() - endOffset) |
| 611 data->deleteData(endOffset, data->length() - endOffset, exceptionState); | 611 data->deleteData(endOffset, data->length() - endOffset, exceptionState); |
| 612 if (startOffset) | 612 if (startOffset) |
| 613 data->deleteData(0, startOffset, exceptionState); | 613 data->deleteData(0, startOffset, exceptionState); |
| 614 } | 614 } |
| 615 | 615 |
| 616 PassRefPtrWillBeRawPtr<Node> Range::processContentsBetweenOffsets(ActionType act
ion, PassRefPtrWillBeRawPtr<DocumentFragment> fragment, | 616 RawPtr<Node> Range::processContentsBetweenOffsets(ActionType action, RawPtr<Docu
mentFragment> fragment, |
| 617 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e
xceptionState) | 617 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e
xceptionState) |
| 618 { | 618 { |
| 619 ASSERT(container); | 619 ASSERT(container); |
| 620 ASSERT(startOffset <= endOffset); | 620 ASSERT(startOffset <= endOffset); |
| 621 | 621 |
| 622 // This switch statement must be consistent with that of Node::lengthOfConte
nts. | 622 // This switch statement must be consistent with that of Node::lengthOfConte
nts. |
| 623 RefPtrWillBeRawPtr<Node> result = nullptr; | 623 RawPtr<Node> result = nullptr; |
| 624 switch (container->getNodeType()) { | 624 switch (container->getNodeType()) { |
| 625 case Node::TEXT_NODE: | 625 case Node::TEXT_NODE: |
| 626 case Node::CDATA_SECTION_NODE: | 626 case Node::CDATA_SECTION_NODE: |
| 627 case Node::COMMENT_NODE: | 627 case Node::COMMENT_NODE: |
| 628 case Node::PROCESSING_INSTRUCTION_NODE: | 628 case Node::PROCESSING_INSTRUCTION_NODE: |
| 629 endOffset = std::min(endOffset, toCharacterData(container)->length()); | 629 endOffset = std::min(endOffset, toCharacterData(container)->length()); |
| 630 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 630 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 631 RefPtrWillBeRawPtr<CharacterData> c = static_pointer_cast<CharacterD
ata>(container->cloneNode(true)); | 631 RawPtr<CharacterData> c = static_pointer_cast<CharacterData>(contain
er->cloneNode(true)); |
| 632 deleteCharacterData(c, startOffset, endOffset, exceptionState); | 632 deleteCharacterData(c, startOffset, endOffset, exceptionState); |
| 633 if (fragment) { | 633 if (fragment) { |
| 634 result = fragment; | 634 result = fragment; |
| 635 result->appendChild(c.release(), exceptionState); | 635 result->appendChild(c.release(), exceptionState); |
| 636 } else { | 636 } else { |
| 637 result = c.release(); | 637 result = c.release(); |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) | 640 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) |
| 641 toCharacterData(container)->deleteData(startOffset, endOffset - star
tOffset, exceptionState); | 641 toCharacterData(container)->deleteData(startOffset, endOffset - star
tOffset, exceptionState); |
| 642 break; | 642 break; |
| 643 case Node::ELEMENT_NODE: | 643 case Node::ELEMENT_NODE: |
| 644 case Node::ATTRIBUTE_NODE: | 644 case Node::ATTRIBUTE_NODE: |
| 645 case Node::DOCUMENT_NODE: | 645 case Node::DOCUMENT_NODE: |
| 646 case Node::DOCUMENT_TYPE_NODE: | 646 case Node::DOCUMENT_TYPE_NODE: |
| 647 case Node::DOCUMENT_FRAGMENT_NODE: | 647 case Node::DOCUMENT_FRAGMENT_NODE: |
| 648 // FIXME: Should we assert that some nodes never appear here? | 648 // FIXME: Should we assert that some nodes never appear here? |
| 649 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 649 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 650 if (fragment) | 650 if (fragment) |
| 651 result = fragment; | 651 result = fragment; |
| 652 else | 652 else |
| 653 result = container->cloneNode(false); | 653 result = container->cloneNode(false); |
| 654 } | 654 } |
| 655 | 655 |
| 656 Node* n = container->firstChild(); | 656 Node* n = container->firstChild(); |
| 657 WillBeHeapVector<RefPtrWillBeMember<Node>> nodes; | 657 HeapVector<Member<Node>> nodes; |
| 658 for (unsigned i = startOffset; n && i; i--) | 658 for (unsigned i = startOffset; n && i; i--) |
| 659 n = n->nextSibling(); | 659 n = n->nextSibling(); |
| 660 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli
ng()) | 660 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli
ng()) |
| 661 nodes.append(n); | 661 nodes.append(n); |
| 662 | 662 |
| 663 processNodes(action, nodes, container, result, exceptionState); | 663 processNodes(action, nodes, container, result, exceptionState); |
| 664 break; | 664 break; |
| 665 } | 665 } |
| 666 | 666 |
| 667 return result.release(); | 667 return result.release(); |
| 668 } | 668 } |
| 669 | 669 |
| 670 void Range::processNodes(ActionType action, WillBeHeapVector<RefPtrWillBeMember<
Node>>& nodes, PassRefPtrWillBeRawPtr<Node> oldContainer, PassRefPtrWillBeRawPtr
<Node> newContainer, ExceptionState& exceptionState) | 670 void Range::processNodes(ActionType action, HeapVector<Member<Node>>& nodes, Raw
Ptr<Node> oldContainer, RawPtr<Node> newContainer, ExceptionState& exceptionStat
e) |
| 671 { | 671 { |
| 672 for (auto& node : nodes) { | 672 for (auto& node : nodes) { |
| 673 switch (action) { | 673 switch (action) { |
| 674 case DELETE_CONTENTS: | 674 case DELETE_CONTENTS: |
| 675 oldContainer->removeChild(node.get(), exceptionState); | 675 oldContainer->removeChild(node.get(), exceptionState); |
| 676 break; | 676 break; |
| 677 case EXTRACT_CONTENTS: | 677 case EXTRACT_CONTENTS: |
| 678 newContainer->appendChild(node.release(), exceptionState); // Will r
emove n from its parent. | 678 newContainer->appendChild(node.release(), exceptionState); // Will r
emove n from its parent. |
| 679 break; | 679 break; |
| 680 case CLONE_CONTENTS: | 680 case CLONE_CONTENTS: |
| 681 newContainer->appendChild(node->cloneNode(true), exceptionState); | 681 newContainer->appendChild(node->cloneNode(true), exceptionState); |
| 682 break; | 682 break; |
| 683 } | 683 } |
| 684 } | 684 } |
| 685 } | 685 } |
| 686 | 686 |
| 687 PassRefPtrWillBeRawPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType
action, Node* container, ContentsProcessDirection direction, PassRefPtrWillBeRaw
Ptr<Node> passedClonedContainer, Node* commonRoot, ExceptionState& exceptionStat
e) | 687 RawPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* co
ntainer, ContentsProcessDirection direction, RawPtr<Node> passedClonedContainer,
Node* commonRoot, ExceptionState& exceptionState) |
| 688 { | 688 { |
| 689 typedef WillBeHeapVector<RefPtrWillBeMember<Node>> NodeVector; | 689 typedef HeapVector<Member<Node>> NodeVector; |
| 690 | 690 |
| 691 RefPtrWillBeRawPtr<Node> clonedContainer = passedClonedContainer; | 691 RawPtr<Node> clonedContainer = passedClonedContainer; |
| 692 NodeVector ancestors; | 692 NodeVector ancestors; |
| 693 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n
->parentNode()) | 693 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n
->parentNode()) |
| 694 ancestors.append(n); | 694 ancestors.append(n); |
| 695 | 695 |
| 696 RefPtrWillBeRawPtr<Node> firstChildInAncestorToProcess = direction == Proces
sContentsForward ? container->nextSibling() : container->previousSibling(); | 696 RawPtr<Node> firstChildInAncestorToProcess = direction == ProcessContentsFor
ward ? container->nextSibling() : container->previousSibling(); |
| 697 for (const RefPtrWillBeRawPtr<Node>& ancestor : ancestors) { | 697 for (const RawPtr<Node>& ancestor : ancestors) { |
| 698 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { | 698 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { |
| 699 if (RefPtrWillBeRawPtr<Node> clonedAncestor = ancestor->cloneNode(fa
lse)) { // Might have been removed already during mutation event. | 699 if (RawPtr<Node> clonedAncestor = ancestor->cloneNode(false)) { // M
ight have been removed already during mutation event. |
| 700 clonedAncestor->appendChild(clonedContainer, exceptionState); | 700 clonedAncestor->appendChild(clonedContainer, exceptionState); |
| 701 clonedContainer = clonedAncestor; | 701 clonedContainer = clonedAncestor; |
| 702 } | 702 } |
| 703 } | 703 } |
| 704 | 704 |
| 705 // Copy siblings of an ancestor of start/end containers | 705 // Copy siblings of an ancestor of start/end containers |
| 706 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt | 706 // FIXME: This assertion may fail if DOM is modified during mutation eve
nt |
| 707 // FIXME: Share code with Range::processNodes | 707 // FIXME: Share code with Range::processNodes |
| 708 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); | 708 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess->
parentNode() == ancestor); |
| 709 | 709 |
| 710 NodeVector nodes; | 710 NodeVector nodes; |
| 711 for (Node* child = firstChildInAncestorToProcess.get(); child; | 711 for (Node* child = firstChildInAncestorToProcess.get(); child; |
| 712 child = (direction == ProcessContentsForward) ? child->nextSibling()
: child->previousSibling()) | 712 child = (direction == ProcessContentsForward) ? child->nextSibling()
: child->previousSibling()) |
| 713 nodes.append(child); | 713 nodes.append(child); |
| 714 | 714 |
| 715 for (const RefPtrWillBeRawPtr<Node>& node : nodes) { | 715 for (const RawPtr<Node>& node : nodes) { |
| 716 Node* child = node.get(); | 716 Node* child = node.get(); |
| 717 switch (action) { | 717 switch (action) { |
| 718 case DELETE_CONTENTS: | 718 case DELETE_CONTENTS: |
| 719 // Prior call of ancestor->removeChild() may cause a tree change
due to DOMSubtreeModified event. | 719 // Prior call of ancestor->removeChild() may cause a tree change
due to DOMSubtreeModified event. |
| 720 // Therefore, we need to make sure |ancestor| is still |child|'s
parent. | 720 // Therefore, we need to make sure |ancestor| is still |child|'s
parent. |
| 721 if (ancestor == child->parentNode()) | 721 if (ancestor == child->parentNode()) |
| 722 ancestor->removeChild(child, exceptionState); | 722 ancestor->removeChild(child, exceptionState); |
| 723 break; | 723 break; |
| 724 case EXTRACT_CONTENTS: // will remove child from ancestor | 724 case EXTRACT_CONTENTS: // will remove child from ancestor |
| 725 if (direction == ProcessContentsForward) | 725 if (direction == ProcessContentsForward) |
| 726 clonedContainer->appendChild(child, exceptionState); | 726 clonedContainer->appendChild(child, exceptionState); |
| 727 else | 727 else |
| 728 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), exceptionState); | 728 clonedContainer->insertBefore(child, clonedContainer->firstC
hild(), exceptionState); |
| 729 break; | 729 break; |
| 730 case CLONE_CONTENTS: | 730 case CLONE_CONTENTS: |
| 731 if (direction == ProcessContentsForward) | 731 if (direction == ProcessContentsForward) |
| 732 clonedContainer->appendChild(child->cloneNode(true), excepti
onState); | 732 clonedContainer->appendChild(child->cloneNode(true), excepti
onState); |
| 733 else | 733 else |
| 734 clonedContainer->insertBefore(child->cloneNode(true), cloned
Container->firstChild(), exceptionState); | 734 clonedContainer->insertBefore(child->cloneNode(true), cloned
Container->firstChild(), exceptionState); |
| 735 break; | 735 break; |
| 736 } | 736 } |
| 737 } | 737 } |
| 738 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an
cestor->nextSibling() : ancestor->previousSibling(); | 738 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an
cestor->nextSibling() : ancestor->previousSibling(); |
| 739 } | 739 } |
| 740 | 740 |
| 741 return clonedContainer.release(); | 741 return clonedContainer.release(); |
| 742 } | 742 } |
| 743 | 743 |
| 744 PassRefPtrWillBeRawPtr<DocumentFragment> Range::extractContents(ExceptionState&
exceptionState) | 744 RawPtr<DocumentFragment> Range::extractContents(ExceptionState& exceptionState) |
| 745 { | 745 { |
| 746 checkExtractPrecondition(exceptionState); | 746 checkExtractPrecondition(exceptionState); |
| 747 if (exceptionState.hadException()) | 747 if (exceptionState.hadException()) |
| 748 return nullptr; | 748 return nullptr; |
| 749 | 749 |
| 750 return processContents(EXTRACT_CONTENTS, exceptionState); | 750 return processContents(EXTRACT_CONTENTS, exceptionState); |
| 751 } | 751 } |
| 752 | 752 |
| 753 PassRefPtrWillBeRawPtr<DocumentFragment> Range::cloneContents(ExceptionState& ex
ceptionState) | 753 RawPtr<DocumentFragment> Range::cloneContents(ExceptionState& exceptionState) |
| 754 { | 754 { |
| 755 return processContents(CLONE_CONTENTS, exceptionState); | 755 return processContents(CLONE_CONTENTS, exceptionState); |
| 756 } | 756 } |
| 757 | 757 |
| 758 void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState&
exceptionState) | 758 void Range::insertNode(RawPtr<Node> prpNewNode, ExceptionState& exceptionState) |
| 759 { | 759 { |
| 760 RefPtrWillBeRawPtr<Node> newNode = prpNewNode; | 760 RawPtr<Node> newNode = prpNewNode; |
| 761 | 761 |
| 762 if (!newNode) { | 762 if (!newNode) { |
| 763 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | 763 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! |
| 764 exceptionState.throwTypeError("The node provided is null."); | 764 exceptionState.throwTypeError("The node provided is null."); |
| 765 return; | 765 return; |
| 766 } | 766 } |
| 767 | 767 |
| 768 // HierarchyRequestError: Raised if the container of the start of the Range
is of a type that | 768 // HierarchyRequestError: Raised if the container of the start of the Range
is of a type that |
| 769 // does not allow children of the type of newNode or if newNode is an ancest
or of the container. | 769 // does not allow children of the type of newNode or if newNode is an ancest
or of the container. |
| 770 | 770 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 default: | 819 default: |
| 820 if (newNode->isShadowRoot()) { | 820 if (newNode->isShadowRoot()) { |
| 821 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to
be inserted is a shadow root, which may not be inserted here."); | 821 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to
be inserted is a shadow root, which may not be inserted here."); |
| 822 return; | 822 return; |
| 823 } | 823 } |
| 824 break; | 824 break; |
| 825 } | 825 } |
| 826 | 826 |
| 827 EventQueueScope scope; | 827 EventQueueScope scope; |
| 828 bool collapsed = m_start == m_end; | 828 bool collapsed = m_start == m_end; |
| 829 RefPtrWillBeRawPtr<Node> container = nullptr; | 829 RawPtr<Node> container = nullptr; |
| 830 if (startIsText) { | 830 if (startIsText) { |
| 831 container = m_start.container(); | 831 container = m_start.container(); |
| 832 RefPtrWillBeRawPtr<Text> newText = toText(container)->splitText(m_start.
offset(), exceptionState); | 832 RawPtr<Text> newText = toText(container)->splitText(m_start.offset(), ex
ceptionState); |
| 833 if (exceptionState.hadException()) | 833 if (exceptionState.hadException()) |
| 834 return; | 834 return; |
| 835 | 835 |
| 836 container = m_start.container(); | 836 container = m_start.container(); |
| 837 container->parentNode()->insertBefore(newNode.release(), newText.get(),
exceptionState); | 837 container->parentNode()->insertBefore(newNode.release(), newText.get(),
exceptionState); |
| 838 if (exceptionState.hadException()) | 838 if (exceptionState.hadException()) |
| 839 return; | 839 return; |
| 840 | 840 |
| 841 if (collapsed) { | 841 if (collapsed) { |
| 842 // Some types of events don't support EventQueueScope. Given | 842 // Some types of events don't support EventQueueScope. Given |
| 843 // circumstance may mutate the tree so newText->parentNode() may | 843 // circumstance may mutate the tree so newText->parentNode() may |
| 844 // become null. | 844 // become null. |
| 845 if (!newText->parentNode()) { | 845 if (!newText->parentNode()) { |
| 846 exceptionState.throwDOMException(HierarchyRequestError, "This op
eration would set range's end to parent with new offset, but there's no parent i
nto which to continue."); | 846 exceptionState.throwDOMException(HierarchyRequestError, "This op
eration would set range's end to parent with new offset, but there's no parent i
nto which to continue."); |
| 847 return; | 847 return; |
| 848 } | 848 } |
| 849 m_end.setToBeforeChild(*newText); | 849 m_end.setToBeforeChild(*newText); |
| 850 } | 850 } |
| 851 } else { | 851 } else { |
| 852 RefPtrWillBeRawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAG
MENT_NODE) ? toDocumentFragment(newNode)->lastChild() : newNode.get(); | 852 RawPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ?
toDocumentFragment(newNode)->lastChild() : newNode.get(); |
| 853 if (lastChild && lastChild == m_start.childBefore()) { | 853 if (lastChild && lastChild == m_start.childBefore()) { |
| 854 // The insertion will do nothing, but we need to extend the range to
include | 854 // The insertion will do nothing, but we need to extend the range to
include |
| 855 // the inserted nodes. | 855 // the inserted nodes. |
| 856 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t
oDocumentFragment(newNode)->firstChild() : newNode.get(); | 856 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t
oDocumentFragment(newNode)->firstChild() : newNode.get(); |
| 857 ASSERT(firstChild); | 857 ASSERT(firstChild); |
| 858 m_start.setToBeforeChild(*firstChild); | 858 m_start.setToBeforeChild(*firstChild); |
| 859 return; | 859 return; |
| 860 } | 860 } |
| 861 | 861 |
| 862 container = m_start.container(); | 862 container = m_start.container(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 888 } | 888 } |
| 889 | 889 |
| 890 return builder.toString(); | 890 return builder.toString(); |
| 891 } | 891 } |
| 892 | 892 |
| 893 String Range::text() const | 893 String Range::text() const |
| 894 { | 894 { |
| 895 return plainText(EphemeralRange(this), TextIteratorEmitsObjectReplacementCha
racter); | 895 return plainText(EphemeralRange(this), TextIteratorEmitsObjectReplacementCha
racter); |
| 896 } | 896 } |
| 897 | 897 |
| 898 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S
tring& markup, ExceptionState& exceptionState) | 898 RawPtr<DocumentFragment> Range::createContextualFragment(const String& markup, E
xceptionState& exceptionState) |
| 899 { | 899 { |
| 900 // Algorithm: http://domparsing.spec.whatwg.org/#extensions-to-the-range-int
erface | 900 // Algorithm: http://domparsing.spec.whatwg.org/#extensions-to-the-range-int
erface |
| 901 | 901 |
| 902 Node* node = m_start.container(); | 902 Node* node = m_start.container(); |
| 903 | 903 |
| 904 // Step 1. | 904 // Step 1. |
| 905 RefPtrWillBeRawPtr<Element> element; | 905 RawPtr<Element> element; |
| 906 if (!m_start.offset() && (node->isDocumentNode() || node->isDocumentFragment
())) | 906 if (!m_start.offset() && (node->isDocumentNode() || node->isDocumentFragment
())) |
| 907 element = nullptr; | 907 element = nullptr; |
| 908 else if (node->isElementNode()) | 908 else if (node->isElementNode()) |
| 909 element = toElement(node); | 909 element = toElement(node); |
| 910 else | 910 else |
| 911 element = node->parentElement(); | 911 element = node->parentElement(); |
| 912 | 912 |
| 913 // Step 2. | 913 // Step 2. |
| 914 if (!element || isHTMLHtmlElement(element)) { | 914 if (!element || isHTMLHtmlElement(element)) { |
| 915 Document& document = node->document(); | 915 Document& document = node->document(); |
| 916 | 916 |
| 917 if (document.isHTMLDocument() || document.isXHTMLDocument()) { | 917 if (document.isHTMLDocument() || document.isXHTMLDocument()) { |
| 918 // Optimization over spec: try to reuse the existing <body> element,
if it is available. | 918 // Optimization over spec: try to reuse the existing <body> element,
if it is available. |
| 919 element = document.body(); | 919 element = document.body(); |
| 920 if (!element) | 920 if (!element) |
| 921 element = HTMLBodyElement::create(document); | 921 element = HTMLBodyElement::create(document); |
| 922 } else if (document.isSVGDocument()) { | 922 } else if (document.isSVGDocument()) { |
| 923 element = document.documentElement(); | 923 element = document.documentElement(); |
| 924 if (!element) | 924 if (!element) |
| 925 element = SVGSVGElement::create(document); | 925 element = SVGSVGElement::create(document); |
| 926 } | 926 } |
| 927 } | 927 } |
| 928 | 928 |
| 929 if (!element || (!element->isHTMLElement() && !element->isSVGElement())) { | 929 if (!element || (!element->isHTMLElement() && !element->isSVGElement())) { |
| 930 exceptionState.throwDOMException(NotSupportedError, "The range's contain
er must be an HTML or SVG Element, Document, or DocumentFragment."); | 930 exceptionState.throwDOMException(NotSupportedError, "The range's contain
er must be an HTML or SVG Element, Document, or DocumentFragment."); |
| 931 return nullptr; | 931 return nullptr; |
| 932 } | 932 } |
| 933 | 933 |
| 934 // Steps 3, 4, 5. | 934 // Steps 3, 4, 5. |
| 935 RefPtrWillBeRawPtr<DocumentFragment> fragment = blink::createContextualFragm
ent(markup, element.get(), AllowScriptingContentAndDoNotMarkAlreadyStarted, exce
ptionState); | 935 RawPtr<DocumentFragment> fragment = blink::createContextualFragment(markup,
element.get(), AllowScriptingContentAndDoNotMarkAlreadyStarted, exceptionState); |
| 936 if (!fragment) | 936 if (!fragment) |
| 937 return nullptr; | 937 return nullptr; |
| 938 | 938 |
| 939 return fragment.release(); | 939 return fragment.release(); |
| 940 } | 940 } |
| 941 | 941 |
| 942 | 942 |
| 943 void Range::detach() | 943 void Range::detach() |
| 944 { | 944 { |
| 945 // This is now a no-op as per the DOM specification. | 945 // This is now a no-op as per the DOM specification. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 case Node::CDATA_SECTION_NODE: | 1022 case Node::CDATA_SECTION_NODE: |
| 1023 case Node::COMMENT_NODE: | 1023 case Node::COMMENT_NODE: |
| 1024 case Node::DOCUMENT_TYPE_NODE: | 1024 case Node::DOCUMENT_TYPE_NODE: |
| 1025 case Node::PROCESSING_INSTRUCTION_NODE: | 1025 case Node::PROCESSING_INSTRUCTION_NODE: |
| 1026 case Node::TEXT_NODE: | 1026 case Node::TEXT_NODE: |
| 1027 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide
d is of type '" + n->nodeName() + "'."); | 1027 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide
d is of type '" + n->nodeName() + "'."); |
| 1028 return; | 1028 return; |
| 1029 } | 1029 } |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 PassRefPtrWillBeRawPtr<Range> Range::cloneRange() const | 1032 RawPtr<Range> Range::cloneRange() const |
| 1033 { | 1033 { |
| 1034 return Range::create(*m_ownerDocument.get(), m_start.container(), m_start.of
fset(), m_end.container(), m_end.offset()); | 1034 return Range::create(*m_ownerDocument.get(), m_start.container(), m_start.of
fset(), m_end.container(), m_end.offset()); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 void Range::setStartAfter(Node* refNode, ExceptionState& exceptionState) | 1037 void Range::setStartAfter(Node* refNode, ExceptionState& exceptionState) |
| 1038 { | 1038 { |
| 1039 checkNodeBA(refNode, exceptionState); | 1039 checkNodeBA(refNode, exceptionState); |
| 1040 if (exceptionState.hadException()) | 1040 if (exceptionState.hadException()) |
| 1041 return; | 1041 return; |
| 1042 | 1042 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1154 |
| 1155 RangeBoundaryPoint startBoundaryPoint(refNode); | 1155 RangeBoundaryPoint startBoundaryPoint(refNode); |
| 1156 startBoundaryPoint.setToStartOfNode(*refNode); | 1156 startBoundaryPoint.setToStartOfNode(*refNode); |
| 1157 start = startBoundaryPoint.toPosition(); | 1157 start = startBoundaryPoint.toPosition(); |
| 1158 RangeBoundaryPoint endBoundaryPoint(refNode); | 1158 RangeBoundaryPoint endBoundaryPoint(refNode); |
| 1159 endBoundaryPoint.setToEndOfNode(*refNode); | 1159 endBoundaryPoint.setToEndOfNode(*refNode); |
| 1160 end = endBoundaryPoint.toPosition(); | 1160 end = endBoundaryPoint.toPosition(); |
| 1161 return true; | 1161 return true; |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 void Range::surroundContents(PassRefPtrWillBeRawPtr<Node> passNewParent, Excepti
onState& exceptionState) | 1164 void Range::surroundContents(RawPtr<Node> passNewParent, ExceptionState& excepti
onState) |
| 1165 { | 1165 { |
| 1166 RefPtrWillBeRawPtr<Node> newParent = passNewParent; | 1166 RawPtr<Node> newParent = passNewParent; |
| 1167 if (!newParent) { | 1167 if (!newParent) { |
| 1168 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! | 1168 // FIXME: Generated bindings code never calls with null, and neither sho
uld other callers! |
| 1169 exceptionState.throwTypeError("The node provided is null."); | 1169 exceptionState.throwTypeError("The node provided is null."); |
| 1170 return; | 1170 return; |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 // InvalidStateError: Raised if the Range partially selects a non-Text node. | 1173 // InvalidStateError: Raised if the Range partially selects a non-Text node. |
| 1174 Node* startNonTextContainer = m_start.container(); | 1174 Node* startNonTextContainer = m_start.container(); |
| 1175 if (startNonTextContainer->getNodeType() == Node::TEXT_NODE) | 1175 if (startNonTextContainer->getNodeType() == Node::TEXT_NODE) |
| 1176 startNonTextContainer = startNonTextContainer->parentNode(); | 1176 startNonTextContainer = startNonTextContainer->parentNode(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 // FIXME: Do we need a check if the node would end up with a child node of a
type not | 1226 // FIXME: Do we need a check if the node would end up with a child node of a
type not |
| 1227 // allowed by the type of node? | 1227 // allowed by the type of node? |
| 1228 | 1228 |
| 1229 while (Node* n = newParent->firstChild()) { | 1229 while (Node* n = newParent->firstChild()) { |
| 1230 toContainerNode(newParent)->removeChild(n, exceptionState); | 1230 toContainerNode(newParent)->removeChild(n, exceptionState); |
| 1231 if (exceptionState.hadException()) | 1231 if (exceptionState.hadException()) |
| 1232 return; | 1232 return; |
| 1233 } | 1233 } |
| 1234 RefPtrWillBeRawPtr<DocumentFragment> fragment = extractContents(exceptionSta
te); | 1234 RawPtr<DocumentFragment> fragment = extractContents(exceptionState); |
| 1235 if (exceptionState.hadException()) | 1235 if (exceptionState.hadException()) |
| 1236 return; | 1236 return; |
| 1237 insertNode(newParent, exceptionState); | 1237 insertNode(newParent, exceptionState); |
| 1238 if (exceptionState.hadException()) | 1238 if (exceptionState.hadException()) |
| 1239 return; | 1239 return; |
| 1240 newParent->appendChild(fragment.release(), exceptionState); | 1240 newParent->appendChild(fragment.release(), exceptionState); |
| 1241 if (exceptionState.hadException()) | 1241 if (exceptionState.hadException()) |
| 1242 return; | 1242 return; |
| 1243 selectNode(newParent.get(), exceptionState); | 1243 selectNode(newParent.get(), exceptionState); |
| 1244 } | 1244 } |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 { | 1570 { |
| 1571 return ClientRect::create(boundingRect()); | 1571 return ClientRect::create(boundingRect()); |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const | 1574 void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const |
| 1575 { | 1575 { |
| 1576 Node* startContainer = m_start.container(); | 1576 Node* startContainer = m_start.container(); |
| 1577 Node* endContainer = m_end.container(); | 1577 Node* endContainer = m_end.container(); |
| 1578 Node* stopNode = pastLastNode(); | 1578 Node* stopNode = pastLastNode(); |
| 1579 | 1579 |
| 1580 WillBeHeapHashSet<RawPtrWillBeMember<Node>> nodeSet; | 1580 HeapHashSet<Member<Node>> nodeSet; |
| 1581 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(
*node)) { | 1581 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(
*node)) { |
| 1582 if (node->isElementNode()) | 1582 if (node->isElementNode()) |
| 1583 nodeSet.add(node); | 1583 nodeSet.add(node); |
| 1584 } | 1584 } |
| 1585 | 1585 |
| 1586 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(
*node)) { | 1586 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next(
*node)) { |
| 1587 if (node->isElementNode()) { | 1587 if (node->isElementNode()) { |
| 1588 if (!nodeSet.contains(node->parentNode())) { | 1588 if (!nodeSet.contains(node->parentNode())) { |
| 1589 if (LayoutBoxModelObject* layoutBoxModelObject = toElement(node)
->layoutBoxModelObject()) { | 1589 if (LayoutBoxModelObject* layoutBoxModelObject = toElement(node)
->layoutBoxModelObject()) { |
| 1590 Vector<FloatQuad> elementQuads; | 1590 Vector<FloatQuad> elementQuads; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 { | 1646 { |
| 1647 if (range && range->boundaryPointsValid()) { | 1647 if (range && range->boundaryPointsValid()) { |
| 1648 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1648 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1649 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1649 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1650 } else { | 1650 } else { |
| 1651 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); | 1651 fprintf(stderr, "Cannot show tree if range is null, or if boundary point
s are invalid.\n"); |
| 1652 } | 1652 } |
| 1653 } | 1653 } |
| 1654 | 1654 |
| 1655 #endif | 1655 #endif |
| OLD | NEW |