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 "Event.h" 25 26 #include "AtomicString.h" 27 #include <wtf/CurrentTime.h> 28 29 namespace WebCore { 30 31 Event::Event() 32 : m_canBubble(false) 33 , m_cancelable(false) 34 , m_propagationStopped(false) 35 , m_defaultPrevented(false) 36 , m_defaultHandled(false) 37 , m_cancelBubble(false) 38 , m_createdByDOM(false) 39 , m_eventPhase(0) 40 , m_currentTarget(0) 41 , m_createTime(static_cast<DOMTimeStamp>(currentTime() * 1000.0)) 42 { 43 } 44 45 Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg) 46 : m_type(eventType) 47 , m_canBubble(canBubbleArg) 48 , m_cancelable(cancelableArg) 49 , m_propagationStopped(false) 50 , m_defaultPrevented(false) 51 , m_defaultHandled(false) 52 , m_cancelBubble(false) 53 , m_createdByDOM(false) 54 , m_eventPhase(0) 55 , m_currentTarget(0) 56 , m_createTime(static_cast<DOMTimeStamp>(currentTime() * 1000.0)) 57 { 58 } 59 60 Event::~Event() 61 { 62 } 63 64 void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg) 65 { 66 if (dispatched()) 67 return; 68 69 m_type = eventTypeArg; 70 m_canBubble = canBubbleArg; 71 m_cancelable = cancelableArg; 72 } 73 74 bool Event::isUIEvent() const 75 { 76 return false; 77 } 78 79 bool Event::isMouseEvent() const 80 { 81 return false; 82 } 83 84 bool Event::isMutationEvent() const 85 { 86 return false; 87 } 88 89 bool Event::isKeyboardEvent() const 90 { 91 return false; 92 } 93 94 bool Event::isTextEvent() const 95 { 96 return false; 97 } 98 99 bool Event::isCompositionEvent() const 100 { 101 return false; 102 } 103 104 bool Event::isDragEvent() const 105 { 106 return false; 107 } 108 109 bool Event::isClipboardEvent() const 110 { 111 return false; 112 } 113 114 bool Event::isWheelEvent() const 115 { 116 return false; 117 } 118 119 bool Event::isMessageEvent() const 120 { 121 return false; 122 } 123 124 bool Event::isBeforeTextInsertedEvent() const 125 { 126 return false; 127 } 128 129 bool Event::isOverflowEvent() const 130 { 131 return false; 132 } 133 134 bool Event::isPageTransitionEvent() const 135 { 136 return false; 137 } 138 139 bool Event::isPopStateEvent() const 140 { 141 return false; 142 } 143 144 bool Event::isProgressEvent() const 145 { 146 return false; 147 } 148 149 bool Event::isWebKitAnimationEvent() const 150 { 151 return false; 152 } 153 154 bool Event::isWebKitTransitionEvent() const 155 { 156 return false; 157 } 158 159 bool Event::isXMLHttpRequestProgressEvent() const 160 { 161 return false; 162 } 163 164 bool Event::isBeforeLoadEvent() const 165 { 166 return false; 167 } 168 169 #if ENABLE(SVG) 170 bool Event::isSVGZoomEvent() const 171 { 172 return false; 173 } 174 #endif 175 176 #if ENABLE(DOM_STORAGE) 177 bool Event::isStorageEvent() const 178 { 179 return false; 180 } 181 #endif 182 183 #if ENABLE(WORKERS) 184 bool Event::isErrorEvent() const 185 { 186 return false; 187 } 188 #endif 189 190 #if ENABLE(TOUCH_EVENTS) 191 bool Event::isTouchEvent() const 192 { 193 return false; 194 } 195 #endif 196 197 bool Event::fromUserGesture() 198 { 199 if (createdByDOM()) 200 return false; 201 202 const AtomicString& type = this->type(); 203 return 204 // mouse events 205 type == eventNames().clickEvent || type == eventNames().mousedownEvent 206 || type == eventNames().mouseupEvent || type == eventNames().dblclickEvent 207 // keyboard events 208 || type == eventNames().keydownEvent || type == eventNames().keypressEvent 209 || type == eventNames().keyupEvent 210 #if ENABLE(TOUCH_EVENTS) 211 // touch events 212 || type == eventNames().touchstartEvent || type == eventNames().touchmoveEvent 213 || type == eventNames().touchendEvent || type == eventNames().touchcancelEvent 214 #endif 215 // other accepted events 216 || type == eventNames().selectEvent || type == eventNames().changeEvent 217 || type == eventNames().focusEvent || type == eventNames().blurEvent 218 || type == eventNames().submitEvent; 219 } 220 221 bool Event::storesResultAsString() const 222 { 223 return false; 224 } 225 226 void Event::storeResult(const String&) 227 { 228 } 229 230 void Event::setTarget(PassRefPtr<EventTarget> target) 231 { 232 m_target = target; 233 if (m_target) 234 receivedTarget(); 235 } 236 237 void Event::receivedTarget() 238 { 239 } 240 241 void Event::setUnderlyingEvent(PassRefPtr<Event> ue) 242 { 243 // Prohibit creation of a cycle -- just do nothing in that case. 244 for (Event* e = ue.get(); e; e = e->underlyingEvent()) 245 if (e == this) 246 return; 247 m_underlyingEvent = ue; 248 } 249 250 } // namespace WebCore 251