OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2007-2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 16 matching lines...) Expand all Loading... |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "Element.h" | 32 #include "Element.h" |
33 | 33 |
34 #include "Attr.h" | 34 #include "Attr.h" |
35 #include "CSSHelper.h" | 35 #include "CSSHelper.h" |
36 #include "Document.h" | 36 #include "Document.h" |
37 #include "EventListener.h" | |
38 #include "ExceptionCode.h" | 37 #include "ExceptionCode.h" |
39 #include "HTMLFrameElementBase.h" | 38 #include "HTMLFrameElementBase.h" |
40 #include "HTMLNames.h" | 39 #include "HTMLNames.h" |
41 #include "Node.h" | 40 #include "Node.h" |
42 | 41 |
43 #include "V8Attr.h" | 42 #include "V8Attr.h" |
44 #include "V8Binding.h" | 43 #include "V8Binding.h" |
45 #include "V8CustomBinding.h" | 44 #include "V8CustomBinding.h" |
46 #include "V8CustomEventListener.h" | |
47 #include "V8Proxy.h" | 45 #include "V8Proxy.h" |
48 | 46 |
49 #include <wtf/RefPtr.h> | 47 #include <wtf/RefPtr.h> |
50 | 48 |
51 namespace WebCore { | 49 namespace WebCore { |
52 | 50 |
53 CALLBACK_FUNC_DECL(ElementSetAttribute) | 51 CALLBACK_FUNC_DECL(ElementSetAttribute) |
54 { | 52 { |
55 INC_STATS("DOM.Element.setAttribute()"); | 53 INC_STATS("DOM.Element.setAttribute()"); |
56 Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holde
r()); | 54 Element* element = V8DOMWrapper::convertDOMWrapperToNode<Element>(args.Holde
r()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return v8::Undefined(); | 118 return v8::Undefined(); |
121 | 119 |
122 ExceptionCode ec = 0; | 120 ExceptionCode ec = 0; |
123 RefPtr<Attr> result = element->setAttributeNodeNS(newAttr, ec); | 121 RefPtr<Attr> result = element->setAttributeNodeNS(newAttr, ec); |
124 if (ec) | 122 if (ec) |
125 throwError(ec); | 123 throwError(ec); |
126 | 124 |
127 return V8DOMWrapper::convertNodeToV8Object(result.get()); | 125 return V8DOMWrapper::convertNodeToV8Object(result.get()); |
128 } | 126 } |
129 | 127 |
130 static inline String toEventType(v8::Local<v8::String> value) | |
131 { | |
132 String key = toWebCoreString(value); | |
133 ASSERT(key.startsWith("on")); | |
134 return key.substring(2); | |
135 } | |
136 | |
137 ACCESSOR_SETTER(ElementEventHandler) | |
138 { | |
139 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder()); | |
140 | |
141 String eventType = toEventType(name); | |
142 | |
143 // Set handler if the value is a function. Otherwise, clear the | |
144 // event handler. | |
145 if (value->IsFunction()) { | |
146 V8Proxy* proxy = V8Proxy::retrieve(node->document()->frame()); | |
147 // the document might be created using createDocument, | |
148 // which does not have a frame, use the active frame | |
149 if (!proxy) | |
150 proxy = V8Proxy::retrieve(V8Proxy::retrieveFrameForEnteredContext())
; | |
151 if (!proxy) | |
152 return; | |
153 | |
154 if (RefPtr<EventListener> listener = proxy->eventListeners()->findOrCrea
teWrapper<V8EventListener>(proxy->frame(), value, true)) | |
155 node->setAttributeEventListener(eventType, listener); | |
156 } else | |
157 node->clearAttributeEventListener(eventType); | |
158 } | |
159 | |
160 ACCESSOR_GETTER(ElementEventHandler) | |
161 { | |
162 Node* node = V8DOMWrapper::convertDOMWrapperToNode<Node>(info.Holder()); | |
163 | |
164 EventListener* listener = node->getAttributeEventListener(toEventType(name))
; | |
165 return V8DOMWrapper::convertEventListenerToV8Object(listener); | |
166 } | |
167 | |
168 } // namespace WebCore | 128 } // namespace WebCore |
OLD | NEW |