comctl32/tests: Make impl_from_IStream() static.
[wine/multimedia.git] / dlls / mshtml / htmlelem.c
blob9d9fc8d957afe599b43def5908c39157b1b12d3a
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"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35 #include "htmlstyle.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR aW[] = {'A',0};
40 static const WCHAR bodyW[] = {'B','O','D','Y',0};
41 static const WCHAR embedW[] = {'E','M','B','E','D',0};
42 static const WCHAR formW[] = {'F','O','R','M',0};
43 static const WCHAR frameW[] = {'F','R','A','M','E',0};
44 static const WCHAR headW[] = {'H','E','A','D',0};
45 static const WCHAR iframeW[] = {'I','F','R','A','M','E',0};
46 static const WCHAR imgW[] = {'I','M','G',0};
47 static const WCHAR inputW[] = {'I','N','P','U','T',0};
48 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
49 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
50 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
51 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
52 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
53 static const WCHAR tableW[] = {'T','A','B','L','E',0};
54 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
55 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
56 static const WCHAR trW[] = {'T','R',0};
58 typedef struct {
59 const WCHAR *name;
60 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
61 } tag_desc_t;
63 static const tag_desc_t tag_descs[] = {
64 {aW, HTMLAnchorElement_Create},
65 {bodyW, HTMLBodyElement_Create},
66 {embedW, HTMLEmbedElement_Create},
67 {formW, HTMLFormElement_Create},
68 {frameW, HTMLFrameElement_Create},
69 {headW, HTMLHeadElement_Create},
70 {iframeW, HTMLIFrame_Create},
71 {imgW, HTMLImgElement_Create},
72 {inputW, HTMLInputElement_Create},
73 {objectW, HTMLObjectElement_Create},
74 {optionW, HTMLOptionElement_Create},
75 {scriptW, HTMLScriptElement_Create},
76 {selectW, HTMLSelectElement_Create},
77 {styleW, HTMLStyleElement_Create},
78 {tableW, HTMLTable_Create},
79 {textareaW, HTMLTextAreaElement_Create},
80 {title_tagW, HTMLTitleElement_Create},
81 {trW, HTMLTableRow_Create}
84 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
86 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
87 int r;
89 while(min <= max) {
90 i = (min+max)/2;
91 r = strcmpW(tag_name, tag_descs[i].name);
92 if(!r)
93 return tag_descs+i;
95 if(r < 0)
96 max = i-1;
97 else
98 min = i+1;
101 return NULL;
104 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
106 nsIDOMDocumentFragment *nsfragment;
107 nsIDOMNSRange *nsrange;
108 nsIDOMNode *nsparent;
109 nsIDOMRange *range;
110 nsAString html_str;
111 nsresult nsres;
112 HRESULT hres = S_OK;
114 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
115 if(NS_FAILED(nsres)) {
116 ERR("CreateRange failed: %08x\n", nsres);
117 return E_FAIL;
120 nsres = nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void**)&nsrange);
121 nsIDOMRange_Release(range);
122 if(NS_FAILED(nsres)) {
123 ERR("Could not get nsIDOMNSRange: %08x\n", nsres);
124 return E_FAIL;
127 nsAString_InitDepend(&html_str, html);
128 nsIDOMNSRange_CreateContextualFragment(nsrange, &html_str, &nsfragment);
129 nsIDOMNSRange_Release(nsrange);
130 nsAString_Finish(&html_str);
131 if(NS_FAILED(nsres)) {
132 ERR("CreateContextualFragment failed: %08x\n", nsres);
133 return E_FAIL;
136 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
137 if(NS_SUCCEEDED(nsres) && nsparent) {
138 nsIDOMNode *nstmp;
140 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
141 nsIDOMNode_Release(nsparent);
142 if(NS_FAILED(nsres)) {
143 ERR("ReplaceChild failed: %08x\n", nsres);
144 hres = E_FAIL;
145 }else if(nstmp) {
146 nsIDOMNode_Release(nstmp);
148 }else {
149 ERR("GetParentNode failed: %08x\n", nsres);
150 hres = E_FAIL;
153 nsIDOMDocumentFragment_Release(nsfragment);
154 return hres;
157 typedef struct
159 DispatchEx dispex;
160 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
162 LONG ref;
163 } HTMLFiltersCollection;
165 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
167 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
170 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
172 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
174 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
177 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
179 nsIDOMElement *nselem;
180 nsAString tag_str;
181 nsresult nsres;
183 if(!doc->nsdoc) {
184 WARN("NULL nsdoc\n");
185 return E_UNEXPECTED;
188 nsAString_InitDepend(&tag_str, tag);
189 nsres = nsIDOMDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
190 nsAString_Finish(&tag_str);
191 if(NS_FAILED(nsres)) {
192 ERR("CreateElement failed: %08x\n", nsres);
193 return E_FAIL;
196 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
197 nsIDOMElement_Release(nselem);
198 if(NS_FAILED(nsres)) {
199 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
200 return E_FAIL;
203 return S_OK;
206 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
207 REFIID riid, void **ppv)
209 HTMLElement *This = impl_from_IHTMLElement(iface);
211 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
214 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
216 HTMLElement *This = impl_from_IHTMLElement(iface);
218 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
221 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
223 HTMLElement *This = impl_from_IHTMLElement(iface);
225 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
228 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
230 HTMLElement *This = impl_from_IHTMLElement(iface);
231 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
234 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
235 LCID lcid, ITypeInfo **ppTInfo)
237 HTMLElement *This = impl_from_IHTMLElement(iface);
238 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
241 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
242 LPOLESTR *rgszNames, UINT cNames,
243 LCID lcid, DISPID *rgDispId)
245 HTMLElement *This = impl_from_IHTMLElement(iface);
246 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
247 lcid, rgDispId);
250 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
251 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
252 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
254 HTMLElement *This = impl_from_IHTMLElement(iface);
255 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
256 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
259 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
260 VARIANT AttributeValue, LONG lFlags)
262 HTMLElement *This = impl_from_IHTMLElement(iface);
263 HRESULT hres;
264 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
265 DISPPARAMS dispParams;
266 EXCEPINFO excep;
268 TRACE("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
270 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
271 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
272 if(FAILED(hres))
273 return hres;
275 dispParams.cArgs = 1;
276 dispParams.cNamedArgs = 1;
277 dispParams.rgdispidNamedArgs = &dispidNamed;
278 dispParams.rgvarg = &AttributeValue;
280 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
281 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
282 return hres;
285 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
286 LONG lFlags, VARIANT *AttributeValue)
288 HTMLElement *This = impl_from_IHTMLElement(iface);
289 DISPID dispid;
290 HRESULT hres;
291 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
292 EXCEPINFO excep;
294 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
296 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
297 fdexNameCaseInsensitive, &dispid);
298 if(hres == DISP_E_UNKNOWNNAME) {
299 V_VT(AttributeValue) = VT_NULL;
300 return S_OK;
303 if(FAILED(hres)) {
304 V_VT(AttributeValue) = VT_NULL;
305 return hres;
308 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
309 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
311 return hres;
314 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
315 LONG lFlags, VARIANT_BOOL *pfSuccess)
317 HTMLElement *This = impl_from_IHTMLElement(iface);
319 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
321 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
324 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
326 HTMLElement *This = impl_from_IHTMLElement(iface);
327 nsAString classname_str;
328 nsresult nsres;
330 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
332 if(!This->nselem) {
333 FIXME("NULL nselem\n");
334 return E_NOTIMPL;
337 nsAString_InitDepend(&classname_str, v);
338 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
339 nsAString_Finish(&classname_str);
340 if(NS_FAILED(nsres))
341 ERR("SetClassName failed: %08x\n", nsres);
343 return S_OK;
346 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
348 HTMLElement *This = impl_from_IHTMLElement(iface);
349 nsAString class_str;
350 nsresult nsres;
351 HRESULT hres = S_OK;
353 TRACE("(%p)->(%p)\n", This, p);
355 if(!This->nselem) {
356 FIXME("NULL nselem\n");
357 return E_NOTIMPL;
360 nsAString_Init(&class_str, NULL);
361 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
363 if(NS_SUCCEEDED(nsres)) {
364 const PRUnichar *class;
365 nsAString_GetData(&class_str, &class);
366 *p = *class ? SysAllocString(class) : NULL;
367 }else {
368 ERR("GetClassName failed: %08x\n", nsres);
369 hres = E_FAIL;
372 nsAString_Finish(&class_str);
374 TRACE("className=%s\n", debugstr_w(*p));
375 return hres;
378 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
380 HTMLElement *This = impl_from_IHTMLElement(iface);
381 nsAString id_str;
382 nsresult nsres;
384 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
386 if(!This->nselem) {
387 FIXME("nselem == NULL\n");
388 return S_OK;
391 nsAString_InitDepend(&id_str, v);
392 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
393 nsAString_Finish(&id_str);
394 if(NS_FAILED(nsres))
395 ERR("SetId failed: %08x\n", nsres);
397 return S_OK;
400 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
402 HTMLElement *This = impl_from_IHTMLElement(iface);
403 const PRUnichar *id;
404 nsAString id_str;
405 nsresult nsres;
407 TRACE("(%p)->(%p)\n", This, p);
409 *p = NULL;
411 if(!This->nselem)
412 return S_OK;
414 nsAString_Init(&id_str, NULL);
415 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
416 nsAString_GetData(&id_str, &id);
418 if(NS_FAILED(nsres))
419 ERR("GetId failed: %08x\n", nsres);
420 else if(*id)
421 *p = SysAllocString(id);
423 nsAString_Finish(&id_str);
424 return S_OK;
427 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
429 HTMLElement *This = impl_from_IHTMLElement(iface);
430 const PRUnichar *tag;
431 nsAString tag_str;
432 nsresult nsres;
434 TRACE("(%p)->(%p)\n", This, p);
436 if(!This->nselem) {
437 static const WCHAR comment_tagW[] = {'!',0};
439 WARN("NULL nselem, assuming comment\n");
441 *p = SysAllocString(comment_tagW);
442 return S_OK;
445 nsAString_Init(&tag_str, NULL);
446 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
447 if(NS_SUCCEEDED(nsres)) {
448 nsAString_GetData(&tag_str, &tag);
449 *p = SysAllocString(tag);
450 }else {
451 ERR("GetTagName failed: %08x\n", nsres);
452 *p = NULL;
454 nsAString_Finish(&tag_str);
456 return S_OK;
459 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
461 HTMLElement *This = impl_from_IHTMLElement(iface);
462 IHTMLDOMNode *node;
463 HRESULT hres;
465 TRACE("(%p)->(%p)\n", This, p);
467 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
468 if(FAILED(hres))
469 return hres;
471 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
472 IHTMLDOMNode_Release(node);
473 if(FAILED(hres))
474 *p = NULL;
476 return S_OK;
479 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
481 HTMLElement *This = impl_from_IHTMLElement(iface);
483 TRACE("(%p)->(%p)\n", This, p);
485 if(!This->style) {
486 nsIDOMElementCSSInlineStyle *nselemstyle;
487 nsIDOMCSSStyleDeclaration *nsstyle;
488 nsresult nsres;
489 HRESULT hres;
491 if(!This->nselem) {
492 FIXME("NULL nselem\n");
493 return E_NOTIMPL;
496 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
497 (void**)&nselemstyle);
498 if(NS_FAILED(nsres)) {
499 ERR("Could not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
500 return E_FAIL;
503 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
504 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
505 if(NS_FAILED(nsres)) {
506 ERR("GetStyle failed: %08x\n", nsres);
507 return E_FAIL;
510 hres = HTMLStyle_Create(nsstyle, &This->style);
511 nsIDOMCSSStyleDeclaration_Release(nsstyle);
512 if(FAILED(hres))
513 return hres;
516 *p = &This->style->IHTMLStyle_iface;
517 IHTMLStyle_AddRef(*p);
518 return S_OK;
521 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
523 HTMLElement *This = impl_from_IHTMLElement(iface);
524 FIXME("(%p)->()\n", This);
525 return E_NOTIMPL;
528 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
530 HTMLElement *This = impl_from_IHTMLElement(iface);
531 FIXME("(%p)->(%p)\n", This, p);
532 return E_NOTIMPL;
535 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
537 HTMLElement *This = impl_from_IHTMLElement(iface);
539 TRACE("(%p)->()\n", This);
541 return set_node_event(&This->node, EVENTID_CLICK, &v);
544 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
546 HTMLElement *This = impl_from_IHTMLElement(iface);
548 TRACE("(%p)->(%p)\n", This, p);
550 return get_node_event(&This->node, EVENTID_CLICK, p);
553 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
555 HTMLElement *This = impl_from_IHTMLElement(iface);
557 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
559 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
562 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
564 HTMLElement *This = impl_from_IHTMLElement(iface);
566 TRACE("(%p)->(%p)\n", This, p);
568 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
571 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
573 HTMLElement *This = impl_from_IHTMLElement(iface);
575 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
577 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
580 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
582 HTMLElement *This = impl_from_IHTMLElement(iface);
584 TRACE("(%p)->(%p)\n", This, p);
586 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
589 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
591 HTMLElement *This = impl_from_IHTMLElement(iface);
593 TRACE("(%p)->()\n", This);
595 return set_node_event(&This->node, EVENTID_KEYUP, &v);
598 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
600 HTMLElement *This = impl_from_IHTMLElement(iface);
601 FIXME("(%p)->(%p)\n", This, p);
602 return E_NOTIMPL;
605 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
607 HTMLElement *This = impl_from_IHTMLElement(iface);
608 FIXME("(%p)->()\n", This);
609 return E_NOTIMPL;
612 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
614 HTMLElement *This = impl_from_IHTMLElement(iface);
615 FIXME("(%p)->(%p)\n", This, p);
616 return E_NOTIMPL;
619 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
621 HTMLElement *This = impl_from_IHTMLElement(iface);
623 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
625 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
628 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
630 HTMLElement *This = impl_from_IHTMLElement(iface);
632 TRACE("(%p)->(%p)\n", This, p);
634 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
637 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
639 HTMLElement *This = impl_from_IHTMLElement(iface);
641 TRACE("(%p)->()\n", This);
643 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
646 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
648 HTMLElement *This = impl_from_IHTMLElement(iface);
650 TRACE("(%p)->(%p)\n", This, p);
652 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
655 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
657 HTMLElement *This = impl_from_IHTMLElement(iface);
659 TRACE("(%p)->()\n", This);
661 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
664 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
666 HTMLElement *This = impl_from_IHTMLElement(iface);
668 TRACE("(%p)->(%p)\n", This, p);
670 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
673 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
675 HTMLElement *This = impl_from_IHTMLElement(iface);
677 TRACE("(%p)->()\n", This);
679 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
682 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
684 HTMLElement *This = impl_from_IHTMLElement(iface);
686 TRACE("(%p)->(%p)\n", This, p);
688 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
691 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
693 HTMLElement *This = impl_from_IHTMLElement(iface);
695 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
697 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
700 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
702 HTMLElement *This = impl_from_IHTMLElement(iface);
704 TRACE("(%p)->(%p)\n", This, p);
706 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
709 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
711 HTMLElement *This = impl_from_IHTMLElement(iface);
713 TRACE("(%p)->(%p)\n", This, p);
715 if(!p)
716 return E_POINTER;
718 if(This->node.vtbl->get_document)
719 return This->node.vtbl->get_document(&This->node, p);
721 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
722 IDispatch_AddRef(*p);
723 return S_OK;
726 static const WCHAR titleW[] = {'t','i','t','l','e',0};
728 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
730 HTMLElement *This = impl_from_IHTMLElement(iface);
731 nsAString title_str;
732 nsresult nsres;
734 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
736 if(!This->nselem) {
737 VARIANT *var;
738 HRESULT hres;
740 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
741 if(FAILED(hres))
742 return hres;
744 VariantClear(var);
745 V_VT(var) = VT_BSTR;
746 V_BSTR(var) = v ? SysAllocString(v) : NULL;
747 return S_OK;
750 nsAString_InitDepend(&title_str, v);
751 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
752 nsAString_Finish(&title_str);
753 if(NS_FAILED(nsres))
754 ERR("SetTitle failed: %08x\n", nsres);
756 return S_OK;
759 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
761 HTMLElement *This = impl_from_IHTMLElement(iface);
762 nsAString title_str;
763 nsresult nsres;
765 TRACE("(%p)->(%p)\n", This, p);
767 if(!This->nselem) {
768 VARIANT *var;
769 HRESULT hres;
771 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
772 if(hres == DISP_E_UNKNOWNNAME) {
773 *p = NULL;
774 }else if(V_VT(var) != VT_BSTR) {
775 FIXME("title = %s\n", debugstr_variant(var));
776 return E_FAIL;
777 }else {
778 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
781 return S_OK;
784 nsAString_Init(&title_str, NULL);
785 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
786 if(NS_SUCCEEDED(nsres)) {
787 const PRUnichar *title;
789 nsAString_GetData(&title_str, &title);
790 *p = *title ? SysAllocString(title) : NULL;
791 }else {
792 ERR("GetTitle failed: %08x\n", nsres);
793 return E_FAIL;
796 return S_OK;
799 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
801 HTMLElement *This = impl_from_IHTMLElement(iface);
802 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
803 return E_NOTIMPL;
806 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
808 HTMLElement *This = impl_from_IHTMLElement(iface);
809 FIXME("(%p)->(%p)\n", This, p);
810 return E_NOTIMPL;
813 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
815 HTMLElement *This = impl_from_IHTMLElement(iface);
817 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
819 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
822 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
824 HTMLElement *This = impl_from_IHTMLElement(iface);
826 TRACE("(%p)->(%p)\n", This, p);
828 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
831 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
833 HTMLElement *This = impl_from_IHTMLElement(iface);
834 FIXME("(%p)->()\n", This);
835 return E_NOTIMPL;
838 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
839 VARIANT_BOOL *pfResult)
841 HTMLElement *This = impl_from_IHTMLElement(iface);
842 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
843 return E_NOTIMPL;
846 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
848 HTMLElement *This = impl_from_IHTMLElement(iface);
849 FIXME("(%p)->(%p)\n", This, p);
850 return E_NOTIMPL;
853 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
855 HTMLElement *This = impl_from_IHTMLElement(iface);
856 FIXME("(%p)->(%p)\n", This, p);
857 return E_NOTIMPL;
860 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
862 HTMLElement *This = impl_from_IHTMLElement(iface);
863 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
864 return E_NOTIMPL;
867 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
869 HTMLElement *This = impl_from_IHTMLElement(iface);
870 FIXME("(%p)->(%p)\n", This, p);
871 return E_NOTIMPL;
874 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
876 HTMLElement *This = impl_from_IHTMLElement(iface);
877 nsIDOMNSHTMLElement *nselem;
878 PRInt32 off_left = 0;
879 nsresult nsres;
881 TRACE("(%p)->(%p)\n", This, p);
883 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
884 if(NS_FAILED(nsres)) {
885 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
886 return E_FAIL;
889 nsres = nsIDOMNSHTMLElement_GetOffsetLeft(nselem, &off_left);
890 nsIDOMNSHTMLElement_Release(nselem);
891 if(NS_FAILED(nsres)) {
892 ERR("GetOffsetLeft failed: %08x\n", nsres);
893 return E_FAIL;
896 *p = off_left;
897 return S_OK;
900 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
902 HTMLElement *This = impl_from_IHTMLElement(iface);
903 nsIDOMNSHTMLElement *nselem;
904 PRInt32 top = 0;
905 nsresult nsres;
907 TRACE("(%p)->(%p)\n", This, p);
909 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
910 if(NS_FAILED(nsres)) {
911 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
912 return E_FAIL;
915 nsres = nsIDOMNSHTMLElement_GetOffsetTop(nselem, &top);
916 nsIDOMNSHTMLElement_Release(nselem);
917 if(NS_FAILED(nsres)) {
918 ERR("GetOffsetTop failed: %08x\n", nsres);
919 return E_FAIL;
922 *p = top;
923 return S_OK;
926 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
928 HTMLElement *This = impl_from_IHTMLElement(iface);
929 nsIDOMNSHTMLElement *nselem;
930 PRInt32 offset = 0;
931 nsresult nsres;
933 TRACE("(%p)->(%p)\n", This, p);
935 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
936 if(NS_FAILED(nsres)) {
937 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
938 return E_FAIL;
941 nsres = nsIDOMNSHTMLElement_GetOffsetWidth(nselem, &offset);
942 nsIDOMNSHTMLElement_Release(nselem);
943 if(NS_FAILED(nsres)) {
944 ERR("GetOffsetWidth failed: %08x\n", nsres);
945 return E_FAIL;
948 *p = offset;
949 return S_OK;
952 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
954 HTMLElement *This = impl_from_IHTMLElement(iface);
955 nsIDOMNSHTMLElement *nselem;
956 PRInt32 offset = 0;
957 nsresult nsres;
959 TRACE("(%p)->(%p)\n", This, p);
961 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
962 if(NS_FAILED(nsres)) {
963 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
964 return E_FAIL;
967 nsres = nsIDOMNSHTMLElement_GetOffsetHeight(nselem, &offset);
968 nsIDOMNSHTMLElement_Release(nselem);
969 if(NS_FAILED(nsres)) {
970 ERR("GetOffsetHeight failed: %08x\n", nsres);
971 return E_FAIL;
974 *p = offset;
975 return S_OK;
978 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
980 HTMLElement *This = impl_from_IHTMLElement(iface);
981 nsIDOMNSHTMLElement *nselem;
982 nsIDOMElement *nsparent;
983 nsresult nsres;
984 HRESULT hres;
986 TRACE("(%p)->(%p)\n", This, p);
988 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
989 if(NS_FAILED(nsres)) {
990 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
991 return E_FAIL;
994 nsres = nsIDOMNSHTMLElement_GetOffsetParent(nselem, &nsparent);
995 nsIDOMNSHTMLElement_Release(nselem);
996 if(NS_FAILED(nsres)) {
997 ERR("GetOffsetParent failed: %08x\n", nsres);
998 return E_FAIL;
1001 if(nsparent) {
1002 HTMLDOMNode *node;
1004 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
1005 nsIDOMElement_Release(nsparent);
1006 if(FAILED(hres))
1007 return hres;
1009 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
1010 }else {
1011 *p = NULL;
1012 hres = S_OK;
1015 return hres;
1018 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
1020 HTMLElement *This = impl_from_IHTMLElement(iface);
1021 nsIDOMNSHTMLElement *nselem;
1022 nsAString html_str;
1023 nsresult nsres;
1025 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1027 if(!This->nselem) {
1028 FIXME("NULL nselem\n");
1029 return E_NOTIMPL;
1032 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
1033 if(NS_FAILED(nsres)) {
1034 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
1035 return E_FAIL;
1038 nsAString_InitDepend(&html_str, v);
1039 nsres = nsIDOMNSHTMLElement_SetInnerHTML(nselem, &html_str);
1040 nsAString_Finish(&html_str);
1042 if(NS_FAILED(nsres)) {
1043 FIXME("SetInnerHtml failed %08x\n", nsres);
1044 return E_FAIL;
1047 return S_OK;
1050 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1052 HTMLElement *This = impl_from_IHTMLElement(iface);
1053 nsIDOMNSHTMLElement *nselem;
1054 nsAString html_str;
1055 nsresult nsres;
1057 TRACE("(%p)->(%p)\n", This, p);
1059 if(!This->nselem) {
1060 FIXME("NULL nselem\n");
1061 return E_NOTIMPL;
1064 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMNSHTMLElement, (void**)&nselem);
1065 if(NS_FAILED(nsres)) {
1066 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres);
1067 return E_FAIL;
1070 nsAString_Init(&html_str, NULL);
1071 nsres = nsIDOMNSHTMLElement_GetInnerHTML(nselem, &html_str);
1072 if(NS_SUCCEEDED(nsres)) {
1073 const PRUnichar *html;
1075 nsAString_GetData(&html_str, &html);
1076 *p = *html ? SysAllocString(html) : NULL;
1077 }else {
1078 FIXME("SetInnerHtml failed %08x\n", nsres);
1079 *p = NULL;
1082 nsAString_Finish(&html_str);
1083 return S_OK;
1086 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1088 HTMLElement *This = impl_from_IHTMLElement(iface);
1089 nsIDOMNode *nschild, *tmp;
1090 nsIDOMText *text_node;
1091 nsAString text_str;
1092 nsresult nsres;
1094 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1096 while(1) {
1097 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1098 if(NS_FAILED(nsres)) {
1099 ERR("GetLastChild failed: %08x\n", nsres);
1100 return E_FAIL;
1102 if(!nschild)
1103 break;
1105 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1106 nsIDOMNode_Release(nschild);
1107 if(NS_FAILED(nsres)) {
1108 ERR("RemoveChild failed: %08x\n", nsres);
1109 return E_FAIL;
1111 nsIDOMNode_Release(tmp);
1114 nsAString_InitDepend(&text_str, v);
1115 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1116 nsAString_Finish(&text_str);
1117 if(NS_FAILED(nsres)) {
1118 ERR("CreateTextNode failed: %08x\n", nsres);
1119 return E_FAIL;
1122 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1123 if(NS_FAILED(nsres)) {
1124 ERR("AppendChild failed: %08x\n", nsres);
1125 return E_FAIL;
1128 nsIDOMNode_Release(tmp);
1129 return S_OK;
1132 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1134 HTMLElement *This = impl_from_IHTMLElement(iface);
1136 TRACE("(%p)->(%p)\n", This, p);
1138 return get_node_text(&This->node, p);
1141 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1143 HTMLElement *This = impl_from_IHTMLElement(iface);
1145 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1147 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1150 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1152 HTMLElement *This = impl_from_IHTMLElement(iface);
1153 nsAString html_str;
1154 HRESULT hres;
1156 WARN("(%p)->(%p) semi-stub\n", This, p);
1158 nsAString_Init(&html_str, NULL);
1159 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1160 if(SUCCEEDED(hres)) {
1161 const PRUnichar *html;
1163 nsAString_GetData(&html_str, &html);
1164 *p = SysAllocString(html);
1165 if(!*p)
1166 hres = E_OUTOFMEMORY;
1169 nsAString_Finish(&html_str);
1171 TRACE("ret %s\n", debugstr_w(*p));
1172 return S_OK;
1175 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1177 HTMLElement *This = impl_from_IHTMLElement(iface);
1178 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1179 return E_NOTIMPL;
1182 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1184 HTMLElement *This = impl_from_IHTMLElement(iface);
1185 FIXME("(%p)->(%p)\n", This, p);
1186 return E_NOTIMPL;
1189 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1191 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1192 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1193 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1194 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1195 nsresult nsres;
1197 if (!strcmpiW(where, wszBeforeBegin))
1199 nsIDOMNode *unused;
1200 nsIDOMNode *parent;
1201 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1202 if (!parent) return E_INVALIDARG;
1203 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1204 if (unused) nsIDOMNode_Release(unused);
1205 nsIDOMNode_Release(parent);
1207 else if (!strcmpiW(where, wszAfterBegin))
1209 nsIDOMNode *unused;
1210 nsIDOMNode *first_child;
1211 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1212 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1213 if (unused) nsIDOMNode_Release(unused);
1214 if (first_child) nsIDOMNode_Release(first_child);
1216 else if (!strcmpiW(where, wszBeforeEnd))
1218 nsIDOMNode *unused;
1219 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1220 if (unused) nsIDOMNode_Release(unused);
1222 else if (!strcmpiW(where, wszAfterEnd))
1224 nsIDOMNode *unused;
1225 nsIDOMNode *next_sibling;
1226 nsIDOMNode *parent;
1227 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1228 if (!parent) return E_INVALIDARG;
1230 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1231 if (next_sibling)
1233 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1234 nsIDOMNode_Release(next_sibling);
1236 else
1237 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1238 nsIDOMNode_Release(parent);
1239 if (unused) nsIDOMNode_Release(unused);
1241 else
1243 ERR("invalid where: %s\n", debugstr_w(where));
1244 return E_INVALIDARG;
1247 if (NS_FAILED(nsres))
1248 return E_FAIL;
1249 else
1250 return S_OK;
1253 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1254 BSTR html)
1256 HTMLElement *This = impl_from_IHTMLElement(iface);
1257 nsIDOMRange *range;
1258 nsIDOMNSRange *nsrange;
1259 nsIDOMNode *nsnode;
1260 nsAString ns_html;
1261 nsresult nsres;
1262 HRESULT hr;
1264 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1266 if(!This->node.doc->nsdoc) {
1267 WARN("NULL nsdoc\n");
1268 return E_UNEXPECTED;
1271 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1272 if(NS_FAILED(nsres))
1274 ERR("CreateRange failed: %08x\n", nsres);
1275 return E_FAIL;
1278 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1280 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
1281 nsIDOMRange_Release(range);
1282 if(NS_FAILED(nsres))
1284 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
1285 return E_FAIL;
1288 nsAString_InitDepend(&ns_html, html);
1290 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1291 nsIDOMNSRange_Release(nsrange);
1292 nsAString_Finish(&ns_html);
1294 if(NS_FAILED(nsres) || !nsnode)
1296 ERR("CreateTextNode failed: %08x\n", nsres);
1297 return E_FAIL;
1300 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1301 nsIDOMNode_Release(nsnode);
1303 return hr;
1306 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1307 BSTR text)
1309 HTMLElement *This = impl_from_IHTMLElement(iface);
1310 nsIDOMNode *nsnode;
1311 nsAString ns_text;
1312 nsresult nsres;
1313 HRESULT hr;
1315 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1317 if(!This->node.doc->nsdoc) {
1318 WARN("NULL nsdoc\n");
1319 return E_UNEXPECTED;
1323 nsAString_InitDepend(&ns_text, text);
1324 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1325 nsAString_Finish(&ns_text);
1327 if(NS_FAILED(nsres) || !nsnode)
1329 ERR("CreateTextNode failed: %08x\n", nsres);
1330 return E_FAIL;
1333 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1334 nsIDOMNode_Release(nsnode);
1336 return hr;
1339 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1341 HTMLElement *This = impl_from_IHTMLElement(iface);
1342 FIXME("(%p)->(%p)\n", This, p);
1343 return E_NOTIMPL;
1346 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1348 HTMLElement *This = impl_from_IHTMLElement(iface);
1349 FIXME("(%p)->(%p)\n", This, p);
1350 return E_NOTIMPL;
1353 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1355 HTMLElement *This = impl_from_IHTMLElement(iface);
1357 TRACE("(%p)\n", This);
1359 return call_fire_event(&This->node, EVENTID_CLICK);
1362 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1363 IHTMLFiltersCollection **p)
1365 HTMLElement *This = impl_from_IHTMLElement(iface);
1366 TRACE("(%p)->(%p)\n", This, p);
1368 if(!p)
1369 return E_POINTER;
1371 *p = HTMLFiltersCollection_Create();
1373 return S_OK;
1376 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1378 HTMLElement *This = impl_from_IHTMLElement(iface);
1379 FIXME("(%p)->()\n", This);
1380 return E_NOTIMPL;
1383 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1385 HTMLElement *This = impl_from_IHTMLElement(iface);
1386 FIXME("(%p)->(%p)\n", This, p);
1387 return E_NOTIMPL;
1390 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1392 HTMLElement *This = impl_from_IHTMLElement(iface);
1393 FIXME("(%p)->(%p)\n", This, String);
1394 return E_NOTIMPL;
1397 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1399 HTMLElement *This = impl_from_IHTMLElement(iface);
1400 FIXME("(%p)->()\n", This);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1406 HTMLElement *This = impl_from_IHTMLElement(iface);
1407 FIXME("(%p)->(%p)\n", This, p);
1408 return E_NOTIMPL;
1411 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1413 HTMLElement *This = impl_from_IHTMLElement(iface);
1414 FIXME("(%p)->()\n", This);
1415 return E_NOTIMPL;
1418 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1420 HTMLElement *This = impl_from_IHTMLElement(iface);
1421 FIXME("(%p)->(%p)\n", This, p);
1422 return E_NOTIMPL;
1425 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1427 HTMLElement *This = impl_from_IHTMLElement(iface);
1428 FIXME("(%p)->()\n", This);
1429 return E_NOTIMPL;
1432 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1434 HTMLElement *This = impl_from_IHTMLElement(iface);
1435 FIXME("(%p)->(%p)\n", This, p);
1436 return E_NOTIMPL;
1439 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1441 HTMLElement *This = impl_from_IHTMLElement(iface);
1442 FIXME("(%p)->()\n", This);
1443 return E_NOTIMPL;
1446 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1448 HTMLElement *This = impl_from_IHTMLElement(iface);
1449 FIXME("(%p)->(%p)\n", This, p);
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1455 HTMLElement *This = impl_from_IHTMLElement(iface);
1456 FIXME("(%p)->()\n", This);
1457 return E_NOTIMPL;
1460 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1462 HTMLElement *This = impl_from_IHTMLElement(iface);
1463 FIXME("(%p)->(%p)\n", This, p);
1464 return E_NOTIMPL;
1467 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1469 HTMLElement *This = impl_from_IHTMLElement(iface);
1470 FIXME("(%p)->()\n", This);
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1476 HTMLElement *This = impl_from_IHTMLElement(iface);
1477 FIXME("(%p)->(%p)\n", This, p);
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1483 HTMLElement *This = impl_from_IHTMLElement(iface);
1484 FIXME("(%p)->()\n", This);
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1490 HTMLElement *This = impl_from_IHTMLElement(iface);
1491 FIXME("(%p)->(%p)\n", This, p);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1497 HTMLElement *This = impl_from_IHTMLElement(iface);
1498 FIXME("(%p)->()\n", This);
1499 return E_NOTIMPL;
1502 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1504 HTMLElement *This = impl_from_IHTMLElement(iface);
1505 FIXME("(%p)->(%p)\n", This, p);
1506 return E_NOTIMPL;
1509 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1511 HTMLElement *This = impl_from_IHTMLElement(iface);
1512 FIXME("(%p)->()\n", This);
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1518 HTMLElement *This = impl_from_IHTMLElement(iface);
1519 FIXME("(%p)->(%p)\n", This, p);
1520 return E_NOTIMPL;
1523 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1525 HTMLElement *This = impl_from_IHTMLElement(iface);
1526 nsIDOMNodeList *nsnode_list;
1527 nsresult nsres;
1529 TRACE("(%p)->(%p)\n", This, p);
1531 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1532 if(NS_FAILED(nsres)) {
1533 ERR("GetChildNodes failed: %08x\n", nsres);
1534 return E_FAIL;
1537 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc,
1538 (IUnknown*)&This->IHTMLElement_iface, nsnode_list);
1540 nsIDOMNodeList_Release(nsnode_list);
1541 return S_OK;
1544 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1546 HTMLElement *This = impl_from_IHTMLElement(iface);
1548 TRACE("(%p)->(%p)\n", This, p);
1550 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1551 return S_OK;
1554 static const IHTMLElementVtbl HTMLElementVtbl = {
1555 HTMLElement_QueryInterface,
1556 HTMLElement_AddRef,
1557 HTMLElement_Release,
1558 HTMLElement_GetTypeInfoCount,
1559 HTMLElement_GetTypeInfo,
1560 HTMLElement_GetIDsOfNames,
1561 HTMLElement_Invoke,
1562 HTMLElement_setAttribute,
1563 HTMLElement_getAttribute,
1564 HTMLElement_removeAttribute,
1565 HTMLElement_put_className,
1566 HTMLElement_get_className,
1567 HTMLElement_put_id,
1568 HTMLElement_get_id,
1569 HTMLElement_get_tagName,
1570 HTMLElement_get_parentElement,
1571 HTMLElement_get_style,
1572 HTMLElement_put_onhelp,
1573 HTMLElement_get_onhelp,
1574 HTMLElement_put_onclick,
1575 HTMLElement_get_onclick,
1576 HTMLElement_put_ondblclick,
1577 HTMLElement_get_ondblclick,
1578 HTMLElement_put_onkeydown,
1579 HTMLElement_get_onkeydown,
1580 HTMLElement_put_onkeyup,
1581 HTMLElement_get_onkeyup,
1582 HTMLElement_put_onkeypress,
1583 HTMLElement_get_onkeypress,
1584 HTMLElement_put_onmouseout,
1585 HTMLElement_get_onmouseout,
1586 HTMLElement_put_onmouseover,
1587 HTMLElement_get_onmouseover,
1588 HTMLElement_put_onmousemove,
1589 HTMLElement_get_onmousemove,
1590 HTMLElement_put_onmousedown,
1591 HTMLElement_get_onmousedown,
1592 HTMLElement_put_onmouseup,
1593 HTMLElement_get_onmouseup,
1594 HTMLElement_get_document,
1595 HTMLElement_put_title,
1596 HTMLElement_get_title,
1597 HTMLElement_put_language,
1598 HTMLElement_get_language,
1599 HTMLElement_put_onselectstart,
1600 HTMLElement_get_onselectstart,
1601 HTMLElement_scrollIntoView,
1602 HTMLElement_contains,
1603 HTMLElement_get_sourceIndex,
1604 HTMLElement_get_recordNumber,
1605 HTMLElement_put_lang,
1606 HTMLElement_get_lang,
1607 HTMLElement_get_offsetLeft,
1608 HTMLElement_get_offsetTop,
1609 HTMLElement_get_offsetWidth,
1610 HTMLElement_get_offsetHeight,
1611 HTMLElement_get_offsetParent,
1612 HTMLElement_put_innerHTML,
1613 HTMLElement_get_innerHTML,
1614 HTMLElement_put_innerText,
1615 HTMLElement_get_innerText,
1616 HTMLElement_put_outerHTML,
1617 HTMLElement_get_outerHTML,
1618 HTMLElement_put_outerText,
1619 HTMLElement_get_outerText,
1620 HTMLElement_insertAdjacentHTML,
1621 HTMLElement_insertAdjacentText,
1622 HTMLElement_get_parentTextEdit,
1623 HTMLElement_get_isTextEdit,
1624 HTMLElement_click,
1625 HTMLElement_get_filters,
1626 HTMLElement_put_ondragstart,
1627 HTMLElement_get_ondragstart,
1628 HTMLElement_toString,
1629 HTMLElement_put_onbeforeupdate,
1630 HTMLElement_get_onbeforeupdate,
1631 HTMLElement_put_onafterupdate,
1632 HTMLElement_get_onafterupdate,
1633 HTMLElement_put_onerrorupdate,
1634 HTMLElement_get_onerrorupdate,
1635 HTMLElement_put_onrowexit,
1636 HTMLElement_get_onrowexit,
1637 HTMLElement_put_onrowenter,
1638 HTMLElement_get_onrowenter,
1639 HTMLElement_put_ondatasetchanged,
1640 HTMLElement_get_ondatasetchanged,
1641 HTMLElement_put_ondataavailable,
1642 HTMLElement_get_ondataavailable,
1643 HTMLElement_put_ondatasetcomplete,
1644 HTMLElement_get_ondatasetcomplete,
1645 HTMLElement_put_onfilterchange,
1646 HTMLElement_get_onfilterchange,
1647 HTMLElement_get_children,
1648 HTMLElement_get_all
1651 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1653 return CONTAINING_RECORD(iface, HTMLElement, node);
1656 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1658 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1660 *ppv = NULL;
1662 if(IsEqualGUID(&IID_IUnknown, riid)) {
1663 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1664 *ppv = &This->IHTMLElement_iface;
1665 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1666 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1667 *ppv = &This->IHTMLElement_iface;
1668 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1669 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1670 *ppv = &This->IHTMLElement_iface;
1671 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1672 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1673 *ppv = &This->IHTMLElement2_iface;
1674 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1675 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1676 *ppv = &This->IHTMLElement3_iface;
1677 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1678 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1679 *ppv = &This->IHTMLElement4_iface;
1680 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1681 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1682 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1685 if(*ppv) {
1686 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1687 return S_OK;
1690 return HTMLDOMNode_QI(&This->node, riid, ppv);
1693 void HTMLElement_destructor(HTMLDOMNode *iface)
1695 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1697 ConnectionPointContainer_Destroy(&This->cp_container);
1699 if(This->nselem)
1700 nsIDOMHTMLElement_Release(This->nselem);
1701 if(This->style)
1702 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1703 if(This->attrs) {
1704 HTMLDOMAttribute *attr;
1706 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1707 attr->elem = NULL;
1709 This->attrs->elem = NULL;
1710 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1713 HTMLDOMNode_destructor(&This->node);
1716 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1718 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1719 HTMLElement *new_elem;
1720 HRESULT hres;
1722 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1723 if(FAILED(hres))
1724 return hres;
1726 IHTMLElement_AddRef(&new_elem->IHTMLElement_iface);
1727 *ret = &new_elem->node;
1728 return S_OK;
1731 static const NodeImplVtbl HTMLElementImplVtbl = {
1732 HTMLElement_QI,
1733 HTMLElement_destructor,
1734 HTMLElement_clone,
1735 HTMLElement_get_attr_col
1738 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1740 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1743 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1744 DWORD grfdex, DISPID *pid)
1746 HTMLElement *This = impl_from_DispatchEx(dispex);
1748 if(This->node.vtbl->get_dispid)
1749 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1751 return DISP_E_UNKNOWNNAME;
1754 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1755 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1756 IServiceProvider *caller)
1758 HTMLElement *This = impl_from_DispatchEx(dispex);
1760 if(This->node.vtbl->invoke)
1761 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1762 params, res, ei, caller);
1764 ERR("(%p): element has no invoke method\n", This);
1765 return E_NOTIMPL;
1768 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1770 HTMLElement *This = impl_from_DispatchEx(dispex);
1771 nsIDOMNamedNodeMap *attrs;
1772 nsIDOMNode *node;
1773 nsAString nsstr;
1774 const PRUnichar *str;
1775 BSTR name;
1776 VARIANT value;
1777 unsigned i;
1778 PRUint32 len;
1779 DISPID id;
1780 nsresult nsres;
1781 HRESULT hres;
1783 if(!This->nselem)
1784 return S_FALSE;
1786 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1787 if(NS_FAILED(nsres))
1788 return E_FAIL;
1790 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1791 if(NS_FAILED(nsres)) {
1792 nsIDOMNamedNodeMap_Release(attrs);
1793 return E_FAIL;
1796 nsAString_Init(&nsstr, NULL);
1797 for(i=0; i<len; i++) {
1798 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1799 if(NS_FAILED(nsres))
1800 continue;
1802 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1803 if(NS_FAILED(nsres)) {
1804 nsIDOMNode_Release(node);
1805 continue;
1808 nsAString_GetData(&nsstr, &str);
1809 name = SysAllocString(str);
1810 if(!name) {
1811 nsIDOMNode_Release(node);
1812 continue;
1815 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1816 if(hres != DISP_E_UNKNOWNNAME) {
1817 nsIDOMNode_Release(node);
1818 SysFreeString(name);
1819 continue;
1822 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1823 nsIDOMNode_Release(node);
1824 if(NS_FAILED(nsres)) {
1825 SysFreeString(name);
1826 continue;
1829 nsAString_GetData(&nsstr, &str);
1830 V_VT(&value) = VT_BSTR;
1831 if(*str) {
1832 V_BSTR(&value) = SysAllocString(str);
1833 if(!V_BSTR(&value)) {
1834 SysFreeString(name);
1835 continue;
1837 } else
1838 V_BSTR(&value) = NULL;
1840 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1841 SysFreeString(name);
1842 VariantClear(&value);
1844 nsAString_Finish(&nsstr);
1846 nsIDOMNamedNodeMap_Release(attrs);
1847 return S_OK;
1850 static const tid_t HTMLElement_iface_tids[] = {
1851 HTMLELEMENT_TIDS,
1855 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1856 NULL,
1857 HTMLElement_get_dispid,
1858 HTMLElement_invoke,
1859 HTMLElement_populate_props
1862 static dispex_static_data_t HTMLElement_dispex = {
1863 &HTMLElement_dispex_vtbl,
1864 DispHTMLUnknownElement_tid,
1865 NULL,
1866 HTMLElement_iface_tids
1869 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1871 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1873 HTMLElement2_Init(This);
1874 HTMLElement3_Init(This);
1876 if(dispex_data && !dispex_data->vtbl)
1877 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1878 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1879 dispex_data ? dispex_data : &HTMLElement_dispex);
1881 if(nselem)
1882 nsIDOMHTMLElement_AddRef(nselem);
1883 This->nselem = nselem;
1885 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1887 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1890 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1892 nsIDOMHTMLElement *nselem;
1893 nsAString class_name_str;
1894 const PRUnichar *class_name;
1895 const tag_desc_t *tag;
1896 HTMLElement *elem;
1897 nsresult nsres;
1898 HRESULT hres;
1900 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1901 if(NS_FAILED(nsres))
1902 return E_FAIL;
1904 nsAString_Init(&class_name_str, NULL);
1905 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1907 nsAString_GetData(&class_name_str, &class_name);
1909 tag = get_tag_desc(class_name);
1910 if(tag) {
1911 hres = tag->constructor(doc, nselem, &elem);
1912 }else if(use_generic) {
1913 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1914 }else {
1915 elem = heap_alloc_zero(sizeof(HTMLElement));
1916 if(elem) {
1917 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1918 elem->node.vtbl = &HTMLElementImplVtbl;
1919 hres = S_OK;
1920 }else {
1921 hres = E_OUTOFMEMORY;
1925 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1927 nsIDOMElement_Release(nselem);
1928 nsAString_Finish(&class_name_str);
1929 if(FAILED(hres))
1930 return hres;
1932 *ret = elem;
1933 return S_OK;
1936 /* interface IHTMLFiltersCollection */
1937 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1939 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1941 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1943 if(IsEqualGUID(&IID_IUnknown, riid)) {
1944 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1945 *ppv = &This->IHTMLFiltersCollection_iface;
1946 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1947 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1948 *ppv = &This->IHTMLFiltersCollection_iface;
1949 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1950 return *ppv ? S_OK : E_NOINTERFACE;
1953 if(*ppv) {
1954 IUnknown_AddRef((IUnknown*)*ppv);
1955 return S_OK;
1958 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1959 return E_NOINTERFACE;
1962 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1964 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1965 LONG ref = InterlockedIncrement(&This->ref);
1967 TRACE("(%p) ref=%d\n", This, ref);
1969 return ref;
1972 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1974 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1975 LONG ref = InterlockedDecrement(&This->ref);
1977 TRACE("(%p) ref=%d\n", This, ref);
1979 if(!ref)
1981 heap_free(This);
1984 return ref;
1987 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1989 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1990 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1993 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1994 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1996 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1997 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2000 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
2001 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
2002 LCID lcid, DISPID *rgDispId)
2004 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2005 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2006 lcid, rgDispId);
2009 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
2010 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2011 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2013 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2014 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2015 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2018 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
2020 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2022 if(!p)
2023 return E_POINTER;
2025 FIXME("(%p)->(%p) Always returning 0\n", This, p);
2026 *p = 0;
2028 return S_OK;
2031 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
2033 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2034 FIXME("(%p)->(%p)\n", This, p);
2035 return E_NOTIMPL;
2038 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
2040 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2041 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2042 return E_NOTIMPL;
2045 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2046 HTMLFiltersCollection_QueryInterface,
2047 HTMLFiltersCollection_AddRef,
2048 HTMLFiltersCollection_Release,
2049 HTMLFiltersCollection_GetTypeInfoCount,
2050 HTMLFiltersCollection_GetTypeInfo,
2051 HTMLFiltersCollection_GetIDsOfNames,
2052 HTMLFiltersCollection_Invoke,
2053 HTMLFiltersCollection_get_length,
2054 HTMLFiltersCollection_get__newEnum,
2055 HTMLFiltersCollection_item
2058 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2060 WCHAR *ptr;
2061 int idx = 0;
2063 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2064 idx = idx*10 + (*ptr-'0');
2065 if(*ptr)
2066 return DISP_E_UNKNOWNNAME;
2068 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2069 TRACE("ret %x\n", *dispid);
2070 return S_OK;
2073 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2074 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2076 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2078 V_VT(res) = VT_DISPATCH;
2079 V_DISPATCH(res) = NULL;
2081 FIXME("always returning NULL\n");
2083 return S_OK;
2086 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2087 NULL,
2088 HTMLFiltersCollection_get_dispid,
2089 HTMLFiltersCollection_invoke,
2090 NULL
2093 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2094 IHTMLFiltersCollection_tid,
2097 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2098 &HTMLFiltersCollection_dispex_vtbl,
2099 IHTMLFiltersCollection_tid,
2100 NULL,
2101 HTMLFiltersCollection_iface_tids
2104 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2106 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2108 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2109 ret->ref = 1;
2111 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2112 &HTMLFiltersCollection_dispex);
2114 return &ret->IHTMLFiltersCollection_iface;
2117 /* interface IHTMLAttributeCollection */
2118 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2120 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2123 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2125 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2127 *ppv = NULL;
2129 if(IsEqualGUID(&IID_IUnknown, riid)) {
2130 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2131 *ppv = &This->IHTMLAttributeCollection_iface;
2132 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2133 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2134 *ppv = &This->IHTMLAttributeCollection_iface;
2135 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2136 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2137 *ppv = &This->IHTMLAttributeCollection2_iface;
2138 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2139 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2140 *ppv = &This->IHTMLAttributeCollection3_iface;
2141 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2142 return *ppv ? S_OK : E_NOINTERFACE;
2145 if(*ppv) {
2146 IUnknown_AddRef((IUnknown*)*ppv);
2147 return S_OK;
2150 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2151 return E_NOINTERFACE;
2154 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2156 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2157 LONG ref = InterlockedIncrement(&This->ref);
2159 TRACE("(%p) ref=%d\n", This, ref);
2161 return ref;
2164 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2166 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2167 LONG ref = InterlockedDecrement(&This->ref);
2169 TRACE("(%p) ref=%d\n", This, ref);
2171 if(!ref) {
2172 while(!list_empty(&This->attrs)) {
2173 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2175 list_remove(&attr->entry);
2176 attr->elem = NULL;
2177 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2180 heap_free(This);
2183 return ref;
2186 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2188 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2189 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2192 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2193 LCID lcid, ITypeInfo **ppTInfo)
2195 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2196 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2199 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2200 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2202 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2203 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2204 lcid, rgDispId);
2207 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2208 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2209 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2211 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2212 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2213 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2216 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2218 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2219 DISPID id = DISPID_STARTENUM;
2220 LONG len = -1;
2221 HRESULT hres;
2223 FIXME("filter non-enumerable attributes out\n");
2225 while(1) {
2226 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2227 if(FAILED(hres))
2228 return hres;
2229 else if(hres == S_FALSE)
2230 break;
2232 len++;
2233 if(len == *idx)
2234 break;
2237 if(dispid) {
2238 *dispid = id;
2239 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2242 *idx = len+1;
2243 return S_OK;
2246 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2248 HRESULT hres;
2250 if(name[0]>='0' && name[0]<='9') {
2251 WCHAR *end_ptr;
2252 LONG idx;
2254 idx = strtoulW(name, &end_ptr, 10);
2255 if(!*end_ptr) {
2256 hres = get_attr_dispid_by_idx(This, &idx, id);
2257 if(SUCCEEDED(hres))
2258 return hres;
2262 if(!This->elem) {
2263 WARN("NULL elem\n");
2264 return E_UNEXPECTED;
2267 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2268 name, fdexNameCaseInsensitive, id);
2269 return hres;
2272 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2274 HTMLDOMAttribute *iter;
2275 LONG pos = 0;
2276 HRESULT hres;
2278 *attr = NULL;
2279 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2280 if(iter->dispid == id) {
2281 *attr = iter;
2282 break;
2284 pos++;
2287 if(!*attr) {
2288 if(!This->elem) {
2289 WARN("NULL elem\n");
2290 return E_UNEXPECTED;
2293 pos++;
2294 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2295 if(FAILED(hres))
2296 return hres;
2299 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2300 if(list_pos)
2301 *list_pos = pos;
2302 return S_OK;
2305 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2307 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2308 HRESULT hres;
2310 TRACE("(%p)->(%p)\n", This, p);
2312 *p = -1;
2313 hres = get_attr_dispid_by_idx(This, p, NULL);
2314 return hres;
2317 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2319 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2320 FIXME("(%p)->(%p)\n", This, p);
2321 return E_NOTIMPL;
2324 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2326 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2327 HTMLDOMAttribute *attr;
2328 DISPID id;
2329 HRESULT hres;
2331 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2333 switch(V_VT(name)) {
2334 case VT_I4:
2335 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2336 break;
2337 case VT_BSTR:
2338 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2339 break;
2340 default:
2341 FIXME("unsupported vt %x\n", V_VT(name));
2342 hres = E_NOTIMPL;
2344 if(hres == DISP_E_UNKNOWNNAME)
2345 return E_INVALIDARG;
2346 if(FAILED(hres))
2347 return hres;
2349 hres = get_domattr(This, id, NULL, &attr);
2350 if(FAILED(hres))
2351 return hres;
2353 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2354 return S_OK;
2357 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2358 HTMLAttributeCollection_QueryInterface,
2359 HTMLAttributeCollection_AddRef,
2360 HTMLAttributeCollection_Release,
2361 HTMLAttributeCollection_GetTypeInfoCount,
2362 HTMLAttributeCollection_GetTypeInfo,
2363 HTMLAttributeCollection_GetIDsOfNames,
2364 HTMLAttributeCollection_Invoke,
2365 HTMLAttributeCollection_get_length,
2366 HTMLAttributeCollection__newEnum,
2367 HTMLAttributeCollection_item
2370 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2372 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2375 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2377 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2378 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2381 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2383 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2384 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2387 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2389 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2390 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2393 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2395 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2396 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2399 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2400 LCID lcid, ITypeInfo **ppTInfo)
2402 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2403 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2406 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2407 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2409 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2410 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2411 lcid, rgDispId);
2414 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2415 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2416 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2418 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2419 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2420 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2423 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2424 IHTMLDOMAttribute **newretNode)
2426 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2427 HTMLDOMAttribute *attr;
2428 DISPID id;
2429 HRESULT hres;
2431 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2433 hres = get_attr_dispid_by_name(This, bstrName, &id);
2434 if(hres == DISP_E_UNKNOWNNAME) {
2435 *newretNode = NULL;
2436 return S_OK;
2437 } else if(FAILED(hres)) {
2438 return hres;
2441 hres = get_domattr(This, id, NULL, &attr);
2442 if(FAILED(hres))
2443 return hres;
2445 *newretNode = &attr->IHTMLDOMAttribute_iface;
2446 return S_OK;
2449 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2450 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2452 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2453 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2454 return E_NOTIMPL;
2457 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2458 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2460 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2461 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2462 return E_NOTIMPL;
2465 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2466 HTMLAttributeCollection2_QueryInterface,
2467 HTMLAttributeCollection2_AddRef,
2468 HTMLAttributeCollection2_Release,
2469 HTMLAttributeCollection2_GetTypeInfoCount,
2470 HTMLAttributeCollection2_GetTypeInfo,
2471 HTMLAttributeCollection2_GetIDsOfNames,
2472 HTMLAttributeCollection2_Invoke,
2473 HTMLAttributeCollection2_getNamedItem,
2474 HTMLAttributeCollection2_setNamedItem,
2475 HTMLAttributeCollection2_removeNamedItem
2478 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2480 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2483 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2485 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2486 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2489 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2491 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2492 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2495 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2497 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2498 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2501 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2503 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2504 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2507 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2508 LCID lcid, ITypeInfo **ppTInfo)
2510 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2511 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2514 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2515 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2517 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2518 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2519 lcid, rgDispId);
2522 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2523 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2524 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2526 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2527 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2528 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2531 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2532 IHTMLDOMAttribute **ppNodeOut)
2534 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2535 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2538 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2539 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2541 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2542 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2543 return E_NOTIMPL;
2546 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2547 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2549 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2550 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2551 return E_NOTIMPL;
2554 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2556 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2557 HTMLDOMAttribute *attr;
2558 DISPID id;
2559 HRESULT hres;
2561 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2563 hres = get_attr_dispid_by_idx(This, &index, &id);
2564 if(hres == DISP_E_UNKNOWNNAME)
2565 return E_INVALIDARG;
2566 if(FAILED(hres))
2567 return hres;
2569 hres = get_domattr(This, id, NULL, &attr);
2570 if(FAILED(hres))
2571 return hres;
2573 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2574 return S_OK;
2577 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2579 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2580 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2583 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2584 HTMLAttributeCollection3_QueryInterface,
2585 HTMLAttributeCollection3_AddRef,
2586 HTMLAttributeCollection3_Release,
2587 HTMLAttributeCollection3_GetTypeInfoCount,
2588 HTMLAttributeCollection3_GetTypeInfo,
2589 HTMLAttributeCollection3_GetIDsOfNames,
2590 HTMLAttributeCollection3_Invoke,
2591 HTMLAttributeCollection3_getNamedItem,
2592 HTMLAttributeCollection3_setNamedItem,
2593 HTMLAttributeCollection3_removeNamedItem,
2594 HTMLAttributeCollection3_item,
2595 HTMLAttributeCollection3_get_length
2598 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2600 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2603 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2605 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2606 HTMLDOMAttribute *attr;
2607 LONG pos;
2608 HRESULT hres;
2610 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2612 hres = get_attr_dispid_by_name(This, name, dispid);
2613 if(FAILED(hres))
2614 return hres;
2616 hres = get_domattr(This, *dispid, &pos, &attr);
2617 if(FAILED(hres))
2618 return hres;
2619 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2621 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2622 return S_OK;
2625 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2626 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2628 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2630 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2632 switch(flags) {
2633 case DISPATCH_PROPERTYGET: {
2634 HTMLDOMAttribute *iter;
2636 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2638 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2639 if(!(--id))
2640 break;
2642 if(id)
2643 return E_INVALIDARG;
2645 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2646 V_VT(res) = VT_DISPATCH;
2647 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2648 return S_OK;
2651 default:
2652 FIXME("unimplemented flags %x\n", flags);
2653 return E_NOTIMPL;
2657 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2658 NULL,
2659 HTMLAttributeCollection_get_dispid,
2660 HTMLAttributeCollection_invoke,
2661 NULL
2664 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2665 IHTMLAttributeCollection_tid,
2666 IHTMLAttributeCollection2_tid,
2667 IHTMLAttributeCollection3_tid,
2671 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2672 &HTMLAttributeCollection_dispex_vtbl,
2673 DispHTMLAttributeCollection_tid,
2674 NULL,
2675 HTMLAttributeCollection_iface_tids
2678 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2680 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2682 if(This->attrs) {
2683 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2684 *ac = This->attrs;
2685 return S_OK;
2688 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2689 if(!This->attrs)
2690 return E_OUTOFMEMORY;
2692 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2693 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2694 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2695 This->attrs->ref = 2;
2697 This->attrs->elem = This;
2698 list_init(&This->attrs->attrs);
2699 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2700 &HTMLAttributeCollection_dispex);
2702 *ac = This->attrs;
2703 return S_OK;