mshtml: Pass HTMLDOMNode pointer to its destructor.
[wine.git] / dlls / mshtml / htmlelem.c
blobf6460841ef019c2ee4d7bfa0700f879641a97420
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 "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "shlwapi.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
41 static HRESULT HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD,IDispatch**);
43 typedef struct {
44 HTMLElement **buf;
45 DWORD len;
46 DWORD size;
47 } elem_vector;
49 static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
51 if(buf->len == buf->size) {
52 buf->size <<= 1;
53 buf->buf = mshtml_realloc(buf->buf, buf->size*sizeof(HTMLElement**));
56 buf->buf[buf->len++] = elem;
59 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
61 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
63 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
64 REFIID riid, void **ppv)
66 HTMLElement *This = HTMLELEM_THIS(iface);
67 HRESULT hres;
69 if(This->impl)
70 return IUnknown_QueryInterface(This->impl, riid, ppv);
72 hres = HTMLElement_QI(This, riid, ppv);
73 if(FAILED(hres))
74 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
76 return hres;
79 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
81 HTMLElement *This = HTMLELEM_THIS(iface);
83 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->node));
86 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
88 HTMLElement *This = HTMLELEM_THIS(iface);
90 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->node));
93 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
95 HTMLElement *This = HTMLELEM_THIS(iface);
96 FIXME("(%p)->(%p)\n", This, pctinfo);
97 return E_NOTIMPL;
100 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
101 LCID lcid, ITypeInfo **ppTInfo)
103 HTMLElement *This = HTMLELEM_THIS(iface);
104 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
105 return E_NOTIMPL;
108 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
109 LPOLESTR *rgszNames, UINT cNames,
110 LCID lcid, DISPID *rgDispId)
112 HTMLElement *This = HTMLELEM_THIS(iface);
113 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
114 lcid, rgDispId);
115 return E_NOTIMPL;
118 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
119 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
120 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
122 HTMLElement *This = HTMLELEM_THIS(iface);
123 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
124 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
125 return E_NOTIMPL;
128 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
129 VARIANT AttributeValue, LONG lFlags)
131 HTMLElement *This = HTMLELEM_THIS(iface);
132 nsAString attr_str;
133 nsAString value_str;
134 nsresult nsres;
135 HRESULT hres;
136 VARIANT AttributeValueChanged;
138 WARN("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
140 VariantInit(&AttributeValueChanged);
142 hres = VariantChangeType(&AttributeValueChanged, &AttributeValue, 0, VT_BSTR);
143 if (FAILED(hres)) {
144 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue));
145 return hres;
148 nsAString_Init(&attr_str, strAttributeName);
149 nsAString_Init(&value_str, V_BSTR(&AttributeValueChanged));
151 TRACE("setting %s to %s\n", debugstr_w(strAttributeName),
152 debugstr_w(V_BSTR(&AttributeValueChanged)));
154 nsres = nsIDOMHTMLElement_SetAttribute(This->nselem, &attr_str, &value_str);
155 nsAString_Finish(&attr_str);
156 nsAString_Finish(&value_str);
158 if(NS_SUCCEEDED(nsres)) {
159 hres = S_OK;
160 }else {
161 ERR("SetAttribute failed: %08x\n", nsres);
162 hres = E_FAIL;
165 return hres;
168 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
169 LONG lFlags, VARIANT *AttributeValue)
171 HTMLElement *This = HTMLELEM_THIS(iface);
172 nsAString attr_str;
173 nsAString value_str;
174 const PRUnichar *value;
175 nsresult nsres;
176 HRESULT hres = S_OK;
178 WARN("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
180 VariantInit(AttributeValue);
182 nsAString_Init(&attr_str, strAttributeName);
183 nsAString_Init(&value_str, NULL);
185 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
186 nsAString_Finish(&attr_str);
188 if(NS_SUCCEEDED(nsres)) {
189 static const WCHAR wszSRC[] = {'s','r','c',0};
190 nsAString_GetData(&value_str, &value, NULL);
191 if(!strcmpiW(strAttributeName, wszSRC))
193 WCHAR buffer[256];
194 DWORD len;
195 BSTR bstrBaseUrl;
196 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
197 if(SUCCEEDED(hres)) {
198 hres = CoInternetCombineUrl(bstrBaseUrl, value,
199 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
200 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
201 SysFreeString(bstrBaseUrl);
202 if(SUCCEEDED(hres)) {
203 V_VT(AttributeValue) = VT_BSTR;
204 V_BSTR(AttributeValue) = SysAllocString(buffer);
205 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
208 }else {
209 V_VT(AttributeValue) = VT_BSTR;
210 V_BSTR(AttributeValue) = SysAllocString(value);
211 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
213 }else {
214 ERR("GetAttribute failed: %08x\n", nsres);
215 hres = E_FAIL;
218 nsAString_Finish(&value_str);
220 return hres;
223 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
224 LONG lFlags, VARIANT_BOOL *pfSuccess)
226 HTMLElement *This = HTMLELEM_THIS(iface);
227 FIXME("(%p)->()\n", This);
228 return E_NOTIMPL;
231 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
233 HTMLElement *This = HTMLELEM_THIS(iface);
234 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
235 return E_NOTIMPL;
238 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
240 HTMLElement *This = HTMLELEM_THIS(iface);
241 nsAString class_str;
242 nsresult nsres;
243 HRESULT hres = S_OK;
245 TRACE("(%p)->(%p)\n", This, p);
247 nsAString_Init(&class_str, NULL);
248 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
250 if(NS_SUCCEEDED(nsres)) {
251 const PRUnichar *class;
252 nsAString_GetData(&class_str, &class, NULL);
253 *p = SysAllocString(class);
254 }else {
255 ERR("GetClassName failed: %08x\n", nsres);
256 hres = E_FAIL;
259 nsAString_Finish(&class_str);
261 TRACE("className=%s\n", debugstr_w(*p));
262 return hres;
265 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
267 HTMLElement *This = HTMLELEM_THIS(iface);
268 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
269 return E_NOTIMPL;
272 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
274 HTMLElement *This = HTMLELEM_THIS(iface);
275 FIXME("(%p)->(%p)\n", This, p);
276 return E_NOTIMPL;
279 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
281 HTMLElement *This = HTMLELEM_THIS(iface);
282 const PRUnichar *tag;
283 nsAString tag_str;
284 nsresult nsres;
286 TRACE("(%p)->(%p)\n", This, p);
288 nsAString_Init(&tag_str, NULL);
289 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
290 if(NS_SUCCEEDED(nsres)) {
291 nsAString_GetData(&tag_str, &tag, NULL);
292 *p = SysAllocString(tag);
293 }else {
294 ERR("GetTagName failed: %08x\n", nsres);
295 *p = NULL;
297 nsAString_Finish(&tag_str);
299 return S_OK;
302 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
304 HTMLElement *This = HTMLELEM_THIS(iface);
305 FIXME("(%p)->(%p)\n", This, p);
306 return E_NOTIMPL;
309 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
311 HTMLElement *This = HTMLELEM_THIS(iface);
312 nsIDOMElementCSSInlineStyle *nselemstyle;
313 nsIDOMCSSStyleDeclaration *nsstyle;
314 nsresult nsres;
316 TRACE("(%p)->(%p)\n", This, p);
318 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
319 (void**)&nselemstyle);
320 if(NS_FAILED(nsres)) {
321 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
322 return E_FAIL;
325 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
326 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
327 if(NS_FAILED(nsres)) {
328 ERR("GetStyle failed: %08x\n", nsres);
329 return E_FAIL;
332 /* FIXME: Store style instead of creating a new instance in each call */
333 *p = HTMLStyle_Create(nsstyle);
335 nsIDOMCSSStyleDeclaration_Release(nsstyle);
336 return S_OK;
339 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
341 HTMLElement *This = HTMLELEM_THIS(iface);
342 FIXME("(%p)->()\n", This);
343 return E_NOTIMPL;
346 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
348 HTMLElement *This = HTMLELEM_THIS(iface);
349 FIXME("(%p)->(%p)\n", This, p);
350 return E_NOTIMPL;
353 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
355 HTMLElement *This = HTMLELEM_THIS(iface);
356 FIXME("(%p)->()\n", This);
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
362 HTMLElement *This = HTMLELEM_THIS(iface);
363 FIXME("(%p)->(%p)\n", This, p);
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
369 HTMLElement *This = HTMLELEM_THIS(iface);
370 FIXME("(%p)->()\n", This);
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
376 HTMLElement *This = HTMLELEM_THIS(iface);
377 FIXME("(%p)->(%p)\n", This, p);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
383 HTMLElement *This = HTMLELEM_THIS(iface);
384 FIXME("(%p)->()\n", This);
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
390 HTMLElement *This = HTMLELEM_THIS(iface);
391 FIXME("(%p)->(%p)\n", This, p);
392 return E_NOTIMPL;
395 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
397 HTMLElement *This = HTMLELEM_THIS(iface);
398 FIXME("(%p)->()\n", This);
399 return E_NOTIMPL;
402 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
404 HTMLElement *This = HTMLELEM_THIS(iface);
405 FIXME("(%p)->(%p)\n", This, p);
406 return E_NOTIMPL;
409 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
411 HTMLElement *This = HTMLELEM_THIS(iface);
412 FIXME("(%p)->()\n", This);
413 return E_NOTIMPL;
416 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
418 HTMLElement *This = HTMLELEM_THIS(iface);
419 FIXME("(%p)->(%p)\n", This, p);
420 return E_NOTIMPL;
423 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
425 HTMLElement *This = HTMLELEM_THIS(iface);
426 FIXME("(%p)->()\n", This);
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
432 HTMLElement *This = HTMLELEM_THIS(iface);
433 FIXME("(%p)->(%p)\n", This, p);
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
439 HTMLElement *This = HTMLELEM_THIS(iface);
440 FIXME("(%p)->()\n", This);
441 return E_NOTIMPL;
444 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
446 HTMLElement *This = HTMLELEM_THIS(iface);
447 FIXME("(%p)->(%p)\n", This, p);
448 return E_NOTIMPL;
451 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
453 HTMLElement *This = HTMLELEM_THIS(iface);
454 FIXME("(%p)->()\n", This);
455 return E_NOTIMPL;
458 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
460 HTMLElement *This = HTMLELEM_THIS(iface);
461 FIXME("(%p)->(%p)\n", This, p);
462 return E_NOTIMPL;
465 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
467 HTMLElement *This = HTMLELEM_THIS(iface);
468 FIXME("(%p)->()\n", This);
469 return E_NOTIMPL;
472 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
474 HTMLElement *This = HTMLELEM_THIS(iface);
475 FIXME("(%p)->(%p)\n", This, p);
476 return E_NOTIMPL;
479 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
481 HTMLElement *This = HTMLELEM_THIS(iface);
482 FIXME("(%p)->()\n", This);
483 return E_NOTIMPL;
486 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
488 HTMLElement *This = HTMLELEM_THIS(iface);
489 FIXME("(%p)->(%p)\n", This, p);
490 return E_NOTIMPL;
493 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
495 HTMLElement *This = HTMLELEM_THIS(iface);
496 FIXME("(%p)->(%p)\n", This, p);
497 return E_NOTIMPL;
500 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
502 HTMLElement *This = HTMLELEM_THIS(iface);
503 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
504 return E_NOTIMPL;
507 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
509 HTMLElement *This = HTMLELEM_THIS(iface);
510 FIXME("(%p)->(%p)\n", This, p);
511 return E_NOTIMPL;
514 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
516 HTMLElement *This = HTMLELEM_THIS(iface);
517 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
518 return E_NOTIMPL;
521 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
523 HTMLElement *This = HTMLELEM_THIS(iface);
524 FIXME("(%p)->(%p)\n", This, p);
525 return E_NOTIMPL;
528 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
530 HTMLElement *This = HTMLELEM_THIS(iface);
531 FIXME("(%p)->()\n", This);
532 return E_NOTIMPL;
535 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
537 HTMLElement *This = HTMLELEM_THIS(iface);
538 FIXME("(%p)->(%p)\n", This, p);
539 return E_NOTIMPL;
542 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
544 HTMLElement *This = HTMLELEM_THIS(iface);
545 FIXME("(%p)->()\n", This);
546 return E_NOTIMPL;
549 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
550 VARIANT_BOOL *pfResult)
552 HTMLElement *This = HTMLELEM_THIS(iface);
553 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
554 return E_NOTIMPL;
557 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
559 HTMLElement *This = HTMLELEM_THIS(iface);
560 FIXME("(%p)->(%p)\n", This, p);
561 return E_NOTIMPL;
564 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
566 HTMLElement *This = HTMLELEM_THIS(iface);
567 FIXME("(%p)->(%p)\n", This, p);
568 return E_NOTIMPL;
571 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
573 HTMLElement *This = HTMLELEM_THIS(iface);
574 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
575 return E_NOTIMPL;
578 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
580 HTMLElement *This = HTMLELEM_THIS(iface);
581 FIXME("(%p)->(%p)\n", This, p);
582 return E_NOTIMPL;
585 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
587 HTMLElement *This = HTMLELEM_THIS(iface);
588 FIXME("(%p)->(%p)\n", This, p);
589 return E_NOTIMPL;
592 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
594 HTMLElement *This = HTMLELEM_THIS(iface);
595 FIXME("(%p)->(%p)\n", This, p);
596 return E_NOTIMPL;
599 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
601 HTMLElement *This = HTMLELEM_THIS(iface);
602 FIXME("(%p)->(%p)\n", This, p);
603 return E_NOTIMPL;
606 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
608 HTMLElement *This = HTMLELEM_THIS(iface);
609 FIXME("(%p)->(%p)\n", This, p);
610 return E_NOTIMPL;
613 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
615 HTMLElement *This = HTMLELEM_THIS(iface);
616 FIXME("(%p)->(%p)\n", This, p);
617 return E_NOTIMPL;
620 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
622 HTMLElement *This = HTMLELEM_THIS(iface);
623 nsIDOMNSHTMLElement *nselem;
624 nsAString html_str;
625 nsresult nsres;
627 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
629 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
630 if(NS_FAILED(nsres)) {
631 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
632 return E_FAIL;
635 nsAString_Init(&html_str, v);
636 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
637 nsAString_Finish(&html_str);
639 if(NS_FAILED(nsres)) {
640 FIXME("SetInnerHtml failed %08x\n", nsres);
641 return E_FAIL;
644 return S_OK;
647 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
649 HTMLElement *This = HTMLELEM_THIS(iface);
650 FIXME("(%p)->(%p)\n", This, p);
651 return E_NOTIMPL;
654 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
656 HTMLElement *This = HTMLELEM_THIS(iface);
657 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
658 return E_NOTIMPL;
661 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
663 HTMLElement *This = HTMLELEM_THIS(iface);
664 FIXME("(%p)->(%p)\n", This, p);
665 return E_NOTIMPL;
668 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
670 HTMLElement *This = HTMLELEM_THIS(iface);
671 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
672 return E_NOTIMPL;
675 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
677 HTMLElement *This = HTMLELEM_THIS(iface);
678 FIXME("(%p)->(%p)\n", This, p);
679 return E_NOTIMPL;
682 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
684 HTMLElement *This = HTMLELEM_THIS(iface);
685 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
686 return E_NOTIMPL;
689 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
691 HTMLElement *This = HTMLELEM_THIS(iface);
692 FIXME("(%p)->(%p)\n", This, p);
693 return E_NOTIMPL;
696 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
698 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
699 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
700 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
701 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
702 nsresult nsres;
704 if (!strcmpiW(where, wszBeforeBegin))
706 nsIDOMNode *unused;
707 nsIDOMNode *parent;
708 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
709 if (!parent) return E_INVALIDARG;
710 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
711 (nsIDOMNode *)This->nselem, &unused);
712 if (unused) nsIDOMNode_Release(unused);
713 nsIDOMNode_Release(parent);
715 else if (!strcmpiW(where, wszAfterBegin))
717 nsIDOMNode *unused;
718 nsIDOMNode *first_child;
719 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
720 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
721 if (unused) nsIDOMNode_Release(unused);
722 if (first_child) nsIDOMNode_Release(first_child);
724 else if (!strcmpiW(where, wszBeforeEnd))
726 nsIDOMNode *unused;
727 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
728 if (unused) nsIDOMNode_Release(unused);
730 else if (!strcmpiW(where, wszAfterEnd))
732 nsIDOMNode *unused;
733 nsIDOMNode *next_sibling;
734 nsIDOMNode *parent;
735 nsIDOMNode_GetParentNode(This->nselem, &parent);
736 if (!parent) return E_INVALIDARG;
738 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
739 if (next_sibling)
741 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
742 nsIDOMNode_Release(next_sibling);
744 else
745 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
746 nsIDOMNode_Release(parent);
747 if (unused) nsIDOMNode_Release(unused);
749 else
751 ERR("invalid where: %s\n", debugstr_w(where));
752 return E_INVALIDARG;
755 if (NS_FAILED(nsres))
756 return E_FAIL;
757 else
758 return S_OK;
761 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
762 BSTR html)
764 HTMLElement *This = HTMLELEM_THIS(iface);
765 nsresult nsres;
766 nsIDOMDocument *nsdoc;
767 nsIDOMDocumentRange *nsdocrange;
768 nsIDOMRange *range;
769 nsIDOMNSRange *nsrange;
770 nsIDOMNode *nsnode;
771 nsAString ns_html;
772 HRESULT hr;
774 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
776 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
777 if(NS_FAILED(nsres))
779 ERR("GetDocument failed: %08x\n", nsres);
780 return E_FAIL;
783 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
784 nsIDOMDocument_Release(nsdoc);
785 if(NS_FAILED(nsres))
787 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
788 return E_FAIL;
790 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
791 nsIDOMDocumentRange_Release(nsdocrange);
792 if(NS_FAILED(nsres))
794 ERR("CreateRange failed: %08x\n", nsres);
795 return E_FAIL;
798 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
800 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
801 nsIDOMRange_Release(range);
802 if(NS_FAILED(nsres))
804 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
805 return E_FAIL;
808 nsAString_Init(&ns_html, html);
810 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
811 nsIDOMNSRange_Release(nsrange);
812 nsAString_Finish(&ns_html);
814 if(NS_FAILED(nsres) || !nsnode)
816 ERR("CreateTextNode failed: %08x\n", nsres);
817 return E_FAIL;
820 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
821 nsIDOMNode_Release(nsnode);
823 return hr;
826 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
827 BSTR text)
829 HTMLElement *This = HTMLELEM_THIS(iface);
830 nsresult nsres;
831 nsIDOMDocument *nsdoc;
832 nsIDOMNode *nsnode;
833 nsAString ns_text;
834 HRESULT hr;
836 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
838 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
839 if(NS_FAILED(nsres) || !nsdoc)
841 ERR("GetDocument failed: %08x\n", nsres);
842 return E_FAIL;
845 nsAString_Init(&ns_text, text);
847 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
848 nsIDOMDocument_Release(nsdoc);
849 nsAString_Finish(&ns_text);
851 if(NS_FAILED(nsres) || !nsnode)
853 ERR("CreateTextNode failed: %08x\n", nsres);
854 return E_FAIL;
857 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
858 nsIDOMNode_Release(nsnode);
860 return hr;
863 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
865 HTMLElement *This = HTMLELEM_THIS(iface);
866 FIXME("(%p)->(%p)\n", This, p);
867 return E_NOTIMPL;
870 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
872 HTMLElement *This = HTMLELEM_THIS(iface);
873 FIXME("(%p)->(%p)\n", This, p);
874 return E_NOTIMPL;
877 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
879 HTMLElement *This = HTMLELEM_THIS(iface);
880 FIXME("(%p)\n", This);
881 return E_NOTIMPL;
884 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
885 IHTMLFiltersCollection **p)
887 HTMLElement *This = HTMLELEM_THIS(iface);
888 FIXME("(%p)->(%p)\n", This, p);
889 return E_NOTIMPL;
892 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
894 HTMLElement *This = HTMLELEM_THIS(iface);
895 FIXME("(%p)->()\n", This);
896 return E_NOTIMPL;
899 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
901 HTMLElement *This = HTMLELEM_THIS(iface);
902 FIXME("(%p)->(%p)\n", This, p);
903 return E_NOTIMPL;
906 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
908 HTMLElement *This = HTMLELEM_THIS(iface);
909 FIXME("(%p)->(%p)\n", This, String);
910 return E_NOTIMPL;
913 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
915 HTMLElement *This = HTMLELEM_THIS(iface);
916 FIXME("(%p)->()\n", This);
917 return E_NOTIMPL;
920 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
922 HTMLElement *This = HTMLELEM_THIS(iface);
923 FIXME("(%p)->(%p)\n", This, p);
924 return E_NOTIMPL;
927 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
929 HTMLElement *This = HTMLELEM_THIS(iface);
930 FIXME("(%p)->()\n", This);
931 return E_NOTIMPL;
934 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
936 HTMLElement *This = HTMLELEM_THIS(iface);
937 FIXME("(%p)->(%p)\n", This, p);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
943 HTMLElement *This = HTMLELEM_THIS(iface);
944 FIXME("(%p)->()\n", This);
945 return E_NOTIMPL;
948 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
950 HTMLElement *This = HTMLELEM_THIS(iface);
951 FIXME("(%p)->(%p)\n", This, p);
952 return E_NOTIMPL;
955 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
957 HTMLElement *This = HTMLELEM_THIS(iface);
958 FIXME("(%p)->()\n", This);
959 return E_NOTIMPL;
962 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
964 HTMLElement *This = HTMLELEM_THIS(iface);
965 FIXME("(%p)->(%p)\n", This, p);
966 return E_NOTIMPL;
969 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
971 HTMLElement *This = HTMLELEM_THIS(iface);
972 FIXME("(%p)->()\n", This);
973 return E_NOTIMPL;
976 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
978 HTMLElement *This = HTMLELEM_THIS(iface);
979 FIXME("(%p)->(%p)\n", This, p);
980 return E_NOTIMPL;
983 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
985 HTMLElement *This = HTMLELEM_THIS(iface);
986 FIXME("(%p)->()\n", This);
987 return E_NOTIMPL;
990 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
992 HTMLElement *This = HTMLELEM_THIS(iface);
993 FIXME("(%p)->(%p)\n", This, p);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
999 HTMLElement *This = HTMLELEM_THIS(iface);
1000 FIXME("(%p)->()\n", This);
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1006 HTMLElement *This = HTMLELEM_THIS(iface);
1007 FIXME("(%p)->(%p)\n", This, p);
1008 return E_NOTIMPL;
1011 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1013 HTMLElement *This = HTMLELEM_THIS(iface);
1014 FIXME("(%p)->()\n", This);
1015 return E_NOTIMPL;
1018 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1020 HTMLElement *This = HTMLELEM_THIS(iface);
1021 FIXME("(%p)->(%p)\n", This, p);
1022 return E_NOTIMPL;
1025 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1027 HTMLElement *This = HTMLELEM_THIS(iface);
1028 FIXME("(%p)->()\n", This);
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1034 HTMLElement *This = HTMLELEM_THIS(iface);
1035 FIXME("(%p)->(%p)\n", This, p);
1036 return E_NOTIMPL;
1039 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1041 nsIDOMNodeList *nsnode_list;
1042 nsIDOMNode *iter;
1043 PRUint32 list_len = 0, i;
1044 PRUint16 node_type;
1045 nsresult nsres;
1047 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1048 if(NS_FAILED(nsres)) {
1049 ERR("GetChildNodes failed: %08x\n", nsres);
1050 return;
1053 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1054 if(!list_len)
1055 return;
1057 buf->size = list_len;
1058 buf->buf = mshtml_alloc(buf->size*sizeof(HTMLElement**));
1060 for(i=0; i<list_len; i++) {
1061 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1062 if(NS_FAILED(nsres)) {
1063 ERR("Item failed: %08x\n", nsres);
1064 continue;
1067 nsres = nsIDOMNode_GetNodeType(iter, &node_type);
1068 if(NS_SUCCEEDED(nsres) && node_type == ELEMENT_NODE)
1069 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter)));
1073 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1075 HTMLElement *This = HTMLELEM_THIS(iface);
1076 elem_vector buf = {NULL, 0, 0};
1078 TRACE("(%p)->(%p)\n", This, p);
1080 create_child_list(This->node.doc, This, &buf);
1082 return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
1085 static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1087 nsIDOMNodeList *nsnode_list;
1088 nsIDOMNode *iter;
1089 PRUint32 list_len = 0, i;
1090 PRUint16 node_type;
1091 nsresult nsres;
1093 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1094 if(NS_FAILED(nsres)) {
1095 ERR("GetChildNodes failed: %08x\n", nsres);
1096 return;
1099 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1100 if(!list_len)
1101 return;
1103 for(i=0; i<list_len; i++) {
1104 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1105 if(NS_FAILED(nsres)) {
1106 ERR("Item failed: %08x\n", nsres);
1107 continue;
1110 nsres = nsIDOMNode_GetNodeType(iter, &node_type);
1111 if(NS_SUCCEEDED(nsres) && node_type == ELEMENT_NODE) {
1112 HTMLDOMNode *node = get_node(doc, iter);
1114 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1115 create_all_list(doc, HTMLELEM_NODE_THIS(node), buf);
1120 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1122 HTMLElement *This = HTMLELEM_THIS(iface);
1123 elem_vector buf = {NULL, 0, 8};
1125 TRACE("(%p)->(%p)\n", This, p);
1127 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**));
1129 create_all_list(This->node.doc, This, &buf);
1131 TRACE("ret\n");
1133 if(!buf.len) {
1134 mshtml_free(buf.buf);
1135 buf.buf = NULL;
1136 }else if(buf.size > buf.len) {
1137 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement**));
1140 return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
1143 #undef HTMLELEM_THIS
1145 static const IHTMLElementVtbl HTMLElementVtbl = {
1146 HTMLElement_QueryInterface,
1147 HTMLElement_AddRef,
1148 HTMLElement_Release,
1149 HTMLElement_GetTypeInfoCount,
1150 HTMLElement_GetTypeInfo,
1151 HTMLElement_GetIDsOfNames,
1152 HTMLElement_Invoke,
1153 HTMLElement_setAttribute,
1154 HTMLElement_getAttribute,
1155 HTMLElement_removeAttribute,
1156 HTMLElement_put_className,
1157 HTMLElement_get_className,
1158 HTMLElement_put_id,
1159 HTMLElement_get_id,
1160 HTMLElement_get_tagName,
1161 HTMLElement_get_parentElement,
1162 HTMLElement_get_style,
1163 HTMLElement_put_onhelp,
1164 HTMLElement_get_onhelp,
1165 HTMLElement_put_onclick,
1166 HTMLElement_get_onclick,
1167 HTMLElement_put_ondblclick,
1168 HTMLElement_get_ondblclick,
1169 HTMLElement_put_onkeydown,
1170 HTMLElement_get_onkeydown,
1171 HTMLElement_put_onkeyup,
1172 HTMLElement_get_onkeyup,
1173 HTMLElement_put_onkeypress,
1174 HTMLElement_get_onkeypress,
1175 HTMLElement_put_onmouseout,
1176 HTMLElement_get_onmouseout,
1177 HTMLElement_put_onmouseover,
1178 HTMLElement_get_onmouseover,
1179 HTMLElement_put_onmousemove,
1180 HTMLElement_get_onmousemove,
1181 HTMLElement_put_onmousedown,
1182 HTMLElement_get_onmousedown,
1183 HTMLElement_put_onmouseup,
1184 HTMLElement_get_onmouseup,
1185 HTMLElement_get_document,
1186 HTMLElement_put_title,
1187 HTMLElement_get_title,
1188 HTMLElement_put_language,
1189 HTMLElement_get_language,
1190 HTMLElement_put_onselectstart,
1191 HTMLElement_get_onselectstart,
1192 HTMLElement_scrollIntoView,
1193 HTMLElement_contains,
1194 HTMLElement_get_sourceIndex,
1195 HTMLElement_get_recordNumber,
1196 HTMLElement_put_lang,
1197 HTMLElement_get_lang,
1198 HTMLElement_get_offsetLeft,
1199 HTMLElement_get_offsetTop,
1200 HTMLElement_get_offsetWidth,
1201 HTMLElement_get_offsetHeight,
1202 HTMLElement_get_offsetParent,
1203 HTMLElement_put_innerHTML,
1204 HTMLElement_get_innerHTML,
1205 HTMLElement_put_innerText,
1206 HTMLElement_get_innerText,
1207 HTMLElement_put_outerHTML,
1208 HTMLElement_get_outerHTML,
1209 HTMLElement_put_outerText,
1210 HTMLElement_get_outerText,
1211 HTMLElement_insertAdjacentHTML,
1212 HTMLElement_insertAdjacentText,
1213 HTMLElement_get_parentTextEdit,
1214 HTMLElement_get_isTextEdit,
1215 HTMLElement_click,
1216 HTMLElement_get_filters,
1217 HTMLElement_put_ondragstart,
1218 HTMLElement_get_ondragstart,
1219 HTMLElement_toString,
1220 HTMLElement_put_onbeforeupdate,
1221 HTMLElement_get_onbeforeupdate,
1222 HTMLElement_put_onafterupdate,
1223 HTMLElement_get_onafterupdate,
1224 HTMLElement_put_onerrorupdate,
1225 HTMLElement_get_onerrorupdate,
1226 HTMLElement_put_onrowexit,
1227 HTMLElement_get_onrowexit,
1228 HTMLElement_put_onrowenter,
1229 HTMLElement_get_onrowenter,
1230 HTMLElement_put_ondatasetchanged,
1231 HTMLElement_get_ondatasetchanged,
1232 HTMLElement_put_ondataavailable,
1233 HTMLElement_get_ondataavailable,
1234 HTMLElement_put_ondatasetcomplete,
1235 HTMLElement_get_ondatasetcomplete,
1236 HTMLElement_put_onfilterchange,
1237 HTMLElement_get_onfilterchange,
1238 HTMLElement_get_children,
1239 HTMLElement_get_all
1242 HRESULT HTMLElement_QI(HTMLElement *This, REFIID riid, void **ppv)
1244 *ppv = NULL;
1246 if(IsEqualGUID(&IID_IUnknown, riid)) {
1247 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1248 *ppv = HTMLELEM(This);
1249 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1250 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1251 *ppv = HTMLELEM(This);
1252 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1253 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1254 *ppv = HTMLELEM(This);
1255 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1256 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1257 *ppv = HTMLELEM2(This);
1260 if(*ppv) {
1261 IHTMLElement_AddRef(HTMLELEM(This));
1262 return S_OK;
1265 return HTMLDOMNode_QI(&This->node, riid, ppv);
1268 static void HTMLElement_destructor(HTMLDOMNode *iface)
1270 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1272 if(This->destructor)
1273 This->destructor(This->impl);
1275 if(This->nselem)
1276 nsIDOMHTMLElement_Release(This->nselem);
1278 mshtml_free(This);
1281 HTMLElement *HTMLElement_Create(nsIDOMNode *nsnode)
1283 nsIDOMHTMLElement *nselem;
1284 HTMLElement *ret = NULL;
1285 nsAString class_name_str;
1286 const PRUnichar *class_name;
1287 nsresult nsres;
1289 static const WCHAR wszA[] = {'A',0};
1290 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1291 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1292 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1293 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1295 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1296 if(NS_FAILED(nsres))
1297 return NULL;
1299 nsAString_Init(&class_name_str, NULL);
1300 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1302 nsAString_GetData(&class_name_str, &class_name, NULL);
1304 if(!strcmpW(class_name, wszA))
1305 ret = HTMLAnchorElement_Create(nselem);
1306 else if(!strcmpW(class_name, wszBODY))
1307 ret = HTMLBodyElement_Create(nselem);
1308 else if(!strcmpW(class_name, wszINPUT))
1309 ret = HTMLInputElement_Create(nselem);
1310 else if(!strcmpW(class_name, wszSELECT))
1311 ret = HTMLSelectElement_Create(nselem);
1312 else if(!strcmpW(class_name, wszTEXTAREA))
1313 ret = HTMLTextAreaElement_Create(nselem);
1315 if(!ret) {
1316 ret = mshtml_alloc(sizeof(HTMLElement));
1318 ret->impl = NULL;
1319 ret->destructor = NULL;
1322 nsAString_Finish(&class_name_str);
1324 ret->lpHTMLElementVtbl = &HTMLElementVtbl;
1325 ret->nselem = nselem;
1327 HTMLElement2_Init(ret);
1329 ret->node.impl.elem = HTMLELEM(ret);
1330 ret->node.destructor = HTMLElement_destructor;
1332 return ret;
1335 typedef struct {
1336 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1338 IUnknown *ref_unk;
1339 HTMLElement **elems;
1340 DWORD len;
1342 LONG ref;
1343 } HTMLElementCollection;
1345 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1347 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1349 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1350 REFIID riid, void **ppv)
1352 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1354 *ppv = NULL;
1356 if(IsEqualGUID(&IID_IUnknown, riid)) {
1357 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1358 *ppv = HTMLELEMCOL(This);
1359 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1360 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1361 *ppv = HTMLELEMCOL(This);
1362 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1363 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1364 *ppv = HTMLELEMCOL(This);
1367 if(*ppv) {
1368 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1369 return S_OK;
1372 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1373 return E_NOINTERFACE;
1376 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1378 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1379 LONG ref = InterlockedIncrement(&This->ref);
1381 TRACE("(%p) ref=%d\n", This, ref);
1383 return ref;
1386 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1388 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1389 LONG ref = InterlockedDecrement(&This->ref);
1391 TRACE("(%p) ref=%d\n", This, ref);
1393 if(!ref) {
1394 IUnknown_Release(This->ref_unk);
1395 mshtml_free(This->elems);
1396 mshtml_free(This);
1399 return ref;
1402 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1403 UINT *pctinfo)
1405 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1406 FIXME("(%p)->(%p)\n", This, pctinfo);
1407 return E_NOTIMPL;
1410 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1411 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1413 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1414 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1415 return E_NOTIMPL;
1418 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1419 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1421 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1422 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1423 lcid, rgDispId);
1424 return E_NOTIMPL;
1427 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1428 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1429 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1431 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1432 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1433 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1434 return E_NOTIMPL;
1437 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1438 BSTR *String)
1440 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1441 FIXME("(%p)->(%p)\n", This, String);
1442 return E_NOTIMPL;
1445 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1446 long v)
1448 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1449 FIXME("(%p)->(%ld)\n", This, v);
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1454 long *p)
1456 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1458 TRACE("(%p)->(%p)\n", This, p);
1460 *p = This->len;
1461 return S_OK;
1464 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1465 IUnknown **p)
1467 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1468 FIXME("(%p)->(%p)\n", This, p);
1469 return E_NOTIMPL;
1472 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1473 VARIANT name, VARIANT index, IDispatch **pdisp)
1475 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1477 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1479 if(V_VT(&name) == VT_I4) {
1480 TRACE("name is VT_I4: %d\n", V_I4(&name));
1481 if(V_I4(&name) < 0 || V_I4(&name) >= This->len) {
1482 ERR("Invalid name! name=%d\n", V_I4(&name));
1483 return E_INVALIDARG;
1486 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1487 IDispatch_AddRef(*pdisp);
1488 TRACE("Returning pdisp=%p\n", pdisp);
1489 return S_OK;
1492 if(V_VT(&name) == VT_BSTR) {
1493 DWORD i;
1494 nsAString tag_str;
1495 const PRUnichar *tag;
1496 elem_vector buf = {NULL, 0, 8};
1498 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1500 nsAString_Init(&tag_str, NULL);
1501 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement*));
1503 for(i=0; i<This->len; i++) {
1504 if(!This->elems[i]->nselem) continue;
1506 nsIDOMHTMLElement_GetId(This->elems[i]->nselem, &tag_str);
1507 nsAString_GetData(&tag_str, &tag, NULL);
1509 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1510 V_BSTR(&name), -1) == CSTR_EQUAL) {
1511 TRACE("Found name. elem=%d\n", i);
1512 if (V_VT(&index) == VT_I4)
1513 if (buf.len == V_I4(&index)) {
1514 nsAString_Finish(&tag_str);
1515 mshtml_free(buf.buf);
1516 buf.buf = NULL;
1517 *pdisp = (IDispatch*)This->elems[i];
1518 TRACE("Returning element %d pdisp=%p\n", i, pdisp);
1519 IDispatch_AddRef(*pdisp);
1520 return S_OK;
1522 elem_vector_add(&buf, This->elems[i]);
1525 nsAString_Finish(&tag_str);
1526 if (V_VT(&index) == VT_I4) {
1527 mshtml_free(buf.buf);
1528 buf.buf = NULL;
1529 ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index), buf.len);
1530 return E_INVALIDARG;
1532 if(!buf.len) {
1533 mshtml_free(buf.buf);
1534 buf.buf = NULL;
1535 } else if(buf.size > buf.len) {
1536 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
1538 TRACE("Returning %d element(s).\n", buf.len);
1539 return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
1542 FIXME("unsupported arguments\n");
1543 return E_INVALIDARG;
1546 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1547 VARIANT tagName, IDispatch **pdisp)
1549 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1550 DWORD i;
1551 nsAString tag_str;
1552 const PRUnichar *tag;
1553 elem_vector buf = {NULL, 0, 8};
1555 if(V_VT(&tagName) != VT_BSTR) {
1556 WARN("Invalid arg\n");
1557 return DISP_E_MEMBERNOTFOUND;
1560 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1562 buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement*));
1564 nsAString_Init(&tag_str, NULL);
1566 for(i=0; i<This->len; i++) {
1567 if(!This->elems[i]->nselem)
1568 continue;
1570 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1571 nsAString_GetData(&tag_str, &tag, NULL);
1573 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1574 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1575 elem_vector_add(&buf, This->elems[i]);
1578 nsAString_Finish(&tag_str);
1580 TRACE("fount %d tags\n", buf.len);
1582 if(!buf.len) {
1583 mshtml_free(buf.buf);
1584 buf.buf = NULL;
1585 }else if(buf.size > buf.len) {
1586 buf.buf = mshtml_realloc(buf.buf, buf.len*sizeof(HTMLElement*));
1589 return HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len, pdisp);
1592 #undef ELEMCOL_THIS
1594 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1595 HTMLElementCollection_QueryInterface,
1596 HTMLElementCollection_AddRef,
1597 HTMLElementCollection_Release,
1598 HTMLElementCollection_GetTypeInfoCount,
1599 HTMLElementCollection_GetTypeInfo,
1600 HTMLElementCollection_GetIDsOfNames,
1601 HTMLElementCollection_Invoke,
1602 HTMLElementCollection_toString,
1603 HTMLElementCollection_put_length,
1604 HTMLElementCollection_get_length,
1605 HTMLElementCollection_get__newEnum,
1606 HTMLElementCollection_item,
1607 HTMLElementCollection_tags
1610 static HRESULT HTMLElementCollection_Create(IUnknown *ref_unk, HTMLElement **elems, DWORD len,
1611 IDispatch **p)
1613 HTMLElementCollection *ret = mshtml_alloc(sizeof(HTMLElementCollection));
1615 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1616 ret->ref = 1;
1617 ret->elems = elems;
1618 ret->len = len;
1620 IUnknown_AddRef(ref_unk);
1621 ret->ref_unk = ref_unk;
1623 TRACE("ret=%p len=%d\n", ret, len);
1625 *p = (IDispatch*)ret;
1626 return S_OK;