Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: third_party/WebKit/Source/core/events/InputEvent.cpp

Issue 2709883004: [InputEvent] Change |InputEventInit::sequence<Range> ranges| to |sequence<StaticRange> targetRanges| (Closed)
Patch Set: yosin's review: Use early return Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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())
97 m_ranges = initializer.ranges(); 97 return;
98 for (const auto& range : initializer.targetRanges())
99 m_ranges.push_back(range->toRange());
98 } 100 }
99 101
100 /* static */ 102 /* static */
101 InputEvent* InputEvent::createBeforeInput(InputType inputType, 103 InputEvent* InputEvent::createBeforeInput(InputType inputType,
102 const String& data, 104 const String& data,
103 EventCancelable cancelable, 105 EventCancelable cancelable,
104 EventIsComposing isComposing, 106 EventIsComposing isComposing,
105 const RangeVector* ranges) { 107 const StaticRangeVector* ranges) {
106 InputEventInit inputEventInit; 108 InputEventInit inputEventInit;
107 109
108 inputEventInit.setBubbles(true); 110 inputEventInit.setBubbles(true);
109 inputEventInit.setCancelable(cancelable == IsCancelable); 111 inputEventInit.setCancelable(cancelable == IsCancelable);
110 // TODO(ojan): We should find a way to prevent conversion like 112 // TODO(ojan): We should find a way to prevent conversion like
111 // String->enum->String just in order to use initializer. 113 // String->enum->String just in order to use initializer.
112 // See InputEvent::InputEvent() for the second conversion. 114 // See InputEvent::InputEvent() for the second conversion.
113 inputEventInit.setInputType(convertInputTypeToString(inputType)); 115 inputEventInit.setInputType(convertInputTypeToString(inputType));
114 inputEventInit.setData(data); 116 inputEventInit.setData(data);
115 inputEventInit.setIsComposing(isComposing == IsComposing); 117 inputEventInit.setIsComposing(isComposing == IsComposing);
116 if (ranges) 118 if (ranges)
117 inputEventInit.setRanges(*ranges); 119 inputEventInit.setTargetRanges(*ranges);
118 inputEventInit.setComposed(true); 120 inputEventInit.setComposed(true);
119 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); 121 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit);
120 } 122 }
121 123
122 /* static */ 124 /* static */
123 InputEvent* InputEvent::createBeforeInput(InputType inputType, 125 InputEvent* InputEvent::createBeforeInput(InputType inputType,
124 DataTransfer* dataTransfer, 126 DataTransfer* dataTransfer,
125 EventCancelable cancelable, 127 EventCancelable cancelable,
126 EventIsComposing isComposing, 128 EventIsComposing isComposing,
127 const RangeVector* ranges) { 129 const StaticRangeVector* ranges) {
128 InputEventInit inputEventInit; 130 InputEventInit inputEventInit;
129 131
130 inputEventInit.setBubbles(true); 132 inputEventInit.setBubbles(true);
131 inputEventInit.setCancelable(cancelable == IsCancelable); 133 inputEventInit.setCancelable(cancelable == IsCancelable);
132 inputEventInit.setInputType(convertInputTypeToString(inputType)); 134 inputEventInit.setInputType(convertInputTypeToString(inputType));
133 inputEventInit.setDataTransfer(dataTransfer); 135 inputEventInit.setDataTransfer(dataTransfer);
134 inputEventInit.setIsComposing(isComposing == IsComposing); 136 inputEventInit.setIsComposing(isComposing == IsComposing);
135 if (ranges) 137 if (ranges)
136 inputEventInit.setRanges(*ranges); 138 inputEventInit.setTargetRanges(*ranges);
137 inputEventInit.setComposed(true); 139 inputEventInit.setComposed(true);
138 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit); 140 return InputEvent::create(EventTypeNames::beforeinput, inputEventInit);
139 } 141 }
140 142
141 /* static */ 143 /* static */
142 InputEvent* InputEvent::createInput(InputType inputType, 144 InputEvent* InputEvent::createInput(InputType inputType,
143 const String& data, 145 const String& data,
144 EventIsComposing isComposing, 146 EventIsComposing isComposing,
145 const RangeVector* ranges) { 147 const StaticRangeVector* ranges) {
146 InputEventInit inputEventInit; 148 InputEventInit inputEventInit;
147 149
148 inputEventInit.setBubbles(true); 150 inputEventInit.setBubbles(true);
149 inputEventInit.setCancelable(false); 151 inputEventInit.setCancelable(false);
150 // TODO(ojan): We should find a way to prevent conversion like 152 // TODO(ojan): We should find a way to prevent conversion like
151 // String->enum->String just in order to use initializer. 153 // String->enum->String just in order to use initializer.
152 // See InputEvent::InputEvent() for the second conversion. 154 // See InputEvent::InputEvent() for the second conversion.
153 inputEventInit.setInputType(convertInputTypeToString(inputType)); 155 inputEventInit.setInputType(convertInputTypeToString(inputType));
154 inputEventInit.setData(data); 156 inputEventInit.setData(data);
155 inputEventInit.setIsComposing(isComposing == IsComposing); 157 inputEventInit.setIsComposing(isComposing == IsComposing);
156 if (ranges) 158 if (ranges)
157 inputEventInit.setRanges(*ranges); 159 inputEventInit.setTargetRanges(*ranges);
158 inputEventInit.setComposed(true); 160 inputEventInit.setComposed(true);
159 return InputEvent::create(EventTypeNames::input, inputEventInit); 161 return InputEvent::create(EventTypeNames::input, inputEventInit);
160 } 162 }
161 163
162 String InputEvent::inputType() const { 164 String InputEvent::inputType() const {
163 return convertInputTypeToString(m_inputType); 165 return convertInputTypeToString(m_inputType);
164 } 166 }
165 167
166 StaticRangeVector InputEvent::getTargetRanges() const { 168 StaticRangeVector InputEvent::getTargetRanges() const {
167 StaticRangeVector staticRanges; 169 StaticRangeVector staticRanges;
168 for (const auto& range : m_ranges) 170 for (const auto& range : m_ranges)
169 staticRanges.push_back(StaticRange::create( 171 staticRanges.push_back(StaticRange::create(range));
170 range->ownerDocument(), range->startContainer(), range->startOffset(),
171 range->endContainer(), range->endOffset()));
172 return staticRanges; 172 return staticRanges;
173 } 173 }
174 174
175 bool InputEvent::isInputEvent() const { 175 bool InputEvent::isInputEvent() const {
176 return true; 176 return true;
177 } 177 }
178 178
179 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and 179 // TODO(chongz): We should get rid of this |EventDispatchMediator| pattern and
180 // introduce simpler interface such as |beforeDispatchEvent()| and 180 // introduce simpler interface such as |beforeDispatchEvent()| and
181 // |afterDispatchEvent()| virtual methods. 181 // |afterDispatchEvent()| virtual methods.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // 3. We don't want authors to hold live |Range| indefinitely by holding 214 // 3. We don't want authors to hold live |Range| indefinitely by holding
215 // |InputEvent|, so we clear them after dispatch. 215 // |InputEvent|, so we clear them after dispatch.
216 // Authors should explicitly call |getTargetRanges()|->|toRange()| if they 216 // Authors should explicitly call |getTargetRanges()|->|toRange()| if they
217 // want to keep a copy of |Range|. See Editing TF meeting notes: 217 // 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 218 // https://docs.google.com/document/d/1hCj6QX77NYIVY0RWrMHT1Yra6t8_Qu8PopaWLG0 AM58/edit?usp=sharing
219 event().m_ranges.clear(); 219 event().m_ranges.clear();
220 return result; 220 return result;
221 } 221 }
222 222
223 } // namespace blink 223 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/events/InputEvent.h ('k') | third_party/WebKit/Source/core/events/InputEventInit.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698