Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Unified Diff: Source/core/editing/FrameSelection.cpp

Issue 1202153004: Enable selection for the composed tree (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename the flag Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/FrameSelection.cpp
diff --git a/Source/core/editing/FrameSelection.cpp b/Source/core/editing/FrameSelection.cpp
index 813dd92bc5924b1cdfc0870e7d0baf5613d1d24f..4b17e6e5d255fe130dcb28c11d7ea769412feffe 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::selectionForComposedTreeEnabled())
+ return setNonDirectionalSelectionIfNeededAlgorithm<VisibleSelection::InComposedTree>(passedNewSelection, granularity, endpointsAdjustmentMode);
setNonDirectionalSelectionIfNeededAlgorithm<VisibleSelection::InDOMTree>(passedNewSelection, granularity, endpointsAdjustmentMode);
}
+static bool areEquivalentSelections(const VisibleSelection& selection1, const VisibleSelection& selection2)
+{
+ if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
+ 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();
+ // TODO(hajimehoshi): validateSelection already checks if the selection
+ // is valid, 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) {
+ 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::selectionForComposedTreeEnabled())
+ 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::selectionForComposedTreeEnabled())
+ 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::selectionForComposedTreeEnabled())
+ return extractSelectedHTMLAlgorithm<VisibleSelection::InDOMTree>(*this);
+ return extractSelectedHTMLAlgorithm<VisibleSelection::InComposedTree>(*this);
}
String FrameSelection::selectedText() const
« no previous file with comments | « LayoutTests/editing/shadow/selection-shadow-mouse-drag-expected.html ('k') | Source/core/editing/SelectionController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698