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

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

Issue 870073003: Remove mouse 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
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 17 matching lines...) Expand all
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" 34 #include "sky/engine/core/dom/Touch.h"
35 #include "sky/engine/core/dom/TouchList.h" 35 #include "sky/engine/core/dom/TouchList.h"
36 #include "sky/engine/core/events/GestureEvent.h" 36 #include "sky/engine/core/events/GestureEvent.h"
37 #include "sky/engine/core/events/KeyboardEvent.h" 37 #include "sky/engine/core/events/KeyboardEvent.h"
38 #include "sky/engine/core/events/MouseEvent.h"
39 #include "sky/engine/core/events/TouchEvent.h" 38 #include "sky/engine/core/events/TouchEvent.h"
40 #include "sky/engine/core/events/WheelEvent.h"
41 #include "sky/engine/core/frame/FrameHost.h" 39 #include "sky/engine/core/frame/FrameHost.h"
42 #include "sky/engine/core/frame/FrameView.h" 40 #include "sky/engine/core/frame/FrameView.h"
43 #include "sky/engine/core/page/Page.h" 41 #include "sky/engine/core/page/Page.h"
44 #include "sky/engine/core/rendering/RenderObject.h" 42 #include "sky/engine/core/rendering/RenderObject.h"
45 #include "sky/engine/platform/KeyboardCodes.h" 43 #include "sky/engine/platform/KeyboardCodes.h"
46 #include "sky/engine/platform/Widget.h" 44 #include "sky/engine/platform/Widget.h"
47 45
48 namespace blink { 46 namespace blink {
49 47
50 static const double millisPerSecond = 1000.0; 48 static const double millisPerSecond = 1000.0;
(...skipping 14 matching lines...) Expand all
65 { 63 {
66 if (!widget) 64 if (!widget)
67 return IntSize(); 65 return IntSize();
68 FrameView* rootView = toFrameView(widget->root()); 66 FrameView* rootView = toFrameView(widget->root());
69 if (!rootView) 67 if (!rootView)
70 return IntSize(); 68 return IntSize();
71 69
72 return rootView->inputEventsOffsetForEmulation(); 70 return rootView->inputEventsOffsetForEmulation();
73 } 71 }
74 72
75 // MakePlatformMouseEvent -----------------------------------------------------
76
77 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo useEvent& e)
78 {
79 float scale = widgetInputEventsScaleFactor(widget);
80 IntSize offset = widgetInputEventsOffset(widget);
81
82 // FIXME: Widget is always toplevel, unless it's a popup. We may be able
83 // to get rid of this once we abstract popups into a WebKit API.
84 m_position = widget->convertFromContainingView(
85 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale ));
86 m_globalPosition = IntPoint(e.globalX, e.globalY);
87 m_movementDelta = IntPoint(e.movementX / scale, e.movementY / scale);
88 m_button = static_cast<MouseButton>(e.button);
89
90 m_modifiers = 0;
91 if (e.modifiers & WebInputEvent::ShiftKey)
92 m_modifiers |= PlatformEvent::ShiftKey;
93 if (e.modifiers & WebInputEvent::ControlKey)
94 m_modifiers |= PlatformEvent::CtrlKey;
95 if (e.modifiers & WebInputEvent::AltKey)
96 m_modifiers |= PlatformEvent::AltKey;
97 if (e.modifiers & WebInputEvent::MetaKey)
98 m_modifiers |= PlatformEvent::MetaKey;
99
100 m_modifierFlags = e.modifiers;
101 m_timestamp = e.timeStampSeconds;
102 m_clickCount = e.clickCount;
103
104 switch (e.type) {
105 case WebInputEvent::MouseMove:
106 case WebInputEvent::MouseLeave: // synthesize a move event
107 m_type = PlatformEvent::MouseMoved;
108 break;
109
110 case WebInputEvent::MouseDown:
111 m_type = PlatformEvent::MousePressed;
112 break;
113
114 case WebInputEvent::MouseUp:
115 m_type = PlatformEvent::MouseReleased;
116 break;
117
118 default:
119 ASSERT_NOT_REACHED();
120 }
121 }
122
123 // PlatformWheelEventBuilder --------------------------------------------------
124
125 PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo useWheelEvent& e)
126 {
127 float scale = widgetInputEventsScaleFactor(widget);
128 IntSize offset = widgetInputEventsOffset(widget);
129
130 m_position = widget->convertFromContainingView(
131 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale ));
132 m_globalPosition = IntPoint(e.globalX, e.globalY);
133 m_deltaX = e.deltaX;
134 m_deltaY = e.deltaY;
135 m_wheelTicksX = e.wheelTicksX;
136 m_wheelTicksY = e.wheelTicksY;
137 m_granularity = e.scrollByPage ?
138 ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
139
140 m_type = PlatformEvent::Wheel;
141
142 m_modifiers = 0;
143 if (e.modifiers & WebInputEvent::ShiftKey)
144 m_modifiers |= PlatformEvent::ShiftKey;
145 if (e.modifiers & WebInputEvent::ControlKey)
146 m_modifiers |= PlatformEvent::CtrlKey;
147 if (e.modifiers & WebInputEvent::AltKey)
148 m_modifiers |= PlatformEvent::AltKey;
149 if (e.modifiers & WebInputEvent::MetaKey)
150 m_modifiers |= PlatformEvent::MetaKey;
151
152 m_hasPreciseScrollingDeltas = e.hasPreciseScrollingDeltas;
153 }
154 73
155 // PlatformGestureEventBuilder ------------------------------------------------- - 74 // PlatformGestureEventBuilder ------------------------------------------------- -
156 75
157 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W ebGestureEvent& e) 76 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W ebGestureEvent& e)
158 { 77 {
159 float scale = widgetInputEventsScaleFactor(widget); 78 float scale = widgetInputEventsScaleFactor(widget);
160 IntSize offset = widgetInputEventsOffset(widget); 79 IntSize offset = widgetInputEventsOffset(widget);
161 80
162 switch (e.type) { 81 switch (e.type) {
163 case WebInputEvent::GestureScrollBegin: 82 case WebInputEvent::GestureScrollBegin:
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 static FloatPoint convertAbsoluteLocationForRenderObjectFloat(const LayoutPoint& location, const RenderObject& renderObject) 368 static FloatPoint convertAbsoluteLocationForRenderObjectFloat(const LayoutPoint& location, const RenderObject& renderObject)
450 { 369 {
451 return renderObject.absoluteToLocal(location, UseTransforms); 370 return renderObject.absoluteToLocal(location, UseTransforms);
452 } 371 }
453 372
454 static IntPoint convertAbsoluteLocationForRenderObject(const LayoutPoint& locati on, const RenderObject& renderObject) 373 static IntPoint convertAbsoluteLocationForRenderObject(const LayoutPoint& locati on, const RenderObject& renderObject)
455 { 374 {
456 return roundedIntPoint(convertAbsoluteLocationForRenderObjectFloat(location, renderObject)); 375 return roundedIntPoint(convertAbsoluteLocationForRenderObjectFloat(location, renderObject));
457 } 376 }
458 377
459 static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event , const Widget& widget, const RenderObject& renderObject, WebMouseEvent& webEven t)
460 {
461 webEvent.timeStampSeconds = event.timeStamp() / millisPerSecond;
462 webEvent.modifiers = getWebInputModifiers(event);
463
464 IntPoint windowPoint = IntPoint(event.absoluteLocation().x(), event.absolute Location().y());
465 windowPoint = widget.convertToContainingView(windowPoint);
466 webEvent.globalX = event.screenX();
467 webEvent.globalY = event.screenY();
468 webEvent.windowX = windowPoint.x();
469 webEvent.windowY = windowPoint.y();
470 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), renderObject);
471 webEvent.x = localPoint.x();
472 webEvent.y = localPoint.y();
473 }
474
475 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const RenderObj ect* renderObject, const MouseEvent& event)
476 {
477 if (event.type() == EventTypeNames::mousemove)
478 type = WebInputEvent::MouseMove;
479 else if (event.type() == EventTypeNames::mouseout)
480 type = WebInputEvent::MouseLeave;
481 else if (event.type() == EventTypeNames::mouseover)
482 type = WebInputEvent::MouseEnter;
483 else if (event.type() == EventTypeNames::mousedown)
484 type = WebInputEvent::MouseDown;
485 else if (event.type() == EventTypeNames::mouseup)
486 type = WebInputEvent::MouseUp;
487 else
488 return; // Skip all other mouse events.
489
490 updateWebMouseEventFromCoreMouseEvent(event, *widget, *renderObject, *this);
491
492 switch (event.button()) {
493 case LeftButton:
494 button = WebMouseEvent::ButtonLeft;
495 break;
496 case MiddleButton:
497 button = WebMouseEvent::ButtonMiddle;
498 break;
499 case RightButton:
500 button = WebMouseEvent::ButtonRight;
501 break;
502 }
503 if (event.buttonDown()) {
504 switch (event.button()) {
505 case LeftButton:
506 modifiers |= WebInputEvent::LeftButtonDown;
507 break;
508 case MiddleButton:
509 modifiers |= WebInputEvent::MiddleButtonDown;
510 break;
511 case RightButton:
512 modifiers |= WebInputEvent::RightButtonDown;
513 break;
514 }
515 } else
516 button = WebMouseEvent::ButtonNone;
517 movementX = event.movementX();
518 movementY = event.movementY();
519 clickCount = event.detail();
520 }
521
522 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a mo use
523 // with touch input for plugins that don't support touch input).
524 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const RenderObj ect* renderObject, const TouchEvent& event)
525 {
526 if (!event.touches())
527 return;
528 if (event.touches()->length() != 1) {
529 if (event.touches()->length() || event.type() != EventTypeNames::touchen d || !event.changedTouches() || event.changedTouches()->length() != 1)
530 return;
531 }
532
533 const Touch* touch = event.touches()->length() == 1 ? event.touches()->item( 0) : event.changedTouches()->item(0);
534 if (touch->identifier())
535 return;
536
537 if (event.type() == EventTypeNames::touchstart)
538 type = MouseDown;
539 else if (event.type() == EventTypeNames::touchmove)
540 type = MouseMove;
541 else if (event.type() == EventTypeNames::touchend)
542 type = MouseUp;
543 else
544 return;
545
546 timeStampSeconds = event.timeStamp() / millisPerSecond;
547 modifiers = getWebInputModifiers(event);
548
549 // The mouse event co-ordinates should be generated from the co-ordinates of the touch point.
550 IntPoint windowPoint = roundedIntPoint(touch->absoluteLocation());
551 windowPoint = widget->convertToContainingView(windowPoint);
552 IntPoint screenPoint = roundedIntPoint(touch->screenLocation());
553 globalX = screenPoint.x();
554 globalY = screenPoint.y();
555 windowX = windowPoint.x();
556 windowY = windowPoint.y();
557
558 button = WebMouseEvent::ButtonLeft;
559 modifiers |= WebInputEvent::LeftButtonDown;
560 clickCount = (type == MouseDown || type == MouseUp);
561
562 IntPoint localPoint = convertAbsoluteLocationForRenderObject(touch->absolute Location(), *renderObject);
563 x = localPoint.x();
564 y = localPoint.y();
565 }
566
567 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const PlatformM ouseEvent& event)
568 {
569 switch (event.type()) {
570 case PlatformEvent::MouseMoved:
571 type = MouseMove;
572 break;
573 case PlatformEvent::MousePressed:
574 type = MouseDown;
575 break;
576 case PlatformEvent::MouseReleased:
577 type = MouseUp;
578 break;
579 default:
580 ASSERT_NOT_REACHED();
581 type = Undefined;
582 return;
583 }
584
585 modifiers = 0;
586 if (event.modifiers() & PlatformEvent::ShiftKey)
587 modifiers |= ShiftKey;
588 if (event.modifiers() & PlatformEvent::CtrlKey)
589 modifiers |= ControlKey;
590 if (event.modifiers() & PlatformEvent::AltKey)
591 modifiers |= AltKey;
592 if (event.modifiers() & PlatformEvent::MetaKey)
593 modifiers |= MetaKey;
594
595 timeStampSeconds = event.timestamp();
596
597 IntPoint position = event.position();
598 float scale = widgetInputEventsScaleFactor(widget);
599 position.scale(scale, scale);
600 x = position.x();
601 y = position.y();
602 globalX = event.globalPosition().x();
603 globalY = event.globalPosition().y();
604 movementX = event.movementDelta().x() * scale;
605 movementY = event.movementDelta().y() * scale;
606
607 button = static_cast<Button>(event.button());
608 clickCount = event.clickCount();
609 }
610
611 WebMouseWheelEventBuilder::WebMouseWheelEventBuilder(const Widget* widget, const RenderObject* renderObject, const WheelEvent& event)
612 {
613 if (event.type() != EventTypeNames::wheel && event.type() != EventTypeNames: :mousewheel)
614 return;
615 type = WebInputEvent::MouseWheel;
616 updateWebMouseEventFromCoreMouseEvent(event, *widget, *renderObject, *this);
617 deltaX = -event.deltaX();
618 deltaY = -event.deltaY();
619 wheelTicksX = event.ticksX();
620 wheelTicksY = event.ticksY();
621 scrollByPage = event.deltaMode() == WheelEvent::DOM_DELTA_PAGE;
622 }
623
624 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) 378 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event)
625 { 379 {
626 if (event.type() == EventTypeNames::keydown) 380 if (event.type() == EventTypeNames::keydown)
627 type = KeyDown; 381 type = KeyDown;
628 else if (event.type() == EventTypeNames::keyup) 382 else if (event.type() == EventTypeNames::keyup)
629 type = WebInputEvent::KeyUp; 383 type = WebInputEvent::KeyUp;
630 else if (event.type() == EventTypeNames::keypress) 384 else if (event.type() == EventTypeNames::keypress)
631 type = WebInputEvent::Char; 385 type = WebInputEvent::Char;
632 else 386 else
633 return; // Skip all other keyboard events. 387 return; // Skip all other keyboard events.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 modifiers = getWebInputModifiers(event); 528 modifiers = getWebInputModifiers(event);
775 529
776 globalX = event.screenX(); 530 globalX = event.screenX();
777 globalY = event.screenY(); 531 globalY = event.screenY();
778 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject); 532 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL ocation(), *renderObject);
779 x = localPoint.x(); 533 x = localPoint.x();
780 y = localPoint.y(); 534 y = localPoint.y();
781 } 535 }
782 536
783 } // namespace blink 537 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698