mshtml: Use inline wrappers and fixed found warnings.
[wine/multimedia.git] / dlls / mshtml / htmlelem.c
blob4ce064dc5a07583f53f3bac9869e48c33eb76c50
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
19 #include <stdarg.h>
20 #include <assert.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 nsIDOMNode *nsparent;
112 nsIDOMRange *range;
113 nsAString html_str;
114 nsresult nsres;
115 HRESULT hres = S_OK;
117 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
118 if(NS_FAILED(nsres)) {
119 ERR("CreateRange failed: %08x\n", nsres);
120 return E_FAIL;
123 nsAString_InitDepend(&html_str, html);
124 nsIDOMRange_CreateContextualFragment(range, &html_str, &nsfragment);
125 nsIDOMRange_Release(range);
126 nsAString_Finish(&html_str);
127 if(NS_FAILED(nsres)) {
128 ERR("CreateContextualFragment failed: %08x\n", nsres);
129 return E_FAIL;
132 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
133 if(NS_SUCCEEDED(nsres) && nsparent) {
134 nsIDOMNode *nstmp;
136 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
137 nsIDOMNode_Release(nsparent);
138 if(NS_FAILED(nsres)) {
139 ERR("ReplaceChild failed: %08x\n", nsres);
140 hres = E_FAIL;
141 }else if(nstmp) {
142 nsIDOMNode_Release(nstmp);
144 }else {
145 ERR("GetParentNode failed: %08x\n", nsres);
146 hres = E_FAIL;
149 nsIDOMDocumentFragment_Release(nsfragment);
150 return hres;
153 typedef struct
155 DispatchEx dispex;
156 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
158 LONG ref;
159 } HTMLFiltersCollection;
161 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
163 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
166 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
168 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
170 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
173 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
175 nsIDOMElement *nselem;
176 nsAString tag_str;
177 nsresult nsres;
179 if(!doc->nsdoc) {
180 WARN("NULL nsdoc\n");
181 return E_UNEXPECTED;
184 nsAString_InitDepend(&tag_str, tag);
185 nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
186 nsAString_Finish(&tag_str);
187 if(NS_FAILED(nsres)) {
188 ERR("CreateElement failed: %08x\n", nsres);
189 return E_FAIL;
192 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
193 nsIDOMElement_Release(nselem);
194 if(NS_FAILED(nsres)) {
195 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
196 return E_FAIL;
199 return S_OK;
202 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
203 REFIID riid, void **ppv)
205 HTMLElement *This = impl_from_IHTMLElement(iface);
207 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
210 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
212 HTMLElement *This = impl_from_IHTMLElement(iface);
214 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
217 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
219 HTMLElement *This = impl_from_IHTMLElement(iface);
221 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
224 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
226 HTMLElement *This = impl_from_IHTMLElement(iface);
227 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
230 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
231 LCID lcid, ITypeInfo **ppTInfo)
233 HTMLElement *This = impl_from_IHTMLElement(iface);
234 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
237 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
238 LPOLESTR *rgszNames, UINT cNames,
239 LCID lcid, DISPID *rgDispId)
241 HTMLElement *This = impl_from_IHTMLElement(iface);
242 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
243 lcid, rgDispId);
246 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
247 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
248 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
250 HTMLElement *This = impl_from_IHTMLElement(iface);
251 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
252 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
255 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
256 VARIANT AttributeValue, LONG lFlags)
258 HTMLElement *This = impl_from_IHTMLElement(iface);
259 HRESULT hres;
260 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
261 DISPPARAMS dispParams;
262 EXCEPINFO excep;
264 TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
266 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
267 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
268 if(FAILED(hres))
269 return hres;
271 dispParams.cArgs = 1;
272 dispParams.cNamedArgs = 1;
273 dispParams.rgdispidNamedArgs = &dispidNamed;
274 dispParams.rgvarg = &AttributeValue;
276 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
277 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
278 return hres;
281 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
282 LONG lFlags, VARIANT *AttributeValue)
284 HTMLElement *This = impl_from_IHTMLElement(iface);
285 DISPID dispid;
286 HRESULT hres;
287 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
288 EXCEPINFO excep;
290 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
292 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
293 fdexNameCaseInsensitive, &dispid);
294 if(hres == DISP_E_UNKNOWNNAME) {
295 V_VT(AttributeValue) = VT_NULL;
296 return S_OK;
299 if(FAILED(hres)) {
300 V_VT(AttributeValue) = VT_NULL;
301 return hres;
304 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
305 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
307 return hres;
310 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
311 LONG lFlags, VARIANT_BOOL *pfSuccess)
313 HTMLElement *This = impl_from_IHTMLElement(iface);
315 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
317 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
320 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
322 HTMLElement *This = impl_from_IHTMLElement(iface);
323 nsAString classname_str;
324 nsresult nsres;
326 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
328 if(!This->nselem) {
329 FIXME("NULL nselem\n");
330 return E_NOTIMPL;
333 nsAString_InitDepend(&classname_str, v);
334 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
335 nsAString_Finish(&classname_str);
336 if(NS_FAILED(nsres))
337 ERR("SetClassName failed: %08x\n", nsres);
339 return S_OK;
342 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
344 HTMLElement *This = impl_from_IHTMLElement(iface);
345 nsAString class_str;
346 nsresult nsres;
348 TRACE("(%p)->(%p)\n", This, p);
350 if(!This->nselem) {
351 FIXME("NULL nselem\n");
352 return E_NOTIMPL;
355 nsAString_Init(&class_str, NULL);
356 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
357 return return_nsstr(nsres, &class_str, p);
360 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
362 HTMLElement *This = impl_from_IHTMLElement(iface);
363 nsAString id_str;
364 nsresult nsres;
366 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
368 if(!This->nselem) {
369 FIXME("nselem == NULL\n");
370 return S_OK;
373 nsAString_InitDepend(&id_str, v);
374 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
375 nsAString_Finish(&id_str);
376 if(NS_FAILED(nsres))
377 ERR("SetId failed: %08x\n", nsres);
379 return S_OK;
382 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
384 HTMLElement *This = impl_from_IHTMLElement(iface);
385 nsAString id_str;
386 nsresult nsres;
388 TRACE("(%p)->(%p)\n", This, p);
390 if(!This->nselem) {
391 *p = NULL;
392 return S_OK;
395 nsAString_Init(&id_str, NULL);
396 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
397 return return_nsstr(nsres, &id_str, p);
400 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
402 HTMLElement *This = impl_from_IHTMLElement(iface);
403 nsAString tag_str;
404 nsresult nsres;
406 TRACE("(%p)->(%p)\n", This, p);
408 if(!This->nselem) {
409 static const WCHAR comment_tagW[] = {'!',0};
411 WARN("NULL nselem, assuming comment\n");
413 *p = SysAllocString(comment_tagW);
414 return *p ? S_OK : E_OUTOFMEMORY;
417 nsAString_Init(&tag_str, NULL);
418 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
419 return return_nsstr(nsres, &tag_str, p);
422 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
424 HTMLElement *This = impl_from_IHTMLElement(iface);
425 IHTMLDOMNode *node;
426 HRESULT hres;
428 TRACE("(%p)->(%p)\n", This, p);
430 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
431 if(FAILED(hres))
432 return hres;
434 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
435 IHTMLDOMNode_Release(node);
436 if(FAILED(hres))
437 *p = NULL;
439 return S_OK;
442 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
444 HTMLElement *This = impl_from_IHTMLElement(iface);
446 TRACE("(%p)->(%p)\n", This, p);
448 if(!This->style) {
449 HRESULT hres;
451 hres = HTMLStyle_Create(This, &This->style);
452 if(FAILED(hres))
453 return hres;
456 *p = &This->style->IHTMLStyle_iface;
457 IHTMLStyle_AddRef(*p);
458 return S_OK;
461 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
463 HTMLElement *This = impl_from_IHTMLElement(iface);
464 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
465 return E_NOTIMPL;
468 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
470 HTMLElement *This = impl_from_IHTMLElement(iface);
471 FIXME("(%p)->(%p)\n", This, p);
472 return E_NOTIMPL;
475 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
477 HTMLElement *This = impl_from_IHTMLElement(iface);
479 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
481 return set_node_event(&This->node, EVENTID_CLICK, &v);
484 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
486 HTMLElement *This = impl_from_IHTMLElement(iface);
488 TRACE("(%p)->(%p)\n", This, p);
490 return get_node_event(&This->node, EVENTID_CLICK, p);
493 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
495 HTMLElement *This = impl_from_IHTMLElement(iface);
497 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
499 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
502 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
504 HTMLElement *This = impl_from_IHTMLElement(iface);
506 TRACE("(%p)->(%p)\n", This, p);
508 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
511 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
513 HTMLElement *This = impl_from_IHTMLElement(iface);
515 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
517 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
520 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
522 HTMLElement *This = impl_from_IHTMLElement(iface);
524 TRACE("(%p)->(%p)\n", This, p);
526 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
529 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
531 HTMLElement *This = impl_from_IHTMLElement(iface);
533 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
535 return set_node_event(&This->node, EVENTID_KEYUP, &v);
538 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
540 HTMLElement *This = impl_from_IHTMLElement(iface);
541 FIXME("(%p)->(%p)\n", This, p);
542 return E_NOTIMPL;
545 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
547 HTMLElement *This = impl_from_IHTMLElement(iface);
549 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
551 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
554 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
556 HTMLElement *This = impl_from_IHTMLElement(iface);
558 TRACE("(%p)->(%p)\n", This, p);
560 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
563 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
565 HTMLElement *This = impl_from_IHTMLElement(iface);
567 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
569 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
572 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
574 HTMLElement *This = impl_from_IHTMLElement(iface);
576 TRACE("(%p)->(%p)\n", This, p);
578 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
581 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
583 HTMLElement *This = impl_from_IHTMLElement(iface);
585 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
587 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
590 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
592 HTMLElement *This = impl_from_IHTMLElement(iface);
594 TRACE("(%p)->(%p)\n", This, p);
596 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
599 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
601 HTMLElement *This = impl_from_IHTMLElement(iface);
603 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
605 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
608 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
610 HTMLElement *This = impl_from_IHTMLElement(iface);
612 TRACE("(%p)->(%p)\n", This, p);
614 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
617 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
619 HTMLElement *This = impl_from_IHTMLElement(iface);
621 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
623 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
626 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
628 HTMLElement *This = impl_from_IHTMLElement(iface);
630 TRACE("(%p)->(%p)\n", This, p);
632 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
635 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
637 HTMLElement *This = impl_from_IHTMLElement(iface);
639 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
641 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
644 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
646 HTMLElement *This = impl_from_IHTMLElement(iface);
648 TRACE("(%p)->(%p)\n", This, p);
650 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
653 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
655 HTMLElement *This = impl_from_IHTMLElement(iface);
657 TRACE("(%p)->(%p)\n", This, p);
659 if(!p)
660 return E_POINTER;
662 if(This->node.vtbl->get_document)
663 return This->node.vtbl->get_document(&This->node, p);
665 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
666 IDispatch_AddRef(*p);
667 return S_OK;
670 static const WCHAR titleW[] = {'t','i','t','l','e',0};
672 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
674 HTMLElement *This = impl_from_IHTMLElement(iface);
675 nsAString title_str;
676 nsresult nsres;
678 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
680 if(!This->nselem) {
681 VARIANT *var;
682 HRESULT hres;
684 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
685 if(FAILED(hres))
686 return hres;
688 VariantClear(var);
689 V_VT(var) = VT_BSTR;
690 V_BSTR(var) = v ? SysAllocString(v) : NULL;
691 return S_OK;
694 nsAString_InitDepend(&title_str, v);
695 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
696 nsAString_Finish(&title_str);
697 if(NS_FAILED(nsres))
698 ERR("SetTitle failed: %08x\n", nsres);
700 return S_OK;
703 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
705 HTMLElement *This = impl_from_IHTMLElement(iface);
706 nsAString title_str;
707 nsresult nsres;
709 TRACE("(%p)->(%p)\n", This, p);
711 if(!This->nselem) {
712 VARIANT *var;
713 HRESULT hres;
715 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
716 if(hres == DISP_E_UNKNOWNNAME) {
717 *p = NULL;
718 }else if(V_VT(var) != VT_BSTR) {
719 FIXME("title = %s\n", debugstr_variant(var));
720 return E_FAIL;
721 }else {
722 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
725 return S_OK;
728 nsAString_Init(&title_str, NULL);
729 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
730 return return_nsstr(nsres, &title_str, p);
733 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
735 HTMLElement *This = impl_from_IHTMLElement(iface);
736 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
737 return E_NOTIMPL;
740 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
742 HTMLElement *This = impl_from_IHTMLElement(iface);
743 FIXME("(%p)->(%p)\n", This, p);
744 return E_NOTIMPL;
747 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
749 HTMLElement *This = impl_from_IHTMLElement(iface);
751 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
753 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
756 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
758 HTMLElement *This = impl_from_IHTMLElement(iface);
760 TRACE("(%p)->(%p)\n", This, p);
762 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
765 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
767 HTMLElement *This = impl_from_IHTMLElement(iface);
768 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
769 return E_NOTIMPL;
772 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
773 VARIANT_BOOL *pfResult)
775 HTMLElement *This = impl_from_IHTMLElement(iface);
776 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
777 return E_NOTIMPL;
780 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
782 HTMLElement *This = impl_from_IHTMLElement(iface);
783 FIXME("(%p)->(%p)\n", This, p);
784 return E_NOTIMPL;
787 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
789 HTMLElement *This = impl_from_IHTMLElement(iface);
790 FIXME("(%p)->(%p)\n", This, p);
791 return E_NOTIMPL;
794 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
796 HTMLElement *This = impl_from_IHTMLElement(iface);
797 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
798 return E_NOTIMPL;
801 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
803 HTMLElement *This = impl_from_IHTMLElement(iface);
804 FIXME("(%p)->(%p)\n", This, p);
805 return E_NOTIMPL;
808 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
810 HTMLElement *This = impl_from_IHTMLElement(iface);
811 PRInt32 off_left = 0;
812 nsresult nsres;
814 TRACE("(%p)->(%p)\n", This, p);
816 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, &off_left);
817 if(NS_FAILED(nsres)) {
818 ERR("GetOffsetLeft failed: %08x\n", nsres);
819 return E_FAIL;
822 *p = off_left;
823 return S_OK;
826 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
828 HTMLElement *This = impl_from_IHTMLElement(iface);
829 PRInt32 top = 0;
830 nsresult nsres;
832 TRACE("(%p)->(%p)\n", This, p);
834 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, &top);
835 if(NS_FAILED(nsres)) {
836 ERR("GetOffsetTop failed: %08x\n", nsres);
837 return E_FAIL;
840 *p = top;
841 return S_OK;
844 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
846 HTMLElement *This = impl_from_IHTMLElement(iface);
847 PRInt32 offset = 0;
848 nsresult nsres;
850 TRACE("(%p)->(%p)\n", This, p);
852 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, &offset);
853 if(NS_FAILED(nsres)) {
854 ERR("GetOffsetWidth failed: %08x\n", nsres);
855 return E_FAIL;
858 *p = offset;
859 return S_OK;
862 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
864 HTMLElement *This = impl_from_IHTMLElement(iface);
865 PRInt32 offset = 0;
866 nsresult nsres;
868 TRACE("(%p)->(%p)\n", This, p);
870 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, &offset);
871 if(NS_FAILED(nsres)) {
872 ERR("GetOffsetHeight failed: %08x\n", nsres);
873 return E_FAIL;
876 *p = offset;
877 return S_OK;
880 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
882 HTMLElement *This = impl_from_IHTMLElement(iface);
883 nsIDOMElement *nsparent;
884 nsresult nsres;
885 HRESULT hres;
887 TRACE("(%p)->(%p)\n", This, p);
889 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
890 if(NS_FAILED(nsres)) {
891 ERR("GetOffsetParent failed: %08x\n", nsres);
892 return E_FAIL;
895 if(nsparent) {
896 HTMLDOMNode *node;
898 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
899 nsIDOMElement_Release(nsparent);
900 if(FAILED(hres))
901 return hres;
903 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
904 node_release(node);
905 }else {
906 *p = NULL;
907 hres = S_OK;
910 return hres;
913 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
915 HTMLElement *This = impl_from_IHTMLElement(iface);
916 nsAString html_str;
917 nsresult nsres;
919 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
921 if(!This->nselem) {
922 FIXME("NULL nselem\n");
923 return E_NOTIMPL;
926 nsAString_InitDepend(&html_str, v);
927 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
928 nsAString_Finish(&html_str);
929 if(NS_FAILED(nsres)) {
930 FIXME("SetInnerHtml failed %08x\n", nsres);
931 return E_FAIL;
934 return S_OK;
937 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
939 HTMLElement *This = impl_from_IHTMLElement(iface);
940 nsAString html_str;
941 nsresult nsres;
943 TRACE("(%p)->(%p)\n", This, p);
945 if(!This->nselem) {
946 FIXME("NULL nselem\n");
947 return E_NOTIMPL;
950 nsAString_Init(&html_str, NULL);
951 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
952 return return_nsstr(nsres, &html_str, p);
955 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
957 HTMLElement *This = impl_from_IHTMLElement(iface);
958 nsIDOMNode *nschild, *tmp;
959 nsIDOMText *text_node;
960 nsAString text_str;
961 nsresult nsres;
963 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
965 while(1) {
966 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
967 if(NS_FAILED(nsres)) {
968 ERR("GetLastChild failed: %08x\n", nsres);
969 return E_FAIL;
971 if(!nschild)
972 break;
974 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
975 nsIDOMNode_Release(nschild);
976 if(NS_FAILED(nsres)) {
977 ERR("RemoveChild failed: %08x\n", nsres);
978 return E_FAIL;
980 nsIDOMNode_Release(tmp);
983 nsAString_InitDepend(&text_str, v);
984 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
985 nsAString_Finish(&text_str);
986 if(NS_FAILED(nsres)) {
987 ERR("CreateTextNode failed: %08x\n", nsres);
988 return E_FAIL;
991 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
992 if(NS_FAILED(nsres)) {
993 ERR("AppendChild failed: %08x\n", nsres);
994 return E_FAIL;
997 nsIDOMNode_Release(tmp);
998 return S_OK;
1001 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1003 HTMLElement *This = impl_from_IHTMLElement(iface);
1005 TRACE("(%p)->(%p)\n", This, p);
1007 return get_node_text(&This->node, p);
1010 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1012 HTMLElement *This = impl_from_IHTMLElement(iface);
1014 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1016 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1019 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1021 HTMLElement *This = impl_from_IHTMLElement(iface);
1022 nsAString html_str;
1023 HRESULT hres;
1025 WARN("(%p)->(%p) semi-stub\n", This, p);
1027 nsAString_Init(&html_str, NULL);
1028 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1029 if(SUCCEEDED(hres)) {
1030 const PRUnichar *html;
1032 nsAString_GetData(&html_str, &html);
1033 *p = SysAllocString(html);
1034 if(!*p)
1035 hres = E_OUTOFMEMORY;
1038 nsAString_Finish(&html_str);
1040 TRACE("ret %s\n", debugstr_w(*p));
1041 return hres;
1044 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1046 HTMLElement *This = impl_from_IHTMLElement(iface);
1047 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1048 return E_NOTIMPL;
1051 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1053 HTMLElement *This = impl_from_IHTMLElement(iface);
1054 FIXME("(%p)->(%p)\n", This, p);
1055 return E_NOTIMPL;
1058 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1060 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1061 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1062 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1063 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1064 nsresult nsres;
1066 if (!strcmpiW(where, wszBeforeBegin))
1068 nsIDOMNode *unused;
1069 nsIDOMNode *parent;
1070 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1071 if (!parent) return E_INVALIDARG;
1072 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1073 if (unused) nsIDOMNode_Release(unused);
1074 nsIDOMNode_Release(parent);
1076 else if (!strcmpiW(where, wszAfterBegin))
1078 nsIDOMNode *unused;
1079 nsIDOMNode *first_child;
1080 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1081 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1082 if (unused) nsIDOMNode_Release(unused);
1083 if (first_child) nsIDOMNode_Release(first_child);
1085 else if (!strcmpiW(where, wszBeforeEnd))
1087 nsIDOMNode *unused;
1088 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1089 if (unused) nsIDOMNode_Release(unused);
1091 else if (!strcmpiW(where, wszAfterEnd))
1093 nsIDOMNode *unused;
1094 nsIDOMNode *next_sibling;
1095 nsIDOMNode *parent;
1096 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1097 if (!parent) return E_INVALIDARG;
1099 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1100 if (next_sibling)
1102 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1103 nsIDOMNode_Release(next_sibling);
1105 else
1106 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1107 nsIDOMNode_Release(parent);
1108 if (unused) nsIDOMNode_Release(unused);
1110 else
1112 ERR("invalid where: %s\n", debugstr_w(where));
1113 return E_INVALIDARG;
1116 if (NS_FAILED(nsres))
1117 return E_FAIL;
1118 else
1119 return S_OK;
1122 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1123 BSTR html)
1125 HTMLElement *This = impl_from_IHTMLElement(iface);
1126 nsIDOMRange *range;
1127 nsIDOMNode *nsnode;
1128 nsAString ns_html;
1129 nsresult nsres;
1130 HRESULT hr;
1132 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1134 if(!This->node.doc->nsdoc) {
1135 WARN("NULL nsdoc\n");
1136 return E_UNEXPECTED;
1139 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1140 if(NS_FAILED(nsres))
1142 ERR("CreateRange failed: %08x\n", nsres);
1143 return E_FAIL;
1146 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1148 nsAString_InitDepend(&ns_html, html);
1149 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1150 nsAString_Finish(&ns_html);
1151 nsIDOMRange_Release(range);
1153 if(NS_FAILED(nsres) || !nsnode)
1155 ERR("CreateTextNode failed: %08x\n", nsres);
1156 return E_FAIL;
1159 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1160 nsIDOMNode_Release(nsnode);
1162 return hr;
1165 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1166 BSTR text)
1168 HTMLElement *This = impl_from_IHTMLElement(iface);
1169 nsIDOMNode *nsnode;
1170 nsAString ns_text;
1171 nsresult nsres;
1172 HRESULT hr;
1174 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1176 if(!This->node.doc->nsdoc) {
1177 WARN("NULL nsdoc\n");
1178 return E_UNEXPECTED;
1182 nsAString_InitDepend(&ns_text, text);
1183 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1184 nsAString_Finish(&ns_text);
1186 if(NS_FAILED(nsres) || !nsnode)
1188 ERR("CreateTextNode failed: %08x\n", nsres);
1189 return E_FAIL;
1192 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1193 nsIDOMNode_Release(nsnode);
1195 return hr;
1198 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1200 HTMLElement *This = impl_from_IHTMLElement(iface);
1201 FIXME("(%p)->(%p)\n", This, p);
1202 return E_NOTIMPL;
1205 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1207 HTMLElement *This = impl_from_IHTMLElement(iface);
1208 FIXME("(%p)->(%p)\n", This, p);
1209 return E_NOTIMPL;
1212 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1214 HTMLElement *This = impl_from_IHTMLElement(iface);
1216 TRACE("(%p)\n", This);
1218 return call_fire_event(&This->node, EVENTID_CLICK);
1221 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1222 IHTMLFiltersCollection **p)
1224 HTMLElement *This = impl_from_IHTMLElement(iface);
1225 TRACE("(%p)->(%p)\n", This, p);
1227 if(!p)
1228 return E_POINTER;
1230 *p = HTMLFiltersCollection_Create();
1232 return S_OK;
1235 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1237 HTMLElement *This = impl_from_IHTMLElement(iface);
1238 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1239 return E_NOTIMPL;
1242 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1244 HTMLElement *This = impl_from_IHTMLElement(iface);
1245 FIXME("(%p)->(%p)\n", This, p);
1246 return E_NOTIMPL;
1249 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1251 HTMLElement *This = impl_from_IHTMLElement(iface);
1252 FIXME("(%p)->(%p)\n", This, String);
1253 return E_NOTIMPL;
1256 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1258 HTMLElement *This = impl_from_IHTMLElement(iface);
1259 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1260 return E_NOTIMPL;
1263 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1265 HTMLElement *This = impl_from_IHTMLElement(iface);
1266 FIXME("(%p)->(%p)\n", This, p);
1267 return E_NOTIMPL;
1270 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1272 HTMLElement *This = impl_from_IHTMLElement(iface);
1273 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1274 return E_NOTIMPL;
1277 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1279 HTMLElement *This = impl_from_IHTMLElement(iface);
1280 FIXME("(%p)->(%p)\n", This, p);
1281 return E_NOTIMPL;
1284 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1286 HTMLElement *This = impl_from_IHTMLElement(iface);
1287 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1288 return E_NOTIMPL;
1291 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1293 HTMLElement *This = impl_from_IHTMLElement(iface);
1294 FIXME("(%p)->(%p)\n", This, p);
1295 return E_NOTIMPL;
1298 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1300 HTMLElement *This = impl_from_IHTMLElement(iface);
1301 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1302 return E_NOTIMPL;
1305 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1307 HTMLElement *This = impl_from_IHTMLElement(iface);
1308 FIXME("(%p)->(%p)\n", This, p);
1309 return E_NOTIMPL;
1312 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1314 HTMLElement *This = impl_from_IHTMLElement(iface);
1315 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1316 return E_NOTIMPL;
1319 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1321 HTMLElement *This = impl_from_IHTMLElement(iface);
1322 FIXME("(%p)->(%p)\n", This, p);
1323 return E_NOTIMPL;
1326 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1328 HTMLElement *This = impl_from_IHTMLElement(iface);
1329 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1330 return E_NOTIMPL;
1333 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1335 HTMLElement *This = impl_from_IHTMLElement(iface);
1336 FIXME("(%p)->(%p)\n", This, p);
1337 return E_NOTIMPL;
1340 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1342 HTMLElement *This = impl_from_IHTMLElement(iface);
1343 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1344 return E_NOTIMPL;
1347 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1349 HTMLElement *This = impl_from_IHTMLElement(iface);
1350 FIXME("(%p)->(%p)\n", This, p);
1351 return E_NOTIMPL;
1354 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1356 HTMLElement *This = impl_from_IHTMLElement(iface);
1357 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1358 return E_NOTIMPL;
1361 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1363 HTMLElement *This = impl_from_IHTMLElement(iface);
1364 FIXME("(%p)->(%p)\n", This, p);
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1370 HTMLElement *This = impl_from_IHTMLElement(iface);
1371 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1372 return E_NOTIMPL;
1375 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1377 HTMLElement *This = impl_from_IHTMLElement(iface);
1378 FIXME("(%p)->(%p)\n", This, p);
1379 return E_NOTIMPL;
1382 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1384 HTMLElement *This = impl_from_IHTMLElement(iface);
1385 nsIDOMNodeList *nsnode_list;
1386 nsresult nsres;
1388 TRACE("(%p)->(%p)\n", This, p);
1390 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1391 if(NS_FAILED(nsres)) {
1392 ERR("GetChildNodes failed: %08x\n", nsres);
1393 return E_FAIL;
1396 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1398 nsIDOMNodeList_Release(nsnode_list);
1399 return S_OK;
1402 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1404 HTMLElement *This = impl_from_IHTMLElement(iface);
1406 TRACE("(%p)->(%p)\n", This, p);
1408 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1409 return S_OK;
1412 static const IHTMLElementVtbl HTMLElementVtbl = {
1413 HTMLElement_QueryInterface,
1414 HTMLElement_AddRef,
1415 HTMLElement_Release,
1416 HTMLElement_GetTypeInfoCount,
1417 HTMLElement_GetTypeInfo,
1418 HTMLElement_GetIDsOfNames,
1419 HTMLElement_Invoke,
1420 HTMLElement_setAttribute,
1421 HTMLElement_getAttribute,
1422 HTMLElement_removeAttribute,
1423 HTMLElement_put_className,
1424 HTMLElement_get_className,
1425 HTMLElement_put_id,
1426 HTMLElement_get_id,
1427 HTMLElement_get_tagName,
1428 HTMLElement_get_parentElement,
1429 HTMLElement_get_style,
1430 HTMLElement_put_onhelp,
1431 HTMLElement_get_onhelp,
1432 HTMLElement_put_onclick,
1433 HTMLElement_get_onclick,
1434 HTMLElement_put_ondblclick,
1435 HTMLElement_get_ondblclick,
1436 HTMLElement_put_onkeydown,
1437 HTMLElement_get_onkeydown,
1438 HTMLElement_put_onkeyup,
1439 HTMLElement_get_onkeyup,
1440 HTMLElement_put_onkeypress,
1441 HTMLElement_get_onkeypress,
1442 HTMLElement_put_onmouseout,
1443 HTMLElement_get_onmouseout,
1444 HTMLElement_put_onmouseover,
1445 HTMLElement_get_onmouseover,
1446 HTMLElement_put_onmousemove,
1447 HTMLElement_get_onmousemove,
1448 HTMLElement_put_onmousedown,
1449 HTMLElement_get_onmousedown,
1450 HTMLElement_put_onmouseup,
1451 HTMLElement_get_onmouseup,
1452 HTMLElement_get_document,
1453 HTMLElement_put_title,
1454 HTMLElement_get_title,
1455 HTMLElement_put_language,
1456 HTMLElement_get_language,
1457 HTMLElement_put_onselectstart,
1458 HTMLElement_get_onselectstart,
1459 HTMLElement_scrollIntoView,
1460 HTMLElement_contains,
1461 HTMLElement_get_sourceIndex,
1462 HTMLElement_get_recordNumber,
1463 HTMLElement_put_lang,
1464 HTMLElement_get_lang,
1465 HTMLElement_get_offsetLeft,
1466 HTMLElement_get_offsetTop,
1467 HTMLElement_get_offsetWidth,
1468 HTMLElement_get_offsetHeight,
1469 HTMLElement_get_offsetParent,
1470 HTMLElement_put_innerHTML,
1471 HTMLElement_get_innerHTML,
1472 HTMLElement_put_innerText,
1473 HTMLElement_get_innerText,
1474 HTMLElement_put_outerHTML,
1475 HTMLElement_get_outerHTML,
1476 HTMLElement_put_outerText,
1477 HTMLElement_get_outerText,
1478 HTMLElement_insertAdjacentHTML,
1479 HTMLElement_insertAdjacentText,
1480 HTMLElement_get_parentTextEdit,
1481 HTMLElement_get_isTextEdit,
1482 HTMLElement_click,
1483 HTMLElement_get_filters,
1484 HTMLElement_put_ondragstart,
1485 HTMLElement_get_ondragstart,
1486 HTMLElement_toString,
1487 HTMLElement_put_onbeforeupdate,
1488 HTMLElement_get_onbeforeupdate,
1489 HTMLElement_put_onafterupdate,
1490 HTMLElement_get_onafterupdate,
1491 HTMLElement_put_onerrorupdate,
1492 HTMLElement_get_onerrorupdate,
1493 HTMLElement_put_onrowexit,
1494 HTMLElement_get_onrowexit,
1495 HTMLElement_put_onrowenter,
1496 HTMLElement_get_onrowenter,
1497 HTMLElement_put_ondatasetchanged,
1498 HTMLElement_get_ondatasetchanged,
1499 HTMLElement_put_ondataavailable,
1500 HTMLElement_get_ondataavailable,
1501 HTMLElement_put_ondatasetcomplete,
1502 HTMLElement_get_ondatasetcomplete,
1503 HTMLElement_put_onfilterchange,
1504 HTMLElement_get_onfilterchange,
1505 HTMLElement_get_children,
1506 HTMLElement_get_all
1509 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1511 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1514 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1516 return CONTAINING_RECORD(iface, HTMLElement, node);
1519 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1521 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1523 *ppv = NULL;
1525 if(IsEqualGUID(&IID_IUnknown, riid)) {
1526 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1527 *ppv = &This->IHTMLElement_iface;
1528 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1529 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1530 *ppv = &This->IHTMLElement_iface;
1531 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1532 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1533 *ppv = &This->IHTMLElement_iface;
1534 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1535 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1536 *ppv = &This->IHTMLElement2_iface;
1537 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1538 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1539 *ppv = &This->IHTMLElement3_iface;
1540 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1541 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1542 *ppv = &This->IHTMLElement4_iface;
1543 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1544 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1545 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1548 if(*ppv) {
1549 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1550 return S_OK;
1553 return HTMLDOMNode_QI(&This->node, riid, ppv);
1556 void HTMLElement_destructor(HTMLDOMNode *iface)
1558 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1560 ConnectionPointContainer_Destroy(&This->cp_container);
1562 if(This->style) {
1563 This->style->elem = NULL;
1564 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1566 if(This->runtime_style) {
1567 This->runtime_style->elem = NULL;
1568 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1570 if(This->attrs) {
1571 HTMLDOMAttribute *attr;
1573 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1574 attr->elem = NULL;
1576 This->attrs->elem = NULL;
1577 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1580 heap_free(This->filter);
1582 HTMLDOMNode_destructor(&This->node);
1585 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1587 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1588 HTMLElement *new_elem;
1589 HRESULT hres;
1591 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1592 if(FAILED(hres))
1593 return hres;
1595 if(This->filter) {
1596 new_elem->filter = heap_strdupW(This->filter);
1597 if(!new_elem->filter) {
1598 IHTMLElement_Release(&This->IHTMLElement_iface);
1599 return E_OUTOFMEMORY;
1603 *ret = &new_elem->node;
1604 return S_OK;
1607 static const NodeImplVtbl HTMLElementImplVtbl = {
1608 HTMLElement_QI,
1609 HTMLElement_destructor,
1610 HTMLElement_clone,
1611 HTMLElement_get_attr_col
1614 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1616 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1619 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1620 DWORD grfdex, DISPID *pid)
1622 HTMLElement *This = impl_from_DispatchEx(dispex);
1624 if(This->node.vtbl->get_dispid)
1625 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1627 return DISP_E_UNKNOWNNAME;
1630 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1631 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1632 IServiceProvider *caller)
1634 HTMLElement *This = impl_from_DispatchEx(dispex);
1636 if(This->node.vtbl->invoke)
1637 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1638 params, res, ei, caller);
1640 ERR("(%p): element has no invoke method\n", This);
1641 return E_NOTIMPL;
1644 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1646 HTMLElement *This = impl_from_DispatchEx(dispex);
1647 nsIDOMNamedNodeMap *attrs;
1648 nsIDOMNode *node;
1649 nsAString nsstr;
1650 const PRUnichar *str;
1651 BSTR name;
1652 VARIANT value;
1653 unsigned i;
1654 PRUint32 len;
1655 DISPID id;
1656 nsresult nsres;
1657 HRESULT hres;
1659 if(!This->nselem)
1660 return S_FALSE;
1662 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1663 if(NS_FAILED(nsres))
1664 return E_FAIL;
1666 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1667 if(NS_FAILED(nsres)) {
1668 nsIDOMNamedNodeMap_Release(attrs);
1669 return E_FAIL;
1672 nsAString_Init(&nsstr, NULL);
1673 for(i=0; i<len; i++) {
1674 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1675 if(NS_FAILED(nsres))
1676 continue;
1678 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1679 if(NS_FAILED(nsres)) {
1680 nsIDOMNode_Release(node);
1681 continue;
1684 nsAString_GetData(&nsstr, &str);
1685 name = SysAllocString(str);
1686 if(!name) {
1687 nsIDOMNode_Release(node);
1688 continue;
1691 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1692 if(hres != DISP_E_UNKNOWNNAME) {
1693 nsIDOMNode_Release(node);
1694 SysFreeString(name);
1695 continue;
1698 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1699 nsIDOMNode_Release(node);
1700 if(NS_FAILED(nsres)) {
1701 SysFreeString(name);
1702 continue;
1705 nsAString_GetData(&nsstr, &str);
1706 V_VT(&value) = VT_BSTR;
1707 if(*str) {
1708 V_BSTR(&value) = SysAllocString(str);
1709 if(!V_BSTR(&value)) {
1710 SysFreeString(name);
1711 continue;
1713 } else
1714 V_BSTR(&value) = NULL;
1716 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1717 SysFreeString(name);
1718 VariantClear(&value);
1720 nsAString_Finish(&nsstr);
1722 nsIDOMNamedNodeMap_Release(attrs);
1723 return S_OK;
1726 static const tid_t HTMLElement_iface_tids[] = {
1727 HTMLELEMENT_TIDS,
1731 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1732 NULL,
1733 HTMLElement_get_dispid,
1734 HTMLElement_invoke,
1735 HTMLElement_populate_props
1738 static dispex_static_data_t HTMLElement_dispex = {
1739 &HTMLElement_dispex_vtbl,
1740 DispHTMLUnknownElement_tid,
1741 NULL,
1742 HTMLElement_iface_tids
1745 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1747 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1749 HTMLElement2_Init(This);
1750 HTMLElement3_Init(This);
1752 if(dispex_data && !dispex_data->vtbl)
1753 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1754 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1755 dispex_data ? dispex_data : &HTMLElement_dispex);
1757 if(nselem) {
1758 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1760 /* No AddRef, share reference with HTMLDOMNode */
1761 assert((nsIDOMNode*)nselem == This->node.nsnode);
1762 This->nselem = nselem;
1765 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1768 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1770 nsIDOMHTMLElement *nselem;
1771 nsAString class_name_str;
1772 const PRUnichar *class_name;
1773 const tag_desc_t *tag;
1774 HTMLElement *elem;
1775 nsresult nsres;
1776 HRESULT hres;
1778 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1779 if(NS_FAILED(nsres))
1780 return E_FAIL;
1782 nsAString_Init(&class_name_str, NULL);
1783 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1785 nsAString_GetData(&class_name_str, &class_name);
1787 tag = get_tag_desc(class_name);
1788 if(tag) {
1789 hres = tag->constructor(doc, nselem, &elem);
1790 }else if(use_generic) {
1791 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1792 }else {
1793 elem = heap_alloc_zero(sizeof(HTMLElement));
1794 if(elem) {
1795 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1796 elem->node.vtbl = &HTMLElementImplVtbl;
1797 hres = S_OK;
1798 }else {
1799 hres = E_OUTOFMEMORY;
1803 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1805 nsIDOMHTMLElement_Release(nselem);
1806 nsAString_Finish(&class_name_str);
1807 if(FAILED(hres))
1808 return hres;
1810 *ret = elem;
1811 return S_OK;
1814 /* interface IHTMLFiltersCollection */
1815 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1817 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1819 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1821 if(IsEqualGUID(&IID_IUnknown, riid)) {
1822 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1823 *ppv = &This->IHTMLFiltersCollection_iface;
1824 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1825 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1826 *ppv = &This->IHTMLFiltersCollection_iface;
1827 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1828 return *ppv ? S_OK : E_NOINTERFACE;
1831 if(*ppv) {
1832 IUnknown_AddRef((IUnknown*)*ppv);
1833 return S_OK;
1836 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1837 return E_NOINTERFACE;
1840 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1842 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1843 LONG ref = InterlockedIncrement(&This->ref);
1845 TRACE("(%p) ref=%d\n", This, ref);
1847 return ref;
1850 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1852 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1853 LONG ref = InterlockedDecrement(&This->ref);
1855 TRACE("(%p) ref=%d\n", This, ref);
1857 if(!ref)
1859 heap_free(This);
1862 return ref;
1865 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1867 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1868 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1871 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1872 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1874 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1875 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1878 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1879 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1880 LCID lcid, DISPID *rgDispId)
1882 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1883 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1884 lcid, rgDispId);
1887 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1888 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1889 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1891 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1892 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1893 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1896 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1898 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1900 if(!p)
1901 return E_POINTER;
1903 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1904 *p = 0;
1906 return S_OK;
1909 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1911 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1912 FIXME("(%p)->(%p)\n", This, p);
1913 return E_NOTIMPL;
1916 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1918 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1919 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
1920 return E_NOTIMPL;
1923 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
1924 HTMLFiltersCollection_QueryInterface,
1925 HTMLFiltersCollection_AddRef,
1926 HTMLFiltersCollection_Release,
1927 HTMLFiltersCollection_GetTypeInfoCount,
1928 HTMLFiltersCollection_GetTypeInfo,
1929 HTMLFiltersCollection_GetIDsOfNames,
1930 HTMLFiltersCollection_Invoke,
1931 HTMLFiltersCollection_get_length,
1932 HTMLFiltersCollection_get__newEnum,
1933 HTMLFiltersCollection_item
1936 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
1938 WCHAR *ptr;
1939 int idx = 0;
1941 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1942 idx = idx*10 + (*ptr-'0');
1943 if(*ptr)
1944 return DISP_E_UNKNOWNNAME;
1946 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
1947 TRACE("ret %x\n", *dispid);
1948 return S_OK;
1951 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1952 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1954 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
1956 V_VT(res) = VT_DISPATCH;
1957 V_DISPATCH(res) = NULL;
1959 FIXME("always returning NULL\n");
1961 return S_OK;
1964 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
1965 NULL,
1966 HTMLFiltersCollection_get_dispid,
1967 HTMLFiltersCollection_invoke,
1968 NULL
1971 static const tid_t HTMLFiltersCollection_iface_tids[] = {
1972 IHTMLFiltersCollection_tid,
1975 static dispex_static_data_t HTMLFiltersCollection_dispex = {
1976 &HTMLFiltersCollection_dispex_vtbl,
1977 IHTMLFiltersCollection_tid,
1978 NULL,
1979 HTMLFiltersCollection_iface_tids
1982 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
1984 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
1986 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
1987 ret->ref = 1;
1989 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
1990 &HTMLFiltersCollection_dispex);
1992 return &ret->IHTMLFiltersCollection_iface;
1995 /* interface IHTMLAttributeCollection */
1996 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
1998 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2001 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2003 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2005 *ppv = NULL;
2007 if(IsEqualGUID(&IID_IUnknown, riid)) {
2008 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2009 *ppv = &This->IHTMLAttributeCollection_iface;
2010 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2011 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2012 *ppv = &This->IHTMLAttributeCollection_iface;
2013 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2014 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2015 *ppv = &This->IHTMLAttributeCollection2_iface;
2016 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2017 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2018 *ppv = &This->IHTMLAttributeCollection3_iface;
2019 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2020 return *ppv ? S_OK : E_NOINTERFACE;
2023 if(*ppv) {
2024 IUnknown_AddRef((IUnknown*)*ppv);
2025 return S_OK;
2028 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2029 return E_NOINTERFACE;
2032 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2034 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2035 LONG ref = InterlockedIncrement(&This->ref);
2037 TRACE("(%p) ref=%d\n", This, ref);
2039 return ref;
2042 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2044 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2045 LONG ref = InterlockedDecrement(&This->ref);
2047 TRACE("(%p) ref=%d\n", This, ref);
2049 if(!ref) {
2050 while(!list_empty(&This->attrs)) {
2051 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2053 list_remove(&attr->entry);
2054 attr->elem = NULL;
2055 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2058 heap_free(This);
2061 return ref;
2064 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2066 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2067 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2070 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2071 LCID lcid, ITypeInfo **ppTInfo)
2073 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2074 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2077 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2078 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2080 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2081 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2082 lcid, rgDispId);
2085 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2086 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2087 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2089 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2090 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2091 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2094 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2096 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2097 DISPID id = DISPID_STARTENUM;
2098 LONG len = -1;
2099 HRESULT hres;
2101 FIXME("filter non-enumerable attributes out\n");
2103 while(1) {
2104 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2105 if(FAILED(hres))
2106 return hres;
2107 else if(hres == S_FALSE)
2108 break;
2110 len++;
2111 if(len == *idx)
2112 break;
2115 if(dispid) {
2116 *dispid = id;
2117 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2120 *idx = len+1;
2121 return S_OK;
2124 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2126 HRESULT hres;
2128 if(name[0]>='0' && name[0]<='9') {
2129 WCHAR *end_ptr;
2130 LONG idx;
2132 idx = strtoulW(name, &end_ptr, 10);
2133 if(!*end_ptr) {
2134 hres = get_attr_dispid_by_idx(This, &idx, id);
2135 if(SUCCEEDED(hres))
2136 return hres;
2140 if(!This->elem) {
2141 WARN("NULL elem\n");
2142 return E_UNEXPECTED;
2145 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2146 name, fdexNameCaseInsensitive, id);
2147 return hres;
2150 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2152 HTMLDOMAttribute *iter;
2153 LONG pos = 0;
2154 HRESULT hres;
2156 *attr = NULL;
2157 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2158 if(iter->dispid == id) {
2159 *attr = iter;
2160 break;
2162 pos++;
2165 if(!*attr) {
2166 if(!This->elem) {
2167 WARN("NULL elem\n");
2168 return E_UNEXPECTED;
2171 pos++;
2172 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2173 if(FAILED(hres))
2174 return hres;
2177 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2178 if(list_pos)
2179 *list_pos = pos;
2180 return S_OK;
2183 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2185 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2186 HRESULT hres;
2188 TRACE("(%p)->(%p)\n", This, p);
2190 *p = -1;
2191 hres = get_attr_dispid_by_idx(This, p, NULL);
2192 return hres;
2195 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2197 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2198 FIXME("(%p)->(%p)\n", This, p);
2199 return E_NOTIMPL;
2202 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2204 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2205 HTMLDOMAttribute *attr;
2206 DISPID id;
2207 HRESULT hres;
2209 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2211 switch(V_VT(name)) {
2212 case VT_I4:
2213 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2214 break;
2215 case VT_BSTR:
2216 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2217 break;
2218 default:
2219 FIXME("unsupported name %s\n", debugstr_variant(name));
2220 hres = E_NOTIMPL;
2222 if(hres == DISP_E_UNKNOWNNAME)
2223 return E_INVALIDARG;
2224 if(FAILED(hres))
2225 return hres;
2227 hres = get_domattr(This, id, NULL, &attr);
2228 if(FAILED(hres))
2229 return hres;
2231 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2232 return S_OK;
2235 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2236 HTMLAttributeCollection_QueryInterface,
2237 HTMLAttributeCollection_AddRef,
2238 HTMLAttributeCollection_Release,
2239 HTMLAttributeCollection_GetTypeInfoCount,
2240 HTMLAttributeCollection_GetTypeInfo,
2241 HTMLAttributeCollection_GetIDsOfNames,
2242 HTMLAttributeCollection_Invoke,
2243 HTMLAttributeCollection_get_length,
2244 HTMLAttributeCollection__newEnum,
2245 HTMLAttributeCollection_item
2248 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2250 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2253 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2255 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2256 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2259 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2261 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2262 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2265 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2267 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2268 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2271 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2273 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2274 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2277 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2278 LCID lcid, ITypeInfo **ppTInfo)
2280 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2281 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2284 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2285 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2287 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2288 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2289 lcid, rgDispId);
2292 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2293 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2294 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2296 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2297 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2298 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2301 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2302 IHTMLDOMAttribute **newretNode)
2304 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2305 HTMLDOMAttribute *attr;
2306 DISPID id;
2307 HRESULT hres;
2309 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2311 hres = get_attr_dispid_by_name(This, bstrName, &id);
2312 if(hres == DISP_E_UNKNOWNNAME) {
2313 *newretNode = NULL;
2314 return S_OK;
2315 } else if(FAILED(hres)) {
2316 return hres;
2319 hres = get_domattr(This, id, NULL, &attr);
2320 if(FAILED(hres))
2321 return hres;
2323 *newretNode = &attr->IHTMLDOMAttribute_iface;
2324 return S_OK;
2327 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2328 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2330 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2331 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2332 return E_NOTIMPL;
2335 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2336 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2338 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2339 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2340 return E_NOTIMPL;
2343 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2344 HTMLAttributeCollection2_QueryInterface,
2345 HTMLAttributeCollection2_AddRef,
2346 HTMLAttributeCollection2_Release,
2347 HTMLAttributeCollection2_GetTypeInfoCount,
2348 HTMLAttributeCollection2_GetTypeInfo,
2349 HTMLAttributeCollection2_GetIDsOfNames,
2350 HTMLAttributeCollection2_Invoke,
2351 HTMLAttributeCollection2_getNamedItem,
2352 HTMLAttributeCollection2_setNamedItem,
2353 HTMLAttributeCollection2_removeNamedItem
2356 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2358 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2361 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2363 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2364 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2367 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2369 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2370 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2373 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2375 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2376 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2379 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2381 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2382 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2385 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2386 LCID lcid, ITypeInfo **ppTInfo)
2388 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2389 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2392 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2393 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2395 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2396 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2397 lcid, rgDispId);
2400 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2401 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2402 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2404 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2405 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2406 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2409 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2410 IHTMLDOMAttribute **ppNodeOut)
2412 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2413 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2416 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2417 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2419 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2420 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2421 return E_NOTIMPL;
2424 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2425 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2427 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2428 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2429 return E_NOTIMPL;
2432 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2434 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2435 HTMLDOMAttribute *attr;
2436 DISPID id;
2437 HRESULT hres;
2439 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2441 hres = get_attr_dispid_by_idx(This, &index, &id);
2442 if(hres == DISP_E_UNKNOWNNAME)
2443 return E_INVALIDARG;
2444 if(FAILED(hres))
2445 return hres;
2447 hres = get_domattr(This, id, NULL, &attr);
2448 if(FAILED(hres))
2449 return hres;
2451 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2452 return S_OK;
2455 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2457 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2458 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2461 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2462 HTMLAttributeCollection3_QueryInterface,
2463 HTMLAttributeCollection3_AddRef,
2464 HTMLAttributeCollection3_Release,
2465 HTMLAttributeCollection3_GetTypeInfoCount,
2466 HTMLAttributeCollection3_GetTypeInfo,
2467 HTMLAttributeCollection3_GetIDsOfNames,
2468 HTMLAttributeCollection3_Invoke,
2469 HTMLAttributeCollection3_getNamedItem,
2470 HTMLAttributeCollection3_setNamedItem,
2471 HTMLAttributeCollection3_removeNamedItem,
2472 HTMLAttributeCollection3_item,
2473 HTMLAttributeCollection3_get_length
2476 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2478 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2481 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2483 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2484 HTMLDOMAttribute *attr;
2485 LONG pos;
2486 HRESULT hres;
2488 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2490 hres = get_attr_dispid_by_name(This, name, dispid);
2491 if(FAILED(hres))
2492 return hres;
2494 hres = get_domattr(This, *dispid, &pos, &attr);
2495 if(FAILED(hres))
2496 return hres;
2497 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2499 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2500 return S_OK;
2503 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2504 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2506 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2508 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2510 switch(flags) {
2511 case DISPATCH_PROPERTYGET: {
2512 HTMLDOMAttribute *iter;
2514 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2516 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2517 if(!(--id))
2518 break;
2520 if(id)
2521 return E_INVALIDARG;
2523 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2524 V_VT(res) = VT_DISPATCH;
2525 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2526 return S_OK;
2529 default:
2530 FIXME("unimplemented flags %x\n", flags);
2531 return E_NOTIMPL;
2535 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2536 NULL,
2537 HTMLAttributeCollection_get_dispid,
2538 HTMLAttributeCollection_invoke,
2539 NULL
2542 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2543 IHTMLAttributeCollection_tid,
2544 IHTMLAttributeCollection2_tid,
2545 IHTMLAttributeCollection3_tid,
2549 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2550 &HTMLAttributeCollection_dispex_vtbl,
2551 DispHTMLAttributeCollection_tid,
2552 NULL,
2553 HTMLAttributeCollection_iface_tids
2556 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2558 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2560 if(This->attrs) {
2561 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2562 *ac = This->attrs;
2563 return S_OK;
2566 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2567 if(!This->attrs)
2568 return E_OUTOFMEMORY;
2570 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2571 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2572 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2573 This->attrs->ref = 2;
2575 This->attrs->elem = This;
2576 list_init(&This->attrs->attrs);
2577 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2578 &HTMLAttributeCollection_dispex);
2580 *ac = This->attrs;
2581 return S_OK;