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

Side by Side Diff: third_party/WebKit/Source/core/page/DragController.cpp

Issue 1634603003: Hide editing commands from DragController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/MoveSelectionCommand.h"
46 #include "core/editing/commands/ReplaceSelectionCommand.h"
47 #include "core/editing/serializers/Serialization.h" 45 #include "core/editing/serializers/Serialization.h"
48 #include "core/events/TextEvent.h" 46 #include "core/events/TextEvent.h"
49 #include "core/fetch/ImageResource.h" 47 #include "core/fetch/ImageResource.h"
50 #include "core/fetch/ResourceFetcher.h" 48 #include "core/fetch/ResourceFetcher.h"
51 #include "core/frame/FrameView.h" 49 #include "core/frame/FrameView.h"
52 #include "core/frame/LocalFrame.h" 50 #include "core/frame/LocalFrame.h"
53 #include "core/frame/Settings.h" 51 #include "core/frame/Settings.h"
54 #include "core/html/HTMLAnchorElement.h" 52 #include "core/html/HTMLAnchorElement.h"
55 #include "core/html/HTMLFormElement.h" 53 #include "core/html/HTMLFormElement.h"
56 #include "core/html/HTMLInputElement.h" 54 #include "core/html/HTMLInputElement.h"
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 bool chosePlainText = false; 494 bool chosePlainText = false;
497 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag Data(dragData, innerFrame.get(), range, true, chosePlainText); 495 RefPtrWillBeRawPtr<DocumentFragment> fragment = documentFragmentFromDrag Data(dragData, innerFrame.get(), range, true, chosePlainText);
498 if (!fragment) 496 if (!fragment)
499 return false; 497 return false;
500 498
501 if (dragIsMove(innerFrame->selection(), dragData)) { 499 if (dragIsMove(innerFrame->selection(), dragData)) {
502 // NSTextView behavior is to always smart delete on moving a selecti on, 500 // NSTextView behavior is to always smart delete on moving a selecti on,
503 // but only to smart insert if the selection granularity is word gra nularity. 501 // but only to smart insert if the selection granularity is word gra nularity.
504 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled(); 502 bool smartDelete = innerFrame->editor().smartInsertDeleteEnabled();
505 bool smartInsert = smartDelete && innerFrame->selection().granularit y() == WordGranularity && dragData->canSmartReplace(); 503 bool smartInsert = smartDelete && innerFrame->selection().granularit y() == WordGranularity && dragData->canSmartReplace();
506 MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert , smartDelete)->apply(); 504 innerFrame->editor().moveSelectionAfterDragging(fragment, dragCaret. base(), smartInsert, smartDelete);
507 } else { 505 } else {
508 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, poin t)) { 506 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, poin t)) {
509 ReplaceSelectionCommand::CommandOptions options = ReplaceSelecti onCommand::SelectReplacement | ReplaceSelectionCommand::PreventNesting;
510 if (dragData->canSmartReplace())
511 options |= ReplaceSelectionCommand::SmartReplace;
512 if (chosePlainText)
513 options |= ReplaceSelectionCommand::MatchStyle;
514 ASSERT(m_documentUnderMouse); 507 ASSERT(m_documentUnderMouse);
515 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), fra gment, options, EditActionDrag)->apply(); 508 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDra gging(fragment, dragData->canSmartReplace(), chosePlainText);
516 } 509 }
517 } 510 }
518 } else { 511 } else {
519 String text = dragData->asPlainText(); 512 String text = dragData->asPlainText();
520 if (text.isEmpty()) 513 if (text.isEmpty())
521 return false; 514 return false;
522 515
523 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) { 516 if (setSelectionToDragCaret(innerFrame.get(), dragCaret, range, point)) {
524 ASSERT(m_documentUnderMouse); 517 ASSERT(m_documentUnderMouse);
525 ReplaceSelectionCommand::create(*m_documentUnderMouse.get(), createF ragmentFromText(EphemeralRange(range.get()), text), ReplaceSelectionCommand::Se lectReplacement | ReplaceSelectionCommand::MatchStyle | ReplaceSelectionCommand: :PreventNesting, EditActionDrag)->apply(); 518 m_documentUnderMouse->frame()->editor().replaceSelectionAfterDraggin g(createFragmentFromText(EphemeralRange(range.get()), text), false, true);
yosin_UTC9 2016/01/27 02:23:03 nit: please use const local variable to name param
Xiaocheng 2016/01/27 03:16:02 Done.
526 } 519 }
527 } 520 }
528 521
529 if (rootEditableElement) { 522 if (rootEditableElement) {
530 if (LocalFrame* frame = rootEditableElement->document().frame()) 523 if (LocalFrame* frame = rootEditableElement->document().frame())
531 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement.get()); 524 frame->eventHandler().updateDragStateAfterEditDragIfNeeded(rootEdita bleElement.get());
532 } 525 }
533 526
534 return true; 527 return true;
535 } 528 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 956
964 DEFINE_TRACE(DragController) 957 DEFINE_TRACE(DragController)
965 { 958 {
966 visitor->trace(m_page); 959 visitor->trace(m_page);
967 visitor->trace(m_documentUnderMouse); 960 visitor->trace(m_documentUnderMouse);
968 visitor->trace(m_dragInitiator); 961 visitor->trace(m_dragInitiator);
969 visitor->trace(m_fileInputElementUnderMouse); 962 visitor->trace(m_fileInputElementUnderMouse);
970 } 963 }
971 964
972 } // namespace blink 965 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698