2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
37 return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
40 static HRESULT WINAPI HTMLScriptElement_QueryInterface(IHTMLScriptElement *iface,
41 REFIID riid, void **ppv)
43 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
45 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
48 static ULONG WINAPI HTMLScriptElement_AddRef(IHTMLScriptElement *iface)
50 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
52 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
55 static ULONG WINAPI HTMLScriptElement_Release(IHTMLScriptElement *iface)
57 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
59 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
62 static HRESULT WINAPI HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement *iface, UINT *pctinfo)
64 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
65 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
68 static HRESULT WINAPI HTMLScriptElement_GetTypeInfo(IHTMLScriptElement *iface, UINT iTInfo,
69 LCID lcid, ITypeInfo **ppTInfo)
71 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
72 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
76 static HRESULT WINAPI HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement *iface, REFIID riid,
77 LPOLESTR *rgszNames, UINT cNames,
78 LCID lcid, DISPID *rgDispId)
80 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
81 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
82 cNames, lcid, rgDispId);
85 static HRESULT WINAPI HTMLScriptElement_Invoke(IHTMLScriptElement *iface, DISPID dispIdMember,
86 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
87 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
89 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
90 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
91 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
94 static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v)
96 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
97 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
101 static HRESULT WINAPI HTMLScriptElement_get_src(IHTMLScriptElement *iface, BSTR *p)
103 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
107 TRACE("(%p)->(%p)\n", This, p);
109 nsAString_Init(&src_str, NULL);
110 nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
111 return return_nsstr(nsres, &src_str, p);
114 static HRESULT WINAPI HTMLScriptElement_put_htmlFor(IHTMLScriptElement *iface, BSTR v)
116 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
117 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
121 static HRESULT WINAPI HTMLScriptElement_get_htmlFor(IHTMLScriptElement *iface, BSTR *p)
123 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
124 FIXME("(%p)->(%p)\n", This, p);
128 static HRESULT WINAPI HTMLScriptElement_put_event(IHTMLScriptElement *iface, BSTR v)
130 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
131 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
135 static HRESULT WINAPI HTMLScriptElement_get_event(IHTMLScriptElement *iface, BSTR *p)
137 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
138 FIXME("(%p)->(%p)\n", This, p);
142 static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v)
144 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
145 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
149 static HRESULT WINAPI HTMLScriptElement_get_text(IHTMLScriptElement *iface, BSTR *p)
151 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
152 FIXME("(%p)->(%p)\n", This, p);
156 static HRESULT WINAPI HTMLScriptElement_put_defer(IHTMLScriptElement *iface, VARIANT_BOOL v)
158 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
162 TRACE("(%p)->(%x)\n", This, v);
164 nsres = nsIDOMHTMLScriptElement_SetDefer(This->nsscript, v != VARIANT_FALSE);
173 static HRESULT WINAPI HTMLScriptElement_get_defer(IHTMLScriptElement *iface, VARIANT_BOOL *p)
175 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
176 cpp_bool defer = FALSE;
179 TRACE("(%p)->(%p)\n", This, p);
184 nsres = nsIDOMHTMLScriptElement_GetDefer(This->nsscript, &defer);
185 if(NS_FAILED(nsres)) {
186 ERR("GetSrc failed: %08x\n", nsres);
189 *p = defer ? VARIANT_TRUE : VARIANT_FALSE;
191 TRACE("*p = %d\n", *p);
195 static HRESULT WINAPI HTMLScriptElement_get_readyState(IHTMLScriptElement *iface, BSTR *p)
197 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
198 FIXME("(%p)->(%p)\n", This, p);
202 static HRESULT WINAPI HTMLScriptElement_put_onerror(IHTMLScriptElement *iface, VARIANT v)
204 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
205 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
209 static HRESULT WINAPI HTMLScriptElement_get_onerror(IHTMLScriptElement *iface, VARIANT *p)
211 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
212 FIXME("(%p)->(%p)\n", This, p);
216 static HRESULT WINAPI HTMLScriptElement_put_type(IHTMLScriptElement *iface, BSTR v)
218 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
219 nsAString nstype_str;
222 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
224 nsAString_Init(&nstype_str, v);
225 nsres = nsIDOMHTMLScriptElement_SetType(This->nsscript, &nstype_str);
226 if (NS_FAILED(nsres))
227 ERR("SetType failed: %08x\n", nsres);
228 nsAString_Finish (&nstype_str);
233 static HRESULT WINAPI HTMLScriptElement_get_type(IHTMLScriptElement *iface, BSTR *p)
235 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
236 nsAString nstype_str;
239 TRACE("(%p)->(%p)\n", This, p);
241 nsAString_Init(&nstype_str, NULL);
242 nsres = nsIDOMHTMLScriptElement_GetType(This->nsscript, &nstype_str);
243 return return_nsstr(nsres, &nstype_str, p);
246 static const IHTMLScriptElementVtbl HTMLScriptElementVtbl = {
247 HTMLScriptElement_QueryInterface,
248 HTMLScriptElement_AddRef,
249 HTMLScriptElement_Release,
250 HTMLScriptElement_GetTypeInfoCount,
251 HTMLScriptElement_GetTypeInfo,
252 HTMLScriptElement_GetIDsOfNames,
253 HTMLScriptElement_Invoke,
254 HTMLScriptElement_put_src,
255 HTMLScriptElement_get_src,
256 HTMLScriptElement_put_htmlFor,
257 HTMLScriptElement_get_htmlFor,
258 HTMLScriptElement_put_event,
259 HTMLScriptElement_get_event,
260 HTMLScriptElement_put_text,
261 HTMLScriptElement_get_text,
262 HTMLScriptElement_put_defer,
263 HTMLScriptElement_get_defer,
264 HTMLScriptElement_get_readyState,
265 HTMLScriptElement_put_onerror,
266 HTMLScriptElement_get_onerror,
267 HTMLScriptElement_put_type,
268 HTMLScriptElement_get_type
271 static inline HTMLScriptElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
273 return CONTAINING_RECORD(iface, HTMLScriptElement, element.node);
276 static HRESULT HTMLScriptElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
278 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
282 if(IsEqualGUID(&IID_IUnknown, riid)) {
283 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
284 *ppv = &This->IHTMLScriptElement_iface;
285 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
286 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
287 *ppv = &This->IHTMLScriptElement_iface;
288 }else if(IsEqualGUID(&IID_IHTMLScriptElement, riid)) {
289 TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This, ppv);
290 *ppv = &This->IHTMLScriptElement_iface;
294 IUnknown_AddRef((IUnknown*)*ppv);
298 return HTMLElement_QI(&This->element.node, riid, ppv);
301 static HRESULT HTMLScriptElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
303 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
305 return IHTMLScriptElement_get_readyState(&This->IHTMLScriptElement_iface, p);
308 static const NodeImplVtbl HTMLScriptElementImplVtbl = {
309 HTMLScriptElement_QI,
310 HTMLElement_destructor,
312 HTMLElement_handle_event,
313 HTMLElement_get_attr_col,
319 HTMLScriptElement_get_readystate
322 HRESULT script_elem_from_nsscript(HTMLDocumentNode *doc, nsIDOMHTMLScriptElement *nsscript, HTMLScriptElement **ret)
327 hres = get_node(doc, (nsIDOMNode*)nsscript, TRUE, &node);
331 assert(node->vtbl == &HTMLScriptElementImplVtbl);
332 *ret = impl_from_HTMLDOMNode(node);
336 static const tid_t HTMLScriptElement_iface_tids[] = {
338 IHTMLScriptElement_tid,
342 static dispex_static_data_t HTMLScriptElement_dispex = {
344 DispHTMLScriptElement_tid,
346 HTMLScriptElement_iface_tids
349 HRESULT HTMLScriptElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
351 HTMLScriptElement *ret;
354 ret = heap_alloc_zero(sizeof(HTMLScriptElement));
356 return E_OUTOFMEMORY;
358 ret->IHTMLScriptElement_iface.lpVtbl = &HTMLScriptElementVtbl;
359 ret->element.node.vtbl = &HTMLScriptElementImplVtbl;
361 HTMLElement_Init(&ret->element, doc, nselem, &HTMLScriptElement_dispex);
363 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLScriptElement, (void**)&ret->nsscript);
365 /* Share nsscript reference with nsnode */
366 assert(nsres == NS_OK && (nsIDOMNode*)ret->nsscript == ret->element.node.nsnode);
367 nsIDOMNode_Release(ret->element.node.nsnode);
369 *elem = &ret->element;