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 } |
| 163 return nullptr; |
| 164 } |
| 165 |
| 166 TouchPointWithTilt* PPB_InputEvent_Shared::GetTouchByTypeAndId( |
| 167 PP_TouchListType list, |
| 168 uint32_t id) { |
| 169 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); |
| 170 if (!points) |
| 171 return nullptr; |
| 172 |
| 173 for (size_t i = 0; i < points->size(); i++) { |
| 174 if (points->at(i).touch.id == id) |
| 175 return &points->at(i); |
| 176 } |
| 177 |
| 178 return nullptr; |
| 179 } |
| 180 |
152 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, | 181 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, |
153 uint32_t index) { | 182 uint32_t index) { |
154 std::vector<PP_TouchPoint>* points; | 183 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); |
155 switch (list) { | 184 |
156 case PP_TOUCHLIST_TYPE_TOUCHES: | 185 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(); | 186 return PP_MakeTouchPoint(); |
170 } | 187 } |
171 return points->at(index); | 188 return points->at(index).touch; |
172 } | 189 } |
173 | 190 |
174 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, | 191 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, |
175 uint32_t id) { | 192 uint32_t id) { |
176 const std::vector<PP_TouchPoint>* points; | 193 TouchPointWithTilt* point = GetTouchByTypeAndId(list, id); |
177 switch (list) { | 194 if (!point) |
178 case PP_TOUCHLIST_TYPE_TOUCHES: | 195 return PP_MakeTouchPoint(); |
179 points = &data_.touches; | 196 |
180 break; | 197 return point->touch; |
181 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 198 } |
182 points = &data_.changed_touches; | 199 |
183 break; | 200 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltByIndex(PP_TouchListType list, |
184 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 201 uint32_t index) { |
185 points = &data_.target_touches; | 202 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list); |
186 break; | 203 |
187 default: | 204 if (!points || index >= points->size()) |
188 return PP_MakeTouchPoint(); | 205 return PP_MakeFloatPoint(0, 0); |
189 } | 206 |
190 for (size_t i = 0; i < points->size(); i++) { | 207 return points->at(index).tilt; |
191 if (points->at(i).id == id) | 208 } |
192 return points->at(i); | 209 |
193 } | 210 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltById(PP_TouchListType list, |
194 return PP_MakeTouchPoint(); | 211 uint32_t id) { |
| 212 TouchPointWithTilt* point = GetTouchByTypeAndId(list, id); |
| 213 if (!point) |
| 214 return PP_MakeFloatPoint(0, 0); |
| 215 |
| 216 return point->tilt; |
195 } | 217 } |
196 | 218 |
197 // static | 219 // static |
198 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( | 220 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( |
199 ResourceObjectType type, | 221 ResourceObjectType type, |
200 PP_Instance instance, | 222 PP_Instance instance, |
201 PP_InputEvent_Type event_type, | 223 PP_InputEvent_Type event_type, |
202 PP_TimeTicks time_stamp, | 224 PP_TimeTicks time_stamp, |
203 struct PP_Var text, | 225 struct PP_Var text, |
204 uint32_t segment_number, | 226 uint32_t segment_number, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 return 0; | 355 return 0; |
334 | 356 |
335 InputEventData data; | 357 InputEventData data; |
336 data.event_type = event_type; | 358 data.event_type = event_type; |
337 data.event_time_stamp = time_stamp; | 359 data.event_time_stamp = time_stamp; |
338 data.event_modifiers = modifiers; | 360 data.event_modifiers = modifiers; |
339 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); | 361 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
340 } | 362 } |
341 | 363 |
342 } // namespace ppapi | 364 } // namespace ppapi |
OLD | NEW |