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

Side by Side Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2288913002: [InputEvent] Support |deleteByDrag| and |insertFromDrop| (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 using namespace Unicode; 97 using namespace Unicode;
98 98
99 namespace { 99 namespace {
100 100
101 void dispatchInputEvent(Element* target, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComposing isComposing) 101 void dispatchInputEvent(Element* target, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComposing isComposing)
102 { 102 {
103 if (!RuntimeEnabledFeatures::inputEventEnabled()) 103 if (!RuntimeEnabledFeatures::inputEventEnabled())
104 return; 104 return;
105 if (!target) 105 if (!target)
106 return; 106 return;
107 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec.
108 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype
109 InputEvent* inputEvent = InputEvent::createInput(inputType, data, isComposin g, nullptr); 107 InputEvent* inputEvent = InputEvent::createInput(inputType, data, isComposin g, nullptr);
110 target->dispatchScopedEvent(inputEvent); 108 target->dispatchScopedEvent(inputEvent);
111 } 109 }
112 110
113 void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRo ot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComp osing isComposing) 111 void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRo ot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComp osing isComposing)
114 { 112 {
113 if (inputType == InputEvent::InputType::MoveByDragDrop) {
chongz 2016/08/30 23:59:21 Do we have any other solution that does not requir
114 // Drag&Drop will be combined into one |MoveSelectionCommand|, we need t o split it into |DeleteByDrag| and |InsertFromDrop|.
115 if (startRoot)
116 dispatchInputEvent(startRoot, InputEvent::InputType::DeleteByDrag, d ata, isComposing);
117 if (endRoot)
118 dispatchInputEvent(endRoot, InputEvent::InputType::InsertFromDrop, d ata, isComposing);
yosin_UTC9 2016/08/31 01:20:34 Q: Do we dispatch "insertFromDrop" even if "delete
chongz 2016/09/02 18:02:10 Yes. Canceling 'deleteByDrag' only means cancellin
yosin_UTC9 2016/09/05 01:37:50 Your testing doesn't covered to make the case |end
chongz 2016/09/07 17:12:55 Added check in |dispatchInputEvent()|.
119 return;
120 }
121
115 if (startRoot) 122 if (startRoot)
116 dispatchInputEvent(startRoot, inputType, data, isComposing); 123 dispatchInputEvent(startRoot, inputType, data, isComposing);
117 if (endRoot && endRoot != startRoot) 124 if (endRoot && endRoot != startRoot)
yosin_UTC9 2016/08/31 01:20:34 Do we need to check |endRoot.isConnected()|?
chongz 2016/09/02 18:02:10 It seems to me that if the element was changed, we
yosin_UTC9 2016/09/05 01:37:50 According DOM spec, https://www.w3.org/TR/dom/#dis
chongz 2016/09/07 17:12:55 OK, thanks for the reference!
118 dispatchInputEvent(endRoot, inputType, data, isComposing); 125 dispatchInputEvent(endRoot, inputType, data, isComposing);
chongz 2016/08/30 23:59:21 Do we have other commands that will affect two edi
119 } 126 }
120 127
121 InputEvent::EventIsComposing isComposingFromCommand(const CompositeEditCommand* command) 128 InputEvent::EventIsComposing isComposingFromCommand(const CompositeEditCommand* command)
122 { 129 {
123 if (command->isTypingCommand() && toTypingCommand(command)->compositionType( ) != TypingCommand::TextCompositionNone) 130 if (command->isTypingCommand() && toTypingCommand(command)->compositionType( ) != TypingCommand::TextCompositionNone)
124 return InputEvent::EventIsComposing::IsComposing; 131 return InputEvent::EventIsComposing::IsComposing;
125 return InputEvent::EventIsComposing::NotComposing; 132 return InputEvent::EventIsComposing::NotComposing;
126 } 133 }
127 134
128 } // anonymous namespace 135 } // anonymous namespace
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 560
554 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. 561 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|.
555 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar tReplace, bool plainText) 562 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar tReplace, bool plainText)
556 { 563 {
557 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::PreventNesting; 564 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::S electReplacement | ReplaceSelectionCommand::PreventNesting;
558 if (smartReplace) 565 if (smartReplace)
559 options |= ReplaceSelectionCommand::SmartReplace; 566 options |= ReplaceSelectionCommand::SmartReplace;
560 if (plainText) 567 if (plainText)
561 options |= ReplaceSelectionCommand::MatchStyle; 568 options |= ReplaceSelectionCommand::MatchStyle;
562 DCHECK(frame().document()); 569 DCHECK(frame().document());
563 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Inpu tEvent::InputType::Drag)->apply(); 570 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Inpu tEvent::InputType::InsertFromDrop)->apply();
564 } 571 }
565 572
566 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi on& pos, bool smartInsert, bool smartDelete) 573 void Editor::moveSelectionAfterDragging(DocumentFragment* fragment, const Positi on& pos, bool smartInsert, bool smartDelete)
567 { 574 {
568 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply (); 575 MoveSelectionCommand::create(fragment, pos, smartInsert, smartDelete)->apply ();
569 } 576 }
570 577
571 EphemeralRange Editor::selectedRange() 578 EphemeralRange Editor::selectedRange()
572 { 579 {
573 return frame().selection().selection().toNormalizedEphemeralRange(); 580 return frame().selection().selection().toNormalizedEphemeralRange();
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 1419
1413 DEFINE_TRACE(Editor) 1420 DEFINE_TRACE(Editor)
1414 { 1421 {
1415 visitor->trace(m_frame); 1422 visitor->trace(m_frame);
1416 visitor->trace(m_lastEditCommand); 1423 visitor->trace(m_lastEditCommand);
1417 visitor->trace(m_undoStack); 1424 visitor->trace(m_undoStack);
1418 visitor->trace(m_mark); 1425 visitor->trace(m_mark);
1419 } 1426 }
1420 1427
1421 } // namespace blink 1428 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698