[webkit-changes] cvs commit: LayoutTests/fast/events init-event-after-dispatch-expected.txt init-event-after-dispatch.html

Darin darin at opensource.apple.com
Tue Oct 25 09:39:26 PDT 2005


darin       05/10/25 09:39:26

  Modified:    .        ChangeLog
               khtml/dom dom_node.h
               khtml/xml dom2_eventsimpl.cpp dom2_eventsimpl.h
                        dom_nodeimpl.cpp
               .        ChangeLog
  Added:       fast/events init-event-after-dispatch-expected.txt
                        init-event-after-dispatch.html
  Log:
  LayoutTests:
  
          - added test for http://bugzilla.opendarwin.org/show_bug.cgi?id=4945
            event init calls should not do anything if the event has already been dispatched
  
          * fast/events/init-event-after-dispatch-expected.txt: Added.
          * fast/events/init-event-after-dispatch.html: Added.
  
  WebCore:
  
          Reviewed by Dave Hyatt.
  
          - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4945
            event init calls should not do anything if the event has already been dispatched
          - made a small performance improvement to event creation by simplifying the date code
            (seen on profiles)
          - changed DOMTimestamp to be a 64-bit integer on Mac OS X (requested by the DOM standard)
  
          * khtml/dom/dom_node.h: Made DOMTimestamp be unsigned long long on Mac OS X.
  
          * khtml/xml/dom_nodeimpl.cpp:
          (DOM::NodeImpl::dispatchGenericEvent): Assert that the event has a target.
          (DOM::NodeImpl::dispatchWindowEvent): Set the event target to the document.
  
          * khtml/xml/dom2_eventsimpl.h: Changed many data members to use SharedPtr instead of
          explicit ref/deref. Changed m_createTime to be a DOMTimeStamp instead of a QDateTime.
          (DOM::EventImpl::setTarget): Now inlined.
          (DOM::EventImpl::timeStamp): Now inlined.
          (DOM::EventImpl::preventDefault): Now inlined.
          (DOM::EventImpl::dispatched): Added. Returns true if the event was already dispatched,
          meaning it already has a target.
  
          * khtml/xml/dom2_eventsimpl.cpp:
          (DOM::currentTimeStamp): Added. Faster inline version on Mac OS X, since this shows
          up in profiles.
          (DOM::EventImpl::EventImpl): Changed to use contructor syntax and set m_createTime to
          currentTimeStamp().
          (DOM::EventImpl::~EventImpl): Removed explicit derefs; no longer needed.
          (DOM::EventImpl::initEvent): Do nothing if dispatched() is true. Simplify since
          SharedPtr handles ref/deref.
          (DOM::UIEventImpl::UIEventImpl): Changed to use contructor syntax and take advantage
          of the fact that some data members are now SharedPtr.
          (DOM::UIEventImpl::initUIEvent): Do nothing if dispatched() is true. Simplify since
          SharedPtr handles ref/deref.
          (DOM::MouseEventImpl::MouseEventImpl): Changed to use contructor syntax and take advantage
          of the fact that some data members are now SharedPtr.
          (DOM::MouseEventImpl::~MouseEventImpl): Removed explicit derefs; no longer needed.
          (DOM::MouseEventImpl::initMouseEvent): Do nothing if dispatched() is true. Simplify since
          SharedPtr handles ref/deref.
          (DOM::MouseEventImpl::isDragEvent): Use a local variable.
          (DOM::KeyboardEventImpl::KeyboardEventImpl): Changed to use contructor syntax and take
          advantage of the fact that some data members are now SharedPtr.
          (DOM::KeyboardEventImpl::~KeyboardEventImpl): Removed explicit derefs; no longer needed.
          (DOM::KeyboardEventImpl::initKeyboardEvent): Do nothing if dispatched() is true. Simplify
          since SharedPtr handles ref/deref.
          (DOM::MutationEventImpl::MutationEventImpl): Changed to use contructor syntax and take
          advantage of the fact that some data members are now SharedPtr.
          (DOM::MutationEventImpl::initMutationEvent): Do nothing if dispatched() is true. Simplify
          since SharedPtr handles ref/deref.
          (DOM::ClipboardEventImpl::ClipboardEventImpl): Simplify since SharedPtr handles initialization
          and ref/deref.
          (DOM::RegisteredEventListener::RegisteredEventListener): Ditto.
  
  Revision  Changes    Path
  1.282     +55 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.281
  retrieving revision 1.282
  diff -u -r1.281 -r1.282
  --- ChangeLog	25 Oct 2005 03:45:29 -0000	1.281
  +++ ChangeLog	25 Oct 2005 16:39:23 -0000	1.282
  @@ -1,3 +1,58 @@
  +2005-10-25  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Dave Hyatt.
  +
  +        - fixed http://bugzilla.opendarwin.org/show_bug.cgi?id=4945
  +          event init calls should not do anything if the event has already been dispatched
  +        - made a small performance improvement to event creation by simplifying the date code
  +          (seen on profiles)
  +        - changed DOMTimestamp to be a 64-bit integer on Mac OS X (requested by the DOM standard)
  +
  +        * khtml/dom/dom_node.h: Made DOMTimestamp be unsigned long long on Mac OS X.
  +
  +        * khtml/xml/dom_nodeimpl.cpp:
  +        (DOM::NodeImpl::dispatchGenericEvent): Assert that the event has a target.
  +        (DOM::NodeImpl::dispatchWindowEvent): Set the event target to the document.
  +
  +        * khtml/xml/dom2_eventsimpl.h: Changed many data members to use SharedPtr instead of
  +        explicit ref/deref. Changed m_createTime to be a DOMTimeStamp instead of a QDateTime.
  +        (DOM::EventImpl::setTarget): Now inlined.
  +        (DOM::EventImpl::timeStamp): Now inlined.
  +        (DOM::EventImpl::preventDefault): Now inlined.
  +        (DOM::EventImpl::dispatched): Added. Returns true if the event was already dispatched,
  +        meaning it already has a target.
  +
  +        * khtml/xml/dom2_eventsimpl.cpp:
  +        (DOM::currentTimeStamp): Added. Faster inline version on Mac OS X, since this shows
  +        up in profiles.
  +        (DOM::EventImpl::EventImpl): Changed to use contructor syntax and set m_createTime to
  +        currentTimeStamp().
  +        (DOM::EventImpl::~EventImpl): Removed explicit derefs; no longer needed.
  +        (DOM::EventImpl::initEvent): Do nothing if dispatched() is true. Simplify since
  +        SharedPtr handles ref/deref.
  +        (DOM::UIEventImpl::UIEventImpl): Changed to use contructor syntax and take advantage
  +        of the fact that some data members are now SharedPtr.
  +        (DOM::UIEventImpl::initUIEvent): Do nothing if dispatched() is true. Simplify since
  +        SharedPtr handles ref/deref.
  +        (DOM::MouseEventImpl::MouseEventImpl): Changed to use contructor syntax and take advantage
  +        of the fact that some data members are now SharedPtr.
  +        (DOM::MouseEventImpl::~MouseEventImpl): Removed explicit derefs; no longer needed.
  +        (DOM::MouseEventImpl::initMouseEvent): Do nothing if dispatched() is true. Simplify since
  +        SharedPtr handles ref/deref.
  +        (DOM::MouseEventImpl::isDragEvent): Use a local variable.
  +        (DOM::KeyboardEventImpl::KeyboardEventImpl): Changed to use contructor syntax and take
  +        advantage of the fact that some data members are now SharedPtr.
  +        (DOM::KeyboardEventImpl::~KeyboardEventImpl): Removed explicit derefs; no longer needed.
  +        (DOM::KeyboardEventImpl::initKeyboardEvent): Do nothing if dispatched() is true. Simplify
  +        since SharedPtr handles ref/deref.
  +        (DOM::MutationEventImpl::MutationEventImpl): Changed to use contructor syntax and take
  +        advantage of the fact that some data members are now SharedPtr.
  +        (DOM::MutationEventImpl::initMutationEvent): Do nothing if dispatched() is true. Simplify
  +        since SharedPtr handles ref/deref.
  +        (DOM::ClipboardEventImpl::ClipboardEventImpl): Simplify since SharedPtr handles initialization
  +        and ref/deref.
  +        (DOM::RegisteredEventListener::RegisteredEventListener): Ditto.
  +
   2005-10-24  Geoffrey Garen  <ggaren at apple.com>
   
           Patch by Niels Leenheer.
  
  
  
  1.15      +5 -1      WebCore/khtml/dom/dom_node.h
  
  Index: dom_node.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/dom/dom_node.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- dom_node.h	16 Sep 2005 22:42:03 -0000	1.14
  +++ dom_node.h	25 Oct 2005 16:39:24 -0000	1.15
  @@ -21,7 +21,7 @@
    * This file includes excerpts from the Document Object Model (DOM)
    * Level 1 Specification (Recommendation)
    * http://www.w3.org/TR/REC-DOM-Level-1/
  - * Copyright © World Wide Web Consortium , (Massachusetts Institute of
  + * Copyright � World Wide Web Consortium , (Massachusetts Institute of
    * Technology , Institut National de Recherche en Informatique et en
    * Automatique , Keio University ). All Rights Reserved.
    *
  @@ -972,7 +972,11 @@
    * A DOMTimeStamp represents a number of milliseconds.
    *
    */
  +#if __APPLE__
  +typedef unsigned long long DOMTimeStamp;
  +#else
   typedef unsigned long DOMTimeStamp;
  +#endif
   
   } //namespace
   
  
  
  
  1.40      +80 -195   WebCore/khtml/xml/dom2_eventsimpl.cpp
  
  Index: dom2_eventsimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom2_eventsimpl.cpp,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- dom2_eventsimpl.cpp	3 Oct 2005 21:12:50 -0000	1.39
  +++ dom2_eventsimpl.cpp	25 Oct 2005 16:39:25 -0000	1.40
  @@ -25,83 +25,68 @@
   #include "xml/dom2_eventsimpl.h"
   
   #include "dom/dom2_events.h"
  -#include "xml/dom_stringimpl.h"
  -#include "xml/dom_nodeimpl.h"
   #include "xml/dom_docimpl.h"
   #include "xml/dom2_viewsimpl.h"
   #include "xml/EventNames.h"
  -#include "rendering/render_object.h"
   #include "rendering/render_layer.h"
   
  -#include <kdebug.h>
  -
   using khtml::RenderObject;
  -
  -using namespace DOM::EventNames;
  +using khtml::RenderLayer;
   
   namespace DOM {
   
  -EventImpl::EventImpl()
  -{
  -    m_canBubble = false;
  -    m_cancelable = false;
  -
  -    m_propagationStopped = false;
  -    m_defaultPrevented = false;
  -    m_cancelBubble = false;
  -    m_currentTarget = 0;
  -    m_eventPhase = 0;
  -    m_target = 0;
  -    m_createTime = QDateTime::currentDateTime();
  -    m_defaultHandled = false;
  -}
  +using namespace EventNames;
   
  -EventImpl::EventImpl(const AtomicString &eventType, bool canBubbleArg, bool cancelableArg)
  -    : m_type(eventType)
  +#if __APPLE__
  +inline DOMTimeStamp currentTimeStamp()
   {
  -    m_canBubble = canBubbleArg;
  -    m_cancelable = cancelableArg;
  -
  -    m_propagationStopped = false;
  -    m_defaultPrevented = false;
  -    m_cancelBubble = false;
  -    m_currentTarget = 0;
  -    m_eventPhase = 0;
  -    m_target = 0;
  -    m_createTime = QDateTime::currentDateTime();
  -    m_defaultHandled = false;
  +    // Since this shows up on profiles, do this an even faster way on Mac OS X.
  +    return static_cast<DOMTimeStamp>((CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) * 1000);
   }
  -
  -EventImpl::~EventImpl()
  +#else
  +static DOMTimeStamp currentTimeStamp()
   {
  -    if (m_target)
  -        m_target->deref();
  +    QDateTime currentDateTime = QDateTime::currentDateTime();
  +    QDateTime epoch(QDate(1970, 1, 1), QTime());
  +    return epoch.secsTo(currentDateTime) * 1000LL + currentDateTime.time().msec();
   }
  +#endif
   
  -void EventImpl::setTarget(NodeImpl *_target)
  +EventImpl::EventImpl()
  +    : m_canBubble(false)
  +    , m_cancelable(false)
  +    , m_propagationStopped(false)
  +    , m_defaultPrevented(false)
  +    , m_defaultHandled(false)
  +    , m_cancelBubble(false)
  +    , m_currentTarget(0)
  +    , m_eventPhase(0)
  +    , m_createTime(currentTimeStamp())
   {
  -    if (m_target)
  -        m_target->deref();
  -    m_target = _target;
  -    if (m_target)
  -        m_target->ref();
   }
   
  -DOMTimeStamp EventImpl::timeStamp()
  +EventImpl::EventImpl(const AtomicString &eventType, bool canBubbleArg, bool cancelableArg)
  +    : m_type(eventType)
  +    , m_canBubble(canBubbleArg)
  +    , m_cancelable(cancelableArg)
  +    , m_propagationStopped(false)
  +    , m_defaultPrevented(false)
  +    , m_defaultHandled(false)
  +    , m_cancelBubble(false)
  +    , m_currentTarget(0)
  +    , m_eventPhase(0)
  +    , m_createTime(currentTimeStamp())
   {
  -    QDateTime epoch(QDate(1970, 1, 1), QTime(0, 0));
  -    return static_cast<DOMTimeStamp>(epoch.secsTo(m_createTime)) * 1000 + m_createTime.time().msec();
   }
   
  -void EventImpl::preventDefault()
  +EventImpl::~EventImpl()
   {
  -    if (m_cancelable)
  -	m_defaultPrevented = true;
   }
   
   void EventImpl::initEvent(const AtomicString &eventTypeArg, bool canBubbleArg, bool cancelableArg)
   {
  -    // ### ensure this is not called after we have been dispatched (also for subclasses)
  +    if (dispatched())
  +        return;
   
       m_type = eventTypeArg;
       m_canBubble = canBubbleArg;
  @@ -146,24 +131,15 @@
   // -----------------------------------------------------------------------------
   
   UIEventImpl::UIEventImpl()
  +    : m_detail(0)
   {
  -    m_view = 0;
  -    m_detail = 0;
   }
   
   UIEventImpl::UIEventImpl(const AtomicString &eventType, bool canBubbleArg, bool cancelableArg, AbstractViewImpl *viewArg, int detailArg)
       : EventImpl(eventType, canBubbleArg, cancelableArg)
  +    , m_view(viewArg)
  +    , m_detail(detailArg)
   {
  -    m_view = viewArg;
  -    if (m_view)
  -        m_view->ref();
  -    m_detail = detailArg;
  -}
  -
  -UIEventImpl::~UIEventImpl()
  -{
  -    if (m_view)
  -        m_view->deref();
   }
   
   void UIEventImpl::initUIEvent(const AtomicString &typeArg,
  @@ -172,14 +148,12 @@
   			      AbstractViewImpl *viewArg,
   			      int detailArg)
   {
  -    EventImpl::initEvent(typeArg,canBubbleArg,cancelableArg);
  +    if (dispatched())
  +        return;
   
  -    if (m_view)
  -	m_view->deref();
  +    initEvent(typeArg, canBubbleArg, cancelableArg);
   
       m_view = viewArg;
  -    if (m_view)
  -	m_view->ref();
       m_detail = detailArg;
   }
   
  @@ -282,7 +256,7 @@
   
       node->renderer()->enclosingLayer()->updateLayerPosition();
       
  -    for (khtml::RenderLayer *layer = node->renderer()->enclosingLayer(); layer != NULL; layer = layer->parent()) {
  +    for (RenderLayer *layer = node->renderer()->enclosingLayer(); layer; layer = layer->parent()) {
   	m_layerX -= layer->xPos();
   	m_layerY -= layer->yPos();
       }
  @@ -301,10 +275,8 @@
   // -----------------------------------------------------------------------------
   
   MouseEventImpl::MouseEventImpl()
  +    : m_button(0)
   {
  -    m_button = 0;
  -    m_relatedTarget = 0;
  -    m_clipboard = 0;
   }
   
   MouseEventImpl::MouseEventImpl(const AtomicString &eventType,
  @@ -326,22 +298,14 @@
       : MouseRelatedEventImpl(eventType, canBubbleArg, cancelableArg, viewArg, detailArg,
           screenXArg, screenYArg, clientXArg, clientYArg,
           ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg)
  +    , m_button(buttonArg)
  +    , m_relatedTarget(relatedTargetArg)
  +    , m_clipboard(clipboardArg)
   {
  -    m_button = buttonArg;
  -    m_relatedTarget = relatedTargetArg;
  -    if (m_relatedTarget)
  -	m_relatedTarget->ref();
  -    m_clipboard = clipboardArg;
  -    if (m_clipboard)
  -	m_clipboard->ref();
   }
   
   MouseEventImpl::~MouseEventImpl()
   {
  -    if (m_relatedTarget)
  -	m_relatedTarget->deref();
  -    if (m_clipboard)
  -	m_clipboard->deref();
   }
   
   void MouseEventImpl::initMouseEvent(const AtomicString &typeArg,
  @@ -360,10 +324,10 @@
                                       unsigned short buttonArg,
                                       NodeImpl *relatedTargetArg)
   {
  -    UIEventImpl::initUIEvent(typeArg,canBubbleArg,cancelableArg,viewArg,detailArg);
  +    if (dispatched())
  +        return;
   
  -    if (m_relatedTarget)
  -	m_relatedTarget->deref();
  +    initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
   
       m_screenX = screenXArg;
       m_screenY = screenYArg;
  @@ -375,8 +339,6 @@
       m_metaKey = metaKeyArg;
       m_button = buttonArg;
       m_relatedTarget = relatedTargetArg;
  -    if (m_relatedTarget)
  -	m_relatedTarget->ref();
       computeLayerPos();
   }
   
  @@ -387,10 +349,10 @@
   
   bool MouseEventImpl::isDragEvent() const
   {
  -    return (m_type == dragenterEvent || m_type == dragoverEvent
  -            || m_type == dragleaveEvent || m_type == dropEvent 
  -            || m_type == dragstartEvent || m_type == dragEvent
  -            || m_type == dragendEvent);
  +    const AtomicString &t = type();
  +    return t == dragenterEvent || t == dragoverEvent || t == dragleaveEvent
  +        || t == dropEvent
  +        || t == dragstartEvent || t == dragEvent || t == dragendEvent;
   }
   
   int MouseEventImpl::which() const
  @@ -404,11 +366,10 @@
   //---------------------------------------------------------------------------------------------
   
   KeyboardEventImpl::KeyboardEventImpl()
  +  : m_keyEvent(0)
  +  , m_keyLocation(KeyboardEvent::DOM_KEY_LOCATION_STANDARD)
  +  , m_altGraphKey(false)
   {
  -  m_keyEvent = 0;
  -  m_keyIdentifier = 0;
  -  m_keyLocation = KeyboardEvent::DOM_KEY_LOCATION_STANDARD;
  -  m_altGraphKey = false;
   }
   
   KeyboardEventImpl::KeyboardEventImpl(QKeyEvent *key, AbstractViewImpl *view)
  @@ -418,28 +379,11 @@
       key->state() & Qt::AltButton,
       key->state() & Qt::ShiftButton,
       key->state() & Qt::MetaButton)
  +  , m_keyEvent(new QKeyEvent(*key))
  +  , m_keyIdentifier(DOMString(key->keyIdentifier()).impl())
  +  , m_keyLocation((key->state() & Qt::Keypad) ? KeyboardEvent::DOM_KEY_LOCATION_NUMPAD : KeyboardEvent::DOM_KEY_LOCATION_STANDARD)
  +  , m_altGraphKey(false)
   {
  -#if APPLE_CHANGES
  -    m_keyEvent = new QKeyEvent(*key);
  -#else
  -    m_keyEvent = new QKeyEvent(key->type(), key->key(), key->ascii(), key->state(), key->text(), key->isAutoRepeat(), key->count());
  -#endif
  -
  -#if APPLE_CHANGES
  -    DOMString identifier(key->keyIdentifier());
  -    m_keyIdentifier = identifier.impl();
  -    m_keyIdentifier->ref();
  -#else
  -    m_keyIdentifier = 0;
  -    // need the equivalent of the above for KDE
  -#endif
  -
  -    int keyState = key->state();
  -
  -    m_altGraphKey = false; // altGraphKey is not supported by Qt.
  -    
  -    // Note: we only support testing for num pad
  -    m_keyLocation = (keyState & Qt::Keypad) ? KeyboardEvent::DOM_KEY_LOCATION_NUMPAD : KeyboardEvent::DOM_KEY_LOCATION_STANDARD;
   }
   
   KeyboardEventImpl::KeyboardEventImpl(const AtomicString &eventType,
  @@ -454,20 +398,16 @@
                                           bool metaKeyArg, 
                                           bool altGraphKeyArg)
     : UIEventWithKeyStateImpl(eventType, canBubbleArg, cancelableArg, viewArg, 0, ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg)
  +  , m_keyEvent(0)
  +  , m_keyIdentifier(keyIdentifierArg.impl())
  +  , m_keyLocation(keyLocationArg)
  +  , m_altGraphKey(altGraphKeyArg)
   {
  -    m_keyEvent = 0;
  -    m_keyIdentifier = keyIdentifierArg.impl();
  -    if (m_keyIdentifier)
  -        m_keyIdentifier->ref();
  -    m_keyLocation = keyLocationArg;
  -    m_altGraphKey = altGraphKeyArg;
   }
   
   KeyboardEventImpl::~KeyboardEventImpl()
   {
       delete m_keyEvent;
  -    if (m_keyIdentifier)
  -        m_keyIdentifier->deref();
   }
   
   void KeyboardEventImpl::initKeyboardEvent(const AtomicString &typeArg,
  @@ -482,13 +422,12 @@
                           bool metaKeyArg, 
                           bool altGraphKeyArg)
   {
  -    if (m_keyIdentifier)
  -        m_keyIdentifier->deref();
  +    if (dispatched())
  +        return;
  +
  +    initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
   
  -    UIEventImpl::initUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
       m_keyIdentifier = keyIdentifierArg.impl();
  -    if (m_keyIdentifier)
  -        m_keyIdentifier->ref();
       m_keyLocation = keyLocationArg;
       m_ctrlKey = ctrlKeyArg;
       m_shiftKey = shiftKeyArg;
  @@ -501,7 +440,7 @@
   {
       if (!m_keyEvent)
           return 0;
  -    if (m_type == keydownEvent || m_type == keyupEvent)
  +    if (type() == keydownEvent || type() == keyupEvent)
           return m_keyEvent->WindowsKeyCode();
       return charCode();
   }
  @@ -533,12 +472,8 @@
   // -----------------------------------------------------------------------------
   
   MutationEventImpl::MutationEventImpl()
  +    : m_attrChange(0)
   {
  -    m_relatedNode = 0;
  -    m_prevValue = 0;
  -    m_newValue = 0;
  -    m_attrName = 0;
  -    m_attrChange = 0;
   }
   
   MutationEventImpl::MutationEventImpl(const AtomicString &eventType,
  @@ -549,33 +484,13 @@
   				     const DOMString &newValueArg,
   				     const DOMString &attrNameArg,
   				     unsigned short attrChangeArg)
  -		      : EventImpl(eventType,canBubbleArg,cancelableArg)
  -{
  -    m_relatedNode = relatedNodeArg;
  -    if (m_relatedNode)
  -	m_relatedNode->ref();
  -    m_prevValue = prevValueArg.impl();
  -    if (m_prevValue)
  -	m_prevValue->ref();
  -    m_newValue = newValueArg.impl();
  -    if (m_newValue)
  -	m_newValue->ref();
  -    m_attrName = attrNameArg.impl();
  -    if (m_attrName)
  -	m_attrName->ref();
  -    m_attrChange = attrChangeArg;
  -}
  -
  -MutationEventImpl::~MutationEventImpl()
  +    : EventImpl(eventType, canBubbleArg, cancelableArg)
  +    , m_relatedNode(relatedNodeArg)
  +    , m_prevValue(prevValueArg.impl())
  +    , m_newValue(newValueArg.impl())
  +    , m_attrName(attrNameArg.impl())
  +    , m_attrChange(attrChangeArg)
   {
  -    if (m_relatedNode)
  -	m_relatedNode->deref();
  -    if (m_prevValue)
  -	m_prevValue->deref();
  -    if (m_newValue)
  -	m_newValue->deref();
  -    if (m_attrName)
  -	m_attrName->deref();
   }
   
   void MutationEventImpl::initMutationEvent(const AtomicString &typeArg,
  @@ -587,29 +502,15 @@
   					  const DOMString &attrNameArg,
   					  unsigned short attrChangeArg)
   {
  -    EventImpl::initEvent(typeArg,canBubbleArg,cancelableArg);
  +    if (dispatched())
  +        return;
   
  -    if (m_relatedNode)
  -	m_relatedNode->deref();
  -    if (m_prevValue)
  -	m_prevValue->deref();
  -    if (m_newValue)
  -	m_newValue->deref();
  -    if (m_attrName)
  -	m_attrName->deref();
  +    initEvent(typeArg, canBubbleArg, cancelableArg);
   
       m_relatedNode = relatedNodeArg;
  -    if (m_relatedNode)
  -	m_relatedNode->ref();
       m_prevValue = prevValueArg.impl();
  -    if (m_prevValue)
  -	m_prevValue->ref();
       m_newValue = newValueArg.impl();
  -    if (m_newValue)
  -	m_newValue->ref();
       m_attrName = attrNameArg.impl();
  -    if (m_attrName)
  -	m_attrName->ref();
       m_attrChange = attrChangeArg;
   }
   
  @@ -622,20 +523,11 @@
   
   ClipboardEventImpl::ClipboardEventImpl()
   {
  -    m_clipboard = 0;
   }
   
   ClipboardEventImpl::ClipboardEventImpl(const AtomicString &eventType, bool canBubbleArg, bool cancelableArg, ClipboardImpl *clipboardArg)
       : EventImpl(eventType, canBubbleArg, cancelableArg), m_clipboard(clipboardArg)
   {
  -      if (m_clipboard)
  -          m_clipboard->ref();
  -}
  -
  -ClipboardEventImpl::~ClipboardEventImpl()
  -{
  -    if (m_clipboard)
  -        m_clipboard->deref();
   }
   
   bool ClipboardEventImpl::isClipboardEvent() const
  @@ -667,13 +559,6 @@
   RegisteredEventListener::RegisteredEventListener(const AtomicString &eventType, EventListener *listener, bool useCapture)
       : m_eventType(eventType), m_listener(listener), m_useCapture(useCapture)
   {
  -    assert(listener);
  -    listener->ref();
  -}
  -
  -RegisteredEventListener::~RegisteredEventListener()
  -{
  -    m_listener->deref();
   }
   
   bool operator==(const RegisteredEventListener &a, const RegisteredEventListener &b)
  
  
  
  1.33      +35 -44    WebCore/khtml/xml/dom2_eventsimpl.h
  
  Index: dom2_eventsimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom2_eventsimpl.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- dom2_eventsimpl.h	3 Oct 2005 21:12:50 -0000	1.32
  +++ dom2_eventsimpl.h	25 Oct 2005 16:39:25 -0000	1.33
  @@ -25,9 +25,10 @@
   #ifndef DOM_EVENTSIMPL_H
   #define DOM_EVENTSIMPL_H
   
  -#include <qdatetime.h>
   #include "dom/dom_node.h"
  +#include "xml/dom_nodeimpl.h"
   #include "xml/dom_atomicstring.h"
  +#include "xml/dom2_viewsimpl.h"
   #include "misc/shared.h"
   
   class KHTMLPart;
  @@ -38,10 +39,7 @@
   
   namespace DOM {
   
  -class AbstractViewImpl;
  -class DOMStringImpl;
   class EventListener;
  -class NodeImpl;
   class ClipboardImpl;
   
   class EventImpl : public khtml::Shared<EventImpl>
  @@ -52,24 +50,24 @@
       virtual ~EventImpl();
   
       const AtomicString &type() const { return m_type; }
  -    NodeImpl *target() const { return m_target; }
  -    void setTarget(NodeImpl *target);
  +    NodeImpl *target() const { return m_target.get(); }
  +    void setTarget(NodeImpl *target) { m_target = target; }
       NodeImpl *currentTarget() const { return m_currentTarget; }
       void setCurrentTarget(NodeImpl *currentTarget) { m_currentTarget = currentTarget; }
       unsigned short eventPhase() const { return m_eventPhase; }
       void setEventPhase(unsigned short eventPhase) { m_eventPhase = eventPhase; }
       bool bubbles() const { return m_canBubble; }
       bool cancelable() const { return m_cancelable; }
  -    DOMTimeStamp timeStamp();
  +    DOMTimeStamp timeStamp() { return m_createTime; }
       void stopPropagation() { m_propagationStopped = true; }
  -    void preventDefault();
  +    void preventDefault() { if (m_cancelable) m_defaultPrevented = true; }
       void initEvent(const AtomicString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
   
       virtual bool isUIEvent() const;
       virtual bool isMouseEvent() const;
       virtual bool isMutationEvent() const;
       virtual bool isKeyboardEvent() const;
  -    virtual bool isDragEvent() const;   // a subset of mouse events
  +    virtual bool isDragEvent() const; // a subset of mouse events
       virtual bool isClipboardEvent() const;
       virtual bool isWheelEvent() const;
   
  @@ -84,6 +82,9 @@
       bool getCancelBubble() const { return m_cancelBubble; }
   
   protected:
  +    bool dispatched() const { return m_target; }
  +
  +private:
       AtomicString m_type;
       bool m_canBubble;
       bool m_cancelable;
  @@ -95,12 +96,10 @@
   
       NodeImpl *m_currentTarget; // ref > 0 maintained externally
       unsigned short m_eventPhase;
  -    NodeImpl *m_target;
  -    QDateTime m_createTime;
  +    SharedPtr<NodeImpl> m_target;
  +    DOMTimeStamp m_createTime;
   };
   
  -
  -
   class UIEventImpl : public EventImpl
   {
   public:
  @@ -110,8 +109,7 @@
   		bool cancelableArg,
   		AbstractViewImpl *viewArg,
   		int detailArg);
  -    virtual ~UIEventImpl();
  -    AbstractViewImpl *view() const { return m_view; }
  +    AbstractViewImpl *view() const { return m_view.get(); }
       int detail() const { return m_detail; }
       void initUIEvent(const AtomicString &typeArg,
   		     bool canBubbleArg,
  @@ -131,10 +129,9 @@
   
       virtual int which() const;
   
  -protected:
  -    AbstractViewImpl *m_view;
  +private:
  +    SharedPtr<AbstractViewImpl> m_view;
       int m_detail;
  -
   };
   
   class UIEventWithKeyStateImpl : public UIEventImpl {
  @@ -215,8 +212,8 @@
                      ClipboardImpl *clipboardArg=0);
       virtual ~MouseEventImpl();
       unsigned short button() const { return m_button; }
  -    NodeImpl *relatedTarget() const { return m_relatedTarget; }
  -    ClipboardImpl *clipboard() const { return m_clipboard; }
  +    NodeImpl *relatedTarget() const { return m_relatedTarget.get(); }
  +    ClipboardImpl *clipboard() const { return m_clipboard.get(); }
       void initMouseEvent(const AtomicString &typeArg,
   			bool canBubbleArg,
   			bool cancelableArg,
  @@ -237,8 +234,8 @@
       virtual int which() const;
   private:
       unsigned short m_button;
  -    NodeImpl *m_relatedTarget;
  -    ClipboardImpl *m_clipboard;
  +    SharedPtr<NodeImpl> m_relatedTarget;
  +    SharedPtr<ClipboardImpl> m_clipboard;
   };
   
   
  @@ -272,7 +269,7 @@
                   bool metaKeyArg,
                   bool altGraphKeyArg);
       
  -    DOMString keyIdentifier() const { return m_keyIdentifier; }
  +    DOMString keyIdentifier() const { return m_keyIdentifier.get(); }
       unsigned keyLocation() const { return m_keyLocation; }
       
       bool altGraphKey() const { return m_altGraphKey; }
  @@ -287,7 +284,7 @@
   
   private:
       QKeyEvent *m_keyEvent;
  -    DOMStringImpl *m_keyIdentifier;
  +    SharedPtr<DOMStringImpl> m_keyIdentifier;
       unsigned m_keyLocation;
       bool m_altGraphKey : 1;
   };
  @@ -304,12 +301,11 @@
   		      const DOMString &newValueArg,
   		      const DOMString &attrNameArg,
   		      unsigned short attrChangeArg);
  -    ~MutationEventImpl();
   
  -    NodeImpl *relatedNode() const { return m_relatedNode; }
  -    DOMString prevValue() const { return m_prevValue; }
  -    DOMString newValue() const { return m_newValue; }
  -    DOMString attrName() const { return m_attrName; }
  +    NodeImpl *relatedNode() const { return m_relatedNode.get(); }
  +    DOMString prevValue() const { return m_prevValue.get(); }
  +    DOMString newValue() const { return m_newValue.get(); }
  +    DOMString attrName() const { return m_attrName.get(); }
       unsigned short attrChange() const { return m_attrChange; }
       void initMutationEvent(const AtomicString &typeArg,
   			   bool canBubbleArg,
  @@ -320,11 +316,11 @@
   			   const DOMString &attrNameArg,
   			   unsigned short attrChangeArg);
       virtual bool isMutationEvent() const;
  -protected:
  -    NodeImpl *m_relatedNode;
  -    DOMStringImpl *m_prevValue;
  -    DOMStringImpl *m_newValue;
  -    DOMStringImpl *m_attrName;
  +private:
  +    SharedPtr<NodeImpl> m_relatedNode;
  +    SharedPtr<DOMStringImpl> m_prevValue;
  +    SharedPtr<DOMStringImpl> m_newValue;
  +    SharedPtr<DOMStringImpl> m_attrName;
       unsigned short m_attrChange;
   };
   
  @@ -332,12 +328,11 @@
   public:
       ClipboardEventImpl();
       ClipboardEventImpl(const AtomicString &type, bool canBubbleArg, bool cancelableArg, ClipboardImpl *clipboardArg);
  -    ~ClipboardEventImpl();
   
  -    ClipboardImpl *clipboard() const { return m_clipboard; }
  +    ClipboardImpl *clipboard() const { return m_clipboard.get(); }
       virtual bool isClipboardEvent() const;
  -protected:
  -    ClipboardImpl *m_clipboard;
  +private:
  +    SharedPtr<ClipboardImpl> m_clipboard;
   };
   
   // extension: mouse wheel event
  @@ -362,19 +357,15 @@
   class RegisteredEventListener {
   public:
       RegisteredEventListener(const AtomicString &eventType, EventListener *listener, bool useCapture);
  -    ~RegisteredEventListener();
   
       const AtomicString &eventType() const { return m_eventType; }
  -    EventListener *listener() const { return m_listener; }
  +    EventListener *listener() const { return m_listener.get(); }
       bool useCapture() const { return m_useCapture; }
   
   private:
       AtomicString m_eventType;
  -    EventListener *m_listener;
  +    SharedPtr<EventListener> m_listener;
       bool m_useCapture;
  -
  -    RegisteredEventListener(const RegisteredEventListener &);
  -    RegisteredEventListener &operator=(const RegisteredEventListener &);
   };
   
   bool operator==(const RegisteredEventListener &, const RegisteredEventListener &);
  
  
  
  1.202     +3 -0      WebCore/khtml/xml/dom_nodeimpl.cpp
  
  Index: dom_nodeimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_nodeimpl.cpp,v
  retrieving revision 1.201
  retrieving revision 1.202
  diff -u -r1.201 -r1.202
  --- dom_nodeimpl.cpp	25 Oct 2005 00:07:47 -0000	1.201
  +++ dom_nodeimpl.cpp	25 Oct 2005 16:39:25 -0000	1.202
  @@ -550,6 +550,8 @@
   
   bool NodeImpl::dispatchGenericEvent( EventImpl *evt, int &/*exceptioncode */)
   {
  +    assert(evt->target());
  +
       evt->ref();
   
       // ### check that type specified
  @@ -659,6 +661,7 @@
       evt->ref();
       DocumentPtr *doc = document;
       doc->ref();
  +    evt->setTarget(doc->document());
       bool r = dispatchGenericEvent( evt, exceptioncode );
       if (!evt->defaultPrevented() && doc->document())
   	doc->document()->defaultEventHandler(evt);
  
  
  
  1.54      +8 -0      LayoutTests/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/LayoutTests/ChangeLog,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- ChangeLog	25 Oct 2005 03:46:47 -0000	1.53
  +++ ChangeLog	25 Oct 2005 16:39:25 -0000	1.54
  @@ -1,3 +1,11 @@
  +2005-10-25  Darin Adler  <darin at apple.com>
  +
  +        - added test for http://bugzilla.opendarwin.org/show_bug.cgi?id=4945
  +          event init calls should not do anything if the event has already been dispatched
  +
  +        * fast/events/init-event-after-dispatch-expected.txt: Added.
  +        * fast/events/init-event-after-dispatch.html: Added.
  +
   2005-10-24  Geoffrey Garen  <ggaren at apple.com>
   
           Reviewed by hyatt.
  
  
  
  1.1                  LayoutTests/fast/events/init-event-after-dispatch-expected.txt
  
  Index: init-event-after-dispatch-expected.txt
  ===================================================================
  This test checks to see if you can change an event after it's dispatched. The DOM standard says that you can't, and that the various init functions do nothing once an event is dispatched.
  
  If the test passes, the attempts to change an event below should fail.
  
  Received an event, type is load
  Target is [object HTMLDocument]
  Trying to change the type to unload
  Event type is now load
  
  
  
  
  1.1                  LayoutTests/fast/events/init-event-after-dispatch.html
  
  Index: init-event-after-dispatch.html
  ===================================================================
  <head>
  <script>
  function print(message)
  {
      var paragraph = document.createElement("li");
      paragraph.appendChild(document.createTextNode(message));
      document.getElementById("console").appendChild(paragraph);
  }
  function test(event)
  {
      if (window.layoutTestController)
          layoutTestController.dumpAsText();
  
      print("Received an event, type is " + event.type);
      print("Target is " + event.target);
      print("Trying to change the type to unload");
      event.initEvent("unload", true, true);
      print("Event type is now " + event.type);
  }
  </script>
  </head>
  <body onload="test(event)">
  <p>This test checks to see if you can change an event after it's dispatched. The DOM standard says that you can't,
  and that the various init functions do nothing once an event is dispatched.</p>
  <p>If the test passes, the attempts to change an event below should fail.</p>
  <hr>
  <p><ol id=console></ol></p>
  </body>
  
  
  



More information about the webkit-changes mailing list