2008-12-13 Darin Adler <darin@apple.com>
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Dec 2008 22:53:55 +0000 (22:53 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Dec 2008 22:53:55 +0000 (22:53 +0000)
        Reviewed by Anders Carlsson.

        - https://bugs.webkit.org/show_bug.cgi?id=17497
          eliminate DeprecatedValueList

        * css/CSSStyleDeclaration.cpp: Removed unneeded include.

        * dom/Document.cpp:
        (WebCore::Document::removeAllEventListenersFromAllNodes):
        Set the removed flag on the window event listeners in case we
        are in the middle of dispatching events on this window.
        (WebCore::Document::clear): Ditto.
        (WebCore::Document::handleWindowEvent): Changed to use a vector
        instead of a DeprecatedPtrList.
        (WebCore::Document::windowInlineEventListenerForType): Ditto.
        (WebCore::Document::removeWindowInlineEventListenerForType): Ditto.
        Also added a call to setRemoved, which is needed here just as in
        other functions that remove.
        (WebCore::Document::removeWindowEventListener): Ditto.
        (WebCore::Document::hasWindowEventListener): Ditto.

        * dom/Document.h: Changed RegisteredEventListenerList to
        RegisteredEventListeners.

        * dom/Element.cpp:
        (WebCore::Element::attach): Use a function to access rare data instead
        of getting directly at the data field.
        (WebCore::Element::focus): Ditto.
        (WebCore::Element::cancelFocusAppearanceUpdate): Ditto.

        * dom/ElementRareData.h: Use "using" to make things that are protected
        in NodeRareData be public here.

        * dom/EventTarget.h: Removed include of DeprecatedValueList and
        related declearations that weren't needed. Tweaked the definitions
        of the forbidEventDispatch functions too.

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::EventTargetNode): Eliminated code that
        was used to initialized m_regdListeners.
        (WebCore::EventTargetNode::~EventTargetNode): Elminated delete of
        m_regdListeners. Changed code to use eventListeners() instead of
        m_regdListeners.
        (WebCore::EventTargetNode::eventListeners): Added.
        (WebCore::EventTargetNode::insertedIntoDocument): Use eventListeners.
        (WebCore::EventTargetNode::removedFromDocument): Ditto.
        (WebCore::EventTargetNode::willMoveToNewOwnerDocument): Ditto.
        (WebCore::EventTargetNode::didMoveToNewOwnerDocument): Ditto.
        (WebCore::EventTargetNode::addEventListener): Ditto.
        (WebCore::EventTargetNode::removeEventListener): Ditto.
        (WebCore::EventTargetNode::removeAllEventListeners): Ditto.
        Also added code to call setRemoved on all the listeners.
        (WebCore::EventTargetNode::handleLocalEvents): Ditto.
        (WebCore::EventTargetNode::dispatchGenericEvent): Fixed indentation.
        (WebCore::EventTargetNode::removeInlineEventListenerForType): Use
        the new event listeners vector. Also added missing call to setRemoved.
        (WebCore::EventTargetNode::inlineEventListenerForType): Ditto.

        * dom/EventTargetNode.h: Added a new RegisteredEventListenerVector
        type and replaced the old localEventListeners function with a new
        eventListeners function. Removed m_regdListeners.

        * dom/Node.cpp:
        (WebCore::Node::childNodes): Removed unneeded std prefix.
        (WebCore::Node::setFocus): Use function instead of going directly
        at rare data.
        (WebCore::Node::rareDataFocused): Ditto.
        (WebCore::Node::registerDynamicNodeList): Removed unneeded std prefix.
        (WebCore::Node::getElementsByName): Ditto.
        (WebCore::Node::getElementsByClassName): Ditto.
        (WebCore::Node::compareDocumentPosition): Ditto.

        * dom/Node.h: Removed unneeded forward declaration of
        RegisteredEventListener. This is now in EventTargetNode.

        * dom/NodeRareData.h: Renamed m_focused to m_isFocused and made it
        private. Made m_needsFocusAppearanceUpdateSoonAfterAttach private.
        Added listeners and ensureListeners functions as well as isFocused,
        setFocused, and focus-appearance functions. Made all data members private.

        * dom/RegisteredEventListener.cpp: Removed operator ==.
        * dom/RegisteredEventListener.h: Removed operator == and !=.

        * svg/SVGElement.cpp:
        (WebCore::hasLoadListener): Rewrote to work with the vector.
        * svg/SVGUseElement.cpp:
        (WebCore::SVGUseElement::transferEventListenersToShadowTree): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39279 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
