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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Google Inc. 3 * Copyright (C) 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 24 matching lines...) Expand all
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/DocumentFragment.h" 36 #include "core/dom/DocumentFragment.h"
37 #include "core/dom/Element.h" 37 #include "core/dom/Element.h"
38 #include "core/dom/Node.h" 38 #include "core/dom/Node.h"
39 #include "core/dom/Text.h" 39 #include "core/dom/Text.h"
40 #include "core/dom/shadow/ShadowRoot.h" 40 #include "core/dom/shadow/ShadowRoot.h"
41 #include "core/editing/DragCaretController.h" 41 #include "core/editing/DragCaretController.h"
42 #include "core/editing/EditingUtilities.h" 42 #include "core/editing/EditingUtilities.h"
43 #include "core/editing/Editor.h" 43 #include "core/editing/Editor.h"
44 #include "core/editing/FrameSelection.h" 44 #include "core/editing/FrameSelection.h"
45 #include "core/editing/commands/DragAndDropCommand.h"
45 #include "core/editing/serializers/Serialization.h" 46 #include "core/editing/serializers/Serialization.h"
46 #include "core/events/TextEvent.h" 47 #include "core/events/TextEvent.h"
47 #include "core/fetch/ImageResource.h" 48 #include "core/fetch/ImageResource.h"
48 #include "core/fetch/ResourceFetcher.h" 49 #include "core/fetch/ResourceFetcher.h"
49 #include "core/frame/FrameHost.h" 50 #include "core/frame/FrameHost.h"
50 #include "core/frame/FrameView.h" 51 #include "core/frame/FrameView.h"
51 #include "core/frame/LocalFrame.h" 52 #include "core/frame/LocalFrame.h"
52 #include "core/frame/Settings.h" 53 #include "core/frame/Settings.h"
53 #include "core/html/HTMLAnchorElement.h" 54 #include "core/html/HTMLAnchorElement.h"
54 #include "core/html/HTMLFormElement.h" 55 #include "core/html/HTMLFormElement.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 141 {
141 } 142 }
142 143
143 DragController* DragController::create(Page* page) 144 DragController* DragController::create(Page* page)
144 { 145 {
145 return new DragController(page); 146 return new DragController(page);
146 } 147 }
147 148
148 static DocumentFragment* documentFragmentFromDragData(DragData* dragData, LocalF rame* frame, Range* context, bool allowPlainText, bool& chosePlainText) 149 static DocumentFragment* documentFragmentFromDragData(DragData* dragData, LocalF rame* frame, Range* context, bool allowPlainText, bool& chosePlainText)
149 { 150 {
150 ASSERT(dragData); 151 DCHECK(dragData);
151 chosePlainText = false; 152 chosePlainText = false;
152 153
153 Document& document = context->ownerDocument(); 154 Document& document = context->ownerDocument();
154 if (dragData->containsCompatibleContent()) { 155 if (dragData->containsCompatibleContent()) {
155 if (DocumentFragment* fragment = dragData->asFragment(frame)) 156 if (DocumentFragment* fragment = dragData->asFragment(frame))
156 return fragment; 157 return fragment;
157 158
158 if (dragData->containsURL(DragData::DoNotConvertFilenames)) { 159 if (dragData->containsURL(DragData::DoNotConvertFilenames)) {
159 String title; 160 String title;
160 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title ); 161 String url = dragData->asURL(DragData::DoNotConvertFilenames, &title );
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 498 }
498 Range* range = createRange(dragCaret.toNormalizedEphemeralRange()); 499 Range* range = createRange(dragCaret.toNormalizedEphemeralRange());
499 Element* rootEditableElement = innerFrame->selection().rootEditableElement() ; 500 Element* rootEditableElement = innerFrame->selection().rootEditableElement() ;
500 501
501 // For range to be null a WebKit client must have done something bad while 502 // For range to be null a WebKit client must have done something bad while
502 // manually controlling drag behaviour 503 // manually controlling drag behaviour
503 if (!range) 504 if (!range)
504 return false; 505 return false;
505 ResourceFetcher* fetcher = range->ownerDocument().fetcher(); 506 ResourceFetcher* fetcher = range->ownerDocument().fetcher();
506 ResourceCacheValidationSuppressor validationSuppressor(fetcher); 507 ResourceCacheValidationSuppressor validationSuppressor(fetcher);
508
509 // Start new Drag&Drop command group, invalidate previous command group.
510 // Assume no other places is firing |DeleteByDrag| and |InsertFromDrop|.
511 innerFrame->editor().registerCommandGroup(DragAndDropCommand::create(*innerF rame->document()));
512
507 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) { 513 if (dragIsMove(innerFrame->selection(), dragData) || dragCaret.isContentRich lyEditable()) {
508 bool chosePlainText = false; 514 bool chosePlainText = false;
509 DocumentFragment* fragment = documentFragmentFromDragData(dragData, inne rFrame, range, true, chosePlainText); 515 DocumentFragment* fragment = documentFragmentFromDragData(dragData, inne rFrame, range, true, chosePlainText);
510 if (!fragment) 516 if (!fragment)
511 return false; 517 return false;
512 518
513 if (dragIsMove(innerFrame->selection(), dragData)) { 519 if (dragIsMove(innerFrame->selection(), dragData)) {
514 // NSTextView behavior is to always smart delete on moving a selecti on, 520 // NSTextView behavior is to always smart delete on moving a selecti on,
515 // but only to smart insert if the selection granularity is word gra nularity. 521 // but only to smart insert if the selection granularity is word gra nularity.
516 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); 522 const bool smartDelete = innerFrame->editor().smartInsertDeleteEnabl ed();
517 bool smartInsert = smartDelete && innerFrame->selection().granularit y() == WordGranularity && dragData->canSmartReplace(); 523 const bool smartInsert = smartDelete && innerFrame->selection().gran ularity() == WordGranularity && dragData->canSmartReplace();
518 innerFrame->editor().moveSelectionAfterDragging(fragment, dragCaret. base(), smartInsert, smartDelete); 524
525 if (!innerFrame->editor().deleteSelectionAfterDraggingWithEvents(inn erFrame->editor().findEventTargetFromSelection(), smartDelete ? SmartDelete::Yes : SmartDelete::No, dragCaret.base()))
526 return false;
527
528 innerFrame->selection().setSelection(VisibleSelection(range->startPo sition(), range->endPosition()));
529 if (innerFrame->selection().isAvailable()) {
530 DCHECK(m_documentUnderMouse);
531 if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvent s(element, dragData, fragment, range, smartInsert ? SmartInsert::Yes : SmartInse rt::No, chosePlainText ? ChosePlainText::Yes : ChosePlainText::No))
532 return false;
533 }
519 } else { 534 } else {
520 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { 535 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) {
521 ASSERT(m_documentUnderMouse); 536 DCHECK(m_documentUnderMouse);
522 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDra gging(fragment, dragData->canSmartReplace(), chosePlainText); 537 if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvent s(element, dragData, fragment, range, dragData->canSmartReplace() ? SmartInsert: :Yes : SmartInsert::No, chosePlainText ? ChosePlainText::Yes : ChosePlainText::N o))
538 return false;
523 } 539 }
524 } 540 }
525 } else { 541 } else {
526 String text = dragData->asPlainText(); 542 String text = dragData->asPlainText();
527 if (text.isEmpty()) 543 if (text.isEmpty())
528 return false; 544 return false;
529 545
530 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) { 546 if (setSelectionToDragCaret(innerFrame, dragCaret, range, point)) {
531 const bool canSmartReplace = false; 547 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.
532 const bool chosePlainText = true; 548 const ChosePlainText chosePlainText = ChosePlainText::Yes;
533 ASSERT(m_documentUnderMouse); 549 DCHECK(m_documentUnderMouse);
534 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDraggin g(createFragmentFromText(EphemeralRange(range), text), canSmartReplace, chosePla inText); 550 if (!innerFrame->editor().replaceSelectionAfterDraggingWithEvents(el ement, dragData, createFragmentFromText(EphemeralRange(range), text), range, can SmartReplace, chosePlainText))
551 return false;
535 } 552 }
536 } 553 }
537 554
538 if (rootEditableElement) { 555 if (rootEditableElement) {
539 if (LocalFrame* frame = rootEditableElement->document().frame()) 556 if (LocalFrame* frame = rootEditableElement->document().frame())
540 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement); 557 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement);
541 } 558 }
542 559
543 return true; 560 return true;
544 } 561 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 1014
998 DEFINE_TRACE(DragController) 1015 DEFINE_TRACE(DragController)
999 { 1016 {
1000 visitor->trace(m_page); 1017 visitor->trace(m_page);
1001 visitor->trace(m_documentUnderMouse); 1018 visitor->trace(m_documentUnderMouse);
1002 visitor->trace(m_dragInitiator); 1019 visitor->trace(m_dragInitiator);
1003 visitor->trace(m_fileInputElementUnderMouse); 1020 visitor->trace(m_fileInputElementUnderMouse);
1004 } 1021 }
1005 1022
1006 } // namespace blink 1023 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698