Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 #include "platform/weborigin/KURL.h" | 89 #include "platform/weborigin/KURL.h" |
| 90 #include "wtf/PtrUtil.h" | 90 #include "wtf/PtrUtil.h" |
| 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 { | |
| 100 | |
| 101 void dispatchInputEvent(Element* target, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComposing isComposing) | |
| 102 { | |
| 103 if (!RuntimeEnabledFeatures::inputEventEnabled()) | |
| 104 return; | |
| 105 if (!target) | |
| 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); | |
| 110 target->dispatchScopedEvent(inputEvent); | |
|
chongz
2016/06/22 05:16:52
I have to check |FrameSelection::isAvailable()| if
yosin_UTC9
2016/06/22 06:29:25
Not sure. Why should we need to check |FrameSelect
chongz
2016/06/23 00:32:06
It's about test "editing/pasteboard/paste-removing
| |
| 111 } | |
| 112 | |
| 113 void dispatchInputEventEditableContentChanged(Element* startRoot, Element* endRo ot, InputEvent::InputType inputType, const String& data, InputEvent::EventIsComp osing isComposing) | |
| 114 { | |
| 115 if (startRoot) | |
| 116 dispatchInputEvent(startRoot, inputType, data, isComposing); | |
| 117 if (endRoot && endRoot != startRoot) | |
| 118 dispatchInputEvent(endRoot, inputType, data, isComposing); | |
| 119 } | |
| 120 | |
| 121 InputEvent::InputType inputTypeFromCommand(CompositeEditCommand* command) | |
|
tkent
2016/06/22 06:53:21
The argument type should be |const CompositeEditCo
chongz
2016/06/23 00:32:06
Done.
| |
| 122 { | |
| 123 if (command->isTypingCommand()) { | |
| 124 TypingCommand* typingCommand = static_cast<TypingCommand*>(command); | |
|
tkent
2016/06/22 06:53:21
Please avoid bare static_cast<>. TypingCommand sh
chongz
2016/06/23 00:32:06
Done.
| |
| 125 // TODO(chongz): Separate command types into more detailed InputType. | |
| 126 switch (typingCommand->commandTypeOfOpenCommand()) { | |
| 127 case TypingCommand::DeleteSelection: | |
| 128 case TypingCommand::DeleteKey: | |
| 129 case TypingCommand::ForwardDeleteKey: | |
| 130 return InputEvent::InputType::DeleteContent; | |
| 131 case TypingCommand::InsertText: | |
| 132 case TypingCommand::InsertLineBreak: | |
| 133 case TypingCommand::InsertParagraphSeparator: | |
| 134 case TypingCommand::InsertParagraphSeparatorInQuotedContent: | |
| 135 return InputEvent::InputType::InsertText; | |
| 136 default: | |
| 137 return InputEvent::InputType::None; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 switch (command->editingAction()) { | |
| 142 // TODO(chongz): Handle other edit actions. | |
| 143 case EditActionBold: | |
| 144 return InputEvent::InputType::Bold; | |
|
chongz
2016/06/23 00:32:06
Actually text styling commands are a little bit co
| |
| 145 default: | |
| 146 return InputEvent::InputType::None; | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 InputEvent::EventIsComposing isComposingFromCommand(CompositeEditCommand* comman d) | |
|
tkent
2016/06/22 06:53:21
The argument type should be |const CompositeEditCo
chongz
2016/06/23 00:32:06
Done.
| |
| 151 { | |
| 152 if (command->isTypingCommand() && static_cast<TypingCommand*>(command)->comp ositionType() != TypingCommand::TextCompositionNone) | |
|
tkent
2016/06/22 06:53:21
We should use toTypingCommand(command).
chongz
2016/06/23 00:32:06
Done.
| |
| 153 return InputEvent::EventIsComposing::IsComposing; | |
| 154 return InputEvent::EventIsComposing::NotComposing; | |
| 155 } | |
| 156 | |
| 157 } // anonymous namespace | |
| 158 | |
| 99 Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor) | 159 Editor::RevealSelectionScope::RevealSelectionScope(Editor* editor) |
| 100 : m_editor(editor) | 160 : m_editor(editor) |
| 101 { | 161 { |
| 102 ++m_editor->m_preventRevealSelection; | 162 ++m_editor->m_preventRevealSelection; |
| 103 } | 163 } |
| 104 | 164 |
| 105 Editor::RevealSelectionScope::~RevealSelectionScope() | 165 Editor::RevealSelectionScope::~RevealSelectionScope() |
| 106 { | 166 { |
| 107 DCHECK(m_editor->m_preventRevealSelection); | 167 DCHECK(m_editor->m_preventRevealSelection); |
| 108 --m_editor->m_preventRevealSelection; | 168 --m_editor->m_preventRevealSelection; |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 { | 755 { |
| 696 EventQueueScope scope; | 756 EventQueueScope scope; |
| 697 frame().document()->updateStyleAndLayout(); | 757 frame().document()->updateStyleAndLayout(); |
| 698 | 758 |
| 699 // Request spell checking after pasting before any further DOM change. | 759 // Request spell checking after pasting before any further DOM change. |
| 700 requestSpellcheckingAfterApplyingCommand(cmd); | 760 requestSpellcheckingAfterApplyingCommand(cmd); |
| 701 | 761 |
| 702 EditCommandComposition* composition = cmd->composition(); | 762 EditCommandComposition* composition = cmd->composition(); |
| 703 DCHECK(composition); | 763 DCHECK(composition); |
| 704 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement()); | 764 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen t(), composition->endingRootEditableElement()); |
| 765 // TODO(chongz): Filter empty InputType after spec is finalized. | |
| 766 // TODO(chongz): Fill in |data| field. | |
| 767 dispatchInputEventEditableContentChanged(composition->startingRootEditableEl ement(), composition->endingRootEditableElement(), inputTypeFromCommand(cmd), em ptyString(), isComposingFromCommand(cmd)); | |
| 705 VisibleSelection newSelection(cmd->endingSelection()); | 768 VisibleSelection newSelection(cmd->endingSelection()); |
| 706 | 769 |
| 707 // Don't clear the typing style with this selection change. We do those thin gs elsewhere if necessary. | 770 // Don't clear the typing style with this selection change. We do those thin gs elsewhere if necessary. |
| 708 changeSelectionAfterCommand(newSelection, 0); | 771 changeSelectionAfterCommand(newSelection, 0); |
| 709 | 772 |
| 710 if (!cmd->preservesTypingStyle()) | 773 if (!cmd->preservesTypingStyle()) |
| 711 frame().selection().clearTypingStyle(); | 774 frame().selection().clearTypingStyle(); |
| 712 | 775 |
| 713 // Command will be equal to last edit command only in the case of typing | 776 // Command will be equal to last edit command only in the case of typing |
| 714 if (m_lastEditCommand.get() == cmd) { | 777 if (m_lastEditCommand.get() == cmd) { |
| 715 DCHECK(cmd->isTypingCommand()); | 778 DCHECK(cmd->isTypingCommand()); |
| 716 } else { | 779 } else { |
| 717 // Only register a new undo command if the command passed in is | 780 // Only register a new undo command if the command passed in is |
| 718 // different from the last command | 781 // different from the last command |
| 719 m_lastEditCommand = cmd; | 782 m_lastEditCommand = cmd; |
| 720 if (UndoStack* undoStack = this->undoStack()) | 783 if (UndoStack* undoStack = this->undoStack()) |
| 721 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); | 784 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); |
| 722 } | 785 } |
| 723 | 786 |
| 724 respondToChangedContents(newSelection); | 787 respondToChangedContents(newSelection); |
| 725 } | 788 } |
| 726 | 789 |
| 727 void Editor::unappliedEditing(EditCommandComposition* cmd) | 790 void Editor::unappliedEditing(EditCommandComposition* cmd) |
| 728 { | 791 { |
| 729 EventQueueScope scope; | 792 EventQueueScope scope; |
| 730 frame().document()->updateStyleAndLayout(); | 793 frame().document()->updateStyleAndLayout(); |
| 731 | 794 |
| 732 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); | 795 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); |
| 796 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Undo, emptyString(), I nputEvent::EventIsComposing::NotComposing); | |
| 733 | 797 |
| 734 VisibleSelection newSelection(cmd->startingSelection()); | 798 VisibleSelection newSelection(cmd->startingSelection()); |
| 735 newSelection.validatePositionsIfNeeded(); | 799 newSelection.validatePositionsIfNeeded(); |
| 736 if (newSelection.start().document() == frame().document() && newSelection.en d().document() == frame().document()) | 800 if (newSelection.start().document() == frame().document() && newSelection.en d().document() == frame().document()) |
| 737 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); | 801 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
| 738 | 802 |
| 739 m_lastEditCommand = nullptr; | 803 m_lastEditCommand = nullptr; |
| 740 if (UndoStack* undoStack = this->undoStack()) | 804 if (UndoStack* undoStack = this->undoStack()) |
| 741 undoStack->registerRedoStep(cmd); | 805 undoStack->registerRedoStep(cmd); |
| 742 respondToChangedContents(newSelection); | 806 respondToChangedContents(newSelection); |
| 743 } | 807 } |
| 744 | 808 |
| 745 void Editor::reappliedEditing(EditCommandComposition* cmd) | 809 void Editor::reappliedEditing(EditCommandComposition* cmd) |
| 746 { | 810 { |
| 747 EventQueueScope scope; | 811 EventQueueScope scope; |
| 748 frame().document()->updateStyleAndLayout(); | 812 frame().document()->updateStyleAndLayout(); |
| 749 | 813 |
| 750 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); | 814 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd ->endingRootEditableElement()); |
| 815 dispatchInputEventEditableContentChanged(cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), InputEvent::InputType::Redo, emptyString(), I nputEvent::EventIsComposing::NotComposing); | |
| 751 | 816 |
| 752 VisibleSelection newSelection(cmd->endingSelection()); | 817 VisibleSelection newSelection(cmd->endingSelection()); |
| 753 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); | 818 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram eSelection::ClearTypingStyle); |
| 754 | 819 |
| 755 m_lastEditCommand = nullptr; | 820 m_lastEditCommand = nullptr; |
| 756 if (UndoStack* undoStack = this->undoStack()) | 821 if (UndoStack* undoStack = this->undoStack()) |
| 757 undoStack->registerUndoStep(cmd); | 822 undoStack->registerUndoStep(cmd); |
| 758 respondToChangedContents(newSelection); | 823 respondToChangedContents(newSelection); |
| 759 } | 824 } |
| 760 | 825 |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1370 } | 1435 } |
| 1371 | 1436 |
| 1372 DEFINE_TRACE(Editor) | 1437 DEFINE_TRACE(Editor) |
| 1373 { | 1438 { |
| 1374 visitor->trace(m_frame); | 1439 visitor->trace(m_frame); |
| 1375 visitor->trace(m_lastEditCommand); | 1440 visitor->trace(m_lastEditCommand); |
| 1376 visitor->trace(m_mark); | 1441 visitor->trace(m_mark); |
| 1377 } | 1442 } |
| 1378 | 1443 |
| 1379 } // namespace blink | 1444 } // namespace blink |
| OLD | NEW |