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

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: Rebase 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::InsertText:
128 return InputEvent::InputType::InsertText;
129 default:
130 return InputEvent::InputType::None;
131 }
132 }
133
107 } // anonymous namespace 134 } // anonymous namespace
108 135
109 class EditorInternalCommand { 136 class EditorInternalCommand {
110 public: 137 public:
111 WebEditingCommandType commandType; 138 WebEditingCommandType commandType;
112 bool (*execute)(LocalFrame&, Event*, EditorCommandSource, const String&); 139 bool (*execute)(LocalFrame&, Event*, EditorCommandSource, const String&);
113 bool (*isSupportedFromDOM)(LocalFrame*); 140 bool (*isSupportedFromDOM)(LocalFrame*);
114 bool (*isEnabled)(LocalFrame&, Event*, EditorCommandSource); 141 bool (*isEnabled)(LocalFrame&, Event*, EditorCommandSource);
115 TriState (*state)(LocalFrame&, Event*); 142 TriState (*state)(LocalFrame&, Event*);
116 String (*value)(LocalFrame&, Event*); 143 String (*value)(LocalFrame&, Event*);
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 { 1771 {
1745 // TODO(yosin) We should move this logic into |canExecute()| member function 1772 // TODO(yosin) We should move this logic into |canExecute()| member function
1746 // in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|. 1773 // in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|.
1747 // |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands 1774 // |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands
1748 // only. 1775 // only.
1749 if (!isEnabled(triggeringEvent)) { 1776 if (!isEnabled(triggeringEvent)) {
1750 // Let certain commands be executed when performed explicitly even if th ey are disabled. 1777 // Let certain commands be executed when performed explicitly even if th ey are disabled.
1751 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled ) 1778 if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled )
1752 return false; 1779 return false;
1753 } 1780 }
1781
1782 if (m_source == CommandFromMenuOrKeyBinding) {
1783 InputEvent::InputType inputType = InputTypeFromCommandType(m_command->co mmandType);
1784 if (inputType != InputEvent::InputType::None) {
1785 if (dispatchBeforeInputEditorCommand(eventTargetNodeForDocument(m_fr ame->document()), inputType) != DispatchEventResult::NotCanceled)
1786 return true;
1787 }
1788 }
1789
1790 // 'beforeinput' event handler may destroy |frame()|.
1791 if (!m_frame || !frame().document())
1792 return false;
1793
1754 frame().document()->updateLayoutIgnorePendingStylesheets(); 1794 frame().document()->updateLayoutIgnorePendingStylesheets();
1755 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands")); 1795 DEFINE_STATIC_LOCAL(SparseHistogram, commandHistogram, ("WebCore.Editing.Com mands"));
1756 commandHistogram.sample(static_cast<int>(m_command->commandType)); 1796 commandHistogram.sample(static_cast<int>(m_command->commandType));
1757 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter); 1797 return m_command->execute(*m_frame, triggeringEvent, m_source, parameter);
1758 } 1798 }
1759 1799
1760 bool Editor::Command::execute(Event* triggeringEvent) const 1800 bool Editor::Command::execute(Event* triggeringEvent) const
1761 { 1801 {
1762 return execute(String(), triggeringEvent); 1802 return execute(String(), triggeringEvent);
1763 } 1803 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 { 1843 {
1804 return m_command && m_command->isTextInsertion; 1844 return m_command && m_command->isTextInsertion;
1805 } 1845 }
1806 1846
1807 int Editor::Command::idForHistogram() const 1847 int Editor::Command::idForHistogram() const
1808 { 1848 {
1809 return isSupported() ? static_cast<int>(m_command->commandType) : 0; 1849 return isSupported() ? static_cast<int>(m_command->commandType) : 0;
1810 } 1850 }
1811 1851
1812 } // namespace blink 1852 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698