Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / dom / EventContext.cpp
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 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 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 "EventContext.h"
29
30 #include "Document.h"
31 #include "FocusEvent.h"
32 #include "MouseEvent.h"
33 #include "TouchEvent.h"
34
35 namespace WebCore {
36
37 EventContext::EventContext(Node* node, EventTarget* currentTarget, EventTarget* target)
38     : m_node(node)
39     , m_currentTarget(currentTarget)
40     , m_target(target)
41 {
42     ASSERT(m_node);
43     ASSERT(!isUnreachableNode(m_target.get()));
44 }
45
46 EventContext::~EventContext() = default;
47
48 void EventContext::handleLocalEvents(Event& event) const
49 {
50     event.setTarget(m_target.get());
51     event.setCurrentTarget(m_currentTarget.get());
52     m_node->handleLocalEvents(event);
53 }
54
55 bool EventContext::isMouseOrFocusEventContext() const
56 {
57     return false;
58 }
59
60 bool EventContext::isTouchEventContext() const
61 {
62     return false;
63 }
64
65 MouseOrFocusEventContext::MouseOrFocusEventContext(Node* node, EventTarget* currentTarget, EventTarget* target)
66     : EventContext(node, currentTarget, target)
67 {
68 }
69
70 MouseOrFocusEventContext::~MouseOrFocusEventContext() = default;
71
72 void MouseOrFocusEventContext::handleLocalEvents(Event& event) const
73 {
74     if (m_relatedTarget)
75         event.setRelatedTarget(*m_relatedTarget);
76     EventContext::handleLocalEvents(event);
77 }
78
79 bool MouseOrFocusEventContext::isMouseOrFocusEventContext() const
80 {
81     return true;
82 }
83
84 #if ENABLE(TOUCH_EVENTS)
85
86 TouchEventContext::TouchEventContext(Node* node, EventTarget* currentTarget, EventTarget* target)
87     : EventContext(node, currentTarget, target)
88     , m_touches(TouchList::create())
89     , m_targetTouches(TouchList::create())
90     , m_changedTouches(TouchList::create())
91 {
92 }
93
94 TouchEventContext::~TouchEventContext() = default;
95
96 void TouchEventContext::handleLocalEvents(Event& event) const
97 {
98 #if !ASSERT_DISABLED
99     checkReachability(m_touches.get());
100     checkReachability(m_targetTouches.get());
101     checkReachability(m_changedTouches.get());
102 #endif
103     ASSERT(is<TouchEvent>(event));
104     TouchEvent& touchEvent = downcast<TouchEvent>(event);
105     touchEvent.setTouches(m_touches.get());
106     touchEvent.setTargetTouches(m_targetTouches.get());
107     touchEvent.setChangedTouches(m_changedTouches.get());
108     EventContext::handleLocalEvents(event);
109 }
110
111 bool TouchEventContext::isTouchEventContext() const
112 {
113     return true;
114 }
115
116 #if !ASSERT_DISABLED
117
118 void TouchEventContext::checkReachability(TouchList* touchList) const
119 {
120     size_t length = touchList->length();
121     for (size_t i = 0; i < length; ++i)
122         ASSERT(!isUnreachableNode(touchList->item(i)->target()->toNode().get()));
123 }
124
125 #endif
126
127 #endif // ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
128
129 }