| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 m_ownerDocument->detachRange(this); | 124 m_ownerDocument->detachRange(this); |
| 125 m_ownerDocument = document; | 125 m_ownerDocument = document; |
| 126 m_start.setToStartOfNode(document); | 126 m_start.setToStartOfNode(document); |
| 127 m_end.setToStartOfNode(document); | 127 m_end.setToStartOfNode(document); |
| 128 m_ownerDocument->attachRange(this); | 128 m_ownerDocument->attachRange(this); |
| 129 } | 129 } |
| 130 | 130 |
| 131 Node* Range::startContainer(ExceptionCode& ec) const | 131 Node* Range::startContainer(ExceptionCode& ec) const |
| 132 { | 132 { |
| 133 if (!m_start.container()) { | 133 if (!m_start.container()) { |
| 134 ec = INVALID_STATE_ERR; | 134 ec = InvalidStateError; |
| 135 return 0; | 135 return 0; |
| 136 } | 136 } |
| 137 | 137 |
| 138 return m_start.container(); | 138 return m_start.container(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 int Range::startOffset(ExceptionCode& ec) const | 141 int Range::startOffset(ExceptionCode& ec) const |
| 142 { | 142 { |
| 143 if (!m_start.container()) { | 143 if (!m_start.container()) { |
| 144 ec = INVALID_STATE_ERR; | 144 ec = InvalidStateError; |
| 145 return 0; | 145 return 0; |
| 146 } | 146 } |
| 147 | 147 |
| 148 return m_start.offset(); | 148 return m_start.offset(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 Node* Range::endContainer(ExceptionCode& ec) const | 151 Node* Range::endContainer(ExceptionCode& ec) const |
| 152 { | 152 { |
| 153 if (!m_start.container()) { | 153 if (!m_start.container()) { |
| 154 ec = INVALID_STATE_ERR; | 154 ec = InvalidStateError; |
| 155 return 0; | 155 return 0; |
| 156 } | 156 } |
| 157 | 157 |
| 158 return m_end.container(); | 158 return m_end.container(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 int Range::endOffset(ExceptionCode& ec) const | 161 int Range::endOffset(ExceptionCode& ec) const |
| 162 { | 162 { |
| 163 if (!m_start.container()) { | 163 if (!m_start.container()) { |
| 164 ec = INVALID_STATE_ERR; | 164 ec = InvalidStateError; |
| 165 return 0; | 165 return 0; |
| 166 } | 166 } |
| 167 | 167 |
| 168 return m_end.offset(); | 168 return m_end.offset(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 Node* Range::commonAncestorContainer(ExceptionCode& ec) const | 171 Node* Range::commonAncestorContainer(ExceptionCode& ec) const |
| 172 { | 172 { |
| 173 if (!m_start.container()) { | 173 if (!m_start.container()) { |
| 174 ec = INVALID_STATE_ERR; | 174 ec = InvalidStateError; |
| 175 return 0; | 175 return 0; |
| 176 } | 176 } |
| 177 | 177 |
| 178 return commonAncestorContainer(m_start.container(), m_end.container()); | 178 return commonAncestorContainer(m_start.container(), m_end.container()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 Node* Range::commonAncestorContainer(Node* containerA, Node* containerB) | 181 Node* Range::commonAncestorContainer(Node* containerA, Node* containerB) |
| 182 { | 182 { |
| 183 for (Node* parentA = containerA; parentA; parentA = parentA->parentNode()) { | 183 for (Node* parentA = containerA; parentA; parentA = parentA->parentNode()) { |
| 184 for (Node* parentB = containerB; parentB; parentB = parentB->parentNode(
)) { | 184 for (Node* parentB = containerB; parentB; parentB = parentB->parentNode(
)) { |
| 185 if (parentA == parentB) | 185 if (parentA == parentB) |
| 186 return parentA; | 186 return parentA; |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 return 0; | 189 return 0; |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool Range::collapsed(ExceptionCode& ec) const | 192 bool Range::collapsed(ExceptionCode& ec) const |
| 193 { | 193 { |
| 194 if (!m_start.container()) { | 194 if (!m_start.container()) { |
| 195 ec = INVALID_STATE_ERR; | 195 ec = InvalidStateError; |
| 196 return 0; | 196 return 0; |
| 197 } | 197 } |
| 198 | 198 |
| 199 return m_start == m_end; | 199 return m_start == m_end; |
| 200 } | 200 } |
| 201 | 201 |
| 202 static inline bool checkForDifferentRootContainer(const RangeBoundaryPoint& star
t, const RangeBoundaryPoint& end) | 202 static inline bool checkForDifferentRootContainer(const RangeBoundaryPoint& star
t, const RangeBoundaryPoint& end) |
| 203 { | 203 { |
| 204 Node* endRootContainer = end.container(); | 204 Node* endRootContainer = end.container(); |
| 205 while (endRootContainer->parentNode()) | 205 while (endRootContainer->parentNode()) |
| 206 endRootContainer = endRootContainer->parentNode(); | 206 endRootContainer = endRootContainer->parentNode(); |
| 207 Node* startRootContainer = start.container(); | 207 Node* startRootContainer = start.container(); |
| 208 while (startRootContainer->parentNode()) | 208 while (startRootContainer->parentNode()) |
| 209 startRootContainer = startRootContainer->parentNode(); | 209 startRootContainer = startRootContainer->parentNode(); |
| 210 | 210 |
| 211 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin
ts(start, end, ASSERT_NO_EXCEPTION) > 0); | 211 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin
ts(start, end, ASSERT_NO_EXCEPTION) > 0); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec) | 214 void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec) |
| 215 { | 215 { |
| 216 if (!m_start.container()) { | 216 if (!m_start.container()) { |
| 217 ec = INVALID_STATE_ERR; | 217 ec = InvalidStateError; |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 if (!refNode) { | 221 if (!refNode) { |
| 222 ec = NotFoundError; | 222 ec = NotFoundError; |
| 223 return; | 223 return; |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool didMoveDocument = false; | 226 bool didMoveDocument = false; |
| 227 if (refNode->document() != m_ownerDocument) { | 227 if (refNode->document() != m_ownerDocument) { |
| 228 setDocument(refNode->document()); | 228 setDocument(refNode->document()); |
| 229 didMoveDocument = true; | 229 didMoveDocument = true; |
| 230 } | 230 } |
| 231 | 231 |
| 232 ec = 0; | 232 ec = 0; |
| 233 Node* childNode = checkNodeWOffset(refNode.get(), offset, ec); | 233 Node* childNode = checkNodeWOffset(refNode.get(), offset, ec); |
| 234 if (ec) | 234 if (ec) |
| 235 return; | 235 return; |
| 236 | 236 |
| 237 m_start.set(refNode, offset, childNode); | 237 m_start.set(refNode, offset, childNode); |
| 238 | 238 |
| 239 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) | 239 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) |
| 240 collapse(true, ec); | 240 collapse(true, ec); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec) | 243 void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionCode& ec) |
| 244 { | 244 { |
| 245 if (!m_start.container()) { | 245 if (!m_start.container()) { |
| 246 ec = INVALID_STATE_ERR; | 246 ec = InvalidStateError; |
| 247 return; | 247 return; |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (!refNode) { | 250 if (!refNode) { |
| 251 ec = NotFoundError; | 251 ec = NotFoundError; |
| 252 return; | 252 return; |
| 253 } | 253 } |
| 254 | 254 |
| 255 bool didMoveDocument = false; | 255 bool didMoveDocument = false; |
| 256 if (refNode->document() != m_ownerDocument) { | 256 if (refNode->document() != m_ownerDocument) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 277 | 277 |
| 278 void Range::setEnd(const Position& end, ExceptionCode& ec) | 278 void Range::setEnd(const Position& end, ExceptionCode& ec) |
| 279 { | 279 { |
| 280 Position parentAnchored = end.parentAnchoredEquivalent(); | 280 Position parentAnchored = end.parentAnchoredEquivalent(); |
| 281 setEnd(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(
), ec); | 281 setEnd(parentAnchored.containerNode(), parentAnchored.offsetInContainerNode(
), ec); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void Range::collapse(bool toStart, ExceptionCode& ec) | 284 void Range::collapse(bool toStart, ExceptionCode& ec) |
| 285 { | 285 { |
| 286 if (!m_start.container()) { | 286 if (!m_start.container()) { |
| 287 ec = INVALID_STATE_ERR; | 287 ec = InvalidStateError; |
| 288 return; | 288 return; |
| 289 } | 289 } |
| 290 | 290 |
| 291 if (toStart) | 291 if (toStart) |
| 292 m_end = m_start; | 292 m_end = m_start; |
| 293 else | 293 else |
| 294 m_start = m_end; | 294 m_start = m_end; |
| 295 } | 295 } |
| 296 | 296 |
| 297 bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec) | 297 bool Range::isPointInRange(Node* refNode, int offset, ExceptionCode& ec) |
| 298 { | 298 { |
| 299 if (!m_start.container()) { | 299 if (!m_start.container()) { |
| 300 ec = INVALID_STATE_ERR; | 300 ec = InvalidStateError; |
| 301 return false; | 301 return false; |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (!refNode) { | 304 if (!refNode) { |
| 305 ec = HierarchyRequestError; | 305 ec = HierarchyRequestError; |
| 306 return false; | 306 return false; |
| 307 } | 307 } |
| 308 | 308 |
| 309 if (!refNode->attached() || refNode->document() != m_ownerDocument) { | 309 if (!refNode->attached() || refNode->document() != m_ownerDocument) { |
| 310 return false; | 310 return false; |
| 311 } | 311 } |
| 312 | 312 |
| 313 ec = 0; | 313 ec = 0; |
| 314 checkNodeWOffset(refNode, offset, ec); | 314 checkNodeWOffset(refNode, offset, ec); |
| 315 if (ec) | 315 if (ec) |
| 316 return false; | 316 return false; |
| 317 | 317 |
| 318 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o
ffset(), ec) >= 0 && !ec | 318 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o
ffset(), ec) >= 0 && !ec |
| 319 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse
t(), ec) <= 0 && !ec; | 319 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse
t(), ec) <= 0 && !ec; |
| 320 } | 320 } |
| 321 | 321 |
| 322 short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const | 322 short Range::comparePoint(Node* refNode, int offset, ExceptionCode& ec) const |
| 323 { | 323 { |
| 324 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint | 324 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint |
| 325 // This method returns -1, 0 or 1 depending on if the point described by the
| 325 // This method returns -1, 0 or 1 depending on if the point described by the
|
| 326 // refNode node and an offset within the node is before, same as, or after t
he range respectively. | 326 // refNode node and an offset within the node is before, same as, or after t
he range respectively. |
| 327 | 327 |
| 328 if (!m_start.container()) { | 328 if (!m_start.container()) { |
| 329 ec = INVALID_STATE_ERR; | 329 ec = InvalidStateError; |
| 330 return 0; | 330 return 0; |
| 331 } | 331 } |
| 332 | 332 |
| 333 if (!refNode) { | 333 if (!refNode) { |
| 334 ec = HierarchyRequestError; | 334 ec = HierarchyRequestError; |
| 335 return 0; | 335 return 0; |
| 336 } | 336 } |
| 337 | 337 |
| 338 if (!refNode->attached() || refNode->document() != m_ownerDocument) { | 338 if (!refNode->attached() || refNode->document() != m_ownerDocument) { |
| 339 ec = WrongDocumentError; | 339 ec = WrongDocumentError; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 365 // http://developer.mozilla.org/en/docs/DOM:range.compareNode | 365 // http://developer.mozilla.org/en/docs/DOM:range.compareNode |
| 366 // This method returns 0, 1, 2, or 3 based on if the node is before, after, | 366 // This method returns 0, 1, 2, or 3 based on if the node is before, after, |
| 367 // before and after(surrounds), or inside the range, respectively | 367 // before and after(surrounds), or inside the range, respectively |
| 368 | 368 |
| 369 if (!refNode) { | 369 if (!refNode) { |
| 370 ec = NotFoundError; | 370 ec = NotFoundError; |
| 371 return NODE_BEFORE; | 371 return NODE_BEFORE; |
| 372 } | 372 } |
| 373 | 373 |
| 374 if (!m_start.container() && refNode->attached()) { | 374 if (!m_start.container() && refNode->attached()) { |
| 375 ec = INVALID_STATE_ERR; | 375 ec = InvalidStateError; |
| 376 return NODE_BEFORE; | 376 return NODE_BEFORE; |
| 377 } | 377 } |
| 378 | 378 |
| 379 if (m_start.container() && !refNode->attached()) { | 379 if (m_start.container() && !refNode->attached()) { |
| 380 // Firefox doesn't throw an exception for this case; it returns 0. | 380 // Firefox doesn't throw an exception for this case; it returns 0. |
| 381 return NODE_BEFORE; | 381 return NODE_BEFORE; |
| 382 } | 382 } |
| 383 | 383 |
| 384 if (refNode->document() != m_ownerDocument) { | 384 if (refNode->document() != m_ownerDocument) { |
| 385 // Firefox doesn't throw an exception for this case; it returns 0. | 385 // Firefox doesn't throw an exception for this case; it returns 0. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 } else { // starts at or after the range start | 403 } else { // starts at or after the range start |
| 404 if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the r
ange | 404 if (comparePoint(parentNode, nodeIndex + 1, ec) > 0) // ends after the r
ange |
| 405 return NODE_AFTER; | 405 return NODE_AFTER; |
| 406 return NODE_INSIDE; // ends inside the range | 406 return NODE_INSIDE; // ends inside the range |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 | 409 |
| 410 short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc
eptionCode& ec) const | 410 short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc
eptionCode& ec) const |
| 411 { | 411 { |
| 412 if (!m_start.container()) { | 412 if (!m_start.container()) { |
| 413 ec = INVALID_STATE_ERR; | 413 ec = InvalidStateError; |
| 414 return 0; | 414 return 0; |
| 415 } | 415 } |
| 416 | 416 |
| 417 if (!sourceRange) { | 417 if (!sourceRange) { |
| 418 ec = NotFoundError; | 418 ec = NotFoundError; |
| 419 return 0; | 419 return 0; |
| 420 } | 420 } |
| 421 | 421 |
| 422 ec = 0; | 422 ec = 0; |
| 423 Node* thisCont = commonAncestorContainer(ec); | 423 Node* thisCont = commonAncestorContainer(ec); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 447 case START_TO_START: | 447 case START_TO_START: |
| 448 return compareBoundaryPoints(m_start, sourceRange->m_start, ec); | 448 return compareBoundaryPoints(m_start, sourceRange->m_start, ec); |
| 449 case START_TO_END: | 449 case START_TO_END: |
| 450 return compareBoundaryPoints(m_end, sourceRange->m_start, ec); | 450 return compareBoundaryPoints(m_end, sourceRange->m_start, ec); |
| 451 case END_TO_END: | 451 case END_TO_END: |
| 452 return compareBoundaryPoints(m_end, sourceRange->m_end, ec); | 452 return compareBoundaryPoints(m_end, sourceRange->m_end, ec); |
| 453 case END_TO_START: | 453 case END_TO_START: |
| 454 return compareBoundaryPoints(m_start, sourceRange->m_end, ec); | 454 return compareBoundaryPoints(m_start, sourceRange->m_end, ec); |
| 455 } | 455 } |
| 456 | 456 |
| 457 ec = SYNTAX_ERR; | 457 ec = SyntaxError; |
| 458 return 0; | 458 return 0; |
| 459 } | 459 } |
| 460 | 460 |
| 461 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe
rB, int offsetB, ExceptionCode& ec) | 461 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe
rB, int offsetB, ExceptionCode& ec) |
| 462 { | 462 { |
| 463 ASSERT(containerA); | 463 ASSERT(containerA); |
| 464 ASSERT(containerB); | 464 ASSERT(containerB); |
| 465 | 465 |
| 466 if (!containerA) | 466 if (!containerA) |
| 467 return -1; | 467 return -1; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 processContents(DELETE_CONTENTS, ec); | 571 processContents(DELETE_CONTENTS, ec); |
| 572 } | 572 } |
| 573 | 573 |
| 574 bool Range::intersectsNode(Node* refNode, ExceptionCode& ec) | 574 bool Range::intersectsNode(Node* refNode, ExceptionCode& ec) |
| 575 { | 575 { |
| 576 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode | 576 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode |
| 577 // Returns a bool if the node intersects the range. | 577 // Returns a bool if the node intersects the range. |
| 578 | 578 |
| 579 // Throw exception if the range is already detached. | 579 // Throw exception if the range is already detached. |
| 580 if (!m_start.container()) { | 580 if (!m_start.container()) { |
| 581 ec = INVALID_STATE_ERR; | 581 ec = InvalidStateError; |
| 582 return false; | 582 return false; |
| 583 } | 583 } |
| 584 if (!refNode) { | 584 if (!refNode) { |
| 585 ec = NotFoundError; | 585 ec = NotFoundError; |
| 586 return false; | 586 return false; |
| 587 } | 587 } |
| 588 | 588 |
| 589 if (!refNode->attached() || refNode->document() != m_ownerDocument) { | 589 if (!refNode->attached() || refNode->document() != m_ownerDocument) { |
| 590 // Firefox doesn't throw an exception for these cases; it returns false. | 590 // Firefox doesn't throw an exception for these cases; it returns false. |
| 591 return false; | 591 return false; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 checkDeleteExtract(ec); | 923 checkDeleteExtract(ec); |
| 924 if (ec) | 924 if (ec) |
| 925 return 0; | 925 return 0; |
| 926 | 926 |
| 927 return processContents(EXTRACT_CONTENTS, ec); | 927 return processContents(EXTRACT_CONTENTS, ec); |
| 928 } | 928 } |
| 929 | 929 |
| 930 PassRefPtr<DocumentFragment> Range::cloneContents(ExceptionCode& ec) | 930 PassRefPtr<DocumentFragment> Range::cloneContents(ExceptionCode& ec) |
| 931 { | 931 { |
| 932 if (!m_start.container()) { | 932 if (!m_start.container()) { |
| 933 ec = INVALID_STATE_ERR; | 933 ec = InvalidStateError; |
| 934 return 0; | 934 return 0; |
| 935 } | 935 } |
| 936 | 936 |
| 937 return processContents(CLONE_CONTENTS, ec); | 937 return processContents(CLONE_CONTENTS, ec); |
| 938 } | 938 } |
| 939 | 939 |
| 940 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec) | 940 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionCode& ec) |
| 941 { | 941 { |
| 942 RefPtr<Node> newNode = prpNewNode; | 942 RefPtr<Node> newNode = prpNewNode; |
| 943 | 943 |
| 944 ec = 0; | 944 ec = 0; |
| 945 | 945 |
| 946 if (!m_start.container()) { | 946 if (!m_start.container()) { |
| 947 ec = INVALID_STATE_ERR; | 947 ec = InvalidStateError; |
| 948 return; | 948 return; |
| 949 } | 949 } |
| 950 | 950 |
| 951 if (!newNode) { | 951 if (!newNode) { |
| 952 ec = NotFoundError; | 952 ec = NotFoundError; |
| 953 return; | 953 return; |
| 954 } | 954 } |
| 955 | 955 |
| 956 // HierarchyRequestError: Raised if the container of the start of the Range
is of a type that | 956 // HierarchyRequestError: Raised if the container of the start of the Range
is of a type that |
| 957 // does not allow children of the type of newNode or if newNode is an ancest
or of the container. | 957 // does not allow children of the type of newNode or if newNode is an ancest
or of the container. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 return; | 1042 return; |
| 1043 | 1043 |
| 1044 if (collapsed && numNewChildren) | 1044 if (collapsed && numNewChildren) |
| 1045 m_end.set(m_start.container(), startOffset + numNewChildren, lastChi
ld.get()); | 1045 m_end.set(m_start.container(), startOffset + numNewChildren, lastChi
ld.get()); |
| 1046 } | 1046 } |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 String Range::toString(ExceptionCode& ec) const | 1049 String Range::toString(ExceptionCode& ec) const |
| 1050 { | 1050 { |
| 1051 if (!m_start.container()) { | 1051 if (!m_start.container()) { |
| 1052 ec = INVALID_STATE_ERR; | 1052 ec = InvalidStateError; |
| 1053 return String(); | 1053 return String(); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 StringBuilder builder; | 1056 StringBuilder builder; |
| 1057 | 1057 |
| 1058 Node* pastLast = pastLastNode(); | 1058 Node* pastLast = pastLastNode(); |
| 1059 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) { | 1059 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) { |
| 1060 if (n->nodeType() == Node::TEXT_NODE || n->nodeType() == Node::CDATA_SEC
TION_NODE) { | 1060 if (n->nodeType() == Node::TEXT_NODE || n->nodeType() == Node::CDATA_SEC
TION_NODE) { |
| 1061 String data = static_cast<CharacterData*>(n)->data(); | 1061 String data = static_cast<CharacterData*>(n)->data(); |
| 1062 int length = data.length(); | 1062 int length = data.length(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1082 // We need to update layout, since plainText uses line boxes in the render t
ree. | 1082 // We need to update layout, since plainText uses line boxes in the render t
ree. |
| 1083 // FIXME: As with innerText, we'd like this to work even if there are no ren
der objects. | 1083 // FIXME: As with innerText, we'd like this to work even if there are no ren
der objects. |
| 1084 m_start.container()->document()->updateLayout(); | 1084 m_start.container()->document()->updateLayout(); |
| 1085 | 1085 |
| 1086 return plainText(this); | 1086 return plainText(this); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku
p, ExceptionCode& ec) | 1089 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku
p, ExceptionCode& ec) |
| 1090 { | 1090 { |
| 1091 if (!m_start.container()) { | 1091 if (!m_start.container()) { |
| 1092 ec = INVALID_STATE_ERR; | 1092 ec = InvalidStateError; |
| 1093 return 0; | 1093 return 0; |
| 1094 } | 1094 } |
| 1095 | 1095 |
| 1096 Node* element = m_start.container()->isElementNode() ? m_start.container() :
m_start.container()->parentNode(); | 1096 Node* element = m_start.container()->isElementNode() ? m_start.container() :
m_start.container()->parentNode(); |
| 1097 if (!element || !element->isHTMLElement()) { | 1097 if (!element || !element->isHTMLElement()) { |
| 1098 ec = NotSupportedError; | 1098 ec = NotSupportedError; |
| 1099 return 0; | 1099 return 0; |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup
, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec); | 1102 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup
, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, ec); |
| 1103 if (!fragment) | 1103 if (!fragment) |
| 1104 return 0; | 1104 return 0; |
| 1105 | 1105 |
| 1106 return fragment.release(); | 1106 return fragment.release(); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 | 1109 |
| 1110 void Range::detach(ExceptionCode& ec) | 1110 void Range::detach(ExceptionCode& ec) |
| 1111 { | 1111 { |
| 1112 // Check first to see if we've already detached: | 1112 // Check first to see if we've already detached: |
| 1113 if (!m_start.container()) { | 1113 if (!m_start.container()) { |
| 1114 ec = INVALID_STATE_ERR; | 1114 ec = InvalidStateError; |
| 1115 return; | 1115 return; |
| 1116 } | 1116 } |
| 1117 | 1117 |
| 1118 m_ownerDocument->detachRange(this); | 1118 m_ownerDocument->detachRange(this); |
| 1119 | 1119 |
| 1120 m_start.clear(); | 1120 m_start.clear(); |
| 1121 m_end.clear(); | 1121 m_end.clear(); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const | 1124 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionCode& ec) const |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 case Node::TEXT_NODE: | 1199 case Node::TEXT_NODE: |
| 1200 case Node::XPATH_NAMESPACE_NODE: | 1200 case Node::XPATH_NAMESPACE_NODE: |
| 1201 ec = INVALID_NODE_TYPE_ERR; | 1201 ec = INVALID_NODE_TYPE_ERR; |
| 1202 return; | 1202 return; |
| 1203 } | 1203 } |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 PassRefPtr<Range> Range::cloneRange(ExceptionCode& ec) const | 1206 PassRefPtr<Range> Range::cloneRange(ExceptionCode& ec) const |
| 1207 { | 1207 { |
| 1208 if (!m_start.container()) { | 1208 if (!m_start.container()) { |
| 1209 ec = INVALID_STATE_ERR; | 1209 ec = InvalidStateError; |
| 1210 return 0; | 1210 return 0; |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 return Range::create(m_ownerDocument, m_start.container(), m_start.offset(),
m_end.container(), m_end.offset()); | 1213 return Range::create(m_ownerDocument, m_start.container(), m_start.offset(),
m_end.container(), m_end.offset()); |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 void Range::setStartAfter(Node* refNode, ExceptionCode& ec) | 1216 void Range::setStartAfter(Node* refNode, ExceptionCode& ec) |
| 1217 { | 1217 { |
| 1218 if (!m_start.container()) { | 1218 if (!m_start.container()) { |
| 1219 ec = INVALID_STATE_ERR; | 1219 ec = InvalidStateError; |
| 1220 return; | 1220 return; |
| 1221 } | 1221 } |
| 1222 | 1222 |
| 1223 if (!refNode) { | 1223 if (!refNode) { |
| 1224 ec = NotFoundError; | 1224 ec = NotFoundError; |
| 1225 return; | 1225 return; |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 ec = 0; | 1228 ec = 0; |
| 1229 checkNodeBA(refNode, ec); | 1229 checkNodeBA(refNode, ec); |
| 1230 if (ec) | 1230 if (ec) |
| 1231 return; | 1231 return; |
| 1232 | 1232 |
| 1233 setStart(refNode->parentNode(), refNode->nodeIndex() + 1, ec); | 1233 setStart(refNode->parentNode(), refNode->nodeIndex() + 1, ec); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 void Range::setEndBefore(Node* refNode, ExceptionCode& ec) | 1236 void Range::setEndBefore(Node* refNode, ExceptionCode& ec) |
| 1237 { | 1237 { |
| 1238 if (!m_start.container()) { | 1238 if (!m_start.container()) { |
| 1239 ec = INVALID_STATE_ERR; | 1239 ec = InvalidStateError; |
| 1240 return; | 1240 return; |
| 1241 } | 1241 } |
| 1242 | 1242 |
| 1243 if (!refNode) { | 1243 if (!refNode) { |
| 1244 ec = NotFoundError; | 1244 ec = NotFoundError; |
| 1245 return; | 1245 return; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 ec = 0; | 1248 ec = 0; |
| 1249 checkNodeBA(refNode, ec); | 1249 checkNodeBA(refNode, ec); |
| 1250 if (ec) | 1250 if (ec) |
| 1251 return; | 1251 return; |
| 1252 | 1252 |
| 1253 setEnd(refNode->parentNode(), refNode->nodeIndex(), ec); | 1253 setEnd(refNode->parentNode(), refNode->nodeIndex(), ec); |
| 1254 } | 1254 } |
| 1255 | 1255 |
| 1256 void Range::setEndAfter(Node* refNode, ExceptionCode& ec) | 1256 void Range::setEndAfter(Node* refNode, ExceptionCode& ec) |
| 1257 { | 1257 { |
| 1258 if (!m_start.container()) { | 1258 if (!m_start.container()) { |
| 1259 ec = INVALID_STATE_ERR; | 1259 ec = InvalidStateError; |
| 1260 return; | 1260 return; |
| 1261 } | 1261 } |
| 1262 | 1262 |
| 1263 if (!refNode) { | 1263 if (!refNode) { |
| 1264 ec = NotFoundError; | 1264 ec = NotFoundError; |
| 1265 return; | 1265 return; |
| 1266 } | 1266 } |
| 1267 | 1267 |
| 1268 ec = 0; | 1268 ec = 0; |
| 1269 checkNodeBA(refNode, ec); | 1269 checkNodeBA(refNode, ec); |
| 1270 if (ec) | 1270 if (ec) |
| 1271 return; | 1271 return; |
| 1272 | 1272 |
| 1273 setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, ec); | 1273 setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, ec); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 void Range::selectNode(Node* refNode, ExceptionCode& ec) | 1276 void Range::selectNode(Node* refNode, ExceptionCode& ec) |
| 1277 { | 1277 { |
| 1278 if (!m_start.container()) { | 1278 if (!m_start.container()) { |
| 1279 ec = INVALID_STATE_ERR; | 1279 ec = InvalidStateError; |
| 1280 return; | 1280 return; |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 if (!refNode) { | 1283 if (!refNode) { |
| 1284 ec = NotFoundError; | 1284 ec = NotFoundError; |
| 1285 return; | 1285 return; |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 // INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Entity, Not
ation or | 1288 // INVALID_NODE_TYPE_ERR: Raised if an ancestor of refNode is an Entity, Not
ation or |
| 1289 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo
ot, Attr, Entity, or Notation | 1289 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo
ot, Attr, Entity, or Notation |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 ec = 0; | 1332 ec = 0; |
| 1333 setStartBefore(refNode, ec); | 1333 setStartBefore(refNode, ec); |
| 1334 if (ec) | 1334 if (ec) |
| 1335 return; | 1335 return; |
| 1336 setEndAfter(refNode, ec); | 1336 setEndAfter(refNode, ec); |
| 1337 } | 1337 } |
| 1338 | 1338 |
| 1339 void Range::selectNodeContents(Node* refNode, ExceptionCode& ec) | 1339 void Range::selectNodeContents(Node* refNode, ExceptionCode& ec) |
| 1340 { | 1340 { |
| 1341 if (!m_start.container()) { | 1341 if (!m_start.container()) { |
| 1342 ec = INVALID_STATE_ERR; | 1342 ec = InvalidStateError; |
| 1343 return; | 1343 return; |
| 1344 } | 1344 } |
| 1345 | 1345 |
| 1346 if (!refNode) { | 1346 if (!refNode) { |
| 1347 ec = NotFoundError; | 1347 ec = NotFoundError; |
| 1348 return; | 1348 return; |
| 1349 } | 1349 } |
| 1350 | 1350 |
| 1351 // INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an
Entity, Notation | 1351 // INVALID_NODE_TYPE_ERR: Raised if refNode or an ancestor of refNode is an
Entity, Notation |
| 1352 // or DocumentType node. | 1352 // or DocumentType node. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1375 | 1375 |
| 1376 m_start.setToStartOfNode(refNode); | 1376 m_start.setToStartOfNode(refNode); |
| 1377 m_end.setToEndOfNode(refNode); | 1377 m_end.setToEndOfNode(refNode); |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec) | 1380 void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionCode& ec) |
| 1381 { | 1381 { |
| 1382 RefPtr<Node> newParent = passNewParent; | 1382 RefPtr<Node> newParent = passNewParent; |
| 1383 | 1383 |
| 1384 if (!m_start.container()) { | 1384 if (!m_start.container()) { |
| 1385 ec = INVALID_STATE_ERR; | 1385 ec = InvalidStateError; |
| 1386 return; | 1386 return; |
| 1387 } | 1387 } |
| 1388 | 1388 |
| 1389 if (!newParent) { | 1389 if (!newParent) { |
| 1390 ec = NotFoundError; | 1390 ec = NotFoundError; |
| 1391 return; | 1391 return; |
| 1392 } | 1392 } |
| 1393 | 1393 |
| 1394 // INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, N
otation, | 1394 // INVALID_NODE_TYPE_ERR: Raised if node is an Attr, Entity, DocumentType, N
otation, |
| 1395 // Document, or DocumentFragment node. | 1395 // Document, or DocumentFragment node. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 // allowed by the type of node? | 1433 // allowed by the type of node? |
| 1434 | 1434 |
| 1435 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text
node. | 1435 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text
node. |
| 1436 Node* startNonTextContainer = m_start.container(); | 1436 Node* startNonTextContainer = m_start.container(); |
| 1437 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) | 1437 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) |
| 1438 startNonTextContainer = startNonTextContainer->parentNode(); | 1438 startNonTextContainer = startNonTextContainer->parentNode(); |
| 1439 Node* endNonTextContainer = m_end.container(); | 1439 Node* endNonTextContainer = m_end.container(); |
| 1440 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) | 1440 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) |
| 1441 endNonTextContainer = endNonTextContainer->parentNode(); | 1441 endNonTextContainer = endNonTextContainer->parentNode(); |
| 1442 if (startNonTextContainer != endNonTextContainer) { | 1442 if (startNonTextContainer != endNonTextContainer) { |
| 1443 ec = INVALID_STATE_ERR; | 1443 ec = InvalidStateError; |
| 1444 return; | 1444 return; |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 ec = 0; | 1447 ec = 0; |
| 1448 while (Node* n = newParent->firstChild()) { | 1448 while (Node* n = newParent->firstChild()) { |
| 1449 toContainerNode(newParent.get())->removeChild(n, ec); | 1449 toContainerNode(newParent.get())->removeChild(n, ec); |
| 1450 if (ec) | 1450 if (ec) |
| 1451 return; | 1451 return; |
| 1452 } | 1452 } |
| 1453 RefPtr<DocumentFragment> fragment = extractContents(ec); | 1453 RefPtr<DocumentFragment> fragment = extractContents(ec); |
| 1454 if (ec) | 1454 if (ec) |
| 1455 return; | 1455 return; |
| 1456 insertNode(newParent, ec); | 1456 insertNode(newParent, ec); |
| 1457 if (ec) | 1457 if (ec) |
| 1458 return; | 1458 return; |
| 1459 newParent->appendChild(fragment.release(), ec); | 1459 newParent->appendChild(fragment.release(), ec); |
| 1460 if (ec) | 1460 if (ec) |
| 1461 return; | 1461 return; |
| 1462 selectNode(newParent.get(), ec); | 1462 selectNode(newParent.get(), ec); |
| 1463 } | 1463 } |
| 1464 | 1464 |
| 1465 void Range::setStartBefore(Node* refNode, ExceptionCode& ec) | 1465 void Range::setStartBefore(Node* refNode, ExceptionCode& ec) |
| 1466 { | 1466 { |
| 1467 if (!m_start.container()) { | 1467 if (!m_start.container()) { |
| 1468 ec = INVALID_STATE_ERR; | 1468 ec = InvalidStateError; |
| 1469 return; | 1469 return; |
| 1470 } | 1470 } |
| 1471 | 1471 |
| 1472 if (!refNode) { | 1472 if (!refNode) { |
| 1473 ec = NotFoundError; | 1473 ec = NotFoundError; |
| 1474 return; | 1474 return; |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 ec = 0; | 1477 ec = 0; |
| 1478 checkNodeBA(refNode, ec); | 1478 checkNodeBA(refNode, ec); |
| 1479 if (ec) | 1479 if (ec) |
| 1480 return; | 1480 return; |
| 1481 | 1481 |
| 1482 setStart(refNode->parentNode(), refNode->nodeIndex(), ec); | 1482 setStart(refNode->parentNode(), refNode->nodeIndex(), ec); |
| 1483 } | 1483 } |
| 1484 | 1484 |
| 1485 void Range::checkDeleteExtract(ExceptionCode& ec) | 1485 void Range::checkDeleteExtract(ExceptionCode& ec) |
| 1486 { | 1486 { |
| 1487 if (!m_start.container()) { | 1487 if (!m_start.container()) { |
| 1488 ec = INVALID_STATE_ERR; | 1488 ec = InvalidStateError; |
| 1489 return; | 1489 return; |
| 1490 } | 1490 } |
| 1491 | 1491 |
| 1492 ec = 0; | 1492 ec = 0; |
| 1493 if (!commonAncestorContainer(ec) || ec) | 1493 if (!commonAncestorContainer(ec) || ec) |
| 1494 return; | 1494 return; |
| 1495 | 1495 |
| 1496 Node* pastLast = pastLastNode(); | 1496 Node* pastLast = pastLastNode(); |
| 1497 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) { | 1497 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) { |
| 1498 if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) { | 1498 if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) { |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 | 1921 |
| 1922 void showTree(const WebCore::Range* range) | 1922 void showTree(const WebCore::Range* range) |
| 1923 { | 1923 { |
| 1924 if (range && range->boundaryPointsValid()) { | 1924 if (range && range->boundaryPointsValid()) { |
| 1925 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); | 1925 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r
ange->endContainer(), "E"); |
| 1926 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); | 1926 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset
(), range->endOffset()); |
| 1927 } | 1927 } |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 #endif | 1930 #endif |
| OLD | NEW |