| 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 0dc76f0fef3b9f52cab367db903ee52d1a675f81..54f028814e5dc4e06f815a4b136d0fe1932d3736 100644
|
| --- a/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
|
| +++ b/third_party/WebKit/Source/core/editing/SelectionEditor.cpp
|
| @@ -36,15 +36,33 @@ SelectionEditor::SelectionEditor(FrameSelection& frameSelection)
|
| : m_frameSelection(frameSelection)
|
| , m_observingVisibleSelection(false)
|
| {
|
| + clearVisibleSelection();
|
| }
|
|
|
| SelectionEditor::~SelectionEditor()
|
| {
|
| }
|
|
|
| +void SelectionEditor::clearVisibleSelection()
|
| +{
|
| + m_selection = VisibleSelection();
|
| + m_selectionInFlatTree = VisibleSelectionInFlatTree();
|
| + if (!shouldAlwaysUseDirectionalSelection())
|
| + return;
|
| + m_selection.setIsDirectional(true);
|
| + m_selectionInFlatTree.setIsDirectional(true);
|
| +}
|
| +
|
| void SelectionEditor::dispose()
|
| {
|
| resetLogicalRange();
|
| + clearVisibleSelection();
|
| +}
|
| +
|
| +const Document& SelectionEditor::document() const
|
| +{
|
| + DCHECK(m_document);
|
| + return *m_document;
|
| }
|
|
|
| LocalFrame* SelectionEditor::frame() const
|
| @@ -55,17 +73,28 @@ LocalFrame* SelectionEditor::frame() const
|
| template <>
|
| const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() const
|
| {
|
| + DCHECK_EQ(frame()->document(), document());
|
| + DCHECK_EQ(frame(), document().frame());
|
| + if (m_selection.isNone())
|
| + return m_selection;
|
| + DCHECK_EQ(m_selection.base().document(), document());
|
| return m_selection;
|
| }
|
|
|
| template <>
|
| const VisibleSelectionInFlatTree& SelectionEditor::visibleSelection<EditingInFlatTreeStrategy>() const
|
| {
|
| + DCHECK_EQ(frame()->document(), document());
|
| + DCHECK_EQ(frame(), document().frame());
|
| + if (m_selectionInFlatTree.isNone())
|
| + return m_selectionInFlatTree;
|
| + DCHECK_EQ(m_selectionInFlatTree.base().document(), document());
|
| return m_selectionInFlatTree;
|
| }
|
|
|
| void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection, FrameSelection::SetSelectionOptions options)
|
| {
|
| + DCHECK(newSelection.isValidFor(document())) << newSelection;
|
| resetLogicalRange();
|
| m_selection = newSelection;
|
| if (options & FrameSelection::DoNotAdjustInFlatTree) {
|
| @@ -78,25 +107,38 @@ void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection,
|
|
|
| void SelectionEditor::setVisibleSelection(const VisibleSelectionInFlatTree& newSelection, FrameSelection::SetSelectionOptions options)
|
| {
|
| + DCHECK(newSelection.isValidFor(document())) << newSelection;
|
| DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree));
|
| resetLogicalRange();
|
| m_selectionInFlatTree = newSelection;
|
| SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInFlatTree);
|
| }
|
|
|
| -void SelectionEditor::setIsDirectional(bool isDirectional)
|
| -{
|
| - m_selection.setIsDirectional(isDirectional);
|
| - m_selectionInFlatTree.setIsDirectional(isDirectional);
|
| -}
|
| -
|
| void SelectionEditor::setWithoutValidation(const Position& base, const Position& extent)
|
| {
|
| resetLogicalRange();
|
| + if (base.isNotNull())
|
| + DCHECK_EQ(base.document(), document());
|
| + if (extent.isNotNull())
|
| + DCHECK_EQ(extent.document(), document());
|
| m_selection.setWithoutValidation(base, extent);
|
| m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), toPositionInFlatTree(extent));
|
| }
|
|
|
| +void SelectionEditor::documentAttached(Document* document)
|
| +{
|
| + DCHECK(document);
|
| + DCHECK(!m_document) << m_document;
|
| + m_document = document;
|
| +}
|
| +
|
| +void SelectionEditor::documentDetached(const Document& document)
|
| +{
|
| + DCHECK_EQ(m_document, &document);
|
| + dispose();
|
| + m_document = nullptr;
|
| +}
|
| +
|
| void SelectionEditor::resetLogicalRange()
|
| {
|
| // Non-collapsed ranges are not allowed to start at the end of a line that
|
| @@ -109,6 +151,7 @@ void SelectionEditor::resetLogicalRange()
|
|
|
| void SelectionEditor::setLogicalRange(Range* range)
|
| {
|
| + DCHECK_EQ(range->ownerDocument(), document());
|
| DCHECK(!m_logicalRange) << "A logical range should be one.";
|
| m_logicalRange = range;
|
| }
|
| @@ -120,14 +163,22 @@ Range* SelectionEditor::firstRange() const
|
| return firstRangeOf(m_selection);
|
| }
|
|
|
| +bool SelectionEditor::shouldAlwaysUseDirectionalSelection() const
|
| +{
|
| + return frame()->editor().behavior().shouldConsiderSelectionAsDirectional();
|
| +}
|
| +
|
| void SelectionEditor::updateIfNeeded()
|
| {
|
| + DCHECK(m_selection.isValidFor(document())) << m_selection;
|
| + DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection;
|
| m_selection.updateIfNeeded();
|
| m_selectionInFlatTree.updateIfNeeded();
|
| }
|
|
|
| DEFINE_TRACE(SelectionEditor)
|
| {
|
| + visitor->trace(m_document);
|
| visitor->trace(m_frameSelection);
|
| visitor->trace(m_selection);
|
| visitor->trace(m_selectionInFlatTree);
|
|
|