Chromium Code Reviews| Index: Source/core/editing/FrameSelection.cpp |
| diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp |
| index 813dd92bc5924b1cdfc0870e7d0baf5613d1d24f..a9baa13b1dcf723ed7065178997780c7f27798b7 100644 |
| --- a/Source/core/editing/FrameSelection.cpp |
| +++ b/Source/core/editing/FrameSelection.cpp |
| @@ -224,9 +224,18 @@ void FrameSelection::setNonDirectionalSelectionIfNeededAlgorithm(const VisibleSe |
| void FrameSelection::setNonDirectionalSelectionIfNeeded(const VisibleSelection& passedNewSelection, TextGranularity granularity, EndPointsAdjustmentMode endpointsAdjustmentMode) |
| { |
| + if (RuntimeEnabledFeatures::selectionForWebComponentsEnabled()) |
| + return setNonDirectionalSelectionIfNeededAlgorithm<VisibleSelection::InComposedTree>(passedNewSelection, granularity, endpointsAdjustmentMode); |
| setNonDirectionalSelectionIfNeededAlgorithm<VisibleSelection::InDOMTree>(passedNewSelection, granularity, endpointsAdjustmentMode); |
| } |
| +static bool areEquivalentSelections(const VisibleSelection& selection1, const VisibleSelection& selection2) |
| +{ |
| + if (RuntimeEnabledFeatures::selectionForWebComponentsEnabled()) |
| + return VisibleSelection::InComposedTree::equalSelections(selection1, selection2); |
| + return VisibleSelection::InDOMTree::equalSelections(selection1, selection2); |
| +} |
| + |
| void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelectionOptions options, CursorAlignOnScroll align, TextGranularity granularity) |
| { |
| if (m_granularityStrategy && (options & FrameSelection::DoNotClearStrategy) == 0) |
| @@ -248,6 +257,8 @@ void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec |
| // if document->frame() == m_frame we can get into an infinite loop |
| if (s.base().anchorNode()) { |
| Document& document = *s.base().document(); |
| + // FIXME: validateSelection already checks if the selection is valid, |
|
tkent
2015/06/24 00:07:41
FIXME: -> TODO(name):
hajimehoshi
2015/06/24 04:21:07
Done.
|
| + // thus we don't need this 'if' clause any more. |
| if (document.frame() && document.frame() != m_frame && document != m_frame->document()) { |
| RefPtrWillBeRawPtr<LocalFrame> guard(document.frame()); |
| document.frame()->selection().setSelection(s, options, align, granularity); |
| @@ -268,7 +279,7 @@ void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec |
| if (shouldClearTypingStyle) |
| clearTypingStyle(); |
| - if (m_selection == s) { |
|
tkent
2015/06/24 00:07:41
Are there other instances of VisibleSelection::ope
hajimehoshi
2015/06/24 04:21:07
Yes (e.g. core/editing/CompositeEditCommand.cpp:25
|
| + if (areEquivalentSelections(m_selection, s)) { |
| // Even if selection was not changed, selection offsets may have been changed. |
| m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid(); |
| notifyLayoutObjectOfSelectionChange(userTriggered); |
| @@ -294,6 +305,13 @@ void FrameSelection::setSelection(const VisibleSelection& newSelection, SetSelec |
| m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); |
| selectFrameElementInParentIfFullySelected(); |
| notifyLayoutObjectOfSelectionChange(userTriggered); |
| + // If the selections are same in the DOM tree but not in the composed tree, |
| + // don't fire events. For example, if the selection crosses shadow tree |
| + // boundary, selection for the DOM tree is shrunk while that for the |
| + // composed tree is not. Additionally, this case occurs in some edge cases. |
| + // See also: editing/pasteboard/4076267-3.html |
| + if (VisibleSelection::InDOMTree::equalSelections(oldSelection, m_selection)) |
| + return; |
| m_frame->editor().respondToChangedSelection(oldSelection, options); |
| if (userTriggered == UserTriggered) { |
| ScrollAlignment alignment; |
| @@ -1336,6 +1354,8 @@ bool FrameSelection::containsAlgorithm(const LayoutPoint& point) |
| bool FrameSelection::contains(const LayoutPoint& point) |
| { |
| + if (RuntimeEnabledFeatures::selectionForWebComponentsEnabled()) |
| + return containsAlgorithm<VisibleSelection::InComposedTree>(point); |
| return containsAlgorithm<VisibleSelection::InDOMTree>(point); |
| } |
| @@ -1693,6 +1713,8 @@ String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato |
| static String extractSelectedText(const FrameSelection& selection, TextIteratorBehavior behavior) |
| { |
| + if (RuntimeEnabledFeatures::selectionForWebComponentsEnabled()) |
| + return extractSelectedTextAlgorithm<VisibleSelection::InComposedTree>(selection, behavior); |
| return extractSelectedTextAlgorithm<VisibleSelection::InDOMTree>(selection, behavior); |
| } |
| @@ -1709,7 +1731,9 @@ static String extractSelectedHTMLAlgorithm(const FrameSelection& selection) |
| String FrameSelection::selectedHTMLForClipboard() const |
| { |
| - return extractSelectedHTMLAlgorithm<VisibleSelection::InDOMTree>(*this); |
| + if (!RuntimeEnabledFeatures::selectionForWebComponentsEnabled()) |
| + return extractSelectedHTMLAlgorithm<VisibleSelection::InDOMTree>(*this); |
| + return extractSelectedHTMLAlgorithm<VisibleSelection::InComposedTree>(*this); |
| } |
| String FrameSelection::selectedText() const |