OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
| 3 * |
| 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are |
| 6 * met: |
| 7 * |
| 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. |
| 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ |
| 30 |
| 31 #ifndef V8AbstractEventListener_h |
| 32 #define V8AbstractEventListener_h |
| 33 |
| 34 #include "EventListener.h" |
| 35 #include <v8.h> |
| 36 |
| 37 namespace WebCore { |
| 38 |
| 39 class Event; |
| 40 class Frame; |
| 41 |
| 42 // There are two kinds of event listeners: HTML or non-HMTL. onload, onfocus
, etc (attributes) are always HTML event handler type; |
| 43 // Event listeners added by Window.addEventListener or EventTargetNode::addE
ventListener are non-HTML type. |
| 44 // |
| 45 // Why does this matter? |
| 46 // WebKit does not allow duplicated HTML event handlers of the same type, bu
t ALLOWs duplicated non-HTML event handlers. |
| 47 class V8AbstractEventListener : public EventListener { |
| 48 public: |
| 49 virtual ~V8AbstractEventListener() { } |
| 50 |
| 51 // Returns the owner frame of the listener. |
| 52 Frame* frame() { return m_frame; } |
| 53 |
| 54 virtual void handleEvent(Event*, bool isWindowEvent); |
| 55 void invokeEventHandler(v8::Handle<v8::Context>, Event*, v8::Handle<v8::
Value> jsEvent, bool isWindowEvent); |
| 56 |
| 57 // Returns the listener object, either a function or an object. |
| 58 virtual v8::Local<v8::Object> getListenerObject() |
| 59 { |
| 60 return v8::Local<v8::Object>::New(m_listener); |
| 61 } |
| 62 |
| 63 // Dispose listener object and clear the handle. |
| 64 void disposeListenerObject(); |
| 65 |
| 66 virtual bool disconnected() const { return !m_frame; } |
| 67 |
| 68 protected: |
| 69 v8::Persistent<v8::Object> m_listener; |
| 70 |
| 71 // Indicates if this is an HTML type listener. |
| 72 bool m_isInline; |
| 73 |
| 74 private: |
| 75 V8AbstractEventListener(Frame*, bool isInline); |
| 76 |
| 77 virtual v8::Local<v8::Value> callListenerFunction(v8::Handle<v8::Value>
jsevent, Event*, bool isWindowEvent) = 0; |
| 78 |
| 79 // Get the receiver object to use for event listener call. |
| 80 v8::Local<v8::Object> getReceiverObject(Event*, bool isWindowEvent); |
| 81 |
| 82 // Frame to which the event listener is attached to. An event listener m
ust be destroyed before its owner frame is |
| 83 // deleted. See fast/dom/replaceChild.html |
| 84 // FIXME: this could hold m_frame live until the event listener is delet
ed. |
| 85 Frame* m_frame; |
| 86 |
| 87 // Position in the HTML source for HTML event listeners. |
| 88 int m_lineNumber; |
| 89 int m_columnNumber; |
| 90 |
| 91 friend class V8EventListener; |
| 92 friend class V8ObjectEventListener; |
| 93 friend class V8LazyEventListener; |
| 94 }; |
| 95 |
| 96 } // namespace WebCore |
| 97 |
| 98 #endif // V8AbstractEventListener_h |
OLD | NEW |