Replace WTF::move with WTFMove
[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(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<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()
47 {
48 }
49
50 void EventContext::handleLocalEvents(Event& event) const
51 {
52     event.setTarget(m_target.get());
53     event.setCurrentTarget(m_currentTarget.get());
54     m_node->handleLocalEvents(event);
55 }
56
57 bool EventContext::isMouseOrFocusEventContext() const
58 {
59     return false;
60 }
61
62 bool EventContext::isTouchEventContext() const
63 {
64     return false;
65 }
66
67 MouseOrFocusEventContext::MouseOrFocusEventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target)
68     : EventContext(node, currentTarget, target)
69 {
70 }
71
72 MouseOrFocusEventContext::~MouseOrFocusEventContext()
73 {
74 }
75
76 void MouseOrFocusEventContext::handleLocalEvents(Event& event) const
77 {
78     ASSERT(is<MouseEvent>(event) || is<FocusEvent>(event));
79     if (m_relatedTarget) {
80         if (is<MouseEvent>(event))
81             downcast<MouseEvent>(event).setRelatedTarget(m_relatedTarget.get());
82         else if (is<FocusEvent>(event))
83             downcast<FocusEvent>(event).setRelatedTarget(m_relatedTarget.get());
84     }
85     EventContext::handleLocalEvents(event);
86 }
87
88 bool MouseOrFocusEventContext::isMouseOrFocusEventContext() const
89 {
90     return true;
91 }
92
93 #if ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
94 TouchEventContext::TouchEventContext(PassRefPtr<Node> node, PassRefPtr<EventTarget> currentTarget, PassRefPtr<EventTarget> target)
95     : EventContext(node, currentTarget, target)
96     , m_touches(TouchList::create())
97     , m_targetTouches(TouchList::create())
98     , m_changedTouches(TouchList::create())
99 {
100 }
101
102 TouchEventContext::~TouchEventContext()
103 {
104 }
105
106 void TouchEventContext::handleLocalEvents(Event& event) const
107 {
108 #ifndef NDEBUG
109     checkReachability(m_touches.get());
110     checkReachability(m_targetTouches.get());
111     checkReachability(m_changedTouches.get());
112 #endif
113     ASSERT(is<TouchEvent>(event));
114     TouchEvent& touchEvent = downcast<TouchEvent>(event);
115     touchEvent.setTouches(m_touches);
116     touchEvent.setTargetTouches(m_targetTouches);
117     touchEvent.setChangedTouches(m_changedTouches);
118     EventContext::handleLocalEvents(event);
119 }
120
121 bool TouchEventContext::isTouchEventContext() const
122 {
123     return true;
124 }
125
126 #ifndef NDEBUG
127 void TouchEventContext::checkReachability(TouchList* touchList) const
128 {
129     size_t length = touchList->length();
130     for (size_t i = 0; i < length; ++i)
131         ASSERT(isReachable(touchList->item(i)->target()->toNode()));
132 }
133 #endif
134
135 #endif // ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS)
136
137 }