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 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#if ENABLE(TOUCH_EVENTS)
30
31#include "TouchEvent.h"
32
33#include "EventDispatcher.h"
34
35namespace WebCore {
36
37TouchEvent::TouchEvent() = default;
38
39TouchEvent::TouchEvent(TouchList* touches, TouchList* targetTouches, TouchList* changedTouches, const AtomString& type,
40 RefPtr<WindowProxy>&& view, const IntPoint& globalLocation, OptionSet<Modifier> modifiers)
41 : MouseRelatedEvent(type, IsCancelable::Yes, MonotonicTime::now(), WTFMove(view), globalLocation, modifiers)
42 , m_touches(touches)
43 , m_targetTouches(targetTouches)
44 , m_changedTouches(changedTouches)
45{
46}
47
48TouchEvent::TouchEvent(const AtomString& type, const Init& initializer, IsTrusted isTrusted)
49 : MouseRelatedEvent(type, initializer, isTrusted)
50 , m_touches(initializer.touches ? initializer.touches : TouchList::create())
51 , m_targetTouches(initializer.targetTouches ? initializer.targetTouches : TouchList::create())
52 , m_changedTouches(initializer.changedTouches ? initializer.changedTouches : TouchList::create())
53{
54}
55
56TouchEvent::~TouchEvent() = default;
57
58void TouchEvent::initTouchEvent(TouchList* touches, TouchList* targetTouches,
59 TouchList* changedTouches, const AtomString& type,
60 RefPtr<WindowProxy>&& view, int screenX, int screenY, int clientX, int clientY,
61 bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
62{
63 if (isBeingDispatched())
64 return;
65
66 initUIEvent(type, true, true, WTFMove(view), 0);
67
68 m_touches = touches;
69 m_targetTouches = targetTouches;
70 m_changedTouches = changedTouches;
71 m_screenLocation = IntPoint(screenX, screenY);
72 setModifierKeys(ctrlKey, altKey, shiftKey, metaKey);
73 initCoordinates(IntPoint(clientX, clientY));
74}
75
76EventInterface TouchEvent::eventInterface() const
77{
78 return TouchEventInterfaceType;
79}
80
81bool TouchEvent::isTouchEvent() const
82{
83 return true;
84}
85
86} // namespace WebCore
87
88#endif // ENABLE(TOUCH_EVENTS)
89