wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mshtml / htmlscript.c
blob60fd94e3d44264f8a1ced7c7145d90715518c979
1 /*
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
19 #include <stdarg.h>
20 #include <assert.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
33 #include "htmlscript.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 static inline HTMLScriptElement *impl_from_IHTMLScriptElement(IHTMLScriptElement *iface)
39 return CONTAINING_RECORD(iface, HTMLScriptElement, IHTMLScriptElement_iface);
42 static HRESULT WINAPI HTMLScriptElement_QueryInterface(IHTMLScriptElement *iface,
43 REFIID riid, void **ppv)
45 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
47 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
50 static ULONG WINAPI HTMLScriptElement_AddRef(IHTMLScriptElement *iface)
52 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
54 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
57 static ULONG WINAPI HTMLScriptElement_Release(IHTMLScriptElement *iface)
59 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
61 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
64 static HRESULT WINAPI HTMLScriptElement_GetTypeInfoCount(IHTMLScriptElement *iface, UINT *pctinfo)
66 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
67 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
70 static HRESULT WINAPI HTMLScriptElement_GetTypeInfo(IHTMLScriptElement *iface, UINT iTInfo,
71 LCID lcid, ITypeInfo **ppTInfo)
73 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
74 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
75 ppTInfo);
78 static HRESULT WINAPI HTMLScriptElement_GetIDsOfNames(IHTMLScriptElement *iface, REFIID riid,
79 LPOLESTR *rgszNames, UINT cNames,
80 LCID lcid, DISPID *rgDispId)
82 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
83 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
84 cNames, lcid, rgDispId);
87 static HRESULT WINAPI HTMLScriptElement_Invoke(IHTMLScriptElement *iface, DISPID dispIdMember,
88 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
89 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
91 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
92 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
93 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
96 static HRESULT WINAPI HTMLScriptElement_put_src(IHTMLScriptElement *iface, BSTR v)
98 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
99 nsAString src_str;
100 nsresult nsres;
101 HRESULT hres;
103 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
105 nsAString_InitDepend(&src_str, v);
106 nsres = nsIDOMHTMLScriptElement_SetSrc(This->nsscript, &src_str);
107 nsAString_Finish(&src_str);
108 if(NS_FAILED(nsres)) {
109 ERR("SetSrc failed: %08x\n", nsres);
110 return E_FAIL;
113 if(This->parsed) {
114 WARN("already parsed\n");
115 return S_OK;
118 if(This->binding) {
119 FIXME("binding in progress\n");
120 return E_FAIL;
123 nsAString_Init(&src_str, NULL);
124 nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
125 if(NS_SUCCEEDED(nsres)) {
126 const PRUnichar *src;
127 nsAString_GetData(&src_str, &src);
128 hres = load_script(This, src, TRUE);
129 }else {
130 ERR("SetSrc failed: %08x\n", nsres);
131 hres = E_FAIL;
133 nsAString_Finish(&src_str);
134 return hres;
137 static HRESULT WINAPI HTMLScriptElement_get_src(IHTMLScriptElement *iface, BSTR *p)
139 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
140 nsAString src_str;
141 nsresult nsres;
143 TRACE("(%p)->(%p)\n", This, p);
145 nsAString_Init(&src_str, NULL);
146 nsres = nsIDOMHTMLScriptElement_GetSrc(This->nsscript, &src_str);
147 return return_nsstr(nsres, &src_str, p);
150 static HRESULT WINAPI HTMLScriptElement_put_htmlFor(IHTMLScriptElement *iface, BSTR v)
152 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
153 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
154 return E_NOTIMPL;
157 static HRESULT WINAPI HTMLScriptElement_get_htmlFor(IHTMLScriptElement *iface, BSTR *p)
159 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
160 nsAString html_str;
161 nsresult nsres;
163 TRACE("(%p)->(%p)\n", This, p);
165 nsAString_Init(&html_str, NULL);
166 nsres = nsIDOMHTMLScriptElement_GetHtmlFor(This->nsscript, &html_str);
167 return return_nsstr(nsres, &html_str, p);
170 static HRESULT WINAPI HTMLScriptElement_put_event(IHTMLScriptElement *iface, BSTR v)
172 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
173 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
174 return E_NOTIMPL;
177 static HRESULT WINAPI HTMLScriptElement_get_event(IHTMLScriptElement *iface, BSTR *p)
179 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
180 FIXME("(%p)->(%p)\n", This, p);
181 return E_NOTIMPL;
184 static HRESULT WINAPI HTMLScriptElement_put_text(IHTMLScriptElement *iface, BSTR v)
186 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
187 HTMLInnerWindow *window;
188 nsIDOMNode *parent;
189 nsAString text_str;
190 nsresult nsres;
192 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
194 if(!This->element.node.doc || !This->element.node.doc->window) {
195 WARN("no windoow\n");
196 return E_UNEXPECTED;
199 window = This->element.node.doc->window;
201 nsAString_InitDepend(&text_str, v);
202 nsres = nsIDOMHTMLScriptElement_SetText(This->nsscript, &text_str);
203 nsAString_Finish(&text_str);
204 if(NS_FAILED(nsres)) {
205 ERR("SetSrc failed: %08x\n", nsres);
206 return E_FAIL;
209 nsres = nsIDOMElement_GetParentNode(This->element.dom_element, &parent);
210 if(NS_FAILED(nsres) || !parent) {
211 TRACE("No parent, not executing\n");
212 This->parse_on_bind = TRUE;
213 return S_OK;
216 nsIDOMNode_Release(parent);
217 doc_insert_script(window, This, FALSE);
218 return S_OK;
221 static HRESULT WINAPI HTMLScriptElement_get_text(IHTMLScriptElement *iface, BSTR *p)
223 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
224 nsAString nsstr;
225 nsresult nsres;
227 TRACE("(%p)->(%p)\n", This, p);
229 nsAString_Init(&nsstr, NULL);
230 nsres = nsIDOMHTMLScriptElement_GetText(This->nsscript, &nsstr);
231 return return_nsstr(nsres, &nsstr, p);
234 static HRESULT WINAPI HTMLScriptElement_put_defer(IHTMLScriptElement *iface, VARIANT_BOOL v)
236 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
237 HRESULT hr = S_OK;
238 nsresult nsres;
240 TRACE("(%p)->(%x)\n", This, v);
242 nsres = nsIDOMHTMLScriptElement_SetDefer(This->nsscript, v != VARIANT_FALSE);
243 if(NS_FAILED(nsres))
245 hr = E_FAIL;
248 return hr;
251 static HRESULT WINAPI HTMLScriptElement_get_defer(IHTMLScriptElement *iface, VARIANT_BOOL *p)
253 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
254 cpp_bool defer = FALSE;
255 nsresult nsres;
257 TRACE("(%p)->(%p)\n", This, p);
259 if(!p)
260 return E_INVALIDARG;
262 nsres = nsIDOMHTMLScriptElement_GetDefer(This->nsscript, &defer);
263 if(NS_FAILED(nsres)) {
264 ERR("GetSrc failed: %08x\n", nsres);
267 *p = variant_bool(defer);
268 return S_OK;
271 static HRESULT WINAPI HTMLScriptElement_get_readyState(IHTMLScriptElement *iface, BSTR *p)
273 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
275 TRACE("(%p)->(%p)\n", This, p);
277 return get_readystate_string(This->readystate, p);
280 static HRESULT WINAPI HTMLScriptElement_put_onerror(IHTMLScriptElement *iface, VARIANT v)
282 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
284 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
286 return set_node_event(&This->element.node, EVENTID_ERROR, &v);
289 static HRESULT WINAPI HTMLScriptElement_get_onerror(IHTMLScriptElement *iface, VARIANT *p)
291 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
293 TRACE("(%p)->(%p)\n", This, p);
295 return get_node_event(&This->element.node, EVENTID_ERROR, p);
298 static HRESULT WINAPI HTMLScriptElement_put_type(IHTMLScriptElement *iface, BSTR v)
300 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
301 nsAString nstype_str;
302 nsresult nsres;
304 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
306 nsAString_Init(&nstype_str, v);
307 nsres = nsIDOMHTMLScriptElement_SetType(This->nsscript, &nstype_str);
308 if (NS_FAILED(nsres))
309 ERR("SetType failed: %08x\n", nsres);
310 nsAString_Finish (&nstype_str);
312 return S_OK;
315 static HRESULT WINAPI HTMLScriptElement_get_type(IHTMLScriptElement *iface, BSTR *p)
317 HTMLScriptElement *This = impl_from_IHTMLScriptElement(iface);
318 nsAString nstype_str;
319 nsresult nsres;
321 TRACE("(%p)->(%p)\n", This, p);
323 nsAString_Init(&nstype_str, NULL);
324 nsres = nsIDOMHTMLScriptElement_GetType(This->nsscript, &nstype_str);
325 return return_nsstr(nsres, &nstype_str, p);
328 static const IHTMLScriptElementVtbl HTMLScriptElementVtbl = {
329 HTMLScriptElement_QueryInterface,
330 HTMLScriptElement_AddRef,
331 HTMLScriptElement_Release,
332 HTMLScriptElement_GetTypeInfoCount,
333 HTMLScriptElement_GetTypeInfo,
334 HTMLScriptElement_GetIDsOfNames,
335 HTMLScriptElement_Invoke,
336 HTMLScriptElement_put_src,
337 HTMLScriptElement_get_src,
338 HTMLScriptElement_put_htmlFor,
339 HTMLScriptElement_get_htmlFor,
340 HTMLScriptElement_put_event,
341 HTMLScriptElement_get_event,
342 HTMLScriptElement_put_text,
343 HTMLScriptElement_get_text,
344 HTMLScriptElement_put_defer,
345 HTMLScriptElement_get_defer,
346 HTMLScriptElement_get_readyState,
347 HTMLScriptElement_put_onerror,
348 HTMLScriptElement_get_onerror,
349 HTMLScriptElement_put_type,
350 HTMLScriptElement_get_type
353 static inline HTMLScriptElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
355 return CONTAINING_RECORD(iface, HTMLScriptElement, element.node);
358 static HRESULT HTMLScriptElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
360 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
362 *ppv = NULL;
364 if(IsEqualGUID(&IID_IUnknown, riid)) {
365 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
366 *ppv = &This->IHTMLScriptElement_iface;
367 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
368 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
369 *ppv = &This->IHTMLScriptElement_iface;
370 }else if(IsEqualGUID(&IID_IHTMLScriptElement, riid)) {
371 TRACE("(%p)->(IID_IHTMLScriptElement %p)\n", This, ppv);
372 *ppv = &This->IHTMLScriptElement_iface;
375 if(*ppv) {
376 IUnknown_AddRef((IUnknown*)*ppv);
377 return S_OK;
380 return HTMLElement_QI(&This->element.node, riid, ppv);
383 static void HTMLScriptElement_destructor(HTMLDOMNode *iface)
385 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
386 heap_free(This->src_text);
387 HTMLElement_destructor(&This->element.node);
390 static HRESULT HTMLScriptElement_get_readystate(HTMLDOMNode *iface, BSTR *p)
392 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
394 return IHTMLScriptElement_get_readyState(&This->IHTMLScriptElement_iface, p);
397 static HRESULT HTMLScriptElement_bind_to_tree(HTMLDOMNode *iface)
399 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
401 TRACE("(%p)\n", This);
403 if(!This->parse_on_bind)
404 return S_OK;
406 if(!This->element.node.doc || !This->element.node.doc->window) {
407 ERR("No window\n");
408 return E_UNEXPECTED;
411 This->parse_on_bind = FALSE;
412 doc_insert_script(This->element.node.doc->window, This, FALSE);
413 return S_OK;
416 static void HTMLScriptElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
418 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
420 if(This->nsscript)
421 note_cc_edge((nsISupports*)This->nsscript, "This->nsscript", cb);
424 static void HTMLScriptElement_unlink(HTMLDOMNode *iface)
426 HTMLScriptElement *This = impl_from_HTMLDOMNode(iface);
428 if(This->nsscript) {
429 nsIDOMHTMLScriptElement *nsscript = This->nsscript;
431 This->nsscript = NULL;
432 nsIDOMHTMLScriptElement_Release(nsscript);
436 static const NodeImplVtbl HTMLScriptElementImplVtbl = {
437 &CLSID_HTMLScriptElement,
438 HTMLScriptElement_QI,
439 HTMLScriptElement_destructor,
440 HTMLElement_cpc,
441 HTMLElement_clone,
442 HTMLElement_handle_event,
443 HTMLElement_get_attr_col,
444 NULL,
445 NULL,
446 NULL,
447 NULL,
448 HTMLScriptElement_get_readystate,
449 NULL,
450 NULL,
451 HTMLScriptElement_bind_to_tree,
452 HTMLScriptElement_traverse,
453 HTMLScriptElement_unlink
456 HRESULT script_elem_from_nsscript(nsIDOMHTMLScriptElement *nsscript, HTMLScriptElement **ret)
458 nsIDOMNode *nsnode;
459 HTMLDOMNode *node;
460 nsresult nsres;
461 HRESULT hres;
463 nsres = nsIDOMHTMLScriptElement_QueryInterface(nsscript, &IID_nsIDOMNode, (void**)&nsnode);
464 assert(nsres == NS_OK);
466 hres = get_node(nsnode, TRUE, &node);
467 nsIDOMNode_Release(nsnode);
468 if(FAILED(hres))
469 return hres;
471 assert(node->vtbl == &HTMLScriptElementImplVtbl);
472 *ret = impl_from_HTMLDOMNode(node);
473 return S_OK;
476 static const tid_t HTMLScriptElement_iface_tids[] = {
477 HTMLELEMENT_TIDS,
478 IHTMLScriptElement_tid,
482 static dispex_static_data_t HTMLScriptElement_dispex = {
483 NULL,
484 DispHTMLScriptElement_tid,
485 HTMLScriptElement_iface_tids,
486 HTMLElement_init_dispex_info
489 HRESULT HTMLScriptElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
491 HTMLScriptElement *ret;
492 nsresult nsres;
494 ret = heap_alloc_zero(sizeof(HTMLScriptElement));
495 if(!ret)
496 return E_OUTOFMEMORY;
498 ret->IHTMLScriptElement_iface.lpVtbl = &HTMLScriptElementVtbl;
499 ret->element.node.vtbl = &HTMLScriptElementImplVtbl;
501 HTMLElement_Init(&ret->element, doc, nselem, &HTMLScriptElement_dispex);
503 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLScriptElement, (void**)&ret->nsscript);
504 assert(nsres == NS_OK);
506 *elem = &ret->element;
507 return S_OK;