| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 | 215 |
| 216 if (offset < 0) { | 216 if (offset < 0) { |
| 217 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is not a valid offset."); | 217 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is not a valid offset."); |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 if (!isValidForPosition(node)) | 221 if (!isValidForPosition(node)) |
| 222 return; | 222 return; |
| 223 RefPtrWillBeRawPtr<Range> range = Range::create(node->document()); | 223 RawPtr<Range> range = Range::create(node->document()); |
| 224 range->setStart(node, offset, exceptionState); | 224 range->setStart(node, offset, exceptionState); |
| 225 if (exceptionState.hadException()) | 225 if (exceptionState.hadException()) |
| 226 return; | 226 return; |
| 227 range->setEnd(node, offset, exceptionState); | 227 range->setEnd(node, offset, exceptionState); |
| 228 if (exceptionState.hadException()) | 228 if (exceptionState.hadException()) |
| 229 return; | 229 return; |
| 230 m_frame->selection().setSelectedRange(range.get(), TextAffinity::Downstream,
m_frame->selection().isDirectional() ? SelectionDirectionalMode::Directional :
SelectionDirectionalMode::NonDirectional); | 230 m_frame->selection().setSelectedRange(range.get(), TextAffinity::Downstream,
m_frame->selection().isDirectional() ? SelectionDirectionalMode::Directional :
SelectionDirectionalMode::NonDirectional); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) | 233 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is larger than the given node's length."); | 359 exceptionState.throwDOMException(IndexSizeError, String::number(offset)
+ " is larger than the given node's length."); |
| 360 return; | 360 return; |
| 361 } | 361 } |
| 362 | 362 |
| 363 if (!isValidForPosition(node)) | 363 if (!isValidForPosition(node)) |
| 364 return; | 364 return; |
| 365 | 365 |
| 366 m_frame->selection().setExtent(createVisiblePosition(createPosition(node, of
fset))); | 366 m_frame->selection().setExtent(createVisiblePosition(createPosition(node, of
fset))); |
| 367 } | 367 } |
| 368 | 368 |
| 369 PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState
& exceptionState) | 369 RawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& exceptionState
) |
| 370 { | 370 { |
| 371 if (!m_frame) | 371 if (!m_frame) |
| 372 return nullptr; | 372 return nullptr; |
| 373 | 373 |
| 374 if (index < 0 || index >= rangeCount()) { | 374 if (index < 0 || index >= rangeCount()) { |
| 375 exceptionState.throwDOMException(IndexSizeError, String::number(index) +
" is not a valid index."); | 375 exceptionState.throwDOMException(IndexSizeError, String::number(index) +
" is not a valid index."); |
| 376 return nullptr; | 376 return nullptr; |
| 377 } | 377 } |
| 378 | 378 |
| 379 // If you're hitting this, you've added broken multi-range selection support | 379 // If you're hitting this, you've added broken multi-range selection support |
| (...skipping 27 matching lines...) Expand all Loading... |
| 407 return; | 407 return; |
| 408 } | 408 } |
| 409 | 409 |
| 410 FrameSelection& selection = m_frame->selection(); | 410 FrameSelection& selection = m_frame->selection(); |
| 411 | 411 |
| 412 if (selection.isNone()) { | 412 if (selection.isNone()) { |
| 413 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY); | 413 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY); |
| 414 return; | 414 return; |
| 415 } | 415 } |
| 416 | 416 |
| 417 RefPtrWillBeRawPtr<Range> originalRange = selection.firstRange(); | 417 RawPtr<Range> originalRange = selection.firstRange(); |
| 418 | 418 |
| 419 if (originalRange->startContainer()->document() != newRange->startContainer(
)->document()) { | 419 if (originalRange->startContainer()->document() != newRange->startContainer(
)->document()) { |
| 420 addConsoleError("The given range does not belong to the current selectio
n's document."); | 420 addConsoleError("The given range does not belong to the current selectio
n's document."); |
| 421 return; | 421 return; |
| 422 } | 422 } |
| 423 if (originalRange->startContainer()->treeScope() != newRange->startContainer
()->treeScope()) { | 423 if (originalRange->startContainer()->treeScope() != newRange->startContainer
()->treeScope()) { |
| 424 addConsoleError("The given range and the current selection belong to two
different document fragments."); | 424 addConsoleError("The given range and the current selection belong to two
different document fragments."); |
| 425 return; | 425 return; |
| 426 } | 426 } |
| 427 | 427 |
| 428 if (originalRange->compareBoundaryPoints(Range::START_TO_END, newRange, ASSE
RT_NO_EXCEPTION) < 0 | 428 if (originalRange->compareBoundaryPoints(Range::START_TO_END, newRange, ASSE
RT_NO_EXCEPTION) < 0 |
| 429 || newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.ge
t(), ASSERT_NO_EXCEPTION) < 0) { | 429 || newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.ge
t(), ASSERT_NO_EXCEPTION) < 0) { |
| 430 addConsoleError("Discontiguous selection is not supported."); | 430 addConsoleError("Discontiguous selection is not supported."); |
| 431 return; | 431 return; |
| 432 } | 432 } |
| 433 | 433 |
| 434 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; o
ther browsers supporting discontiguous | 434 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; o
ther browsers supporting discontiguous |
| 435 // selection (obviously) keep each Range added and return it in getRangeAt()
. But it's unclear if we can really | 435 // selection (obviously) keep each Range added and return it in getRangeAt()
. But it's unclear if we can really |
| 436 // do the same, since we don't support discontiguous selection. Further disc
ussions at | 436 // do the same, since we don't support discontiguous selection. Further disc
ussions at |
| 437 // <https://code.google.com/p/chromium/issues/detail?id=353069>. | 437 // <https://code.google.com/p/chromium/issues/detail?id=353069>. |
| 438 | 438 |
| 439 Range* start = originalRange->compareBoundaryPoints(Range::START_TO_START, n
ewRange, ASSERT_NO_EXCEPTION) < 0 ? originalRange.get() : newRange; | 439 Range* start = originalRange->compareBoundaryPoints(Range::START_TO_START, n
ewRange, ASSERT_NO_EXCEPTION) < 0 ? originalRange.get() : newRange; |
| 440 Range* end = originalRange->compareBoundaryPoints(Range::END_TO_END, newRang
e, ASSERT_NO_EXCEPTION) < 0 ? newRange : originalRange.get(); | 440 Range* end = originalRange->compareBoundaryPoints(Range::END_TO_END, newRang
e, ASSERT_NO_EXCEPTION) < 0 ? newRange : originalRange.get(); |
| 441 RefPtrWillBeRawPtr<Range> merged = Range::create(originalRange->startContain
er()->document(), start->startContainer(), start->startOffset(), end->endContain
er(), end->endOffset()); | 441 RawPtr<Range> merged = Range::create(originalRange->startContainer()->docume
nt(), start->startContainer(), start->startOffset(), end->endContainer(), end->e
ndOffset()); |
| 442 TextAffinity affinity = selection.selection().affinity(); | 442 TextAffinity affinity = selection.selection().affinity(); |
| 443 selection.setSelectedRange(merged.get(), affinity); | 443 selection.setSelectedRange(merged.get(), affinity); |
| 444 } | 444 } |
| 445 | 445 |
| 446 void DOMSelection::deleteFromDocument() | 446 void DOMSelection::deleteFromDocument() |
| 447 { | 447 { |
| 448 if (!m_frame) | 448 if (!m_frame) |
| 449 return; | 449 return; |
| 450 | 450 |
| 451 FrameSelection& selection = m_frame->selection(); | 451 FrameSelection& selection = m_frame->selection(); |
| 452 | 452 |
| 453 if (selection.isNone()) | 453 if (selection.isNone()) |
| 454 return; | 454 return; |
| 455 | 455 |
| 456 RefPtrWillBeRawPtr<Range> selectedRange = createRange(selection.selection().
toNormalizedEphemeralRange()); | 456 RawPtr<Range> selectedRange = createRange(selection.selection().toNormalized
EphemeralRange()); |
| 457 if (!selectedRange) | 457 if (!selectedRange) |
| 458 return; | 458 return; |
| 459 | 459 |
| 460 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); | 460 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); |
| 461 | 461 |
| 462 setBaseAndExtent(selectedRange->startContainer(), selectedRange->startOffset
(), selectedRange->startContainer(), selectedRange->startOffset(), ASSERT_NO_EXC
EPTION); | 462 setBaseAndExtent(selectedRange->startContainer(), selectedRange->startOffset
(), selectedRange->startContainer(), selectedRange->startOffset(), ASSERT_NO_EXC
EPTION); |
| 463 } | 463 } |
| 464 | 464 |
| 465 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const | 465 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const |
| 466 { | 466 { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa
geSource, ErrorMessageLevel, message)); | 566 m_treeScope->document().addConsoleMessage(ConsoleMessage::create(JSMessa
geSource, ErrorMessageLevel, message)); |
| 567 } | 567 } |
| 568 | 568 |
| 569 DEFINE_TRACE(DOMSelection) | 569 DEFINE_TRACE(DOMSelection) |
| 570 { | 570 { |
| 571 visitor->trace(m_treeScope); | 571 visitor->trace(m_treeScope); |
| 572 DOMWindowProperty::trace(visitor); | 572 DOMWindowProperty::trace(visitor); |
| 573 } | 573 } |
| 574 | 574 |
| 575 } // namespace blink | 575 } // namespace blink |
| OLD | NEW |