1/*
2 * Copyright 2008, The Android Open Source Project
3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28
29#include "core/events/TouchEvent.h"
30
31#include "core/events/EventDispatcher.h"
32#include "core/events/EventRetargeter.h"
33#include "core/events/ThreadLocalEventNames.h"
34
35namespace WebCore {
36
37TouchEvent::TouchEvent()
38{
39    ScriptWrappable::init(this);
40}
41
42TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches,
43        TouchList* changedTouches, const AtomicString& type,
44        PassRefPtr<AbstractView> view, int screenX, int screenY, int pageX, int pageY,
45        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
46    : MouseRelatedEvent(type, true, true, view, 0, IntPoint(screenX, screenY),
47                        IntPoint(pageX, pageY),
48                        IntPoint(0, 0),
49                        ctrlKey, altKey, shiftKey, metaKey)
50    , m_touches(touches)
51    , m_targetTouches(targetTouches)
52    , m_changedTouches(changedTouches)
53{
54    ScriptWrappable::init(this);
55}
56
57TouchEvent::~TouchEvent()
58{
59}
60
61void TouchEvent::initTouchEvent(TouchList* touches, TouchList* targetTouches,
62        TouchList* changedTouches, const AtomicString& type,
63        PassRefPtr<AbstractView> view, int screenX, int screenY, int clientX, int clientY,
64        bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
65{
66    if (dispatched())
67        return;
68
69    initUIEvent(type, true, true, view, 0);
70
71    m_touches = touches;
72    m_targetTouches = targetTouches;
73    m_changedTouches = changedTouches;
74    m_screenLocation = IntPoint(screenX, screenY);
75    m_ctrlKey = ctrlKey;
76    m_altKey = altKey;
77    m_shiftKey = shiftKey;
78    m_metaKey = metaKey;
79    initCoordinates(IntPoint(clientX, clientY));
80}
81
82const AtomicString& TouchEvent::interfaceName() const
83{
84    return EventNames::TouchEvent;
85}
86
87bool TouchEvent::isTouchEvent() const
88{
89    return true;
90}
91
92PassRefPtr<TouchEventDispatchMediator> TouchEventDispatchMediator::create(PassRefPtr<TouchEvent> touchEvent)
93{
94    return adoptRef(new TouchEventDispatchMediator(touchEvent));
95}
96
97TouchEventDispatchMediator::TouchEventDispatchMediator(PassRefPtr<TouchEvent> touchEvent)
98    : EventDispatchMediator(touchEvent)
99{
100}
101
102TouchEvent* TouchEventDispatchMediator::event() const
103{
104    return toTouchEvent(EventDispatchMediator::event());
105}
106
107bool TouchEventDispatchMediator::dispatchEvent(EventDispatcher* dispatcher) const
108{
109    EventRetargeter::adjustForTouchEvent(dispatcher->node(), *event());
110    return dispatcher->dispatch();
111}
112
113} // namespace WebCore
114