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

Side by Side Diff: sky/engine/web/WebInputEventConversion.cpp

Issue 868133003: Remove touch events from Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/engine/web/WebInputEventConversion.h ('k') | sky/engine/web/WebSettingsImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/web/WebInputEventConversion.h" 32 #include "sky/engine/web/WebInputEventConversion.h"
33 33
34 #include "sky/engine/core/dom/Touch.h"
35 #include "sky/engine/core/dom/TouchList.h"
36 #include "sky/engine/core/events/GestureEvent.h" 34 #include "sky/engine/core/events/GestureEvent.h"
37 #include "sky/engine/core/events/KeyboardEvent.h" 35 #include "sky/engine/core/events/KeyboardEvent.h"
38 #include "sky/engine/core/events/TouchEvent.h"
39 #include "sky/engine/core/frame/FrameHost.h" 36 #include "sky/engine/core/frame/FrameHost.h"
40 #include "sky/engine/core/frame/FrameView.h" 37 #include "sky/engine/core/frame/FrameView.h"
41 #include "sky/engine/core/page/Page.h" 38 #include "sky/engine/core/page/Page.h"
42 #include "sky/engine/core/rendering/RenderObject.h" 39 #include "sky/engine/core/rendering/RenderObject.h"
43 #include "sky/engine/platform/KeyboardCodes.h" 40 #include "sky/engine/platform/KeyboardCodes.h"
44 #include "sky/engine/platform/Widget.h" 41 #include "sky/engine/platform/Widget.h"
45 42
46 namespace blink { 43 namespace blink {
47 44
48 static const double millisPerSecond = 1000.0; 45 static const double millisPerSecond = 1000.0;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 bool PlatformKeyboardEventBuilder::isCharacterKey() const 254 bool PlatformKeyboardEventBuilder::isCharacterKey() const
258 { 255 {
259 switch (windowsVirtualKeyCode()) { 256 switch (windowsVirtualKeyCode()) {
260 case VKEY_BACK: 257 case VKEY_BACK:
261 case VKEY_ESCAPE: 258 case VKEY_ESCAPE:
262 return false; 259 return false;
263 } 260 }
264 return true; 261 return true;
265 } 262 }
266 263
267 inline PlatformEvent::Type toPlatformTouchEventType(const WebInputEvent::Type ty pe)
268 {
269 switch (type) {
270 case WebInputEvent::TouchStart:
271 return PlatformEvent::TouchStart;
272 case WebInputEvent::TouchMove:
273 return PlatformEvent::TouchMove;
274 case WebInputEvent::TouchEnd:
275 return PlatformEvent::TouchEnd;
276 case WebInputEvent::TouchCancel:
277 return PlatformEvent::TouchCancel;
278 default:
279 ASSERT_NOT_REACHED();
280 }
281 return PlatformEvent::TouchStart;
282 }
283
284 inline PlatformTouchPoint::State toPlatformTouchPointState(const WebTouchPoint:: State state)
285 {
286 switch (state) {
287 case WebTouchPoint::StateReleased:
288 return PlatformTouchPoint::TouchReleased;
289 case WebTouchPoint::StatePressed:
290 return PlatformTouchPoint::TouchPressed;
291 case WebTouchPoint::StateMoved:
292 return PlatformTouchPoint::TouchMoved;
293 case WebTouchPoint::StateStationary:
294 return PlatformTouchPoint::TouchStationary;
295 case WebTouchPoint::StateCancelled:
296 return PlatformTouchPoint::TouchCancelled;
297 case WebTouchPoint::StateUndefined:
298 ASSERT_NOT_REACHED();
299 }
300 return PlatformTouchPoint::TouchReleased;
301 }
302
303 inline WebTouchPoint::State toWebTouchPointState(const AtomicString& type)
304 {
305 if (type == EventTypeNames::touchend)
306 return WebTouchPoint::StateReleased;
307 if (type == EventTypeNames::touchcancel)
308 return WebTouchPoint::StateCancelled;
309 if (type == EventTypeNames::touchstart)
310 return WebTouchPoint::StatePressed;
311 if (type == EventTypeNames::touchmove)
312 return WebTouchPoint::StateMoved;
313 return WebTouchPoint::StateUndefined;
314 }
315
316 PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo uchPoint& point)
317 {
318 float scale = 1.0f / widgetInputEventsScaleFactor(widget);
319 IntSize offset = widgetInputEventsOffset(widget);
320 m_id = point.id;
321 m_state = toPlatformTouchPointState(point.state);
322 FloatPoint pos = (point.position - offset).scaledBy(scale);
323 IntPoint flooredPoint = flooredIntPoint(pos);
324 // This assumes convertFromContainingView does only translations, not scales .
325 m_pos = widget->convertFromContainingView(flooredPoint) + (pos - flooredPoin t);
326 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y);
327 m_radius = FloatSize(point.radiusX, point.radiusY).scaledBy(scale);
328 m_rotationAngle = point.rotationAngle;
329 m_force = point.force;
330 }
331
332 PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo uchEvent& event)
333 {
334 m_type = toPlatformTouchEventType(event.type);
335
336 m_modifiers = 0;
337 if (event.modifiers & WebInputEvent::ShiftKey)
338 m_modifiers |= PlatformEvent::ShiftKey;
339 if (event.modifiers & WebInputEvent::ControlKey)
340 m_modifiers |= PlatformEvent::CtrlKey;
341 if (event.modifiers & WebInputEvent::AltKey)
342 m_modifiers |= PlatformEvent::AltKey;
343 if (event.modifiers & WebInputEvent::MetaKey)
344 m_modifiers |= PlatformEvent::MetaKey;
345
346 m_timestamp = event.timeStampSeconds;
347
348 for (unsigned i = 0; i < event.touchesLength; ++i)
349 m_touchPoints.append(PlatformTouchPointBuilder(widget, event.touches[i]) );
350
351 m_cancelable = event.cancelable;
352 }
353
354 static int getWebInputModifiers(const UIEventWithKeyState& event) 264 static int getWebInputModifiers(const UIEventWithKeyState& event)
355 { 265 {
356 int modifiers = 0; 266 int modifiers = 0;
357 if (event.ctrlKey()) 267 if (event.ctrlKey())
358 modifiers |= WebInputEvent::ControlKey; 268 modifiers |= WebInputEvent::ControlKey;
359 if (event.shiftKey()) 269 if (event.shiftKey())
360 modifiers |= WebInputEvent::ShiftKey; 270 modifiers |= WebInputEvent::ShiftKey;
361 if (event.altKey()) 271 if (event.altKey())
362 modifiers |= WebInputEvent::AltKey; 272 modifiers |= WebInputEvent::AltKey;
363 if (event.metaKey()) 273 if (event.metaKey())
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 nativeKeyCode = event.nativeVirtualKeyCode(); 362 nativeKeyCode = event.nativeVirtualKeyCode();
453 363
454 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() ); 364 windowsKeyCode = windowsKeyCodeWithoutLocation(event.windowsVirtualKeyCode() );
455 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ()); 365 modifiers |= locationModifiersFromWindowsKeyCode(event.windowsVirtualKeyCode ());
456 366
457 event.text().copyTo(text, 0, textLengthCap); 367 event.text().copyTo(text, 0, textLengthCap);
458 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap); 368 event.unmodifiedText().copyTo(unmodifiedText, 0, textLengthCap);
459 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length())); 369 memcpy(keyIdentifier, event.keyIdentifier().ascii().data(), std::min(static_ cast<unsigned>(keyIdentifierLengthCap), event.keyIdentifier().length()));
460 } 370 }
461 371
462 static void addTouchPoints(const Widget* widget, const AtomicString& touchType, TouchList* touches, WebTouchPoint* touchPoints, unsigned* touchPointsLength, con st RenderObject* renderObject)
463 {
464 unsigned numberOfTouches = std::min(touches->length(), static_cast<unsigned> (WebTouchEvent::touchesLengthCap));
465 for (unsigned i = 0; i < numberOfTouches; ++i) {
466 const Touch* touch = touches->item(i);
467
468 WebTouchPoint point;
469 point.id = touch->identifier();
470 point.screenPosition = touch->screenLocation();
471 point.position = convertAbsoluteLocationForRenderObjectFloat(touch->abso luteLocation(), *renderObject);
472 point.radiusX = touch->radiusX();
473 point.radiusY = touch->radiusY();
474 point.rotationAngle = touch->rotationAngle();
475 point.force = touch->force();
476 point.state = toWebTouchPointState(touchType);
477
478 touchPoints[i] = point;
479 }
480 *touchPointsLength = numberOfTouches;
481 }
482
483 WebTouchEventBuilder::WebTouchEventBuilder(const Widget* widget, const RenderObj ect* renderObject, const TouchEvent& event)
484 {
485 if (event.type() == EventTypeNames::touchstart)
486 type = TouchStart;
487 else if (event.type() == EventTypeNames::touchmove)
488 type = TouchMove;
489 else if (event.type() == EventTypeNames::touchend)
490 type = TouchEnd;
491 else if (event.type() == EventTypeNames::touchcancel)
492 type = TouchCancel;
493 else {
494 ASSERT_NOT_REACHED();
495 type = Undefined;
496 return;
497 }
498
499 modifiers = getWebInputModifiers(event);
500 timeStampSeconds = event.timeStamp() / millisPerSecond;
501 cancelable = event.cancelable();
502
503 addTouchPoints(widget, event.type(), event.touches(), touches, &touchesLengt h, renderObject);
504 addTouchPoints(widget, event.type(), event.changedTouches(), changedTouches, &changedTouchesLength, renderObject);
505 addTouchPoints(widget, event.type(), event.targetTouches(), targetTouches, & targetTouchesLength, renderObject);
506 }
507
508 WebGestureEventBuilder::WebGestureEventBuilder(const Widget* widget, const Rende rObject* renderObject, const GestureEvent& event) 372 WebGestureEventBuilder::WebGestureEventBuilder(const Widget* widget, const Rende rObject* renderObject, const GestureEvent& event)
509 { 373 {
510 if (event.type() == EventTypeNames::gestureshowpress) 374 if (event.type() == EventTypeNames::gestureshowpress)
511 type = GestureShowPress; 375 type = GestureShowPress;
512 else if (event.type() == EventTypeNames::gesturetapdown) 376 else if (event.type() == EventTypeNames::gesturetapdown)
513 type = GestureTapDown; 377 type = GestureTapDown;
514 else if (event.type() == EventTypeNames::gesturescrollstart) 378 else if (event.type() == EventTypeNames::gesturescrollstart)
515 type = GestureScrollBegin; 379 type = GestureScrollBegin;
516 else if (event.type() == EventTypeNames::gesturescrollend) 380 else if (event.type() == EventTypeNames::gesturescrollend)
517 type = GestureScrollEnd; 381 type = GestureScrollEnd;
(...skipping 10 matching lines...) Expand all
528 modifiers = getWebInputModifiers(event); 392 modifiers = getWebInputModifiers(event);
529 393
530 globalX = event.screenX(); 394 globalX = event.screenX();
531 globalY = event.screenY(); 395 globalY = event.screenY();
532 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject); 396 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject);
533 x = localPoint.x(); 397 x = localPoint.x();
534 y = localPoint.y(); 398 y = localPoint.y();
535 } 399 }
536 400
537 } // namespace blink 401 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/web/WebInputEventConversion.h ('k') | sky/engine/web/WebSettingsImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698