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"}, | |
ojan
2016/04/16 00:11:46
We will need the spec to make sure to list all the
chongz
2016/04/18 22:54:47
Posted question in https://github.com/w3c/editing/
| |
25 }; | |
26 | |
27 static_assert(arraysize(kInputTypeStringNameMap) == static_cast<size_t>(InputEve nt::InputType::NumberOfInputTypes), | |
28 "must handle all InputEvent::InputType"); | |
29 | |
30 String convertInputTypeToString(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 AtomicString(it->stringName); | |
35 return emptyString(); | |
36 } | |
37 | |
38 InputEvent::InputType convertStringToInputType(const String& stringName) | |
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 ) | |
ojan
2016/04/16 00:11:46
Why do we need to ignore case?
chongz
2016/04/18 22:54:48
I was trying to match the style of |execCommand()|
| |
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 = convertStringToInputType(initializer.inputType()); | |
ojan
2016/04/16 00:11:45
TODO: ojan
chongz
2016/04/18 22:54:47
Done.
| |
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(convertInputTypeToString(inputType)); | |
ojan
2016/04/16 00:11:46
It seems pretty silly for us to convert the enum t
chongz
2016/04/18 22:54:47
Done.
| |
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(convertInputTypeToString(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) | |
ojan
2016/04/16 00:11:46
This looks the same as createBeforeInputTyping. Ca
chongz
2016/04/18 22:54:47
Done.
| |
91 { | |
92 InputEventInit inputEventInit; | |
93 | |
94 inputEventInit.setBubbles(true); | |
95 inputEventInit.setCancelable(true); | |
96 inputEventInit.setInputType(convertInputTypeToString(inputType)); | |
97 inputEventInit.setData(data); | |
98 | |
99 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | |
100 } | |
101 | |
102 String InputEvent::inputType() const | |
103 { | |
104 return convertInputTypeToString(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 |