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

Side by Side Diff: ppapi/shared_impl/ppb_input_event_shared.cc

Issue 2890323002: Add tilt_x and tilt_y to ppapi touchpoint. (Closed)
Patch Set: Add tilt_x and tilt_y to ppapi touchpoint. Created 3 years, 7 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 (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
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 break;
bbudge 2017/05/23 18:28:47 breaks are unreachable, remove.
jkwang 2017/05/23 22:07:57 Done.
159 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
160 return &data_.changed_touches;
161 break;
162 case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
163 return &data_.target_touches;
164 break;
165 default:
166 return nullptr;
167 }
168 }
169
152 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, 170 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list,
153 uint32_t index) { 171 uint32_t index) {
154 std::vector<PP_TouchPoint>* points; 172 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list);
155 switch (list) { 173
156 case PP_TOUCHLIST_TYPE_TOUCHES: 174 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(); 175 return PP_MakeTouchPoint();
170 } 176 }
171 return points->at(index); 177 return points->at(index).touch;
172 } 178 }
173 179
174 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, 180 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list,
175 uint32_t id) { 181 uint32_t id) {
176 const std::vector<PP_TouchPoint>* points; 182 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list);
177 switch (list) { 183
178 case PP_TOUCHLIST_TYPE_TOUCHES: 184 if (!points)
179 points = &data_.touches; 185 return PP_MakeTouchPoint();
180 break; 186
181 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES:
182 points = &data_.changed_touches;
183 break;
184 case PP_TOUCHLIST_TYPE_TARGETTOUCHES:
185 points = &data_.target_touches;
186 break;
187 default:
188 return PP_MakeTouchPoint();
189 }
190 for (size_t i = 0; i < points->size(); i++) { 187 for (size_t i = 0; i < points->size(); i++) {
191 if (points->at(i).id == id) 188 if (points->at(i).touch.id == id)
192 return points->at(i); 189 return points->at(i).touch;
193 } 190 }
bbudge 2017/05/23 18:28:47 You could further reduce duplication by adding ano
jkwang 2017/05/23 22:07:57 Done.
194 return PP_MakeTouchPoint(); 191 return PP_MakeTouchPoint();
bbudge 2017/05/23 18:28:46 Then this function body would be just: return Get
jkwang 2017/05/23 22:07:57 Done.
195 } 192 }
196 193
194 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltByIndex(PP_TouchListType list,
195 uint32_t index) {
196 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list);
197
198 if (!points || index >= points->size()) {
199 return PP_MakeFloatPoint(0, 0);
200 }
201 return points->at(index).tilt;
202 }
203
204 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltById(PP_TouchListType list,
205 uint32_t id) {
206 std::vector<TouchPointWithTilt>* points = GetTouchListByType(list);
207
208 if (!points)
209 return PP_MakeFloatPoint(0, 0);
210
211 for (size_t i = 0; i < points->size(); i++) {
212 if (points->at(i).touch.id == id)
213 return points->at(i).tilt;
214 }
215 return PP_MakeFloatPoint(0, 0);
216 }
217
197 // static 218 // static
198 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( 219 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent(
199 ResourceObjectType type, 220 ResourceObjectType type,
200 PP_Instance instance, 221 PP_Instance instance,
201 PP_InputEvent_Type event_type, 222 PP_InputEvent_Type event_type,
202 PP_TimeTicks time_stamp, 223 PP_TimeTicks time_stamp,
203 struct PP_Var text, 224 struct PP_Var text,
204 uint32_t segment_number, 225 uint32_t segment_number,
205 const uint32_t* segment_offsets, 226 const uint32_t* segment_offsets,
206 int32_t target_segment, 227 int32_t target_segment,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return 0; 354 return 0;
334 355
335 InputEventData data; 356 InputEventData data;
336 data.event_type = event_type; 357 data.event_type = event_type;
337 data.event_time_stamp = time_stamp; 358 data.event_time_stamp = time_stamp;
338 data.event_modifiers = modifiers; 359 data.event_modifiers = modifiers;
339 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); 360 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference();
340 } 361 }
341 362
342 } // namespace ppapi 363 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698