push 7f8c39dca3a5819e8ef115eebf7abed537de3a22
[wine/hacks.git] / dlls / mshtml / htmlelem.c
blob7c20c2caaf57d88d58945094c462d0d5b2ebd086
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 V_VT(AttributeValue) = VT_NULL;
198 return S_OK;
201 V_VT(AttributeValue) = VT_NULL;
203 nsAString_Init(&attr_str, strAttributeName);
204 nsAString_Init(&value_str, NULL);
206 nsres = nsIDOMHTMLElement_GetAttribute(This->nselem, &attr_str, &value_str);
207 nsAString_Finish(&attr_str);
209 if(NS_SUCCEEDED(nsres)) {
210 static const WCHAR wszSRC[] = {'s','r','c',0};
211 nsAString_GetData(&value_str, &value);
212 if(!strcmpiW(strAttributeName, wszSRC))
214 WCHAR buffer[256];
215 DWORD len;
216 BSTR bstrBaseUrl;
217 hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
218 if(SUCCEEDED(hres)) {
219 hres = CoInternetCombineUrl(bstrBaseUrl, value,
220 URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
221 buffer, sizeof(buffer)/sizeof(WCHAR), &len, 0);
222 SysFreeString(bstrBaseUrl);
223 if(SUCCEEDED(hres)) {
224 V_VT(AttributeValue) = VT_BSTR;
225 V_BSTR(AttributeValue) = SysAllocString(buffer);
226 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
229 }else if(*value) {
230 V_VT(AttributeValue) = VT_BSTR;
231 V_BSTR(AttributeValue) = SysAllocString(value);
232 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue)));
234 }else {
235 ERR("GetAttribute failed: %08x\n", nsres);
236 hres = E_FAIL;
239 nsAString_Finish(&value_str);
241 return hres;
244 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
245 LONG lFlags, VARIANT_BOOL *pfSuccess)
247 HTMLElement *This = HTMLELEM_THIS(iface);
248 FIXME("(%p)->()\n", This);
249 return E_NOTIMPL;
252 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
254 HTMLElement *This = HTMLELEM_THIS(iface);
255 nsAString classname_str;
256 nsresult nsres;
258 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
260 if(!This->nselem) {
261 FIXME("NULL nselem\n");
262 return E_NOTIMPL;
265 nsAString_Init(&classname_str, v);
266 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
267 nsAString_Finish(&classname_str);
268 if(NS_FAILED(nsres))
269 ERR("SetClassName failed: %08x\n", nsres);
271 return S_OK;
274 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
276 HTMLElement *This = HTMLELEM_THIS(iface);
277 nsAString class_str;
278 nsresult nsres;
279 HRESULT hres = S_OK;
281 TRACE("(%p)->(%p)\n", This, p);
283 if(!This->nselem) {
284 FIXME("NULL nselem\n");
285 return E_NOTIMPL;
288 nsAString_Init(&class_str, NULL);
289 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
291 if(NS_SUCCEEDED(nsres)) {
292 const PRUnichar *class;
293 nsAString_GetData(&class_str, &class);
294 *p = *class ? SysAllocString(class) : NULL;
295 }else {
296 ERR("GetClassName failed: %08x\n", nsres);
297 hres = E_FAIL;
300 nsAString_Finish(&class_str);
302 TRACE("className=%s\n", debugstr_w(*p));
303 return hres;
306 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
308 HTMLElement *This = HTMLELEM_THIS(iface);
309 nsAString id_str;
310 nsresult nsres;
312 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
314 if(!This->nselem) {
315 FIXME("nselem == NULL\n");
316 return S_OK;
319 nsAString_Init(&id_str, v);
320 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
321 nsAString_Finish(&id_str);
322 if(NS_FAILED(nsres))
323 ERR("SetId failed: %08x\n", nsres);
325 return S_OK;
328 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
330 HTMLElement *This = HTMLELEM_THIS(iface);
331 const PRUnichar *id;
332 nsAString id_str;
333 nsresult nsres;
335 TRACE("(%p)->(%p)\n", This, p);
337 *p = NULL;
339 if(!This->nselem)
340 return S_OK;
342 nsAString_Init(&id_str, NULL);
343 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
344 nsAString_GetData(&id_str, &id);
346 if(NS_FAILED(nsres))
347 ERR("GetId failed: %08x\n", nsres);
348 else if(*id)
349 *p = SysAllocString(id);
351 nsAString_Finish(&id_str);
352 return S_OK;
355 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
357 HTMLElement *This = HTMLELEM_THIS(iface);
358 const PRUnichar *tag;
359 nsAString tag_str;
360 nsresult nsres;
362 TRACE("(%p)->(%p)\n", This, p);
364 if(!This->nselem) {
365 static const WCHAR comment_tagW[] = {'!',0};
367 WARN("NULL nselem, assuming comment\n");
369 *p = SysAllocString(comment_tagW);
370 return S_OK;
373 nsAString_Init(&tag_str, NULL);
374 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
375 if(NS_SUCCEEDED(nsres)) {
376 nsAString_GetData(&tag_str, &tag);
377 *p = SysAllocString(tag);
378 }else {
379 ERR("GetTagName failed: %08x\n", nsres);
380 *p = NULL;
382 nsAString_Finish(&tag_str);
384 return S_OK;
387 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
389 HTMLElement *This = HTMLELEM_THIS(iface);
390 FIXME("(%p)->(%p)\n", This, p);
391 return E_NOTIMPL;
394 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
396 HTMLElement *This = HTMLELEM_THIS(iface);
397 nsIDOMElementCSSInlineStyle *nselemstyle;
398 nsIDOMCSSStyleDeclaration *nsstyle;
399 nsresult nsres;
401 TRACE("(%p)->(%p)\n", This, p);
403 if(!This->nselem) {
404 FIXME("NULL nselem\n");
405 return E_NOTIMPL;
408 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
409 (void**)&nselemstyle);
410 if(NS_FAILED(nsres)) {
411 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
412 return E_FAIL;
415 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
416 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
417 if(NS_FAILED(nsres)) {
418 ERR("GetStyle failed: %08x\n", nsres);
419 return E_FAIL;
422 /* FIXME: Store style instead of creating a new instance in each call */
423 *p = HTMLStyle_Create(nsstyle);
425 nsIDOMCSSStyleDeclaration_Release(nsstyle);
426 return S_OK;
429 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
431 HTMLElement *This = HTMLELEM_THIS(iface);
432 FIXME("(%p)->()\n", This);
433 return E_NOTIMPL;
436 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
438 HTMLElement *This = HTMLELEM_THIS(iface);
439 FIXME("(%p)->(%p)\n", This, p);
440 return E_NOTIMPL;
443 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
445 HTMLElement *This = HTMLELEM_THIS(iface);
447 TRACE("(%p)->()\n", This);
449 return set_node_event(&This->node, EVENTID_CLICK, &v);
452 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
454 HTMLElement *This = HTMLELEM_THIS(iface);
455 FIXME("(%p)->(%p)\n", This, p);
456 return E_NOTIMPL;
459 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
461 HTMLElement *This = HTMLELEM_THIS(iface);
462 FIXME("(%p)->()\n", This);
463 return E_NOTIMPL;
466 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
468 HTMLElement *This = HTMLELEM_THIS(iface);
469 FIXME("(%p)->(%p)\n", This, p);
470 return E_NOTIMPL;
473 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
475 HTMLElement *This = HTMLELEM_THIS(iface);
476 FIXME("(%p)->()\n", This);
477 return E_NOTIMPL;
480 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
482 HTMLElement *This = HTMLELEM_THIS(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
489 HTMLElement *This = HTMLELEM_THIS(iface);
491 TRACE("(%p)->()\n", This);
493 return set_node_event(&This->node, EVENTID_KEYUP, &v);
496 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
498 HTMLElement *This = HTMLELEM_THIS(iface);
499 FIXME("(%p)->(%p)\n", This, p);
500 return E_NOTIMPL;
503 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
505 HTMLElement *This = HTMLELEM_THIS(iface);
506 FIXME("(%p)->()\n", This);
507 return E_NOTIMPL;
510 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
512 HTMLElement *This = HTMLELEM_THIS(iface);
513 FIXME("(%p)->(%p)\n", This, p);
514 return E_NOTIMPL;
517 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
519 HTMLElement *This = HTMLELEM_THIS(iface);
520 FIXME("(%p)->()\n", This);
521 return E_NOTIMPL;
524 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
526 HTMLElement *This = HTMLELEM_THIS(iface);
527 FIXME("(%p)->(%p)\n", This, p);
528 return E_NOTIMPL;
531 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
533 HTMLElement *This = HTMLELEM_THIS(iface);
534 FIXME("(%p)->()\n", This);
535 return E_NOTIMPL;
538 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
540 HTMLElement *This = HTMLELEM_THIS(iface);
541 FIXME("(%p)->(%p)\n", This, p);
542 return E_NOTIMPL;
545 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
547 HTMLElement *This = HTMLELEM_THIS(iface);
548 FIXME("(%p)->()\n", This);
549 return E_NOTIMPL;
552 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
554 HTMLElement *This = HTMLELEM_THIS(iface);
555 FIXME("(%p)->(%p)\n", This, p);
556 return E_NOTIMPL;
559 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
561 HTMLElement *This = HTMLELEM_THIS(iface);
562 FIXME("(%p)->()\n", This);
563 return E_NOTIMPL;
566 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
568 HTMLElement *This = HTMLELEM_THIS(iface);
569 FIXME("(%p)->(%p)\n", This, p);
570 return E_NOTIMPL;
573 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
575 HTMLElement *This = HTMLELEM_THIS(iface);
576 FIXME("(%p)->()\n", This);
577 return E_NOTIMPL;
580 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
582 HTMLElement *This = HTMLELEM_THIS(iface);
583 FIXME("(%p)->(%p)\n", This, p);
584 return E_NOTIMPL;
587 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
589 HTMLElement *This = HTMLELEM_THIS(iface);
590 FIXME("(%p)->(%p)\n", This, p);
591 return E_NOTIMPL;
594 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
596 HTMLElement *This = HTMLELEM_THIS(iface);
597 nsAString title_str;
598 nsresult nsres;
600 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
602 nsAString_Init(&title_str, v);
603 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
604 nsAString_Finish(&title_str);
605 if(NS_FAILED(nsres))
606 ERR("SetTitle failed: %08x\n", nsres);
608 return S_OK;
611 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
613 HTMLElement *This = HTMLELEM_THIS(iface);
614 nsAString title_str;
615 nsresult nsres;
617 TRACE("(%p)->(%p)\n", This, p);
619 nsAString_Init(&title_str, NULL);
620 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
621 if(NS_SUCCEEDED(nsres)) {
622 const PRUnichar *title;
624 nsAString_GetData(&title_str, &title);
625 *p = *title ? SysAllocString(title) : NULL;
626 }else {
627 ERR("GetTitle failed: %08x\n", nsres);
628 return E_FAIL;
631 return S_OK;
634 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
636 HTMLElement *This = HTMLELEM_THIS(iface);
637 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
638 return E_NOTIMPL;
641 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
643 HTMLElement *This = HTMLELEM_THIS(iface);
644 FIXME("(%p)->(%p)\n", This, p);
645 return E_NOTIMPL;
648 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
650 HTMLElement *This = HTMLELEM_THIS(iface);
651 FIXME("(%p)->()\n", This);
652 return E_NOTIMPL;
655 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
657 HTMLElement *This = HTMLELEM_THIS(iface);
658 FIXME("(%p)->(%p)\n", This, p);
659 return E_NOTIMPL;
662 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
664 HTMLElement *This = HTMLELEM_THIS(iface);
665 FIXME("(%p)->()\n", This);
666 return E_NOTIMPL;
669 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
670 VARIANT_BOOL *pfResult)
672 HTMLElement *This = HTMLELEM_THIS(iface);
673 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
674 return E_NOTIMPL;
677 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, long *p)
679 HTMLElement *This = HTMLELEM_THIS(iface);
680 FIXME("(%p)->(%p)\n", This, p);
681 return E_NOTIMPL;
684 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
686 HTMLElement *This = HTMLELEM_THIS(iface);
687 FIXME("(%p)->(%p)\n", This, p);
688 return E_NOTIMPL;
691 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
693 HTMLElement *This = HTMLELEM_THIS(iface);
694 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
695 return E_NOTIMPL;
698 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
700 HTMLElement *This = HTMLELEM_THIS(iface);
701 FIXME("(%p)->(%p)\n", This, p);
702 return E_NOTIMPL;
705 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, long *p)
707 HTMLElement *This = HTMLELEM_THIS(iface);
708 FIXME("(%p)->(%p)\n", This, p);
709 return E_NOTIMPL;
712 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, long *p)
714 HTMLElement *This = HTMLELEM_THIS(iface);
715 nsIDOMNSHTMLElement *nselem;
716 PRInt32 top = 0;
717 nsresult nsres;
719 TRACE("(%p)->(%p)\n", This, p);
721 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
722 if(NS_FAILED(nsres)) {
723 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
724 return E_FAIL;
727 nsres = nsIDOMNSHTMLElement_GetOffsetTop(nselem, &top);
728 nsIDOMNSHTMLElement_Release(nselem);
729 if(NS_FAILED(nsres)) {
730 ERR("GetOffsetTop failed: %08x\n", nsres);
731 return E_FAIL;
734 *p = top;
735 return S_OK;
738 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, long *p)
740 HTMLElement *This = HTMLELEM_THIS(iface);
741 FIXME("(%p)->(%p)\n", This, p);
742 return E_NOTIMPL;
745 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, long *p)
747 HTMLElement *This = HTMLELEM_THIS(iface);
748 FIXME("(%p)->(%p)\n", This, p);
749 return E_NOTIMPL;
752 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
754 HTMLElement *This = HTMLELEM_THIS(iface);
755 FIXME("(%p)->(%p)\n", This, p);
756 return E_NOTIMPL;
759 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
761 HTMLElement *This = HTMLELEM_THIS(iface);
762 nsIDOMNSHTMLElement *nselem;
763 nsAString html_str;
764 nsresult nsres;
766 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
768 if(!This->nselem) {
769 FIXME("NULL nselem\n");
770 return E_NOTIMPL;
773 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
774 if(NS_FAILED(nsres)) {
775 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
776 return E_FAIL;
779 nsAString_Init(&html_str, v);
780 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
781 nsAString_Finish(&html_str);
783 if(NS_FAILED(nsres)) {
784 FIXME("SetInnerHtml failed %08x\n", nsres);
785 return E_FAIL;
788 return S_OK;
791 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
793 HTMLElement *This = HTMLELEM_THIS(iface);
794 FIXME("(%p)->(%p)\n", This, p);
795 return E_NOTIMPL;
798 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
800 HTMLElement *This = HTMLELEM_THIS(iface);
801 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
802 return E_NOTIMPL;
805 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
807 HTMLElement *This = HTMLELEM_THIS(iface);
808 FIXME("(%p)->(%p)\n", This, p);
809 return E_NOTIMPL;
812 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
814 HTMLElement *This = HTMLELEM_THIS(iface);
815 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
816 return E_NOTIMPL;
819 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
821 HTMLElement *This = HTMLELEM_THIS(iface);
822 FIXME("(%p)->(%p)\n", This, p);
823 return E_NOTIMPL;
826 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
828 HTMLElement *This = HTMLELEM_THIS(iface);
829 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
830 return E_NOTIMPL;
833 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
835 HTMLElement *This = HTMLELEM_THIS(iface);
836 FIXME("(%p)->(%p)\n", This, p);
837 return E_NOTIMPL;
840 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
842 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
843 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
844 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
845 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
846 nsresult nsres;
848 if(!This->nselem) {
849 FIXME("NULL nselem\n");
850 return E_NOTIMPL;
853 if (!strcmpiW(where, wszBeforeBegin))
855 nsIDOMNode *unused;
856 nsIDOMNode *parent;
857 nsres = nsIDOMNode_GetParentNode(This->nselem, &parent);
858 if (!parent) return E_INVALIDARG;
859 nsres = nsIDOMNode_InsertBefore(parent, nsnode,
860 (nsIDOMNode *)This->nselem, &unused);
861 if (unused) nsIDOMNode_Release(unused);
862 nsIDOMNode_Release(parent);
864 else if (!strcmpiW(where, wszAfterBegin))
866 nsIDOMNode *unused;
867 nsIDOMNode *first_child;
868 nsIDOMNode_GetFirstChild(This->nselem, &first_child);
869 nsres = nsIDOMNode_InsertBefore(This->nselem, nsnode, first_child, &unused);
870 if (unused) nsIDOMNode_Release(unused);
871 if (first_child) nsIDOMNode_Release(first_child);
873 else if (!strcmpiW(where, wszBeforeEnd))
875 nsIDOMNode *unused;
876 nsres = nsIDOMNode_AppendChild(This->nselem, nsnode, &unused);
877 if (unused) nsIDOMNode_Release(unused);
879 else if (!strcmpiW(where, wszAfterEnd))
881 nsIDOMNode *unused;
882 nsIDOMNode *next_sibling;
883 nsIDOMNode *parent;
884 nsIDOMNode_GetParentNode(This->nselem, &parent);
885 if (!parent) return E_INVALIDARG;
887 nsIDOMNode_GetNextSibling(This->nselem, &next_sibling);
888 if (next_sibling)
890 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
891 nsIDOMNode_Release(next_sibling);
893 else
894 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
895 nsIDOMNode_Release(parent);
896 if (unused) nsIDOMNode_Release(unused);
898 else
900 ERR("invalid where: %s\n", debugstr_w(where));
901 return E_INVALIDARG;
904 if (NS_FAILED(nsres))
905 return E_FAIL;
906 else
907 return S_OK;
910 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
911 BSTR html)
913 HTMLElement *This = HTMLELEM_THIS(iface);
914 nsresult nsres;
915 nsIDOMDocument *nsdoc;
916 nsIDOMDocumentRange *nsdocrange;
917 nsIDOMRange *range;
918 nsIDOMNSRange *nsrange;
919 nsIDOMNode *nsnode;
920 nsAString ns_html;
921 HRESULT hr;
923 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
925 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
926 if(NS_FAILED(nsres))
928 ERR("GetDocument failed: %08x\n", nsres);
929 return E_FAIL;
932 nsres = nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void **)&nsdocrange);
933 nsIDOMDocument_Release(nsdoc);
934 if(NS_FAILED(nsres))
936 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres);
937 return E_FAIL;
939 nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
940 nsIDOMDocumentRange_Release(nsdocrange);
941 if(NS_FAILED(nsres))
943 ERR("CreateRange failed: %08x\n", nsres);
944 return E_FAIL;
947 nsIDOMRange_SetStartBefore(range, (nsIDOMNode *)This->nselem);
949 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
950 nsIDOMRange_Release(range);
951 if(NS_FAILED(nsres))
953 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
954 return E_FAIL;
957 nsAString_Init(&ns_html, html);
959 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
960 nsIDOMNSRange_Release(nsrange);
961 nsAString_Finish(&ns_html);
963 if(NS_FAILED(nsres) || !nsnode)
965 ERR("CreateTextNode failed: %08x\n", nsres);
966 return E_FAIL;
969 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
970 nsIDOMNode_Release(nsnode);
972 return hr;
975 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
976 BSTR text)
978 HTMLElement *This = HTMLELEM_THIS(iface);
979 nsresult nsres;
980 nsIDOMDocument *nsdoc;
981 nsIDOMNode *nsnode;
982 nsAString ns_text;
983 HRESULT hr;
985 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
987 nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
988 if(NS_FAILED(nsres) || !nsdoc)
990 ERR("GetDocument failed: %08x\n", nsres);
991 return E_FAIL;
994 nsAString_Init(&ns_text, text);
996 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &ns_text, (nsIDOMText **)&nsnode);
997 nsIDOMDocument_Release(nsdoc);
998 nsAString_Finish(&ns_text);
1000 if(NS_FAILED(nsres) || !nsnode)
1002 ERR("CreateTextNode failed: %08x\n", nsres);
1003 return E_FAIL;
1006 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1007 nsIDOMNode_Release(nsnode);
1009 return hr;
1012 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1014 HTMLElement *This = HTMLELEM_THIS(iface);
1015 FIXME("(%p)->(%p)\n", This, p);
1016 return E_NOTIMPL;
1019 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1021 HTMLElement *This = HTMLELEM_THIS(iface);
1022 FIXME("(%p)->(%p)\n", This, p);
1023 return E_NOTIMPL;
1026 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1028 HTMLElement *This = HTMLELEM_THIS(iface);
1029 FIXME("(%p)\n", This);
1030 return E_NOTIMPL;
1033 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1034 IHTMLFiltersCollection **p)
1036 HTMLElement *This = HTMLELEM_THIS(iface);
1037 FIXME("(%p)->(%p)\n", This, p);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1043 HTMLElement *This = HTMLELEM_THIS(iface);
1044 FIXME("(%p)->()\n", This);
1045 return E_NOTIMPL;
1048 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1050 HTMLElement *This = HTMLELEM_THIS(iface);
1051 FIXME("(%p)->(%p)\n", This, p);
1052 return E_NOTIMPL;
1055 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1057 HTMLElement *This = HTMLELEM_THIS(iface);
1058 FIXME("(%p)->(%p)\n", This, String);
1059 return E_NOTIMPL;
1062 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1064 HTMLElement *This = HTMLELEM_THIS(iface);
1065 FIXME("(%p)->()\n", This);
1066 return E_NOTIMPL;
1069 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1071 HTMLElement *This = HTMLELEM_THIS(iface);
1072 FIXME("(%p)->(%p)\n", This, p);
1073 return E_NOTIMPL;
1076 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1078 HTMLElement *This = HTMLELEM_THIS(iface);
1079 FIXME("(%p)->()\n", This);
1080 return E_NOTIMPL;
1083 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1085 HTMLElement *This = HTMLELEM_THIS(iface);
1086 FIXME("(%p)->(%p)\n", This, p);
1087 return E_NOTIMPL;
1090 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1092 HTMLElement *This = HTMLELEM_THIS(iface);
1093 FIXME("(%p)->()\n", This);
1094 return E_NOTIMPL;
1097 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1099 HTMLElement *This = HTMLELEM_THIS(iface);
1100 FIXME("(%p)->(%p)\n", This, p);
1101 return E_NOTIMPL;
1104 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1106 HTMLElement *This = HTMLELEM_THIS(iface);
1107 FIXME("(%p)->()\n", This);
1108 return E_NOTIMPL;
1111 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1113 HTMLElement *This = HTMLELEM_THIS(iface);
1114 FIXME("(%p)->(%p)\n", This, p);
1115 return E_NOTIMPL;
1118 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1120 HTMLElement *This = HTMLELEM_THIS(iface);
1121 FIXME("(%p)->()\n", This);
1122 return E_NOTIMPL;
1125 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1127 HTMLElement *This = HTMLELEM_THIS(iface);
1128 FIXME("(%p)->(%p)\n", This, p);
1129 return E_NOTIMPL;
1132 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1134 HTMLElement *This = HTMLELEM_THIS(iface);
1135 FIXME("(%p)->()\n", This);
1136 return E_NOTIMPL;
1139 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1141 HTMLElement *This = HTMLELEM_THIS(iface);
1142 FIXME("(%p)->(%p)\n", This, p);
1143 return E_NOTIMPL;
1146 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1148 HTMLElement *This = HTMLELEM_THIS(iface);
1149 FIXME("(%p)->()\n", This);
1150 return E_NOTIMPL;
1153 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1155 HTMLElement *This = HTMLELEM_THIS(iface);
1156 FIXME("(%p)->(%p)\n", This, p);
1157 return E_NOTIMPL;
1160 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1162 HTMLElement *This = HTMLELEM_THIS(iface);
1163 FIXME("(%p)->()\n", This);
1164 return E_NOTIMPL;
1167 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1169 HTMLElement *This = HTMLELEM_THIS(iface);
1170 FIXME("(%p)->(%p)\n", This, p);
1171 return E_NOTIMPL;
1174 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1176 HTMLElement *This = HTMLELEM_THIS(iface);
1177 FIXME("(%p)->()\n", This);
1178 return E_NOTIMPL;
1181 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1183 HTMLElement *This = HTMLELEM_THIS(iface);
1184 FIXME("(%p)->(%p)\n", This, p);
1185 return E_NOTIMPL;
1188 static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
1190 nsIDOMNodeList *nsnode_list;
1191 nsIDOMNode *iter;
1192 PRUint32 list_len = 0, i;
1193 nsresult nsres;
1195 nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
1196 if(NS_FAILED(nsres)) {
1197 ERR("GetChildNodes failed: %08x\n", nsres);
1198 return;
1201 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1202 if(!list_len)
1203 return;
1205 buf->size = list_len;
1206 buf->buf = heap_alloc(buf->size*sizeof(HTMLElement**));
1208 for(i=0; i<list_len; i++) {
1209 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1210 if(NS_FAILED(nsres)) {
1211 ERR("Item failed: %08x\n", nsres);
1212 continue;
1215 if(is_elem_node(iter))
1216 elem_vector_add(buf, HTMLELEM_NODE_THIS(get_node(doc, iter, TRUE)));
1220 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1222 HTMLElement *This = HTMLELEM_THIS(iface);
1223 elem_vector buf = {NULL, 0, 0};
1225 TRACE("(%p)->(%p)\n", This, p);
1227 create_child_list(This->node.doc, This, &buf);
1229 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1230 return S_OK;
1233 static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
1235 nsIDOMNodeList *nsnode_list;
1236 nsIDOMNode *iter;
1237 PRUint32 list_len = 0, i;
1238 nsresult nsres;
1240 nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
1241 if(NS_FAILED(nsres)) {
1242 ERR("GetChildNodes failed: %08x\n", nsres);
1243 return;
1246 nsIDOMNodeList_GetLength(nsnode_list, &list_len);
1247 if(!list_len)
1248 return;
1250 for(i=0; i<list_len; i++) {
1251 nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
1252 if(NS_FAILED(nsres)) {
1253 ERR("Item failed: %08x\n", nsres);
1254 continue;
1257 if(is_elem_node(iter)) {
1258 HTMLDOMNode *node = get_node(doc, iter, TRUE);
1260 elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
1261 create_all_list(doc, node, buf);
1266 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1268 HTMLElement *This = HTMLELEM_THIS(iface);
1269 elem_vector buf = {NULL, 0, 8};
1271 TRACE("(%p)->(%p)\n", This, p);
1273 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1275 create_all_list(This->node.doc, &This->node, &buf);
1276 elem_vector_normalize(&buf);
1278 *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
1279 return S_OK;
1282 #undef HTMLELEM_THIS
1284 static const IHTMLElementVtbl HTMLElementVtbl = {
1285 HTMLElement_QueryInterface,
1286 HTMLElement_AddRef,
1287 HTMLElement_Release,
1288 HTMLElement_GetTypeInfoCount,
1289 HTMLElement_GetTypeInfo,
1290 HTMLElement_GetIDsOfNames,
1291 HTMLElement_Invoke,
1292 HTMLElement_setAttribute,
1293 HTMLElement_getAttribute,
1294 HTMLElement_removeAttribute,
1295 HTMLElement_put_className,
1296 HTMLElement_get_className,
1297 HTMLElement_put_id,
1298 HTMLElement_get_id,
1299 HTMLElement_get_tagName,
1300 HTMLElement_get_parentElement,
1301 HTMLElement_get_style,
1302 HTMLElement_put_onhelp,
1303 HTMLElement_get_onhelp,
1304 HTMLElement_put_onclick,
1305 HTMLElement_get_onclick,
1306 HTMLElement_put_ondblclick,
1307 HTMLElement_get_ondblclick,
1308 HTMLElement_put_onkeydown,
1309 HTMLElement_get_onkeydown,
1310 HTMLElement_put_onkeyup,
1311 HTMLElement_get_onkeyup,
1312 HTMLElement_put_onkeypress,
1313 HTMLElement_get_onkeypress,
1314 HTMLElement_put_onmouseout,
1315 HTMLElement_get_onmouseout,
1316 HTMLElement_put_onmouseover,
1317 HTMLElement_get_onmouseover,
1318 HTMLElement_put_onmousemove,
1319 HTMLElement_get_onmousemove,
1320 HTMLElement_put_onmousedown,
1321 HTMLElement_get_onmousedown,
1322 HTMLElement_put_onmouseup,
1323 HTMLElement_get_onmouseup,
1324 HTMLElement_get_document,
1325 HTMLElement_put_title,
1326 HTMLElement_get_title,
1327 HTMLElement_put_language,
1328 HTMLElement_get_language,
1329 HTMLElement_put_onselectstart,
1330 HTMLElement_get_onselectstart,
1331 HTMLElement_scrollIntoView,
1332 HTMLElement_contains,
1333 HTMLElement_get_sourceIndex,
1334 HTMLElement_get_recordNumber,
1335 HTMLElement_put_lang,
1336 HTMLElement_get_lang,
1337 HTMLElement_get_offsetLeft,
1338 HTMLElement_get_offsetTop,
1339 HTMLElement_get_offsetWidth,
1340 HTMLElement_get_offsetHeight,
1341 HTMLElement_get_offsetParent,
1342 HTMLElement_put_innerHTML,
1343 HTMLElement_get_innerHTML,
1344 HTMLElement_put_innerText,
1345 HTMLElement_get_innerText,
1346 HTMLElement_put_outerHTML,
1347 HTMLElement_get_outerHTML,
1348 HTMLElement_put_outerText,
1349 HTMLElement_get_outerText,
1350 HTMLElement_insertAdjacentHTML,
1351 HTMLElement_insertAdjacentText,
1352 HTMLElement_get_parentTextEdit,
1353 HTMLElement_get_isTextEdit,
1354 HTMLElement_click,
1355 HTMLElement_get_filters,
1356 HTMLElement_put_ondragstart,
1357 HTMLElement_get_ondragstart,
1358 HTMLElement_toString,
1359 HTMLElement_put_onbeforeupdate,
1360 HTMLElement_get_onbeforeupdate,
1361 HTMLElement_put_onafterupdate,
1362 HTMLElement_get_onafterupdate,
1363 HTMLElement_put_onerrorupdate,
1364 HTMLElement_get_onerrorupdate,
1365 HTMLElement_put_onrowexit,
1366 HTMLElement_get_onrowexit,
1367 HTMLElement_put_onrowenter,
1368 HTMLElement_get_onrowenter,
1369 HTMLElement_put_ondatasetchanged,
1370 HTMLElement_get_ondatasetchanged,
1371 HTMLElement_put_ondataavailable,
1372 HTMLElement_get_ondataavailable,
1373 HTMLElement_put_ondatasetcomplete,
1374 HTMLElement_get_ondatasetcomplete,
1375 HTMLElement_put_onfilterchange,
1376 HTMLElement_get_onfilterchange,
1377 HTMLElement_get_children,
1378 HTMLElement_get_all
1381 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1383 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1385 *ppv = NULL;
1387 if(IsEqualGUID(&IID_IUnknown, riid)) {
1388 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1389 *ppv = HTMLELEM(This);
1390 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1391 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1392 *ppv = HTMLELEM(This);
1393 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1394 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1395 *ppv = HTMLELEM(This);
1396 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1397 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1398 *ppv = HTMLELEM2(This);
1399 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1400 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1401 *ppv = CONPTCONT(&This->cp_container);
1404 if(*ppv) {
1405 IHTMLElement_AddRef(HTMLELEM(This));
1406 return S_OK;
1409 return HTMLDOMNode_QI(&This->node, riid, ppv);
1412 void HTMLElement_destructor(HTMLDOMNode *iface)
1414 HTMLElement *This = HTMLELEM_NODE_THIS(iface);
1416 ConnectionPointContainer_Destroy(&This->cp_container);
1418 if(This->nselem)
1419 nsIDOMHTMLElement_Release(This->nselem);
1421 HTMLDOMNode_destructor(&This->node);
1424 static const NodeImplVtbl HTMLElementImplVtbl = {
1425 HTMLElement_QI,
1426 HTMLElement_destructor
1429 static const tid_t HTMLElement_iface_tids[] = {
1430 IHTMLDOMNode_tid,
1431 IHTMLDOMNode2_tid,
1432 IHTMLElement_tid,
1433 IHTMLElement2_tid,
1437 static dispex_static_data_t HTMLElement_dispex = {
1438 NULL,
1439 DispHTMLUnknownElement_tid,
1440 NULL,
1441 HTMLElement_iface_tids
1444 void HTMLElement_Init(HTMLElement *This)
1446 This->lpHTMLElementVtbl = &HTMLElementVtbl;
1448 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)HTMLELEM(This));
1450 HTMLElement2_Init(This);
1452 if(!This->node.dispex.data)
1453 init_dispex(&This->node.dispex, (IUnknown*)HTMLELEM(This), &HTMLElement_dispex);
1456 HTMLElement *HTMLElement_Create(HTMLDocument *doc, nsIDOMNode *nsnode, BOOL use_generic)
1458 nsIDOMHTMLElement *nselem;
1459 HTMLElement *ret = NULL;
1460 nsAString class_name_str;
1461 const PRUnichar *class_name;
1462 nsresult nsres;
1464 static const WCHAR wszA[] = {'A',0};
1465 static const WCHAR wszBODY[] = {'B','O','D','Y',0};
1466 static const WCHAR wszIMG[] = {'I','M','G',0};
1467 static const WCHAR wszINPUT[] = {'I','N','P','U','T',0};
1468 static const WCHAR wszOPTION[] = {'O','P','T','I','O','N',0};
1469 static const WCHAR wszSCRIPT[] = {'S','C','R','I','P','T',0};
1470 static const WCHAR wszSELECT[] = {'S','E','L','E','C','T',0};
1471 static const WCHAR wszTABLE[] = {'T','A','B','L','E',0};
1472 static const WCHAR wszTEXTAREA[] = {'T','E','X','T','A','R','E','A',0};
1474 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1475 if(NS_FAILED(nsres))
1476 return NULL;
1478 nsAString_Init(&class_name_str, NULL);
1479 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1481 nsAString_GetData(&class_name_str, &class_name);
1483 if(!strcmpW(class_name, wszA))
1484 ret = HTMLAnchorElement_Create(nselem);
1485 else if(!strcmpW(class_name, wszBODY))
1486 ret = HTMLBodyElement_Create(nselem);
1487 else if(!strcmpW(class_name, wszIMG))
1488 ret = HTMLImgElement_Create(nselem);
1489 else if(!strcmpW(class_name, wszINPUT))
1490 ret = HTMLInputElement_Create(nselem);
1491 else if(!strcmpW(class_name, wszOPTION))
1492 ret = HTMLOptionElement_Create(nselem);
1493 else if(!strcmpW(class_name, wszSCRIPT))
1494 ret = HTMLScriptElement_Create(nselem);
1495 else if(!strcmpW(class_name, wszSELECT))
1496 ret = HTMLSelectElement_Create(nselem);
1497 else if(!strcmpW(class_name, wszTABLE))
1498 ret = HTMLTable_Create(nselem);
1499 else if(!strcmpW(class_name, wszTEXTAREA))
1500 ret = HTMLTextAreaElement_Create(nselem);
1501 else if(use_generic)
1502 ret = HTMLGenericElement_Create(nselem);
1504 if(!ret) {
1505 ret = heap_alloc_zero(sizeof(HTMLElement));
1506 HTMLElement_Init(ret);
1507 ret->node.vtbl = &HTMLElementImplVtbl;
1510 TRACE("%s ret %p\n", debugstr_w(class_name), ret);
1512 nsAString_Finish(&class_name_str);
1514 ret->nselem = nselem;
1515 HTMLDOMNode_Init(doc, &ret->node, (nsIDOMNode*)nselem);
1517 return ret;
1520 typedef struct {
1521 DispatchEx dispex;
1522 const IHTMLElementCollectionVtbl *lpHTMLElementCollectionVtbl;
1524 IUnknown *ref_unk;
1525 HTMLElement **elems;
1526 DWORD len;
1528 LONG ref;
1529 } HTMLElementCollection;
1531 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1533 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1535 static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
1536 REFIID riid, void **ppv)
1538 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1540 *ppv = NULL;
1542 if(IsEqualGUID(&IID_IUnknown, riid)) {
1543 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1544 *ppv = HTMLELEMCOL(This);
1545 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1546 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1547 *ppv = HTMLELEMCOL(This);
1548 }else if(IsEqualGUID(&IID_IDispatchEx, riid)) {
1549 TRACE("(%p)->(IID_IDispatchEx %p)\n", This, ppv);
1550 *ppv = DISPATCHEX(&This->dispex);
1551 }else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
1552 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This, ppv);
1553 *ppv = HTMLELEMCOL(This);
1556 if(*ppv) {
1557 IHTMLElementCollection_AddRef(HTMLELEMCOL(This));
1558 return S_OK;
1561 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1562 return E_NOINTERFACE;
1565 static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
1567 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1568 LONG ref = InterlockedIncrement(&This->ref);
1570 TRACE("(%p) ref=%d\n", This, ref);
1572 return ref;
1575 static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
1577 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1578 LONG ref = InterlockedDecrement(&This->ref);
1580 TRACE("(%p) ref=%d\n", This, ref);
1582 if(!ref) {
1583 IUnknown_Release(This->ref_unk);
1584 heap_free(This->elems);
1585 heap_free(This);
1588 return ref;
1591 static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
1592 UINT *pctinfo)
1594 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1595 FIXME("(%p)->(%p)\n", This, pctinfo);
1596 return E_NOTIMPL;
1599 static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
1600 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1602 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1603 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1604 return E_NOTIMPL;
1607 static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
1608 REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
1610 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1611 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1612 lcid, rgDispId);
1613 return E_NOTIMPL;
1616 static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
1617 DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1618 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1620 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1621 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1622 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1623 return E_NOTIMPL;
1626 static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
1627 BSTR *String)
1629 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1630 FIXME("(%p)->(%p)\n", This, String);
1631 return E_NOTIMPL;
1634 static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
1635 long v)
1637 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1638 FIXME("(%p)->(%ld)\n", This, v);
1639 return E_NOTIMPL;
1642 static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
1643 long *p)
1645 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1647 TRACE("(%p)->(%p)\n", This, p);
1649 *p = This->len;
1650 return S_OK;
1653 static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
1654 IUnknown **p)
1656 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1657 FIXME("(%p)->(%p)\n", This, p);
1658 return E_NOTIMPL;
1661 static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
1663 const PRUnichar *str;
1664 nsAString nsstr, nsname;
1665 BOOL ret = FALSE;
1666 nsresult nsres;
1668 static const PRUnichar nameW[] = {'n','a','m','e',0};
1670 if(!elem->nselem)
1671 return FALSE;
1673 nsAString_Init(&nsstr, NULL);
1674 nsIDOMHTMLElement_GetId(elem->nselem, &nsstr);
1675 nsAString_GetData(&nsstr, &str);
1676 if(!strcmpiW(str, name)) {
1677 nsAString_Finish(&nsstr);
1678 return TRUE;
1681 nsAString_Init(&nsname, nameW);
1682 nsres = nsIDOMHTMLElement_GetAttribute(elem->nselem, &nsname, &nsstr);
1683 nsAString_Finish(&nsname);
1684 if(NS_SUCCEEDED(nsres)) {
1685 nsAString_GetData(&nsstr, &str);
1686 ret = !strcmpiW(str, name);
1689 nsAString_Finish(&nsstr);
1690 return ret;
1693 static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
1694 VARIANT name, VARIANT index, IDispatch **pdisp)
1696 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1698 TRACE("(%p)->(v(%d) v(%d) %p)\n", This, V_VT(&name), V_VT(&index), pdisp);
1700 *pdisp = NULL;
1702 if(V_VT(&name) == VT_I4) {
1703 TRACE("name is VT_I4: %d\n", V_I4(&name));
1705 if(V_I4(&name) < 0)
1706 return E_INVALIDARG;
1707 if(V_I4(&name) >= This->len)
1708 return S_OK;
1710 *pdisp = (IDispatch*)This->elems[V_I4(&name)];
1711 IDispatch_AddRef(*pdisp);
1712 TRACE("Returning pdisp=%p\n", pdisp);
1713 return S_OK;
1716 if(V_VT(&name) == VT_BSTR) {
1717 DWORD i;
1719 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name)));
1721 if(V_VT(&index) == VT_I4) {
1722 LONG idx = V_I4(&index);
1724 TRACE("index = %d\n", idx);
1726 if(idx < 0)
1727 return E_INVALIDARG;
1729 for(i=0; i<This->len; i++) {
1730 if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
1731 break;
1734 if(i != This->len) {
1735 *pdisp = (IDispatch*)HTMLELEM(This->elems[i]);
1736 IDispatch_AddRef(*pdisp);
1739 return S_OK;
1740 }else {
1741 elem_vector buf = {NULL, 0, 8};
1743 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1745 for(i=0; i<This->len; i++) {
1746 if(is_elem_name(This->elems[i], V_BSTR(&name)))
1747 elem_vector_add(&buf, This->elems[i]);
1750 if(buf.len > 1) {
1751 elem_vector_normalize(&buf);
1752 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1753 }else {
1754 if(buf.len == 1) {
1755 *pdisp = (IDispatch*)HTMLELEM(buf.buf[0]);
1756 IDispatch_AddRef(*pdisp);
1759 heap_free(buf.buf);
1762 return S_OK;
1766 FIXME("unsupported arguments\n");
1767 return E_INVALIDARG;
1770 static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
1771 VARIANT tagName, IDispatch **pdisp)
1773 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1774 DWORD i;
1775 nsAString tag_str;
1776 const PRUnichar *tag;
1777 elem_vector buf = {NULL, 0, 8};
1779 if(V_VT(&tagName) != VT_BSTR) {
1780 WARN("Invalid arg\n");
1781 return DISP_E_MEMBERNOTFOUND;
1784 TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
1786 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
1788 nsAString_Init(&tag_str, NULL);
1790 for(i=0; i<This->len; i++) {
1791 if(!This->elems[i]->nselem)
1792 continue;
1794 nsIDOMElement_GetTagName(This->elems[i]->nselem, &tag_str);
1795 nsAString_GetData(&tag_str, &tag);
1797 if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
1798 V_BSTR(&tagName), -1) == CSTR_EQUAL)
1799 elem_vector_add(&buf, This->elems[i]);
1802 nsAString_Finish(&tag_str);
1803 elem_vector_normalize(&buf);
1805 TRACE("fount %d tags\n", buf.len);
1807 *pdisp = (IDispatch*)HTMLElementCollection_Create(This->ref_unk, buf.buf, buf.len);
1808 return S_OK;
1811 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1813 static HRESULT HTMLElementCollection_get_dispid(IUnknown *iface, BSTR name, DWORD flags, DISPID *dispid)
1815 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1816 WCHAR *ptr;
1817 DWORD idx=0;
1819 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1820 idx = idx*10 + (*ptr-'0');
1822 if(*ptr || idx >= This->len)
1823 return DISP_E_UNKNOWNNAME;
1825 *dispid = DISPID_ELEMCOL_0 + idx;
1826 TRACE("ret %x\n", *dispid);
1827 return S_OK;
1830 static HRESULT HTMLElementCollection_invoke(IUnknown *iface, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1831 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1833 HTMLElementCollection *This = ELEMCOL_THIS(iface);
1834 DWORD idx;
1836 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
1838 idx = id - DISPID_ELEMCOL_0;
1839 if(idx >= This->len)
1840 return DISP_E_UNKNOWNNAME;
1842 switch(flags) {
1843 case INVOKE_PROPERTYGET:
1844 V_VT(res) = VT_DISPATCH;
1845 V_DISPATCH(res) = (IDispatch*)HTMLELEM(This->elems[idx]);
1846 IHTMLElement_AddRef(HTMLELEM(This->elems[idx]));
1847 break;
1848 default:
1849 FIXME("unimplemented flags %x\n", flags);
1850 return E_NOTIMPL;
1853 return S_OK;
1856 #undef ELEMCOL_THIS
1858 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
1859 HTMLElementCollection_QueryInterface,
1860 HTMLElementCollection_AddRef,
1861 HTMLElementCollection_Release,
1862 HTMLElementCollection_GetTypeInfoCount,
1863 HTMLElementCollection_GetTypeInfo,
1864 HTMLElementCollection_GetIDsOfNames,
1865 HTMLElementCollection_Invoke,
1866 HTMLElementCollection_toString,
1867 HTMLElementCollection_put_length,
1868 HTMLElementCollection_get_length,
1869 HTMLElementCollection_get__newEnum,
1870 HTMLElementCollection_item,
1871 HTMLElementCollection_tags
1874 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
1875 HTMLElementCollection_get_dispid,
1876 HTMLElementCollection_invoke
1879 static const tid_t HTMLElementCollection_iface_tids[] = {
1880 IHTMLElementCollection_tid,
1883 static dispex_static_data_t HTMLElementCollection_dispex = {
1884 &HTMLElementColection_dispex_vtbl,
1885 DispHTMLElementCollection_tid,
1886 NULL,
1887 HTMLElementCollection_iface_tids
1890 IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
1892 elem_vector buf = {NULL, 0, 8};
1894 buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
1896 elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
1897 create_all_list(node->doc, node, &buf);
1898 elem_vector_normalize(&buf);
1900 return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
1903 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
1904 HTMLElement **elems, DWORD len)
1906 HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
1908 ret->lpHTMLElementCollectionVtbl = &HTMLElementCollectionVtbl;
1909 ret->ref = 1;
1910 ret->elems = elems;
1911 ret->len = len;
1913 init_dispex(&ret->dispex, (IUnknown*)HTMLELEMCOL(ret), &HTMLElementCollection_dispex);
1915 IUnknown_AddRef(ref_unk);
1916 ret->ref_unk = ref_unk;
1918 TRACE("ret=%p len=%d\n", ret, len);
1920 return HTMLELEMCOL(ret);