Chromium Code Reviews| Index: third_party/WebKit/Source/core/events/InputEvent.cpp |
| diff --git a/third_party/WebKit/Source/core/events/InputEvent.cpp b/third_party/WebKit/Source/core/events/InputEvent.cpp |
| index f7eb07a65d040c9cb0071ccc8a29dc660983bf09..aa3f456f03ca00f946db3d06b78bcc050b90efb5 100644 |
| --- a/third_party/WebKit/Source/core/events/InputEvent.cpp |
| +++ b/third_party/WebKit/Source/core/events/InputEvent.cpp |
| @@ -5,9 +5,48 @@ |
| #include "core/events/InputEvent.h" |
| #include "core/events/EventDispatcher.h" |
| +#include "public/platform/WebEditingCommandType.h" |
| namespace blink { |
| +namespace { |
| + |
| +const struct { |
| + InputEvent::InputType inputType; |
| + const char* stringName; |
| +} kInputTypeStringNameMap[] = { |
| + {InputEvent::InputType::None, ""}, |
| + {InputEvent::InputType::InsertText, "insertText"}, |
| + {InputEvent::InputType::ReplaceContent, "replaceContent"}, |
| + {InputEvent::InputType::DeleteContent, "deleteContent"}, |
| + {InputEvent::InputType::DeleteComposedCharacter, "deleteComposedCharacter"}, |
| + {InputEvent::InputType::Undo, "undo"}, |
| + {InputEvent::InputType::Redo, "redo"}, |
| +}; |
| + |
| +static_assert(arraysize(kInputTypeStringNameMap) == static_cast<size_t>(InputEvent::InputType::NumberOfInputTypes), |
| + "must handle all InputEvent::InputType"); |
| + |
| +String InputTypeToString(InputEvent::InputType inputType) |
| +{ |
| + const auto& it = std::begin(kInputTypeStringNameMap) + static_cast<size_t>(inputType); |
| + if (it >= std::begin(kInputTypeStringNameMap) && it < std::end(kInputTypeStringNameMap)) |
| + return String(it->stringName); |
|
chongz
2016/04/13 00:34:28
Should I construct a local String table from |kInp
yosin_UTC9
2016/04/13 06:13:09
How about using AtomicString?
chongz
2016/04/13 23:53:09
Done.
|
| + return ""; |
|
yosin_UTC9
2016/04/13 06:13:09
s/""/emptyString()/
chongz
2016/04/13 23:53:09
Done.
|
| +} |
| + |
| +InputEvent::InputType InputTypeFromString(const String& stringName) |
|
yosin_UTC9
2016/04/13 06:13:09
s/InputTypeFromString/inputTypeFromString/ or |con
chongz
2016/04/13 23:53:09
Done.
|
| +{ |
| + // TODO(chongz): Use binary search if the map goes larger. |
| + for (const auto& entry : kInputTypeStringNameMap) { |
| + if (codePointCompareIgnoringASCIICase(stringName, entry.stringName) == 0) |
| + return entry.inputType; |
| + } |
| + return InputEvent::InputType::None; |
| +} |
| + |
| +} // anonymous namespace |
| + |
| InputEvent::InputEvent() |
| { |
| } |
| @@ -15,6 +54,54 @@ InputEvent::InputEvent() |
| InputEvent::InputEvent(const AtomicString& type, const InputEventInit& initializer) |
| : UIEvent(type, initializer) |
| { |
| + if (initializer.hasInputType()) |
| + m_inputType = InputTypeFromString(initializer.inputType()); |
| + if (initializer.hasData()) |
| + m_data = initializer.data(); |
| +} |
| + |
| +/* static */ |
| +InputEvent* InputEvent::createBeforeInputTyping(InputType inputType, const String& data) |
| +{ |
| + InputEventInit inputEventInit; |
| + |
| + inputEventInit.setBubbles(true); |
| + inputEventInit.setCancelable(true); |
| + inputEventInit.setInputType(InputTypeToString(inputType)); |
|
chongz
2016/04/13 00:34:28
I have to convert |inputType| to String here and t
|
| + inputEventInit.setData(data); |
| + |
| + return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
| +} |
| + |
| +/* static */ |
| +InputEvent* InputEvent::createBeforeInputFromComposition(InputType inputType, const String& data) |
| +{ |
| + InputEventInit inputEventInit; |
| + |
| + inputEventInit.setBubbles(true); |
| + inputEventInit.setCancelable(false); |
| + inputEventInit.setInputType(InputTypeToString(inputType)); |
| + inputEventInit.setData(data); |
| + |
| + return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
| +} |
| + |
| +/* static */ |
| +InputEvent* InputEvent::createBeforeInputEditorCommand(InputType inputType, const String& data) |
| +{ |
| + InputEventInit inputEventInit; |
| + |
| + inputEventInit.setBubbles(true); |
| + inputEventInit.setCancelable(true); |
| + inputEventInit.setInputType(InputTypeToString(inputType)); |
| + inputEventInit.setData(data); |
| + |
| + return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
| +} |
| + |
| +String InputEvent::inputType() const |
| +{ |
| + return InputTypeToString(m_inputType); |
| } |
| bool InputEvent::isInputEvent() const |