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

Unified Diff: third_party/WebKit/Source/core/page/DragController.cpp

Issue 2374743002: [InputEvent] Support |deleteByDrag|, |insertFromDrop| and fire in sequential order (Closed)
Patch Set: Yosin's review Created 4 years, 3 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: 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 70e4290a77a1b481e6320b4fce4f54f1837486a4..eb031fb0b45edb0c66664b679842536119e134b2 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"
@@ -147,7 +148,7 @@ DragController* DragController::create(Page* page)
static DocumentFragment* documentFragmentFromDragData(DragData* dragData, LocalFrame* frame, Range* context, bool allowPlainText, bool& chosePlainText)
{
- ASSERT(dragData);
+ DCHECK(dragData);
chosePlainText = false;
Document& document = context->ownerDocument();
@@ -504,6 +505,11 @@ 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;
DocumentFragment* fragment = documentFragmentFromDragData(dragData, innerFrame, range, true, chosePlainText);
@@ -513,13 +519,23 @@ bool DragController::concludeEditDrag(DragData* dragData)
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 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled();
+ const bool smartInsert = smartDelete && innerFrame->selection().granularity() == WordGranularity && dragData->canSmartReplace();
+
+ if (!innerFrame->editor().deleteSelectionAfterDraggingWithEvents(innerFrame->editor().findEventTargetFromSelection(), smartDelete ? SmartDelete::Yes : SmartDelete::No, dragCaret.base()))
+ return false;
+
+ innerFrame->selection().setSelection(VisibleSelection(range->startPosition(), range->endPosition()));
+ if (innerFrame->selection().isAvailable()) {
+ DCHECK(m_documentUnderMouse);
+ if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents(element, dragData, fragment, range, smartInsert ? SmartInsert::Yes : SmartInsert::No, chosePlainText ? ChosePlainText::Yes : ChosePlainText::No))
+ 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() ? SmartInsert::Yes : SmartInsert::No, chosePlainText ? ChosePlainText::Yes : ChosePlainText::No))
+ return false;
}
}
} else {
@@ -528,10 +544,11 @@ 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);
+ const SmartInsert canSmartReplace = SmartInsert::No;
yosin_UTC9 2016/10/03 09:19:03 nit: Since we have enum class for smart insert and
chongz 2016/10/04 02:18:39 Done.
+ const ChosePlainText chosePlainText = ChosePlainText::Yes;
+ DCHECK(m_documentUnderMouse);
+ if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents(element, dragData, createFragmentFromText(EphemeralRange(range), text), range, canSmartReplace, chosePlainText))
+ return false;
}
}

Powered by Google App Engine
This is Rietveld 408576698