msvcrt: Follow Vista behaviour in wcscpy_s.
[wine.git] / dlls / mshtml / htmlelem.c
blob22e8c5ce8fd75bc617e91e526c970a5e6cb1ab23
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"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD);
40 typedef struct {
41 HTMLElement **buf;
42 DWORD len;
43 DWORD size;
44 } elem_vector;
46 static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
48 if(buf->len == buf->size) {
49 buf->size <<= 1;
50 buf->buf = heap_realloc(buf->buf, buf->size*sizeof(HTMLElement**));
53 buf->buf[buf->len++] = elem;
56 static void elem_vector_normalize(elem_vector *buf)
58 if(!buf->len) {
59 heap_free(buf->buf);
60 buf->buf = NULL;
61 }else if(buf->size > buf->len) {
62 buf->buf = heap_realloc(buf->buf, buf->len*sizeof(HTMLElement**));
65 buf->size = buf->len;
68 static BOOL is_elem_node(nsIDOMNode *node)
70 PRUint16 type=0;
72 nsIDOMNode_GetNodeType(node, &type);
74 return type == ELEMENT_NODE || type == COMMENT_NODE;
77 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
79 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
81 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
82 REFIID riid, void **ppv)
84 HTMLElement *This = HTMLELEM_THIS(iface);
86 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This->node), riid, ppv);
89 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
91 HTMLElement *This = HTMLELEM_THIS(iface);
93 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This->node));
96 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
98 HTMLElement *This = HTMLELEM_THIS(iface);
100 return IHTMLDOMNode_Release(HTMLDOMNODE(&This->node));
103 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
105 HTMLElement *This = HTMLELEM_THIS(iface);
106 FIXME("(%p)->(%p)\n", This, pctinfo);
107 return E_NOTIMPL;
110 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
111 LCID lcid, ITypeInfo **ppTInfo)
113 HTMLElement *This = HTMLELEM_THIS(iface);
114 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
115 return E_NOTIMPL;
118 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
119 LPOLESTR *rgszNames, UINT cNames,
120 LCID lcid, DISPID *rgDispId)
122 HTMLElement *This = HTMLELEM_THIS(iface);
123 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
124 lcid, rgDispId);
125 return E_NOTIMPL;
128 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
129 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
130 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
132 HTMLElement *This = HTMLELEM_THIS(iface);
133 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
134 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
135 return E_NOTIMPL;
138 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
139 VARIANT AttributeValue, LONG lFlags)
141 HTMLElement *This = HTMLELEM_THIS(iface);
142 nsAString attr_str;
143 nsAString value_str;
144 nsresult nsres;
145 HRESULT hres;
146 VARIANT AttributeValueChanged;
148 WARN("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
150 if(!This->nselem) {
151 FIXME("NULL nselem\n");
152 return E_NOTIMPL;
155 VariantInit(&AttributeValueChanged);
157 hres = VariantChangeType(&AttributeValueChanged, &AttributeValue, 0, VT_BSTR);
158 if (FAILED(hres)) {
159 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue));
160 return hres;
163 nsAString_Init(&attr_str, strAttributeName);
164 nsAString_Init(&value_str, V_BSTR(&AttributeValueChanged));
166 TRACE("setting %s to %s\n", debugstr_w(strAttributeName),
167 debugstr_w(V_BSTR(&AttributeValueChanged)));
169 nsres = nsIDOMHTMLElement_SetAttribute(This->nselem, &attr_str, &value_str);
170 nsAString_Finish(&attr_str);
171 nsAString_Finish(&value_str);
173 if(NS_SUCCEEDED(nsres)) {
174 hres = S_OK;
175 }else {
176 ERR("SetAttribute failed: %08x\n", nsres);
177 hres = E_FAIL;
180 return hres;
183 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
184 LONG lFlags, VARIANT *AttributeValue)
186 HTMLElement *This = HTMLELEM_THIS(iface);
187 nsAString attr_str;
188 nsAString value_str;
189 const PRUnichar *value;
190 nsresult nsres;
191 HRESULT hres = S_OK;
193 WARN("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
195 if(!This->nselem) {
196 FIXME("NULL nselem\n");
197 return E_NOTIMPL;
200 V_VT(AttributeValue) = VT_NULL;
202 nsAString_Init(&attr_str, strAttributeName);
203 nsAString_Init(&value_str, NULL);
205 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
206 nsAString_Finish(&attr_str);
208 if(NS_SUCCEEDED(nsres)) {
209 static const WCHAR wszSRC[] = {'s','r','c',0};
210 nsAString_GetData(&value_str, &value);
211 if(!strcmpiW(strAttributeName, wszSRC))
213 WCHAR buffer[256];
214 DWORD len;
215 BSTR bstrBaseUrl;
216 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
217 if(SUCCEEDED(hres)) {
218 hres = CoInternetCombineUrl(bstrBaseUrl, value,
219 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
220 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
221 SysFreeString(bstrBaseUrl);
222 if(SUCCEEDED(hres)) {
223 V_VT(AttributeValue) = VT_BSTR;
224 V_BSTR(AttributeValue) = SysAllocString(buffer);
225 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
228 }else if(*value) {
229 V_VT(AttributeValue) = VT_BSTR;
230 V_BSTR(AttributeValue) = SysAllocString(value);
231 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
233 }else {
234 ERR("GetAttribute failed: %08x\n", nsres);
235 hres = E_FAIL;
238 nsAString_Finish(&value_str);
240 return hres;
243 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
244 LONG lFlags, VARIANT_BOOL *pfSuccess)
246 HTMLElement *This = HTMLELEM_THIS(iface);
247 FIXME("(%p)->()\n", This);
248 return E_NOTIMPL;
251 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
253 HTMLElement *This = HTMLELEM_THIS(iface);
254 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
255 return E_NOTIMPL;
258 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
260 HTMLElement *This = HTMLELEM_THIS(iface);
261 nsAString class_str;
262 nsresult nsres;
263 HRESULT hres = S_OK;
265 TRACE("(%p)->(%p)\n", This, p);
267 if(!This->nselem) {
268 FIXME("NULL nselem\n");
269 return E_NOTIMPL;
272 nsAString_Init(&class_str, NULL);
273 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
275 if(NS_SUCCEEDED(nsres)) {
276 const PRUnichar *class;
277 nsAString_GetData(&class_str, &class);
278 *p = SysAllocString(class);
279 }else {
280 ERR("GetClassName failed: %08x\n", nsres);
281 hres = E_FAIL;
284 nsAString_Finish(&class_str);
286 TRACE("className=%s\n", debugstr_w(*p));
287 return hres;
290 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
292 HTMLElement *This = HTMLELEM_THIS(iface);
293 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
294 return E_NOTIMPL;
297 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
299 HTMLElement *This = HTMLELEM_THIS(iface);
300 FIXME("(%p)->(%p)\n", This, p);
301 return E_NOTIMPL;
304 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
306 HTMLElement *This = HTMLELEM_THIS(iface);
307 const PRUnichar *tag;
308 nsAString tag_str;
309 nsresult nsres;
311 TRACE("(%p)->(%p)\n", This, p);
313 if(!This->nselem) {
314 static const WCHAR comment_tagW[] = {'!',0};
316 WARN("NULL nselem, assuming comment\n");
318 *p = SysAllocString(comment_tagW);
319 return S_OK;
322 nsAString_Init(&tag_str, NULL);
323 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
324 if(NS_SUCCEEDED(nsres)) {
325 nsAString_GetData(&tag_str, &tag);
326 *p = SysAllocString(tag);
327 }else {
328 ERR("GetTagName failed: %08x\n", nsres);
329 *p = NULL;
331 nsAString_Finish(&tag_str);
333 return S_OK;
336 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
338 HTMLElement *This = HTMLELEM_THIS(iface);
339 FIXME("(%p)->(%p)\n", This, p);
340 return E_NOTIMPL;
343 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
345 HTMLElement *This = HTMLELEM_THIS(iface);
346 nsIDOMElementCSSInlineStyle *nselemstyle;
347 nsIDOMCSSStyleDeclaration *nsstyle;
348 nsresult nsres;
350 TRACE("(%p)->(%p)\n", This, p);
352 if(!This->nselem) {
353 FIXME("NULL nselem\n");
354 return E_NOTIMPL;
357 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
358 (void**)&nselemstyle);
359 if(NS_FAILED(nsres)) {
360 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
361 return E_FAIL;
364 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
365 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
366 if(NS_FAILED(nsres)) {
367 ERR("GetStyle failed: %08x\n", nsres);
368 return E_FAIL;
371 /* FIXME: Store style instead of creating a new instance in each call */
372 *p = HTMLStyle_Create(nsstyle);
374 nsIDOMCSSStyleDeclaration_Release(nsstyle);
375 return S_OK;
378 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
380 HTMLElement *This = HTMLELEM_THIS(iface);
381 FIXME("(%p)->()\n", This);
382 return E_NOTIMPL;
385 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
387 HTMLElement *This = HTMLELEM_THIS(iface);
388 FIXME("(%p)->(%p)\n", This, p);
389 return E_NOTIMPL;
392 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
394 HTMLElement *This = HTMLELEM_THIS(iface);
395 FIXME("(%p)->()\n", This);
396 return E_NOTIMPL;
399 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
401 HTMLElement *This = HTMLELEM_THIS(iface);
402 FIXME("(%p)->(%p)\n", This, p);
403 return E_NOTIMPL;
406 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
408 HTMLElement *This = HTMLELEM_THIS(iface);
409 FIXME("(%p)->()\n", This);
410 return E_NOTIMPL;
413 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
415 HTMLElement *This = HTMLELEM_THIS(iface);
416 FIXME("(%p)->(%p)\n", This, p);
417 return E_NOTIMPL;
420 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
422 HTMLElement *This = HTMLELEM_THIS(iface);
423 FIXME("(%p)->()\n", This);
424 return E_NOTIMPL;
427 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
429 HTMLElement *This = HTMLELEM_THIS(iface);
430 FIXME("(%p)->(%p)\n", This, p);
431 return E_NOTIMPL;
434 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
436 HTMLElement *This = HTMLELEM_THIS(iface);
437 FIXME("(%p)->()\n", This);
438 return E_NOTIMPL;
441 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
443 HTMLElement *This = HTMLELEM_THIS(iface);
444 FIXME("(%p)->(%p)\n", This, p);
445 return E_NOTIMPL;
448 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
450 HTMLElement *This = HTMLELEM_THIS(iface);
451 FIXME("(%p)->()\n", This);
452 return E_NOTIMPL;
455 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
457 HTMLElement *This = HTMLELEM_THIS(iface);
458 FIXME("(%p)->(%p)\n", This, p);
459 return E_NOTIMPL;
462 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
464 HTMLElement *This = HTMLELEM_THIS(iface);
465 FIXME("(%p)->()\n", This);
466 return E_NOTIMPL;
469 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
471 HTMLElement *This = HTMLELEM_THIS(iface);
472 FIXME("(%p)->(%p)\n", This, p);
473 return E_NOTIMPL;
476 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
478 HTMLElement *This = HTMLELEM_THIS(iface);
479 FIXME("(%p)->()\n", This);
480 return E_NOTIMPL;
483 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
485 HTMLElement *This = HTMLELEM_THIS(iface);
486 FIXME("(%p)->(%p)\n", This, p);
487 return E_NOTIMPL;
490 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
492 HTMLElement *This = HTMLELEM_THIS(iface);
493 FIXME("(%p)->()\n", This);
494 return E_NOTIMPL;
497 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
499 HTMLElement *This = HTMLELEM_THIS(iface);
500 FIXME("(%p)->(%p)\n", This, p);
501 return E_NOTIMPL;
504 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
506 HTMLElement *This = HTMLELEM_THIS(iface);
507 FIXME("(%p)->()\n", This);
508 return E_NOTIMPL;
511 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
513 HTMLElement *This = HTMLELEM_THIS(iface);
514 FIXME("(%p)->(%p)\n", This, p);
515 return E_NOTIMPL;
518 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
520 HTMLElement *This = HTMLELEM_THIS(iface);
521 FIXME("(%p)->()\n", This);
522 return E_NOTIMPL;
525 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
527 HTMLElement *This = HTMLELEM_THIS(iface);
528 FIXME("(%p)->(%p)\n", This, p);
529 return E_NOTIMPL;
532 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
534 HTMLElement *This = HTMLELEM_THIS(iface);
535 FIXME("(%p)->(%p)\n", This, p);
536 return E_NOTIMPL;
539 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
541 HTMLElement *This = HTMLELEM_THIS(iface);
542 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
543 return E_NOTIMPL;
546 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
548 HTMLElement *This = HTMLELEM_THIS(iface);
549 FIXME("(%p)->(%p)\n", This, p);
550 return E_NOTIMPL;
553 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
555 HTMLElement *This = HTMLELEM_THIS(iface);
556 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
557 return E_NOTIMPL;
560 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
562 HTMLElement *This = HTMLELEM_THIS(iface);
563 FIXME("(%p)->(%p)\n", This, p);
564 return E_NOTIMPL;
567 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
569 HTMLElement *This = HTMLELEM_THIS(iface);
570 FIXME("(%p)->()\n", This);
571 return E_NOTIMPL;
574 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
576 HTMLElement *This = HTMLELEM_THIS(iface);
577 FIXME("(%p)->(%p)\n", This, p);
578 return E_NOTIMPL;
581 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
583 HTMLElement *This = HTMLELEM_THIS(iface);
584 FIXME("(%p)->()\n", This);
585 return E_NOTIMPL;
588 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
589 VARIANT_BOOL *pfResult)
591 HTMLElement *This = HTMLELEM_THIS(iface);
592 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
593 return E_NOTIMPL;
596 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
598 HTMLElement *This = HTMLELEM_THIS(iface);
599 FIXME("(%p)->(%p)\n", This, p);
600 return E_NOTIMPL;
603 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
605 HTMLElement *This = HTMLELEM_THIS(iface);
606 FIXME("(%p)->(%p)\n", This, p);
607 return E_NOTIMPL;
610 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
612 HTMLElement *This = HTMLELEM_THIS(iface);
613 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
614 return E_NOTIMPL;
617 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
619 HTMLElement *This = HTMLELEM_THIS(iface);
620 FIXME("(%p)->(%p)\n", This, p);
621 return E_NOTIMPL;
624 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
626 HTMLElement *This = HTMLELEM_THIS(iface);
627 FIXME("(%p)->(%p)\n", This, p);
628 return E_NOTIMPL;
631 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
633 HTMLElement *This = HTMLELEM_THIS(iface);
634 FIXME("(%p)->(%p)\n", This, p);
635 return E_NOTIMPL;
638 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
640 HTMLElement *This = HTMLELEM_THIS(iface);
641 FIXME("(%p)->(%p)\n", This, p);
642 return E_NOTIMPL;
645 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
647 HTMLElement *This = HTMLELEM_THIS(iface);
648 FIXME("(%p)->(%p)\n", This, p);
649 return E_NOTIMPL;
652 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
654 HTMLElement *This = HTMLELEM_THIS(iface);
655 FIXME("(%p)->(%p)\n", This, p);
656 return E_NOTIMPL;
659 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
661 HTMLElement *This = HTMLELEM_THIS(iface);
662 nsIDOMNSHTMLElement *nselem;
663 nsAString html_str;
664 nsresult nsres;
666 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
668 if(!This->nselem) {
669 FIXME("NULL nselem\n");
670 return E_NOTIMPL;
673 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
674 if(NS_FAILED(nsres)) {
675 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
676 return E_FAIL;
679 nsAString_Init(&html_str, v);
680 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
681 nsAString_Finish(&html_str);
683 if(NS_FAILED(nsres)) {
684 FIXME("SetInnerHtml failed %08x\n", nsres);
685 return E_FAIL;
688 return S_OK;
691 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
693 HTMLElement *This = HTMLELEM_THIS(iface);
694 FIXME("(%p)->(%p)\n", This, p);
695 return E_NOTIMPL;
698 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
700 HTMLElement *This = HTMLELEM_THIS(iface);
701 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
702 return E_NOTIMPL;
705 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
707 HTMLElement *This = HTMLELEM_THIS(iface);
708 FIXME("(%p)->(%p)\n", This, p);
709 return E_NOTIMPL;
712 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
714 HTMLElement *This = HTMLELEM_THIS(iface);
715 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
716 return E_NOTIMPL;
719 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
721 HTMLElement *This = HTMLELEM_THIS(iface);
722 FIXME("(%p)->(%p)\n", This, p);
723 return E_NOTIMPL;
726 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
728 HTMLElement *This = HTMLELEM_THIS(iface);
729 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
730 return E_NOTIMPL;
733 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
735 HTMLElement *This = HTMLELEM_THIS(iface);
736 FIXME("(%p)->(%p)\n", This, p);
737 return E_NOTIMPL;
740 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
742 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
743 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
744 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
745 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
746 nsresult nsres;
748 if(!This->nselem) {
749 FIXME("NULL nselem\n");
750 return E_NOTIMPL;
753 if (!strcmpiW(where, wszBeforeBegin))
755 nsIDOMNode *unused;
756 nsIDOMNode *parent;
757 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
758 if (!parent) return E_INVALIDARG;
759 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
760 (nsIDOMNode *)This->nselem, &unused);
761 if (unused) nsIDOMNode_Release(unused);
762 nsIDOMNode_Release(parent);
764 else if (!strcmpiW(where, wszAfterBegin))
766 nsIDOMNode *unused;
767 nsIDOMNode *first_child;
768 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
769 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
770 if (unused) nsIDOMNode_Release(unused);
771 if (first_child) nsIDOMNode_Release(first_child);
773 else if (!strcmpiW(where, wszBeforeEnd))
775 nsIDOMNode *unused;
776 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
777 if (unused) nsIDOMNode_Release(unused);
779 else if (!strcmpiW(where, wszAfterEnd))
781 nsIDOMNode *unused;
782 nsIDOMNode *next_sibling;
783 nsIDOMNode *parent;
784 nsIDOMNode_GetParentNode(This->nselem, &parent);
785 if (!parent) return E_INVALIDARG;
787 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
788 if (next_sibling)
790 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
791 nsIDOMNode_Release(next_sibling);
793 else
794 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
795 nsIDOMNode_Release(parent);
796 if (unused) nsIDOMNode_Release(unused);
798 else
800 ERR("invalid where: %s\n", debugstr_w(where));
801 return E_INVALIDARG;
804 if (NS_FAILED(nsres))
805 return E_FAIL;
806 else
807 return S_OK;
810 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
811 BSTR html)
813 HTMLElement *This = HTMLELEM_THIS(iface);
814 nsresult nsres;
815 nsIDOMDocument *nsdoc;
816 nsIDOMDocumentRange *nsdocrange;
817 nsIDOMRange *range;
818 nsIDOMNSRange *nsrange;
819 nsIDOMNode *nsnode;
820 nsAString ns_html;
821 HRESULT hr;
823 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
825 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
826 if(NS_FAILED(nsres))
828 ERR("GetDocument failed: %08x\n", nsres);
829 return E_FAIL;
832 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
833 nsIDOMDocument_Release(nsdoc);
834 if(NS_FAILED(nsres))
836 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
837 return E_FAIL;
839 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
840 nsIDOMDocumentRange_Release(nsdocrange);
841 if(NS_FAILED(nsres))
843 ERR("CreateRange failed: %08x\n", nsres);
844 return E_FAIL;
847 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
849 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
850 nsIDOMRange_Release(range);
851 if(NS_FAILED(nsres))
853 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
854 return E_FAIL;
857 nsAString_Init(&ns_html, html);
859 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
860 nsIDOMNSRange_Release(nsrange);
861 nsAString_Finish(&ns_html);
863 if(NS_FAILED(nsres) || !nsnode)
865 ERR("CreateTextNode failed: %08x\n", nsres);
866 return E_FAIL;
869 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
870 nsIDOMNode_Release(nsnode);
872 return hr;
875 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
876 BSTR text)
878 HTMLElement *This = HTMLELEM_THIS(iface);
879 nsresult nsres;
880 nsIDOMDocument *nsdoc;
881 nsIDOMNode *nsnode;
882 nsAString ns_text;
883 HRESULT hr;
885 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
887 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
888 if(NS_FAILED(nsres) || !nsdoc)
890 ERR("GetDocument failed: %08x\n", nsres);
891 return E_FAIL;
894 nsAString_Init(&ns_text, text);
896 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
897 nsIDOMDocument_Release(nsdoc);
898 nsAString_Finish(&ns_text);
900 if(NS_FAILED(nsres) || !nsnode)
902 ERR("CreateTextNode failed: %08x\n", nsres);
903 return E_FAIL;
906 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
907 nsIDOMNode_Release(nsnode);
909 return hr;
912 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
914 HTMLElement *This = HTMLELEM_THIS(iface);
915 FIXME("(%p)->(%p)\n", This, p);
916 return E_NOTIMPL;
919 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
921 HTMLElement *This = HTMLELEM_THIS(iface);
922 FIXME("(%p)->(%p)\n", This, p);
923 return E_NOTIMPL;
926 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
928 HTMLElement *This = HTMLELEM_THIS(iface);
929 FIXME("(%p)\n", This);
930 return E_NOTIMPL;
933 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
934 IHTMLFiltersCollection **p)
936 HTMLElement *This = HTMLELEM_THIS(iface);
937 FIXME("(%p)->(%p)\n", This, p);
938 return E_NOTIMPL;
941 static HRESULT WINAPI HTMLElement_put_ondragstart(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_ondragstart(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_toString(IHTMLElement *iface, BSTR *String)
957 HTMLElement *This = HTMLELEM_THIS(iface);
958 FIXME("(%p)->(%p)\n", This, String);
959 return E_NOTIMPL;
962 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
964 HTMLElement *This = HTMLELEM_THIS(iface);
965 FIXME("(%p)->()\n", This);
966 return E_NOTIMPL;
969 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
971 HTMLElement *This = HTMLELEM_THIS(iface);
972 FIXME("(%p)->(%p)\n", This, p);
973 return E_NOTIMPL;
976 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
978 HTMLElement *This = HTMLELEM_THIS(iface);
979 FIXME("(%p)->()\n", This);
980 return E_NOTIMPL;
983 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
985 HTMLElement *This = HTMLELEM_THIS(iface);
986 FIXME("(%p)->(%p)\n", This, p);
987 return E_NOTIMPL;
990 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
992 HTMLElement *This = HTMLELEM_THIS(iface);
993 FIXME("(%p)->()\n", This);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
999 HTMLElement *This = HTMLELEM_THIS(iface);
1000 FIXME("(%p)->(%p)\n", This, p);
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1006 HTMLElement *This = HTMLELEM_THIS(iface);
1007 FIXME("(%p)->()\n", This);
1008 return E_NOTIMPL;
1011 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1013 HTMLElement *This = HTMLELEM_THIS(iface);
1014 FIXME("(%p)->(%p)\n", This, p);
1015 return E_NOTIMPL;
1018 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1020 HTMLElement *This = HTMLELEM_THIS(iface);
1021 FIXME("(%p)->()\n", This);
1022 return E_NOTIMPL;
1025 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1027 HTMLElement *This = HTMLELEM_THIS(iface);
1028 FIXME("(%p)->(%p)\n", This, p);
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1034 HTMLElement *This = HTMLELEM_THIS(iface);
1035 FIXME("(%p)->()\n", This);
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1041 HTMLElement *This = HTMLELEM_THIS(iface);
1042 FIXME("(%p)->(%p)\n", This, p);
1043 return E_NOTIMPL;
1046 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1048 HTMLElement *This = HTMLELEM_THIS(iface);
1049 FIXME("(%p)->()\n", This);
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1055 HTMLElement *This = HTMLELEM_THIS(iface);
1056 FIXME("(%p)->(%p)\n", This, p);
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1062 HTMLElement *This = HTMLELEM_THIS(iface);
1063 FIXME("(%p)->()\n", This);
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1069 HTMLElement *This = HTMLELEM_THIS(iface);
1070 FIXME("(%p)->(%p)\n", This, p);
1071 return E_NOTIMPL;
1074 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1076 HTMLElement *This = HTMLELEM_THIS(iface);
1077 FIXME("(%p)->()\n", This);
1078 return E_NOTIMPL;
1081 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1083 HTMLElement *This = HTMLELEM_THIS(iface);
1084 FIXME("(%p)->(%p)\n", This, p);
1085 return E_NOTIMPL;
1088 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1090 nsIDOMNodeList *nsnode_list;
1091 nsIDOMNode *iter;
1092 PRUint32 list_len = 0, i;
1093 nsresult nsres;
1095 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1096 if(NS_FAILED(nsres)) {
1097 ERR("GetChildNodes failed: %08x\n", nsres);
1098 return;
1101 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1102 if(!list_len)
1103 return;
1105 buf->size = list_len;
1106 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1108 for(i=0; i<list_len; i++) {
1109 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1110 if(NS_FAILED(nsres)) {
1111 ERR("Item failed: %08x\n", nsres);
1112 continue;
1115 if(is_elem_node(iter))
1116 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1120 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1122 HTMLElement *This = HTMLELEM_THIS(iface);
1123 elem_vector buf = {NULL, 0, 0};
1125 TRACE("(%p)->(%p)\n", This, p);
1127 create_child_list(This->node.doc, This, &buf);
1129 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1130 return S_OK;
1133 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1135 nsIDOMNodeList *nsnode_list;
1136 nsIDOMNode *iter;
1137 PRUint32 list_len = 0, i;
1138 nsresult nsres;
1140 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1141 if(NS_FAILED(nsres)) {
1142 ERR("GetChildNodes failed: %08x\n", nsres);
1143 return;
1146 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1147 if(!list_len)
1148 return;
1150 for(i=0; i<list_len; i++) {
1151 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1152 if(NS_FAILED(nsres)) {
1153 ERR("Item failed: %08x\n", nsres);
1154 continue;
1157 if(is_elem_node(iter)) {
1158 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1160 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1161 create_all_list(doc, node, buf);
1166 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1168 HTMLElement *This = HTMLELEM_THIS(iface);
1169 elem_vector buf = {NULL, 0, 8};
1171 TRACE("(%p)->(%p)\n", This, p);
1173 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1175 create_all_list(This->node.doc, &This->node, &buf);
1176 elem_vector_normalize(&buf);
1178 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1179 return S_OK;
1182 #undef HTMLELEM_THIS
1184 static const IHTMLElementVtbl HTMLElementVtbl = {
1185 HTMLElement_QueryInterface,
1186 HTMLElement_AddRef,
1187 HTMLElement_Release,
1188 HTMLElement_GetTypeInfoCount,
1189 HTMLElement_GetTypeInfo,
1190 HTMLElement_GetIDsOfNames,
1191 HTMLElement_Invoke,
1192 HTMLElement_setAttribute,
1193 HTMLElement_getAttribute,
1194 HTMLElement_removeAttribute,
1195 HTMLElement_put_className,
1196 HTMLElement_get_className,
1197 HTMLElement_put_id,
1198 HTMLElement_get_id,
1199 HTMLElement_get_tagName,
1200 HTMLElement_get_parentElement,
1201 HTMLElement_get_style,
1202 HTMLElement_put_onhelp,
1203 HTMLElement_get_onhelp,
1204 HTMLElement_put_onclick,
1205 HTMLElement_get_onclick,
1206 HTMLElement_put_ondblclick,
1207 HTMLElement_get_ondblclick,
1208 HTMLElement_put_onkeydown,
1209 HTMLElement_get_onkeydown,
1210 HTMLElement_put_onkeyup,
1211 HTMLElement_get_onkeyup,
1212 HTMLElement_put_onkeypress,
1213 HTMLElement_get_onkeypress,
1214 HTMLElement_put_onmouseout,
1215 HTMLElement_get_onmouseout,
1216 HTMLElement_put_onmouseover,
1217 HTMLElement_get_onmouseover,
1218 HTMLElement_put_onmousemove,
1219 HTMLElement_get_onmousemove,
1220 HTMLElement_put_onmousedown,
1221 HTMLElement_get_onmousedown,
1222 HTMLElement_put_onmouseup,
1223 HTMLElement_get_onmouseup,
1224 HTMLElement_get_document,
1225 HTMLElement_put_title,
1226 HTMLElement_get_title,
1227 HTMLElement_put_language,
1228 HTMLElement_get_language,
1229 HTMLElement_put_onselectstart,
1230 HTMLElement_get_onselectstart,
1231 HTMLElement_scrollIntoView,
1232 HTMLElement_contains,
1233 HTMLElement_get_sourceIndex,
1234 HTMLElement_get_recordNumber,
1235 HTMLElement_put_lang,
1236 HTMLElement_get_lang,
1237 HTMLElement_get_offsetLeft,
1238 HTMLElement_get_offsetTop,
1239 HTMLElement_get_offsetWidth,
1240 HTMLElement_get_offsetHeight,
1241 HTMLElement_get_offsetParent,
1242 HTMLElement_put_innerHTML,
1243 HTMLElement_get_innerHTML,
1244 HTMLElement_put_innerText,
1245 HTMLElement_get_innerText,
1246 HTMLElement_put_outerHTML,
1247 HTMLElement_get_outerHTML,
1248 HTMLElement_put_outerText,
1249 HTMLElement_get_outerText,
1250 HTMLElement_insertAdjacentHTML,
1251 HTMLElement_insertAdjacentText,
1252 HTMLElement_get_parentTextEdit,
1253 HTMLElement_get_isTextEdit,
1254 HTMLElement_click,
1255 HTMLElement_get_filters,
1256 HTMLElement_put_ondragstart,
1257 HTMLElement_get_ondragstart,
1258 HTMLElement_toString,
1259 HTMLElement_put_onbeforeupdate,
1260 HTMLElement_get_onbeforeupdate,
1261 HTMLElement_put_onafterupdate,
1262 HTMLElement_get_onafterupdate,
1263 HTMLElement_put_onerrorupdate,
1264 HTMLElement_get_onerrorupdate,
1265 HTMLElement_put_onrowexit,
1266 HTMLElement_get_onrowexit,
1267 HTMLElement_put_onrowenter,
1268 HTMLElement_get_onrowenter,
1269 HTMLElement_put_ondatasetchanged,
1270 HTMLElement_get_ondatasetchanged,
1271 HTMLElement_put_ondataavailable,
1272 HTMLElement_get_ondataavailable,
1273 HTMLElement_put_ondatasetcomplete,
1274 HTMLElement_get_ondatasetcomplete,
1275 HTMLElement_put_onfilterchange,
1276 HTMLElement_get_onfilterchange,
1277 HTMLElement_get_children,
1278 HTMLElement_get_all
1281 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1283 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1285 *ppv = NULL;
1287 if(IsEqualGUID(&IID_IUnknown, riid)) {
1288 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1289 *ppv = HTMLELEM(This);
1290 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1291 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1292 *ppv = HTMLELEM(This);
1293 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1294 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1295 *ppv = HTMLELEM(This);
1296 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1297 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1298 *ppv = HTMLELEM2(This);
1299 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1300 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1301 *ppv = CONPTCONT(&This->cp_container);
1304 if(*ppv) {
1305 IHTMLElement_AddRef(HTMLELEM(This));
1306 return S_OK;
1309 return HTMLDOMNode_QI(&This->node, riid, ppv);
1312 void HTMLElement_destructor(HTMLDOMNode *iface)
1314 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1316 ConnectionPointContainer_Destroy(&This->cp_container);
1318 if(This->nselem)
1319 nsIDOMHTMLElement_Release(This->nselem);
1321 HTMLDOMNode_destructor(&This->node);
1324 static const NodeImplVtbl HTMLElementImplVtbl = {
1325 HTMLElement_QI,
1326 HTMLElement_destructor
1329 static const tid_t HTMLElement_iface_tids[] = {
1330 IHTMLDOMNode_tid,
1331 IHTMLDOMNode2_tid,
1332 IHTMLElement_tid,
1333 IHTMLElement2_tid,
1336 static dispex_static_data_t HTMLElement_dispex = {
1337 NULL,
1338 DispHTMLUnknownElement_tid,
1339 NULL,
1340 HTMLElement_iface_tids
1343 void HTMLElement_Init(HTMLElement *This)
1345 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1347 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1349 HTMLElement2_Init(This);
1351 if(!This->node.dispex.data)
1352 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1355 HTMLElement *HTMLElement_Create(nsIDOMNode *nsnode)
1357 nsIDOMHTMLElement *nselem;
1358 HTMLElement *ret = NULL;
1359 nsAString class_name_str;
1360 const PRUnichar *class_name;
1361 nsresult nsres;
1363 static const WCHAR wszA[] = {'A',0};
1364 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1365 static const WCHAR wszIMG[] = {'I','M','G',0};
1366 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1367 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1368 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1369 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1370 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1371 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1373 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1374 if(NS_FAILED(nsres))
1375 return NULL;
1377 nsAString_Init(&class_name_str, NULL);
1378 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1380 nsAString_GetData(&class_name_str, &class_name);
1382 if(!strcmpW(class_name, wszA))
1383 ret = HTMLAnchorElement_Create(nselem);
1384 else if(!strcmpW(class_name, wszBODY))
1385 ret = HTMLBodyElement_Create(nselem);
1386 else if(!strcmpW(class_name, wszIMG))
1387 ret = HTMLImgElement_Create(nselem);
1388 else if(!strcmpW(class_name, wszINPUT))
1389 ret = HTMLInputElement_Create(nselem);
1390 else if(!strcmpW(class_name, wszOPTION))
1391 ret = HTMLOptionElement_Create(nselem);
1392 else if(!strcmpW(class_name, wszSCRIPT))
1393 ret = HTMLScriptElement_Create(nselem);
1394 else if(!strcmpW(class_name, wszSELECT))
1395 ret = HTMLSelectElement_Create(nselem);
1396 else if(!strcmpW(class_name, wszTABLE))
1397 ret = HTMLTable_Create(nselem);
1398 else if(!strcmpW(class_name, wszTEXTAREA))
1399 ret = HTMLTextAreaElement_Create(nselem);
1401 if(!ret) {
1402 ret = heap_alloc_zero(sizeof(HTMLElement));
1403 HTMLElement_Init(ret);
1404 ret->node.vtbl = &HTMLElementImplVtbl;
1407 nsAString_Finish(&class_name_str);
1409 ret->nselem = nselem;
1411 return ret;
1414 typedef struct {
1415 DispatchEx dispex;
1416 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1418 IUnknown *ref_unk;
1419 HTMLElement **elems;
1420 DWORD len;
1422 LONG ref;
1423 } HTMLElementCollection;
1425 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1427 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1429 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1430 REFIID riid, void **ppv)
1432 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1434 *ppv = NULL;
1436 if(IsEqualGUID(&IID_IUnknown, riid)) {
1437 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1438 *ppv = HTMLELEMCOL(This);
1439 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1440 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1441 *ppv = HTMLELEMCOL(This);
1442 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1443 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1444 *ppv = DISPATCHEX(&This->dispex);
1445 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1446 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1447 *ppv = HTMLELEMCOL(This);
1450 if(*ppv) {
1451 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1452 return S_OK;
1455 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1456 return E_NOINTERFACE;
1459 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1461 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1462 LONG ref = InterlockedIncrement(&This->ref);
1464 TRACE("(%p) ref=%d\n", This, ref);
1466 return ref;
1469 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1471 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1472 LONG ref = InterlockedDecrement(&This->ref);
1474 TRACE("(%p) ref=%d\n", This, ref);
1476 if(!ref) {
1477 IUnknown_Release(This->ref_unk);
1478 heap_free(This->elems);
1479 heap_free(This);
1482 return ref;
1485 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1486 UINT *pctinfo)
1488 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1489 FIXME("(%p)->(%p)\n", This, pctinfo);
1490 return E_NOTIMPL;
1493 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1494 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1496 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1497 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1498 return E_NOTIMPL;
1501 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1502 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1504 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1505 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1506 lcid, rgDispId);
1507 return E_NOTIMPL;
1510 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1511 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1512 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1514 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1515 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1516 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1517 return E_NOTIMPL;
1520 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1521 BSTR *String)
1523 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1524 FIXME("(%p)->(%p)\n", This, String);
1525 return E_NOTIMPL;
1528 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1529 long v)
1531 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1532 FIXME("(%p)->(%ld)\n", This, v);
1533 return E_NOTIMPL;
1536 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1537 long *p)
1539 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1541 TRACE("(%p)->(%p)\n", This, p);
1543 *p = This->len;
1544 return S_OK;
1547 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1548 IUnknown **p)
1550 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1551 FIXME("(%p)->(%p)\n", This, p);
1552 return E_NOTIMPL;
1555 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1557 const PRUnichar *str;
1558 nsAString nsstr, nsname;
1559 BOOL ret = FALSE;
1560 nsresult nsres;
1562 static const PRUnichar nameW[] = {'n','a','m','e',0};
1564 if(!elem->nselem)
1565 return FALSE;
1567 nsAString_Init(&nsstr, NULL);
1568 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1569 nsAString_GetData(&nsstr, &str);
1570 if(!strcmpiW(str, name)) {
1571 nsAString_Finish(&nsstr);
1572 return TRUE;
1575 nsAString_Init(&nsname, nameW);
1576 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1577 nsAString_Finish(&nsname);
1578 if(NS_SUCCEEDED(nsres)) {
1579 nsAString_GetData(&nsstr, &str);
1580 ret = !strcmpiW(str, name);
1583 nsAString_Finish(&nsstr);
1584 return ret;
1587 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1588 VARIANT name, VARIANT index, IDispatch **pdisp)
1590 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1592 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1594 *pdisp = NULL;
1596 if(V_VT(&name) == VT_I4) {
1597 TRACE("name is VT_I4: %d\n", V_I4(&name));
1599 if(V_I4(&name) < 0)
1600 return E_INVALIDARG;
1601 if(V_I4(&name) >= This->len)
1602 return S_OK;
1604 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1605 IDispatch_AddRef(*pdisp);
1606 TRACE("Returning pdisp=%p\n", pdisp);
1607 return S_OK;
1610 if(V_VT(&name) == VT_BSTR) {
1611 DWORD i;
1613 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1615 if(V_VT(&index) == VT_I4) {
1616 LONG idx = V_I4(&index);
1618 TRACE("index = %d\n", idx);
1620 if(idx < 0)
1621 return E_INVALIDARG;
1623 for(i=0; i<This->len; i++) {
1624 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1625 break;
1628 if(i != This->len) {
1629 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1630 IDispatch_AddRef(*pdisp);
1633 return S_OK;
1634 }else {
1635 elem_vector buf = {NULL, 0, 8};
1637 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1639 for(i=0; i<This->len; i++) {
1640 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1641 elem_vector_add(&buf, This->elems[i]);
1644 if(buf.len > 1) {
1645 elem_vector_normalize(&buf);
1646 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1647 }else {
1648 if(buf.len == 1) {
1649 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1650 IDispatch_AddRef(*pdisp);
1653 heap_free(buf.buf);
1656 return S_OK;
1660 FIXME("unsupported arguments\n");
1661 return E_INVALIDARG;
1664 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1665 VARIANT tagName, IDispatch **pdisp)
1667 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1668 DWORD i;
1669 nsAString tag_str;
1670 const PRUnichar *tag;
1671 elem_vector buf = {NULL, 0, 8};
1673 if(V_VT(&tagName) != VT_BSTR) {
1674 WARN("Invalid arg\n");
1675 return DISP_E_MEMBERNOTFOUND;
1678 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1680 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1682 nsAString_Init(&tag_str, NULL);
1684 for(i=0; i<This->len; i++) {
1685 if(!This->elems[i]->nselem)
1686 continue;
1688 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1689 nsAString_GetData(&tag_str, &tag);
1691 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1692 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1693 elem_vector_add(&buf, This->elems[i]);
1696 nsAString_Finish(&tag_str);
1697 elem_vector_normalize(&buf);
1699 TRACE("fount %d tags\n", buf.len);
1701 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1702 return S_OK;
1705 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1707 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1709 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1710 WCHAR *ptr;
1711 DWORD idx=0;
1713 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1714 idx = idx*10 + (*ptr-'0');
1716 if(*ptr || idx >= This->len)
1717 return DISP_E_UNKNOWNNAME;
1719 *dispid = DISPID_ELEMCOL_0 + idx;
1720 TRACE("ret %x\n", *dispid);
1721 return S_OK;
1724 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1725 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1727 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1728 DWORD idx;
1730 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1732 idx = id - DISPID_ELEMCOL_0;
1733 if(idx >= This->len)
1734 return DISP_E_UNKNOWNNAME;
1736 switch(flags) {
1737 case INVOKE_PROPERTYGET:
1738 V_VT(res) = VT_DISPATCH;
1739 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1740 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1741 break;
1742 default:
1743 FIXME("unimplemented flags %x\n", flags);
1744 return E_NOTIMPL;
1747 return S_OK;
1750 #undef ELEMCOL_THIS
1752 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1753 HTMLElementCollection_QueryInterface,
1754 HTMLElementCollection_AddRef,
1755 HTMLElementCollection_Release,
1756 HTMLElementCollection_GetTypeInfoCount,
1757 HTMLElementCollection_GetTypeInfo,
1758 HTMLElementCollection_GetIDsOfNames,
1759 HTMLElementCollection_Invoke,
1760 HTMLElementCollection_toString,
1761 HTMLElementCollection_put_length,
1762 HTMLElementCollection_get_length,
1763 HTMLElementCollection_get__newEnum,
1764 HTMLElementCollection_item,
1765 HTMLElementCollection_tags
1768 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1769 HTMLElementCollection_get_dispid,
1770 HTMLElementCollection_invoke
1773 static const tid_t HTMLElementCollection_iface_tids[] = {
1774 IHTMLElementCollection_tid,
1777 static dispex_static_data_t HTMLElementCollection_dispex = {
1778 &HTMLElementColection_dispex_vtbl,
1779 DispHTMLElementCollection_tid,
1780 NULL,
1781 HTMLElementCollection_iface_tids
1784 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1786 elem_vector buf = {NULL, 0, 8};
1788 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1790 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1791 create_all_list(node->doc, node, &buf);
1792 elem_vector_normalize(&buf);
1794 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1797 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1798 HTMLElement **elems, DWORD len)
1800 HTMLElementCollection *ret = heap_alloc(sizeof(HTMLElementCollection));
1802 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1803 ret->ref = 1;
1804 ret->elems = elems;
1805 ret->len = len;
1807 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1809 IUnknown_AddRef(ref_unk);
1810 ret->ref_unk = ref_unk;
1812 TRACE("ret=%p len=%d\n", ret, len);
1814 return HTMLELEMCOL(ret);