Commit cc78b117 authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Hide editing commands from DragController

BUG=n/a
TEST=n/a; no behavior change

Review URL: https://codereview.chromium.org/1634603003

Cr-Commit-Position: refs/heads/master@{#371720}
parent 13ddcd3a
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "core/editing/commands/DeleteSelectionCommand.h" #include "core/editing/commands/DeleteSelectionCommand.h"
#include "core/editing/commands/IndentOutdentCommand.h" #include "core/editing/commands/IndentOutdentCommand.h"
#include "core/editing/commands/InsertListCommand.h" #include "core/editing/commands/InsertListCommand.h"
#include "core/editing/commands/MoveSelectionCommand.h"
#include "core/editing/commands/RemoveFormatCommand.h" #include "core/editing/commands/RemoveFormatCommand.h"
#include "core/editing/commands/ReplaceSelectionCommand.h" #include "core/editing/commands/ReplaceSelectionCommand.h"
#include "core/editing/commands/SimplifyMarkupCommand.h" #include "core/editing/commands/SimplifyMarkupCommand.h"
...@@ -524,6 +525,23 @@ void Editor::replaceSelectionWithText(const String& text, bool selectReplacement ...@@ -524,6 +525,23 @@ void Editor::replaceSelectionWithText(const String& text, bool selectReplacement
replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), selectReplacement, smartReplace, true); replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), selectReplacement, smartReplace, true);
} }
// TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|.
void Editor::replaceSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragment> fragment, bool smartReplace, bool plainText)
{
ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
if (smartReplace)
options |= ReplaceSelectionCommand::SmartReplace;
if (plainText)
options |= ReplaceSelectionCommand::MatchStyle;
ASSERT(frame().document());
ReplaceSelectionCommand::create(*frame().document(), fragment, options, EditActionDrag)->apply();
}
void Editor::moveSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragment> fragment, const Position& pos, bool smartInsert, bool smartDelete)
{
MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply();
}
EphemeralRange Editor::selectedRange() EphemeralRange Editor::selectedRange()
{ {
return frame().selection().selection().toNormalizedEphemeralRange(); return frame().selection().selection().toNormalizedEphemeralRange();
......
...@@ -222,6 +222,10 @@ public: ...@@ -222,6 +222,10 @@ public:
void replaceSelectionWithFragment(PassRefPtrWillBeRawPtr<DocumentFragment>, bool selectReplacement, bool smartReplace, bool matchStyle); void replaceSelectionWithFragment(PassRefPtrWillBeRawPtr<DocumentFragment>, bool selectReplacement, bool smartReplace, bool matchStyle);
void replaceSelectionWithText(const String&, bool selectReplacement, bool smartReplace); void replaceSelectionWithText(const String&, bool selectReplacement, bool smartReplace);
// TODO(xiaochengh): Replace |bool| parameters by |enum|.
void replaceSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragment>, bool smartReplace, bool plainText);
void moveSelectionAfterDragging(PassRefPtrWillBeRawPtr<DocumentFragment>, const Position&, bool smartInsert, bool smartDelete);
EditorParagraphSeparator defaultParagraphSeparator() const { return m_defaultParagraphSeparator; } EditorParagraphSeparator defaultParagraphSeparator() const { return m_defaultParagraphSeparator; }
void setDefaultParagraphSeparator(EditorParagraphSeparator separator) { m_defaultParagraphSeparator = separator; } void setDefaultParagraphSeparator(EditorParagraphSeparator separator) { m_defaultParagraphSeparator = separator; }
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
#include "core/editing/EditingUtilities.h" #include "core/editing/EditingUtilities.h"
#include "core/editing/Editor.h" #include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h" #include "core/editing/FrameSelection.h"
#include "core/editing/commands/MoveSelectionCommand.h"
#include "core/editing/commands/ReplaceSelectionCommand.h"
#include "core/editing/serializers/Serialization.h" #include "core/editing/serializers/Serialization.h"
#include "core/events/TextEvent.h" #include "core/events/TextEvent.h"
#include "core/fetch/ImageResource.h" #include "core/fetch/ImageResource.h"
...@@ -503,16 +501,11 @@ bool DragController::concludeEditDrag(DragData* dragData) ...@@ -503,16 +501,11 @@ bool DragController::concludeEditDrag(DragData* dragData)
// but only to smart insert if the selection granularity is word granularity. // but only to smart insert if the selection granularity is word granularity.
bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled();
bool smartInsert = smartDelete && innerFrame->selection().granularity() == WordGranularity && dragData->canSmartReplace(); bool smartInsert = smartDelete && innerFrame->selection().granularity() == WordGranularity && dragData->canSmartReplace();
MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete)->apply(); innerFrame->editor().moveSelectionAfterDragging(fragment, dragCaret.base(), smartInsert, smartDelete);
} else { } else {
if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) {
ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
if (dragData->canSmartReplace())
options |= ReplaceSelectionCommand::SmartReplace;
if (chosePlainText)
options |= ReplaceSelectionCommand::MatchStyle;
ASSERT(m_documentUnderMouse); ASSERT(m_documentUnderMouse);
ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), fragment, options, EditActionDrag)->apply(); m_documentUnderMouse->frame()->editor().replaceSelectionAfterDragging(fragment, dragData->canSmartReplace(), chosePlainText);
} }
} }
} else { } else {
...@@ -521,8 +514,10 @@ bool DragController::concludeEditDrag(DragData* dragData) ...@@ -521,8 +514,10 @@ bool DragController::concludeEditDrag(DragData* dragData)
return false; return false;
if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) {
const bool canSmartReplace = false;
const bool chosePlainText = true;
ASSERT(m_documentUnderMouse); ASSERT(m_documentUnderMouse);
ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createFragmentFromText(EphemeralRange(range.get()), text), ReplaceSelectionCommand::SelectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand::PreventNesting, EditActionDrag)->apply(); m_documentUnderMouse->frame()->editor().replaceSelectionAfterDragging(createFragmentFromText(EphemeralRange(range.get()), text), canSmartReplace, chosePlainText);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment