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

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

Issue 1752933002: [InputEvent] Fire 'beforeinput' during typing, pressing hot keys and IME composition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Yosin's review 3 Created 4 years, 8 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 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 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 * Copyright (C) 2009 Igalia S.L. 4 * Copyright (C) 2009 Igalia S.L.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 std::begin(kCommandNameEntries), std::end(kCommandNameEntries), commandN ame, 97 std::begin(kCommandNameEntries), std::end(kCommandNameEntries), commandN ame,
98 [](const CommandNameEntry& entry, const String& needle) 98 [](const CommandNameEntry& entry, const String& needle)
99 { 99 {
100 return codePointCompareIgnoringASCIICase(needle, entry.name) > 0; 100 return codePointCompareIgnoringASCIICase(needle, entry.name) > 0;
101 }); 101 });
102 if (result != std::end(kCommandNameEntries) && codePointCompareIgnoringASCII Case(commandName, result->name) == 0) 102 if (result != std::end(kCommandNameEntries) && codePointCompareIgnoringASCII Case(commandName, result->name) == 0)
103 return result->type; 103 return result->type;
104 return WebEditingCommandType::Invalid; 104 return WebEditingCommandType::Invalid;
105 } 105 }
106 106
107 InputEvent::InputType InputTypeFromCommandType(WebEditingCommandType commandType )
108 {
109 switch (commandType) {
110 case WebEditingCommandType::Delete:
111 case WebEditingCommandType::DeleteBackward:
112 case WebEditingCommandType::DeleteBackwardByDecomposingPreviousCharacter:
113 case WebEditingCommandType::DeleteForward:
114 case WebEditingCommandType::DeleteToBeginningOfLine:
115 case WebEditingCommandType::DeleteToBeginningOfParagraph:
116 case WebEditingCommandType::DeleteToEndOfLine:
117 case WebEditingCommandType::DeleteToEndOfParagraph:
118 case WebEditingCommandType::DeleteToMark:
119 case WebEditingCommandType::DeleteWordBackward:
120 case WebEditingCommandType::DeleteWordForward:
121 return InputEvent::InputType::DeleteContent;
122 case WebEditingCommandType::Redo:
123 return InputEvent::InputType::Redo;
124 case WebEditingCommandType::Undo:
125 return InputEvent::InputType::Undo;
126 case WebEditingCommandType::InsertBacktab:
127 case WebEditingCommandType::InsertHTML:
128 case WebEditingCommandType::InsertHorizontalRule:
129 case WebEditingCommandType::InsertImage:
130 case WebEditingCommandType::InsertLineBreak:
131 case WebEditingCommandType::InsertNewline:
132 case WebEditingCommandType::InsertNewlineInQuotedContent:
133 case WebEditingCommandType::InsertOrderedList:
134 case WebEditingCommandType::InsertParagraph:
135 case WebEditingCommandType::InsertTab:
136 case WebEditingCommandType::InsertText:
137 case WebEditingCommandType::InsertUnorderedList:
138 return InputEvent::InputType::InsertText;
ojan 2016/04/16 00:11:45 I think InsertText and InsertHTML should be two se
chongz 2016/04/18 22:54:47 The spec (http://w3c.github.io/editing/input-event
chongz 2016/04/19 21:17:01 Actually according to https://github.com/w3c/editi
139 default:
140 return InputEvent::InputType::None;
141 }
142 }
143
107 } // anonymous namespace 144 } // anonymous namespace
108 145
109 class EditorInternalCommand { 146 class EditorInternalCommand {
110 public: 147 public:
111 WebEditingCommandType commandType; 148 WebEditingCommandType commandType;
112 bool (*execute)(LocalFrame&, Event*, EditorCommandSource, const String&); 149 bool (*execute)(LocalFrame&, Event*, EditorCommandSource, const String&);
113 bool (*isSupportedFromDOM)(LocalFrame*); 150 bool (*isSupportedFromDOM)(LocalFrame*);
114 bool (*isEnabled)(LocalFrame&, Event*, EditorCommandSource); 151 bool (*isEnabled)(LocalFrame&, Event*, EditorCommandSource);
115 TriState (*state)(LocalFrame&, Event*); 152 TriState (*state)(LocalFrame&, Event*);
116 String (*value)(LocalFrame&, Event*); 153 String (*value)(LocalFrame&, Event*);
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 { 1781 {
1745 // TODO(yosin) We should move this logic into |canExecute()| member function 1782 // TODO(yosin) We should move this logic into |canExecute()| member function
1746 // in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|. 1783 // in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|.
1747 // |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands 1784 // |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands
1748 // only. 1785 // only.
1749 if (!isEnabled(triggeringEvent)) { 1786 if (!isEnabled(triggeringEvent)) {
1750 // Let certain commands be executed when performed explicitly even if th ey are disabled. 1787 // Let certain commands be executed when performed explicitly even if th ey are disabled.
1751 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled ) 1788 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled )
1752 return false; 1789 return false;
1753 } 1790 }
1791
1792 if (m_source == CommandFromMenuOrKeyBinding) {
1793 InputEvent::InputType inputType = InputTypeFromCommandType(m_command->co mmandType);
1794 if (inputType != InputEvent::InputType::None) {
1795 if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_fr ame->document()), inputType) != DispatchEventResult::NotCanceled)
1796 return true;
1797 }
1798 }
1799
1800 // 'beforeinput' event handler may destroy |frame()|.
1801 if (!m_frame || !frame().document())
1802 return false;
1803
1754 frame().document()->updateLayoutIgnorePendingStylesheets(); 1804 frame().document()->updateLayoutIgnorePendingStylesheets();
1755 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands")); 1805 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands"));
1756 commandHistogram.sample(static_cast<int>(m_command->commandType)); 1806 commandHistogram.sample(static_cast<int>(m_command->commandType));
1757 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter); 1807 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter);
1758 } 1808 }
1759 1809
1760 bool Editor::Command::execute(Event* triggeringEvent) const 1810 bool Editor::Command::execute(Event* triggeringEvent) const
1761 { 1811 {
1762 return execute(String(), triggeringEvent); 1812 return execute(String(), triggeringEvent);
1763 } 1813 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 { 1853 {
1804 return m_command && m_command->isTextInsertion; 1854 return m_command && m_command->isTextInsertion;
1805 } 1855 }
1806 1856
1807 int Editor::Command::idForHistogram() const 1857 int Editor::Command::idForHistogram() const
1808 { 1858 {
1809 return isSupported() ? static_cast<int>(m_command->commandType) : 0; 1859 return isSupported() ? static_cast<int>(m_command->commandType) : 0;
1810 } 1860 }
1811 1861
1812 } // namespace blink 1862 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698