mshtml: Send load event synchronously for img elements that loaded instantly in legac...
[wine.git] / dlls / mshtml / htmltextarea.c
blob8e6f931c6353a065af41efb8f0145a01313c14ed
1 /*
2 * Copyright 2006 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>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
28 #include "wine/debug.h"
30 #include "mshtml_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
34 struct HTMLTextAreaElement {
35 HTMLElement element;
37 IHTMLTextAreaElement IHTMLTextAreaElement_iface;
39 nsIDOMHTMLTextAreaElement *nstextarea;
42 static inline HTMLTextAreaElement *impl_from_IHTMLTextAreaElement(IHTMLTextAreaElement *iface)
44 return CONTAINING_RECORD(iface, HTMLTextAreaElement, IHTMLTextAreaElement_iface);
47 static HRESULT WINAPI HTMLTextAreaElement_QueryInterface(IHTMLTextAreaElement *iface,
48 REFIID riid, void **ppv)
50 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
52 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
55 static ULONG WINAPI HTMLTextAreaElement_AddRef(IHTMLTextAreaElement *iface)
57 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
59 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
62 static ULONG WINAPI HTMLTextAreaElement_Release(IHTMLTextAreaElement *iface)
64 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
66 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
69 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfoCount(IHTMLTextAreaElement *iface, UINT *pctinfo)
71 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
72 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
75 static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfo(IHTMLTextAreaElement *iface, UINT iTInfo,
76 LCID lcid, ITypeInfo **ppTInfo)
78 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
79 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
80 ppTInfo);
83 static HRESULT WINAPI HTMLTextAreaElement_GetIDsOfNames(IHTMLTextAreaElement *iface, REFIID riid,
84 LPOLESTR *rgszNames, UINT cNames,
85 LCID lcid, DISPID *rgDispId)
87 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
88 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
89 cNames, lcid, rgDispId);
92 static HRESULT WINAPI HTMLTextAreaElement_Invoke(IHTMLTextAreaElement *iface, DISPID dispIdMember,
93 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
96 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
97 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
98 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
101 static HRESULT WINAPI HTMLTextAreaElement_get_type(IHTMLTextAreaElement *iface, BSTR *p)
103 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
105 TRACE("(%p)->(%p)\n", This, p);
107 *p = SysAllocString(L"textarea");
108 if(!*p)
109 return E_OUTOFMEMORY;
110 return S_OK;
113 static HRESULT WINAPI HTMLTextAreaElement_put_value(IHTMLTextAreaElement *iface, BSTR v)
115 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
116 nsAString value_str;
117 nsresult nsres;
119 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
121 nsAString_InitDepend(&value_str, v);
122 nsres = nsIDOMHTMLTextAreaElement_SetValue(This->nstextarea, &value_str);
123 nsAString_Finish(&value_str);
124 if(NS_FAILED(nsres)) {
125 ERR("SetValue failed: %08lx\n", nsres);
126 return E_FAIL;
129 return S_OK;
132 static HRESULT WINAPI HTMLTextAreaElement_get_value(IHTMLTextAreaElement *iface, BSTR *p)
134 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
135 nsAString value_str;
136 nsresult nsres;
138 TRACE("(%p)->(%p)\n", This, p);
140 nsAString_Init(&value_str, NULL);
141 nsres = nsIDOMHTMLTextAreaElement_GetValue(This->nstextarea, &value_str);
142 return return_nsstr(nsres, &value_str, p);
145 static HRESULT WINAPI HTMLTextAreaElement_put_name(IHTMLTextAreaElement *iface, BSTR v)
147 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
148 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
149 return E_NOTIMPL;
152 static HRESULT WINAPI HTMLTextAreaElement_get_name(IHTMLTextAreaElement *iface, BSTR *p)
154 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
155 nsAString name_str;
156 nsresult nsres;
158 TRACE("(%p)->(%p)\n", This, p);
160 nsAString_Init(&name_str, NULL);
161 nsres = nsIDOMHTMLTextAreaElement_GetName(This->nstextarea, &name_str);
162 return return_nsstr(nsres, &name_str, p);
165 static HRESULT WINAPI HTMLTextAreaElement_put_status(IHTMLTextAreaElement *iface, VARIANT v)
167 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
168 FIXME("(%p)->()\n", This);
169 return E_NOTIMPL;
172 static HRESULT WINAPI HTMLTextAreaElement_get_status(IHTMLTextAreaElement *iface, VARIANT *p)
174 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
175 FIXME("(%p)->(%p)\n", This, p);
176 return E_NOTIMPL;
179 static HRESULT WINAPI HTMLTextAreaElement_put_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
181 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
182 FIXME("(%p)->(%x)\n", This, v);
183 return E_NOTIMPL;
186 static HRESULT WINAPI HTMLTextAreaElement_get_disabled(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
188 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
189 FIXME("(%p)->(%p)\n", This, p);
190 return E_NOTIMPL;
193 static HRESULT WINAPI HTMLTextAreaElement_get_form(IHTMLTextAreaElement *iface, IHTMLFormElement **p)
195 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
196 nsIDOMHTMLFormElement *nsform;
197 nsresult nsres;
199 TRACE("(%p)->(%p)\n", This, p);
201 nsres = nsIDOMHTMLTextAreaElement_GetForm(This->nstextarea, &nsform);
202 return return_nsform(nsres, nsform, p);
205 static HRESULT WINAPI HTMLTextAreaElement_put_defaultValue(IHTMLTextAreaElement *iface, BSTR v)
207 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
208 nsAString nsstr;
209 nsresult nsres;
211 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
213 nsAString_InitDepend(&nsstr, v);
214 nsres = nsIDOMHTMLTextAreaElement_SetDefaultValue(This->nstextarea, &nsstr);
215 nsAString_Finish(&nsstr);
216 return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
219 static HRESULT WINAPI HTMLTextAreaElement_get_defaultValue(IHTMLTextAreaElement *iface, BSTR *p)
221 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
222 nsAString nsstr;
223 nsresult nsres;
225 TRACE("(%p)->(%p)\n", This, p);
227 nsAString_Init(&nsstr, NULL);
228 nsres = nsIDOMHTMLTextAreaElement_GetDefaultValue(This->nstextarea, &nsstr);
229 return return_nsstr(nsres, &nsstr, p);
232 static HRESULT WINAPI HTMLTextAreaElement_select(IHTMLTextAreaElement *iface)
234 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
235 FIXME("(%p)\n", This);
236 return E_NOTIMPL;
239 static HRESULT WINAPI HTMLTextAreaElement_put_onchange(IHTMLTextAreaElement *iface, VARIANT v)
241 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
242 FIXME("(%p)->()\n", This);
243 return E_NOTIMPL;
246 static HRESULT WINAPI HTMLTextAreaElement_get_onchange(IHTMLTextAreaElement *iface, VARIANT *p)
248 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
249 FIXME("(%p)->(%p)\n", This, p);
250 return E_NOTIMPL;
253 static HRESULT WINAPI HTMLTextAreaElement_put_onselect(IHTMLTextAreaElement *iface, VARIANT v)
255 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
256 FIXME("(%p)->()\n", This);
257 return E_NOTIMPL;
260 static HRESULT WINAPI HTMLTextAreaElement_get_onselect(IHTMLTextAreaElement *iface, VARIANT *p)
262 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
263 FIXME("(%p)->(%p)\n", This, p);
264 return E_NOTIMPL;
267 static HRESULT WINAPI HTMLTextAreaElement_put_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL v)
269 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
270 nsresult nsres;
272 TRACE("(%p)->(%x)\n", This, v);
274 nsres = nsIDOMHTMLTextAreaElement_SetReadOnly(This->nstextarea, v != VARIANT_FALSE);
275 if(NS_FAILED(nsres)) {
276 ERR("SetReadOnly failed: %08lx\n", nsres);
277 return E_FAIL;
280 return S_OK;
283 static HRESULT WINAPI HTMLTextAreaElement_get_readOnly(IHTMLTextAreaElement *iface, VARIANT_BOOL *p)
285 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
286 cpp_bool b;
287 nsresult nsres;
289 TRACE("(%p)->(%p)\n", This, p);
291 nsres = nsIDOMHTMLTextAreaElement_GetReadOnly(This->nstextarea, &b);
292 if(NS_FAILED(nsres)) {
293 ERR("GetReadOnly failed: %08lx\n", nsres);
294 return E_FAIL;
297 *p = variant_bool(b);
298 return S_OK;
301 static HRESULT WINAPI HTMLTextAreaElement_put_rows(IHTMLTextAreaElement *iface, LONG v)
303 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
304 FIXME("(%p)->(%ld)\n", This, v);
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLTextAreaElement_get_rows(IHTMLTextAreaElement *iface, LONG *p)
310 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
311 FIXME("(%p)->(%p)\n", This, p);
312 return E_NOTIMPL;
315 static HRESULT WINAPI HTMLTextAreaElement_put_cols(IHTMLTextAreaElement *iface, LONG v)
317 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
318 FIXME("(%p)->(%ld)\n", This, v);
319 return E_NOTIMPL;
322 static HRESULT WINAPI HTMLTextAreaElement_get_cols(IHTMLTextAreaElement *iface, LONG *p)
324 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
325 FIXME("(%p)->(%p)\n", This, p);
326 return E_NOTIMPL;
329 static HRESULT WINAPI HTMLTextAreaElement_put_wrap(IHTMLTextAreaElement *iface, BSTR v)
331 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
332 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
333 return E_NOTIMPL;
336 static HRESULT WINAPI HTMLTextAreaElement_get_wrap(IHTMLTextAreaElement *iface, BSTR *p)
338 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
339 FIXME("(%p)->(%p)\n", This, p);
340 return E_NOTIMPL;
343 static HRESULT WINAPI HTMLTextAreaElement_createTextRange(IHTMLTextAreaElement *iface,
344 IHTMLTxtRange **range)
346 HTMLTextAreaElement *This = impl_from_IHTMLTextAreaElement(iface);
347 FIXME("(%p)->(%p)\n", This, range);
348 return E_NOTIMPL;
351 static const IHTMLTextAreaElementVtbl HTMLTextAreaElementVtbl = {
352 HTMLTextAreaElement_QueryInterface,
353 HTMLTextAreaElement_AddRef,
354 HTMLTextAreaElement_Release,
355 HTMLTextAreaElement_GetTypeInfoCount,
356 HTMLTextAreaElement_GetTypeInfo,
357 HTMLTextAreaElement_GetIDsOfNames,
358 HTMLTextAreaElement_Invoke,
359 HTMLTextAreaElement_get_type,
360 HTMLTextAreaElement_put_value,
361 HTMLTextAreaElement_get_value,
362 HTMLTextAreaElement_put_name,
363 HTMLTextAreaElement_get_name,
364 HTMLTextAreaElement_put_status,
365 HTMLTextAreaElement_get_status,
366 HTMLTextAreaElement_put_disabled,
367 HTMLTextAreaElement_get_disabled,
368 HTMLTextAreaElement_get_form,
369 HTMLTextAreaElement_put_defaultValue,
370 HTMLTextAreaElement_get_defaultValue,
371 HTMLTextAreaElement_select,
372 HTMLTextAreaElement_put_onchange,
373 HTMLTextAreaElement_get_onchange,
374 HTMLTextAreaElement_put_onselect,
375 HTMLTextAreaElement_get_onselect,
376 HTMLTextAreaElement_put_readOnly,
377 HTMLTextAreaElement_get_readOnly,
378 HTMLTextAreaElement_put_rows,
379 HTMLTextAreaElement_get_rows,
380 HTMLTextAreaElement_put_cols,
381 HTMLTextAreaElement_get_cols,
382 HTMLTextAreaElement_put_wrap,
383 HTMLTextAreaElement_get_wrap,
384 HTMLTextAreaElement_createTextRange
387 static inline HTMLTextAreaElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
389 return CONTAINING_RECORD(iface, HTMLTextAreaElement, element.node);
392 static HRESULT HTMLTextAreaElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
394 HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
396 *ppv = NULL;
398 if(IsEqualGUID(&IID_IUnknown, riid)) {
399 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
400 *ppv = &This->IHTMLTextAreaElement_iface;
401 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
402 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
403 *ppv = &This->IHTMLTextAreaElement_iface;
404 }else if(IsEqualGUID(&IID_IHTMLTextAreaElement, riid)) {
405 TRACE("(%p)->(IID_IHTMLTextAreaElement %p)\n", This, ppv);
406 *ppv = &This->IHTMLTextAreaElement_iface;
409 if(*ppv) {
410 IUnknown_AddRef((IUnknown*)*ppv);
411 return S_OK;
414 return HTMLElement_QI(&This->element.node, riid, ppv);
417 static HRESULT HTMLTextAreaElementImpl_put_disabled(HTMLDOMNode *iface, VARIANT_BOOL v)
419 HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
420 return IHTMLTextAreaElement_put_disabled(&This->IHTMLTextAreaElement_iface, v);
423 static HRESULT HTMLTextAreaElementImpl_get_disabled(HTMLDOMNode *iface, VARIANT_BOOL *p)
425 HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
426 return IHTMLTextAreaElement_get_disabled(&This->IHTMLTextAreaElement_iface, p);
429 static BOOL HTMLTextAreaElement_is_text_edit(HTMLDOMNode *iface)
431 return TRUE;
434 static void HTMLTextAreaElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
436 HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
438 if(This->nstextarea)
439 note_cc_edge((nsISupports*)This->nstextarea, "This->nstextarea", cb);
442 static void HTMLTextAreaElement_unlink(HTMLDOMNode *iface)
444 HTMLTextAreaElement *This = impl_from_HTMLDOMNode(iface);
446 if(This->nstextarea) {
447 nsIDOMHTMLTextAreaElement *nstextarea = This->nstextarea;
449 This->nstextarea = NULL;
450 nsIDOMHTMLTextAreaElement_Release(nstextarea);
454 static const NodeImplVtbl HTMLTextAreaElementImplVtbl = {
455 &CLSID_HTMLTextAreaElement,
456 HTMLTextAreaElement_QI,
457 HTMLElement_destructor,
458 HTMLElement_cpc,
459 HTMLElement_clone,
460 HTMLElement_dispatch_nsevent_hook,
461 HTMLElement_handle_event,
462 HTMLElement_get_attr_col,
463 NULL,
464 HTMLTextAreaElementImpl_put_disabled,
465 HTMLTextAreaElementImpl_get_disabled,
466 NULL,
467 NULL,
468 NULL,
469 NULL,
470 NULL,
471 NULL,
472 HTMLTextAreaElement_traverse,
473 HTMLTextAreaElement_unlink,
474 HTMLTextAreaElement_is_text_edit
477 static const tid_t HTMLTextAreaElement_iface_tids[] = {
478 HTMLELEMENT_TIDS,
479 IHTMLTextAreaElement_tid,
483 static dispex_static_data_t HTMLTextAreaElement_dispex = {
484 L"HTMLTextAreaElement",
485 NULL,
486 DispHTMLTextAreaElement_tid,
487 HTMLTextAreaElement_iface_tids,
488 HTMLElement_init_dispex_info
491 HRESULT HTMLTextAreaElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
493 HTMLTextAreaElement *ret;
494 nsresult nsres;
496 ret = calloc(1, sizeof(HTMLTextAreaElement));
497 if(!ret)
498 return E_OUTOFMEMORY;
500 ret->IHTMLTextAreaElement_iface.lpVtbl = &HTMLTextAreaElementVtbl;
501 ret->element.node.vtbl = &HTMLTextAreaElementImplVtbl;
503 HTMLElement_Init(&ret->element, doc, nselem, &HTMLTextAreaElement_dispex);
505 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLTextAreaElement, (void**)&ret->nstextarea);
506 assert(nsres == NS_OK);
508 *elem = &ret->element;
509 return S_OK;