Commit 9edb01fe authored by eric@webkit.org's avatar eric@webkit.org

2010-01-27 Jay Campan <jcampan@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: svn://svn.chromium.org/blink/trunk@53934 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c024fcf3
2010-01-27 Jay Campan <jcampan@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@chromium.org> 2010-01-26 Yaar Schnitman <yaar@chromium.org>
Reviewed by Darin Fisher. Reviewed by Darin Fisher.
......
...@@ -107,6 +107,8 @@ ...@@ -107,6 +107,8 @@
'public/WebDragData.h', 'public/WebDragData.h',
'public/WebEditingAction.h', 'public/WebEditingAction.h',
'public/WebElement.h', 'public/WebElement.h',
'public/WebEvent.h',
'public/WebEventListener.h',
'public/WebFileChooserCompletion.h', 'public/WebFileChooserCompletion.h',
'public/WebFileChooserParams.h', 'public/WebFileChooserParams.h',
'public/WebFindOptions.h', 'public/WebFindOptions.h',
...@@ -130,6 +132,7 @@ ...@@ -130,6 +132,7 @@
'public/WebMessagePortChannel.h', 'public/WebMessagePortChannel.h',
'public/WebMessagePortChannelClient.h', 'public/WebMessagePortChannelClient.h',
'public/WebMimeRegistry.h', 'public/WebMimeRegistry.h',
'public/WebMutationEvent.h',
'public/WebNavigationType.h', 'public/WebNavigationType.h',
'public/WebNode.h', 'public/WebNode.h',
'public/WebNodeCollection.h', 'public/WebNodeCollection.h',
...@@ -210,6 +213,8 @@ ...@@ -210,6 +213,8 @@
'src/DragClientImpl.h', 'src/DragClientImpl.h',
'src/EditorClientImpl.cpp', 'src/EditorClientImpl.cpp',
'src/EditorClientImpl.h', 'src/EditorClientImpl.h',
'src/EventListenerWrapper.cpp',
'src/EventListenerWrapper.h',
'src/FrameLoaderClientImpl.cpp', 'src/FrameLoaderClientImpl.cpp',
'src/FrameLoaderClientImpl.h', 'src/FrameLoaderClientImpl.h',
'src/gtk/WebFontInfo.cpp', 'src/gtk/WebFontInfo.cpp',
...@@ -259,6 +264,10 @@ ...@@ -259,6 +264,10 @@
'src/WebElement.cpp', 'src/WebElement.cpp',
'src/WebEntities.cpp', 'src/WebEntities.cpp',
'src/WebEntities.h', 'src/WebEntities.h',
'src/WebEvent.cpp',
'src/WebEventListener.cpp',
'src/WebEventListenerPrivate.cpp',
'src/WebEventListenerPrivate.h',
'src/WebFileChooserCompletionImpl.cpp', 'src/WebFileChooserCompletionImpl.cpp',
'src/WebFileChooserCompletionImpl.h', 'src/WebFileChooserCompletionImpl.h',
'src/WebFontCache.cpp', 'src/WebFontCache.cpp',
...@@ -277,6 +286,7 @@ ...@@ -277,6 +286,7 @@
'src/WebKit.cpp', 'src/WebKit.cpp',
'src/WebMediaPlayerClientImpl.cpp', 'src/WebMediaPlayerClientImpl.cpp',
'src/WebMediaPlayerClientImpl.h', 'src/WebMediaPlayerClientImpl.h',
'src/WebMutationEvent.cpp',
'src/WebNode.cpp', 'src/WebNode.cpp',
'src/WebNodeCollection.cpp', 'src/WebNodeCollection.cpp',
'src/WebNodeList.cpp', 'src/WebNodeList.cpp',
......
/*
* 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
/*
* 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
/*
* 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
...@@ -41,6 +41,8 @@ namespace WTF { template <typename T> class PassRefPtr; } ...@@ -41,6 +41,8 @@ namespace WTF { template <typename T> class PassRefPtr; }
namespace WebKit { namespace WebKit {
class WebDocument; class WebDocument;
class WebEventListener;
class WebEventListenerPrivate;
class WebFrame; class WebFrame;
class WebNodeList; class WebNodeList;
...@@ -100,6 +102,8 @@ public: ...@@ -100,6 +102,8 @@ public:
WEBKIT_API WebString createMarkup() const; WEBKIT_API WebString createMarkup() const;
WEBKIT_API bool isTextNode() const; WEBKIT_API bool isTextNode() const;
WEBKIT_API bool isElementNode() 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() template<typename T> T toElement()
{ {
......
...@@ -76,6 +76,8 @@ public: ...@@ -76,6 +76,8 @@ public:
WEBKIT_API void assign(const WebString&); WEBKIT_API void assign(const WebString&);
WEBKIT_API void assign(const WebUChar* data, size_t len); 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 size_t length() const;
WEBKIT_API const WebUChar* data() const; WEBKIT_API const WebUChar* data() const;
...@@ -163,6 +165,16 @@ private: ...@@ -163,6 +165,16 @@ private:
WebStringPrivate* m_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 } // namespace WebKit
#endif #endif
/*
* 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
/*
* 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
/*
* 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();
}
}
/*
* 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
/*
* 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
/*
* 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
...@@ -37,7 +37,10 @@ ...@@ -37,7 +37,10 @@
#include "Node.h" #include "Node.h"
#include "NodeList.h" #include "NodeList.h"
#include "EventListenerWrapper.h"
#include "WebDocument.h" #include "WebDocument.h"
#include "WebEvent.h"
#include "WebEventListener.h"
#include "WebFrameImpl.h" #include "WebFrameImpl.h"
#include "WebNodeList.h" #include "WebNodeList.h"
#include "WebString.h" #include "WebString.h"
...@@ -173,4 +176,22 @@ bool WebNode::isElementNode() const ...@@ -173,4 +176,22 @@ bool WebNode::isElementNode() const
return m_private->isElementNode(); 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 } // namespace WebKit
...@@ -86,6 +86,11 @@ WebString WebString::fromUTF8(const char* data) ...@@ -86,6 +86,11 @@ WebString WebString::fromUTF8(const char* data)
return WebCore::String::fromUTF8(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) WebString::WebString(const WebCore::String& s)
: m_private(static_cast<WebStringPrivate*>(s.impl())) : m_private(static_cast<WebStringPrivate*>(s.impl()))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment