1/* 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * Copyright (C) 2003, 2005, 2006, 2008, 2013 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 "EventTarget.h" 27#include "UserGestureIndicator.h" 28#include <wtf/CurrentTime.h> 29 30namespace WebCore { 31 32EventInit::EventInit() 33 : bubbles(false) 34 , cancelable(false) 35{ 36} 37 38EventInit::EventInit(bool b, bool c) 39 : bubbles(b) 40 , cancelable(c) 41{ 42} 43 44Event::Event() 45 : m_canBubble(false) 46 , m_cancelable(false) 47 , m_propagationStopped(false) 48 , m_immediatePropagationStopped(false) 49 , m_defaultPrevented(false) 50 , m_defaultHandled(false) 51 , m_cancelBubble(false) 52 , m_eventPhase(0) 53 , m_currentTarget(0) 54 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 55{ 56} 57 58Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg) 59 : m_type(eventType) 60 , m_canBubble(canBubbleArg) 61 , m_cancelable(cancelableArg) 62 , m_propagationStopped(false) 63 , m_immediatePropagationStopped(false) 64 , m_defaultPrevented(false) 65 , m_defaultHandled(false) 66 , m_cancelBubble(false) 67 , m_eventPhase(0) 68 , m_currentTarget(0) 69 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 70{ 71} 72 73Event::Event(const AtomicString& eventType, bool canBubbleArg, bool cancelableArg, double timestamp) 74 : m_type(eventType) 75 , m_canBubble(canBubbleArg) 76 , m_cancelable(cancelableArg) 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(timestamp)) 85{ 86} 87 88Event::Event(const AtomicString& eventType, const EventInit& initializer) 89 : m_type(eventType) 90 , m_canBubble(initializer.bubbles) 91 , m_cancelable(initializer.cancelable) 92 , m_propagationStopped(false) 93 , m_immediatePropagationStopped(false) 94 , m_defaultPrevented(false) 95 , m_defaultHandled(false) 96 , m_cancelBubble(false) 97 , m_eventPhase(0) 98 , m_currentTarget(0) 99 , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) 100{ 101} 102 103Event::~Event() 104{ 105} 106 107void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg) 108{ 109 if (dispatched()) 110 return; 111 112 m_propagationStopped = false; 113 m_immediatePropagationStopped = false; 114 m_defaultPrevented = false; 115 116 m_type = eventTypeArg; 117 m_canBubble = canBubbleArg; 118 m_cancelable = cancelableArg; 119} 120 121EventInterface Event::eventInterface() const 122{ 123 return EventInterfaceType; 124} 125 126bool Event::isUIEvent() const 127{ 128 return false; 129} 130 131bool Event::isMouseEvent() const 132{ 133 return false; 134} 135 136bool Event::isFocusEvent() const 137{ 138 return false; 139} 140 141bool Event::isKeyboardEvent() const 142{ 143 return false; 144} 145 146bool Event::isTouchEvent() const 147{ 148 return false; 149} 150 151bool Event::isDragEvent() const 152{ 153 return false; 154} 155 156bool Event::isClipboardEvent() const 157{ 158 return false; 159} 160 161bool Event::isBeforeTextInsertedEvent() const 162{ 163 return false; 164} 165 166bool Event::isBeforeUnloadEvent() const 167{ 168 return false; 169} 170 171bool Event::isErrorEvent() const 172{ 173 return false; 174} 175 176bool Event::isTextEvent() const 177{ 178 return false; 179} 180 181bool Event::isWheelEvent() const 182{ 183 return false; 184} 185 186PassRefPtr<Event> Event::cloneFor(HTMLIFrameElement*) const 187{ 188 return Event::create(type(), bubbles(), cancelable()); 189} 190 191void Event::setTarget(PassRefPtr<EventTarget> target) 192{ 193 if (m_target == target) 194 return; 195 196 m_target = target; 197 if (m_target) 198 receivedTarget(); 199} 200 201void Event::receivedTarget() 202{ 203} 204 205void Event::setUnderlyingEvent(PassRefPtr<Event> ue) 206{ 207 // Prohibit creation of a cycle -- just do nothing in that case. 208 for (Event* e = ue.get(); e; e = e->underlyingEvent()) 209 if (e == this) 210 return; 211 m_underlyingEvent = ue; 212} 213 214} // namespace WebCore 215