| OLD | NEW |
| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #include "wtf/text/CharacterNames.h" | 91 #include "wtf/text/CharacterNames.h" |
| 92 | 92 |
| 93 namespace blink { | 93 namespace blink { |
| 94 | 94 |
| 95 using namespace HTMLNames; | 95 using namespace HTMLNames; |
| 96 using namespace WTF; | 96 using namespace WTF; |
| 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, const Document* original
Document = nullptr) |
| 102 { | 102 { |
| 103 if (!RuntimeEnabledFeatures::inputEventEnabled()) | 103 if (!RuntimeEnabledFeatures::inputEventEnabled()) |
| 104 return; | 104 return; |
| 105 if (!target) | 105 if (!target || !target->isConnected()) |
| 106 return; | 106 return; |
| 107 // TODO(chongz): Pass appreciate |ranges| after it's defined on spec. | 107 if (originalDocument) |
| 108 // http://w3c.github.io/editing/input-events.html#dom-inputevent-inputtype | 108 DCHECK(originalDocument == target->ownerDocument()); |
| 109 InputEvent* inputEvent = InputEvent::createInput(inputType, data, isComposin
g, nullptr); | 109 InputEvent* inputEvent = InputEvent::createInput(inputType, data, isComposin
g, nullptr); |
| 110 target->dispatchScopedEvent(inputEvent); | 110 target->dispatchScopedEvent(inputEvent); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRo
ot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComp
osing isComposing) | 113 void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRo
ot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComp
osing isComposing) |
| 114 { | 114 { |
| 115 if (startRoot) | 115 const Document* endRootOriginalDocument = endRoot ? endRoot->ownerDocument()
: nullptr; |
| 116 dispatchInputEvent(startRoot, inputType, data, isComposing); | 116 if (inputType == InputEvent::InputType::MoveByDragDrop) { |
| 117 if (endRoot && endRoot != startRoot) | 117 // Drag&Drop will be combined into one |MoveSelectionCommand|, we need t
o split it into |DeleteByDrag| and |InsertFromDrop|. |
| 118 dispatchInputEvent(endRoot, inputType, data, isComposing); | 118 dispatchInputEvent(startRoot, InputEvent::InputType::DeleteByDrag, data,
isComposing); |
| 119 dispatchInputEvent(endRoot, InputEvent::InputType::InsertFromDrop, data,
isComposing, endRootOriginalDocument); |
| 120 return; |
| 121 } |
| 122 |
| 123 dispatchInputEvent(startRoot, inputType, data, isComposing); |
| 124 if (endRoot != startRoot) |
| 125 dispatchInputEvent(endRoot, inputType, data, isComposing, endRootOrigina
lDocument); |
| 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 Loading... |
| 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 | 1420 |
| 1414 DEFINE_TRACE(Editor) | 1421 DEFINE_TRACE(Editor) |
| 1415 { | 1422 { |
| 1416 visitor->trace(m_frame); | 1423 visitor->trace(m_frame); |
| 1417 visitor->trace(m_lastEditCommand); | 1424 visitor->trace(m_lastEditCommand); |
| 1418 visitor->trace(m_undoStack); | 1425 visitor->trace(m_undoStack); |
| 1419 visitor->trace(m_mark); | 1426 visitor->trace(m_mark); |
| 1420 } | 1427 } |
| 1421 | 1428 |
| 1422 } // namespace blink | 1429 } // namespace blink |
| OLD | NEW |