OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ppapi/shared_impl/ppb_input_event_shared.h" | 5 #include "ppapi/shared_impl/ppb_input_event_shared.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
10 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 114 |
115 void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) { | 115 void PPB_InputEvent_Shared::GetIMESelection(uint32_t* start, uint32_t* end) { |
116 if (start) | 116 if (start) |
117 *start = data_.composition_selection_start; | 117 *start = data_.composition_selection_start; |
118 if (end) | 118 if (end) |
119 *end = data_.composition_selection_end; | 119 *end = data_.composition_selection_end; |
120 } | 120 } |
121 | 121 |
122 void PPB_InputEvent_Shared::AddTouchPoint(PP_TouchListType list, | 122 void PPB_InputEvent_Shared::AddTouchPoint(PP_TouchListType list, |
123 const PP_TouchPoint& point) { | 123 const PP_TouchPoint& point) { |
124 TouchPointWithTilt point_with_tilt{point, {0, 0}}; | |
124 switch (list) { | 125 switch (list) { |
125 case PP_TOUCHLIST_TYPE_TOUCHES: | 126 case PP_TOUCHLIST_TYPE_TOUCHES: |
126 data_.touches.push_back(point); | 127 data_.touches.push_back(point_with_tilt); |
127 break; | 128 break; |
128 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 129 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: |
129 data_.changed_touches.push_back(point); | 130 data_.changed_touches.push_back(point_with_tilt); |
130 break; | 131 break; |
131 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 132 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: |
132 data_.target_touches.push_back(point); | 133 data_.target_touches.push_back(point_with_tilt); |
133 break; | 134 break; |
134 default: | 135 default: |
135 break; | 136 break; |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 uint32_t PPB_InputEvent_Shared::GetTouchCount(PP_TouchListType list) { | 140 uint32_t PPB_InputEvent_Shared::GetTouchCount(PP_TouchListType list) { |
140 switch (list) { | 141 switch (list) { |
141 case PP_TOUCHLIST_TYPE_TOUCHES: | 142 case PP_TOUCHLIST_TYPE_TOUCHES: |
142 return static_cast<uint32_t>(data_.touches.size()); | 143 return static_cast<uint32_t>(data_.touches.size()); |
143 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 144 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: |
144 return static_cast<uint32_t>(data_.changed_touches.size()); | 145 return static_cast<uint32_t>(data_.changed_touches.size()); |
145 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 146 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: |
146 return static_cast<uint32_t>(data_.target_touches.size()); | 147 return static_cast<uint32_t>(data_.target_touches.size()); |
147 } | 148 } |
148 | 149 |
149 return 0; | 150 return 0; |
150 } | 151 } |
151 | 152 |
153 std::vector<TouchPointWithTilt>* PPB_InputEvent_Shared::GetTouchListByType( | |
154 PP_TouchListType list) { | |
155 switch (list) { | |
156 case PP_TOUCHLIST_TYPE_TOUCHES: | |
157 return &data_.touches; | |
158 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | |
159 return &data_.changed_touches; | |
160 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | |
161 return &data_.target_touches; | |
162 default: | |
dcheng
2017/05/25 21:55:02
Nit: remove default, move return nullptr to outsid
| |
163 return nullptr; | |
164 } | |
165 } | |
166 | |
167 TouchPointWithTilt* PPB_InputEvent_Shared::GetTouchByTypeAndId( | |
168 PP_TouchListType list, | |
169 uint32_t id) { | |
170 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); | |
171 if (!points) | |
172 return nullptr; | |
173 | |
174 for (size_t i = 0; i < points->size(); i++) { | |
175 if (points->at(i).touch.id == id) | |
176 return &points->at(i); | |
177 } | |
178 | |
179 return nullptr; | |
180 } | |
181 | |
152 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, | 182 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, |
153 uint32_t index) { | 183 uint32_t index) { |
154 std::vector<PP_TouchPoint>* points; | 184 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); |
155 switch (list) { | 185 |
156 case PP_TOUCHLIST_TYPE_TOUCHES: | 186 if (!points || index >= points->size()) { |
157 points = &data_.touches; | |
158 break; | |
159 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | |
160 points = &data_.changed_touches; | |
161 break; | |
162 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | |
163 points = &data_.target_touches; | |
164 break; | |
165 default: | |
166 return PP_MakeTouchPoint(); | |
167 } | |
168 if (index >= points->size()) { | |
169 return PP_MakeTouchPoint(); | 187 return PP_MakeTouchPoint(); |
170 } | 188 } |
171 return points->at(index); | 189 return points->at(index).touch; |
172 } | 190 } |
173 | 191 |
174 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, | 192 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, |
175 uint32_t id) { | 193 uint32_t id) { |
176 const std::vector<PP_TouchPoint>* points; | 194 TouchPointWithTilt* point = GetTouchByTypeAndId(list, id); |
177 switch (list) { | 195 if (!point) |
178 case PP_TOUCHLIST_TYPE_TOUCHES: | 196 return PP_MakeTouchPoint(); |
179 points = &data_.touches; | 197 |
180 break; | 198 return point->touch; |
181 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 199 } |
182 points = &data_.changed_touches; | 200 |
183 break; | 201 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltByIndex(PP_TouchListType list, |
184 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 202 uint32_t index) { |
185 points = &data_.target_touches; | 203 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); |
186 break; | 204 |
187 default: | 205 if (!points || index >= points->size()) { |
dcheng
2017/05/25 21:55:02
Super minor nit: be consistent with { }'s around o
| |
188 return PP_MakeTouchPoint(); | 206 return PP_MakeFloatPoint(0, 0); |
189 } | 207 } |
190 for (size_t i = 0; i < points->size(); i++) { | 208 return points->at(index).tilt; |
191 if (points->at(i).id == id) | 209 } |
192 return points->at(i); | 210 |
193 } | 211 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltById(PP_TouchListType list, |
194 return PP_MakeTouchPoint(); | 212 uint32_t id) { |
213 TouchPointWithTilt* point = GetTouchByTypeAndId(list, id); | |
214 if (!point) | |
215 return PP_MakeFloatPoint(0, 0); | |
216 | |
217 return point->tilt; | |
195 } | 218 } |
196 | 219 |
197 // static | 220 // static |
198 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( | 221 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( |
199 ResourceObjectType type, | 222 ResourceObjectType type, |
200 PP_Instance instance, | 223 PP_Instance instance, |
201 PP_InputEvent_Type event_type, | 224 PP_InputEvent_Type event_type, |
202 PP_TimeTicks time_stamp, | 225 PP_TimeTicks time_stamp, |
203 struct PP_Var text, | 226 struct PP_Var text, |
204 uint32_t segment_number, | 227 uint32_t segment_number, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 return 0; | 356 return 0; |
334 | 357 |
335 InputEventData data; | 358 InputEventData data; |
336 data.event_type = event_type; | 359 data.event_type = event_type; |
337 data.event_time_stamp = time_stamp; | 360 data.event_time_stamp = time_stamp; |
338 data.event_modifiers = modifiers; | 361 data.event_modifiers = modifiers; |
339 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); | 362 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
340 } | 363 } |
341 | 364 |
342 } // namespace ppapi | 365 } // namespace ppapi |
OLD | NEW |