Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/SelectionEditor.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp |
| index 8206ecf15d3debae364272601af153a1bff8911d..d771967c0f4897c557818540be5aa8c114abf735 100644 |
| --- a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp |
| +++ b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp |
| @@ -25,6 +25,7 @@ |
| #include "core/editing/SelectionEditor.h" |
| +#include "core/editing/DOMSelection.h" |
| #include "core/editing/EditingUtilities.h" |
| #include "core/editing/Editor.h" |
| #include "core/editing/SelectionAdjuster.h" |
| @@ -80,11 +81,35 @@ SelectionEditor::visibleSelection<EditingInFlatTreeStrategy>() const { |
| return m_selectionInFlatTree; |
| } |
| +static void markRangeDirty(const TreeScope* treeScope) { |
| + for (const TreeScope* runner = treeScope; runner; |
| + runner = runner->parentTreeScope()) { |
| + if (runner->hasSelection()) |
| + runner->getSelection()->markRangeDirty(); |
| + } |
| +} |
| + |
| +static void markDOMSelectionDirty(const VisibleSelection& selection) { |
| + if (selection.isNone()) |
| + return; |
| + |
| + const TreeScope& startScope = selection.start().anchorNode()->treeScope(); |
| + markRangeDirty(&startScope); |
|
yosin_UTC9
2017/02/08 06:20:26
We should reset all ranges in whole tree-of-tree n
|
| + if (selection.isCaret()) |
| + return; |
| + |
| + const TreeScope& endScope = selection.end().anchorNode()->treeScope(); |
| + if (startScope != endScope) |
| + markRangeDirty(&endScope); |
| +} |
| + |
| void SelectionEditor::setVisibleSelection( |
| const VisibleSelection& newSelection, |
| FrameSelection::SetSelectionOptions options) { |
| DCHECK(newSelection.isValidFor(document())) << newSelection; |
| resetLogicalRange(); |
| + markDOMSelectionDirty(m_selection); |
| + |
| m_selection = newSelection; |
| if (options & FrameSelection::DoNotAdjustInFlatTree) { |
| m_selectionInFlatTree.setWithoutValidation( |
| @@ -95,6 +120,8 @@ void SelectionEditor::setVisibleSelection( |
| SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, |
| m_selection); |
| + |
| + markDOMSelectionDirty(m_selection); |
| } |
| void SelectionEditor::setVisibleSelection( |
| @@ -103,9 +130,13 @@ void SelectionEditor::setVisibleSelection( |
| DCHECK(newSelection.isValidFor(document())) << newSelection; |
| DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
| resetLogicalRange(); |
| + markDOMSelectionDirty(m_selection); |
| + |
| m_selectionInFlatTree = newSelection; |
| SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
| m_selectionInFlatTree); |
| + |
| + markDOMSelectionDirty(m_selection); |
|
yosin_UTC9
2017/02/08 06:20:26
Why do we need to call markDOMSelectionDirty() twi
|
| } |
| void SelectionEditor::setWithoutValidation(const Position& base, |
| @@ -115,9 +146,12 @@ void SelectionEditor::setWithoutValidation(const Position& base, |
| DCHECK_EQ(base.document(), document()); |
| if (extent.isNotNull()) |
| DCHECK_EQ(extent.document(), document()); |
| + markDOMSelectionDirty(m_selection); |
| + |
| m_selection.setWithoutValidation(base, extent); |
| m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
| toPositionInFlatTree(extent)); |
| + markDOMSelectionDirty(m_selection); |
| } |
| void SelectionEditor::documentAttached(Document* document) { |