Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 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 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/dom/Event.h" |
| 25 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 26 | #include "core/dom/EventNames.h" |
| 27 | #include "core/dom/EventTarget.h" |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 28 | #include "core/dom/StaticNodeList.h" |
Ben Murdoch | e69819b | 2013-07-17 14:56:49 +0100 | [diff] [blame] | 29 | #include "wtf/CurrentTime.h" |
| 30 | #include "wtf/text/AtomicString.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | EventInit::EventInit() |
| 35 | : bubbles(false) |
| 36 | , cancelable(false) |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | |
| 41 | Event::Event() |
| 42 | : m_canBubble(false) |
| 43 | , m_cancelable(false) |
| 44 | , m_propagationStopped(false) |
| 45 | , m_immediatePropagationStopped(false) |
| 46 | , m_defaultPrevented(false) |
| 47 | , m_defaultHandled(false) |
| 48 | , m_cancelBubble(false) |
| 49 | , m_eventPhase(0) |
| 50 | , m_currentTarget(0) |
| 51 | , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) |
| 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 | { |
| 69 | ScriptWrappable::init(this); |
| 70 | } |
| 71 | |
| 72 | Event::Event(const AtomicString& eventType, const EventInit& initializer) |
| 73 | : m_type(eventType) |
| 74 | , m_canBubble(initializer.bubbles) |
| 75 | , m_cancelable(initializer.cancelable) |
| 76 | , m_propagationStopped(false) |
| 77 | , m_immediatePropagationStopped(false) |
| 78 | , m_defaultPrevented(false) |
| 79 | , m_defaultHandled(false) |
| 80 | , m_cancelBubble(false) |
| 81 | , m_eventPhase(0) |
| 82 | , m_currentTarget(0) |
| 83 | , m_createTime(convertSecondsToDOMTimeStamp(currentTime())) |
| 84 | { |
| 85 | ScriptWrappable::init(this); |
| 86 | } |
| 87 | |
| 88 | Event::~Event() |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | void Event::initEvent(const AtomicString& eventTypeArg, bool canBubbleArg, bool cancelableArg) |
| 93 | { |
| 94 | if (dispatched()) |
| 95 | return; |
| 96 | |
| 97 | m_propagationStopped = false; |
| 98 | m_immediatePropagationStopped = false; |
| 99 | m_defaultPrevented = false; |
| 100 | |
| 101 | m_type = eventTypeArg; |
| 102 | m_canBubble = canBubbleArg; |
| 103 | m_cancelable = cancelableArg; |
| 104 | } |
| 105 | |
| 106 | const AtomicString& Event::interfaceName() const |
| 107 | { |
| 108 | return eventNames().interfaceForEvent; |
| 109 | } |
| 110 | |
| 111 | bool Event::hasInterface(const AtomicString& name) const |
| 112 | { |
| 113 | return interfaceName() == name; |
| 114 | } |
| 115 | |
| 116 | bool Event::isUIEvent() const |
| 117 | { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | bool Event::isMouseEvent() const |
| 122 | { |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool Event::isFocusEvent() const |
| 127 | { |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | bool Event::isKeyboardEvent() const |
| 132 | { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | bool Event::isTouchEvent() const |
| 137 | { |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | bool Event::isDragEvent() const |
| 142 | { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | bool Event::isClipboardEvent() const |
| 147 | { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool Event::storesResultAsString() const |
| 152 | { |
| 153 | return false; |
| 154 | } |
| 155 | |
| 156 | bool Event::isBeforeTextInsertedEvent() const |
| 157 | { |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | void Event::storeResult(const String&) |
| 162 | { |
| 163 | } |
| 164 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 165 | void Event::setTarget(PassRefPtr<EventTarget> target) |
| 166 | { |
| 167 | if (m_target == target) |
| 168 | return; |
| 169 | |
| 170 | m_target = target; |
| 171 | if (m_target) |
| 172 | receivedTarget(); |
| 173 | } |
| 174 | |
| 175 | void Event::receivedTarget() |
| 176 | { |
| 177 | } |
| 178 | |
| 179 | void Event::setUnderlyingEvent(PassRefPtr<Event> ue) |
| 180 | { |
| 181 | // Prohibit creation of a cycle -- just do nothing in that case. |
| 182 | for (Event* e = ue.get(); e; e = e->underlyingEvent()) |
| 183 | if (e == this) |
| 184 | return; |
| 185 | m_underlyingEvent = ue; |
| 186 | } |
| 187 | |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 188 | PassRefPtr<NodeList> Event::path() const |
| 189 | { |
| 190 | if (!m_currentTarget || !m_currentTarget->toNode()) |
| 191 | return StaticNodeList::createEmpty(); |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 192 | Node* node = m_currentTarget->toNode(); |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 193 | size_t eventPathSize = m_eventPath.size(); |
| 194 | for (size_t i = 0; i < eventPathSize; ++i) { |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 195 | if (node == m_eventPath[i]->node()) { |
| 196 | ASSERT(m_eventPath[i]->eventPath()); |
| 197 | return m_eventPath[i]->eventPath(); |
| 198 | } |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 199 | } |
Torne (Richard Coles) | e524955 | 2013-05-15 11:35:13 +0100 | [diff] [blame] | 200 | return StaticNodeList::createEmpty(); |
Torne (Richard Coles) | 81a5157 | 2013-05-13 16:52:28 +0100 | [diff] [blame] | 201 | } |
| 202 | |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 203 | } // namespace WebCore |