push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / mshtml / htmlelem.c
blobb3703f3d0b55a014d8f984e156c116f08a6d7bd7
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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
29 #include "shlwapi.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
35 #include "htmlevent.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
41 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
43 nsIDOMElement *nselem;
44 nsAString tag_str;
45 nsresult nsres;
47 if(!doc->nsdoc) {
48 WARN("NULL nsdoc\n");
49 return E_UNEXPECTED;
52 nsAString_Init(&tag_str, tag);
53 nsres = nsIDOMDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
54 nsAString_Finish(&tag_str);
55 if(NS_FAILED(nsres)) {
56 ERR("CreateElement failed: %08x\n", nsres);
57 return E_FAIL;
60 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
61 nsIDOMElement_Release(nselem);
62 if(NS_FAILED(nsres)) {
63 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
64 return E_FAIL;
67 return S_OK;
70 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
72 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
73 REFIID riid, void **ppv)
75 HTMLElement *This = HTMLELEM_THIS(iface);
77 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->node), riid, ppv);
80 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
82 HTMLElement *This = HTMLELEM_THIS(iface);
84 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->node));
87 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
89 HTMLElement *This = HTMLELEM_THIS(iface);
91 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->node));
94 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
96 HTMLElement *This = HTMLELEM_THIS(iface);
97 return IDispatchEx_GetTypeInfoCount(DISPATCHEX(&This->node.dispex), pctinfo);
100 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
101 LCID lcid, ITypeInfo **ppTInfo)
103 HTMLElement *This = HTMLELEM_THIS(iface);
104 return IDispatchEx_GetTypeInfo(DISPATCHEX(&This->node.dispex), iTInfo, lcid, ppTInfo);
107 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
108 LPOLESTR *rgszNames, UINT cNames,
109 LCID lcid, DISPID *rgDispId)
111 HTMLElement *This = HTMLELEM_THIS(iface);
112 return IDispatchEx_GetIDsOfNames(DISPATCHEX(&This->node.dispex), riid, rgszNames, cNames, lcid, rgDispId);
115 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
116 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
117 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
119 HTMLElement *This = HTMLELEM_THIS(iface);
120 return IDispatchEx_Invoke(DISPATCHEX(&This->node.dispex), dispIdMember, riid, lcid,
121 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
124 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
125 VARIANT AttributeValue, LONG lFlags)
127 HTMLElement *This = HTMLELEM_THIS(iface);
128 HRESULT hres;
129 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
130 DISPPARAMS dispParams;
131 EXCEPINFO excep;
133 TRACE("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
135 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->node.dispex), strAttributeName,
136 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
137 if(FAILED(hres))
138 return hres;
140 dispParams.cArgs = 1;
141 dispParams.cNamedArgs = 1;
142 dispParams.rgdispidNamedArgs = &dispidNamed;
143 dispParams.rgvarg = &AttributeValue;
145 hres = IDispatchEx_InvokeEx(DISPATCHEX(&This->node.dispex), dispid,
146 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams,
147 NULL, &excep, NULL);
148 return hres;
151 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
152 LONG lFlags, VARIANT *AttributeValue)
154 HTMLElement *This = HTMLELEM_THIS(iface);
155 DISPID dispid;
156 HRESULT hres;
157 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
158 EXCEPINFO excep;
160 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
162 hres = IDispatchEx_GetDispID(DISPATCHEX(&This->node.dispex), strAttributeName,
163 fdexNameCaseInsensitive, &dispid);
164 if(hres == DISP_E_UNKNOWNNAME) {
165 V_VT(AttributeValue) = VT_NULL;
166 return S_OK;
169 if(FAILED(hres)) {
170 V_VT(AttributeValue) = VT_NULL;
171 return hres;
174 hres = IDispatchEx_InvokeEx(DISPATCHEX(&This->node.dispex), dispid,
175 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dispParams,
176 AttributeValue, &excep, NULL);
178 return hres;
181 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
182 LONG lFlags, VARIANT_BOOL *pfSuccess)
184 HTMLElement *This = HTMLELEM_THIS(iface);
185 FIXME("(%p)->()\n", This);
186 return E_NOTIMPL;
189 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
191 HTMLElement *This = HTMLELEM_THIS(iface);
192 nsAString classname_str;
193 nsresult nsres;
195 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
197 if(!This->nselem) {
198 FIXME("NULL nselem\n");
199 return E_NOTIMPL;
202 nsAString_Init(&classname_str, v);
203 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
204 nsAString_Finish(&classname_str);
205 if(NS_FAILED(nsres))
206 ERR("SetClassName failed: %08x\n", nsres);
208 return S_OK;
211 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
213 HTMLElement *This = HTMLELEM_THIS(iface);
214 nsAString class_str;
215 nsresult nsres;
216 HRESULT hres = S_OK;
218 TRACE("(%p)->(%p)\n", This, p);
220 if(!This->nselem) {
221 FIXME("NULL nselem\n");
222 return E_NOTIMPL;
225 nsAString_Init(&class_str, NULL);
226 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
228 if(NS_SUCCEEDED(nsres)) {
229 const PRUnichar *class;
230 nsAString_GetData(&class_str, &class);
231 *p = *class ? SysAllocString(class) : NULL;
232 }else {
233 ERR("GetClassName failed: %08x\n", nsres);
234 hres = E_FAIL;
237 nsAString_Finish(&class_str);
239 TRACE("className=%s\n", debugstr_w(*p));
240 return hres;
243 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
245 HTMLElement *This = HTMLELEM_THIS(iface);
246 nsAString id_str;
247 nsresult nsres;
249 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
251 if(!This->nselem) {
252 FIXME("nselem == NULL\n");
253 return S_OK;
256 nsAString_Init(&id_str, v);
257 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
258 nsAString_Finish(&id_str);
259 if(NS_FAILED(nsres))
260 ERR("SetId failed: %08x\n", nsres);
262 return S_OK;
265 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
267 HTMLElement *This = HTMLELEM_THIS(iface);
268 const PRUnichar *id;
269 nsAString id_str;
270 nsresult nsres;
272 TRACE("(%p)->(%p)\n", This, p);
274 *p = NULL;
276 if(!This->nselem)
277 return S_OK;
279 nsAString_Init(&id_str, NULL);
280 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
281 nsAString_GetData(&id_str, &id);
283 if(NS_FAILED(nsres))
284 ERR("GetId failed: %08x\n", nsres);
285 else if(*id)
286 *p = SysAllocString(id);
288 nsAString_Finish(&id_str);
289 return S_OK;
292 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
294 HTMLElement *This = HTMLELEM_THIS(iface);
295 const PRUnichar *tag;
296 nsAString tag_str;
297 nsresult nsres;
299 TRACE("(%p)->(%p)\n", This, p);
301 if(!This->nselem) {
302 static const WCHAR comment_tagW[] = {'!',0};
304 WARN("NULL nselem, assuming comment\n");
306 *p = SysAllocString(comment_tagW);
307 return S_OK;
310 nsAString_Init(&tag_str, NULL);
311 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
312 if(NS_SUCCEEDED(nsres)) {
313 nsAString_GetData(&tag_str, &tag);
314 *p = SysAllocString(tag);
315 }else {
316 ERR("GetTagName failed: %08x\n", nsres);
317 *p = NULL;
319 nsAString_Finish(&tag_str);
321 return S_OK;
324 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
326 HTMLElement *This = HTMLELEM_THIS(iface);
327 IHTMLDOMNode *node;
328 HRESULT hres;
330 TRACE("(%p)->(%p)\n", This, p);
332 hres = IHTMLDOMNode_get_parentNode(HTMLDOMNODE(&This->node), &node);
333 if(FAILED(hres))
334 return hres;
336 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
337 IHTMLDOMNode_Release(node);
338 if(FAILED(hres))
339 *p = NULL;
341 return S_OK;
344 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
346 HTMLElement *This = HTMLELEM_THIS(iface);
347 nsIDOMElementCSSInlineStyle *nselemstyle;
348 nsIDOMCSSStyleDeclaration *nsstyle;
349 nsresult nsres;
351 TRACE("(%p)->(%p)\n", This, p);
353 if(!This->nselem) {
354 FIXME("NULL nselem\n");
355 return E_NOTIMPL;
358 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
359 (void**)&nselemstyle);
360 if(NS_FAILED(nsres)) {
361 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
362 return E_FAIL;
365 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
366 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
367 if(NS_FAILED(nsres)) {
368 ERR("GetStyle failed: %08x\n", nsres);
369 return E_FAIL;
372 /* FIXME: Store style instead of creating a new instance in each call */
373 *p = HTMLStyle_Create(nsstyle);
375 nsIDOMCSSStyleDeclaration_Release(nsstyle);
376 return S_OK;
379 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
381 HTMLElement *This = HTMLELEM_THIS(iface);
382 FIXME("(%p)->()\n", This);
383 return E_NOTIMPL;
386 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
388 HTMLElement *This = HTMLELEM_THIS(iface);
389 FIXME("(%p)->(%p)\n", This, p);
390 return E_NOTIMPL;
393 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
395 HTMLElement *This = HTMLELEM_THIS(iface);
397 TRACE("(%p)->()\n", This);
399 return set_node_event(&This->node, EVENTID_CLICK, &v);
402 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
404 HTMLElement *This = HTMLELEM_THIS(iface);
406 TRACE("(%p)->(%p)\n", This, p);
408 return get_node_event(&This->node, EVENTID_CLICK, p);
411 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
413 HTMLElement *This = HTMLELEM_THIS(iface);
415 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
417 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
420 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
422 HTMLElement *This = HTMLELEM_THIS(iface);
424 TRACE("(%p)->(%p)\n", This, p);
426 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
429 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
431 HTMLElement *This = HTMLELEM_THIS(iface);
433 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
435 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
438 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
440 HTMLElement *This = HTMLELEM_THIS(iface);
442 TRACE("(%p)->(%p)\n", This, p);
444 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
447 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
449 HTMLElement *This = HTMLELEM_THIS(iface);
451 TRACE("(%p)->()\n", This);
453 return set_node_event(&This->node, EVENTID_KEYUP, &v);
456 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
458 HTMLElement *This = HTMLELEM_THIS(iface);
459 FIXME("(%p)->(%p)\n", This, p);
460 return E_NOTIMPL;
463 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
465 HTMLElement *This = HTMLELEM_THIS(iface);
466 FIXME("(%p)->()\n", This);
467 return E_NOTIMPL;
470 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
472 HTMLElement *This = HTMLELEM_THIS(iface);
473 FIXME("(%p)->(%p)\n", This, p);
474 return E_NOTIMPL;
477 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
479 HTMLElement *This = HTMLELEM_THIS(iface);
481 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
483 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
486 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
488 HTMLElement *This = HTMLELEM_THIS(iface);
490 TRACE("(%p)->(%p)\n", This, p);
492 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
495 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
497 HTMLElement *This = HTMLELEM_THIS(iface);
499 TRACE("(%p)->()\n", This);
501 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
504 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
506 HTMLElement *This = HTMLELEM_THIS(iface);
508 TRACE("(%p)->(%p)\n", This, p);
510 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
513 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
515 HTMLElement *This = HTMLELEM_THIS(iface);
516 FIXME("(%p)->()\n", This);
517 return E_NOTIMPL;
520 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
522 HTMLElement *This = HTMLELEM_THIS(iface);
523 FIXME("(%p)->(%p)\n", This, p);
524 return E_NOTIMPL;
527 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
529 HTMLElement *This = HTMLELEM_THIS(iface);
531 TRACE("(%p)->()\n", This);
533 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
536 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
538 HTMLElement *This = HTMLELEM_THIS(iface);
540 TRACE("(%p)->(%p)\n", This, p);
542 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
545 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
547 HTMLElement *This = HTMLELEM_THIS(iface);
549 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
551 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
554 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
556 HTMLElement *This = HTMLELEM_THIS(iface);
558 TRACE("(%p)->(%p)\n", This, p);
560 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
563 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
565 HTMLElement *This = HTMLELEM_THIS(iface);
567 TRACE("(%p)->(%p)\n", This, p);
569 if(!p)
570 return E_POINTER;
572 if(This->node.vtbl->get_document)
573 return This->node.vtbl->get_document(&This->node, p);
575 *p = (IDispatch*)HTMLDOC(&This->node.doc->basedoc);
576 IDispatch_AddRef(*p);
577 return S_OK;
580 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
582 HTMLElement *This = HTMLELEM_THIS(iface);
583 nsAString title_str;
584 nsresult nsres;
586 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
588 nsAString_Init(&title_str, v);
589 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
590 nsAString_Finish(&title_str);
591 if(NS_FAILED(nsres))
592 ERR("SetTitle failed: %08x\n", nsres);
594 return S_OK;
597 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
599 HTMLElement *This = HTMLELEM_THIS(iface);
600 nsAString title_str;
601 nsresult nsres;
603 TRACE("(%p)->(%p)\n", This, p);
605 nsAString_Init(&title_str, NULL);
606 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
607 if(NS_SUCCEEDED(nsres)) {
608 const PRUnichar *title;
610 nsAString_GetData(&title_str, &title);
611 *p = *title ? SysAllocString(title) : NULL;
612 }else {
613 ERR("GetTitle failed: %08x\n", nsres);
614 return E_FAIL;
617 return S_OK;
620 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
622 HTMLElement *This = HTMLELEM_THIS(iface);
623 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
624 return E_NOTIMPL;
627 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
629 HTMLElement *This = HTMLELEM_THIS(iface);
630 FIXME("(%p)->(%p)\n", This, p);
631 return E_NOTIMPL;
634 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
636 HTMLElement *This = HTMLELEM_THIS(iface);
638 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
640 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
643 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
645 HTMLElement *This = HTMLELEM_THIS(iface);
647 TRACE("(%p)->(%p)\n", This, p);
649 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
652 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
654 HTMLElement *This = HTMLELEM_THIS(iface);
655 FIXME("(%p)->()\n", This);
656 return E_NOTIMPL;
659 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
660 VARIANT_BOOL *pfResult)
662 HTMLElement *This = HTMLELEM_THIS(iface);
663 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
664 return E_NOTIMPL;
667 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
669 HTMLElement *This = HTMLELEM_THIS(iface);
670 FIXME("(%p)->(%p)\n", This, p);
671 return E_NOTIMPL;
674 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
676 HTMLElement *This = HTMLELEM_THIS(iface);
677 FIXME("(%p)->(%p)\n", This, p);
678 return E_NOTIMPL;
681 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
683 HTMLElement *This = HTMLELEM_THIS(iface);
684 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
685 return E_NOTIMPL;
688 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
690 HTMLElement *This = HTMLELEM_THIS(iface);
691 FIXME("(%p)->(%p)\n", This, p);
692 return E_NOTIMPL;
695 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
697 HTMLElement *This = HTMLELEM_THIS(iface);
698 FIXME("(%p)->(%p)\n", This, p);
699 return E_NOTIMPL;
702 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
704 HTMLElement *This = HTMLELEM_THIS(iface);
705 nsIDOMNSHTMLElement *nselem;
706 PRInt32 top = 0;
707 nsresult nsres;
709 TRACE("(%p)->(%p)\n", This, p);
711 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
712 if(NS_FAILED(nsres)) {
713 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
714 return E_FAIL;
717 nsres = nsIDOMNSHTMLElement_GetOffsetTop(nselem, &top);
718 nsIDOMNSHTMLElement_Release(nselem);
719 if(NS_FAILED(nsres)) {
720 ERR("GetOffsetTop failed: %08x\n", nsres);
721 return E_FAIL;
724 *p = top;
725 return S_OK;
728 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
730 HTMLElement *This = HTMLELEM_THIS(iface);
731 nsIDOMNSHTMLElement *nselem;
732 PRInt32 offset = 0;
733 nsresult nsres;
735 TRACE("(%p)->(%p)\n", This, p);
737 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
738 if(NS_FAILED(nsres)) {
739 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
740 return E_FAIL;
743 nsres = nsIDOMNSHTMLElement_GetOffsetWidth(nselem, &offset);
744 nsIDOMNSHTMLElement_Release(nselem);
745 if(NS_FAILED(nsres)) {
746 ERR("GetOffsetWidth failed: %08x\n", nsres);
747 return E_FAIL;
750 *p = offset;
751 return S_OK;
754 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
756 HTMLElement *This = HTMLELEM_THIS(iface);
757 nsIDOMNSHTMLElement *nselem;
758 PRInt32 offset = 0;
759 nsresult nsres;
761 TRACE("(%p)->(%p)\n", This, p);
763 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
764 if(NS_FAILED(nsres)) {
765 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
766 return E_FAIL;
769 nsres = nsIDOMNSHTMLElement_GetOffsetHeight(nselem, &offset);
770 nsIDOMNSHTMLElement_Release(nselem);
771 if(NS_FAILED(nsres)) {
772 ERR("GetOffsetHeight failed: %08x\n", nsres);
773 return E_FAIL;
776 *p = offset;
777 return S_OK;
780 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
782 HTMLElement *This = HTMLELEM_THIS(iface);
783 FIXME("(%p)->(%p)\n", This, p);
784 return E_NOTIMPL;
787 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
789 HTMLElement *This = HTMLELEM_THIS(iface);
790 nsIDOMNSHTMLElement *nselem;
791 nsAString html_str;
792 nsresult nsres;
794 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
796 if(!This->nselem) {
797 FIXME("NULL nselem\n");
798 return E_NOTIMPL;
801 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
802 if(NS_FAILED(nsres)) {
803 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
804 return E_FAIL;
807 nsAString_Init(&html_str, v);
808 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
809 nsAString_Finish(&html_str);
811 if(NS_FAILED(nsres)) {
812 FIXME("SetInnerHtml failed %08x\n", nsres);
813 return E_FAIL;
816 return S_OK;
819 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
821 HTMLElement *This = HTMLELEM_THIS(iface);
822 nsIDOMNSHTMLElement *nselem;
823 nsAString html_str;
824 nsresult nsres;
826 TRACE("(%p)->(%p)\n", This, p);
828 if(!This->nselem) {
829 FIXME("NULL nselem\n");
830 return E_NOTIMPL;
833 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
834 if(NS_FAILED(nsres)) {
835 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
836 return E_FAIL;
839 nsAString_Init(&html_str, NULL);
840 nsres = nsIDOMNSHTMLElement_GetInnerHTML(nselem, &html_str);
841 if(NS_SUCCEEDED(nsres)) {
842 const PRUnichar *html;
844 nsAString_GetData(&html_str, &html);
845 *p = *html ? SysAllocString(html) : NULL;
846 }else {
847 FIXME("SetInnerHtml failed %08x\n", nsres);
848 *p = NULL;
851 nsAString_Finish(&html_str);
852 return S_OK;
855 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
857 HTMLElement *This = HTMLELEM_THIS(iface);
858 nsIDOMNode *nschild, *tmp;
859 nsIDOMText *text_node;
860 nsAString text_str;
861 nsresult nsres;
863 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
865 while(1) {
866 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
867 if(NS_FAILED(nsres)) {
868 ERR("GetLastChild failed: %08x\n", nsres);
869 return E_FAIL;
871 if(!nschild)
872 break;
874 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
875 nsIDOMNode_Release(nschild);
876 if(NS_FAILED(nsres)) {
877 ERR("RemoveChild failed: %08x\n", nsres);
878 return E_FAIL;
880 nsIDOMNode_Release(tmp);
883 nsAString_Init(&text_str, v);
884 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
885 nsAString_Finish(&text_str);
886 if(NS_FAILED(nsres)) {
887 ERR("CreateTextNode failed: %08x\n", nsres);
888 return E_FAIL;
891 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
892 if(NS_FAILED(nsres)) {
893 ERR("AppendChild failed: %08x\n", nsres);
894 return E_FAIL;
897 nsIDOMNode_Release(tmp);
898 return S_OK;
901 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
903 HTMLElement *This = HTMLELEM_THIS(iface);
905 TRACE("(%p)->(%p)\n", This, p);
907 return get_node_text(&This->node, p);
910 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
912 HTMLElement *This = HTMLELEM_THIS(iface);
913 nsIDOMDocumentFragment *nsfragment;
914 nsIDOMDocumentRange *nsdocrange;
915 nsIDOMNSRange *nsrange;
916 nsIDOMNode *nsparent;
917 nsIDOMRange *range;
918 nsAString html_str;
919 nsresult nsres;
920 HRESULT hres = S_OK;
922 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
924 nsres = nsIDOMHTMLDocument_QueryInterface(This->node.doc->nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
925 if(NS_FAILED(nsres))
926 return E_FAIL;
928 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
929 nsIDOMDocumentRange_Release(nsdocrange);
930 if(NS_FAILED(nsres)) {
931 ERR("CreateRange failed: %08x\n", nsres);
932 return E_FAIL;
935 nsres = nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void**)&nsrange);
936 nsIDOMRange_Release(range);
937 if(NS_FAILED(nsres)) {
938 ERR("Could not get nsIDOMNSRange: %08x\n", nsres);
939 return E_FAIL;
942 nsAString_Init(&html_str, v);
943 nsIDOMNSRange_CreateContextualFragment(nsrange, &html_str, &nsfragment);
944 nsIDOMNSRange_Release(nsrange);
945 nsAString_Finish(&html_str);
946 if(NS_FAILED(nsres)) {
947 ERR("CreateContextualFragment failed: %08x\n", nsres);
948 return E_FAIL;
951 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &nsparent);
952 if(NS_SUCCEEDED(nsres) && nsparent) {
953 nsIDOMNode *nstmp;
955 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, This->node.nsnode, &nstmp);
956 nsIDOMNode_Release(nsparent);
957 if(NS_FAILED(nsres)) {
958 ERR("ReplaceChild failed: %08x\n", nsres);
959 hres = E_FAIL;
960 }else if(nstmp) {
961 nsIDOMNode_Release(nstmp);
963 }else {
964 ERR("GetParentNode failed: %08x\n", nsres);
965 hres = E_FAIL;
968 nsIDOMDocumentFragment_Release(nsfragment);
969 return hres;
972 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
974 HTMLElement *This = HTMLELEM_THIS(iface);
975 nsAString html_str;
976 HRESULT hres;
978 WARN("(%p)->(%p) semi-stub\n", This, p);
980 nsAString_Init(&html_str, NULL);
981 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
982 if(SUCCEEDED(hres)) {
983 const PRUnichar *html;
985 nsAString_GetData(&html_str, &html);
986 *p = SysAllocString(html);
987 if(!*p)
988 hres = E_OUTOFMEMORY;
991 nsAString_Finish(&html_str);
993 TRACE("ret %s\n", debugstr_w(*p));
994 return S_OK;
997 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
999 HTMLElement *This = HTMLELEM_THIS(iface);
1000 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1006 HTMLElement *This = HTMLELEM_THIS(iface);
1007 FIXME("(%p)->(%p)\n", This, p);
1008 return E_NOTIMPL;
1011 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1013 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1014 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1015 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1016 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1017 nsresult nsres;
1019 if (!strcmpiW(where, wszBeforeBegin))
1021 nsIDOMNode *unused;
1022 nsIDOMNode *parent;
1023 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1024 if (!parent) return E_INVALIDARG;
1025 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1026 if (unused) nsIDOMNode_Release(unused);
1027 nsIDOMNode_Release(parent);
1029 else if (!strcmpiW(where, wszAfterBegin))
1031 nsIDOMNode *unused;
1032 nsIDOMNode *first_child;
1033 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1034 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1035 if (unused) nsIDOMNode_Release(unused);
1036 if (first_child) nsIDOMNode_Release(first_child);
1038 else if (!strcmpiW(where, wszBeforeEnd))
1040 nsIDOMNode *unused;
1041 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1042 if (unused) nsIDOMNode_Release(unused);
1044 else if (!strcmpiW(where, wszAfterEnd))
1046 nsIDOMNode *unused;
1047 nsIDOMNode *next_sibling;
1048 nsIDOMNode *parent;
1049 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1050 if (!parent) return E_INVALIDARG;
1052 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1053 if (next_sibling)
1055 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1056 nsIDOMNode_Release(next_sibling);
1058 else
1059 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1060 nsIDOMNode_Release(parent);
1061 if (unused) nsIDOMNode_Release(unused);
1063 else
1065 ERR("invalid where: %s\n", debugstr_w(where));
1066 return E_INVALIDARG;
1069 if (NS_FAILED(nsres))
1070 return E_FAIL;
1071 else
1072 return S_OK;
1075 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1076 BSTR html)
1078 HTMLElement *This = HTMLELEM_THIS(iface);
1079 nsIDOMDocumentRange *nsdocrange;
1080 nsIDOMRange *range;
1081 nsIDOMNSRange *nsrange;
1082 nsIDOMNode *nsnode;
1083 nsAString ns_html;
1084 nsresult nsres;
1085 HRESULT hr;
1087 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1089 if(!This->node.doc->nsdoc) {
1090 WARN("NULL nsdoc\n");
1091 return E_UNEXPECTED;
1094 nsres = nsIDOMDocument_QueryInterface(This->node.doc->nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
1095 if(NS_FAILED(nsres))
1097 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
1098 return E_FAIL;
1100 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
1101 nsIDOMDocumentRange_Release(nsdocrange);
1102 if(NS_FAILED(nsres))
1104 ERR("CreateRange failed: %08x\n", nsres);
1105 return E_FAIL;
1108 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1110 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
1111 nsIDOMRange_Release(range);
1112 if(NS_FAILED(nsres))
1114 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
1115 return E_FAIL;
1118 nsAString_Init(&ns_html, html);
1120 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1121 nsIDOMNSRange_Release(nsrange);
1122 nsAString_Finish(&ns_html);
1124 if(NS_FAILED(nsres) || !nsnode)
1126 ERR("CreateTextNode failed: %08x\n", nsres);
1127 return E_FAIL;
1130 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1131 nsIDOMNode_Release(nsnode);
1133 return hr;
1136 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1137 BSTR text)
1139 HTMLElement *This = HTMLELEM_THIS(iface);
1140 nsIDOMNode *nsnode;
1141 nsAString ns_text;
1142 nsresult nsres;
1143 HRESULT hr;
1145 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1147 if(!This->node.doc->nsdoc) {
1148 WARN("NULL nsdoc\n");
1149 return E_UNEXPECTED;
1153 nsAString_Init(&ns_text, text);
1154 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1155 nsAString_Finish(&ns_text);
1157 if(NS_FAILED(nsres) || !nsnode)
1159 ERR("CreateTextNode failed: %08x\n", nsres);
1160 return E_FAIL;
1163 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1164 nsIDOMNode_Release(nsnode);
1166 return hr;
1169 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1171 HTMLElement *This = HTMLELEM_THIS(iface);
1172 FIXME("(%p)->(%p)\n", This, p);
1173 return E_NOTIMPL;
1176 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1178 HTMLElement *This = HTMLELEM_THIS(iface);
1179 FIXME("(%p)->(%p)\n", This, p);
1180 return E_NOTIMPL;
1183 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1185 HTMLElement *This = HTMLELEM_THIS(iface);
1187 TRACE("(%p)\n", This);
1189 return call_event(&This->node, EVENTID_CLICK);
1192 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1193 IHTMLFiltersCollection **p)
1195 HTMLElement *This = HTMLELEM_THIS(iface);
1196 FIXME("(%p)->(%p)\n", This, p);
1197 return E_NOTIMPL;
1200 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1202 HTMLElement *This = HTMLELEM_THIS(iface);
1203 FIXME("(%p)->()\n", This);
1204 return E_NOTIMPL;
1207 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1209 HTMLElement *This = HTMLELEM_THIS(iface);
1210 FIXME("(%p)->(%p)\n", This, p);
1211 return E_NOTIMPL;
1214 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1216 HTMLElement *This = HTMLELEM_THIS(iface);
1217 FIXME("(%p)->(%p)\n", This, String);
1218 return E_NOTIMPL;
1221 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1223 HTMLElement *This = HTMLELEM_THIS(iface);
1224 FIXME("(%p)->()\n", This);
1225 return E_NOTIMPL;
1228 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1230 HTMLElement *This = HTMLELEM_THIS(iface);
1231 FIXME("(%p)->(%p)\n", This, p);
1232 return E_NOTIMPL;
1235 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1237 HTMLElement *This = HTMLELEM_THIS(iface);
1238 FIXME("(%p)->()\n", This);
1239 return E_NOTIMPL;
1242 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1244 HTMLElement *This = HTMLELEM_THIS(iface);
1245 FIXME("(%p)->(%p)\n", This, p);
1246 return E_NOTIMPL;
1249 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1251 HTMLElement *This = HTMLELEM_THIS(iface);
1252 FIXME("(%p)->()\n", This);
1253 return E_NOTIMPL;
1256 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1258 HTMLElement *This = HTMLELEM_THIS(iface);
1259 FIXME("(%p)->(%p)\n", This, p);
1260 return E_NOTIMPL;
1263 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1265 HTMLElement *This = HTMLELEM_THIS(iface);
1266 FIXME("(%p)->()\n", This);
1267 return E_NOTIMPL;
1270 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1272 HTMLElement *This = HTMLELEM_THIS(iface);
1273 FIXME("(%p)->(%p)\n", This, p);
1274 return E_NOTIMPL;
1277 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1279 HTMLElement *This = HTMLELEM_THIS(iface);
1280 FIXME("(%p)->()\n", This);
1281 return E_NOTIMPL;
1284 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1286 HTMLElement *This = HTMLELEM_THIS(iface);
1287 FIXME("(%p)->(%p)\n", This, p);
1288 return E_NOTIMPL;
1291 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1293 HTMLElement *This = HTMLELEM_THIS(iface);
1294 FIXME("(%p)->()\n", This);
1295 return E_NOTIMPL;
1298 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1300 HTMLElement *This = HTMLELEM_THIS(iface);
1301 FIXME("(%p)->(%p)\n", This, p);
1302 return E_NOTIMPL;
1305 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1307 HTMLElement *This = HTMLELEM_THIS(iface);
1308 FIXME("(%p)->()\n", This);
1309 return E_NOTIMPL;
1312 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1314 HTMLElement *This = HTMLELEM_THIS(iface);
1315 FIXME("(%p)->(%p)\n", This, p);
1316 return E_NOTIMPL;
1319 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1321 HTMLElement *This = HTMLELEM_THIS(iface);
1322 FIXME("(%p)->()\n", This);
1323 return E_NOTIMPL;
1326 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1328 HTMLElement *This = HTMLELEM_THIS(iface);
1329 FIXME("(%p)->(%p)\n", This, p);
1330 return E_NOTIMPL;
1333 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1335 HTMLElement *This = HTMLELEM_THIS(iface);
1336 FIXME("(%p)->()\n", This);
1337 return E_NOTIMPL;
1340 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1342 HTMLElement *This = HTMLELEM_THIS(iface);
1343 FIXME("(%p)->(%p)\n", This, p);
1344 return E_NOTIMPL;
1347 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1349 HTMLElement *This = HTMLELEM_THIS(iface);
1350 nsIDOMNodeList *nsnode_list;
1351 nsresult nsres;
1353 TRACE("(%p)->(%p)\n", This, p);
1355 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1356 if(NS_FAILED(nsres)) {
1357 ERR("GetChildNodes failed: %08x\n", nsres);
1358 return E_FAIL;
1361 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, (IUnknown*)HTMLELEM(This), nsnode_list);
1363 nsIDOMNodeList_Release(nsnode_list);
1364 return S_OK;
1367 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1369 HTMLElement *This = HTMLELEM_THIS(iface);
1371 TRACE("(%p)->(%p)\n", This, p);
1373 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1374 return S_OK;
1377 static HRESULT HTMLElement_get_dispid(IUnknown *iface, BSTR name,
1378 DWORD grfdex, DISPID *pid)
1380 HTMLElement *This = HTMLELEM_THIS(iface);
1382 if(This->node.vtbl->get_dispid)
1383 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1385 return DISP_E_UNKNOWNNAME;
1388 static HRESULT HTMLElement_invoke(IUnknown *iface, DISPID id, LCID lcid,
1389 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1390 IServiceProvider *caller)
1392 HTMLElement *This = HTMLELEM_THIS(iface);
1394 if(This->node.vtbl->invoke)
1395 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1396 params, res, ei, caller);
1398 ERR("(%p): element has no invoke method\n", This);
1399 return E_NOTIMPL;
1402 #undef HTMLELEM_THIS
1404 static const IHTMLElementVtbl HTMLElementVtbl = {
1405 HTMLElement_QueryInterface,
1406 HTMLElement_AddRef,
1407 HTMLElement_Release,
1408 HTMLElement_GetTypeInfoCount,
1409 HTMLElement_GetTypeInfo,
1410 HTMLElement_GetIDsOfNames,
1411 HTMLElement_Invoke,
1412 HTMLElement_setAttribute,
1413 HTMLElement_getAttribute,
1414 HTMLElement_removeAttribute,
1415 HTMLElement_put_className,
1416 HTMLElement_get_className,
1417 HTMLElement_put_id,
1418 HTMLElement_get_id,
1419 HTMLElement_get_tagName,
1420 HTMLElement_get_parentElement,
1421 HTMLElement_get_style,
1422 HTMLElement_put_onhelp,
1423 HTMLElement_get_onhelp,
1424 HTMLElement_put_onclick,
1425 HTMLElement_get_onclick,
1426 HTMLElement_put_ondblclick,
1427 HTMLElement_get_ondblclick,
1428 HTMLElement_put_onkeydown,
1429 HTMLElement_get_onkeydown,
1430 HTMLElement_put_onkeyup,
1431 HTMLElement_get_onkeyup,
1432 HTMLElement_put_onkeypress,
1433 HTMLElement_get_onkeypress,
1434 HTMLElement_put_onmouseout,
1435 HTMLElement_get_onmouseout,
1436 HTMLElement_put_onmouseover,
1437 HTMLElement_get_onmouseover,
1438 HTMLElement_put_onmousemove,
1439 HTMLElement_get_onmousemove,
1440 HTMLElement_put_onmousedown,
1441 HTMLElement_get_onmousedown,
1442 HTMLElement_put_onmouseup,
1443 HTMLElement_get_onmouseup,
1444 HTMLElement_get_document,
1445 HTMLElement_put_title,
1446 HTMLElement_get_title,
1447 HTMLElement_put_language,
1448 HTMLElement_get_language,
1449 HTMLElement_put_onselectstart,
1450 HTMLElement_get_onselectstart,
1451 HTMLElement_scrollIntoView,
1452 HTMLElement_contains,
1453 HTMLElement_get_sourceIndex,
1454 HTMLElement_get_recordNumber,
1455 HTMLElement_put_lang,
1456 HTMLElement_get_lang,
1457 HTMLElement_get_offsetLeft,
1458 HTMLElement_get_offsetTop,
1459 HTMLElement_get_offsetWidth,
1460 HTMLElement_get_offsetHeight,
1461 HTMLElement_get_offsetParent,
1462 HTMLElement_put_innerHTML,
1463 HTMLElement_get_innerHTML,
1464 HTMLElement_put_innerText,
1465 HTMLElement_get_innerText,
1466 HTMLElement_put_outerHTML,
1467 HTMLElement_get_outerHTML,
1468 HTMLElement_put_outerText,
1469 HTMLElement_get_outerText,
1470 HTMLElement_insertAdjacentHTML,
1471 HTMLElement_insertAdjacentText,
1472 HTMLElement_get_parentTextEdit,
1473 HTMLElement_get_isTextEdit,
1474 HTMLElement_click,
1475 HTMLElement_get_filters,
1476 HTMLElement_put_ondragstart,
1477 HTMLElement_get_ondragstart,
1478 HTMLElement_toString,
1479 HTMLElement_put_onbeforeupdate,
1480 HTMLElement_get_onbeforeupdate,
1481 HTMLElement_put_onafterupdate,
1482 HTMLElement_get_onafterupdate,
1483 HTMLElement_put_onerrorupdate,
1484 HTMLElement_get_onerrorupdate,
1485 HTMLElement_put_onrowexit,
1486 HTMLElement_get_onrowexit,
1487 HTMLElement_put_onrowenter,
1488 HTMLElement_get_onrowenter,
1489 HTMLElement_put_ondatasetchanged,
1490 HTMLElement_get_ondatasetchanged,
1491 HTMLElement_put_ondataavailable,
1492 HTMLElement_get_ondataavailable,
1493 HTMLElement_put_ondatasetcomplete,
1494 HTMLElement_get_ondatasetcomplete,
1495 HTMLElement_put_onfilterchange,
1496 HTMLElement_get_onfilterchange,
1497 HTMLElement_get_children,
1498 HTMLElement_get_all
1501 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1503 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1505 *ppv = NULL;
1507 if(IsEqualGUID(&IID_IUnknown, riid)) {
1508 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1509 *ppv = HTMLELEM(This);
1510 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1511 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1512 *ppv = HTMLELEM(This);
1513 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1514 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1515 *ppv = HTMLELEM(This);
1516 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1517 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1518 *ppv = HTMLELEM2(This);
1519 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1520 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1521 *ppv = HTMLELEM3(This);
1522 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1523 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1524 *ppv = CONPTCONT(&This->cp_container);
1527 if(*ppv) {
1528 IHTMLElement_AddRef(HTMLELEM(This));
1529 return S_OK;
1532 return HTMLDOMNode_QI(&This->node, riid, ppv);
1535 void HTMLElement_destructor(HTMLDOMNode *iface)
1537 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1539 ConnectionPointContainer_Destroy(&This->cp_container);
1541 if(This->nselem)
1542 nsIDOMHTMLElement_Release(This->nselem);
1544 HTMLDOMNode_destructor(&This->node);
1547 static const NodeImplVtbl HTMLElementImplVtbl = {
1548 HTMLElement_QI,
1549 HTMLElement_destructor
1552 static const tid_t HTMLElement_iface_tids[] = {
1553 IHTMLDOMNode_tid,
1554 IHTMLDOMNode2_tid,
1555 IHTMLElement_tid,
1556 IHTMLElement2_tid,
1557 IHTMLElement3_tid,
1561 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1562 NULL,
1563 HTMLElement_get_dispid,
1564 HTMLElement_invoke
1567 static dispex_static_data_t HTMLElement_dispex = {
1568 &HTMLElement_dispex_vtbl,
1569 DispHTMLUnknownElement_tid,
1570 NULL,
1571 HTMLElement_iface_tids
1574 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1576 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1578 HTMLElement2_Init(This);
1579 HTMLElement3_Init(This);
1581 if(dispex_data && !dispex_data->vtbl)
1582 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1583 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), dispex_data ? dispex_data : &HTMLElement_dispex);
1585 if(nselem)
1586 nsIDOMHTMLElement_AddRef(nselem);
1587 This->nselem = nselem;
1589 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1591 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1594 HTMLElement *HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic)
1596 nsIDOMHTMLElement *nselem;
1597 HTMLElement *ret = NULL;
1598 nsAString class_name_str;
1599 const PRUnichar *class_name;
1600 nsresult nsres;
1602 static const WCHAR wszA[] = {'A',0};
1603 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1604 static const WCHAR wszFORM[] = {'F','O','R','M',0};
1605 static const WCHAR wszFRAME[] = {'F','R','A','M','E',0};
1606 static const WCHAR wszIFRAME[] = {'I','F','R','A','M','E',0};
1607 static const WCHAR wszIMG[] = {'I','M','G',0};
1608 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1609 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1610 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1611 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1612 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1613 static const WCHAR wszTR[] = {'T','R',0};
1614 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1616 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1617 if(NS_FAILED(nsres))
1618 return NULL;
1620 nsAString_Init(&class_name_str, NULL);
1621 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1623 nsAString_GetData(&class_name_str, &class_name);
1625 if(!strcmpW(class_name, wszA))
1626 ret = HTMLAnchorElement_Create(doc, nselem);
1627 else if(!strcmpW(class_name, wszBODY))
1628 ret = HTMLBodyElement_Create(doc, nselem);
1629 else if(!strcmpW(class_name, wszFORM))
1630 ret = HTMLFormElement_Create(doc, nselem);
1631 else if(!strcmpW(class_name, wszFRAME))
1632 ret = HTMLFrameElement_Create(doc, nselem);
1633 else if(!strcmpW(class_name, wszIFRAME))
1634 ret = HTMLIFrame_Create(doc, nselem);
1635 else if(!strcmpW(class_name, wszIMG))
1636 ret = HTMLImgElement_Create(doc, nselem);
1637 else if(!strcmpW(class_name, wszINPUT))
1638 ret = HTMLInputElement_Create(doc, nselem);
1639 else if(!strcmpW(class_name, wszOPTION))
1640 ret = HTMLOptionElement_Create(doc, nselem);
1641 else if(!strcmpW(class_name, wszSCRIPT))
1642 ret = HTMLScriptElement_Create(doc, nselem);
1643 else if(!strcmpW(class_name, wszSELECT))
1644 ret = HTMLSelectElement_Create(doc, nselem);
1645 else if(!strcmpW(class_name, wszTABLE))
1646 ret = HTMLTable_Create(doc, nselem);
1647 else if(!strcmpW(class_name, wszTR))
1648 ret = HTMLTableRow_Create(doc, nselem);
1649 else if(!strcmpW(class_name, wszTEXTAREA))
1650 ret = HTMLTextAreaElement_Create(doc, nselem);
1651 else if(use_generic)
1652 ret = HTMLGenericElement_Create(doc, nselem);
1654 if(!ret) {
1655 ret = heap_alloc_zero(sizeof(HTMLElement));
1656 HTMLElement_Init(ret, doc, nselem, NULL);
1657 ret->node.vtbl = &HTMLElementImplVtbl;
1660 TRACE("%s ret %p\n", debugstr_w(class_name), ret);
1662 nsIDOMElement_Release(nselem);
1663 nsAString_Finish(&class_name_str);
1665 return ret;