Home | History | Annotate | Download | only in dom
      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/dom/Event.h"
     25 
     26 #include "core/dom/EventNames.h"
     27 #include "core/dom/EventTarget.h"
     28 #include "core/dom/StaticNodeList.h"
     29 #include "wtf/CurrentTime.h"
     30 #include "wtf/text/AtomicString.h"
     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::isGestureEvent() const
    142 {
    143     return false;
    144 }
    145 
    146 bool Event::isDragEvent() const
    147 {
    148     return false;
    149 }
    150 
    151 bool Event::isClipboardEvent() const
    152 {
    153     return false;
    154 }
    155 
    156 bool Event::storesResultAsString() const
    157 {
    158     return false;
    159 }
    160 
    161 bool Event::isBeforeTextInsertedEvent() const
    162 {
    163     return false;
    164 }
    165 
    166 void Event::storeResult(const String&)
    167 {
    168 }
    169 
    170 void Event::setTarget(PassRefPtr<EventTarget> target)
    171 {
    172     if (m_target == target)
    173         return;
    174 
    175     m_target = target;
    176     if (m_target)
    177         receivedTarget();
    178 }
    179 
    180 void Event::receivedTarget()
    181 {
    182 }
    183 
    184 void Event::setUnderlyingEvent(PassRefPtr<Event> ue)
    185 {
    186     // Prohibit creation of a cycle -- just do nothing in that case.
    187     for (Event* e = ue.get(); e; e = e->underlyingEvent())
    188         if (e == this)
    189             return;
    190     m_underlyingEvent = ue;
    191 }
    192 
    193 PassRefPtr<NodeList> Event::path() const
    194 {
    195     if (!m_currentTarget || !m_currentTarget->toNode())
    196         return StaticNodeList::createEmpty();
    197     Node* node = m_currentTarget->toNode();
    198     size_t eventPathSize = m_eventPath.size();
    199     for (size_t i = 0; i < eventPathSize; ++i) {
    200         if (node == m_eventPath[i]->node()) {
    201             ASSERT(m_eventPath[i]->eventPath());
    202             return m_eventPath[i]->eventPath();
    203         }
    204     }
    205     return StaticNodeList::createEmpty();
    206 }
    207 
    208 } // namespace WebCore
    209