Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/events/InputEvent.h" | 5 #include "core/events/InputEvent.h" |
| 6 | 6 |
| 7 #include "core/events/EventDispatcher.h" | 7 #include "core/events/EventDispatcher.h" |
| 8 #include "public/platform/WebEditingCommandType.h" | |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 12 namespace { | |
| 13 | |
| 14 const struct { | |
| 15 InputEvent::InputType inputType; | |
| 16 const char* stringName; | |
| 17 } kInputTypeStringNameMap[] = { | |
| 18 {InputEvent::InputType::None, ""}, | |
| 19 {InputEvent::InputType::InsertText, "insertText"}, | |
| 20 {InputEvent::InputType::ReplaceContent, "replaceContent"}, | |
| 21 {InputEvent::InputType::DeleteContent, "deleteContent"}, | |
| 22 {InputEvent::InputType::DeleteComposedCharacter, "deleteComposedCharacter"}, | |
| 23 {InputEvent::InputType::Undo, "undo"}, | |
| 24 {InputEvent::InputType::Redo, "redo"}, | |
| 25 }; | |
| 26 | |
| 27 static_assert(arraysize(kInputTypeStringNameMap) == static_cast<size_t>(InputEve nt::InputType::NumberOfInputTypes), | |
| 28 "must handle all InputEvent::InputType"); | |
| 29 | |
| 30 String InputTypeToString(InputEvent::InputType inputType) | |
| 31 { | |
| 32 const auto& it = std::begin(kInputTypeStringNameMap) + static_cast<size_t>(i nputType); | |
| 33 if (it >= std::begin(kInputTypeStringNameMap) && it < std::end(kInputTypeStr ingNameMap)) | |
| 34 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.
| |
| 35 return ""; | |
|
yosin_UTC9
2016/04/13 06:13:09
s/""/emptyString()/
chongz
2016/04/13 23:53:09
Done.
| |
| 36 } | |
| 37 | |
| 38 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.
| |
| 39 { | |
| 40 // TODO(chongz): Use binary search if the map goes larger. | |
| 41 for (const auto& entry : kInputTypeStringNameMap) { | |
| 42 if (codePointCompareIgnoringASCIICase(stringName, entry.stringName) == 0 ) | |
| 43 return entry.inputType; | |
| 44 } | |
| 45 return InputEvent::InputType::None; | |
| 46 } | |
| 47 | |
| 48 } // anonymous namespace | |
| 49 | |
| 11 InputEvent::InputEvent() | 50 InputEvent::InputEvent() |
| 12 { | 51 { |
| 13 } | 52 } |
| 14 | 53 |
| 15 InputEvent::InputEvent(const AtomicString& type, const InputEventInit& initializ er) | 54 InputEvent::InputEvent(const AtomicString& type, const InputEventInit& initializ er) |
| 16 : UIEvent(type, initializer) | 55 : UIEvent(type, initializer) |
| 17 { | 56 { |
| 57 if (initializer.hasInputType()) | |
| 58 m_inputType = InputTypeFromString(initializer.inputType()); | |
| 59 if (initializer.hasData()) | |
| 60 m_data = initializer.data(); | |
| 61 } | |
| 62 | |
| 63 /* static */ | |
| 64 InputEvent* InputEvent::createBeforeInputTyping(InputType inputType, const Strin g& data) | |
| 65 { | |
| 66 InputEventInit inputEventInit; | |
| 67 | |
| 68 inputEventInit.setBubbles(true); | |
| 69 inputEventInit.setCancelable(true); | |
| 70 inputEventInit.setInputType(InputTypeToString(inputType)); | |
|
chongz
2016/04/13 00:34:28
I have to convert |inputType| to String here and t
| |
| 71 inputEventInit.setData(data); | |
| 72 | |
| 73 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | |
| 74 } | |
| 75 | |
| 76 /* static */ | |
| 77 InputEvent* InputEvent::createBeforeInputFromComposition(InputType inputType, co nst String& data) | |
| 78 { | |
| 79 InputEventInit inputEventInit; | |
| 80 | |
| 81 inputEventInit.setBubbles(true); | |
| 82 inputEventInit.setCancelable(false); | |
| 83 inputEventInit.setInputType(InputTypeToString(inputType)); | |
| 84 inputEventInit.setData(data); | |
| 85 | |
| 86 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | |
| 87 } | |
| 88 | |
| 89 /* static */ | |
| 90 InputEvent* InputEvent::createBeforeInputEditorCommand(InputType inputType, cons t String& data) | |
| 91 { | |
| 92 InputEventInit inputEventInit; | |
| 93 | |
| 94 inputEventInit.setBubbles(true); | |
| 95 inputEventInit.setCancelable(true); | |
| 96 inputEventInit.setInputType(InputTypeToString(inputType)); | |
| 97 inputEventInit.setData(data); | |
| 98 | |
| 99 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | |
| 100 } | |
| 101 | |
| 102 String InputEvent::inputType() const | |
| 103 { | |
| 104 return InputTypeToString(m_inputType); | |
| 18 } | 105 } |
| 19 | 106 |
| 20 bool InputEvent::isInputEvent() const | 107 bool InputEvent::isInputEvent() const |
| 21 { | 108 { |
| 22 return true; | 109 return true; |
| 23 } | 110 } |
| 24 | 111 |
| 25 DEFINE_TRACE(InputEvent) | 112 DEFINE_TRACE(InputEvent) |
| 26 { | 113 { |
| 27 UIEvent::trace(visitor); | 114 UIEvent::trace(visitor); |
| 28 } | 115 } |
| 29 | 116 |
| 30 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |