Index: third_party/WebKit/Source/core/page/DragController.cpp |
diff --git a/third_party/WebKit/Source/core/page/DragController.cpp b/third_party/WebKit/Source/core/page/DragController.cpp |
index c7938b4518e0a78294801d7a639abfd978e3bb52..acf38ded4e0d92dfb0ddc60e8392b83de9f3a265 100644 |
--- a/third_party/WebKit/Source/core/page/DragController.cpp |
+++ b/third_party/WebKit/Source/core/page/DragController.cpp |
@@ -42,6 +42,7 @@ |
#include "core/editing/EditingUtilities.h" |
#include "core/editing/Editor.h" |
#include "core/editing/FrameSelection.h" |
+#include "core/editing/commands/DragAndDropCommand.h" |
#include "core/editing/serializers/Serialization.h" |
#include "core/events/TextEvent.h" |
#include "core/fetch/ImageResource.h" |
@@ -143,13 +144,14 @@ DragController* DragController::create(Page* page) { |
return new DragController(page); |
} |
-static DocumentFragment* documentFragmentFromDragData(DragData* dragData, |
- LocalFrame* frame, |
- Range* context, |
- bool allowPlainText, |
- bool& chosePlainText) { |
- ASSERT(dragData); |
- chosePlainText = false; |
+static DocumentFragment* documentFragmentFromDragData( |
+ DragData* dragData, |
+ LocalFrame* frame, |
+ Range* context, |
+ bool allowPlainText, |
+ DragSourceType& dragSourceType) { |
+ DCHECK(dragData); |
+ dragSourceType = DragSourceType::HTMLSource; |
Document& document = context->ownerDocument(); |
if (dragData->containsCompatibleContent()) { |
@@ -178,7 +180,7 @@ static DocumentFragment* documentFragmentFromDragData(DragData* dragData, |
} |
} |
if (allowPlainText && dragData->containsPlainText()) { |
- chosePlainText = true; |
+ dragSourceType = DragSourceType::PlainTextSource; |
return createFragmentFromText(EphemeralRange(context), |
dragData->asPlainText()); |
} |
@@ -541,29 +543,55 @@ bool DragController::concludeEditDrag(DragData* dragData) { |
return false; |
ResourceFetcher* fetcher = range->ownerDocument().fetcher(); |
ResourceCacheValidationSuppressor validationSuppressor(fetcher); |
+ |
+ // Start new Drag&Drop command group, invalidate previous command group. |
+ // Assume no other places is firing |DeleteByDrag| and |InsertFromDrop|. |
+ innerFrame->editor().registerCommandGroup( |
+ DragAndDropCommand::create(*innerFrame->document())); |
+ |
if (dragIsMove(innerFrame->selection(), dragData) || |
dragCaret.isContentRichlyEditable()) { |
- bool chosePlainText = false; |
+ DragSourceType dragSourceType = DragSourceType::HTMLSource; |
DocumentFragment* fragment = documentFragmentFromDragData( |
- dragData, innerFrame, range, true, chosePlainText); |
+ dragData, innerFrame, range, true, dragSourceType); |
if (!fragment) |
return false; |
if (dragIsMove(innerFrame->selection(), dragData)) { |
// NSTextView behavior is to always smart delete on moving a selection, |
// but only to smart insert if the selection granularity is word granularity. |
- bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); |
- bool smartInsert = |
- smartDelete && |
- innerFrame->selection().granularity() == WordGranularity && |
- dragData->canSmartReplace(); |
- innerFrame->editor().moveSelectionAfterDragging( |
- fragment, dragCaret.base(), smartInsert, smartDelete); |
+ const DeleteMode deleteMode = |
+ innerFrame->editor().smartInsertDeleteEnabled() ? DeleteMode::Smart |
+ : DeleteMode::Simple; |
+ const InsertMode insertMode = |
+ (deleteMode == DeleteMode::Smart && |
+ innerFrame->selection().granularity() == WordGranularity && |
+ dragData->canSmartReplace()) |
+ ? InsertMode::Smart |
+ : InsertMode::Simple; |
+ |
+ if (!innerFrame->editor().deleteSelectionAfterDraggingWithEvents( |
+ innerFrame->editor().findEventTargetFromSelection(), deleteMode, |
+ dragCaret.base())) |
+ return false; |
+ |
+ innerFrame->selection().setSelection(createVisibleSelectionDeprecated( |
+ range->startPosition(), range->endPosition())); |
+ if (innerFrame->selection().isAvailable()) { |
+ DCHECK(m_documentUnderMouse); |
+ if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents( |
+ element, dragData, fragment, range, insertMode, dragSourceType)) |
+ return false; |
+ } |
} else { |
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { |
- ASSERT(m_documentUnderMouse); |
- m_documentUnderMouse->frame()->editor().replaceSelectionAfterDragging( |
- fragment, dragData->canSmartReplace(), chosePlainText); |
+ DCHECK(m_documentUnderMouse); |
+ if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents( |
+ element, dragData, fragment, range, |
+ dragData->canSmartReplace() ? InsertMode::Smart |
+ : InsertMode::Simple, |
+ dragSourceType)) |
+ return false; |
} |
} |
} else { |
@@ -572,12 +600,12 @@ bool DragController::concludeEditDrag(DragData* dragData) { |
return false; |
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { |
- const bool canSmartReplace = false; |
- const bool chosePlainText = true; |
- ASSERT(m_documentUnderMouse); |
- m_documentUnderMouse->frame()->editor().replaceSelectionAfterDragging( |
- createFragmentFromText(EphemeralRange(range), text), canSmartReplace, |
- chosePlainText); |
+ DCHECK(m_documentUnderMouse); |
+ if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents( |
+ element, dragData, |
+ createFragmentFromText(EphemeralRange(range), text), range, |
+ InsertMode::Simple, DragSourceType::PlainTextSource)) |
+ return false; |
} |
} |