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

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 2 Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/events/InputEvent.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « third_party/WebKit/Source/core/events/InputEvent.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698