Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/input/web_input_event_util.h" | 5 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 9 | |
| 10 using blink::WebInputEvent; | |
| 11 using blink::WebGestureEvent; | |
| 9 | 12 |
| 10 namespace { | 13 namespace { |
| 11 | 14 |
| 12 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { | 15 const char* GetKeyIdentifier(ui::KeyboardCode key_code) { |
| 13 switch (key_code) { | 16 switch (key_code) { |
| 14 case ui::VKEY_MENU: | 17 case ui::VKEY_MENU: |
| 15 return "Alt"; | 18 return "Alt"; |
| 16 case ui::VKEY_CONTROL: | 19 case ui::VKEY_CONTROL: |
| 17 return "Control"; | 20 return "Control"; |
| 18 case ui::VKEY_SHIFT: | 21 case ui::VKEY_SHIFT: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 138 |
| 136 const char* id = GetKeyIdentifier(windows_key_code); | 139 const char* id = GetKeyIdentifier(windows_key_code); |
| 137 if (id) { | 140 if (id) { |
| 138 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); | 141 base::strlcpy(event->keyIdentifier, id, sizeof(event->keyIdentifier) - 1); |
| 139 } else { | 142 } else { |
| 140 base::snprintf(event->keyIdentifier, sizeof(event->keyIdentifier), "U+%04X", | 143 base::snprintf(event->keyIdentifier, sizeof(event->keyIdentifier), "U+%04X", |
| 141 base::ToUpperASCII(static_cast<int>(windows_key_code))); | 144 base::ToUpperASCII(static_cast<int>(windows_key_code))); |
| 142 } | 145 } |
| 143 } | 146 } |
| 144 | 147 |
| 148 WebGestureEvent CreateWebGestureEventFromGestureEventData( | |
|
tdresser
2014/03/03 19:44:32
The type conversion could be factored out of here
jdduke (slow)
2014/03/03 22:33:17
See above. In general I agree, but that file is o
tdresser
2014/03/04 13:48:35
A new file in events_base which contains some of c
jdduke (slow)
2014/03/04 15:50:14
Hmm, GestureEventData only exists in gesture_detec
tdresser
2014/03/04 16:32:14
If we thought it was worthwhile, we could at least
| |
| 149 const ui::GestureEventData& data, | |
| 150 float scale) { | |
| 151 WebGestureEvent gesture; | |
| 152 gesture.x = data.x * scale; | |
| 153 gesture.y = data.y * scale; | |
| 154 gesture.timeStampSeconds = (data.time - base::TimeTicks()).InSecondsF(); | |
| 155 gesture.sourceDevice = WebGestureEvent::Touchscreen; | |
| 156 | |
| 157 switch (data.type) { | |
| 158 case ui::GESTURE_SHOW_PRESS: | |
| 159 gesture.type = WebInputEvent::GestureShowPress; | |
| 160 gesture.data.showPress.width = data.details.show_press.width * scale; | |
| 161 gesture.data.showPress.width = data.details.show_press.width * scale; | |
| 162 break; | |
| 163 case ui::GESTURE_DOUBLE_TAP: | |
| 164 gesture.type = WebInputEvent::GestureDoubleTap; | |
| 165 break; | |
| 166 case ui::GESTURE_TAP: | |
| 167 gesture.type = WebInputEvent::GestureTap; | |
| 168 gesture.data.tap.tapCount = data.details.tap.tap_count; | |
| 169 gesture.data.tap.width = data.details.tap.width * scale; | |
| 170 gesture.data.tap.height = data.details.tap.height * scale; | |
| 171 break; | |
| 172 case ui::GESTURE_TAP_UNCONFIRMED: | |
| 173 gesture.type = WebInputEvent::GestureTapUnconfirmed; | |
| 174 gesture.data.tap.tapCount = data.details.tap.tap_count; | |
| 175 gesture.data.tap.width = data.details.tap.width * scale; | |
| 176 gesture.data.tap.height = data.details.tap.height * scale; | |
| 177 break; | |
| 178 case ui::GESTURE_LONG_PRESS: | |
| 179 gesture.type = WebInputEvent::GestureLongPress; | |
| 180 gesture.data.longPress.width = data.details.long_press.width * scale; | |
| 181 gesture.data.longPress.height = data.details.long_press.height * scale; | |
| 182 break; | |
| 183 case ui::GESTURE_LONG_TAP: | |
| 184 gesture.type = WebInputEvent::GestureLongTap; | |
| 185 gesture.data.longPress.width = data.details.long_press.width * scale; | |
| 186 gesture.data.longPress.height = data.details.long_press.height * scale; | |
| 187 break; | |
| 188 case ui::GESTURE_SCROLL_BEGIN: | |
| 189 gesture.type = WebInputEvent::GestureScrollBegin; | |
| 190 gesture.data.scrollBegin.deltaXHint = | |
| 191 data.details.scroll_begin.delta_x_hint * scale; | |
| 192 gesture.data.scrollBegin.deltaYHint = | |
| 193 data.details.scroll_begin.delta_y_hint * scale; | |
| 194 break; | |
| 195 case ui::GESTURE_SCROLL_UPDATE: | |
| 196 gesture.type = WebInputEvent::GestureScrollUpdate; | |
| 197 gesture.data.scrollUpdate.deltaX = | |
| 198 data.details.scroll_update.delta_x * scale; | |
| 199 gesture.data.scrollUpdate.deltaY = | |
| 200 data.details.scroll_update.delta_y * scale; | |
| 201 gesture.data.scrollUpdate.velocityX = | |
| 202 data.details.scroll_update.velocity_x * scale; | |
| 203 gesture.data.scrollUpdate.velocityY = | |
| 204 data.details.scroll_update.velocity_y * scale; | |
| 205 break; | |
| 206 case ui::GESTURE_SCROLL_END: | |
| 207 gesture.type = WebInputEvent::GestureScrollEnd; | |
| 208 break; | |
| 209 case ui::GESTURE_FLING_START: | |
| 210 gesture.type = WebInputEvent::GestureFlingStart; | |
| 211 gesture.data.flingStart.velocityX = | |
| 212 data.details.fling_start.velocity_x * scale; | |
| 213 gesture.data.flingStart.velocityY = | |
| 214 data.details.fling_start.velocity_y * scale; | |
| 215 break; | |
| 216 case ui::GESTURE_FLING_CANCEL: | |
| 217 gesture.type = WebInputEvent::GestureFlingCancel; | |
| 218 break; | |
| 219 case ui::GESTURE_PINCH_BEGIN: | |
| 220 gesture.type = WebInputEvent::GesturePinchBegin; | |
| 221 break; | |
| 222 case ui::GESTURE_PINCH_UPDATE: | |
| 223 gesture.type = WebInputEvent::GesturePinchUpdate; | |
| 224 gesture.data.pinchUpdate.scale = data.details.pinch_update.scale; | |
| 225 break; | |
| 226 case ui::GESTURE_PINCH_END: | |
| 227 gesture.type = WebInputEvent::GesturePinchEnd; | |
| 228 break; | |
| 229 case ui::GESTURE_TAP_CANCEL: | |
| 230 gesture.type = WebInputEvent::GestureTapCancel; | |
| 231 break; | |
| 232 case ui::GESTURE_TAP_DOWN: | |
| 233 gesture.type = WebInputEvent::GestureTapDown; | |
| 234 gesture.data.tapDown.width = data.details.tap_down.width * scale; | |
| 235 gesture.data.tapDown.height = data.details.tap_down.height * scale; | |
| 236 break; | |
| 237 case ui::GESTURE_TYPE_INVALID: | |
| 238 NOTREACHED() << "Invalid ui::GestureEventType provided."; | |
| 239 break; | |
| 240 } | |
| 241 | |
| 242 return gesture; | |
| 243 } | |
| 244 | |
| 145 } // namespace content | 245 } // namespace content |
| OLD | NEW |