1/* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 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 26#include "config.h" 27 28#if ENABLE(GESTURE_EVENTS) 29 30#include "GestureEvent.h" 31 32#include "Element.h" 33#include <wtf/text/AtomicString.h> 34 35namespace WebCore { 36 37PassRefPtr<GestureEvent> GestureEvent::create() 38{ 39 return adoptRef(new GestureEvent); 40} 41 42PassRefPtr<GestureEvent> GestureEvent::create(PassRefPtr<AbstractView> view, const PlatformGestureEvent& event) 43{ 44 AtomicString eventType; 45 switch (event.type()) { 46 case PlatformEvent::GestureScrollBegin: 47 eventType = eventNames().gesturescrollstartEvent; break; 48 case PlatformEvent::GestureScrollEnd: 49 eventType = eventNames().gesturescrollendEvent; break; 50 case PlatformEvent::GestureScrollUpdate: 51 case PlatformEvent::GestureScrollUpdateWithoutPropagation: 52 eventType = eventNames().gesturescrollupdateEvent; break; 53 case PlatformEvent::GestureTap: 54 eventType = eventNames().gesturetapEvent; break; 55 case PlatformEvent::GestureTapDown: 56 eventType = eventNames().gesturetapdownEvent; break; 57 case PlatformEvent::GestureTwoFingerTap: 58 case PlatformEvent::GestureLongPress: 59 case PlatformEvent::GesturePinchBegin: 60 case PlatformEvent::GesturePinchEnd: 61 case PlatformEvent::GesturePinchUpdate: 62 case PlatformEvent::GestureTapDownCancel: 63 default: 64 return 0; 65 } 66 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(), event.deltaX(), event.deltaY())); 67} 68 69void GestureEvent::initGestureEvent(const AtomicString& type, PassRefPtr<AbstractView> view, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, float deltaX, float deltaY) 70{ 71 if (dispatched()) 72 return; 73 74 initUIEvent(type, true, true, view, 0); 75 m_screenLocation = IntPoint(screenX, screenY); 76 m_ctrlKey = ctrlKey; 77 m_altKey = altKey; 78 m_shiftKey = shiftKey; 79 m_metaKey = metaKey; 80 81 m_deltaX = deltaX; 82 m_deltaY = deltaY; 83 84 initCoordinates(IntPoint(clientX, clientY)); 85} 86 87const AtomicString& GestureEvent::interfaceName() const 88{ 89 DEFINE_STATIC_LOCAL(AtomicString, name, ("TBDInterface")); 90 return name; 91} 92 93GestureEvent::GestureEvent() 94 : m_deltaX(0) 95 , m_deltaY(0) 96{ 97} 98 99GestureEvent::GestureEvent(const AtomicString& type, PassRefPtr<AbstractView> view, int screenX, int screenY, int clientX, int clientY, bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, float deltaX, float deltaY) 100 : MouseRelatedEvent(type, true, true, view, 0, IntPoint(screenX, screenY), IntPoint(clientX, clientY), 101#if ENABLE(POINTER_LOCK) 102 IntPoint(0, 0), 103#endif 104 ctrlKey, altKey, shiftKey, metaKey) 105 , m_deltaX(deltaX) 106 , m_deltaY(deltaY) 107{ 108} 109 110GestureEventDispatchMediator::GestureEventDispatchMediator(PassRefPtr<GestureEvent> gestureEvent) 111 : EventDispatchMediator(gestureEvent) 112{ 113} 114 115GestureEvent* GestureEventDispatchMediator::event() const 116{ 117 return static_cast<GestureEvent*>(EventDispatchMediator::event()); 118} 119 120bool GestureEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const 121{ 122 if (isDisabledFormControl(dispatcher->node())) 123 return true; 124 125 dispatcher->dispatch(); 126 ASSERT(!event()->defaultPrevented()); 127 return event()->defaultHandled() || event()->defaultPrevented(); 128} 129 130} // namespace WebCore 131 132#endif // ENABLE(GESTURE_EVENTS) 133