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/dom/Range.h" | 7 #include "core/dom/Range.h" |
8 #include "core/events/EventDispatcher.h" | 8 #include "core/events/EventDispatcher.h" |
9 #include "public/platform/WebEditingCommandType.h" | 9 #include "public/platform/WebEditingCommandType.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const struct { | 15 const struct { |
16 InputEvent::InputType inputType; | 16 InputEvent::InputType inputType; |
17 const char* stringName; | 17 const char* stringName; |
18 } kInputTypeStringNameMap[] = { | 18 } kInputTypeStringNameMap[] = { |
19 { InputEvent::InputType::None, "" }, | 19 { InputEvent::InputType::None, "" }, |
20 { InputEvent::InputType::InsertText, "insertText" }, | 20 { InputEvent::InputType::InsertText, "insertText" }, |
21 { InputEvent::InputType::InsertNonText, "insertNonText" }, | 21 { InputEvent::InputType::InsertNonText, "insertNonText" }, |
22 { InputEvent::InputType::InsertLineBreak, "insertLineBreak" }, | 22 { InputEvent::InputType::InsertLineBreak, "insertLineBreak" }, |
23 { InputEvent::InputType::InsertParagraph, "insertParagraph" }, | 23 { InputEvent::InputType::InsertParagraph, "insertParagraph" }, |
24 { InputEvent::InputType::InsertOrderedList, "insertOrderedList" }, | 24 { InputEvent::InputType::InsertOrderedList, "insertOrderedList" }, |
25 { InputEvent::InputType::InsertUnorderedList, "insertUnorderedList" }, | 25 { InputEvent::InputType::InsertUnorderedList, "insertUnorderedList" }, |
26 { InputEvent::InputType::InsertHorizontalRule, "insertHorizontalRule" }, | 26 { InputEvent::InputType::InsertHorizontalRule, "insertHorizontalRule" }, |
| 27 { InputEvent::InputType::InsertFromPaste, "insertFromPaste" }, |
27 { InputEvent::InputType::DeleteComposedCharacterForward, "deleteComposedChar
acterForward" }, | 28 { InputEvent::InputType::DeleteComposedCharacterForward, "deleteComposedChar
acterForward" }, |
28 { InputEvent::InputType::DeleteComposedCharacterBackward, "deleteComposedCha
racterBackward" }, | 29 { InputEvent::InputType::DeleteComposedCharacterBackward, "deleteComposedCha
racterBackward" }, |
29 { InputEvent::InputType::DeleteWordBackward, "deleteWordBackward" }, | 30 { InputEvent::InputType::DeleteWordBackward, "deleteWordBackward" }, |
30 { InputEvent::InputType::DeleteWordForward, "deleteWordForward" }, | 31 { InputEvent::InputType::DeleteWordForward, "deleteWordForward" }, |
31 { InputEvent::InputType::DeleteLineBackward, "deleteLineBackward" }, | 32 { InputEvent::InputType::DeleteLineBackward, "deleteLineBackward" }, |
32 { InputEvent::InputType::DeleteLineForward, "deleteLineForward" }, | 33 { InputEvent::InputType::DeleteLineForward, "deleteLineForward" }, |
33 { InputEvent::InputType::DeleteContentBackward, "deleteContentBackward" }, | 34 { InputEvent::InputType::DeleteContentBackward, "deleteContentBackward" }, |
34 { InputEvent::InputType::DeleteContentForward, "deleteContentForward" }, | 35 { InputEvent::InputType::DeleteContentForward, "deleteContentForward" }, |
| 36 { InputEvent::InputType::DeleteByCut, "deleteByCut" }, |
35 { InputEvent::InputType::Undo, "undo" }, | 37 { InputEvent::InputType::Undo, "undo" }, |
36 { InputEvent::InputType::Redo, "redo" }, | 38 { InputEvent::InputType::Redo, "redo" }, |
37 { InputEvent::InputType::Copy, "copy" }, | |
38 { InputEvent::InputType::Cut, "cut" }, | |
39 { InputEvent::InputType::Paste, "paste" }, | |
40 { InputEvent::InputType::Bold, "bold" }, | 39 { InputEvent::InputType::Bold, "bold" }, |
41 { InputEvent::InputType::Italic, "italic" }, | 40 { InputEvent::InputType::Italic, "italic" }, |
42 { InputEvent::InputType::Underline, "underline" }, | 41 { InputEvent::InputType::Underline, "underline" }, |
43 { InputEvent::InputType::StrikeThrough, "strikeThrough" }, | 42 { InputEvent::InputType::StrikeThrough, "strikeThrough" }, |
44 { InputEvent::InputType::Superscript, "superscript" }, | 43 { InputEvent::InputType::Superscript, "superscript" }, |
45 { InputEvent::InputType::Subscript, "subscript" }, | 44 { InputEvent::InputType::Subscript, "subscript" }, |
46 { InputEvent::InputType::JustifyCenter, "justifyCenter" }, | 45 { InputEvent::InputType::JustifyCenter, "justifyCenter" }, |
47 { InputEvent::InputType::JustifyRight, "justifyRight" }, | 46 { InputEvent::InputType::JustifyRight, "justifyRight" }, |
48 { InputEvent::InputType::JustifyLeft, "justifyLeft" }, | 47 { InputEvent::InputType::JustifyLeft, "justifyLeft" }, |
49 { InputEvent::InputType::Indent, "indent" }, | 48 { InputEvent::InputType::Indent, "indent" }, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 86 |
88 InputEvent::InputEvent(const AtomicString& type, const InputEventInit& initializ
er) | 87 InputEvent::InputEvent(const AtomicString& type, const InputEventInit& initializ
er) |
89 : UIEvent(type, initializer) | 88 : UIEvent(type, initializer) |
90 { | 89 { |
91 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. | 90 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. |
92 // See InputEvent::createBeforeInput() for the first conversion. | 91 // See InputEvent::createBeforeInput() for the first conversion. |
93 if (initializer.hasInputType()) | 92 if (initializer.hasInputType()) |
94 m_inputType = convertStringToInputType(initializer.inputType()); | 93 m_inputType = convertStringToInputType(initializer.inputType()); |
95 if (initializer.hasData()) | 94 if (initializer.hasData()) |
96 m_data = initializer.data(); | 95 m_data = initializer.data(); |
| 96 if (initializer.hasDataTransfer()) |
| 97 m_dataTransfer = initializer.dataTransfer(); |
97 if (initializer.hasIsComposing()) | 98 if (initializer.hasIsComposing()) |
98 m_isComposing = initializer.isComposing(); | 99 m_isComposing = initializer.isComposing(); |
99 if (initializer.hasRanges()) | 100 if (initializer.hasRanges()) |
100 m_ranges = initializer.ranges(); | 101 m_ranges = initializer.ranges(); |
101 } | 102 } |
102 | 103 |
103 /* static */ | 104 /* static */ |
104 InputEvent* InputEvent::createBeforeInput(InputType inputType, const String& dat
a, EventCancelable cancelable, EventIsComposing isComposing, const RangeVector*
ranges) | 105 InputEvent* InputEvent::createBeforeInput(InputType inputType, const String& dat
a, EventCancelable cancelable, EventIsComposing isComposing, const RangeVector*
ranges) |
105 { | 106 { |
106 InputEventInit inputEventInit; | 107 InputEventInit inputEventInit; |
107 | 108 |
108 inputEventInit.setBubbles(true); | 109 inputEventInit.setBubbles(true); |
109 inputEventInit.setCancelable(cancelable == IsCancelable); | 110 inputEventInit.setCancelable(cancelable == IsCancelable); |
110 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. | 111 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. |
111 // See InputEvent::InputEvent() for the second conversion. | 112 // See InputEvent::InputEvent() for the second conversion. |
112 inputEventInit.setInputType(convertInputTypeToString(inputType)); | 113 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
113 inputEventInit.setData(data); | 114 inputEventInit.setData(data); |
114 inputEventInit.setIsComposing(isComposing == IsComposing); | 115 inputEventInit.setIsComposing(isComposing == IsComposing); |
115 if (ranges) | 116 if (ranges) |
116 inputEventInit.setRanges(*ranges); | 117 inputEventInit.setRanges(*ranges); |
117 | 118 |
118 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | 119 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
119 } | 120 } |
120 | 121 |
121 /* static */ | 122 /* static */ |
| 123 InputEvent* InputEvent::createBeforeInput(InputType inputType, DataTransfer* dat
aTransfer, EventCancelable cancelable, EventIsComposing isComposing, const Range
Vector* ranges) |
| 124 { |
| 125 InputEventInit inputEventInit; |
| 126 |
| 127 inputEventInit.setBubbles(true); |
| 128 inputEventInit.setCancelable(cancelable == IsCancelable); |
| 129 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
| 130 inputEventInit.setDataTransfer(dataTransfer); |
| 131 inputEventInit.setIsComposing(isComposing == IsComposing); |
| 132 if (ranges) |
| 133 inputEventInit.setRanges(*ranges); |
| 134 |
| 135 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
| 136 } |
| 137 |
| 138 /* static */ |
122 InputEvent* InputEvent::createInput(InputType inputType, const String& data, Eve
ntIsComposing isComposing, const RangeVector* ranges) | 139 InputEvent* InputEvent::createInput(InputType inputType, const String& data, Eve
ntIsComposing isComposing, const RangeVector* ranges) |
123 { | 140 { |
124 InputEventInit inputEventInit; | 141 InputEventInit inputEventInit; |
125 | 142 |
126 inputEventInit.setBubbles(true); | 143 inputEventInit.setBubbles(true); |
127 inputEventInit.setCancelable(false); | 144 inputEventInit.setCancelable(false); |
128 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. | 145 // TODO(ojan): We should find a way to prevent conversion like String->enum-
>String just in order to use initializer. |
129 // See InputEvent::InputEvent() for the second conversion. | 146 // See InputEvent::InputEvent() for the second conversion. |
130 inputEventInit.setInputType(convertInputTypeToString(inputType)); | 147 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
131 inputEventInit.setData(data); | 148 inputEventInit.setData(data); |
(...skipping 25 matching lines...) Expand all Loading... |
157 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and i
ntroduce | 174 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and i
ntroduce |
158 // simpler interface such as |beforeDispatchEvent()| and |afterDispatchEvent()|
virtual methods. | 175 // simpler interface such as |beforeDispatchEvent()| and |afterDispatchEvent()|
virtual methods. |
159 EventDispatchMediator* InputEvent::createMediator() | 176 EventDispatchMediator* InputEvent::createMediator() |
160 { | 177 { |
161 return InputEventDispatchMediator::create(this); | 178 return InputEventDispatchMediator::create(this); |
162 } | 179 } |
163 | 180 |
164 DEFINE_TRACE(InputEvent) | 181 DEFINE_TRACE(InputEvent) |
165 { | 182 { |
166 UIEvent::trace(visitor); | 183 UIEvent::trace(visitor); |
| 184 visitor->trace(m_dataTransfer); |
167 visitor->trace(m_ranges); | 185 visitor->trace(m_ranges); |
168 } | 186 } |
169 | 187 |
170 InputEventDispatchMediator* InputEventDispatchMediator::create(InputEvent* input
Event) | 188 InputEventDispatchMediator* InputEventDispatchMediator::create(InputEvent* input
Event) |
171 { | 189 { |
172 return new InputEventDispatchMediator(inputEvent); | 190 return new InputEventDispatchMediator(inputEvent); |
173 } | 191 } |
174 | 192 |
175 InputEventDispatchMediator::InputEventDispatchMediator(InputEvent* inputEvent) | 193 InputEventDispatchMediator::InputEventDispatchMediator(InputEvent* inputEvent) |
176 : EventDispatchMediator(inputEvent) | 194 : EventDispatchMediator(inputEvent) |
(...skipping 17 matching lines...) Expand all Loading... |
194 // 3. We don't want authors to hold live |Range| indefinitely by holding |
InputEvent|, so we | 212 // 3. We don't want authors to hold live |Range| indefinitely by holding |
InputEvent|, so we |
195 // clear them after dispatch. | 213 // clear them after dispatch. |
196 // Authors should explicitly call |getRanges()|->|toRange()| if they want to
keep a copy of |Range|. | 214 // Authors should explicitly call |getRanges()|->|toRange()| if they want to
keep a copy of |Range|. |
197 // See Editing TF meeting notes: | 215 // See Editing TF meeting notes: |
198 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWL
G0AM58/edit?usp=sharing | 216 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWL
G0AM58/edit?usp=sharing |
199 event().m_ranges.clear(); | 217 event().m_ranges.clear(); |
200 return result; | 218 return result; |
201 } | 219 } |
202 | 220 |
203 } // namespace blink | 221 } // namespace blink |
OLD | NEW |