winex11: Store the DC bounds rectangle as a pointer.
[wine/multimedia.git] / dlls / mshtml / htmlelem.c
blob9184b9bdccae0d50c5131a8e600dac7dd562bcf0
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 %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), 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;
356 TRACE("(%p)->(%p)\n", This, p);
358 if(!This->nselem) {
359 FIXME("NULL nselem\n");
360 return E_NOTIMPL;
363 nsAString_Init(&class_str, NULL);
364 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
365 return return_nsstr(nsres, &class_str, p);
368 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
370 HTMLElement *This = impl_from_IHTMLElement(iface);
371 nsAString id_str;
372 nsresult nsres;
374 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
376 if(!This->nselem) {
377 FIXME("nselem == NULL\n");
378 return S_OK;
381 nsAString_InitDepend(&id_str, v);
382 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
383 nsAString_Finish(&id_str);
384 if(NS_FAILED(nsres))
385 ERR("SetId failed: %08x\n", nsres);
387 return S_OK;
390 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
392 HTMLElement *This = impl_from_IHTMLElement(iface);
393 nsAString id_str;
394 nsresult nsres;
396 TRACE("(%p)->(%p)\n", This, p);
398 if(!This->nselem) {
399 *p = NULL;
400 return S_OK;
403 nsAString_Init(&id_str, NULL);
404 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
405 return return_nsstr(nsres, &id_str, p);
408 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
410 HTMLElement *This = impl_from_IHTMLElement(iface);
411 nsAString tag_str;
412 nsresult nsres;
414 TRACE("(%p)->(%p)\n", This, p);
416 if(!This->nselem) {
417 static const WCHAR comment_tagW[] = {'!',0};
419 WARN("NULL nselem, assuming comment\n");
421 *p = SysAllocString(comment_tagW);
422 return *p ? S_OK : E_OUTOFMEMORY;
425 nsAString_Init(&tag_str, NULL);
426 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
427 return return_nsstr(nsres, &tag_str, p);
430 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
432 HTMLElement *This = impl_from_IHTMLElement(iface);
433 IHTMLDOMNode *node;
434 HRESULT hres;
436 TRACE("(%p)->(%p)\n", This, p);
438 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
439 if(FAILED(hres))
440 return hres;
442 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
443 IHTMLDOMNode_Release(node);
444 if(FAILED(hres))
445 *p = NULL;
447 return S_OK;
450 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
452 HTMLElement *This = impl_from_IHTMLElement(iface);
454 TRACE("(%p)->(%p)\n", This, p);
456 if(!This->style) {
457 nsIDOMElementCSSInlineStyle *nselemstyle;
458 nsIDOMCSSStyleDeclaration *nsstyle;
459 nsresult nsres;
460 HRESULT hres;
462 if(!This->nselem) {
463 FIXME("NULL nselem\n");
464 return E_NOTIMPL;
467 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
468 (void**)&nselemstyle);
469 if(NS_FAILED(nsres)) {
470 ERR("Could not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
471 return E_FAIL;
474 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
475 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
476 if(NS_FAILED(nsres)) {
477 ERR("GetStyle failed: %08x\n", nsres);
478 return E_FAIL;
481 hres = HTMLStyle_Create(This, nsstyle, &This->style);
482 nsIDOMCSSStyleDeclaration_Release(nsstyle);
483 if(FAILED(hres))
484 return hres;
487 *p = &This->style->IHTMLStyle_iface;
488 IHTMLStyle_AddRef(*p);
489 return S_OK;
492 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
494 HTMLElement *This = impl_from_IHTMLElement(iface);
495 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
496 return E_NOTIMPL;
499 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
501 HTMLElement *This = impl_from_IHTMLElement(iface);
502 FIXME("(%p)->(%p)\n", This, p);
503 return E_NOTIMPL;
506 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
508 HTMLElement *This = impl_from_IHTMLElement(iface);
510 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
512 return set_node_event(&This->node, EVENTID_CLICK, &v);
515 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
517 HTMLElement *This = impl_from_IHTMLElement(iface);
519 TRACE("(%p)->(%p)\n", This, p);
521 return get_node_event(&This->node, EVENTID_CLICK, p);
524 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
526 HTMLElement *This = impl_from_IHTMLElement(iface);
528 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
530 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
533 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
535 HTMLElement *This = impl_from_IHTMLElement(iface);
537 TRACE("(%p)->(%p)\n", This, p);
539 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
542 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
544 HTMLElement *This = impl_from_IHTMLElement(iface);
546 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
548 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
551 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
553 HTMLElement *This = impl_from_IHTMLElement(iface);
555 TRACE("(%p)->(%p)\n", This, p);
557 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
560 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
562 HTMLElement *This = impl_from_IHTMLElement(iface);
564 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
566 return set_node_event(&This->node, EVENTID_KEYUP, &v);
569 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
571 HTMLElement *This = impl_from_IHTMLElement(iface);
572 FIXME("(%p)->(%p)\n", This, p);
573 return E_NOTIMPL;
576 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
578 HTMLElement *This = impl_from_IHTMLElement(iface);
579 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
580 return E_NOTIMPL;
583 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
585 HTMLElement *This = impl_from_IHTMLElement(iface);
586 FIXME("(%p)->(%p)\n", This, p);
587 return E_NOTIMPL;
590 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
592 HTMLElement *This = impl_from_IHTMLElement(iface);
594 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
596 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
599 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
601 HTMLElement *This = impl_from_IHTMLElement(iface);
603 TRACE("(%p)->(%p)\n", This, p);
605 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
608 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
610 HTMLElement *This = impl_from_IHTMLElement(iface);
612 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
614 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
617 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
619 HTMLElement *This = impl_from_IHTMLElement(iface);
621 TRACE("(%p)->(%p)\n", This, p);
623 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
626 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
628 HTMLElement *This = impl_from_IHTMLElement(iface);
630 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
632 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
635 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
637 HTMLElement *This = impl_from_IHTMLElement(iface);
639 TRACE("(%p)->(%p)\n", This, p);
641 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
644 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
646 HTMLElement *This = impl_from_IHTMLElement(iface);
648 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
650 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
653 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
655 HTMLElement *This = impl_from_IHTMLElement(iface);
657 TRACE("(%p)->(%p)\n", This, p);
659 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
662 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
664 HTMLElement *This = impl_from_IHTMLElement(iface);
666 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
668 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
671 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
673 HTMLElement *This = impl_from_IHTMLElement(iface);
675 TRACE("(%p)->(%p)\n", This, p);
677 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
680 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
682 HTMLElement *This = impl_from_IHTMLElement(iface);
684 TRACE("(%p)->(%p)\n", This, p);
686 if(!p)
687 return E_POINTER;
689 if(This->node.vtbl->get_document)
690 return This->node.vtbl->get_document(&This->node, p);
692 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
693 IDispatch_AddRef(*p);
694 return S_OK;
697 static const WCHAR titleW[] = {'t','i','t','l','e',0};
699 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
701 HTMLElement *This = impl_from_IHTMLElement(iface);
702 nsAString title_str;
703 nsresult nsres;
705 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
707 if(!This->nselem) {
708 VARIANT *var;
709 HRESULT hres;
711 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
712 if(FAILED(hres))
713 return hres;
715 VariantClear(var);
716 V_VT(var) = VT_BSTR;
717 V_BSTR(var) = v ? SysAllocString(v) : NULL;
718 return S_OK;
721 nsAString_InitDepend(&title_str, v);
722 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
723 nsAString_Finish(&title_str);
724 if(NS_FAILED(nsres))
725 ERR("SetTitle failed: %08x\n", nsres);
727 return S_OK;
730 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
732 HTMLElement *This = impl_from_IHTMLElement(iface);
733 nsAString title_str;
734 nsresult nsres;
736 TRACE("(%p)->(%p)\n", This, p);
738 if(!This->nselem) {
739 VARIANT *var;
740 HRESULT hres;
742 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
743 if(hres == DISP_E_UNKNOWNNAME) {
744 *p = NULL;
745 }else if(V_VT(var) != VT_BSTR) {
746 FIXME("title = %s\n", debugstr_variant(var));
747 return E_FAIL;
748 }else {
749 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
752 return S_OK;
755 nsAString_Init(&title_str, NULL);
756 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
757 return return_nsstr(nsres, &title_str, p);
760 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
762 HTMLElement *This = impl_from_IHTMLElement(iface);
763 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
764 return E_NOTIMPL;
767 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
769 HTMLElement *This = impl_from_IHTMLElement(iface);
770 FIXME("(%p)->(%p)\n", This, p);
771 return E_NOTIMPL;
774 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
776 HTMLElement *This = impl_from_IHTMLElement(iface);
778 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
780 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
783 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
785 HTMLElement *This = impl_from_IHTMLElement(iface);
787 TRACE("(%p)->(%p)\n", This, p);
789 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
792 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
794 HTMLElement *This = impl_from_IHTMLElement(iface);
795 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
796 return E_NOTIMPL;
799 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
800 VARIANT_BOOL *pfResult)
802 HTMLElement *This = impl_from_IHTMLElement(iface);
803 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
804 return E_NOTIMPL;
807 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
809 HTMLElement *This = impl_from_IHTMLElement(iface);
810 FIXME("(%p)->(%p)\n", This, p);
811 return E_NOTIMPL;
814 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
816 HTMLElement *This = impl_from_IHTMLElement(iface);
817 FIXME("(%p)->(%p)\n", This, p);
818 return E_NOTIMPL;
821 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
823 HTMLElement *This = impl_from_IHTMLElement(iface);
824 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
825 return E_NOTIMPL;
828 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
830 HTMLElement *This = impl_from_IHTMLElement(iface);
831 FIXME("(%p)->(%p)\n", This, p);
832 return E_NOTIMPL;
835 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
837 HTMLElement *This = impl_from_IHTMLElement(iface);
838 PRInt32 off_left = 0;
839 nsresult nsres;
841 TRACE("(%p)->(%p)\n", This, p);
843 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, &off_left);
844 if(NS_FAILED(nsres)) {
845 ERR("GetOffsetLeft failed: %08x\n", nsres);
846 return E_FAIL;
849 *p = off_left;
850 return S_OK;
853 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
855 HTMLElement *This = impl_from_IHTMLElement(iface);
856 PRInt32 top = 0;
857 nsresult nsres;
859 TRACE("(%p)->(%p)\n", This, p);
861 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, &top);
862 if(NS_FAILED(nsres)) {
863 ERR("GetOffsetTop failed: %08x\n", nsres);
864 return E_FAIL;
867 *p = top;
868 return S_OK;
871 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
873 HTMLElement *This = impl_from_IHTMLElement(iface);
874 PRInt32 offset = 0;
875 nsresult nsres;
877 TRACE("(%p)->(%p)\n", This, p);
879 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, &offset);
880 if(NS_FAILED(nsres)) {
881 ERR("GetOffsetWidth failed: %08x\n", nsres);
882 return E_FAIL;
885 *p = offset;
886 return S_OK;
889 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
891 HTMLElement *This = impl_from_IHTMLElement(iface);
892 PRInt32 offset = 0;
893 nsresult nsres;
895 TRACE("(%p)->(%p)\n", This, p);
897 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, &offset);
898 if(NS_FAILED(nsres)) {
899 ERR("GetOffsetHeight failed: %08x\n", nsres);
900 return E_FAIL;
903 *p = offset;
904 return S_OK;
907 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
909 HTMLElement *This = impl_from_IHTMLElement(iface);
910 nsIDOMElement *nsparent;
911 nsresult nsres;
912 HRESULT hres;
914 TRACE("(%p)->(%p)\n", This, p);
916 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
917 if(NS_FAILED(nsres)) {
918 ERR("GetOffsetParent failed: %08x\n", nsres);
919 return E_FAIL;
922 if(nsparent) {
923 HTMLDOMNode *node;
925 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
926 nsIDOMElement_Release(nsparent);
927 if(FAILED(hres))
928 return hres;
930 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
931 }else {
932 *p = NULL;
933 hres = S_OK;
936 return hres;
939 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
941 HTMLElement *This = impl_from_IHTMLElement(iface);
942 nsAString html_str;
943 nsresult nsres;
945 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
947 if(!This->nselem) {
948 FIXME("NULL nselem\n");
949 return E_NOTIMPL;
952 nsAString_InitDepend(&html_str, v);
953 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
954 nsAString_Finish(&html_str);
955 if(NS_FAILED(nsres)) {
956 FIXME("SetInnerHtml failed %08x\n", nsres);
957 return E_FAIL;
960 return S_OK;
963 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
965 HTMLElement *This = impl_from_IHTMLElement(iface);
966 nsAString html_str;
967 nsresult nsres;
969 TRACE("(%p)->(%p)\n", This, p);
971 if(!This->nselem) {
972 FIXME("NULL nselem\n");
973 return E_NOTIMPL;
976 nsAString_Init(&html_str, NULL);
977 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
978 return return_nsstr(nsres, &html_str, p);
981 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
983 HTMLElement *This = impl_from_IHTMLElement(iface);
984 nsIDOMNode *nschild, *tmp;
985 nsIDOMText *text_node;
986 nsAString text_str;
987 nsresult nsres;
989 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
991 while(1) {
992 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
993 if(NS_FAILED(nsres)) {
994 ERR("GetLastChild failed: %08x\n", nsres);
995 return E_FAIL;
997 if(!nschild)
998 break;
1000 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1001 nsIDOMNode_Release(nschild);
1002 if(NS_FAILED(nsres)) {
1003 ERR("RemoveChild failed: %08x\n", nsres);
1004 return E_FAIL;
1006 nsIDOMNode_Release(tmp);
1009 nsAString_InitDepend(&text_str, v);
1010 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1011 nsAString_Finish(&text_str);
1012 if(NS_FAILED(nsres)) {
1013 ERR("CreateTextNode failed: %08x\n", nsres);
1014 return E_FAIL;
1017 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1018 if(NS_FAILED(nsres)) {
1019 ERR("AppendChild failed: %08x\n", nsres);
1020 return E_FAIL;
1023 nsIDOMNode_Release(tmp);
1024 return S_OK;
1027 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1029 HTMLElement *This = impl_from_IHTMLElement(iface);
1031 TRACE("(%p)->(%p)\n", This, p);
1033 return get_node_text(&This->node, p);
1036 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1038 HTMLElement *This = impl_from_IHTMLElement(iface);
1040 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1042 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1045 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1047 HTMLElement *This = impl_from_IHTMLElement(iface);
1048 nsAString html_str;
1049 HRESULT hres;
1051 WARN("(%p)->(%p) semi-stub\n", This, p);
1053 nsAString_Init(&html_str, NULL);
1054 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1055 if(SUCCEEDED(hres)) {
1056 const PRUnichar *html;
1058 nsAString_GetData(&html_str, &html);
1059 *p = SysAllocString(html);
1060 if(!*p)
1061 hres = E_OUTOFMEMORY;
1064 nsAString_Finish(&html_str);
1066 TRACE("ret %s\n", debugstr_w(*p));
1067 return hres;
1070 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1072 HTMLElement *This = impl_from_IHTMLElement(iface);
1073 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1074 return E_NOTIMPL;
1077 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1079 HTMLElement *This = impl_from_IHTMLElement(iface);
1080 FIXME("(%p)->(%p)\n", This, p);
1081 return E_NOTIMPL;
1084 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1086 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1087 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1088 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1089 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1090 nsresult nsres;
1092 if (!strcmpiW(where, wszBeforeBegin))
1094 nsIDOMNode *unused;
1095 nsIDOMNode *parent;
1096 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1097 if (!parent) return E_INVALIDARG;
1098 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1099 if (unused) nsIDOMNode_Release(unused);
1100 nsIDOMNode_Release(parent);
1102 else if (!strcmpiW(where, wszAfterBegin))
1104 nsIDOMNode *unused;
1105 nsIDOMNode *first_child;
1106 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1107 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1108 if (unused) nsIDOMNode_Release(unused);
1109 if (first_child) nsIDOMNode_Release(first_child);
1111 else if (!strcmpiW(where, wszBeforeEnd))
1113 nsIDOMNode *unused;
1114 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1115 if (unused) nsIDOMNode_Release(unused);
1117 else if (!strcmpiW(where, wszAfterEnd))
1119 nsIDOMNode *unused;
1120 nsIDOMNode *next_sibling;
1121 nsIDOMNode *parent;
1122 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1123 if (!parent) return E_INVALIDARG;
1125 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1126 if (next_sibling)
1128 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1129 nsIDOMNode_Release(next_sibling);
1131 else
1132 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1133 nsIDOMNode_Release(parent);
1134 if (unused) nsIDOMNode_Release(unused);
1136 else
1138 ERR("invalid where: %s\n", debugstr_w(where));
1139 return E_INVALIDARG;
1142 if (NS_FAILED(nsres))
1143 return E_FAIL;
1144 else
1145 return S_OK;
1148 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1149 BSTR html)
1151 HTMLElement *This = impl_from_IHTMLElement(iface);
1152 nsIDOMRange *range;
1153 nsIDOMNSRange *nsrange;
1154 nsIDOMNode *nsnode;
1155 nsAString ns_html;
1156 nsresult nsres;
1157 HRESULT hr;
1159 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1161 if(!This->node.doc->nsdoc) {
1162 WARN("NULL nsdoc\n");
1163 return E_UNEXPECTED;
1166 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1167 if(NS_FAILED(nsres))
1169 ERR("CreateRange failed: %08x\n", nsres);
1170 return E_FAIL;
1173 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1175 nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void **)&nsrange);
1176 nsIDOMRange_Release(range);
1177 if(NS_FAILED(nsres))
1179 ERR("getting nsIDOMNSRange failed: %08x\n", nsres);
1180 return E_FAIL;
1183 nsAString_InitDepend(&ns_html, html);
1185 nsres = nsIDOMNSRange_CreateContextualFragment(nsrange, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1186 nsIDOMNSRange_Release(nsrange);
1187 nsAString_Finish(&ns_html);
1189 if(NS_FAILED(nsres) || !nsnode)
1191 ERR("CreateTextNode failed: %08x\n", nsres);
1192 return E_FAIL;
1195 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1196 nsIDOMNode_Release(nsnode);
1198 return hr;
1201 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1202 BSTR text)
1204 HTMLElement *This = impl_from_IHTMLElement(iface);
1205 nsIDOMNode *nsnode;
1206 nsAString ns_text;
1207 nsresult nsres;
1208 HRESULT hr;
1210 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1212 if(!This->node.doc->nsdoc) {
1213 WARN("NULL nsdoc\n");
1214 return E_UNEXPECTED;
1218 nsAString_InitDepend(&ns_text, text);
1219 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1220 nsAString_Finish(&ns_text);
1222 if(NS_FAILED(nsres) || !nsnode)
1224 ERR("CreateTextNode failed: %08x\n", nsres);
1225 return E_FAIL;
1228 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1229 nsIDOMNode_Release(nsnode);
1231 return hr;
1234 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1236 HTMLElement *This = impl_from_IHTMLElement(iface);
1237 FIXME("(%p)->(%p)\n", This, p);
1238 return E_NOTIMPL;
1241 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1243 HTMLElement *This = impl_from_IHTMLElement(iface);
1244 FIXME("(%p)->(%p)\n", This, p);
1245 return E_NOTIMPL;
1248 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1250 HTMLElement *This = impl_from_IHTMLElement(iface);
1252 TRACE("(%p)\n", This);
1254 return call_fire_event(&This->node, EVENTID_CLICK);
1257 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1258 IHTMLFiltersCollection **p)
1260 HTMLElement *This = impl_from_IHTMLElement(iface);
1261 TRACE("(%p)->(%p)\n", This, p);
1263 if(!p)
1264 return E_POINTER;
1266 *p = HTMLFiltersCollection_Create();
1268 return S_OK;
1271 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1273 HTMLElement *This = impl_from_IHTMLElement(iface);
1274 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1275 return E_NOTIMPL;
1278 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1280 HTMLElement *This = impl_from_IHTMLElement(iface);
1281 FIXME("(%p)->(%p)\n", This, p);
1282 return E_NOTIMPL;
1285 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1287 HTMLElement *This = impl_from_IHTMLElement(iface);
1288 FIXME("(%p)->(%p)\n", This, String);
1289 return E_NOTIMPL;
1292 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1294 HTMLElement *This = impl_from_IHTMLElement(iface);
1295 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1296 return E_NOTIMPL;
1299 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1301 HTMLElement *This = impl_from_IHTMLElement(iface);
1302 FIXME("(%p)->(%p)\n", This, p);
1303 return E_NOTIMPL;
1306 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1308 HTMLElement *This = impl_from_IHTMLElement(iface);
1309 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1310 return E_NOTIMPL;
1313 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1315 HTMLElement *This = impl_from_IHTMLElement(iface);
1316 FIXME("(%p)->(%p)\n", This, p);
1317 return E_NOTIMPL;
1320 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1322 HTMLElement *This = impl_from_IHTMLElement(iface);
1323 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1324 return E_NOTIMPL;
1327 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1329 HTMLElement *This = impl_from_IHTMLElement(iface);
1330 FIXME("(%p)->(%p)\n", This, p);
1331 return E_NOTIMPL;
1334 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1336 HTMLElement *This = impl_from_IHTMLElement(iface);
1337 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1338 return E_NOTIMPL;
1341 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1343 HTMLElement *This = impl_from_IHTMLElement(iface);
1344 FIXME("(%p)->(%p)\n", This, p);
1345 return E_NOTIMPL;
1348 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1350 HTMLElement *This = impl_from_IHTMLElement(iface);
1351 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1352 return E_NOTIMPL;
1355 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1357 HTMLElement *This = impl_from_IHTMLElement(iface);
1358 FIXME("(%p)->(%p)\n", This, p);
1359 return E_NOTIMPL;
1362 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1364 HTMLElement *This = impl_from_IHTMLElement(iface);
1365 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1366 return E_NOTIMPL;
1369 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1371 HTMLElement *This = impl_from_IHTMLElement(iface);
1372 FIXME("(%p)->(%p)\n", This, p);
1373 return E_NOTIMPL;
1376 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1378 HTMLElement *This = impl_from_IHTMLElement(iface);
1379 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1380 return E_NOTIMPL;
1383 static HRESULT WINAPI HTMLElement_get_ondataavailable(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_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1392 HTMLElement *This = impl_from_IHTMLElement(iface);
1393 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1394 return E_NOTIMPL;
1397 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1399 HTMLElement *This = impl_from_IHTMLElement(iface);
1400 FIXME("(%p)->(%p)\n", This, p);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1406 HTMLElement *This = impl_from_IHTMLElement(iface);
1407 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1408 return E_NOTIMPL;
1411 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1413 HTMLElement *This = impl_from_IHTMLElement(iface);
1414 FIXME("(%p)->(%p)\n", This, p);
1415 return E_NOTIMPL;
1418 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1420 HTMLElement *This = impl_from_IHTMLElement(iface);
1421 nsIDOMNodeList *nsnode_list;
1422 nsresult nsres;
1424 TRACE("(%p)->(%p)\n", This, p);
1426 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1427 if(NS_FAILED(nsres)) {
1428 ERR("GetChildNodes failed: %08x\n", nsres);
1429 return E_FAIL;
1432 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc,
1433 (IUnknown*)&This->IHTMLElement_iface, nsnode_list);
1435 nsIDOMNodeList_Release(nsnode_list);
1436 return S_OK;
1439 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1441 HTMLElement *This = impl_from_IHTMLElement(iface);
1443 TRACE("(%p)->(%p)\n", This, p);
1445 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1446 return S_OK;
1449 static const IHTMLElementVtbl HTMLElementVtbl = {
1450 HTMLElement_QueryInterface,
1451 HTMLElement_AddRef,
1452 HTMLElement_Release,
1453 HTMLElement_GetTypeInfoCount,
1454 HTMLElement_GetTypeInfo,
1455 HTMLElement_GetIDsOfNames,
1456 HTMLElement_Invoke,
1457 HTMLElement_setAttribute,
1458 HTMLElement_getAttribute,
1459 HTMLElement_removeAttribute,
1460 HTMLElement_put_className,
1461 HTMLElement_get_className,
1462 HTMLElement_put_id,
1463 HTMLElement_get_id,
1464 HTMLElement_get_tagName,
1465 HTMLElement_get_parentElement,
1466 HTMLElement_get_style,
1467 HTMLElement_put_onhelp,
1468 HTMLElement_get_onhelp,
1469 HTMLElement_put_onclick,
1470 HTMLElement_get_onclick,
1471 HTMLElement_put_ondblclick,
1472 HTMLElement_get_ondblclick,
1473 HTMLElement_put_onkeydown,
1474 HTMLElement_get_onkeydown,
1475 HTMLElement_put_onkeyup,
1476 HTMLElement_get_onkeyup,
1477 HTMLElement_put_onkeypress,
1478 HTMLElement_get_onkeypress,
1479 HTMLElement_put_onmouseout,
1480 HTMLElement_get_onmouseout,
1481 HTMLElement_put_onmouseover,
1482 HTMLElement_get_onmouseover,
1483 HTMLElement_put_onmousemove,
1484 HTMLElement_get_onmousemove,
1485 HTMLElement_put_onmousedown,
1486 HTMLElement_get_onmousedown,
1487 HTMLElement_put_onmouseup,
1488 HTMLElement_get_onmouseup,
1489 HTMLElement_get_document,
1490 HTMLElement_put_title,
1491 HTMLElement_get_title,
1492 HTMLElement_put_language,
1493 HTMLElement_get_language,
1494 HTMLElement_put_onselectstart,
1495 HTMLElement_get_onselectstart,
1496 HTMLElement_scrollIntoView,
1497 HTMLElement_contains,
1498 HTMLElement_get_sourceIndex,
1499 HTMLElement_get_recordNumber,
1500 HTMLElement_put_lang,
1501 HTMLElement_get_lang,
1502 HTMLElement_get_offsetLeft,
1503 HTMLElement_get_offsetTop,
1504 HTMLElement_get_offsetWidth,
1505 HTMLElement_get_offsetHeight,
1506 HTMLElement_get_offsetParent,
1507 HTMLElement_put_innerHTML,
1508 HTMLElement_get_innerHTML,
1509 HTMLElement_put_innerText,
1510 HTMLElement_get_innerText,
1511 HTMLElement_put_outerHTML,
1512 HTMLElement_get_outerHTML,
1513 HTMLElement_put_outerText,
1514 HTMLElement_get_outerText,
1515 HTMLElement_insertAdjacentHTML,
1516 HTMLElement_insertAdjacentText,
1517 HTMLElement_get_parentTextEdit,
1518 HTMLElement_get_isTextEdit,
1519 HTMLElement_click,
1520 HTMLElement_get_filters,
1521 HTMLElement_put_ondragstart,
1522 HTMLElement_get_ondragstart,
1523 HTMLElement_toString,
1524 HTMLElement_put_onbeforeupdate,
1525 HTMLElement_get_onbeforeupdate,
1526 HTMLElement_put_onafterupdate,
1527 HTMLElement_get_onafterupdate,
1528 HTMLElement_put_onerrorupdate,
1529 HTMLElement_get_onerrorupdate,
1530 HTMLElement_put_onrowexit,
1531 HTMLElement_get_onrowexit,
1532 HTMLElement_put_onrowenter,
1533 HTMLElement_get_onrowenter,
1534 HTMLElement_put_ondatasetchanged,
1535 HTMLElement_get_ondatasetchanged,
1536 HTMLElement_put_ondataavailable,
1537 HTMLElement_get_ondataavailable,
1538 HTMLElement_put_ondatasetcomplete,
1539 HTMLElement_get_ondatasetcomplete,
1540 HTMLElement_put_onfilterchange,
1541 HTMLElement_get_onfilterchange,
1542 HTMLElement_get_children,
1543 HTMLElement_get_all
1546 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1548 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1551 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1553 return CONTAINING_RECORD(iface, HTMLElement, node);
1556 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1558 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1560 *ppv = NULL;
1562 if(IsEqualGUID(&IID_IUnknown, riid)) {
1563 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1564 *ppv = &This->IHTMLElement_iface;
1565 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1566 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1567 *ppv = &This->IHTMLElement_iface;
1568 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1569 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1570 *ppv = &This->IHTMLElement_iface;
1571 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1572 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1573 *ppv = &This->IHTMLElement2_iface;
1574 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1575 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1576 *ppv = &This->IHTMLElement3_iface;
1577 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1578 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1579 *ppv = &This->IHTMLElement4_iface;
1580 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1581 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1582 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1585 if(*ppv) {
1586 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1587 return S_OK;
1590 return HTMLDOMNode_QI(&This->node, riid, ppv);
1593 void HTMLElement_destructor(HTMLDOMNode *iface)
1595 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1597 ConnectionPointContainer_Destroy(&This->cp_container);
1599 if(This->nselem)
1600 nsIDOMHTMLElement_Release(This->nselem);
1601 if(This->style) {
1602 This->style->elem = NULL;
1603 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1605 if(This->attrs) {
1606 HTMLDOMAttribute *attr;
1608 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1609 attr->elem = NULL;
1611 This->attrs->elem = NULL;
1612 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1615 heap_free(This->filter);
1617 HTMLDOMNode_destructor(&This->node);
1620 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1622 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1623 HTMLElement *new_elem;
1624 HRESULT hres;
1626 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1627 if(FAILED(hres))
1628 return hres;
1630 if(This->filter) {
1631 new_elem->filter = heap_strdupW(This->filter);
1632 if(!new_elem->filter) {
1633 IHTMLElement_Release(&This->IHTMLElement_iface);
1634 return E_OUTOFMEMORY;
1638 IHTMLElement_AddRef(&new_elem->IHTMLElement_iface);
1639 *ret = &new_elem->node;
1640 return S_OK;
1643 static const NodeImplVtbl HTMLElementImplVtbl = {
1644 HTMLElement_QI,
1645 HTMLElement_destructor,
1646 HTMLElement_clone,
1647 HTMLElement_get_attr_col
1650 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1652 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1655 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1656 DWORD grfdex, DISPID *pid)
1658 HTMLElement *This = impl_from_DispatchEx(dispex);
1660 if(This->node.vtbl->get_dispid)
1661 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1663 return DISP_E_UNKNOWNNAME;
1666 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1667 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1668 IServiceProvider *caller)
1670 HTMLElement *This = impl_from_DispatchEx(dispex);
1672 if(This->node.vtbl->invoke)
1673 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1674 params, res, ei, caller);
1676 ERR("(%p): element has no invoke method\n", This);
1677 return E_NOTIMPL;
1680 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1682 HTMLElement *This = impl_from_DispatchEx(dispex);
1683 nsIDOMNamedNodeMap *attrs;
1684 nsIDOMNode *node;
1685 nsAString nsstr;
1686 const PRUnichar *str;
1687 BSTR name;
1688 VARIANT value;
1689 unsigned i;
1690 PRUint32 len;
1691 DISPID id;
1692 nsresult nsres;
1693 HRESULT hres;
1695 if(!This->nselem)
1696 return S_FALSE;
1698 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1699 if(NS_FAILED(nsres))
1700 return E_FAIL;
1702 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1703 if(NS_FAILED(nsres)) {
1704 nsIDOMNamedNodeMap_Release(attrs);
1705 return E_FAIL;
1708 nsAString_Init(&nsstr, NULL);
1709 for(i=0; i<len; i++) {
1710 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1711 if(NS_FAILED(nsres))
1712 continue;
1714 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1715 if(NS_FAILED(nsres)) {
1716 nsIDOMNode_Release(node);
1717 continue;
1720 nsAString_GetData(&nsstr, &str);
1721 name = SysAllocString(str);
1722 if(!name) {
1723 nsIDOMNode_Release(node);
1724 continue;
1727 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1728 if(hres != DISP_E_UNKNOWNNAME) {
1729 nsIDOMNode_Release(node);
1730 SysFreeString(name);
1731 continue;
1734 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1735 nsIDOMNode_Release(node);
1736 if(NS_FAILED(nsres)) {
1737 SysFreeString(name);
1738 continue;
1741 nsAString_GetData(&nsstr, &str);
1742 V_VT(&value) = VT_BSTR;
1743 if(*str) {
1744 V_BSTR(&value) = SysAllocString(str);
1745 if(!V_BSTR(&value)) {
1746 SysFreeString(name);
1747 continue;
1749 } else
1750 V_BSTR(&value) = NULL;
1752 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1753 SysFreeString(name);
1754 VariantClear(&value);
1756 nsAString_Finish(&nsstr);
1758 nsIDOMNamedNodeMap_Release(attrs);
1759 return S_OK;
1762 static const tid_t HTMLElement_iface_tids[] = {
1763 HTMLELEMENT_TIDS,
1767 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1768 NULL,
1769 HTMLElement_get_dispid,
1770 HTMLElement_invoke,
1771 HTMLElement_populate_props
1774 static dispex_static_data_t HTMLElement_dispex = {
1775 &HTMLElement_dispex_vtbl,
1776 DispHTMLUnknownElement_tid,
1777 NULL,
1778 HTMLElement_iface_tids
1781 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1783 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1785 HTMLElement2_Init(This);
1786 HTMLElement3_Init(This);
1788 if(dispex_data && !dispex_data->vtbl)
1789 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1790 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1791 dispex_data ? dispex_data : &HTMLElement_dispex);
1793 if(nselem)
1794 nsIDOMHTMLElement_AddRef(nselem);
1795 This->nselem = nselem;
1797 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1799 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1802 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1804 nsIDOMHTMLElement *nselem;
1805 nsAString class_name_str;
1806 const PRUnichar *class_name;
1807 const tag_desc_t *tag;
1808 HTMLElement *elem;
1809 nsresult nsres;
1810 HRESULT hres;
1812 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1813 if(NS_FAILED(nsres))
1814 return E_FAIL;
1816 nsAString_Init(&class_name_str, NULL);
1817 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1819 nsAString_GetData(&class_name_str, &class_name);
1821 tag = get_tag_desc(class_name);
1822 if(tag) {
1823 hres = tag->constructor(doc, nselem, &elem);
1824 }else if(use_generic) {
1825 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1826 }else {
1827 elem = heap_alloc_zero(sizeof(HTMLElement));
1828 if(elem) {
1829 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1830 elem->node.vtbl = &HTMLElementImplVtbl;
1831 hres = S_OK;
1832 }else {
1833 hres = E_OUTOFMEMORY;
1837 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1839 nsIDOMElement_Release(nselem);
1840 nsAString_Finish(&class_name_str);
1841 if(FAILED(hres))
1842 return hres;
1844 *ret = elem;
1845 return S_OK;
1848 /* interface IHTMLFiltersCollection */
1849 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1851 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1853 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1855 if(IsEqualGUID(&IID_IUnknown, riid)) {
1856 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1857 *ppv = &This->IHTMLFiltersCollection_iface;
1858 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1859 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1860 *ppv = &This->IHTMLFiltersCollection_iface;
1861 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1862 return *ppv ? S_OK : E_NOINTERFACE;
1865 if(*ppv) {
1866 IUnknown_AddRef((IUnknown*)*ppv);
1867 return S_OK;
1870 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1871 return E_NOINTERFACE;
1874 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1876 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1877 LONG ref = InterlockedIncrement(&This->ref);
1879 TRACE("(%p) ref=%d\n", This, ref);
1881 return ref;
1884 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1886 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1887 LONG ref = InterlockedDecrement(&This->ref);
1889 TRACE("(%p) ref=%d\n", This, ref);
1891 if(!ref)
1893 heap_free(This);
1896 return ref;
1899 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1901 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1902 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1905 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1906 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1908 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1909 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1912 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1913 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1914 LCID lcid, DISPID *rgDispId)
1916 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1917 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1918 lcid, rgDispId);
1921 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1922 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1923 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1925 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1926 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1927 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1930 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1932 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1934 if(!p)
1935 return E_POINTER;
1937 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1938 *p = 0;
1940 return S_OK;
1943 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1945 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1946 FIXME("(%p)->(%p)\n", This, p);
1947 return E_NOTIMPL;
1950 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1952 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1953 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
1954 return E_NOTIMPL;
1957 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
1958 HTMLFiltersCollection_QueryInterface,
1959 HTMLFiltersCollection_AddRef,
1960 HTMLFiltersCollection_Release,
1961 HTMLFiltersCollection_GetTypeInfoCount,
1962 HTMLFiltersCollection_GetTypeInfo,
1963 HTMLFiltersCollection_GetIDsOfNames,
1964 HTMLFiltersCollection_Invoke,
1965 HTMLFiltersCollection_get_length,
1966 HTMLFiltersCollection_get__newEnum,
1967 HTMLFiltersCollection_item
1970 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
1972 WCHAR *ptr;
1973 int idx = 0;
1975 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1976 idx = idx*10 + (*ptr-'0');
1977 if(*ptr)
1978 return DISP_E_UNKNOWNNAME;
1980 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
1981 TRACE("ret %x\n", *dispid);
1982 return S_OK;
1985 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1986 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1988 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
1990 V_VT(res) = VT_DISPATCH;
1991 V_DISPATCH(res) = NULL;
1993 FIXME("always returning NULL\n");
1995 return S_OK;
1998 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
1999 NULL,
2000 HTMLFiltersCollection_get_dispid,
2001 HTMLFiltersCollection_invoke,
2002 NULL
2005 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2006 IHTMLFiltersCollection_tid,
2009 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2010 &HTMLFiltersCollection_dispex_vtbl,
2011 IHTMLFiltersCollection_tid,
2012 NULL,
2013 HTMLFiltersCollection_iface_tids
2016 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2018 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2020 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2021 ret->ref = 1;
2023 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2024 &HTMLFiltersCollection_dispex);
2026 return &ret->IHTMLFiltersCollection_iface;
2029 /* interface IHTMLAttributeCollection */
2030 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2032 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2035 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2037 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2039 *ppv = NULL;
2041 if(IsEqualGUID(&IID_IUnknown, riid)) {
2042 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2043 *ppv = &This->IHTMLAttributeCollection_iface;
2044 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2045 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2046 *ppv = &This->IHTMLAttributeCollection_iface;
2047 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2048 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2049 *ppv = &This->IHTMLAttributeCollection2_iface;
2050 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2051 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2052 *ppv = &This->IHTMLAttributeCollection3_iface;
2053 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2054 return *ppv ? S_OK : E_NOINTERFACE;
2057 if(*ppv) {
2058 IUnknown_AddRef((IUnknown*)*ppv);
2059 return S_OK;
2062 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2063 return E_NOINTERFACE;
2066 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2068 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2069 LONG ref = InterlockedIncrement(&This->ref);
2071 TRACE("(%p) ref=%d\n", This, ref);
2073 return ref;
2076 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2078 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2079 LONG ref = InterlockedDecrement(&This->ref);
2081 TRACE("(%p) ref=%d\n", This, ref);
2083 if(!ref) {
2084 while(!list_empty(&This->attrs)) {
2085 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2087 list_remove(&attr->entry);
2088 attr->elem = NULL;
2089 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2092 heap_free(This);
2095 return ref;
2098 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2100 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2101 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2104 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2105 LCID lcid, ITypeInfo **ppTInfo)
2107 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2108 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2111 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2112 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2114 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2115 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2116 lcid, rgDispId);
2119 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2120 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2121 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2123 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2124 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2125 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2128 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2130 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2131 DISPID id = DISPID_STARTENUM;
2132 LONG len = -1;
2133 HRESULT hres;
2135 FIXME("filter non-enumerable attributes out\n");
2137 while(1) {
2138 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2139 if(FAILED(hres))
2140 return hres;
2141 else if(hres == S_FALSE)
2142 break;
2144 len++;
2145 if(len == *idx)
2146 break;
2149 if(dispid) {
2150 *dispid = id;
2151 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2154 *idx = len+1;
2155 return S_OK;
2158 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2160 HRESULT hres;
2162 if(name[0]>='0' && name[0]<='9') {
2163 WCHAR *end_ptr;
2164 LONG idx;
2166 idx = strtoulW(name, &end_ptr, 10);
2167 if(!*end_ptr) {
2168 hres = get_attr_dispid_by_idx(This, &idx, id);
2169 if(SUCCEEDED(hres))
2170 return hres;
2174 if(!This->elem) {
2175 WARN("NULL elem\n");
2176 return E_UNEXPECTED;
2179 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2180 name, fdexNameCaseInsensitive, id);
2181 return hres;
2184 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2186 HTMLDOMAttribute *iter;
2187 LONG pos = 0;
2188 HRESULT hres;
2190 *attr = NULL;
2191 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2192 if(iter->dispid == id) {
2193 *attr = iter;
2194 break;
2196 pos++;
2199 if(!*attr) {
2200 if(!This->elem) {
2201 WARN("NULL elem\n");
2202 return E_UNEXPECTED;
2205 pos++;
2206 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2207 if(FAILED(hres))
2208 return hres;
2211 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2212 if(list_pos)
2213 *list_pos = pos;
2214 return S_OK;
2217 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2219 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2220 HRESULT hres;
2222 TRACE("(%p)->(%p)\n", This, p);
2224 *p = -1;
2225 hres = get_attr_dispid_by_idx(This, p, NULL);
2226 return hres;
2229 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2231 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2232 FIXME("(%p)->(%p)\n", This, p);
2233 return E_NOTIMPL;
2236 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2238 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2239 HTMLDOMAttribute *attr;
2240 DISPID id;
2241 HRESULT hres;
2243 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2245 switch(V_VT(name)) {
2246 case VT_I4:
2247 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2248 break;
2249 case VT_BSTR:
2250 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2251 break;
2252 default:
2253 FIXME("unsupported name %s\n", debugstr_variant(name));
2254 hres = E_NOTIMPL;
2256 if(hres == DISP_E_UNKNOWNNAME)
2257 return E_INVALIDARG;
2258 if(FAILED(hres))
2259 return hres;
2261 hres = get_domattr(This, id, NULL, &attr);
2262 if(FAILED(hres))
2263 return hres;
2265 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2266 return S_OK;
2269 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2270 HTMLAttributeCollection_QueryInterface,
2271 HTMLAttributeCollection_AddRef,
2272 HTMLAttributeCollection_Release,
2273 HTMLAttributeCollection_GetTypeInfoCount,
2274 HTMLAttributeCollection_GetTypeInfo,
2275 HTMLAttributeCollection_GetIDsOfNames,
2276 HTMLAttributeCollection_Invoke,
2277 HTMLAttributeCollection_get_length,
2278 HTMLAttributeCollection__newEnum,
2279 HTMLAttributeCollection_item
2282 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2284 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2287 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2289 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2290 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2293 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2295 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2296 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2299 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2301 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2302 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2305 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2307 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2308 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2311 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2312 LCID lcid, ITypeInfo **ppTInfo)
2314 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2315 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2318 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2319 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2321 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2322 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2323 lcid, rgDispId);
2326 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2327 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2328 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2330 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2331 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2332 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2335 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2336 IHTMLDOMAttribute **newretNode)
2338 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2339 HTMLDOMAttribute *attr;
2340 DISPID id;
2341 HRESULT hres;
2343 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2345 hres = get_attr_dispid_by_name(This, bstrName, &id);
2346 if(hres == DISP_E_UNKNOWNNAME) {
2347 *newretNode = NULL;
2348 return S_OK;
2349 } else if(FAILED(hres)) {
2350 return hres;
2353 hres = get_domattr(This, id, NULL, &attr);
2354 if(FAILED(hres))
2355 return hres;
2357 *newretNode = &attr->IHTMLDOMAttribute_iface;
2358 return S_OK;
2361 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2362 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2364 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2365 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2366 return E_NOTIMPL;
2369 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2370 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2372 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2373 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2374 return E_NOTIMPL;
2377 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2378 HTMLAttributeCollection2_QueryInterface,
2379 HTMLAttributeCollection2_AddRef,
2380 HTMLAttributeCollection2_Release,
2381 HTMLAttributeCollection2_GetTypeInfoCount,
2382 HTMLAttributeCollection2_GetTypeInfo,
2383 HTMLAttributeCollection2_GetIDsOfNames,
2384 HTMLAttributeCollection2_Invoke,
2385 HTMLAttributeCollection2_getNamedItem,
2386 HTMLAttributeCollection2_setNamedItem,
2387 HTMLAttributeCollection2_removeNamedItem
2390 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2392 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2395 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2397 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2398 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2401 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2403 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2404 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2407 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2409 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2410 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2413 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2415 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2416 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2419 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2420 LCID lcid, ITypeInfo **ppTInfo)
2422 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2423 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2426 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2427 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2429 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2430 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2431 lcid, rgDispId);
2434 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2435 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2436 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2438 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2439 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2440 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2443 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2444 IHTMLDOMAttribute **ppNodeOut)
2446 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2447 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2450 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2451 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2453 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2454 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2455 return E_NOTIMPL;
2458 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2459 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2461 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2462 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2463 return E_NOTIMPL;
2466 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2468 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2469 HTMLDOMAttribute *attr;
2470 DISPID id;
2471 HRESULT hres;
2473 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2475 hres = get_attr_dispid_by_idx(This, &index, &id);
2476 if(hres == DISP_E_UNKNOWNNAME)
2477 return E_INVALIDARG;
2478 if(FAILED(hres))
2479 return hres;
2481 hres = get_domattr(This, id, NULL, &attr);
2482 if(FAILED(hres))
2483 return hres;
2485 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2486 return S_OK;
2489 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2491 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2492 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2495 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2496 HTMLAttributeCollection3_QueryInterface,
2497 HTMLAttributeCollection3_AddRef,
2498 HTMLAttributeCollection3_Release,
2499 HTMLAttributeCollection3_GetTypeInfoCount,
2500 HTMLAttributeCollection3_GetTypeInfo,
2501 HTMLAttributeCollection3_GetIDsOfNames,
2502 HTMLAttributeCollection3_Invoke,
2503 HTMLAttributeCollection3_getNamedItem,
2504 HTMLAttributeCollection3_setNamedItem,
2505 HTMLAttributeCollection3_removeNamedItem,
2506 HTMLAttributeCollection3_item,
2507 HTMLAttributeCollection3_get_length
2510 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2512 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2515 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2517 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2518 HTMLDOMAttribute *attr;
2519 LONG pos;
2520 HRESULT hres;
2522 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2524 hres = get_attr_dispid_by_name(This, name, dispid);
2525 if(FAILED(hres))
2526 return hres;
2528 hres = get_domattr(This, *dispid, &pos, &attr);
2529 if(FAILED(hres))
2530 return hres;
2531 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2533 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2534 return S_OK;
2537 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2538 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2540 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2542 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2544 switch(flags) {
2545 case DISPATCH_PROPERTYGET: {
2546 HTMLDOMAttribute *iter;
2548 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2550 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2551 if(!(--id))
2552 break;
2554 if(id)
2555 return E_INVALIDARG;
2557 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2558 V_VT(res) = VT_DISPATCH;
2559 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2560 return S_OK;
2563 default:
2564 FIXME("unimplemented flags %x\n", flags);
2565 return E_NOTIMPL;
2569 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2570 NULL,
2571 HTMLAttributeCollection_get_dispid,
2572 HTMLAttributeCollection_invoke,
2573 NULL
2576 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2577 IHTMLAttributeCollection_tid,
2578 IHTMLAttributeCollection2_tid,
2579 IHTMLAttributeCollection3_tid,
2583 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2584 &HTMLAttributeCollection_dispex_vtbl,
2585 DispHTMLAttributeCollection_tid,
2586 NULL,
2587 HTMLAttributeCollection_iface_tids
2590 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2592 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2594 if(This->attrs) {
2595 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2596 *ac = This->attrs;
2597 return S_OK;
2600 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2601 if(!This->attrs)
2602 return E_OUTOFMEMORY;
2604 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2605 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2606 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2607 This->attrs->ref = 2;
2609 This->attrs->elem = This;
2610 list_init(&This->attrs->attrs);
2611 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2612 &HTMLAttributeCollection_dispex);
2614 *ac = This->attrs;
2615 return S_OK;