1/* 2 * Copyright (C) 2010 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 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. 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 APPLE COMPUTER, INC. ``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 27#include "config.h" 28#include "core/events/EventContext.h" 29 30#include "core/events/Event.h" 31#include "core/events/FocusEvent.h" 32#include "core/events/MouseEvent.h" 33#include "core/events/TouchEvent.h" 34#include "core/dom/TouchList.h" 35 36namespace WebCore { 37 38EventContext::EventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget) 39 : m_node(node) 40 , m_currentTarget(currentTarget) 41{ 42 ASSERT(m_node); 43} 44 45EventContext::~EventContext() 46{ 47} 48 49void EventContext::adoptEventPath(Vector<RefPtr<Node> >& nodes) 50{ 51 m_eventPath = StaticNodeList::adopt(nodes); 52} 53 54void EventContext::handleLocalEvents(Event* event) const 55{ 56 if (m_touchEventContext) { 57 m_touchEventContext->handleLocalEvents(event); 58 } else if (m_relatedTarget && event->isMouseEvent()) { 59 toMouseEvent(event)->setRelatedTarget(m_relatedTarget.get()); 60 } else if (m_relatedTarget && event->isFocusEvent()) { 61 toFocusEvent(event)->setRelatedTarget(m_relatedTarget.get()); 62 } 63 event->setTarget(m_target); 64 event->setCurrentTarget(m_currentTarget.get()); 65 m_node->handleLocalEvents(event); 66} 67 68TouchEventContext* EventContext::ensureTouchEventContext() 69{ 70 if (!m_touchEventContext) 71 m_touchEventContext = TouchEventContext::create(); 72 return m_touchEventContext.get(); 73} 74 75PassRefPtr<TouchEventContext> TouchEventContext::create() 76{ 77 return adoptRef(new TouchEventContext); 78} 79 80TouchEventContext::TouchEventContext() 81 : m_touches(TouchList::create()) 82 , m_targetTouches(TouchList::create()) 83 , m_changedTouches(TouchList::create()) 84{ 85} 86 87TouchEventContext::~TouchEventContext() 88{ 89} 90 91void TouchEventContext::handleLocalEvents(Event* event) const 92{ 93 ASSERT(event->isTouchEvent()); 94 TouchEvent* touchEvent = toTouchEvent(event); 95 touchEvent->setTouches(m_touches); 96 touchEvent->setTargetTouches(m_targetTouches); 97 touchEvent->setChangedTouches(m_changedTouches); 98} 99 100} 101