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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 return; | 395 return; |
396 } | 396 } |
397 | 397 |
398 FrameSelection& selection = m_frame->selection(); | 398 FrameSelection& selection = m_frame->selection(); |
399 | 399 |
400 if (selection.isNone()) { | 400 if (selection.isNone()) { |
401 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY); | 401 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY); |
402 return; | 402 return; |
403 } | 403 } |
404 | 404 |
405 RefPtr<Range> originalRange = selection.selection().toNormalizedRange(); | 405 RefPtr<Range> originalRange = selection.firstRange(); |
406 | 406 |
407 if (originalRange->startContainer()->document() != newRange->startContainer(
)->document()) { | 407 if (originalRange->startContainer()->document() != newRange->startContainer(
)->document()) { |
408 addConsoleError("The given range does not belong to the current selectio
n's document."); | 408 addConsoleError("The given range does not belong to the current selectio
n's document."); |
409 return; | 409 return; |
410 } | 410 } |
411 if (originalRange->startContainer()->treeScope() != newRange->startContainer
()->treeScope()) { | 411 if (originalRange->startContainer()->treeScope() != newRange->startContainer
()->treeScope()) { |
412 addConsoleError("The given range and the current selection belong to two
different document fragments."); | 412 addConsoleError("The given range and the current selection belong to two
different document fragments."); |
413 return; | 413 return; |
414 } | 414 } |
415 | 415 |
416 // FIXME: Emit a console error if the combined ranges would form a discontig
uous selection. | 416 if (originalRange->compareBoundaryPoints(Range::START_TO_END, newRange, ASSE
RT_NO_EXCEPTION) < 0 |
417 if (newRange->compareBoundaryPoints(Range::START_TO_START, originalRange.get
(), ASSERT_NO_EXCEPTION) == -1) { | 417 || newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.ge
t(), ASSERT_NO_EXCEPTION) < 0) { |
418 // We don't support discontiguous selection. We don't do anything if new
Range and originalRange don't intersect. | 418 addConsoleError("Discontiguous selection is not supported."); |
419 if (newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.g
et(), ASSERT_NO_EXCEPTION) > -1) { | 419 return; |
420 if (newRange->compareBoundaryPoints(Range::END_TO_END, originalRange
.get(), ASSERT_NO_EXCEPTION) == -1) { | |
421 // The original originalRange and newRange intersect. | |
422 selection.setSelection(VisibleSelection(newRange->startPosition(
), originalRange->endPosition(), DOWNSTREAM)); | |
423 } else { | |
424 // newRange contains the original originalRange. | |
425 selection.setSelection(VisibleSelection(newRange)); | |
426 } | |
427 } | |
428 } else { | |
429 // We don't support discontiguous selection. We don't do anything if new
Range and originalRange don't intersect. | |
430 if (newRange->compareBoundaryPoints(Range::END_TO_START, originalRange.g
et(), ASSERT_NO_EXCEPTION) < 1) { | |
431 if (newRange->compareBoundaryPoints(Range::END_TO_END, originalRange
.get(), ASSERT_NO_EXCEPTION) == -1) { | |
432 // The original range contains newRange. | |
433 selection.setSelection(VisibleSelection(originalRange.get())); | |
434 } else { | |
435 // The original range and r intersect. | |
436 selection.setSelection(VisibleSelection(originalRange->startPosi
tion(), newRange->endPosition(), DOWNSTREAM)); | |
437 } | |
438 } | |
439 } | 420 } |
| 421 |
| 422 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; o
ther browsers supporting discontiguous |
| 423 // selection (obviously) keep each Range added and return it in getRangeAt()
. But it's unclear if we can really |
| 424 // do the same, since we don't support discontiguous selection. Further disc
ussions at |
| 425 // <https://code.google.com/p/chromium/issues/detail?id=353069>. |
| 426 |
| 427 Range* start = originalRange->compareBoundaryPoints(Range::START_TO_START, n
ewRange, ASSERT_NO_EXCEPTION) < 0 ? originalRange.get() : newRange; |
| 428 Range* end = originalRange->compareBoundaryPoints(Range::END_TO_END, newRang
e, ASSERT_NO_EXCEPTION) < 0 ? newRange : originalRange.get(); |
| 429 RefPtr<Range> merged = Range::create(originalRange->startContainer()->docume
nt(), start->startContainer(), start->startOffset(), end->endContainer(), end->e
ndOffset()); |
| 430 EAffinity affinity = selection.selection().affinity(); |
| 431 selection.setSelectedRange(merged.get(), affinity); |
440 } | 432 } |
441 | 433 |
442 void DOMSelection::deleteFromDocument() | 434 void DOMSelection::deleteFromDocument() |
443 { | 435 { |
444 if (!m_frame) | 436 if (!m_frame) |
445 return; | 437 return; |
446 | 438 |
447 FrameSelection& selection = m_frame->selection(); | 439 FrameSelection& selection = m_frame->selection(); |
448 | 440 |
449 if (selection.isNone()) | 441 if (selection.isNone()) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 return node->document() == m_frame->document(); | 547 return node->document() == m_frame->document(); |
556 } | 548 } |
557 | 549 |
558 void DOMSelection::addConsoleError(const String& message) | 550 void DOMSelection::addConsoleError(const String& message) |
559 { | 551 { |
560 if (m_treeScope) | 552 if (m_treeScope) |
561 m_treeScope->document().addConsoleMessage(JSMessageSource, ErrorMessageL
evel, message); | 553 m_treeScope->document().addConsoleMessage(JSMessageSource, ErrorMessageL
evel, message); |
562 } | 554 } |
563 | 555 |
564 } // namespace WebCore | 556 } // namespace WebCore |
OLD | NEW |