mshtml: Added IHTMLElement::put_id implementation.
[wine/testsucceed.git] / dlls / mshtml / htmlelem.c
blob67a961124c778414ff9249a3e53b745dace349b2
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 nsAString id_str;
294 nsresult nsres;
296 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
298 if(!This->nselem) {
299 FIXME("nselem == NULL\n");
300 return S_OK;
303 nsAString_Init(&id_str, v);
304 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
305 nsAString_Finish(&id_str);
306 if(NS_FAILED(nsres))
307 ERR("SetId failed: %08x\n", nsres);
309 return S_OK;
312 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
314 HTMLElement *This = HTMLELEM_THIS(iface);
315 const PRUnichar *id;
316 nsAString id_str;
317 nsresult nsres;
319 TRACE("(%p)->(%p)\n", This, p);
321 *p = NULL;
323 if(!This->nselem)
324 return S_OK;
326 nsAString_Init(&id_str, NULL);
327 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
328 nsAString_GetData(&id_str, &id);
330 if(NS_FAILED(nsres))
331 ERR("GetId failed: %08x\n", nsres);
332 else if(*id)
333 *p = SysAllocString(id);
335 nsAString_Finish(&id_str);
336 return S_OK;
339 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
341 HTMLElement *This = HTMLELEM_THIS(iface);
342 const PRUnichar *tag;
343 nsAString tag_str;
344 nsresult nsres;
346 TRACE("(%p)->(%p)\n", This, p);
348 if(!This->nselem) {
349 static const WCHAR comment_tagW[] = {'!',0};
351 WARN("NULL nselem, assuming comment\n");
353 *p = SysAllocString(comment_tagW);
354 return S_OK;
357 nsAString_Init(&tag_str, NULL);
358 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
359 if(NS_SUCCEEDED(nsres)) {
360 nsAString_GetData(&tag_str, &tag);
361 *p = SysAllocString(tag);
362 }else {
363 ERR("GetTagName failed: %08x\n", nsres);
364 *p = NULL;
366 nsAString_Finish(&tag_str);
368 return S_OK;
371 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
373 HTMLElement *This = HTMLELEM_THIS(iface);
374 FIXME("(%p)->(%p)\n", This, p);
375 return E_NOTIMPL;
378 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
380 HTMLElement *This = HTMLELEM_THIS(iface);
381 nsIDOMElementCSSInlineStyle *nselemstyle;
382 nsIDOMCSSStyleDeclaration *nsstyle;
383 nsresult nsres;
385 TRACE("(%p)->(%p)\n", This, p);
387 if(!This->nselem) {
388 FIXME("NULL nselem\n");
389 return E_NOTIMPL;
392 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
393 (void**)&nselemstyle);
394 if(NS_FAILED(nsres)) {
395 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
396 return E_FAIL;
399 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
400 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
401 if(NS_FAILED(nsres)) {
402 ERR("GetStyle failed: %08x\n", nsres);
403 return E_FAIL;
406 /* FIXME: Store style instead of creating a new instance in each call */
407 *p = HTMLStyle_Create(nsstyle);
409 nsIDOMCSSStyleDeclaration_Release(nsstyle);
410 return S_OK;
413 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
415 HTMLElement *This = HTMLELEM_THIS(iface);
416 FIXME("(%p)->()\n", This);
417 return E_NOTIMPL;
420 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
422 HTMLElement *This = HTMLELEM_THIS(iface);
423 FIXME("(%p)->(%p)\n", This, p);
424 return E_NOTIMPL;
427 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
429 HTMLElement *This = HTMLELEM_THIS(iface);
430 FIXME("(%p)->()\n", This);
431 return E_NOTIMPL;
434 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
436 HTMLElement *This = HTMLELEM_THIS(iface);
437 FIXME("(%p)->(%p)\n", This, p);
438 return E_NOTIMPL;
441 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
443 HTMLElement *This = HTMLELEM_THIS(iface);
444 FIXME("(%p)->()\n", This);
445 return E_NOTIMPL;
448 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
450 HTMLElement *This = HTMLELEM_THIS(iface);
451 FIXME("(%p)->(%p)\n", This, p);
452 return E_NOTIMPL;
455 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
457 HTMLElement *This = HTMLELEM_THIS(iface);
458 FIXME("(%p)->()\n", This);
459 return E_NOTIMPL;
462 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
464 HTMLElement *This = HTMLELEM_THIS(iface);
465 FIXME("(%p)->(%p)\n", This, p);
466 return E_NOTIMPL;
469 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
471 HTMLElement *This = HTMLELEM_THIS(iface);
472 FIXME("(%p)->()\n", This);
473 return E_NOTIMPL;
476 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
478 HTMLElement *This = HTMLELEM_THIS(iface);
479 FIXME("(%p)->(%p)\n", This, p);
480 return E_NOTIMPL;
483 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
485 HTMLElement *This = HTMLELEM_THIS(iface);
486 FIXME("(%p)->()\n", This);
487 return E_NOTIMPL;
490 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
492 HTMLElement *This = HTMLELEM_THIS(iface);
493 FIXME("(%p)->(%p)\n", This, p);
494 return E_NOTIMPL;
497 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
499 HTMLElement *This = HTMLELEM_THIS(iface);
500 FIXME("(%p)->()\n", This);
501 return E_NOTIMPL;
504 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
506 HTMLElement *This = HTMLELEM_THIS(iface);
507 FIXME("(%p)->(%p)\n", This, p);
508 return E_NOTIMPL;
511 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
513 HTMLElement *This = HTMLELEM_THIS(iface);
514 FIXME("(%p)->()\n", This);
515 return E_NOTIMPL;
518 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
520 HTMLElement *This = HTMLELEM_THIS(iface);
521 FIXME("(%p)->(%p)\n", This, p);
522 return E_NOTIMPL;
525 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
527 HTMLElement *This = HTMLELEM_THIS(iface);
528 FIXME("(%p)->()\n", This);
529 return E_NOTIMPL;
532 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
534 HTMLElement *This = HTMLELEM_THIS(iface);
535 FIXME("(%p)->(%p)\n", This, p);
536 return E_NOTIMPL;
539 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
541 HTMLElement *This = HTMLELEM_THIS(iface);
542 FIXME("(%p)->()\n", This);
543 return E_NOTIMPL;
546 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
548 HTMLElement *This = HTMLELEM_THIS(iface);
549 FIXME("(%p)->(%p)\n", This, p);
550 return E_NOTIMPL;
553 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
555 HTMLElement *This = HTMLELEM_THIS(iface);
556 FIXME("(%p)->()\n", This);
557 return E_NOTIMPL;
560 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
562 HTMLElement *This = HTMLELEM_THIS(iface);
563 FIXME("(%p)->(%p)\n", This, p);
564 return E_NOTIMPL;
567 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
569 HTMLElement *This = HTMLELEM_THIS(iface);
570 FIXME("(%p)->(%p)\n", This, p);
571 return E_NOTIMPL;
574 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
576 HTMLElement *This = HTMLELEM_THIS(iface);
577 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
578 return E_NOTIMPL;
581 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
583 HTMLElement *This = HTMLELEM_THIS(iface);
584 FIXME("(%p)->(%p)\n", This, p);
585 return E_NOTIMPL;
588 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
590 HTMLElement *This = HTMLELEM_THIS(iface);
591 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
592 return E_NOTIMPL;
595 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
597 HTMLElement *This = HTMLELEM_THIS(iface);
598 FIXME("(%p)->(%p)\n", This, p);
599 return E_NOTIMPL;
602 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
604 HTMLElement *This = HTMLELEM_THIS(iface);
605 FIXME("(%p)->()\n", This);
606 return E_NOTIMPL;
609 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
611 HTMLElement *This = HTMLELEM_THIS(iface);
612 FIXME("(%p)->(%p)\n", This, p);
613 return E_NOTIMPL;
616 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
618 HTMLElement *This = HTMLELEM_THIS(iface);
619 FIXME("(%p)->()\n", This);
620 return E_NOTIMPL;
623 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
624 VARIANT_BOOL *pfResult)
626 HTMLElement *This = HTMLELEM_THIS(iface);
627 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
628 return E_NOTIMPL;
631 static HRESULT WINAPI HTMLElement_get_sourceIndex(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_recordNumber(IHTMLElement *iface, VARIANT *p)
640 HTMLElement *This = HTMLELEM_THIS(iface);
641 FIXME("(%p)->(%p)\n", This, p);
642 return E_NOTIMPL;
645 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
647 HTMLElement *This = HTMLELEM_THIS(iface);
648 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
649 return E_NOTIMPL;
652 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
654 HTMLElement *This = HTMLELEM_THIS(iface);
655 FIXME("(%p)->(%p)\n", This, p);
656 return E_NOTIMPL;
659 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
661 HTMLElement *This = HTMLELEM_THIS(iface);
662 FIXME("(%p)->(%p)\n", This, p);
663 return E_NOTIMPL;
666 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
668 HTMLElement *This = HTMLELEM_THIS(iface);
669 FIXME("(%p)->(%p)\n", This, p);
670 return E_NOTIMPL;
673 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
675 HTMLElement *This = HTMLELEM_THIS(iface);
676 FIXME("(%p)->(%p)\n", This, p);
677 return E_NOTIMPL;
680 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
682 HTMLElement *This = HTMLELEM_THIS(iface);
683 FIXME("(%p)->(%p)\n", This, p);
684 return E_NOTIMPL;
687 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
689 HTMLElement *This = HTMLELEM_THIS(iface);
690 FIXME("(%p)->(%p)\n", This, p);
691 return E_NOTIMPL;
694 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
696 HTMLElement *This = HTMLELEM_THIS(iface);
697 nsIDOMNSHTMLElement *nselem;
698 nsAString html_str;
699 nsresult nsres;
701 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
703 if(!This->nselem) {
704 FIXME("NULL nselem\n");
705 return E_NOTIMPL;
708 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
709 if(NS_FAILED(nsres)) {
710 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
711 return E_FAIL;
714 nsAString_Init(&html_str, v);
715 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
716 nsAString_Finish(&html_str);
718 if(NS_FAILED(nsres)) {
719 FIXME("SetInnerHtml failed %08x\n", nsres);
720 return E_FAIL;
723 return S_OK;
726 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
728 HTMLElement *This = HTMLELEM_THIS(iface);
729 FIXME("(%p)->(%p)\n", This, p);
730 return E_NOTIMPL;
733 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
735 HTMLElement *This = HTMLELEM_THIS(iface);
736 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
737 return E_NOTIMPL;
740 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
742 HTMLElement *This = HTMLELEM_THIS(iface);
743 FIXME("(%p)->(%p)\n", This, p);
744 return E_NOTIMPL;
747 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
749 HTMLElement *This = HTMLELEM_THIS(iface);
750 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
751 return E_NOTIMPL;
754 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
756 HTMLElement *This = HTMLELEM_THIS(iface);
757 FIXME("(%p)->(%p)\n", This, p);
758 return E_NOTIMPL;
761 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
763 HTMLElement *This = HTMLELEM_THIS(iface);
764 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
765 return E_NOTIMPL;
768 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
770 HTMLElement *This = HTMLELEM_THIS(iface);
771 FIXME("(%p)->(%p)\n", This, p);
772 return E_NOTIMPL;
775 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
777 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
778 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
779 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
780 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
781 nsresult nsres;
783 if(!This->nselem) {
784 FIXME("NULL nselem\n");
785 return E_NOTIMPL;
788 if (!strcmpiW(where, wszBeforeBegin))
790 nsIDOMNode *unused;
791 nsIDOMNode *parent;
792 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
793 if (!parent) return E_INVALIDARG;
794 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
795 (nsIDOMNode *)This->nselem, &unused);
796 if (unused) nsIDOMNode_Release(unused);
797 nsIDOMNode_Release(parent);
799 else if (!strcmpiW(where, wszAfterBegin))
801 nsIDOMNode *unused;
802 nsIDOMNode *first_child;
803 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
804 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
805 if (unused) nsIDOMNode_Release(unused);
806 if (first_child) nsIDOMNode_Release(first_child);
808 else if (!strcmpiW(where, wszBeforeEnd))
810 nsIDOMNode *unused;
811 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
812 if (unused) nsIDOMNode_Release(unused);
814 else if (!strcmpiW(where, wszAfterEnd))
816 nsIDOMNode *unused;
817 nsIDOMNode *next_sibling;
818 nsIDOMNode *parent;
819 nsIDOMNode_GetParentNode(This->nselem, &parent);
820 if (!parent) return E_INVALIDARG;
822 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
823 if (next_sibling)
825 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
826 nsIDOMNode_Release(next_sibling);
828 else
829 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
830 nsIDOMNode_Release(parent);
831 if (unused) nsIDOMNode_Release(unused);
833 else
835 ERR("invalid where: %s\n", debugstr_w(where));
836 return E_INVALIDARG;
839 if (NS_FAILED(nsres))
840 return E_FAIL;
841 else
842 return S_OK;
845 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
846 BSTR html)
848 HTMLElement *This = HTMLELEM_THIS(iface);
849 nsresult nsres;
850 nsIDOMDocument *nsdoc;
851 nsIDOMDocumentRange *nsdocrange;
852 nsIDOMRange *range;
853 nsIDOMNSRange *nsrange;
854 nsIDOMNode *nsnode;
855 nsAString ns_html;
856 HRESULT hr;
858 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
860 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
861 if(NS_FAILED(nsres))
863 ERR("GetDocument failed: %08x\n", nsres);
864 return E_FAIL;
867 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
868 nsIDOMDocument_Release(nsdoc);
869 if(NS_FAILED(nsres))
871 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
872 return E_FAIL;
874 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
875 nsIDOMDocumentRange_Release(nsdocrange);
876 if(NS_FAILED(nsres))
878 ERR("CreateRange failed: %08x\n", nsres);
879 return E_FAIL;
882 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
884 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
885 nsIDOMRange_Release(range);
886 if(NS_FAILED(nsres))
888 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
889 return E_FAIL;
892 nsAString_Init(&ns_html, html);
894 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
895 nsIDOMNSRange_Release(nsrange);
896 nsAString_Finish(&ns_html);
898 if(NS_FAILED(nsres) || !nsnode)
900 ERR("CreateTextNode failed: %08x\n", nsres);
901 return E_FAIL;
904 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
905 nsIDOMNode_Release(nsnode);
907 return hr;
910 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
911 BSTR text)
913 HTMLElement *This = HTMLELEM_THIS(iface);
914 nsresult nsres;
915 nsIDOMDocument *nsdoc;
916 nsIDOMNode *nsnode;
917 nsAString ns_text;
918 HRESULT hr;
920 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
922 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
923 if(NS_FAILED(nsres) || !nsdoc)
925 ERR("GetDocument failed: %08x\n", nsres);
926 return E_FAIL;
929 nsAString_Init(&ns_text, text);
931 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
932 nsIDOMDocument_Release(nsdoc);
933 nsAString_Finish(&ns_text);
935 if(NS_FAILED(nsres) || !nsnode)
937 ERR("CreateTextNode failed: %08x\n", nsres);
938 return E_FAIL;
941 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
942 nsIDOMNode_Release(nsnode);
944 return hr;
947 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
949 HTMLElement *This = HTMLELEM_THIS(iface);
950 FIXME("(%p)->(%p)\n", This, p);
951 return E_NOTIMPL;
954 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
956 HTMLElement *This = HTMLELEM_THIS(iface);
957 FIXME("(%p)->(%p)\n", This, p);
958 return E_NOTIMPL;
961 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
963 HTMLElement *This = HTMLELEM_THIS(iface);
964 FIXME("(%p)\n", This);
965 return E_NOTIMPL;
968 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
969 IHTMLFiltersCollection **p)
971 HTMLElement *This = HTMLELEM_THIS(iface);
972 FIXME("(%p)->(%p)\n", This, p);
973 return E_NOTIMPL;
976 static HRESULT WINAPI HTMLElement_put_ondragstart(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_ondragstart(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_toString(IHTMLElement *iface, BSTR *String)
992 HTMLElement *This = HTMLELEM_THIS(iface);
993 FIXME("(%p)->(%p)\n", This, String);
994 return E_NOTIMPL;
997 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(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_onbeforeupdate(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_onafterupdate(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_onafterupdate(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_onerrorupdate(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_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1034 HTMLElement *This = HTMLELEM_THIS(iface);
1035 FIXME("(%p)->(%p)\n", This, p);
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1041 HTMLElement *This = HTMLELEM_THIS(iface);
1042 FIXME("(%p)->()\n", This);
1043 return E_NOTIMPL;
1046 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1048 HTMLElement *This = HTMLELEM_THIS(iface);
1049 FIXME("(%p)->(%p)\n", This, p);
1050 return E_NOTIMPL;
1053 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1055 HTMLElement *This = HTMLELEM_THIS(iface);
1056 FIXME("(%p)->()\n", This);
1057 return E_NOTIMPL;
1060 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1062 HTMLElement *This = HTMLELEM_THIS(iface);
1063 FIXME("(%p)->(%p)\n", This, p);
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1069 HTMLElement *This = HTMLELEM_THIS(iface);
1070 FIXME("(%p)->()\n", This);
1071 return E_NOTIMPL;
1074 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1076 HTMLElement *This = HTMLELEM_THIS(iface);
1077 FIXME("(%p)->(%p)\n", This, p);
1078 return E_NOTIMPL;
1081 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1083 HTMLElement *This = HTMLELEM_THIS(iface);
1084 FIXME("(%p)->()\n", This);
1085 return E_NOTIMPL;
1088 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1090 HTMLElement *This = HTMLELEM_THIS(iface);
1091 FIXME("(%p)->(%p)\n", This, p);
1092 return E_NOTIMPL;
1095 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1097 HTMLElement *This = HTMLELEM_THIS(iface);
1098 FIXME("(%p)->()\n", This);
1099 return E_NOTIMPL;
1102 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1104 HTMLElement *This = HTMLELEM_THIS(iface);
1105 FIXME("(%p)->(%p)\n", This, p);
1106 return E_NOTIMPL;
1109 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1111 HTMLElement *This = HTMLELEM_THIS(iface);
1112 FIXME("(%p)->()\n", This);
1113 return E_NOTIMPL;
1116 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1118 HTMLElement *This = HTMLELEM_THIS(iface);
1119 FIXME("(%p)->(%p)\n", This, p);
1120 return E_NOTIMPL;
1123 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1125 nsIDOMNodeList *nsnode_list;
1126 nsIDOMNode *iter;
1127 PRUint32 list_len = 0, i;
1128 nsresult nsres;
1130 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1131 if(NS_FAILED(nsres)) {
1132 ERR("GetChildNodes failed: %08x\n", nsres);
1133 return;
1136 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1137 if(!list_len)
1138 return;
1140 buf->size = list_len;
1141 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1143 for(i=0; i<list_len; i++) {
1144 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1145 if(NS_FAILED(nsres)) {
1146 ERR("Item failed: %08x\n", nsres);
1147 continue;
1150 if(is_elem_node(iter))
1151 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1155 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1157 HTMLElement *This = HTMLELEM_THIS(iface);
1158 elem_vector buf = {NULL, 0, 0};
1160 TRACE("(%p)->(%p)\n", This, p);
1162 create_child_list(This->node.doc, This, &buf);
1164 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1165 return S_OK;
1168 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1170 nsIDOMNodeList *nsnode_list;
1171 nsIDOMNode *iter;
1172 PRUint32 list_len = 0, i;
1173 nsresult nsres;
1175 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1176 if(NS_FAILED(nsres)) {
1177 ERR("GetChildNodes failed: %08x\n", nsres);
1178 return;
1181 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1182 if(!list_len)
1183 return;
1185 for(i=0; i<list_len; i++) {
1186 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1187 if(NS_FAILED(nsres)) {
1188 ERR("Item failed: %08x\n", nsres);
1189 continue;
1192 if(is_elem_node(iter)) {
1193 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1195 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1196 create_all_list(doc, node, buf);
1201 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1203 HTMLElement *This = HTMLELEM_THIS(iface);
1204 elem_vector buf = {NULL, 0, 8};
1206 TRACE("(%p)->(%p)\n", This, p);
1208 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1210 create_all_list(This->node.doc, &This->node, &buf);
1211 elem_vector_normalize(&buf);
1213 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1214 return S_OK;
1217 #undef HTMLELEM_THIS
1219 static const IHTMLElementVtbl HTMLElementVtbl = {
1220 HTMLElement_QueryInterface,
1221 HTMLElement_AddRef,
1222 HTMLElement_Release,
1223 HTMLElement_GetTypeInfoCount,
1224 HTMLElement_GetTypeInfo,
1225 HTMLElement_GetIDsOfNames,
1226 HTMLElement_Invoke,
1227 HTMLElement_setAttribute,
1228 HTMLElement_getAttribute,
1229 HTMLElement_removeAttribute,
1230 HTMLElement_put_className,
1231 HTMLElement_get_className,
1232 HTMLElement_put_id,
1233 HTMLElement_get_id,
1234 HTMLElement_get_tagName,
1235 HTMLElement_get_parentElement,
1236 HTMLElement_get_style,
1237 HTMLElement_put_onhelp,
1238 HTMLElement_get_onhelp,
1239 HTMLElement_put_onclick,
1240 HTMLElement_get_onclick,
1241 HTMLElement_put_ondblclick,
1242 HTMLElement_get_ondblclick,
1243 HTMLElement_put_onkeydown,
1244 HTMLElement_get_onkeydown,
1245 HTMLElement_put_onkeyup,
1246 HTMLElement_get_onkeyup,
1247 HTMLElement_put_onkeypress,
1248 HTMLElement_get_onkeypress,
1249 HTMLElement_put_onmouseout,
1250 HTMLElement_get_onmouseout,
1251 HTMLElement_put_onmouseover,
1252 HTMLElement_get_onmouseover,
1253 HTMLElement_put_onmousemove,
1254 HTMLElement_get_onmousemove,
1255 HTMLElement_put_onmousedown,
1256 HTMLElement_get_onmousedown,
1257 HTMLElement_put_onmouseup,
1258 HTMLElement_get_onmouseup,
1259 HTMLElement_get_document,
1260 HTMLElement_put_title,
1261 HTMLElement_get_title,
1262 HTMLElement_put_language,
1263 HTMLElement_get_language,
1264 HTMLElement_put_onselectstart,
1265 HTMLElement_get_onselectstart,
1266 HTMLElement_scrollIntoView,
1267 HTMLElement_contains,
1268 HTMLElement_get_sourceIndex,
1269 HTMLElement_get_recordNumber,
1270 HTMLElement_put_lang,
1271 HTMLElement_get_lang,
1272 HTMLElement_get_offsetLeft,
1273 HTMLElement_get_offsetTop,
1274 HTMLElement_get_offsetWidth,
1275 HTMLElement_get_offsetHeight,
1276 HTMLElement_get_offsetParent,
1277 HTMLElement_put_innerHTML,
1278 HTMLElement_get_innerHTML,
1279 HTMLElement_put_innerText,
1280 HTMLElement_get_innerText,
1281 HTMLElement_put_outerHTML,
1282 HTMLElement_get_outerHTML,
1283 HTMLElement_put_outerText,
1284 HTMLElement_get_outerText,
1285 HTMLElement_insertAdjacentHTML,
1286 HTMLElement_insertAdjacentText,
1287 HTMLElement_get_parentTextEdit,
1288 HTMLElement_get_isTextEdit,
1289 HTMLElement_click,
1290 HTMLElement_get_filters,
1291 HTMLElement_put_ondragstart,
1292 HTMLElement_get_ondragstart,
1293 HTMLElement_toString,
1294 HTMLElement_put_onbeforeupdate,
1295 HTMLElement_get_onbeforeupdate,
1296 HTMLElement_put_onafterupdate,
1297 HTMLElement_get_onafterupdate,
1298 HTMLElement_put_onerrorupdate,
1299 HTMLElement_get_onerrorupdate,
1300 HTMLElement_put_onrowexit,
1301 HTMLElement_get_onrowexit,
1302 HTMLElement_put_onrowenter,
1303 HTMLElement_get_onrowenter,
1304 HTMLElement_put_ondatasetchanged,
1305 HTMLElement_get_ondatasetchanged,
1306 HTMLElement_put_ondataavailable,
1307 HTMLElement_get_ondataavailable,
1308 HTMLElement_put_ondatasetcomplete,
1309 HTMLElement_get_ondatasetcomplete,
1310 HTMLElement_put_onfilterchange,
1311 HTMLElement_get_onfilterchange,
1312 HTMLElement_get_children,
1313 HTMLElement_get_all
1316 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1318 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1320 *ppv = NULL;
1322 if(IsEqualGUID(&IID_IUnknown, riid)) {
1323 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1324 *ppv = HTMLELEM(This);
1325 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1326 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1327 *ppv = HTMLELEM(This);
1328 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1329 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1330 *ppv = HTMLELEM(This);
1331 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1332 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1333 *ppv = HTMLELEM2(This);
1334 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1335 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1336 *ppv = CONPTCONT(&This->cp_container);
1339 if(*ppv) {
1340 IHTMLElement_AddRef(HTMLELEM(This));
1341 return S_OK;
1344 return HTMLDOMNode_QI(&This->node, riid, ppv);
1347 void HTMLElement_destructor(HTMLDOMNode *iface)
1349 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1351 ConnectionPointContainer_Destroy(&This->cp_container);
1353 if(This->nselem)
1354 nsIDOMHTMLElement_Release(This->nselem);
1356 HTMLDOMNode_destructor(&This->node);
1359 static const NodeImplVtbl HTMLElementImplVtbl = {
1360 HTMLElement_QI,
1361 HTMLElement_destructor
1364 static const tid_t HTMLElement_iface_tids[] = {
1365 IHTMLDOMNode_tid,
1366 IHTMLDOMNode2_tid,
1367 IHTMLElement_tid,
1368 IHTMLElement2_tid,
1371 static dispex_static_data_t HTMLElement_dispex = {
1372 NULL,
1373 DispHTMLUnknownElement_tid,
1374 NULL,
1375 HTMLElement_iface_tids
1378 void HTMLElement_Init(HTMLElement *This)
1380 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1382 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1384 HTMLElement2_Init(This);
1386 if(!This->node.dispex.data)
1387 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1390 HTMLElement *HTMLElement_Create(nsIDOMNode *nsnode)
1392 nsIDOMHTMLElement *nselem;
1393 HTMLElement *ret = NULL;
1394 nsAString class_name_str;
1395 const PRUnichar *class_name;
1396 nsresult nsres;
1398 static const WCHAR wszA[] = {'A',0};
1399 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1400 static const WCHAR wszIMG[] = {'I','M','G',0};
1401 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1402 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1403 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1404 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1405 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1406 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1408 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1409 if(NS_FAILED(nsres))
1410 return NULL;
1412 nsAString_Init(&class_name_str, NULL);
1413 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1415 nsAString_GetData(&class_name_str, &class_name);
1417 if(!strcmpW(class_name, wszA))
1418 ret = HTMLAnchorElement_Create(nselem);
1419 else if(!strcmpW(class_name, wszBODY))
1420 ret = HTMLBodyElement_Create(nselem);
1421 else if(!strcmpW(class_name, wszIMG))
1422 ret = HTMLImgElement_Create(nselem);
1423 else if(!strcmpW(class_name, wszINPUT))
1424 ret = HTMLInputElement_Create(nselem);
1425 else if(!strcmpW(class_name, wszOPTION))
1426 ret = HTMLOptionElement_Create(nselem);
1427 else if(!strcmpW(class_name, wszSCRIPT))
1428 ret = HTMLScriptElement_Create(nselem);
1429 else if(!strcmpW(class_name, wszSELECT))
1430 ret = HTMLSelectElement_Create(nselem);
1431 else if(!strcmpW(class_name, wszTABLE))
1432 ret = HTMLTable_Create(nselem);
1433 else if(!strcmpW(class_name, wszTEXTAREA))
1434 ret = HTMLTextAreaElement_Create(nselem);
1436 if(!ret) {
1437 ret = heap_alloc_zero(sizeof(HTMLElement));
1438 HTMLElement_Init(ret);
1439 ret->node.vtbl = &HTMLElementImplVtbl;
1442 nsAString_Finish(&class_name_str);
1444 ret->nselem = nselem;
1446 return ret;
1449 typedef struct {
1450 DispatchEx dispex;
1451 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1453 IUnknown *ref_unk;
1454 HTMLElement **elems;
1455 DWORD len;
1457 LONG ref;
1458 } HTMLElementCollection;
1460 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1462 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1464 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1465 REFIID riid, void **ppv)
1467 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1469 *ppv = NULL;
1471 if(IsEqualGUID(&IID_IUnknown, riid)) {
1472 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1473 *ppv = HTMLELEMCOL(This);
1474 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1475 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1476 *ppv = HTMLELEMCOL(This);
1477 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1478 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1479 *ppv = DISPATCHEX(&This->dispex);
1480 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1481 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1482 *ppv = HTMLELEMCOL(This);
1485 if(*ppv) {
1486 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1487 return S_OK;
1490 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1491 return E_NOINTERFACE;
1494 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1496 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1497 LONG ref = InterlockedIncrement(&This->ref);
1499 TRACE("(%p) ref=%d\n", This, ref);
1501 return ref;
1504 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1506 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1507 LONG ref = InterlockedDecrement(&This->ref);
1509 TRACE("(%p) ref=%d\n", This, ref);
1511 if(!ref) {
1512 IUnknown_Release(This->ref_unk);
1513 heap_free(This->elems);
1514 heap_free(This);
1517 return ref;
1520 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1521 UINT *pctinfo)
1523 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1524 FIXME("(%p)->(%p)\n", This, pctinfo);
1525 return E_NOTIMPL;
1528 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1529 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1531 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1532 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1533 return E_NOTIMPL;
1536 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1537 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1539 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1540 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1541 lcid, rgDispId);
1542 return E_NOTIMPL;
1545 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1546 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1547 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1549 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1550 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1551 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1552 return E_NOTIMPL;
1555 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1556 BSTR *String)
1558 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1559 FIXME("(%p)->(%p)\n", This, String);
1560 return E_NOTIMPL;
1563 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1564 long v)
1566 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1567 FIXME("(%p)->(%ld)\n", This, v);
1568 return E_NOTIMPL;
1571 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1572 long *p)
1574 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1576 TRACE("(%p)->(%p)\n", This, p);
1578 *p = This->len;
1579 return S_OK;
1582 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1583 IUnknown **p)
1585 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1586 FIXME("(%p)->(%p)\n", This, p);
1587 return E_NOTIMPL;
1590 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1592 const PRUnichar *str;
1593 nsAString nsstr, nsname;
1594 BOOL ret = FALSE;
1595 nsresult nsres;
1597 static const PRUnichar nameW[] = {'n','a','m','e',0};
1599 if(!elem->nselem)
1600 return FALSE;
1602 nsAString_Init(&nsstr, NULL);
1603 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1604 nsAString_GetData(&nsstr, &str);
1605 if(!strcmpiW(str, name)) {
1606 nsAString_Finish(&nsstr);
1607 return TRUE;
1610 nsAString_Init(&nsname, nameW);
1611 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1612 nsAString_Finish(&nsname);
1613 if(NS_SUCCEEDED(nsres)) {
1614 nsAString_GetData(&nsstr, &str);
1615 ret = !strcmpiW(str, name);
1618 nsAString_Finish(&nsstr);
1619 return ret;
1622 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1623 VARIANT name, VARIANT index, IDispatch **pdisp)
1625 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1627 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1629 *pdisp = NULL;
1631 if(V_VT(&name) == VT_I4) {
1632 TRACE("name is VT_I4: %d\n", V_I4(&name));
1634 if(V_I4(&name) < 0)
1635 return E_INVALIDARG;
1636 if(V_I4(&name) >= This->len)
1637 return S_OK;
1639 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1640 IDispatch_AddRef(*pdisp);
1641 TRACE("Returning pdisp=%p\n", pdisp);
1642 return S_OK;
1645 if(V_VT(&name) == VT_BSTR) {
1646 DWORD i;
1648 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1650 if(V_VT(&index) == VT_I4) {
1651 LONG idx = V_I4(&index);
1653 TRACE("index = %d\n", idx);
1655 if(idx < 0)
1656 return E_INVALIDARG;
1658 for(i=0; i<This->len; i++) {
1659 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1660 break;
1663 if(i != This->len) {
1664 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1665 IDispatch_AddRef(*pdisp);
1668 return S_OK;
1669 }else {
1670 elem_vector buf = {NULL, 0, 8};
1672 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1674 for(i=0; i<This->len; i++) {
1675 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1676 elem_vector_add(&buf, This->elems[i]);
1679 if(buf.len > 1) {
1680 elem_vector_normalize(&buf);
1681 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1682 }else {
1683 if(buf.len == 1) {
1684 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1685 IDispatch_AddRef(*pdisp);
1688 heap_free(buf.buf);
1691 return S_OK;
1695 FIXME("unsupported arguments\n");
1696 return E_INVALIDARG;
1699 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1700 VARIANT tagName, IDispatch **pdisp)
1702 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1703 DWORD i;
1704 nsAString tag_str;
1705 const PRUnichar *tag;
1706 elem_vector buf = {NULL, 0, 8};
1708 if(V_VT(&tagName) != VT_BSTR) {
1709 WARN("Invalid arg\n");
1710 return DISP_E_MEMBERNOTFOUND;
1713 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1715 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1717 nsAString_Init(&tag_str, NULL);
1719 for(i=0; i<This->len; i++) {
1720 if(!This->elems[i]->nselem)
1721 continue;
1723 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1724 nsAString_GetData(&tag_str, &tag);
1726 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1727 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1728 elem_vector_add(&buf, This->elems[i]);
1731 nsAString_Finish(&tag_str);
1732 elem_vector_normalize(&buf);
1734 TRACE("fount %d tags\n", buf.len);
1736 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1737 return S_OK;
1740 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1742 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1744 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1745 WCHAR *ptr;
1746 DWORD idx=0;
1748 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1749 idx = idx*10 + (*ptr-'0');
1751 if(*ptr || idx >= This->len)
1752 return DISP_E_UNKNOWNNAME;
1754 *dispid = DISPID_ELEMCOL_0 + idx;
1755 TRACE("ret %x\n", *dispid);
1756 return S_OK;
1759 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1760 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1762 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1763 DWORD idx;
1765 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1767 idx = id - DISPID_ELEMCOL_0;
1768 if(idx >= This->len)
1769 return DISP_E_UNKNOWNNAME;
1771 switch(flags) {
1772 case INVOKE_PROPERTYGET:
1773 V_VT(res) = VT_DISPATCH;
1774 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1775 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1776 break;
1777 default:
1778 FIXME("unimplemented flags %x\n", flags);
1779 return E_NOTIMPL;
1782 return S_OK;
1785 #undef ELEMCOL_THIS
1787 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1788 HTMLElementCollection_QueryInterface,
1789 HTMLElementCollection_AddRef,
1790 HTMLElementCollection_Release,
1791 HTMLElementCollection_GetTypeInfoCount,
1792 HTMLElementCollection_GetTypeInfo,
1793 HTMLElementCollection_GetIDsOfNames,
1794 HTMLElementCollection_Invoke,
1795 HTMLElementCollection_toString,
1796 HTMLElementCollection_put_length,
1797 HTMLElementCollection_get_length,
1798 HTMLElementCollection_get__newEnum,
1799 HTMLElementCollection_item,
1800 HTMLElementCollection_tags
1803 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1804 HTMLElementCollection_get_dispid,
1805 HTMLElementCollection_invoke
1808 static const tid_t HTMLElementCollection_iface_tids[] = {
1809 IHTMLElementCollection_tid,
1812 static dispex_static_data_t HTMLElementCollection_dispex = {
1813 &HTMLElementColection_dispex_vtbl,
1814 DispHTMLElementCollection_tid,
1815 NULL,
1816 HTMLElementCollection_iface_tids
1819 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1821 elem_vector buf = {NULL, 0, 8};
1823 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1825 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1826 create_all_list(node->doc, node, &buf);
1827 elem_vector_normalize(&buf);
1829 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1832 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1833 HTMLElement **elems, DWORD len)
1835 HTMLElementCollection *ret = heap_alloc(sizeof(HTMLElementCollection));
1837 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1838 ret->ref = 1;
1839 ret->elems = elems;
1840 ret->len = len;
1842 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1844 IUnknown_AddRef(ref_unk);
1845 ret->ref_unk = ref_unk;
1847 TRACE("ret=%p len=%d\n", ret, len);
1849 return HTMLELEMCOL(ret);