| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionCode& ec) | 291 PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionCode& ec) |
| 292 { | 292 { |
| 293 if (!m_frame) | 293 if (!m_frame) |
| 294 return 0; | 294 return 0; |
| 295 | 295 |
| 296 if (index < 0 || index >= rangeCount()) { | 296 if (index < 0 || index >= rangeCount()) { |
| 297 ec = INDEX_SIZE_ERR; | 297 ec = INDEX_SIZE_ERR; |
| 298 return 0; | 298 return 0; |
| 299 } | 299 } |
| 300 | 300 |
| 301 // If you're hitting this, you've added broken multi-range selection support |
| 302 ASSERT(rangeCount() == 1); |
| 303 |
| 301 const Selection& selection = m_frame->selection()->selection(); | 304 const Selection& selection = m_frame->selection()->selection(); |
| 302 return selection.toRange(); | 305 return selection.firstRange(); |
| 303 } | 306 } |
| 304 | 307 |
| 305 void DOMSelection::removeAllRanges() | 308 void DOMSelection::removeAllRanges() |
| 306 { | 309 { |
| 307 if (!m_frame) | 310 if (!m_frame) |
| 308 return; | 311 return; |
| 309 m_frame->selection()->clear(); | 312 m_frame->selection()->clear(); |
| 310 } | 313 } |
| 311 | 314 |
| 312 void DOMSelection::addRange(Range* r) | 315 void DOMSelection::addRange(Range* r) |
| 313 { | 316 { |
| 314 if (!m_frame) | 317 if (!m_frame) |
| 315 return; | 318 return; |
| 316 if (!r) | 319 if (!r) |
| 317 return; | 320 return; |
| 318 | 321 |
| 319 SelectionController* selection = m_frame->selection(); | 322 SelectionController* selection = m_frame->selection(); |
| 320 | 323 |
| 321 if (selection->isNone()) { | 324 if (selection->isNone()) { |
| 322 selection->setSelection(Selection(r)); | 325 selection->setSelection(Selection(r)); |
| 323 return; | 326 return; |
| 324 } | 327 } |
| 325 | 328 |
| 326 RefPtr<Range> range = selection->selection().toRange(); | 329 RefPtr<Range> range = selection->selection().toNormalizedRange(); |
| 327 ExceptionCode ec = 0; | 330 ExceptionCode ec = 0; |
| 328 if (r->compareBoundaryPoints(Range::START_TO_START, range.get(), ec) == -1)
{ | 331 if (r->compareBoundaryPoints(Range::START_TO_START, range.get(), ec) == -1)
{ |
| 329 // We don't support discontiguous selection. We don't do anything if r a
nd range don't intersect. | 332 // We don't support discontiguous selection. We don't do anything if r a
nd range don't intersect. |
| 330 if (r->compareBoundaryPoints(Range::START_TO_END, range.get(), ec) > -1)
{ | 333 if (r->compareBoundaryPoints(Range::START_TO_END, range.get(), ec) > -1)
{ |
| 331 if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), ec) ==
-1) | 334 if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), ec) ==
-1) |
| 332 // The original range and r intersect. | 335 // The original range and r intersect. |
| 333 selection->setSelection(Selection(r->startPosition(), range->end
Position(), DOWNSTREAM)); | 336 selection->setSelection(Selection(r->startPosition(), range->end
Position(), DOWNSTREAM)); |
| 334 else | 337 else |
| 335 // r contains the original range. | 338 // r contains the original range. |
| 336 selection->setSelection(Selection(r)); | 339 selection->setSelection(Selection(r)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 354 return; | 357 return; |
| 355 | 358 |
| 356 SelectionController* selection = m_frame->selection(); | 359 SelectionController* selection = m_frame->selection(); |
| 357 | 360 |
| 358 if (selection->isNone()) | 361 if (selection->isNone()) |
| 359 return; | 362 return; |
| 360 | 363 |
| 361 if (isCollapsed()) | 364 if (isCollapsed()) |
| 362 selection->modify(SelectionController::EXTEND, SelectionController::BACK
WARD, CharacterGranularity); | 365 selection->modify(SelectionController::EXTEND, SelectionController::BACK
WARD, CharacterGranularity); |
| 363 | 366 |
| 364 RefPtr<Range> selectedRange = selection->selection().toRange(); | 367 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); |
| 365 | 368 |
| 366 ExceptionCode ec = 0; | 369 ExceptionCode ec = 0; |
| 367 selectedRange->deleteContents(ec); | 370 selectedRange->deleteContents(ec); |
| 368 ASSERT(!ec); | 371 ASSERT(!ec); |
| 369 | 372 |
| 370 setBaseAndExtent(selectedRange->startContainer(ec), selectedRange->startOffs
et(ec), selectedRange->startContainer(ec), selectedRange->startOffset(ec), ec); | 373 setBaseAndExtent(selectedRange->startContainer(ec), selectedRange->startOffs
et(ec), selectedRange->startContainer(ec), selectedRange->startOffset(ec), ec); |
| 371 ASSERT(!ec); | 374 ASSERT(!ec); |
| 372 } | 375 } |
| 373 | 376 |
| 374 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const | 377 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const |
| 375 { | 378 { |
| 376 if (!m_frame) | 379 if (!m_frame) |
| 377 return false; | 380 return false; |
| 378 | 381 |
| 379 SelectionController* selection = m_frame->selection(); | 382 SelectionController* selection = m_frame->selection(); |
| 380 | 383 |
| 381 if (!n || selection->isNone()) | 384 if (!n || selection->isNone()) |
| 382 return false; | 385 return false; |
| 383 | 386 |
| 384 Node* parentNode = n->parentNode(); | 387 Node* parentNode = n->parentNode(); |
| 385 unsigned nodeIndex = n->nodeIndex(); | 388 unsigned nodeIndex = n->nodeIndex(); |
| 386 RefPtr<Range> selectedRange = selection->selection().toRange(); | 389 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); |
| 387 | 390 |
| 388 if (!parentNode) | 391 if (!parentNode) |
| 389 return false; | 392 return false; |
| 390 | 393 |
| 391 ExceptionCode ec = 0; | 394 ExceptionCode ec = 0; |
| 392 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex,
selectedRange->startContainer(ec), selectedRange->startOffset(ec)) >= 0 | 395 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex,
selectedRange->startContainer(ec), selectedRange->startOffset(ec)) >= 0 |
| 393 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange
->endContainer(ec), selectedRange->endOffset(ec)) <= 0; | 396 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange
->endContainer(ec), selectedRange->endOffset(ec)) <= 0; |
| 394 ASSERT(!ec); | 397 ASSERT(!ec); |
| 395 if (nodeFullySelected) | 398 if (nodeFullySelected) |
| 396 return true; | 399 return true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 411 | 414 |
| 412 // This doesn't (and shouldn't) select text node characters. | 415 // This doesn't (and shouldn't) select text node characters. |
| 413 setBaseAndExtent(n, 0, n, n->childNodeCount(), ec); | 416 setBaseAndExtent(n, 0, n, n->childNodeCount(), ec); |
| 414 } | 417 } |
| 415 | 418 |
| 416 String DOMSelection::toString() | 419 String DOMSelection::toString() |
| 417 { | 420 { |
| 418 if (!m_frame) | 421 if (!m_frame) |
| 419 return String(); | 422 return String(); |
| 420 | 423 |
| 421 return plainText(m_frame->selection()->selection().toRange().get()); | 424 return plainText(m_frame->selection()->selection().toNormalizedRange().get()
); |
| 422 } | 425 } |
| 423 | 426 |
| 424 } // namespace WebCore | 427 } // namespace WebCore |
| OLD | NEW |