1 /* 2 * Copyright (C) 2001 Peter Kelly (pmk (at) post.com) 3 * Copyright (C) 2001 Tobias Anton (anton (at) stud.fbi.fh-darmstadt.de) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com) 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #include "config.h" 24 #include "core/events/Event.h" 25 26 #include "core/dom/StaticNodeList.h" 27 #include "core/events/EventTarget.h" 28 #include "core/events/ThreadLocalEventNames.h" 29 #include "wtf/CurrentTime.h" 30 31 namespace WebCore { 32 33 EventInit::EventInit() 34 : bubbles(false) 35 , cancelable(false) 36 { 37 } 38 39 40 Event::Event() 41 : m_canBubble(false) 42 , m_cancelable(false) 43 , m_propagationStopped(false) 44 , m_immediatePropagationStopped(false) 45 , m_defaultPrevented(false) 46 , m_defaultHandled(false) 47 , m_cancelBubble(false) 48 , m_eventPhase(0) 49 , m_currentTarget(0) 50 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 51 , m_eventPath(this) 52 { 53 ScriptWrappable::init(this); 54 } 55 56 Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg) 57 : m_type(eventType) 58 , m_canBubble(canBubbleArg) 59 , m_cancelable(cancelableArg) 60 , m_propagationStopped(false) 61 , m_immediatePropagationStopped(false) 62 , m_defaultPrevented(false) 63 , m_defaultHandled(false) 64 , m_cancelBubble(false) 65 , m_eventPhase(0) 66 , m_currentTarget(0) 67 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 68 , m_eventPath(this) 69 { 70 ScriptWrappable::init(this); 71 } 72 73 Event::Event(const AtomicString& eventType, const EventInit& initializer) 74 : m_type(eventType) 75 , m_canBubble(initializer.bubbles) 76 , m_cancelable(initializer.cancelable) 77 , m_propagationStopped(false) 78 , m_immediatePropagationStopped(false) 79 , m_defaultPrevented(false) 80 , m_defaultHandled(false) 81 , m_cancelBubble(false) 82 , m_eventPhase(0) 83 , m_currentTarget(0) 84 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 85 , m_eventPath(this) 86 { 87 ScriptWrappable::init(this); 88 } 89 90 Event::~Event() 91 { 92 } 93 94 void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg) 95 { 96 if (dispatched()) 97 return; 98 99 m_propagationStopped = false; 100 m_immediatePropagationStopped = false; 101 m_defaultPrevented = false; 102 103 m_type = eventTypeArg; 104 m_canBubble = canBubbleArg; 105 m_cancelable = cancelableArg; 106 } 107 108 const AtomicString& Event::interfaceName() const 109 { 110 return EventNames::Event; 111 } 112 113 bool Event::hasInterface(const AtomicString& name) const 114 { 115 return interfaceName() == name; 116 } 117 118 bool Event::isUIEvent() const 119 { 120 return false; 121 } 122 123 bool Event::isMouseEvent() const 124 { 125 return false; 126 } 127 128 bool Event::isFocusEvent() const 129 { 130 return false; 131 } 132 133 bool Event::isKeyboardEvent() const 134 { 135 return false; 136 } 137 138 bool Event::isTouchEvent() const 139 { 140 return false; 141 } 142 143 bool Event::isGestureEvent() const 144 { 145 return false; 146 } 147 148 bool Event::isWheelEvent() const 149 { 150 return false; 151 } 152 153 bool Event::isDragEvent() const 154 { 155 return false; 156 } 157 158 bool Event::isClipboardEvent() const 159 { 160 return false; 161 } 162 163 bool Event::isBeforeTextInsertedEvent() const 164 { 165 return false; 166 } 167 168 bool Event::isBeforeUnloadEvent() const 169 { 170 return false; 171 } 172 173 void Event::setTarget(PassRefPtr<EventTarget> target) 174 { 175 if (m_target == target) 176 return; 177 178 m_target = target; 179 if (m_target) 180 receivedTarget(); 181 } 182 183 void Event::receivedTarget() 184 { 185 } 186 187 void Event::setUnderlyingEvent(PassRefPtr<Event> ue) 188 { 189 // Prohibit creation of a cycle -- just do nothing in that case. 190 for (Event* e = ue.get(); e; e = e->underlyingEvent()) 191 if (e == this) 192 return; 193 m_underlyingEvent = ue; 194 } 195 196 PassRefPtr<NodeList> Event::path() const 197 { 198 if (!m_currentTarget || !m_currentTarget->toNode()) 199 return StaticNodeList::createEmpty(); 200 Node* node = m_currentTarget->toNode(); 201 size_t eventPathSize = m_eventPath.size(); 202 for (size_t i = 0; i < eventPathSize; ++i) { 203 if (node == m_eventPath[i].node()) { 204 ASSERT(m_eventPath[i].eventPath()); 205 return m_eventPath[i].eventPath(); 206 } 207 } 208 return StaticNodeList::createEmpty(); 209 } 210 211 } // namespace WebCore 212