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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // String->enum->String just in order to use initializer. | 86 // String->enum->String just in order to use initializer. |
87 // See InputEvent::createBeforeInput() for the first conversion. | 87 // See InputEvent::createBeforeInput() for the first conversion. |
88 if (initializer.hasInputType()) | 88 if (initializer.hasInputType()) |
89 m_inputType = convertStringToInputType(initializer.inputType()); | 89 m_inputType = convertStringToInputType(initializer.inputType()); |
90 if (initializer.hasData()) | 90 if (initializer.hasData()) |
91 m_data = initializer.data(); | 91 m_data = initializer.data(); |
92 if (initializer.hasDataTransfer()) | 92 if (initializer.hasDataTransfer()) |
93 m_dataTransfer = initializer.dataTransfer(); | 93 m_dataTransfer = initializer.dataTransfer(); |
94 if (initializer.hasIsComposing()) | 94 if (initializer.hasIsComposing()) |
95 m_isComposing = initializer.isComposing(); | 95 m_isComposing = initializer.isComposing(); |
96 if (initializer.hasRanges()) | 96 if (initializer.hasTargetRanges()) { |
yosin_UTC9
2017/02/24 06:37:14
Prefer early return style.
if (!initializer.hasTa
chongz
2017/02/24 21:19:15
Done.
| |
97 m_ranges = initializer.ranges(); | 97 m_ranges.clear(); |
yosin_UTC9
2017/02/24 06:37:14
It seems noboday add elements to |m_ranges| since
chongz
2017/02/24 21:19:15
Removed.
| |
98 for (const auto& range : initializer.targetRanges()) | |
yosin_UTC9
2017/02/24 06:37:14
Can we do |m_ranges = initializer.targetRanges()|?
chongz
2017/02/24 21:19:15
|initializer.targetRanges()| is of type |HeapVecto
yosin_UTC9
2017/02/27 10:31:46
No.
| |
99 m_ranges.push_back(range->toRange()); | |
yosin_UTC9
2017/02/24 06:37:14
nit: s/push_back/emplace_back/
| |
100 } | |
98 } | 101 } |
99 | 102 |
100 /* static */ | 103 /* static */ |
101 InputEvent* InputEvent::createBeforeInput(InputType inputType, | 104 InputEvent* InputEvent::createBeforeInput(InputType inputType, |
102 const String& data, | 105 const String& data, |
103 EventCancelable cancelable, | 106 EventCancelable cancelable, |
104 EventIsComposing isComposing, | 107 EventIsComposing isComposing, |
105 const RangeVector* ranges) { | 108 const StaticRangeVector* ranges) { |
106 InputEventInit inputEventInit; | 109 InputEventInit inputEventInit; |
107 | 110 |
108 inputEventInit.setBubbles(true); | 111 inputEventInit.setBubbles(true); |
109 inputEventInit.setCancelable(cancelable == IsCancelable); | 112 inputEventInit.setCancelable(cancelable == IsCancelable); |
110 // TODO(ojan): We should find a way to prevent conversion like | 113 // TODO(ojan): We should find a way to prevent conversion like |
111 // String->enum->String just in order to use initializer. | 114 // String->enum->String just in order to use initializer. |
112 // See InputEvent::InputEvent() for the second conversion. | 115 // See InputEvent::InputEvent() for the second conversion. |
113 inputEventInit.setInputType(convertInputTypeToString(inputType)); | 116 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
114 inputEventInit.setData(data); | 117 inputEventInit.setData(data); |
115 inputEventInit.setIsComposing(isComposing == IsComposing); | 118 inputEventInit.setIsComposing(isComposing == IsComposing); |
116 if (ranges) | 119 if (ranges) |
117 inputEventInit.setRanges(*ranges); | 120 inputEventInit.setTargetRanges(*ranges); |
118 inputEventInit.setComposed(true); | 121 inputEventInit.setComposed(true); |
119 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | 122 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
120 } | 123 } |
121 | 124 |
122 /* static */ | 125 /* static */ |
123 InputEvent* InputEvent::createBeforeInput(InputType inputType, | 126 InputEvent* InputEvent::createBeforeInput(InputType inputType, |
124 DataTransfer* dataTransfer, | 127 DataTransfer* dataTransfer, |
125 EventCancelable cancelable, | 128 EventCancelable cancelable, |
126 EventIsComposing isComposing, | 129 EventIsComposing isComposing, |
127 const RangeVector* ranges) { | 130 const StaticRangeVector* ranges) { |
128 InputEventInit inputEventInit; | 131 InputEventInit inputEventInit; |
129 | 132 |
130 inputEventInit.setBubbles(true); | 133 inputEventInit.setBubbles(true); |
131 inputEventInit.setCancelable(cancelable == IsCancelable); | 134 inputEventInit.setCancelable(cancelable == IsCancelable); |
132 inputEventInit.setInputType(convertInputTypeToString(inputType)); | 135 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
133 inputEventInit.setDataTransfer(dataTransfer); | 136 inputEventInit.setDataTransfer(dataTransfer); |
134 inputEventInit.setIsComposing(isComposing == IsComposing); | 137 inputEventInit.setIsComposing(isComposing == IsComposing); |
135 if (ranges) | 138 if (ranges) |
136 inputEventInit.setRanges(*ranges); | 139 inputEventInit.setTargetRanges(*ranges); |
137 inputEventInit.setComposed(true); | 140 inputEventInit.setComposed(true); |
138 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); | 141 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); |
139 } | 142 } |
140 | 143 |
141 /* static */ | 144 /* static */ |
142 InputEvent* InputEvent::createInput(InputType inputType, | 145 InputEvent* InputEvent::createInput(InputType inputType, |
143 const String& data, | 146 const String& data, |
144 EventIsComposing isComposing, | 147 EventIsComposing isComposing, |
145 const RangeVector* ranges) { | 148 const StaticRangeVector* ranges) { |
146 InputEventInit inputEventInit; | 149 InputEventInit inputEventInit; |
147 | 150 |
148 inputEventInit.setBubbles(true); | 151 inputEventInit.setBubbles(true); |
149 inputEventInit.setCancelable(false); | 152 inputEventInit.setCancelable(false); |
150 // TODO(ojan): We should find a way to prevent conversion like | 153 // TODO(ojan): We should find a way to prevent conversion like |
151 // String->enum->String just in order to use initializer. | 154 // String->enum->String just in order to use initializer. |
152 // See InputEvent::InputEvent() for the second conversion. | 155 // See InputEvent::InputEvent() for the second conversion. |
153 inputEventInit.setInputType(convertInputTypeToString(inputType)); | 156 inputEventInit.setInputType(convertInputTypeToString(inputType)); |
154 inputEventInit.setData(data); | 157 inputEventInit.setData(data); |
155 inputEventInit.setIsComposing(isComposing == IsComposing); | 158 inputEventInit.setIsComposing(isComposing == IsComposing); |
156 if (ranges) | 159 if (ranges) |
157 inputEventInit.setRanges(*ranges); | 160 inputEventInit.setTargetRanges(*ranges); |
158 inputEventInit.setComposed(true); | 161 inputEventInit.setComposed(true); |
159 return InputEvent::create(EventTypeNames::input, inputEventInit); | 162 return InputEvent::create(EventTypeNames::input, inputEventInit); |
160 } | 163 } |
161 | 164 |
162 String InputEvent::inputType() const { | 165 String InputEvent::inputType() const { |
163 return convertInputTypeToString(m_inputType); | 166 return convertInputTypeToString(m_inputType); |
164 } | 167 } |
165 | 168 |
166 StaticRangeVector InputEvent::getTargetRanges() const { | 169 StaticRangeVector InputEvent::getTargetRanges() const { |
167 StaticRangeVector staticRanges; | 170 StaticRangeVector staticRanges; |
168 for (const auto& range : m_ranges) | 171 for (const auto& range : m_ranges) |
169 staticRanges.push_back(StaticRange::create( | 172 staticRanges.push_back(StaticRange::create(range)); |
yosin_UTC9
2017/02/24 06:37:14
nit: s/push_back/emplace_back/
| |
170 range->ownerDocument(), range->startContainer(), range->startOffset(), | |
171 range->endContainer(), range->endOffset())); | |
172 return staticRanges; | 173 return staticRanges; |
173 } | 174 } |
174 | 175 |
175 bool InputEvent::isInputEvent() const { | 176 bool InputEvent::isInputEvent() const { |
176 return true; | 177 return true; |
177 } | 178 } |
178 | 179 |
179 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and | 180 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and |
180 // introduce simpler interface such as |beforeDispatchEvent()| and | 181 // introduce simpler interface such as |beforeDispatchEvent()| and |
181 // |afterDispatchEvent()| virtual methods. | 182 // |afterDispatchEvent()| virtual methods. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 // 3. We don't want authors to hold live |Range| indefinitely by holding | 215 // 3. We don't want authors to hold live |Range| indefinitely by holding |
215 // |InputEvent|, so we clear them after dispatch. | 216 // |InputEvent|, so we clear them after dispatch. |
216 // Authors should explicitly call |getTargetRanges()|->|toRange()| if they | 217 // Authors should explicitly call |getTargetRanges()|->|toRange()| if they |
217 // want to keep a copy of |Range|. See Editing TF meeting notes: | 218 // want to keep a copy of |Range|. See Editing TF meeting notes: |
218 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWLG0 AM58/edit?usp=sharing | 219 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWLG0 AM58/edit?usp=sharing |
219 event().m_ranges.clear(); | 220 event().m_ranges.clear(); |
220 return result; | 221 return result; |
221 } | 222 } |
222 | 223 |
223 } // namespace blink | 224 } // namespace blink |
OLD | NEW |