WebCore/ChangeLog
WebCore/css/CSSStyleDeclaration.cpp
WebCore/dom/Document.cpp
WebCore/dom/Document.h
WebCore/dom/Element.cpp
WebCore/dom/ElementRareData.h
WebCore/dom/EventTarget.h
WebCore/dom/EventTargetNode.cpp
WebCore/dom/EventTargetNode.h
WebCore/dom/Node.cpp
WebCore/dom/Node.h
WebCore/dom/NodeRareData.h
WebCore/dom/RegisteredEventListener.cpp
WebCore/dom/RegisteredEventListener.h
WebCore/svg/SVGElement.cpp
WebCore/svg/SVGUseElement.cpp

index e50864f..4b3955e 100644 (file)
@@ -1,3 +1,93 @@
+2008-12-13  Darin Adler  <darin@apple.com>
+
+        Reviewed by Anders Carlsson.
+
+        - https://bugs.webkit.org/show_bug.cgi?id=17497
+          eliminate DeprecatedValueList
+
+        * css/CSSStyleDeclaration.cpp: Removed unneeded include.
+
+        * dom/Document.cpp:
+        (WebCore::Document::removeAllEventListenersFromAllNodes):
+        Set the removed flag on the window event listeners in case we
+        are in the middle of dispatching events on this window.
+        (WebCore::Document::clear): Ditto.
+        (WebCore::Document::handleWindowEvent): Changed to use a vector
+        instead of a DeprecatedPtrList.
+        (WebCore::Document::windowInlineEventListenerForType): Ditto.
+        (WebCore::Document::removeWindowInlineEventListenerForType): Ditto.
+        Also added a call to setRemoved, which is needed here just as in
+        other functions that remove.
+        (WebCore::Document::removeWindowEventListener): Ditto.
+        (WebCore::Document::hasWindowEventListener): Ditto.
+
+        * dom/Document.h: Changed RegisteredEventListenerList to
+        RegisteredEventListeners.
+
+        * dom/Element.cpp:
+        (WebCore::Element::attach): Use a function to access rare data instead
+        of getting directly at the data field.
+        (WebCore::Element::focus): Ditto.
+        (WebCore::Element::cancelFocusAppearanceUpdate): Ditto.
+
+        * dom/ElementRareData.h: Use "using" to make things that are protected
+        in NodeRareData be public here.
+
+        * dom/EventTarget.h: Removed include of DeprecatedValueList and
+        related declearations that weren't needed. Tweaked the definitions
+        of the forbidEventDispatch functions too.
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::EventTargetNode): Eliminated code that
+        was used to initialized m_regdListeners.
+        (WebCore::EventTargetNode::~EventTargetNode): Elminated delete of
+        m_regdListeners. Changed code to use eventListeners() instead of
+        m_regdListeners.
+        (WebCore::EventTargetNode::eventListeners): Added.
+        (WebCore::EventTargetNode::insertedIntoDocument): Use eventListeners.
+        (WebCore::EventTargetNode::removedFromDocument): Ditto.
+        (WebCore::EventTargetNode::willMoveToNewOwnerDocument): Ditto.
+        (WebCore::EventTargetNode::didMoveToNewOwnerDocument): Ditto.
+        (WebCore::EventTargetNode::addEventListener): Ditto.
+        (WebCore::EventTargetNode::removeEventListener): Ditto.
+        (WebCore::EventTargetNode::removeAllEventListeners): Ditto.
+        Also added code to call setRemoved on all the listeners.
+        (WebCore::EventTargetNode::handleLocalEvents): Ditto.
+        (WebCore::EventTargetNode::dispatchGenericEvent): Fixed indentation.
+        (WebCore::EventTargetNode::removeInlineEventListenerForType): Use
+        the new event listeners vector. Also added missing call to setRemoved.
+        (WebCore::EventTargetNode::inlineEventListenerForType): Ditto.
+
+        * dom/EventTargetNode.h: Added a new RegisteredEventListenerVector
+        type and replaced the old localEventListeners function with a new
+        eventListeners function. Removed m_regdListeners.
+
+        * dom/Node.cpp:
+        (WebCore::Node::childNodes): Removed unneeded std prefix.
+        (WebCore::Node::setFocus): Use function instead of going directly
+        at rare data.
+        (WebCore::Node::rareDataFocused): Ditto.
+        (WebCore::Node::registerDynamicNodeList): Removed unneeded std prefix.
+        (WebCore::Node::getElementsByName): Ditto.
+        (WebCore::Node::getElementsByClassName): Ditto.
+        (WebCore::Node::compareDocumentPosition): Ditto.
+
+        * dom/Node.h: Removed unneeded forward declaration of
+        RegisteredEventListener. This is now in EventTargetNode.
+
+        * dom/NodeRareData.h: Renamed m_focused to m_isFocused and made it
+        private. Made m_needsFocusAppearanceUpdateSoonAfterAttach private.
+        Added listeners and ensureListeners functions as well as isFocused,
+        setFocused, and focus-appearance functions. Made all data members private.
+
+        * dom/RegisteredEventListener.cpp: Removed operator ==.
+        * dom/RegisteredEventListener.h: Removed operator == and !=.
+
+        * svg/SVGElement.cpp:
+        (WebCore::hasLoadListener): Rewrote to work with the vector.
+        * svg/SVGUseElement.cpp:
+        (WebCore::SVGUseElement::transferEventListenersToShadowTree): Ditto.
+
 2008-12-13  Holger Hans Peter Freyther  <zecke@selfish.org>
 
         Reviewed by Dan Bernstein.
index f1a43b0..b840e07 100644 (file)
@@ -26,7 +26,6 @@
 #include "CSSProperty.h"
 #include "CSSPropertyNames.h"
 #include "CSSRule.h"
-#include "DeprecatedValueList.h"
 #include <wtf/ASCIICType.h>
 
 using namespace WTF;
index c1058f9..8f844d4 100644 (file)
@@ -1319,6 +1319,9 @@ void Document::clearFramePointer()
 
 void Document::removeAllEventListenersFromAllNodes()
 {
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i)
+        m_windowEventListeners[i]->setRemoved(true);
     m_windowEventListeners.clear();
     removeAllDisconnectedNodeEventListeners();
     for (Node *n = this; n; n = n->traverseNextNode()) {
@@ -1720,6 +1723,9 @@ void Document::clear()
 
     removeChildren();
 
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i)
+        m_windowEventListeners[i]->setRemoved(true);
     m_windowEventListeners.clear();
 }
 
@@ -2695,18 +2701,19 @@ CSSStyleDeclaration* Document::getOverrideStyle(Element*, const String&)
     return 0;
 }
 
-void Document::handleWindowEvent(Event* evt, bool useCapture)
+void Document::handleWindowEvent(Event* event, bool useCapture)
 {
     if (m_windowEventListeners.isEmpty())
         return;
         
-    // if any html event listeners are registered on the window, then dispatch them here
-    RegisteredEventListenerList listenersCopy = m_windowEventListeners;
-    RegisteredEventListenerList::iterator it = listenersCopy.begin();
-    
-    for (; it != listenersCopy.end(); ++it)
-        if ((*it)->eventType() == evt->type() && (*it)->useCapture() == useCapture && !(*it)->removed()) 
-            (*it)->listener()->handleEvent(evt, true);
+    // If any HTML event listeners are registered on the window, dispatch them here.
+    RegisteredEventListenerVector listenersCopy = m_windowEventListeners;
+    size_t size = listenersCopy.size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *listenersCopy[i];
+        if (r.eventType() == event->type() && r.useCapture() == useCapture && !r.removed())
+            r.listener()->handleEvent(event, true);
+    }
 }
 
 void Document::setWindowInlineEventListenerForType(const AtomicString& eventType, PassRefPtr<EventListener> listener)
@@ -2719,24 +2726,27 @@ void Document::setWindowInlineEventListenerForType(const AtomicString& eventType
 
 EventListener* Document::windowInlineEventListenerForType(const AtomicString& eventType)
 {
-    RegisteredEventListenerList::iterator it = m_windowEventListeners.begin();
-    for (; it != m_windowEventListeners.end(); ++it) {
-        if ((*it)->eventType() == eventType && (*it)->listener()->isInline())
-            return (*it)->listener();
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *m_windowEventListeners[i];
+        if (r.eventType() == eventType && r.listener()->isInline())
+            return r.listener();
     }
     return 0;
 }
 
 void Document::removeWindowInlineEventListenerForType(const AtomicString& eventType)
 {
-    RegisteredEventListenerList::iterator it = m_windowEventListeners.begin();
-    for (; it != m_windowEventListeners.end(); ++it) {
-        if ((*it)->eventType() == eventType && (*it)->listener()->isInline()) {
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *m_windowEventListeners[i];
+        if (r.eventType() == eventType && r.listener()->isInline()) {
             if (eventType == eventNames().unloadEvent)
                 removePendingFrameUnloadEventCount();
             else if (eventType == eventNames().beforeunloadEvent)
                 removePendingFrameBeforeUnloadEventCount();
-            m_windowEventListeners.remove(it);
+            r.setRemoved(true);
+            m_windowEventListeners.remove(i);
             return;
         }
     }
@@ -2757,15 +2767,16 @@ void Document::addWindowEventListener(const AtomicString& eventType, PassRefPtr<
 
 void Document::removeWindowEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
 {
-    RegisteredEventListenerList::iterator it = m_windowEventListeners.begin();
-    for (; it != m_windowEventListeners.end(); ++it) {
-        RegisteredEventListener& r = **it;
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *m_windowEventListeners[i];
         if (r.eventType() == eventType && r.listener() == listener && r.useCapture() == useCapture) {
             if (eventType == eventNames().unloadEvent)
                 removePendingFrameUnloadEventCount();
             else if (eventType == eventNames().beforeunloadEvent)
                 removePendingFrameBeforeUnloadEventCount();
-            m_windowEventListeners.remove(it);
+            r.setRemoved(true);
+            m_windowEventListeners.remove(i);
             return;
         }
     }
@@ -2773,10 +2784,11 @@ void Document::removeWindowEventListener(const AtomicString& eventType, EventLis
 
 bool Document::hasWindowEventListener(const AtomicString& eventType)
 {
-    RegisteredEventListenerList::iterator it = m_windowEventListeners.begin();
-    for (; it != m_windowEventListeners.end(); ++it)
-        if ((*it)->eventType() == eventType)
+    size_t size = m_windowEventListeners.size();
+    for (size_t i = 0; i < size; ++i) {
+        if (m_windowEventListeners[i]->eventType() == eventType)
             return true;
+    }
     return false;
 }
 
index cfd001b..6eae3fb 100644 (file)
@@ -867,7 +867,7 @@ private:
     RefPtr<StyleSheetList> m_styleSheets; // All of the stylesheets that are currently in effect for our media type and stylesheet set.
     ListHashSet<Node*> m_styleSheetCandidateNodes; // All of the nodes that could potentially provide stylesheets to the document (<link>, <style>, <?xml-stylesheet>)
 
-    RegisteredEventListenerList m_windowEventListeners;
+    RegisteredEventListenerVector m_windowEventListeners;
 
     typedef HashMap<FormElementKey, Vector<String>, FormElementKeyHash, FormElementKeyHashTraits> FormElementStateMap;
     ListHashSet<HTMLFormControlElementWithState*> m_formElementsWithState;
index b9367ab..1d0525b 100644 (file)
@@ -649,10 +649,10 @@ void Element::attach()
     ContainerNode::attach();
     if (hasRareData()) {   
         ElementRareData* data = rareData();
-        if (data->m_needsFocusAppearanceUpdateSoonAfterAttach) {
+        if (data->needsFocusAppearanceUpdateSoonAfterAttach()) {
             if (isFocusable() && document()->focusedNode() == this)
                 document()->updateFocusAppearanceSoon();
-            data->m_needsFocusAppearanceUpdateSoonAfterAttach = false;
+            data->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
         }
     }
 }
@@ -1083,7 +1083,7 @@ void Element::focus(bool restorePreviousSelection)
         page->focusController()->setFocusedNode(this, doc->frame());
 
     if (!isFocusable()) {
-        ensureRareData()->m_needsFocusAppearanceUpdateSoonAfterAttach = true;
+        ensureRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(true);
         return;
     }
         
@@ -1178,7 +1178,7 @@ RenderStyle* Element::computedStyle()
 void Element::cancelFocusAppearanceUpdate()
 {
     if (hasRareData())
-        rareData()->m_needsFocusAppearanceUpdateSoonAfterAttach = false;
+        rareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
     if (document()->focusedNode() == this)
         document()->cancelFocusAppearanceUpdate();
 }
index 8250757..096f846 100644 (file)
@@ -31,8 +31,12 @@ namespace WebCore {
 class ElementRareData : public NodeRareData {
 public:
     ElementRareData(Element*);
+
     void resetComputedStyle(Element*);
 
+    using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
+    using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
+
     IntSize m_minimumSizeForResizing;
     RefPtr<RenderStyle> m_computedStyle;
 };
index 232a5fe..1b78e3e 100644 (file)
@@ -32,7 +32,6 @@
 #ifndef EventTarget_h
 #define EventTarget_h
 
-#include "DeprecatedValueList.h"
 #include <wtf/Forward.h>
 
 namespace WebCore {
@@ -43,7 +42,6 @@ namespace WebCore {
     class EventListener;
     class EventTargetNode;
     class MessagePort;
-    class RegisteredEventListener;
     class ScriptExecutionContext;
     class SVGElementInstance;
     class Worker;
@@ -53,9 +51,6 @@ namespace WebCore {
 
     typedef int ExceptionCode;
 
-    template<typename T> class DeprecatedValueList;
-    typedef DeprecatedValueList<RefPtr<RegisteredEventListener> > RegisteredEventListenerList;
-
     class EventTarget {
     public:
         virtual MessagePort* toMessagePort();
@@ -95,14 +90,16 @@ namespace WebCore {
         virtual void derefEventTarget() = 0;
     };
 
+    void forbidEventDispatch();
+    void allowEventDispatch();
+
 #ifndef NDEBUG
-void forbidEventDispatch();
-void allowEventDispatch();
-bool eventDispatchForbidden();
+    bool eventDispatchForbidden();
 #else
-inline void forbidEventDispatch() { }
-inline void allowEventDispatch() { }
-#endif // NDEBUG 
+    inline void forbidEventDispatch() { }
+    inline void allowEventDispatch() { }
+#endif
 
 }
+
 #endif
index 8a16424..ef4542c 100644 (file)
@@ -35,6 +35,7 @@
 #include "KeyboardEvent.h"
 #include "MouseEvent.h"
 #include "MutationEvent.h"
+#include "NodeRareData.h"
 #include "Page.h"
 #include "PlatformMouseEvent.h"
 #include "PlatformWheelEvent.h"
@@ -62,17 +63,13 @@ static HashSet<EventTargetNode*>* gNodesDispatchingSimulatedClicks = 0;
 
 EventTargetNode::EventTargetNode(Document* doc, bool isElement, bool isContainer)
     : Node(doc, isElement, isContainer)
-    , m_regdListeners(0)
 {
 }
 
 EventTargetNode::~EventTargetNode()
 {
-    if (m_regdListeners && !m_regdListeners->isEmpty() && !inDocument())
+    if (!eventListeners().isEmpty() && !inDocument())
         document()->unregisterDisconnectedNodeWithEventListeners(this);
-
-    delete m_regdListeners;
-    m_regdListeners = 0;
 }
 
 ScriptExecutionContext* EventTargetNode::scriptExecutionContext() const
@@ -80,9 +77,19 @@ ScriptExecutionContext* EventTargetNode::scriptExecutionContext() const
     return document();
 }
 
+const RegisteredEventListenerVector& EventTargetNode::eventListeners() const
+{
+    if (hasRareData()) {
+        if (RegisteredEventListenerVector* listeners = rareData()->listeners())
+            return *listeners;
+    }
+    static const RegisteredEventListenerVector* emptyListenersVector = new RegisteredEventListenerVector;
+    return *emptyListenersVector;
+}
+
 void EventTargetNode::insertedIntoDocument()
 {
-    if (m_regdListeners && !m_regdListeners->isEmpty())
+    if (!eventListeners().isEmpty())
         document()->unregisterDisconnectedNodeWithEventListeners(this);
 
     Node::insertedIntoDocument();
@@ -90,7 +97,7 @@ void EventTargetNode::insertedIntoDocument()
 
 void EventTargetNode::removedFromDocument()
 {
-    if (m_regdListeners && !m_regdListeners->isEmpty())
+    if (!eventListeners().isEmpty())
         document()->registerDisconnectedNodeWithEventListeners(this);
 
     Node::removedFromDocument();
@@ -98,7 +105,7 @@ void EventTargetNode::removedFromDocument()
 
 void EventTargetNode::willMoveToNewOwnerDocument()
 {
-    if (m_regdListeners && !m_regdListeners->isEmpty())
+    if (!eventListeners().isEmpty())
         document()->unregisterDisconnectedNodeWithEventListeners(this);
 
     Node::willMoveToNewOwnerDocument();
@@ -106,7 +113,7 @@ void EventTargetNode::willMoveToNewOwnerDocument()
 
 void EventTargetNode::didMoveToNewOwnerDocument()
 {
-    if (m_regdListeners && !m_regdListeners->isEmpty())
+    if (!eventListeners().isEmpty())
         document()->registerDisconnectedNodeWithEventListeners(this);
 
     Node::didMoveToNewOwnerDocument();
@@ -138,41 +145,44 @@ static inline void updateSVGElementInstancesAfterEventListenerChange(EventTarget
 
 void EventTargetNode::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture)
 {
-    Document* doc = document();
-    if (!doc->attached())
+    Document* document = this->document();
+    if (!document->attached())
         return;
 
-    doc->addListenerTypeIfNeeded(eventType);
+    document->addListenerTypeIfNeeded(eventType);
 
-    if (!m_regdListeners)
-        m_regdListeners = new RegisteredEventListenerList;
+    RegisteredEventListenerVector& listeners = ensureRareData()->ensureListeners();
 
     // Remove existing identical listener set with identical arguments.
     // The DOM2 spec says that "duplicate instances are discarded" in this case.
     removeEventListener(eventType, listener.get(), useCapture);
 
     // adding the first one
-    if (m_regdListeners->isEmpty() && !inDocument())
-        doc->registerDisconnectedNodeWithEventListeners(this);
+    if (listeners.isEmpty() && !inDocument())
+        document->registerDisconnectedNodeWithEventListeners(this);
 
-    m_regdListeners->append(RegisteredEventListener::create(eventType, listener, useCapture));
+    listeners.append(RegisteredEventListener::create(eventType, listener, useCapture));
     updateSVGElementInstancesAfterEventListenerChange(this);
 }
 
 void EventTargetNode::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture)
 {
-    if (!m_regdListeners)
+    if (!hasRareData())
         return;
 
-    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
-    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it) {
-        RegisteredEventListener& r = **it;
+    RegisteredEventListenerVector* listeners = rareData()->listeners();
+    if (!listeners)
+        return;
+
+    size_t size = listeners->size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *listeners->at(i);
         if (r.eventType() == eventType && r.listener() == listener && r.useCapture() == useCapture) {
-            (*it)->setRemoved(true);
-            it = m_regdListeners->remove(it);
+            r.setRemoved(true);
+            listeners->remove(i);
 
             // removed last
-            if (m_regdListeners->isEmpty() && !inDocument())
+            if (listeners->isEmpty() && !inDocument())
                 document()->unregisterDisconnectedNodeWithEventListeners(this);
 
             updateSVGElementInstancesAfterEventListenerChange(this);
@@ -183,24 +193,30 @@ void EventTargetNode::removeEventListener(const AtomicString& eventType, EventLi
 
 void EventTargetNode::removeAllEventListeners()
 {
-    delete m_regdListeners;
-    m_regdListeners = 0;
-}
-
-void EventTargetNode::handleLocalEvents(Event *evt, bool useCapture)
-{
-    if (disabled() && evt->isMouseEvent())
+    if (!hasRareData())
         return;
 
-    if (!m_regdListeners || m_regdListeners->isEmpty())
+    RegisteredEventListenerVector* listeners = rareData()->listeners();
+    if (!listeners)
         return;
 
-    RegisteredEventListenerList listenersCopy = *m_regdListeners;
-    RegisteredEventListenerList::Iterator end = listenersCopy.end();
+    size_t size = listeners->size();
+    for (size_t i = 0; i < size; ++i)
+        listeners->at(i)->setRemoved(true);
+    listeners->clear();
+}
+
+void EventTargetNode::handleLocalEvents(Event* event, bool useCapture)
+{
+    if (disabled() && event->isMouseEvent())
+        return;
 
-    for (RegisteredEventListenerList::Iterator it = listenersCopy.begin(); it != end; ++it) {
-        if ((*it)->eventType() == evt->type() && (*it)->useCapture() == useCapture && !(*it)->removed())
-            (*it)->listener()->handleEvent(evt, false);
+    RegisteredEventListenerVector listenersCopy = eventListeners();
+    size_t size = listenersCopy.size();
+    for (size_t i = 0; i < size; ++i) {
+        const RegisteredEventListener& r = *listenersCopy[i];
+        if (r.eventType() == event->type() && r.useCapture() == useCapture && !r.removed())
+            r.listener()->handleEvent(event, false);
     }
 }
 
@@ -269,13 +285,12 @@ bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode& e
     DeprecatedPtrList<Node> nodeChain;
 
     if (inDocument()) {
-            for (Node* n = this; n; n = n->eventParentNode()) {
+        for (Node* n = this; n; n = n->eventParentNode()) {
 #if ENABLE(SVG)
             // Skip <use> shadow tree elements    
             if (n->isSVGElement() && n->isShadowNode())
                 continue;
 #endif
-
             n->ref();
             nodeChain.prepend(n);
         }
@@ -673,19 +688,24 @@ void EventTargetNode::dispatchStorageEvent(const AtomicString &eventType, const
 
 void EventTargetNode::removeInlineEventListenerForType(const AtomicString& eventType)
 {
-    if (!m_regdListeners) // nothing to remove
+    if (!hasRareData())
         return;
-    
-    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
-    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it) {
-        EventListener* listener = (*it)->listener();
-        if ((*it)->eventType() != eventType || !listener->isInline())
+
+    RegisteredEventListenerVector* listeners = rareData()->listeners();
+    if (!listeners)
+        return;
+
+    size_t size = listeners->size();
+    for (size_t i = 0; i < size; ++i) {
+        RegisteredEventListener& r = *listeners->at(i);
+        if (r.eventType() != eventType || !r.listener()->isInline())
             continue;
 
-        it = m_regdListeners->remove(it);
+        r.setRemoved(true);
+        listeners->remove(i);
 
         // removed last
-        if (m_regdListeners->isEmpty() && !inDocument())
+        if (listeners->isEmpty() && !inDocument())
             document()->unregisterDisconnectedNodeWithEventListeners(this);
 
         updateSVGElementInstancesAfterEventListenerChange(this);
@@ -708,13 +728,13 @@ void EventTargetNode::setInlineEventListenerForTypeAndAttribute(const AtomicStri
 
 EventListener* EventTargetNode::inlineEventListenerForType(const AtomicString& eventType) const
 {
-    if (!m_regdListeners)
-        return 0;
-    
-    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
-    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it)
-        if ((*it)->eventType() == eventType && (*it)->listener()->isInline())
-            return (*it)->listener();
+    const RegisteredEventListenerVector& listeners = eventListeners();
+    size_t size = listeners.size();
+    for (size_t i = 0; i < size; ++i) {
+        const RegisteredEventListener& r = *listeners[i];
+        if (r.eventType() == eventType && r.listener()->isInline())
+            return r.listener();
+    }
     return 0;
 }
 
index b3dced8..201b108 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
  *           (C) 2001 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
  *           (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
  *
  * This library is free software; you can redistribute it and/or
@@ -32,6 +32,9 @@ namespace WebCore {
 
 class Attribute;
 class Frame;
+class RegisteredEventListener;
+
+typedef Vector<RefPtr<RegisteredEventListener> > RegisteredEventListenerVector;
 
 class EventTargetNode : public Node, public EventTarget {
 public:
@@ -95,7 +98,7 @@ public:
      */
     virtual bool disabled() const;
 
-    RegisteredEventListenerList* localEventListeners() const { return m_regdListeners; }
+    const RegisteredEventListenerVector& eventListeners() const;
 
     EventListener* onabort() const;
     void setOnabort(PassRefPtr<EventListener>);
@@ -181,10 +184,6 @@ public:
     using Node::ref;
     using Node::deref;
  
-protected:
-    friend class EventTarget;
-    RegisteredEventListenerList* m_regdListeners;
-
 private:
     virtual void refEventTarget() { ref(); }
     virtual void derefEventTarget() { deref(); }
index c6a2773..3e0d2f1 100644 (file)
@@ -58,6 +58,8 @@
 #include "htmlediting.h"
 #include <wtf/RefCountedLeakCounter.h>
 
+using namespace std;
+
 namespace WebCore {
 
 using namespace HTMLNames;
@@ -262,7 +264,7 @@ PassRefPtr<NodeList> Node::childNodes()
 {
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
-        data->setNodeLists(std::auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
+        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
         document()->addNodeListCache();
     }
 
@@ -475,13 +477,13 @@ bool Node::canLazyAttach()
 void Node::setFocus(bool b)
 { 
     if (b || hasRareData())
-        ensureRareData()->m_focused = b;
+        ensureRareData()->setFocused(b);
 }
 
 bool Node::rareDataFocused() const
 {
     ASSERT(hasRareData());
-    return rareData()->m_focused;
+    return rareData()->isFocused();
 }
     
 bool Node::isFocusable() const
@@ -512,7 +514,7 @@ void Node::registerDynamicNodeList(DynamicNodeList* list)
 {
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
-        data->setNodeLists(std::auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
+        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
         document()->addNodeListCache();
     } else if (!m_document->hasNodeListCaches()) {
         // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now.
@@ -1225,7 +1227,7 @@ PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
 {
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
-        data->setNodeLists(std::auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
+        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
         document()->addNodeListCache();
     }
 
@@ -1240,7 +1242,7 @@ PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
 {
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
-        data->setNodeLists(std::auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
+        data->setNodeLists(auto_ptr<NodeListsNodeData>(new NodeListsNodeData));
         document()->addNodeListCache();
     }
 
@@ -1765,7 +1767,7 @@ unsigned short Node::compareDocumentPosition(Node* otherNode)
     // Walk the two chains backwards and look for the first difference.
     unsigned index1 = chain1.size();
     unsigned index2 = chain2.size();
-    for (unsigned i = std::min(index1, index2); i; --i) {
+    for (unsigned i = min(index1, index2); i; --i) {
         Node* child1 = chain1[--index1];
         Node* child2 = chain2[--index2];
         if (child1 != child2) {
index e560488..e1259b6 100644 (file)
@@ -51,7 +51,6 @@ class PlatformKeyboardEvent;
 class PlatformMouseEvent;
 class PlatformWheelEvent;
 class QualifiedName;
-class RegisteredEventListener;
 class RenderArena;
 class RenderObject;
 class RenderStyle;
index acad86c..59cc29a 100644 (file)
@@ -1,6 +1,5 @@
-/**
- *
- * Copyright (C) 2008 Apple Computer, Inc.
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
  * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -24,6 +23,8 @@
 #define NodeRareData_h
 
 #include "DynamicNodeList.h"
+#include "EventListener.h"
+#include "RegisteredEventListener.h"
 #include "StringHash.h"
 #include <wtf/HashSet.h>
 #include <wtf/OwnPtr.h>
@@ -54,9 +55,9 @@ struct NodeListsNodeData {
 class NodeRareData {
 public:    
     NodeRareData()
-        : m_focused(false)
-        , m_tabIndex(0)
-        , m_tabIndexSetExplicitly(false)
+        : m_tabIndex(0)
+        , m_tabIndexWasSetExplicitly(false)
+        , m_isFocused(false)
         , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
     {
     }
@@ -79,18 +80,34 @@ public:
     NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
     
     short tabIndex() const { return m_tabIndex; }
-    void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexSetExplicitly = true; }
-    bool tabIndexSetExplicitly() const { return m_tabIndexSetExplicitly; }
-        
-    bool m_focused : 1;
+    void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
+    bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
+
+    RegisteredEventListenerVector* listeners() { return m_eventListeners.get(); }
+    RegisteredEventListenerVector& ensureListeners()
+    {
+        if (!m_eventListeners)
+            m_eventListeners.set(new RegisteredEventListenerVector);
+        return *m_eventListeners;
+    }
+
+    bool isFocused() const { return m_isFocused; }
+    void setFocused(bool focused) { m_isFocused = focused; }
+
+protected:
+    // for ElementRareData
+    bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; }
+    void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; }
 
 private:
     OwnPtr<NodeListsNodeData> m_nodeLists;
+    OwnPtr<RegisteredEventListenerVector > m_eventListeners;
     short m_tabIndex;
-    bool m_tabIndexSetExplicitly : 1;
-public:
-    bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1; //for ElementRareData
+    bool m_tabIndexWasSetExplicitly : 1;
+    bool m_isFocused : 1;
+    bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1;
 };
+
 } //namespace
 
 #endif
index 7312785..f257e56 100644 (file)
@@ -35,9 +35,4 @@ RegisteredEventListener::RegisteredEventListener(const AtomicString& eventType,
 {
 }
 
-bool operator==(const RegisteredEventListener& a, const RegisteredEventListener& b)
-{
-    return a.eventType() == b.eventType() && a.listener() == b.listener() && a.useCapture() == b.useCapture();
-}
-
 } // namespace WebCore
index 58cd931..29b061d 100644 (file)
@@ -53,10 +53,6 @@ namespace WebCore {
         bool m_removed;
     };
 
-
-    bool operator==(const RegisteredEventListener&, const RegisteredEventListener&);
-    inline bool operator!=(const RegisteredEventListener& a, const RegisteredEventListener& b) { return !(a == b); }
-
 } // namespace WebCore
 
 #endif // RegisteredEventListener_h
index 8bf8eb1..7c1dcc3 100644 (file)
@@ -188,13 +188,12 @@ static bool hasLoadListener(SVGElement* node)
 {
     Node* currentNode = node;
     while (currentNode && currentNode->isElementNode()) {
-        RegisteredEventListenerList *list = static_cast<Element*>(currentNode)->localEventListeners();
-        if (list) {
-            RegisteredEventListenerList::Iterator end = list->end();
-            for (RegisteredEventListenerList::Iterator it = list->begin(); it != end; ++it)
-                if ((*it)->eventType() == eventNames().loadEvent &&
-                    (*it)->useCapture() == true || currentNode == node)
-                    return true;
+        const RegisteredEventListenerVector& listeners = static_cast<Element*>(currentNode)->eventListeners();
+        size_t size = listeners.size();
+        for (size_t i = 0; i < size; ++i) {
+            const RegisteredEventListener& r = *listeners[i];
+            if (r.eventType() == eventNames().loadEvent && r.useCapture() || currentNode == node)
+                return true;
         }
         currentNode = currentNode->parentNode();
     }
index 83ad559..4eb2d9f 100644 (file)
@@ -767,18 +767,18 @@ void SVGUseElement::transferEventListenersToShadowTree(SVGElementInstance* targe
     ASSERT(originalElement);
 
     if (SVGElement* shadowTreeElement = target->shadowTreeElement()) {
-        if (RegisteredEventListenerList* localEventListeners = originalElement->localEventListeners()) {
-            RegisteredEventListenerList::Iterator end = localEventListeners->end();
-            for (RegisteredEventListenerList::Iterator it = localEventListeners->begin(); it != end; ++it) {
-                EventListener* listener = (*it)->listener();
-                ASSERT(listener);
-
-                // Event listeners created from markup have already been transfered to the shadow tree during cloning!
-                if (listener->wasCreatedFromMarkup())
-                    continue;
-
-                shadowTreeElement->addEventListener((*it)->eventType(), listener, (*it)->useCapture());
-            }
+        const RegisteredEventListenerVector& listeners = originalElement->eventListeners();
+        size_t size = listeners.size();
+        for (size_t i = 0; i < size; ++i) {
+            const RegisteredEventListener& r = *listeners[i];
+            EventListener* listener = r.listener();
+            ASSERT(listener);
+
+            // Event listeners created from markup have already been transfered to the shadow tree during cloning!
+            if (listener->wasCreatedFromMarkup())
+                continue;
+
+            shadowTreeElement->addEventListener(r.eventType(), listener, r.useCapture());
         }
     }