mshtml: Added IHTMLMetaElement stub implementation.
[wine.git] / dlls / mshtml / htmlelem.c
blob1baf9e2fe45457ef35bbb0908a1847c27b59b50d
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 metaW[] = {'M','E','T','A',0};
49 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
50 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
51 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
52 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
53 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
54 static const WCHAR tableW[] = {'T','A','B','L','E',0};
55 static const WCHAR tdW[] = {'T','D',0};
56 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
57 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
58 static const WCHAR trW[] = {'T','R',0};
60 typedef struct {
61 const WCHAR *name;
62 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
63 } tag_desc_t;
65 static const tag_desc_t tag_descs[] = {
66 {aW, HTMLAnchorElement_Create},
67 {bodyW, HTMLBodyElement_Create},
68 {embedW, HTMLEmbedElement_Create},
69 {formW, HTMLFormElement_Create},
70 {frameW, HTMLFrameElement_Create},
71 {headW, HTMLHeadElement_Create},
72 {iframeW, HTMLIFrame_Create},
73 {imgW, HTMLImgElement_Create},
74 {inputW, HTMLInputElement_Create},
75 {metaW, HTMLMetaElement_Create},
76 {objectW, HTMLObjectElement_Create},
77 {optionW, HTMLOptionElement_Create},
78 {scriptW, HTMLScriptElement_Create},
79 {selectW, HTMLSelectElement_Create},
80 {styleW, HTMLStyleElement_Create},
81 {tableW, HTMLTable_Create},
82 {tdW, HTMLTableCell_Create},
83 {textareaW, HTMLTextAreaElement_Create},
84 {title_tagW, HTMLTitleElement_Create},
85 {trW, HTMLTableRow_Create}
88 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
90 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
91 int r;
93 while(min <= max) {
94 i = (min+max)/2;
95 r = strcmpW(tag_name, tag_descs[i].name);
96 if(!r)
97 return tag_descs+i;
99 if(r < 0)
100 max = i-1;
101 else
102 min = i+1;
105 return NULL;
108 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
110 nsIDOMDocumentFragment *nsfragment;
111 nsIDOMNSRange *nsrange;
112 nsIDOMNode *nsparent;
113 nsIDOMRange *range;
114 nsAString html_str;
115 nsresult nsres;
116 HRESULT hres = S_OK;
118 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
119 if(NS_FAILED(nsres)) {
120 ERR("CreateRange failed: %08x\n", nsres);
121 return E_FAIL;
124 nsres = nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void**)&nsrange);
125 nsIDOMRange_Release(range);
126 if(NS_FAILED(nsres)) {
127 ERR("Could not get nsIDOMNSRange: %08x\n", nsres);
128 return E_FAIL;
131 nsAString_InitDepend(&html_str, html);
132 nsIDOMNSRange_CreateContextualFragment(nsrange, &html_str, &nsfragment);
133 nsIDOMNSRange_Release(nsrange);
134 nsAString_Finish(&html_str);
135 if(NS_FAILED(nsres)) {
136 ERR("CreateContextualFragment failed: %08x\n", nsres);
137 return E_FAIL;
140 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
141 if(NS_SUCCEEDED(nsres) && nsparent) {
142 nsIDOMNode *nstmp;
144 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
145 nsIDOMNode_Release(nsparent);
146 if(NS_FAILED(nsres)) {
147 ERR("ReplaceChild failed: %08x\n", nsres);
148 hres = E_FAIL;
149 }else if(nstmp) {
150 nsIDOMNode_Release(nstmp);
152 }else {
153 ERR("GetParentNode failed: %08x\n", nsres);
154 hres = E_FAIL;
157 nsIDOMDocumentFragment_Release(nsfragment);
158 return hres;
161 typedef struct
163 DispatchEx dispex;
164 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
166 LONG ref;
167 } HTMLFiltersCollection;
169 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
171 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
174 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
176 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
178 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
181 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
183 nsIDOMElement *nselem;
184 nsAString tag_str;
185 nsresult nsres;
187 if(!doc->nsdoc) {
188 WARN("NULL nsdoc\n");
189 return E_UNEXPECTED;
192 nsAString_InitDepend(&tag_str, tag);
193 nsres = nsIDOMDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
194 nsAString_Finish(&tag_str);
195 if(NS_FAILED(nsres)) {
196 ERR("CreateElement failed: %08x\n", nsres);
197 return E_FAIL;
200 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
201 nsIDOMElement_Release(nselem);
202 if(NS_FAILED(nsres)) {
203 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
204 return E_FAIL;
207 return S_OK;
210 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
211 REFIID riid, void **ppv)
213 HTMLElement *This = impl_from_IHTMLElement(iface);
215 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
218 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
220 HTMLElement *This = impl_from_IHTMLElement(iface);
222 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
225 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
227 HTMLElement *This = impl_from_IHTMLElement(iface);
229 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
232 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
234 HTMLElement *This = impl_from_IHTMLElement(iface);
235 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
238 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
239 LCID lcid, ITypeInfo **ppTInfo)
241 HTMLElement *This = impl_from_IHTMLElement(iface);
242 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
245 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
246 LPOLESTR *rgszNames, UINT cNames,
247 LCID lcid, DISPID *rgDispId)
249 HTMLElement *This = impl_from_IHTMLElement(iface);
250 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
251 lcid, rgDispId);
254 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
255 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
256 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
258 HTMLElement *This = impl_from_IHTMLElement(iface);
259 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
260 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
263 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
264 VARIANT AttributeValue, LONG lFlags)
266 HTMLElement *This = impl_from_IHTMLElement(iface);
267 HRESULT hres;
268 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
269 DISPPARAMS dispParams;
270 EXCEPINFO excep;
272 TRACE("(%p)->(%s . %08x)\n", This, debugstr_w(strAttributeName), lFlags);
274 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
275 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
276 if(FAILED(hres))
277 return hres;
279 dispParams.cArgs = 1;
280 dispParams.cNamedArgs = 1;
281 dispParams.rgdispidNamedArgs = &dispidNamed;
282 dispParams.rgvarg = &AttributeValue;
284 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
285 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
286 return hres;
289 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
290 LONG lFlags, VARIANT *AttributeValue)
292 HTMLElement *This = impl_from_IHTMLElement(iface);
293 DISPID dispid;
294 HRESULT hres;
295 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
296 EXCEPINFO excep;
298 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
300 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
301 fdexNameCaseInsensitive, &dispid);
302 if(hres == DISP_E_UNKNOWNNAME) {
303 V_VT(AttributeValue) = VT_NULL;
304 return S_OK;
307 if(FAILED(hres)) {
308 V_VT(AttributeValue) = VT_NULL;
309 return hres;
312 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
313 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
315 return hres;
318 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
319 LONG lFlags, VARIANT_BOOL *pfSuccess)
321 HTMLElement *This = impl_from_IHTMLElement(iface);
323 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
325 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
328 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
330 HTMLElement *This = impl_from_IHTMLElement(iface);
331 nsAString classname_str;
332 nsresult nsres;
334 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
336 if(!This->nselem) {
337 FIXME("NULL nselem\n");
338 return E_NOTIMPL;
341 nsAString_InitDepend(&classname_str, v);
342 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
343 nsAString_Finish(&classname_str);
344 if(NS_FAILED(nsres))
345 ERR("SetClassName failed: %08x\n", nsres);
347 return S_OK;
350 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
352 HTMLElement *This = impl_from_IHTMLElement(iface);
353 nsAString class_str;
354 nsresult nsres;
355 HRESULT hres = S_OK;
357 TRACE("(%p)->(%p)\n", This, p);
359 if(!This->nselem) {
360 FIXME("NULL nselem\n");
361 return E_NOTIMPL;
364 nsAString_Init(&class_str, NULL);
365 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
367 if(NS_SUCCEEDED(nsres)) {
368 const PRUnichar *class;
369 nsAString_GetData(&class_str, &class);
370 *p = *class ? SysAllocString(class) : NULL;
371 }else {
372 ERR("GetClassName failed: %08x\n", nsres);
373 hres = E_FAIL;
376 nsAString_Finish(&class_str);
378 TRACE("className=%s\n", debugstr_w(*p));
379 return hres;
382 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
384 HTMLElement *This = impl_from_IHTMLElement(iface);
385 nsAString id_str;
386 nsresult nsres;
388 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
390 if(!This->nselem) {
391 FIXME("nselem == NULL\n");
392 return S_OK;
395 nsAString_InitDepend(&id_str, v);
396 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
397 nsAString_Finish(&id_str);
398 if(NS_FAILED(nsres))
399 ERR("SetId failed: %08x\n", nsres);
401 return S_OK;
404 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
406 HTMLElement *This = impl_from_IHTMLElement(iface);
407 const PRUnichar *id;
408 nsAString id_str;
409 nsresult nsres;
411 TRACE("(%p)->(%p)\n", This, p);
413 *p = NULL;
415 if(!This->nselem)
416 return S_OK;
418 nsAString_Init(&id_str, NULL);
419 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
420 nsAString_GetData(&id_str, &id);
422 if(NS_FAILED(nsres))
423 ERR("GetId failed: %08x\n", nsres);
424 else if(*id)
425 *p = SysAllocString(id);
427 nsAString_Finish(&id_str);
428 return S_OK;
431 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
433 HTMLElement *This = impl_from_IHTMLElement(iface);
434 const PRUnichar *tag;
435 nsAString tag_str;
436 nsresult nsres;
438 TRACE("(%p)->(%p)\n", This, p);
440 if(!This->nselem) {
441 static const WCHAR comment_tagW[] = {'!',0};
443 WARN("NULL nselem, assuming comment\n");
445 *p = SysAllocString(comment_tagW);
446 return S_OK;
449 nsAString_Init(&tag_str, NULL);
450 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
451 if(NS_SUCCEEDED(nsres)) {
452 nsAString_GetData(&tag_str, &tag);
453 *p = SysAllocString(tag);
454 }else {
455 ERR("GetTagName failed: %08x\n", nsres);
456 *p = NULL;
458 nsAString_Finish(&tag_str);
460 return S_OK;
463 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
465 HTMLElement *This = impl_from_IHTMLElement(iface);
466 IHTMLDOMNode *node;
467 HRESULT hres;
469 TRACE("(%p)->(%p)\n", This, p);
471 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
472 if(FAILED(hres))
473 return hres;
475 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
476 IHTMLDOMNode_Release(node);
477 if(FAILED(hres))
478 *p = NULL;
480 return S_OK;
483 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
485 HTMLElement *This = impl_from_IHTMLElement(iface);
487 TRACE("(%p)->(%p)\n", This, p);
489 if(!This->style) {
490 nsIDOMElementCSSInlineStyle *nselemstyle;
491 nsIDOMCSSStyleDeclaration *nsstyle;
492 nsresult nsres;
493 HRESULT hres;
495 if(!This->nselem) {
496 FIXME("NULL nselem\n");
497 return E_NOTIMPL;
500 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
501 (void**)&nselemstyle);
502 if(NS_FAILED(nsres)) {
503 ERR("Could not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
504 return E_FAIL;
507 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
508 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
509 if(NS_FAILED(nsres)) {
510 ERR("GetStyle failed: %08x\n", nsres);
511 return E_FAIL;
514 hres = HTMLStyle_Create(This, nsstyle, &This->style);
515 nsIDOMCSSStyleDeclaration_Release(nsstyle);
516 if(FAILED(hres))
517 return hres;
520 *p = &This->style->IHTMLStyle_iface;
521 IHTMLStyle_AddRef(*p);
522 return S_OK;
525 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
527 HTMLElement *This = impl_from_IHTMLElement(iface);
528 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
529 return E_NOTIMPL;
532 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
534 HTMLElement *This = impl_from_IHTMLElement(iface);
535 FIXME("(%p)->(%p)\n", This, p);
536 return E_NOTIMPL;
539 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
541 HTMLElement *This = impl_from_IHTMLElement(iface);
543 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
545 return set_node_event(&This->node, EVENTID_CLICK, &v);
548 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
550 HTMLElement *This = impl_from_IHTMLElement(iface);
552 TRACE("(%p)->(%p)\n", This, p);
554 return get_node_event(&This->node, EVENTID_CLICK, p);
557 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
559 HTMLElement *This = impl_from_IHTMLElement(iface);
561 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
563 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
566 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
568 HTMLElement *This = impl_from_IHTMLElement(iface);
570 TRACE("(%p)->(%p)\n", This, p);
572 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
575 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
577 HTMLElement *This = impl_from_IHTMLElement(iface);
579 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
581 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
584 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
586 HTMLElement *This = impl_from_IHTMLElement(iface);
588 TRACE("(%p)->(%p)\n", This, p);
590 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
593 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
595 HTMLElement *This = impl_from_IHTMLElement(iface);
597 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
599 return set_node_event(&This->node, EVENTID_KEYUP, &v);
602 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
604 HTMLElement *This = impl_from_IHTMLElement(iface);
605 FIXME("(%p)->(%p)\n", This, p);
606 return E_NOTIMPL;
609 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
611 HTMLElement *This = impl_from_IHTMLElement(iface);
612 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
613 return E_NOTIMPL;
616 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
618 HTMLElement *This = impl_from_IHTMLElement(iface);
619 FIXME("(%p)->(%p)\n", This, p);
620 return E_NOTIMPL;
623 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
625 HTMLElement *This = impl_from_IHTMLElement(iface);
627 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
629 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
632 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
634 HTMLElement *This = impl_from_IHTMLElement(iface);
636 TRACE("(%p)->(%p)\n", This, p);
638 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
641 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
643 HTMLElement *This = impl_from_IHTMLElement(iface);
645 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
647 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
650 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
652 HTMLElement *This = impl_from_IHTMLElement(iface);
654 TRACE("(%p)->(%p)\n", This, p);
656 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
659 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
661 HTMLElement *This = impl_from_IHTMLElement(iface);
663 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
665 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
668 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
670 HTMLElement *This = impl_from_IHTMLElement(iface);
672 TRACE("(%p)->(%p)\n", This, p);
674 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
677 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
679 HTMLElement *This = impl_from_IHTMLElement(iface);
681 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
683 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
686 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
688 HTMLElement *This = impl_from_IHTMLElement(iface);
690 TRACE("(%p)->(%p)\n", This, p);
692 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
695 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
697 HTMLElement *This = impl_from_IHTMLElement(iface);
699 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
701 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
704 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
706 HTMLElement *This = impl_from_IHTMLElement(iface);
708 TRACE("(%p)->(%p)\n", This, p);
710 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
713 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
715 HTMLElement *This = impl_from_IHTMLElement(iface);
717 TRACE("(%p)->(%p)\n", This, p);
719 if(!p)
720 return E_POINTER;
722 if(This->node.vtbl->get_document)
723 return This->node.vtbl->get_document(&This->node, p);
725 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
726 IDispatch_AddRef(*p);
727 return S_OK;
730 static const WCHAR titleW[] = {'t','i','t','l','e',0};
732 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
734 HTMLElement *This = impl_from_IHTMLElement(iface);
735 nsAString title_str;
736 nsresult nsres;
738 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
740 if(!This->nselem) {
741 VARIANT *var;
742 HRESULT hres;
744 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
745 if(FAILED(hres))
746 return hres;
748 VariantClear(var);
749 V_VT(var) = VT_BSTR;
750 V_BSTR(var) = v ? SysAllocString(v) : NULL;
751 return S_OK;
754 nsAString_InitDepend(&title_str, v);
755 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
756 nsAString_Finish(&title_str);
757 if(NS_FAILED(nsres))
758 ERR("SetTitle failed: %08x\n", nsres);
760 return S_OK;
763 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
765 HTMLElement *This = impl_from_IHTMLElement(iface);
766 nsAString title_str;
767 nsresult nsres;
769 TRACE("(%p)->(%p)\n", This, p);
771 if(!This->nselem) {
772 VARIANT *var;
773 HRESULT hres;
775 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
776 if(hres == DISP_E_UNKNOWNNAME) {
777 *p = NULL;
778 }else if(V_VT(var) != VT_BSTR) {
779 FIXME("title = %s\n", debugstr_variant(var));
780 return E_FAIL;
781 }else {
782 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
785 return S_OK;
788 nsAString_Init(&title_str, NULL);
789 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
790 if(NS_SUCCEEDED(nsres)) {
791 const PRUnichar *title;
793 nsAString_GetData(&title_str, &title);
794 *p = *title ? SysAllocString(title) : NULL;
795 }else {
796 ERR("GetTitle failed: %08x\n", nsres);
797 return E_FAIL;
800 return S_OK;
803 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
805 HTMLElement *This = impl_from_IHTMLElement(iface);
806 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
807 return E_NOTIMPL;
810 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
812 HTMLElement *This = impl_from_IHTMLElement(iface);
813 FIXME("(%p)->(%p)\n", This, p);
814 return E_NOTIMPL;
817 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
819 HTMLElement *This = impl_from_IHTMLElement(iface);
821 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
823 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
826 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
828 HTMLElement *This = impl_from_IHTMLElement(iface);
830 TRACE("(%p)->(%p)\n", This, p);
832 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
835 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
837 HTMLElement *This = impl_from_IHTMLElement(iface);
838 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
839 return E_NOTIMPL;
842 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
843 VARIANT_BOOL *pfResult)
845 HTMLElement *This = impl_from_IHTMLElement(iface);
846 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
847 return E_NOTIMPL;
850 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
852 HTMLElement *This = impl_from_IHTMLElement(iface);
853 FIXME("(%p)->(%p)\n", This, p);
854 return E_NOTIMPL;
857 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
859 HTMLElement *This = impl_from_IHTMLElement(iface);
860 FIXME("(%p)->(%p)\n", This, p);
861 return E_NOTIMPL;
864 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
866 HTMLElement *This = impl_from_IHTMLElement(iface);
867 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
868 return E_NOTIMPL;
871 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
873 HTMLElement *This = impl_from_IHTMLElement(iface);
874 FIXME("(%p)->(%p)\n", This, p);
875 return E_NOTIMPL;
878 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
880 HTMLElement *This = impl_from_IHTMLElement(iface);
881 PRInt32 off_left = 0;
882 nsresult nsres;
884 TRACE("(%p)->(%p)\n", This, p);
886 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, &off_left);
887 if(NS_FAILED(nsres)) {
888 ERR("GetOffsetLeft failed: %08x\n", nsres);
889 return E_FAIL;
892 *p = off_left;
893 return S_OK;
896 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
898 HTMLElement *This = impl_from_IHTMLElement(iface);
899 PRInt32 top = 0;
900 nsresult nsres;
902 TRACE("(%p)->(%p)\n", This, p);
904 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, &top);
905 if(NS_FAILED(nsres)) {
906 ERR("GetOffsetTop failed: %08x\n", nsres);
907 return E_FAIL;
910 *p = top;
911 return S_OK;
914 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
916 HTMLElement *This = impl_from_IHTMLElement(iface);
917 PRInt32 offset = 0;
918 nsresult nsres;
920 TRACE("(%p)->(%p)\n", This, p);
922 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, &offset);
923 if(NS_FAILED(nsres)) {
924 ERR("GetOffsetWidth failed: %08x\n", nsres);
925 return E_FAIL;
928 *p = offset;
929 return S_OK;
932 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
934 HTMLElement *This = impl_from_IHTMLElement(iface);
935 PRInt32 offset = 0;
936 nsresult nsres;
938 TRACE("(%p)->(%p)\n", This, p);
940 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, &offset);
941 if(NS_FAILED(nsres)) {
942 ERR("GetOffsetHeight failed: %08x\n", nsres);
943 return E_FAIL;
946 *p = offset;
947 return S_OK;
950 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
952 HTMLElement *This = impl_from_IHTMLElement(iface);
953 nsIDOMElement *nsparent;
954 nsresult nsres;
955 HRESULT hres;
957 TRACE("(%p)->(%p)\n", This, p);
959 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
960 if(NS_FAILED(nsres)) {
961 ERR("GetOffsetParent failed: %08x\n", nsres);
962 return E_FAIL;
965 if(nsparent) {
966 HTMLDOMNode *node;
968 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
969 nsIDOMElement_Release(nsparent);
970 if(FAILED(hres))
971 return hres;
973 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
974 }else {
975 *p = NULL;
976 hres = S_OK;
979 return hres;
982 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
984 HTMLElement *This = impl_from_IHTMLElement(iface);
985 nsAString html_str;
986 nsresult nsres;
988 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
990 if(!This->nselem) {
991 FIXME("NULL nselem\n");
992 return E_NOTIMPL;
995 nsAString_InitDepend(&html_str, v);
996 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
997 nsAString_Finish(&html_str);
998 if(NS_FAILED(nsres)) {
999 FIXME("SetInnerHtml failed %08x\n", nsres);
1000 return E_FAIL;
1003 return S_OK;
1006 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1008 HTMLElement *This = impl_from_IHTMLElement(iface);
1009 nsAString html_str;
1010 nsresult nsres;
1012 TRACE("(%p)->(%p)\n", This, p);
1014 if(!This->nselem) {
1015 FIXME("NULL nselem\n");
1016 return E_NOTIMPL;
1019 nsAString_Init(&html_str, NULL);
1020 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
1021 if(NS_SUCCEEDED(nsres)) {
1022 const PRUnichar *html;
1024 nsAString_GetData(&html_str, &html);
1025 *p = *html ? SysAllocString(html) : NULL;
1026 }else {
1027 FIXME("SetInnerHtml failed %08x\n", nsres);
1028 *p = NULL;
1031 nsAString_Finish(&html_str);
1032 return S_OK;
1035 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1037 HTMLElement *This = impl_from_IHTMLElement(iface);
1038 nsIDOMNode *nschild, *tmp;
1039 nsIDOMText *text_node;
1040 nsAString text_str;
1041 nsresult nsres;
1043 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1045 while(1) {
1046 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1047 if(NS_FAILED(nsres)) {
1048 ERR("GetLastChild failed: %08x\n", nsres);
1049 return E_FAIL;
1051 if(!nschild)
1052 break;
1054 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1055 nsIDOMNode_Release(nschild);
1056 if(NS_FAILED(nsres)) {
1057 ERR("RemoveChild failed: %08x\n", nsres);
1058 return E_FAIL;
1060 nsIDOMNode_Release(tmp);
1063 nsAString_InitDepend(&text_str, v);
1064 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1065 nsAString_Finish(&text_str);
1066 if(NS_FAILED(nsres)) {
1067 ERR("CreateTextNode failed: %08x\n", nsres);
1068 return E_FAIL;
1071 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1072 if(NS_FAILED(nsres)) {
1073 ERR("AppendChild failed: %08x\n", nsres);
1074 return E_FAIL;
1077 nsIDOMNode_Release(tmp);
1078 return S_OK;
1081 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1083 HTMLElement *This = impl_from_IHTMLElement(iface);
1085 TRACE("(%p)->(%p)\n", This, p);
1087 return get_node_text(&This->node, p);
1090 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1092 HTMLElement *This = impl_from_IHTMLElement(iface);
1094 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1096 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1099 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1101 HTMLElement *This = impl_from_IHTMLElement(iface);
1102 nsAString html_str;
1103 HRESULT hres;
1105 WARN("(%p)->(%p) semi-stub\n", This, p);
1107 nsAString_Init(&html_str, NULL);
1108 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1109 if(SUCCEEDED(hres)) {
1110 const PRUnichar *html;
1112 nsAString_GetData(&html_str, &html);
1113 *p = SysAllocString(html);
1114 if(!*p)
1115 hres = E_OUTOFMEMORY;
1118 nsAString_Finish(&html_str);
1120 TRACE("ret %s\n", debugstr_w(*p));
1121 return hres;
1124 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1126 HTMLElement *This = impl_from_IHTMLElement(iface);
1127 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1128 return E_NOTIMPL;
1131 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1133 HTMLElement *This = impl_from_IHTMLElement(iface);
1134 FIXME("(%p)->(%p)\n", This, p);
1135 return E_NOTIMPL;
1138 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1140 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1141 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1142 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1143 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1144 nsresult nsres;
1146 if (!strcmpiW(where, wszBeforeBegin))
1148 nsIDOMNode *unused;
1149 nsIDOMNode *parent;
1150 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1151 if (!parent) return E_INVALIDARG;
1152 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1153 if (unused) nsIDOMNode_Release(unused);
1154 nsIDOMNode_Release(parent);
1156 else if (!strcmpiW(where, wszAfterBegin))
1158 nsIDOMNode *unused;
1159 nsIDOMNode *first_child;
1160 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1161 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1162 if (unused) nsIDOMNode_Release(unused);
1163 if (first_child) nsIDOMNode_Release(first_child);
1165 else if (!strcmpiW(where, wszBeforeEnd))
1167 nsIDOMNode *unused;
1168 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1169 if (unused) nsIDOMNode_Release(unused);
1171 else if (!strcmpiW(where, wszAfterEnd))
1173 nsIDOMNode *unused;
1174 nsIDOMNode *next_sibling;
1175 nsIDOMNode *parent;
1176 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1177 if (!parent) return E_INVALIDARG;
1179 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1180 if (next_sibling)
1182 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1183 nsIDOMNode_Release(next_sibling);
1185 else
1186 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1187 nsIDOMNode_Release(parent);
1188 if (unused) nsIDOMNode_Release(unused);
1190 else
1192 ERR("invalid where: %s\n", debugstr_w(where));
1193 return E_INVALIDARG;
1196 if (NS_FAILED(nsres))
1197 return E_FAIL;
1198 else
1199 return S_OK;
1202 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1203 BSTR html)
1205 HTMLElement *This = impl_from_IHTMLElement(iface);
1206 nsIDOMRange *range;
1207 nsIDOMNSRange *nsrange;
1208 nsIDOMNode *nsnode;
1209 nsAString ns_html;
1210 nsresult nsres;
1211 HRESULT hr;
1213 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1215 if(!This->node.doc->nsdoc) {
1216 WARN("NULL nsdoc\n");
1217 return E_UNEXPECTED;
1220 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1221 if(NS_FAILED(nsres))
1223 ERR("CreateRange failed: %08x\n", nsres);
1224 return E_FAIL;
1227 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1229 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
1230 nsIDOMRange_Release(range);
1231 if(NS_FAILED(nsres))
1233 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
1234 return E_FAIL;
1237 nsAString_InitDepend(&ns_html, html);
1239 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1240 nsIDOMNSRange_Release(nsrange);
1241 nsAString_Finish(&ns_html);
1243 if(NS_FAILED(nsres) || !nsnode)
1245 ERR("CreateTextNode failed: %08x\n", nsres);
1246 return E_FAIL;
1249 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1250 nsIDOMNode_Release(nsnode);
1252 return hr;
1255 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1256 BSTR text)
1258 HTMLElement *This = impl_from_IHTMLElement(iface);
1259 nsIDOMNode *nsnode;
1260 nsAString ns_text;
1261 nsresult nsres;
1262 HRESULT hr;
1264 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1266 if(!This->node.doc->nsdoc) {
1267 WARN("NULL nsdoc\n");
1268 return E_UNEXPECTED;
1272 nsAString_InitDepend(&ns_text, text);
1273 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1274 nsAString_Finish(&ns_text);
1276 if(NS_FAILED(nsres) || !nsnode)
1278 ERR("CreateTextNode failed: %08x\n", nsres);
1279 return E_FAIL;
1282 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1283 nsIDOMNode_Release(nsnode);
1285 return hr;
1288 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1290 HTMLElement *This = impl_from_IHTMLElement(iface);
1291 FIXME("(%p)->(%p)\n", This, p);
1292 return E_NOTIMPL;
1295 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1297 HTMLElement *This = impl_from_IHTMLElement(iface);
1298 FIXME("(%p)->(%p)\n", This, p);
1299 return E_NOTIMPL;
1302 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1304 HTMLElement *This = impl_from_IHTMLElement(iface);
1306 TRACE("(%p)\n", This);
1308 return call_fire_event(&This->node, EVENTID_CLICK);
1311 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1312 IHTMLFiltersCollection **p)
1314 HTMLElement *This = impl_from_IHTMLElement(iface);
1315 TRACE("(%p)->(%p)\n", This, p);
1317 if(!p)
1318 return E_POINTER;
1320 *p = HTMLFiltersCollection_Create();
1322 return S_OK;
1325 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1327 HTMLElement *This = impl_from_IHTMLElement(iface);
1328 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1329 return E_NOTIMPL;
1332 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1334 HTMLElement *This = impl_from_IHTMLElement(iface);
1335 FIXME("(%p)->(%p)\n", This, p);
1336 return E_NOTIMPL;
1339 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1341 HTMLElement *This = impl_from_IHTMLElement(iface);
1342 FIXME("(%p)->(%p)\n", This, String);
1343 return E_NOTIMPL;
1346 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1348 HTMLElement *This = impl_from_IHTMLElement(iface);
1349 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1350 return E_NOTIMPL;
1353 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1355 HTMLElement *This = impl_from_IHTMLElement(iface);
1356 FIXME("(%p)->(%p)\n", This, p);
1357 return E_NOTIMPL;
1360 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1362 HTMLElement *This = impl_from_IHTMLElement(iface);
1363 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1364 return E_NOTIMPL;
1367 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1369 HTMLElement *This = impl_from_IHTMLElement(iface);
1370 FIXME("(%p)->(%p)\n", This, p);
1371 return E_NOTIMPL;
1374 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1376 HTMLElement *This = impl_from_IHTMLElement(iface);
1377 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1378 return E_NOTIMPL;
1381 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1383 HTMLElement *This = impl_from_IHTMLElement(iface);
1384 FIXME("(%p)->(%p)\n", This, p);
1385 return E_NOTIMPL;
1388 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1390 HTMLElement *This = impl_from_IHTMLElement(iface);
1391 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1392 return E_NOTIMPL;
1395 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1397 HTMLElement *This = impl_from_IHTMLElement(iface);
1398 FIXME("(%p)->(%p)\n", This, p);
1399 return E_NOTIMPL;
1402 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1404 HTMLElement *This = impl_from_IHTMLElement(iface);
1405 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1406 return E_NOTIMPL;
1409 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1411 HTMLElement *This = impl_from_IHTMLElement(iface);
1412 FIXME("(%p)->(%p)\n", This, p);
1413 return E_NOTIMPL;
1416 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1418 HTMLElement *This = impl_from_IHTMLElement(iface);
1419 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1420 return E_NOTIMPL;
1423 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1425 HTMLElement *This = impl_from_IHTMLElement(iface);
1426 FIXME("(%p)->(%p)\n", This, p);
1427 return E_NOTIMPL;
1430 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1432 HTMLElement *This = impl_from_IHTMLElement(iface);
1433 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1434 return E_NOTIMPL;
1437 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1439 HTMLElement *This = impl_from_IHTMLElement(iface);
1440 FIXME("(%p)->(%p)\n", This, p);
1441 return E_NOTIMPL;
1444 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1446 HTMLElement *This = impl_from_IHTMLElement(iface);
1447 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1448 return E_NOTIMPL;
1451 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1453 HTMLElement *This = impl_from_IHTMLElement(iface);
1454 FIXME("(%p)->(%p)\n", This, p);
1455 return E_NOTIMPL;
1458 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1460 HTMLElement *This = impl_from_IHTMLElement(iface);
1461 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1462 return E_NOTIMPL;
1465 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1467 HTMLElement *This = impl_from_IHTMLElement(iface);
1468 FIXME("(%p)->(%p)\n", This, p);
1469 return E_NOTIMPL;
1472 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1474 HTMLElement *This = impl_from_IHTMLElement(iface);
1475 nsIDOMNodeList *nsnode_list;
1476 nsresult nsres;
1478 TRACE("(%p)->(%p)\n", This, p);
1480 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1481 if(NS_FAILED(nsres)) {
1482 ERR("GetChildNodes failed: %08x\n", nsres);
1483 return E_FAIL;
1486 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc,
1487 (IUnknown*)&This->IHTMLElement_iface, nsnode_list);
1489 nsIDOMNodeList_Release(nsnode_list);
1490 return S_OK;
1493 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1495 HTMLElement *This = impl_from_IHTMLElement(iface);
1497 TRACE("(%p)->(%p)\n", This, p);
1499 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1500 return S_OK;
1503 static const IHTMLElementVtbl HTMLElementVtbl = {
1504 HTMLElement_QueryInterface,
1505 HTMLElement_AddRef,
1506 HTMLElement_Release,
1507 HTMLElement_GetTypeInfoCount,
1508 HTMLElement_GetTypeInfo,
1509 HTMLElement_GetIDsOfNames,
1510 HTMLElement_Invoke,
1511 HTMLElement_setAttribute,
1512 HTMLElement_getAttribute,
1513 HTMLElement_removeAttribute,
1514 HTMLElement_put_className,
1515 HTMLElement_get_className,
1516 HTMLElement_put_id,
1517 HTMLElement_get_id,
1518 HTMLElement_get_tagName,
1519 HTMLElement_get_parentElement,
1520 HTMLElement_get_style,
1521 HTMLElement_put_onhelp,
1522 HTMLElement_get_onhelp,
1523 HTMLElement_put_onclick,
1524 HTMLElement_get_onclick,
1525 HTMLElement_put_ondblclick,
1526 HTMLElement_get_ondblclick,
1527 HTMLElement_put_onkeydown,
1528 HTMLElement_get_onkeydown,
1529 HTMLElement_put_onkeyup,
1530 HTMLElement_get_onkeyup,
1531 HTMLElement_put_onkeypress,
1532 HTMLElement_get_onkeypress,
1533 HTMLElement_put_onmouseout,
1534 HTMLElement_get_onmouseout,
1535 HTMLElement_put_onmouseover,
1536 HTMLElement_get_onmouseover,
1537 HTMLElement_put_onmousemove,
1538 HTMLElement_get_onmousemove,
1539 HTMLElement_put_onmousedown,
1540 HTMLElement_get_onmousedown,
1541 HTMLElement_put_onmouseup,
1542 HTMLElement_get_onmouseup,
1543 HTMLElement_get_document,
1544 HTMLElement_put_title,
1545 HTMLElement_get_title,
1546 HTMLElement_put_language,
1547 HTMLElement_get_language,
1548 HTMLElement_put_onselectstart,
1549 HTMLElement_get_onselectstart,
1550 HTMLElement_scrollIntoView,
1551 HTMLElement_contains,
1552 HTMLElement_get_sourceIndex,
1553 HTMLElement_get_recordNumber,
1554 HTMLElement_put_lang,
1555 HTMLElement_get_lang,
1556 HTMLElement_get_offsetLeft,
1557 HTMLElement_get_offsetTop,
1558 HTMLElement_get_offsetWidth,
1559 HTMLElement_get_offsetHeight,
1560 HTMLElement_get_offsetParent,
1561 HTMLElement_put_innerHTML,
1562 HTMLElement_get_innerHTML,
1563 HTMLElement_put_innerText,
1564 HTMLElement_get_innerText,
1565 HTMLElement_put_outerHTML,
1566 HTMLElement_get_outerHTML,
1567 HTMLElement_put_outerText,
1568 HTMLElement_get_outerText,
1569 HTMLElement_insertAdjacentHTML,
1570 HTMLElement_insertAdjacentText,
1571 HTMLElement_get_parentTextEdit,
1572 HTMLElement_get_isTextEdit,
1573 HTMLElement_click,
1574 HTMLElement_get_filters,
1575 HTMLElement_put_ondragstart,
1576 HTMLElement_get_ondragstart,
1577 HTMLElement_toString,
1578 HTMLElement_put_onbeforeupdate,
1579 HTMLElement_get_onbeforeupdate,
1580 HTMLElement_put_onafterupdate,
1581 HTMLElement_get_onafterupdate,
1582 HTMLElement_put_onerrorupdate,
1583 HTMLElement_get_onerrorupdate,
1584 HTMLElement_put_onrowexit,
1585 HTMLElement_get_onrowexit,
1586 HTMLElement_put_onrowenter,
1587 HTMLElement_get_onrowenter,
1588 HTMLElement_put_ondatasetchanged,
1589 HTMLElement_get_ondatasetchanged,
1590 HTMLElement_put_ondataavailable,
1591 HTMLElement_get_ondataavailable,
1592 HTMLElement_put_ondatasetcomplete,
1593 HTMLElement_get_ondatasetcomplete,
1594 HTMLElement_put_onfilterchange,
1595 HTMLElement_get_onfilterchange,
1596 HTMLElement_get_children,
1597 HTMLElement_get_all
1600 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1602 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1605 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1607 return CONTAINING_RECORD(iface, HTMLElement, node);
1610 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1612 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1614 *ppv = NULL;
1616 if(IsEqualGUID(&IID_IUnknown, riid)) {
1617 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1618 *ppv = &This->IHTMLElement_iface;
1619 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1620 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1621 *ppv = &This->IHTMLElement_iface;
1622 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1623 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1624 *ppv = &This->IHTMLElement_iface;
1625 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1626 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1627 *ppv = &This->IHTMLElement2_iface;
1628 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1629 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1630 *ppv = &This->IHTMLElement3_iface;
1631 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1632 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1633 *ppv = &This->IHTMLElement4_iface;
1634 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1635 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1636 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1639 if(*ppv) {
1640 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1641 return S_OK;
1644 return HTMLDOMNode_QI(&This->node, riid, ppv);
1647 void HTMLElement_destructor(HTMLDOMNode *iface)
1649 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1651 ConnectionPointContainer_Destroy(&This->cp_container);
1653 if(This->nselem)
1654 nsIDOMHTMLElement_Release(This->nselem);
1655 if(This->style) {
1656 This->style->elem = NULL;
1657 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1659 if(This->attrs) {
1660 HTMLDOMAttribute *attr;
1662 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1663 attr->elem = NULL;
1665 This->attrs->elem = NULL;
1666 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1669 heap_free(This->filter);
1671 HTMLDOMNode_destructor(&This->node);
1674 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1676 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1677 HTMLElement *new_elem;
1678 HRESULT hres;
1680 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1681 if(FAILED(hres))
1682 return hres;
1684 IHTMLElement_AddRef(&new_elem->IHTMLElement_iface);
1685 *ret = &new_elem->node;
1686 return S_OK;
1689 static const NodeImplVtbl HTMLElementImplVtbl = {
1690 HTMLElement_QI,
1691 HTMLElement_destructor,
1692 HTMLElement_clone,
1693 HTMLElement_get_attr_col
1696 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1698 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1701 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1702 DWORD grfdex, DISPID *pid)
1704 HTMLElement *This = impl_from_DispatchEx(dispex);
1706 if(This->node.vtbl->get_dispid)
1707 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1709 return DISP_E_UNKNOWNNAME;
1712 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1713 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1714 IServiceProvider *caller)
1716 HTMLElement *This = impl_from_DispatchEx(dispex);
1718 if(This->node.vtbl->invoke)
1719 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1720 params, res, ei, caller);
1722 ERR("(%p): element has no invoke method\n", This);
1723 return E_NOTIMPL;
1726 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1728 HTMLElement *This = impl_from_DispatchEx(dispex);
1729 nsIDOMNamedNodeMap *attrs;
1730 nsIDOMNode *node;
1731 nsAString nsstr;
1732 const PRUnichar *str;
1733 BSTR name;
1734 VARIANT value;
1735 unsigned i;
1736 PRUint32 len;
1737 DISPID id;
1738 nsresult nsres;
1739 HRESULT hres;
1741 if(!This->nselem)
1742 return S_FALSE;
1744 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1745 if(NS_FAILED(nsres))
1746 return E_FAIL;
1748 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1749 if(NS_FAILED(nsres)) {
1750 nsIDOMNamedNodeMap_Release(attrs);
1751 return E_FAIL;
1754 nsAString_Init(&nsstr, NULL);
1755 for(i=0; i<len; i++) {
1756 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1757 if(NS_FAILED(nsres))
1758 continue;
1760 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1761 if(NS_FAILED(nsres)) {
1762 nsIDOMNode_Release(node);
1763 continue;
1766 nsAString_GetData(&nsstr, &str);
1767 name = SysAllocString(str);
1768 if(!name) {
1769 nsIDOMNode_Release(node);
1770 continue;
1773 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1774 if(hres != DISP_E_UNKNOWNNAME) {
1775 nsIDOMNode_Release(node);
1776 SysFreeString(name);
1777 continue;
1780 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1781 nsIDOMNode_Release(node);
1782 if(NS_FAILED(nsres)) {
1783 SysFreeString(name);
1784 continue;
1787 nsAString_GetData(&nsstr, &str);
1788 V_VT(&value) = VT_BSTR;
1789 if(*str) {
1790 V_BSTR(&value) = SysAllocString(str);
1791 if(!V_BSTR(&value)) {
1792 SysFreeString(name);
1793 continue;
1795 } else
1796 V_BSTR(&value) = NULL;
1798 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1799 SysFreeString(name);
1800 VariantClear(&value);
1802 nsAString_Finish(&nsstr);
1804 nsIDOMNamedNodeMap_Release(attrs);
1805 return S_OK;
1808 static const tid_t HTMLElement_iface_tids[] = {
1809 HTMLELEMENT_TIDS,
1813 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1814 NULL,
1815 HTMLElement_get_dispid,
1816 HTMLElement_invoke,
1817 HTMLElement_populate_props
1820 static dispex_static_data_t HTMLElement_dispex = {
1821 &HTMLElement_dispex_vtbl,
1822 DispHTMLUnknownElement_tid,
1823 NULL,
1824 HTMLElement_iface_tids
1827 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1829 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1831 HTMLElement2_Init(This);
1832 HTMLElement3_Init(This);
1834 if(dispex_data && !dispex_data->vtbl)
1835 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1836 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1837 dispex_data ? dispex_data : &HTMLElement_dispex);
1839 if(nselem)
1840 nsIDOMHTMLElement_AddRef(nselem);
1841 This->nselem = nselem;
1843 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1845 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1848 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1850 nsIDOMHTMLElement *nselem;
1851 nsAString class_name_str;
1852 const PRUnichar *class_name;
1853 const tag_desc_t *tag;
1854 HTMLElement *elem;
1855 nsresult nsres;
1856 HRESULT hres;
1858 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1859 if(NS_FAILED(nsres))
1860 return E_FAIL;
1862 nsAString_Init(&class_name_str, NULL);
1863 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1865 nsAString_GetData(&class_name_str, &class_name);
1867 tag = get_tag_desc(class_name);
1868 if(tag) {
1869 hres = tag->constructor(doc, nselem, &elem);
1870 }else if(use_generic) {
1871 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1872 }else {
1873 elem = heap_alloc_zero(sizeof(HTMLElement));
1874 if(elem) {
1875 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1876 elem->node.vtbl = &HTMLElementImplVtbl;
1877 hres = S_OK;
1878 }else {
1879 hres = E_OUTOFMEMORY;
1883 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1885 nsIDOMElement_Release(nselem);
1886 nsAString_Finish(&class_name_str);
1887 if(FAILED(hres))
1888 return hres;
1890 *ret = elem;
1891 return S_OK;
1894 /* interface IHTMLFiltersCollection */
1895 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1897 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1899 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1901 if(IsEqualGUID(&IID_IUnknown, riid)) {
1902 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1903 *ppv = &This->IHTMLFiltersCollection_iface;
1904 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1905 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1906 *ppv = &This->IHTMLFiltersCollection_iface;
1907 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1908 return *ppv ? S_OK : E_NOINTERFACE;
1911 if(*ppv) {
1912 IUnknown_AddRef((IUnknown*)*ppv);
1913 return S_OK;
1916 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1917 return E_NOINTERFACE;
1920 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1922 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1923 LONG ref = InterlockedIncrement(&This->ref);
1925 TRACE("(%p) ref=%d\n", This, ref);
1927 return ref;
1930 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1932 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1933 LONG ref = InterlockedDecrement(&This->ref);
1935 TRACE("(%p) ref=%d\n", This, ref);
1937 if(!ref)
1939 heap_free(This);
1942 return ref;
1945 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1947 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1948 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1951 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1952 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1954 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1955 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1958 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1959 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1960 LCID lcid, DISPID *rgDispId)
1962 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1963 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1964 lcid, rgDispId);
1967 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1968 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1969 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1971 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1972 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1973 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1976 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1978 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1980 if(!p)
1981 return E_POINTER;
1983 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1984 *p = 0;
1986 return S_OK;
1989 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1991 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1992 FIXME("(%p)->(%p)\n", This, p);
1993 return E_NOTIMPL;
1996 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1998 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1999 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2000 return E_NOTIMPL;
2003 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2004 HTMLFiltersCollection_QueryInterface,
2005 HTMLFiltersCollection_AddRef,
2006 HTMLFiltersCollection_Release,
2007 HTMLFiltersCollection_GetTypeInfoCount,
2008 HTMLFiltersCollection_GetTypeInfo,
2009 HTMLFiltersCollection_GetIDsOfNames,
2010 HTMLFiltersCollection_Invoke,
2011 HTMLFiltersCollection_get_length,
2012 HTMLFiltersCollection_get__newEnum,
2013 HTMLFiltersCollection_item
2016 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2018 WCHAR *ptr;
2019 int idx = 0;
2021 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2022 idx = idx*10 + (*ptr-'0');
2023 if(*ptr)
2024 return DISP_E_UNKNOWNNAME;
2026 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2027 TRACE("ret %x\n", *dispid);
2028 return S_OK;
2031 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2032 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2034 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2036 V_VT(res) = VT_DISPATCH;
2037 V_DISPATCH(res) = NULL;
2039 FIXME("always returning NULL\n");
2041 return S_OK;
2044 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2045 NULL,
2046 HTMLFiltersCollection_get_dispid,
2047 HTMLFiltersCollection_invoke,
2048 NULL
2051 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2052 IHTMLFiltersCollection_tid,
2055 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2056 &HTMLFiltersCollection_dispex_vtbl,
2057 IHTMLFiltersCollection_tid,
2058 NULL,
2059 HTMLFiltersCollection_iface_tids
2062 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2064 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2066 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2067 ret->ref = 1;
2069 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2070 &HTMLFiltersCollection_dispex);
2072 return &ret->IHTMLFiltersCollection_iface;
2075 /* interface IHTMLAttributeCollection */
2076 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2078 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2081 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2083 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2085 *ppv = NULL;
2087 if(IsEqualGUID(&IID_IUnknown, riid)) {
2088 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2089 *ppv = &This->IHTMLAttributeCollection_iface;
2090 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2091 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2092 *ppv = &This->IHTMLAttributeCollection_iface;
2093 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2094 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2095 *ppv = &This->IHTMLAttributeCollection2_iface;
2096 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2097 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2098 *ppv = &This->IHTMLAttributeCollection3_iface;
2099 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2100 return *ppv ? S_OK : E_NOINTERFACE;
2103 if(*ppv) {
2104 IUnknown_AddRef((IUnknown*)*ppv);
2105 return S_OK;
2108 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2109 return E_NOINTERFACE;
2112 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2114 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2115 LONG ref = InterlockedIncrement(&This->ref);
2117 TRACE("(%p) ref=%d\n", This, ref);
2119 return ref;
2122 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2124 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2125 LONG ref = InterlockedDecrement(&This->ref);
2127 TRACE("(%p) ref=%d\n", This, ref);
2129 if(!ref) {
2130 while(!list_empty(&This->attrs)) {
2131 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2133 list_remove(&attr->entry);
2134 attr->elem = NULL;
2135 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2138 heap_free(This);
2141 return ref;
2144 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2146 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2147 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2150 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2151 LCID lcid, ITypeInfo **ppTInfo)
2153 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2154 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2157 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2158 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2160 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2161 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2162 lcid, rgDispId);
2165 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2166 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2167 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2169 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2170 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2171 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2174 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2176 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2177 DISPID id = DISPID_STARTENUM;
2178 LONG len = -1;
2179 HRESULT hres;
2181 FIXME("filter non-enumerable attributes out\n");
2183 while(1) {
2184 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2185 if(FAILED(hres))
2186 return hres;
2187 else if(hres == S_FALSE)
2188 break;
2190 len++;
2191 if(len == *idx)
2192 break;
2195 if(dispid) {
2196 *dispid = id;
2197 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2200 *idx = len+1;
2201 return S_OK;
2204 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2206 HRESULT hres;
2208 if(name[0]>='0' && name[0]<='9') {
2209 WCHAR *end_ptr;
2210 LONG idx;
2212 idx = strtoulW(name, &end_ptr, 10);
2213 if(!*end_ptr) {
2214 hres = get_attr_dispid_by_idx(This, &idx, id);
2215 if(SUCCEEDED(hres))
2216 return hres;
2220 if(!This->elem) {
2221 WARN("NULL elem\n");
2222 return E_UNEXPECTED;
2225 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2226 name, fdexNameCaseInsensitive, id);
2227 return hres;
2230 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2232 HTMLDOMAttribute *iter;
2233 LONG pos = 0;
2234 HRESULT hres;
2236 *attr = NULL;
2237 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2238 if(iter->dispid == id) {
2239 *attr = iter;
2240 break;
2242 pos++;
2245 if(!*attr) {
2246 if(!This->elem) {
2247 WARN("NULL elem\n");
2248 return E_UNEXPECTED;
2251 pos++;
2252 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2253 if(FAILED(hres))
2254 return hres;
2257 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2258 if(list_pos)
2259 *list_pos = pos;
2260 return S_OK;
2263 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2265 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2266 HRESULT hres;
2268 TRACE("(%p)->(%p)\n", This, p);
2270 *p = -1;
2271 hres = get_attr_dispid_by_idx(This, p, NULL);
2272 return hres;
2275 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2277 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2278 FIXME("(%p)->(%p)\n", This, p);
2279 return E_NOTIMPL;
2282 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2284 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2285 HTMLDOMAttribute *attr;
2286 DISPID id;
2287 HRESULT hres;
2289 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2291 switch(V_VT(name)) {
2292 case VT_I4:
2293 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2294 break;
2295 case VT_BSTR:
2296 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2297 break;
2298 default:
2299 FIXME("unsupported name %s\n", debugstr_variant(name));
2300 hres = E_NOTIMPL;
2302 if(hres == DISP_E_UNKNOWNNAME)
2303 return E_INVALIDARG;
2304 if(FAILED(hres))
2305 return hres;
2307 hres = get_domattr(This, id, NULL, &attr);
2308 if(FAILED(hres))
2309 return hres;
2311 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2312 return S_OK;
2315 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2316 HTMLAttributeCollection_QueryInterface,
2317 HTMLAttributeCollection_AddRef,
2318 HTMLAttributeCollection_Release,
2319 HTMLAttributeCollection_GetTypeInfoCount,
2320 HTMLAttributeCollection_GetTypeInfo,
2321 HTMLAttributeCollection_GetIDsOfNames,
2322 HTMLAttributeCollection_Invoke,
2323 HTMLAttributeCollection_get_length,
2324 HTMLAttributeCollection__newEnum,
2325 HTMLAttributeCollection_item
2328 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2330 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2333 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2335 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2336 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2339 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2341 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2342 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2345 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2347 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2348 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2351 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2353 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2354 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2357 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2358 LCID lcid, ITypeInfo **ppTInfo)
2360 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2361 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2364 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2365 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2367 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2368 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2369 lcid, rgDispId);
2372 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2373 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2374 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2376 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2377 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2378 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2381 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2382 IHTMLDOMAttribute **newretNode)
2384 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2385 HTMLDOMAttribute *attr;
2386 DISPID id;
2387 HRESULT hres;
2389 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2391 hres = get_attr_dispid_by_name(This, bstrName, &id);
2392 if(hres == DISP_E_UNKNOWNNAME) {
2393 *newretNode = NULL;
2394 return S_OK;
2395 } else if(FAILED(hres)) {
2396 return hres;
2399 hres = get_domattr(This, id, NULL, &attr);
2400 if(FAILED(hres))
2401 return hres;
2403 *newretNode = &attr->IHTMLDOMAttribute_iface;
2404 return S_OK;
2407 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2408 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2410 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2411 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2412 return E_NOTIMPL;
2415 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2416 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2418 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2419 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2420 return E_NOTIMPL;
2423 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2424 HTMLAttributeCollection2_QueryInterface,
2425 HTMLAttributeCollection2_AddRef,
2426 HTMLAttributeCollection2_Release,
2427 HTMLAttributeCollection2_GetTypeInfoCount,
2428 HTMLAttributeCollection2_GetTypeInfo,
2429 HTMLAttributeCollection2_GetIDsOfNames,
2430 HTMLAttributeCollection2_Invoke,
2431 HTMLAttributeCollection2_getNamedItem,
2432 HTMLAttributeCollection2_setNamedItem,
2433 HTMLAttributeCollection2_removeNamedItem
2436 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2438 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2441 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2443 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2444 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2447 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2449 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2450 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2453 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2455 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2456 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2459 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2461 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2462 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2465 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2466 LCID lcid, ITypeInfo **ppTInfo)
2468 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2469 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2472 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2473 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2475 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2476 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2477 lcid, rgDispId);
2480 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2481 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2482 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2484 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2485 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2486 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2489 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2490 IHTMLDOMAttribute **ppNodeOut)
2492 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2493 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2496 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2497 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2499 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2500 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2501 return E_NOTIMPL;
2504 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2505 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2507 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2508 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2509 return E_NOTIMPL;
2512 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2514 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2515 HTMLDOMAttribute *attr;
2516 DISPID id;
2517 HRESULT hres;
2519 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2521 hres = get_attr_dispid_by_idx(This, &index, &id);
2522 if(hres == DISP_E_UNKNOWNNAME)
2523 return E_INVALIDARG;
2524 if(FAILED(hres))
2525 return hres;
2527 hres = get_domattr(This, id, NULL, &attr);
2528 if(FAILED(hres))
2529 return hres;
2531 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2532 return S_OK;
2535 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2537 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2538 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2541 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2542 HTMLAttributeCollection3_QueryInterface,
2543 HTMLAttributeCollection3_AddRef,
2544 HTMLAttributeCollection3_Release,
2545 HTMLAttributeCollection3_GetTypeInfoCount,
2546 HTMLAttributeCollection3_GetTypeInfo,
2547 HTMLAttributeCollection3_GetIDsOfNames,
2548 HTMLAttributeCollection3_Invoke,
2549 HTMLAttributeCollection3_getNamedItem,
2550 HTMLAttributeCollection3_setNamedItem,
2551 HTMLAttributeCollection3_removeNamedItem,
2552 HTMLAttributeCollection3_item,
2553 HTMLAttributeCollection3_get_length
2556 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2558 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2561 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2563 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2564 HTMLDOMAttribute *attr;
2565 LONG pos;
2566 HRESULT hres;
2568 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2570 hres = get_attr_dispid_by_name(This, name, dispid);
2571 if(FAILED(hres))
2572 return hres;
2574 hres = get_domattr(This, *dispid, &pos, &attr);
2575 if(FAILED(hres))
2576 return hres;
2577 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2579 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2580 return S_OK;
2583 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2584 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2586 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2588 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2590 switch(flags) {
2591 case DISPATCH_PROPERTYGET: {
2592 HTMLDOMAttribute *iter;
2594 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2596 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2597 if(!(--id))
2598 break;
2600 if(id)
2601 return E_INVALIDARG;
2603 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2604 V_VT(res) = VT_DISPATCH;
2605 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2606 return S_OK;
2609 default:
2610 FIXME("unimplemented flags %x\n", flags);
2611 return E_NOTIMPL;
2615 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2616 NULL,
2617 HTMLAttributeCollection_get_dispid,
2618 HTMLAttributeCollection_invoke,
2619 NULL
2622 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2623 IHTMLAttributeCollection_tid,
2624 IHTMLAttributeCollection2_tid,
2625 IHTMLAttributeCollection3_tid,
2629 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2630 &HTMLAttributeCollection_dispex_vtbl,
2631 DispHTMLAttributeCollection_tid,
2632 NULL,
2633 HTMLAttributeCollection_iface_tids
2636 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2638 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2640 if(This->attrs) {
2641 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2642 *ac = This->attrs;
2643 return S_OK;
2646 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2647 if(!This->attrs)
2648 return E_OUTOFMEMORY;
2650 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2651 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2652 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2653 This->attrs->ref = 2;
2655 This->attrs->elem = This;
2656 list_init(&This->attrs->attrs);
2657 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2658 &HTMLAttributeCollection_dispex);
2660 *ac = This->attrs;
2661 return S_OK;