Chromium Code Reviews| 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 |
| 152 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, | 153 PP_TouchPoint PPB_InputEvent_Shared::GetTouchByIndex(PP_TouchListType list, |
| 153 uint32_t index) { | 154 uint32_t index) { |
| 154 std::vector<PP_TouchPoint>* points; | 155 std::vector<TouchPointWithTilt>* points; |
| 155 switch (list) { | 156 switch (list) { |
| 156 case PP_TOUCHLIST_TYPE_TOUCHES: | 157 case PP_TOUCHLIST_TYPE_TOUCHES: |
| 157 points = &data_.touches; | 158 points = &data_.touches; |
| 158 break; | 159 break; |
| 159 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 160 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: |
| 160 points = &data_.changed_touches; | 161 points = &data_.changed_touches; |
| 161 break; | 162 break; |
| 162 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 163 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: |
| 163 points = &data_.target_touches; | 164 points = &data_.target_touches; |
| 164 break; | 165 break; |
| 165 default: | 166 default: |
| 166 return PP_MakeTouchPoint(); | 167 return PP_MakeTouchPoint(); |
| 167 } | 168 } |
|
bbudge
2017/05/19 22:52:47
This switch is now replicated 4 times. Perhaps a h
jkwang
2017/05/23 04:07:45
Done.
| |
| 168 if (index >= points->size()) { | 169 if (index >= points->size()) { |
| 169 return PP_MakeTouchPoint(); | 170 return PP_MakeTouchPoint(); |
| 170 } | 171 } |
| 171 return points->at(index); | 172 return points->at(index).touch; |
| 172 } | 173 } |
| 173 | 174 |
| 174 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, | 175 PP_TouchPoint PPB_InputEvent_Shared::GetTouchById(PP_TouchListType list, |
| 175 uint32_t id) { | 176 uint32_t id) { |
| 176 const std::vector<PP_TouchPoint>* points; | 177 const std::vector<TouchPointWithTilt>* points; |
| 177 switch (list) { | 178 switch (list) { |
| 178 case PP_TOUCHLIST_TYPE_TOUCHES: | 179 case PP_TOUCHLIST_TYPE_TOUCHES: |
| 179 points = &data_.touches; | 180 points = &data_.touches; |
| 180 break; | 181 break; |
| 181 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | 182 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: |
| 182 points = &data_.changed_touches; | 183 points = &data_.changed_touches; |
| 183 break; | 184 break; |
| 184 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | 185 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: |
| 185 points = &data_.target_touches; | 186 points = &data_.target_touches; |
| 186 break; | 187 break; |
| 187 default: | 188 default: |
| 188 return PP_MakeTouchPoint(); | 189 return PP_MakeTouchPoint(); |
| 189 } | 190 } |
| 190 for (size_t i = 0; i < points->size(); i++) { | 191 for (size_t i = 0; i < points->size(); i++) { |
| 191 if (points->at(i).id == id) | 192 if (points->at(i).touch.id == id) |
| 192 return points->at(i); | 193 return points->at(i).touch; |
| 193 } | 194 } |
| 194 return PP_MakeTouchPoint(); | 195 return PP_MakeTouchPoint(); |
| 195 } | 196 } |
| 196 | 197 |
| 198 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltByIndex(PP_TouchListType list, | |
| 199 uint32_t index) { | |
| 200 std::vector<TouchPointWithTilt>* points; | |
| 201 switch (list) { | |
| 202 case PP_TOUCHLIST_TYPE_TOUCHES: | |
| 203 points = &data_.touches; | |
| 204 break; | |
| 205 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | |
| 206 points = &data_.changed_touches; | |
| 207 break; | |
| 208 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | |
| 209 points = &data_.target_touches; | |
| 210 break; | |
| 211 default: | |
| 212 return PP_MakeFloatPoint(0, 0); | |
| 213 } | |
| 214 if (index >= points->size()) { | |
| 215 return PP_MakeFloatPoint(0, 0); | |
| 216 } | |
| 217 return points->at(index).tilt; | |
| 218 } | |
| 219 | |
| 220 PP_FloatPoint PPB_InputEvent_Shared::GetTouchTiltById(PP_TouchListType list, | |
| 221 uint32_t id) { | |
| 222 const std::vector<TouchPointWithTilt>* points; | |
| 223 switch (list) { | |
| 224 case PP_TOUCHLIST_TYPE_TOUCHES: | |
| 225 points = &data_.touches; | |
| 226 break; | |
| 227 case PP_TOUCHLIST_TYPE_CHANGEDTOUCHES: | |
| 228 points = &data_.changed_touches; | |
| 229 break; | |
| 230 case PP_TOUCHLIST_TYPE_TARGETTOUCHES: | |
| 231 points = &data_.target_touches; | |
| 232 break; | |
| 233 default: | |
| 234 return PP_MakeFloatPoint(0, 0); | |
| 235 } | |
| 236 for (size_t i = 0; i < points->size(); i++) { | |
| 237 if (points->at(i).touch.id == id) | |
| 238 return points->at(i).tilt; | |
| 239 } | |
| 240 return PP_MakeFloatPoint(0, 0); | |
| 241 } | |
| 242 | |
| 197 // static | 243 // static |
| 198 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( | 244 PP_Resource PPB_InputEvent_Shared::CreateIMEInputEvent( |
| 199 ResourceObjectType type, | 245 ResourceObjectType type, |
| 200 PP_Instance instance, | 246 PP_Instance instance, |
| 201 PP_InputEvent_Type event_type, | 247 PP_InputEvent_Type event_type, |
| 202 PP_TimeTicks time_stamp, | 248 PP_TimeTicks time_stamp, |
| 203 struct PP_Var text, | 249 struct PP_Var text, |
| 204 uint32_t segment_number, | 250 uint32_t segment_number, |
| 205 const uint32_t* segment_offsets, | 251 const uint32_t* segment_offsets, |
| 206 int32_t target_segment, | 252 int32_t target_segment, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 return 0; | 379 return 0; |
| 334 | 380 |
| 335 InputEventData data; | 381 InputEventData data; |
| 336 data.event_type = event_type; | 382 data.event_type = event_type; |
| 337 data.event_time_stamp = time_stamp; | 383 data.event_time_stamp = time_stamp; |
| 338 data.event_modifiers = modifiers; | 384 data.event_modifiers = modifiers; |
| 339 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); | 385 return (new PPB_InputEvent_Shared(type, instance, data))->GetReference(); |
| 340 } | 386 } |
| 341 | 387 |
| 342 } // namespace ppapi | 388 } // namespace ppapi |
| OLD | NEW |