| OLD | NEW |
| 1 /* | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 * | 3 // found in the LICENSE file. |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * * Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * * Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | 4 |
| 26 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 27 #include "sky/engine/core/dom/Element.h" | 6 #include "sky/engine/core/dom/Element.h" |
| 28 #include "sky/engine/core/events/GestureEvent.h" | 7 #include "sky/engine/core/events/GestureEvent.h" |
| 29 #include "sky/engine/wtf/text/AtomicString.h" | 8 #include "sky/engine/wtf/text/AtomicString.h" |
| 30 | 9 |
| 31 namespace blink { | 10 namespace blink { |
| 32 | 11 |
| 33 PassRefPtr<GestureEvent> GestureEvent::create(PassRefPtr<AbstractView> view, con
st PlatformGestureEvent& event) | 12 static AtomicString stringForType(WebInputEvent::Type type) |
| 34 { | 13 { |
| 35 AtomicString eventType; | 14 if (type == WebInputEvent::GestureScrollBegin) |
| 36 float deltaX = 0; | 15 return EventTypeNames::gesturescrollstart; |
| 37 float deltaY = 0; | 16 if (type == WebInputEvent::GestureScrollEnd) |
| 38 float velocityX = 0; | 17 return EventTypeNames::gesturescrollend; |
| 39 float velocityY = 0; | 18 if (type == WebInputEvent::GestureScrollUpdate) |
| 40 switch (event.type()) { | 19 return EventTypeNames::gesturescrollupdate; |
| 41 case PlatformEvent::GestureScrollBegin: | 20 if (type == WebInputEvent::GestureScrollUpdateWithoutPropagation) |
| 42 eventType = EventTypeNames::gesturescrollstart; | 21 return EventTypeNames::gesturescrollupdate; |
| 43 break; | 22 if (type == WebInputEvent::GestureFlingStart) |
| 44 case PlatformEvent::GestureScrollEnd: | 23 return EventTypeNames::gestureflingstart; |
| 45 eventType = EventTypeNames::gesturescrollend; | 24 if (type == WebInputEvent::GestureFlingCancel) |
| 46 break; | 25 return EventTypeNames::gestureflingcancel; |
| 47 case PlatformEvent::GestureScrollUpdate: | 26 if (type == WebInputEvent::GestureShowPress) |
| 48 case PlatformEvent::GestureScrollUpdateWithoutPropagation: | 27 return EventTypeNames::gestureshowpress; |
| 49 // Only deltaX/Y are used when converting this | 28 if (type == WebInputEvent::GestureTap) |
| 50 // back to a PlatformGestureEvent. | 29 return EventTypeNames::gesturetap; |
| 51 eventType = EventTypeNames::gesturescrollupdate; | 30 if (type == WebInputEvent::GestureTapUnconfirmed) |
| 52 deltaX = event.deltaX(); | 31 return EventTypeNames::gesturetapunconfirmed; |
| 53 deltaY = event.deltaY(); | 32 if (type == WebInputEvent::GestureTapDown) |
| 54 velocityX = event.velocityX(); | 33 return EventTypeNames::gesturetapdown; |
| 55 velocityY = event.velocityY(); | 34 if (type == WebInputEvent::GestureTapCancel) |
| 56 break; | 35 return EventTypeNames::gesturetapcancel; |
| 57 case PlatformEvent::GestureTap: | 36 if (type == WebInputEvent::GestureDoubleTap) |
| 58 eventType = EventTypeNames::gesturetap; | 37 return EventTypeNames::gesturedoubletap; |
| 59 break; | 38 if (type == WebInputEvent::GestureTwoFingerTap) |
| 60 case PlatformEvent::GestureTapUnconfirmed: | 39 return EventTypeNames::gesturetwofingertap; |
| 61 eventType = EventTypeNames::gesturetapunconfirmed; | 40 if (type == WebInputEvent::GestureLongPress) |
| 62 break; | 41 return EventTypeNames::gesturelongpress; |
| 63 case PlatformEvent::GestureTapDown: | 42 if (type == WebInputEvent::GestureLongTap) |
| 64 eventType = EventTypeNames::gesturetapdown; | 43 return EventTypeNames::gesturelongtap; |
| 65 break; | 44 if (type == WebInputEvent::GesturePinchBegin) |
| 66 case PlatformEvent::GestureShowPress: | 45 return EventTypeNames::gesturepinchstart; |
| 67 eventType = EventTypeNames::gestureshowpress; | 46 if (type == WebInputEvent::GesturePinchEnd) |
| 68 break; | 47 return EventTypeNames::gesturepinchend; |
| 69 case PlatformEvent::GestureTwoFingerTap: | 48 if (type == WebInputEvent::GesturePinchUpdate) |
| 70 case PlatformEvent::GestureLongPress: | 49 return EventTypeNames::gesturepinchupdate; |
| 71 case PlatformEvent::GesturePinchBegin: | 50 ASSERT_NOT_REACHED(); |
| 72 case PlatformEvent::GesturePinchEnd: | 51 return AtomicString(); |
| 73 case PlatformEvent::GesturePinchUpdate: | |
| 74 case PlatformEvent::GestureTapDownCancel: | |
| 75 default: | |
| 76 return nullptr; | |
| 77 } | |
| 78 return adoptRef(new GestureEvent(eventType, view, event.globalPosition().x()
, event.globalPosition().y(), event.position().x(), event.position().y(), event.
ctrlKey(), event.altKey(), event.shiftKey(), event.metaKey(), deltaX, deltaY, ve
locityX, velocityY)); | |
| 79 } | 52 } |
| 80 | 53 |
| 81 PassRefPtr<GestureEvent> GestureEvent::create(const AtomicString& type, const Ge
stureEventInit& initializer) | 54 GestureEvent::~GestureEvent() |
| 82 { | 55 { |
| 83 return adoptRef(new GestureEvent(type, initializer)); | |
| 84 } | 56 } |
| 85 | 57 |
| 86 const AtomicString& GestureEvent::interfaceName() const | 58 const AtomicString& GestureEvent::interfaceName() const |
| 87 { | 59 { |
| 88 return EventNames::GestureEvent; | 60 return EventNames::GestureEvent; |
| 89 } | 61 } |
| 90 | 62 |
| 91 bool GestureEvent::isGestureEvent() const | 63 GestureEvent::GestureEvent() |
| 64 : GestureEvent(AtomicString(), GestureEventInit()) |
| 92 { | 65 { |
| 93 return true; | |
| 94 } | 66 } |
| 95 | 67 |
| 96 GestureEvent::GestureEvent() | 68 GestureEvent::GestureEvent(const WebGestureEvent& event) |
| 97 : m_deltaX(0) | 69 : Event(stringForType(event.type), true, true) |
| 98 , m_deltaY(0) | 70 , m_x(event.x) |
| 71 , m_y(event.y) |
| 72 , m_dx(0) |
| 73 , m_dy(0) |
| 99 , m_velocityX(0) | 74 , m_velocityX(0) |
| 100 , m_velocityY(0) | 75 , m_velocityY(0) |
| 101 { | 76 { |
| 77 if (event.type == WebInputEvent::GestureFlingStart) { |
| 78 m_velocityX = event.data.flingStart.velocityX; |
| 79 m_velocityY = event.data.flingStart.velocityY; |
| 80 } else if (event.type == WebInputEvent::GestureScrollUpdate |
| 81 || event.type == WebInputEvent::GestureScrollUpdateWithoutPropagatio
n) { |
| 82 m_dx = event.data.scrollUpdate.deltaX; |
| 83 m_dy = event.data.scrollUpdate.deltaY; |
| 84 m_velocityX = event.data.scrollUpdate.velocityX; |
| 85 m_velocityY = event.data.scrollUpdate.velocityY; |
| 86 } |
| 102 } | 87 } |
| 103 | 88 |
| 104 GestureEvent::GestureEvent(const AtomicString& type, const GestureEventInit& ini
tializer) | 89 GestureEvent::GestureEvent(const AtomicString& type, const GestureEventInit& ini
tializer) |
| 105 : MouseRelatedEvent(type, initializer.bubbles, initializer.cancelable, initi
alizer.view, initializer.detail, IntPoint(initializer.screenX, initializer.scree
nY), | 90 : Event(type, true, true) |
| 106 IntPoint(0 /* pageX */, 0 /* pageY */), | 91 , m_x(initializer.x) |
| 107 IntPoint(0 /* movementX */, 0 /* movementY */), | 92 , m_y(initializer.y) |
| 108 initializer.ctrlKey, initializer.altKey, initializer.shiftKey, initializ
er.metaKey, false /* isSimulated */) | 93 , m_dx(initializer.dx) |
| 109 , m_deltaX(initializer.deltaX) | 94 , m_dy(initializer.dy) |
| 110 , m_deltaY(initializer.deltaY) | |
| 111 , m_velocityX(initializer.velocityX) | 95 , m_velocityX(initializer.velocityX) |
| 112 , m_velocityY(initializer.velocityY) | 96 , m_velocityY(initializer.velocityY) |
| 113 { | 97 { |
| 114 } | 98 } |
| 115 | 99 |
| 116 GestureEvent::GestureEvent(const AtomicString& type, PassRefPtr<AbstractView> vi
ew, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKe
y, bool shiftKey, bool metaKey, float deltaX, float deltaY, float velocityX, flo
at velocityY) | |
| 117 : MouseRelatedEvent(type, true, true, view, 0, IntPoint(screenX, screenY), I
ntPoint(clientX, clientY), IntPoint(0, 0), ctrlKey, altKey, shiftKey, metaKey) | |
| 118 , m_deltaX(deltaX) | |
| 119 , m_deltaY(deltaY) | |
| 120 , m_velocityX(velocityX) | |
| 121 , m_velocityY(velocityY) | |
| 122 { | |
| 123 } | |
| 124 | |
| 125 GestureEventDispatchMediator::GestureEventDispatchMediator(PassRefPtr<GestureEve
nt> gestureEvent) | |
| 126 : EventDispatchMediator(gestureEvent) | |
| 127 { | |
| 128 } | |
| 129 | |
| 130 GestureEvent* GestureEventDispatchMediator::event() const | |
| 131 { | |
| 132 return toGestureEvent(EventDispatchMediator::event()); | |
| 133 } | |
| 134 | |
| 135 bool GestureEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) co
nst | |
| 136 { | |
| 137 dispatcher->dispatch(); | |
| 138 ASSERT(!event()->defaultPrevented()); | |
| 139 return event()->defaultHandled() || event()->defaultPrevented(); | |
| 140 } | |
| 141 | |
| 142 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |