Chromium Code Reviews| 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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 return; | 593 return; |
| 594 } | 594 } |
| 595 | 595 |
| 596 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 596 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 597 // needs to be audited. See http://crbug.com/590369 for more details. | 597 // needs to be audited. See http://crbug.com/590369 for more details. |
| 598 // In the long term, we should change FrameSelection::setSelection to take a | 598 // In the long term, we should change FrameSelection::setSelection to take a |
| 599 // parameter that does not require clean layout, so that modifying selection | 599 // parameter that does not require clean layout, so that modifying selection |
| 600 // no longer performs synchronous layout by itself. | 600 // no longer performs synchronous layout by itself. |
| 601 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 601 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 602 | 602 |
| 603 if (selection.isNone()) { | 603 if (rangeCount() == 0) { |
| 604 selection.setSelectedRange(EphemeralRange(newRange), VP_DEFAULT_AFFINITY); | 604 selection.setSelectedRange(EphemeralRange(newRange), VP_DEFAULT_AFFINITY); |
| 605 cacheRangeIfSelectionOfDocument(newRange); | 605 cacheRangeIfSelectionOfDocument(newRange); |
| 606 return; | 606 return; |
| 607 } | 607 } |
| 608 | 608 |
| 609 Range* originalRange = selection.firstRange(); | 609 Range* originalRange = selection.firstRange(); |
| 610 | 610 |
| 611 if (originalRange->startContainer()->document() != | |
| 612 newRange->startContainer()->document()) { | |
| 613 addConsoleError( | |
| 614 "The given range does not belong to the current selection's document."); | |
| 615 return; | |
| 616 } | |
| 617 if (originalRange->startContainer()->treeScope() != | 611 if (originalRange->startContainer()->treeScope() != |
| 618 newRange->startContainer()->treeScope()) { | 612 newRange->startContainer()->treeScope()) { |
|
yoichio
2017/02/20 07:42:19
Why do you leave these two early returns though yo
tkent
2017/02/20 07:53:25
The removed one was dead code. We check Document i
| |
| 619 addConsoleError( | |
| 620 "The given range and the current selection belong to two different " | |
| 621 "document fragments."); | |
| 622 return; | 613 return; |
| 623 } | 614 } |
| 624 | 615 |
| 625 if (originalRange->compareBoundaryPoints(Range::kStartToEnd, newRange, | 616 if (originalRange->compareBoundaryPoints(Range::kStartToEnd, newRange, |
| 626 ASSERT_NO_EXCEPTION) < 0 || | 617 ASSERT_NO_EXCEPTION) < 0 || |
| 627 newRange->compareBoundaryPoints(Range::kStartToEnd, originalRange, | 618 newRange->compareBoundaryPoints(Range::kStartToEnd, originalRange, |
| 628 ASSERT_NO_EXCEPTION) < 0) { | 619 ASSERT_NO_EXCEPTION) < 0) { |
| 629 addConsoleError("Discontiguous selection is not supported."); | |
| 630 return; | 620 return; |
| 631 } | 621 } |
| 632 | 622 |
| 633 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; | 623 // TODO(tkent): "Merge the ranges if they intersect" was removed. We show a |
| 634 // other browsers supporting discontiguous selection (obviously) keep each | 624 // warning message for a while, and continue to collect the usage data. |
| 635 // Range added and return it in getRangeAt(). But it's unclear if we can | |
| 636 // really do the same, since we don't support discontiguous selection. Further | |
| 637 // discussions at | |
| 638 // <https://code.google.com/p/chromium/issues/detail?id=353069>. | 625 // <https://code.google.com/p/chromium/issues/detail?id=353069>. |
| 639 Deprecation::countDeprecation(frame(), | 626 Deprecation::countDeprecation(frame(), |
| 640 UseCounter::SelectionAddRangeIntersect); | 627 UseCounter::SelectionAddRangeIntersect); |
| 641 | |
| 642 Range* start = originalRange->compareBoundaryPoints( | |
| 643 Range::kStartToStart, newRange, ASSERT_NO_EXCEPTION) < 0 | |
| 644 ? originalRange | |
| 645 : newRange; | |
| 646 Range* end = originalRange->compareBoundaryPoints(Range::kEndToEnd, newRange, | |
| 647 ASSERT_NO_EXCEPTION) < 0 | |
| 648 ? newRange | |
| 649 : originalRange; | |
| 650 const EphemeralRange merged = | |
| 651 EphemeralRange(start->startPosition(), end->endPosition()); | |
| 652 TextAffinity affinity = selection.selection().affinity(); | |
| 653 selection.setSelectedRange(merged, affinity); | |
| 654 cacheRangeIfSelectionOfDocument(createRange(merged)); | |
| 655 } | 628 } |
| 656 | 629 |
| 657 void DOMSelection::deleteFromDocument() { | 630 void DOMSelection::deleteFromDocument() { |
| 658 if (!isAvailable()) | 631 if (!isAvailable()) |
| 659 return; | 632 return; |
| 660 | 633 |
| 661 FrameSelection& selection = frame()->selection(); | 634 FrameSelection& selection = frame()->selection(); |
| 662 | 635 |
| 663 if (selection.isNone()) | 636 if (selection.isNone()) |
| 664 return; | 637 return; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 m_treeScope->document().addConsoleMessage( | 784 m_treeScope->document().addConsoleMessage( |
| 812 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 785 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 813 } | 786 } |
| 814 | 787 |
| 815 DEFINE_TRACE(DOMSelection) { | 788 DEFINE_TRACE(DOMSelection) { |
| 816 visitor->trace(m_treeScope); | 789 visitor->trace(m_treeScope); |
| 817 ContextClient::trace(visitor); | 790 ContextClient::trace(visitor); |
| 818 } | 791 } |
| 819 | 792 |
| 820 } // namespace blink | 793 } // namespace blink |
| OLD | NEW |