[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9

eric at webkit.org eric at webkit.org
Thu Feb 4 21:29:33 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 7f2fdee8b40a9bf4cbb6aad990ad91d88fd507df
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jan 27 15:15:23 2010 +0000

    2010-01-27  Jay Campan  <jcampan at google.com>
    
            Reviewed by Darin Fisher.
    
            Adding EventListeners to the chromium API.
    
            https://bugs.webkit.org/show_bug.cgi?id=33882
    
            * WebKit.gyp:
            * public/WebEvent.h: Added.
            * public/WebEventListener.h: Added.
            * public/WebMutationEvent.h: Added.
            * public/WebNode.h:
            * public/WebString.h:
            (WebKit::operator==):
            (WebKit::operator!=):
            * src/EventListenerWrapper.cpp: Added.
            * src/EventListenerWrapper.h: Added.
            * src/WebEvent.cpp: Added.
            * src/WebEventListener.cpp: Added.
            * src/WebEventListenerPrivate.cpp: Added.
            * src/WebEventListenerPrivate.h: Added.
            * src/WebNode.cpp:
            (WebKit::WebNode::addEventListener):
            (WebKit::WebNode::removeEventListener):
            * src/WebString.cpp:
            (WebKit::WebString::equals):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53934 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index bd20ba7..a692255 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,31 @@
+2010-01-27  Jay Campan  <jcampan at google.com>
+
+        Reviewed by Darin Fisher.
+
+        Adding EventListeners to the chromium API.
+
+        https://bugs.webkit.org/show_bug.cgi?id=33882
+
+        * WebKit.gyp:
+        * public/WebEvent.h: Added.
+        * public/WebEventListener.h: Added.
+        * public/WebMutationEvent.h: Added.
+        * public/WebNode.h:
+        * public/WebString.h:
+        (WebKit::operator==):
+        (WebKit::operator!=):
+        * src/EventListenerWrapper.cpp: Added.
+        * src/EventListenerWrapper.h: Added.
+        * src/WebEvent.cpp: Added.
+        * src/WebEventListener.cpp: Added.
+        * src/WebEventListenerPrivate.cpp: Added.
+        * src/WebEventListenerPrivate.h: Added.
+        * src/WebNode.cpp:
+        (WebKit::WebNode::addEventListener):
+        (WebKit::WebNode::removeEventListener):
+        * src/WebString.cpp:
+        (WebKit::WebString::equals):
+
 2010-01-26  Yaar Schnitman  <yaar at chromium.org>
 
         Reviewed by Darin Fisher.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index 34309a7..3b5a17f 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -107,6 +107,8 @@
                 'public/WebDragData.h',
                 'public/WebEditingAction.h',
                 'public/WebElement.h',
+                'public/WebEvent.h',
+                'public/WebEventListener.h',
                 'public/WebFileChooserCompletion.h',
                 'public/WebFileChooserParams.h',
                 'public/WebFindOptions.h',
@@ -130,6 +132,7 @@
                 'public/WebMessagePortChannel.h',
                 'public/WebMessagePortChannelClient.h',
                 'public/WebMimeRegistry.h',
+                'public/WebMutationEvent.h',
                 'public/WebNavigationType.h',
                 'public/WebNode.h',
                 'public/WebNodeCollection.h',
@@ -210,6 +213,8 @@
                 'src/DragClientImpl.h',
                 'src/EditorClientImpl.cpp',
                 'src/EditorClientImpl.h',
+                'src/EventListenerWrapper.cpp',
+                'src/EventListenerWrapper.h',
                 'src/FrameLoaderClientImpl.cpp',
                 'src/FrameLoaderClientImpl.h',
                 'src/gtk/WebFontInfo.cpp',
@@ -259,6 +264,10 @@
                 'src/WebElement.cpp',
                 'src/WebEntities.cpp',
                 'src/WebEntities.h',
+                'src/WebEvent.cpp',
+                'src/WebEventListener.cpp',
+                'src/WebEventListenerPrivate.cpp',
+                'src/WebEventListenerPrivate.h',
                 'src/WebFileChooserCompletionImpl.cpp',
                 'src/WebFileChooserCompletionImpl.h',
                 'src/WebFontCache.cpp',
@@ -277,6 +286,7 @@
                 'src/WebKit.cpp',
                 'src/WebMediaPlayerClientImpl.cpp',
                 'src/WebMediaPlayerClientImpl.h',
+                'src/WebMutationEvent.cpp',
                 'src/WebNode.cpp',
                 'src/WebNodeCollection.cpp',
                 'src/WebNodeList.cpp',
diff --git a/WebKit/chromium/public/WebEvent.h b/WebKit/chromium/public/WebEvent.h
new file mode 100644
index 0000000..b0964d1
--- /dev/null
+++ b/WebKit/chromium/public/WebEvent.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebEvent_h
+#define WebEvent_h
+
+#include "WebCommon.h"
+#include "WebNode.h"
+#include "WebString.h"
+
+namespace WebCore { class Event; }
+#if WEBKIT_IMPLEMENTATION
+namespace WTF { template <typename T> class PassRefPtr; }
+#endif
+
+namespace WebKit {
+
+class WebEvent {
+public:
+    enum PhaseType {
+        CapturingPhase     = 1,
+        AtTarget           = 2,
+        BubblingPhase      = 3
+    };
+
+    WebEvent() : m_private(0) { }
+    WebEvent(const WebEvent& e) : m_private(0) { assign(e); }
+    WebEvent& operator=(const WebEvent& e)
+    {
+        assign(e);
+        return *this;
+    }
+
+    WEBKIT_API void reset();
+    WEBKIT_API void assign(const WebEvent&);
+
+    bool isNull() const { return !m_private; }
+
+    WEBKIT_API WebString type() const;
+    WEBKIT_API WebNode target() const;
+    WEBKIT_API WebNode currentTarget() const;
+
+    WEBKIT_API PhaseType eventPhase() const;
+    WEBKIT_API bool bubbles() const;
+    WEBKIT_API bool cancelable() const;
+
+    WEBKIT_API bool isUIEvent() const;
+    WEBKIT_API bool isMouseEvent() const;
+    WEBKIT_API bool isMutationEvent() const;
+    WEBKIT_API bool isKeyboardEvent() const;
+    WEBKIT_API bool isTextEvent() const;
+    WEBKIT_API bool isCompositionEvent() const;
+    WEBKIT_API bool isDragEvent() const;
+    WEBKIT_API bool isClipboardEvent() const;
+    WEBKIT_API bool isMessageEvent() const;
+    WEBKIT_API bool isWheelEvent() const;
+    WEBKIT_API bool isBeforeTextInsertedEvent() const;
+    WEBKIT_API bool isOverflowEvent() const;
+    WEBKIT_API bool isPageTransitionEvent() const;
+    WEBKIT_API bool isPopStateEvent() const;
+    WEBKIT_API bool isProgressEvent() const;
+    WEBKIT_API bool isXMLHttpRequestProgressEvent() const;
+    WEBKIT_API bool isWebKitAnimationEvent() const;
+    WEBKIT_API bool isWebKitTransitionEvent() const;
+    WEBKIT_API bool isBeforeLoadEvent() const;
+
+#if WEBKIT_IMPLEMENTATION
+    WebEvent(const WTF::PassRefPtr<WebCore::Event>&);
+#endif
+
+protected:
+    typedef WebCore::Event WebEventPrivate;
+    void assign(WebEventPrivate*);
+    WebEventPrivate* m_private;
+
+    template<typename T> T* unwrap()
+    {
+        return static_cast<T*>(m_private);
+    }
+
+    template<typename T> const T* constUnwrap() const
+    {
+        return static_cast<const T*>(m_private);
+    }
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebEventListener.h b/WebKit/chromium/public/WebEventListener.h
new file mode 100644
index 0000000..52de1cd
--- /dev/null
+++ b/WebKit/chromium/public/WebEventListener.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebEventListener_h
+#define WebEventListener_h
+
+#if WEBKIT_IMPLEMENTATION
+namespace WebCore { class Node; }
+#endif
+
+namespace WebKit {
+
+class EventListenerWrapper;
+class WebEvent;
+class WebEventListenerPrivate;
+class WebNode;
+class WebString;
+
+class WebEventListener {
+public:
+    WebEventListener();
+    virtual ~WebEventListener();
+
+    // Called when an event is received.
+    virtual void handleEvent(const WebEvent&) = 0;
+
+#if WEBKIT_IMPLEMENTATION
+    void notifyEventListenerDeleted(EventListenerWrapper*);
+    EventListenerWrapper* createEventListenerWrapper(const WebString& eventType, bool useCapture, WebCore::Node* node);
+    EventListenerWrapper* getEventListenerWrapper(const WebString& eventType, bool useCapture, WebCore::Node* node);
+#endif
+
+private:
+    WebEventListenerPrivate* m_private;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebMutationEvent.h b/WebKit/chromium/public/WebMutationEvent.h
new file mode 100644
index 0000000..bc378f0
--- /dev/null
+++ b/WebKit/chromium/public/WebMutationEvent.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef WebMutationEvent_h
+#define WebMutationEvent_h
+
+#include "WebEvent.h"
+
+#if WEBKIT_IMPLEMENTATION
+namespace WebCore { class Event; }
+#endif
+
+namespace WebKit {
+
+class WebMutationEvent : public WebEvent {
+public:
+    enum AttrChangeType {
+        Modification    = 1,
+        Addition        = 2,
+        Removal         = 3
+    };
+
+    WEBKIT_API WebNode relatedNode() const;
+    WEBKIT_API WebString prevValue() const;
+    WEBKIT_API WebString newValue() const;
+    WEBKIT_API WebString attrName() const;
+    WEBKIT_API AttrChangeType attrChange() const;
+
+#if WEBKIT_IMPLEMENTATION
+    WebMutationEvent(const WTF::PassRefPtr<WebCore::Event>&);
+#endif
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/public/WebNode.h b/WebKit/chromium/public/WebNode.h
index ab9c767..4d2a0e9 100644
--- a/WebKit/chromium/public/WebNode.h
+++ b/WebKit/chromium/public/WebNode.h
@@ -41,6 +41,8 @@ namespace WTF { template <typename T> class PassRefPtr; }
 
 namespace WebKit {
 class WebDocument;
+class WebEventListener;
+class WebEventListenerPrivate;
 class WebFrame;
 class WebNodeList;
 
@@ -100,6 +102,8 @@ public:
     WEBKIT_API WebString createMarkup() const;
     WEBKIT_API bool isTextNode() const;
     WEBKIT_API bool isElementNode() const;
+    WEBKIT_API void addEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture);
+    WEBKIT_API void removeEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture);
 
     template<typename T> T toElement()
     {
diff --git a/WebKit/chromium/public/WebString.h b/WebKit/chromium/public/WebString.h
index 95e9305..d2cf9ea 100644
--- a/WebKit/chromium/public/WebString.h
+++ b/WebKit/chromium/public/WebString.h
@@ -76,6 +76,8 @@ public:
     WEBKIT_API void assign(const WebString&);
     WEBKIT_API void assign(const WebUChar* data, size_t len);
 
+    WEBKIT_API bool equals(const WebString& s) const;
+
     WEBKIT_API size_t length() const;
     WEBKIT_API const WebUChar* data() const;
 
@@ -163,6 +165,16 @@ private:
     WebStringPrivate* m_private;
 };
 
+inline bool operator==(const WebString& a, const WebString& b)
+{
+    return a.equals(b);
+}
+
+inline bool operator!=(const WebString& a, const WebString& b)
+{
+    return !(a == b);
+}
+
 } // namespace WebKit
 
 #endif
diff --git a/WebKit/chromium/src/EventListenerWrapper.cpp b/WebKit/chromium/src/EventListenerWrapper.cpp
new file mode 100644
index 0000000..f2d2979
--- /dev/null
+++ b/WebKit/chromium/src/EventListenerWrapper.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "EventListenerWrapper.h"
+
+#include "Event.h"
+#include "EventListener.h"
+
+#include "WebEvent.h"
+#include "WebEventListener.h"
+
+namespace WebKit {
+
+EventListenerWrapper::EventListenerWrapper(WebEventListener* webEventListener)
+    : EventListener(EventListener::JSEventListenerType)
+    , m_webEventListener(webEventListener)
+{
+}
+
+EventListenerWrapper::~EventListenerWrapper()
+{
+    if (m_webEventListener)
+        m_webEventListener->notifyEventListenerDeleted(this);
+}
+
+bool EventListenerWrapper::operator==(const EventListener& listener)
+{
+    return this == &listener;
+}
+
+void EventListenerWrapper::handleEvent(ScriptExecutionContext* context, Event* event)
+{
+    if (!m_webEventListener)
+        return;
+    WebEvent webEvent(event);
+    m_webEventListener->handleEvent(webEvent);
+}
+
+void EventListenerWrapper::webEventListenerDeleted()
+{
+    m_webEventListener = 0;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/EventListenerWrapper.h b/WebKit/chromium/src/EventListenerWrapper.h
new file mode 100644
index 0000000..2a0cbbb
--- /dev/null
+++ b/WebKit/chromium/src/EventListenerWrapper.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef EventListenerWrapper_h
+#define EventListenerWrapper_h
+
+#include "EventListener.h"
+
+namespace WebCore {
+class ScriptExecutionContext;
+}
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class WebEventListener;
+
+class EventListenerWrapper : public EventListener {
+public:
+    EventListenerWrapper(WebEventListener*);
+    ~EventListenerWrapper();
+
+    virtual bool operator==(const EventListener&);
+    virtual void handleEvent(ScriptExecutionContext*, Event*);
+
+    void webEventListenerDeleted();
+
+private:
+    WebEventListener* m_webEventListener;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/WebEvent.cpp b/WebKit/chromium/src/WebEvent.cpp
new file mode 100644
index 0000000..62ae65f
--- /dev/null
+++ b/WebKit/chromium/src/WebEvent.cpp
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEvent.h"
+
+#include "Event.h"
+#include "Node.h"
+#include "WebMutationEvent.h"
+#include <wtf/PassRefPtr.h>
+
+namespace WebKit {
+
+class WebEventPrivate : public WebCore::Event {
+};
+
+void WebEvent::reset()
+{
+    assign(0);
+}
+
+void WebEvent::assign(const WebEvent& other)
+{
+    WebEventPrivate* p = const_cast<WebEventPrivate*>(other.m_private);
+    if (p)
+        p->ref();
+    assign(p);
+}
+
+void WebEvent::assign(WebEventPrivate* p)
+{
+    // p is already ref'd for us by the caller
+    if (m_private)
+        m_private->deref();
+    m_private = p;
+}
+
+WebEvent::WebEvent(const WTF::PassRefPtr<WebCore::Event>& event)
+    : m_private(static_cast<WebEventPrivate*>(event.releaseRef()))
+{
+}
+
+WebString WebEvent::type() const
+{
+    ASSERT(m_private);
+    return m_private->type();
+}
+
+WebNode WebEvent::target() const
+{
+    ASSERT(m_private);
+    return WebNode(m_private->target()->toNode());
+}
+
+WebNode WebEvent::currentTarget() const
+{
+    ASSERT(m_private);
+    return WebNode(m_private->currentTarget()->toNode());
+}
+
+WebEvent::PhaseType WebEvent::eventPhase() const
+{
+    ASSERT(m_private);
+    return static_cast<WebEvent::PhaseType>(m_private->eventPhase());
+}
+
+bool WebEvent::bubbles() const
+{
+    ASSERT(m_private);
+    return m_private->bubbles();
+}
+
+bool WebEvent::cancelable() const
+{
+    ASSERT(m_private);
+    return m_private->cancelable();
+}
+
+bool WebEvent::isUIEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isUIEvent();
+}
+
+bool WebEvent::isMouseEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isMouseEvent();
+}
+
+bool WebEvent::isMutationEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isMutationEvent();
+}
+
+bool WebEvent::isKeyboardEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isKeyboardEvent();
+}
+
+bool WebEvent::isTextEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isTextEvent();
+}
+
+bool WebEvent::isCompositionEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isCompositionEvent();
+}
+
+bool WebEvent::isDragEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isDragEvent();
+}
+
+bool WebEvent::isClipboardEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isClipboardEvent();
+}
+
+bool WebEvent::isMessageEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isMessageEvent();
+}
+
+bool WebEvent::isWheelEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isWheelEvent();
+}
+
+bool WebEvent::isBeforeTextInsertedEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isBeforeTextInsertedEvent();
+}
+
+bool WebEvent::isOverflowEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isOverflowEvent();
+}
+
+bool WebEvent::isPageTransitionEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isPageTransitionEvent();
+}
+
+bool WebEvent::isPopStateEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isPopStateEvent();
+}
+
+bool WebEvent::isProgressEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isProgressEvent();
+}
+
+bool WebEvent::isXMLHttpRequestProgressEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isXMLHttpRequestProgressEvent();
+}
+
+bool WebEvent::isWebKitAnimationEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isWebKitAnimationEvent();
+}
+
+bool WebEvent::isWebKitTransitionEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isWebKitTransitionEvent();
+}
+
+bool WebEvent::isBeforeLoadEvent() const
+{
+    ASSERT(m_private);
+    return m_private->isBeforeLoadEvent();
+}
+
+}
diff --git a/WebKit/chromium/src/WebEventListener.cpp b/WebKit/chromium/src/WebEventListener.cpp
new file mode 100644
index 0000000..8d9a887
--- /dev/null
+++ b/WebKit/chromium/src/WebEventListener.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEventListener.h"
+
+#include "WebEventListenerPrivate.h"
+
+namespace WebKit {
+
+WebEventListener::WebEventListener()
+    : m_private(new WebEventListenerPrivate(this))
+{
+}
+
+WebEventListener::~WebEventListener()
+{
+    m_private->webEventListenerDeleted();
+    delete m_private;
+}
+
+void WebEventListener::notifyEventListenerDeleted(EventListenerWrapper* wrapper)
+{
+    m_private->eventListenerDeleted(wrapper);
+}
+
+EventListenerWrapper* WebEventListener::createEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+    return m_private->createEventListenerWrapper(eventType, useCapture, node);
+}
+
+EventListenerWrapper* WebEventListener::getEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+    return m_private->getEventListenerWrapper(eventType, useCapture, node);
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEventListenerPrivate.cpp b/WebKit/chromium/src/WebEventListenerPrivate.cpp
new file mode 100644
index 0000000..bd14baf
--- /dev/null
+++ b/WebKit/chromium/src/WebEventListenerPrivate.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebEventListenerPrivate.h"
+
+#include "EventListenerWrapper.h"
+#include "WebEventListener.h"
+
+namespace WebKit {
+
+WebEventListenerPrivate::WebEventListenerPrivate(WebEventListener* webEventListener)
+    : m_webEventListener(webEventListener)
+{
+}
+
+WebEventListenerPrivate::~WebEventListenerPrivate()
+{
+}
+
+EventListenerWrapper* WebEventListenerPrivate::createEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+    EventListenerWrapper* listenerWrapper = new EventListenerWrapper(m_webEventListener);
+    WebEventListenerPrivate::ListenerInfo listenerInfo(eventType, useCapture, listenerWrapper, node);
+    m_listenerWrappers.append(listenerInfo);
+    return listenerWrapper;
+}
+
+EventListenerWrapper* WebEventListenerPrivate::getEventListenerWrapper(const WebString& eventType, bool useCapture, Node* node)
+{
+    Vector<WebEventListenerPrivate::ListenerInfo>::const_iterator iter;
+    for (iter = m_listenerWrappers.begin(); iter != m_listenerWrappers.end(); ++iter) {
+        if (iter->node == node)
+          return iter->eventListenerWrapper;
+    }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+void WebEventListenerPrivate::webEventListenerDeleted()
+{
+    // Notifies all WebEventListenerWrappers that we are going away so they can
+    // invalidate their pointer to us.
+    Vector<WebEventListenerPrivate::ListenerInfo>::const_iterator iter;
+    for (iter = m_listenerWrappers.begin(); iter != m_listenerWrappers.end(); ++iter)
+        iter->eventListenerWrapper->webEventListenerDeleted();
+}
+
+void WebEventListenerPrivate::eventListenerDeleted(EventListenerWrapper* eventListener)
+{
+    for (size_t i = 0; i < m_listenerWrappers.size(); ++i) {
+        if (m_listenerWrappers[i].eventListenerWrapper == eventListener) {
+            m_listenerWrappers.remove(i);
+            return;
+        }
+    }
+    ASSERT_NOT_REACHED();
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/WebEventListenerPrivate.h b/WebKit/chromium/src/WebEventListenerPrivate.h
new file mode 100644
index 0000000..0ba2b5d
--- /dev/null
+++ b/WebKit/chromium/src/WebEventListenerPrivate.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebEventListenerPrivate_h
+#define WebEventListenerPrivate_h
+
+#include "WebString.h"
+
+#include <wtf/Vector.h>
+
+namespace WebCore {
+class Node;
+}
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class EventListenerWrapper;
+class WebEventListener;
+
+class WebEventListenerPrivate {
+public:
+    WebEventListenerPrivate(WebEventListener* webEventListener);
+    ~WebEventListenerPrivate();
+
+    EventListenerWrapper* createEventListenerWrapper(
+        const WebString& eventType, bool useCapture, Node* node);
+
+    // Gets the ListenerEventWrapper for a specific node.
+    // Used by WebNode::removeEventListener().
+    EventListenerWrapper* getEventListenerWrapper(
+        const WebString& eventType, bool useCapture, Node* node);
+
+    // Called by the WebEventListener when it is about to be deleted.
+    void webEventListenerDeleted();
+
+    // Called by the EventListenerWrapper when it is about to be deleted.
+    void eventListenerDeleted(EventListenerWrapper* eventListener);
+
+    struct ListenerInfo {
+        ListenerInfo(const WebString& eventType, bool useCapture,
+                     EventListenerWrapper* eventListenerWrapper,
+                     Node* node)
+            : eventType(eventType)
+            , useCapture(useCapture)
+            , eventListenerWrapper(eventListenerWrapper)
+            , node(node)
+        {
+        }
+
+        WebString eventType;
+        bool useCapture;
+        EventListenerWrapper* eventListenerWrapper;
+        Node* node;
+    };
+
+private:
+    WebEventListener* m_webEventListener;
+
+    // We keep a list of the wrapper for the WebKit EventListener, it is needed
+    // to implement WebNode::removeEventListener().
+    Vector<ListenerInfo> m_listenerWrappers;
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/WebNode.cpp b/WebKit/chromium/src/WebNode.cpp
index 702823d..9fbf573 100644
--- a/WebKit/chromium/src/WebNode.cpp
+++ b/WebKit/chromium/src/WebNode.cpp
@@ -37,7 +37,10 @@
 #include "Node.h"
 #include "NodeList.h"
 
+#include "EventListenerWrapper.h"
 #include "WebDocument.h"
+#include "WebEvent.h"
+#include "WebEventListener.h"
 #include "WebFrameImpl.h"
 #include "WebNodeList.h"
 #include "WebString.h"
@@ -173,4 +176,22 @@ bool WebNode::isElementNode() const
     return m_private->isElementNode();
 }
 
+void WebNode::addEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture)
+{
+    EventListenerWrapper* listenerWrapper =
+        listener->createEventListenerWrapper(eventType, useCapture, m_private);
+    // The listenerWrapper is only referenced by the actual Node.  Once it goes
+    // away, the wrapper notifies the WebEventListener so it can clear its
+    // pointer to it.
+    m_private->addEventListener(eventType, adoptRef(listenerWrapper), useCapture);
+}
+
+void WebNode::removeEventListener(const WebString& eventType, WebEventListener* listener, bool useCapture)
+{
+    EventListenerWrapper* listenerWrapper =
+        listener->getEventListenerWrapper(eventType, useCapture, m_private);
+    m_private->removeEventListener(eventType, listenerWrapper, useCapture);
+    // listenerWrapper is now deleted.
+}
+
 } // namespace WebKit
diff --git a/WebKit/chromium/src/WebString.cpp b/WebKit/chromium/src/WebString.cpp
index f45e05f..36d5f86 100644
--- a/WebKit/chromium/src/WebString.cpp
+++ b/WebKit/chromium/src/WebString.cpp
@@ -86,6 +86,11 @@ WebString WebString::fromUTF8(const char* data)
     return WebCore::String::fromUTF8(data);
 }
 
+bool WebString::equals(const WebString& s) const
+{
+    return equal(m_private, s.m_private);
+}
+
 WebString::WebString(const WebCore::String& s)
     : m_private(static_cast<WebStringPrivate*>(s.impl()))
 {

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list