opengl32: Remove redundant fields in the functions hashes.
[wine.git] / dlls / mshtml / htmlelem.c
blob82967d890d7b87d4dbbf7e1be3e3039d2add561d
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 = nsIDOMDocument_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 nsIDOMElementCSSInlineStyle *nselemstyle;
450 nsIDOMCSSStyleDeclaration *nsstyle;
451 nsresult nsres;
452 HRESULT hres;
454 if(!This->nselem) {
455 FIXME("NULL nselem\n");
456 return E_NOTIMPL;
459 nsres = nsIDOMHTMLElement_QueryInterface(This->nselem, &IID_nsIDOMElementCSSInlineStyle,
460 (void**)&nselemstyle);
461 if(NS_FAILED(nsres)) {
462 ERR("Could not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres);
463 return E_FAIL;
466 nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
467 nsIDOMElementCSSInlineStyle_Release(nselemstyle);
468 if(NS_FAILED(nsres)) {
469 ERR("GetStyle failed: %08x\n", nsres);
470 return E_FAIL;
473 hres = HTMLStyle_Create(This, nsstyle, &This->style);
474 nsIDOMCSSStyleDeclaration_Release(nsstyle);
475 if(FAILED(hres))
476 return hres;
479 *p = &This->style->IHTMLStyle_iface;
480 IHTMLStyle_AddRef(*p);
481 return S_OK;
484 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
486 HTMLElement *This = impl_from_IHTMLElement(iface);
487 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
488 return E_NOTIMPL;
491 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
493 HTMLElement *This = impl_from_IHTMLElement(iface);
494 FIXME("(%p)->(%p)\n", This, p);
495 return E_NOTIMPL;
498 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
500 HTMLElement *This = impl_from_IHTMLElement(iface);
502 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
504 return set_node_event(&This->node, EVENTID_CLICK, &v);
507 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
509 HTMLElement *This = impl_from_IHTMLElement(iface);
511 TRACE("(%p)->(%p)\n", This, p);
513 return get_node_event(&This->node, EVENTID_CLICK, p);
516 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
518 HTMLElement *This = impl_from_IHTMLElement(iface);
520 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
522 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
525 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
527 HTMLElement *This = impl_from_IHTMLElement(iface);
529 TRACE("(%p)->(%p)\n", This, p);
531 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
534 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
536 HTMLElement *This = impl_from_IHTMLElement(iface);
538 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
540 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
543 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
545 HTMLElement *This = impl_from_IHTMLElement(iface);
547 TRACE("(%p)->(%p)\n", This, p);
549 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
552 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
554 HTMLElement *This = impl_from_IHTMLElement(iface);
556 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
558 return set_node_event(&This->node, EVENTID_KEYUP, &v);
561 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
563 HTMLElement *This = impl_from_IHTMLElement(iface);
564 FIXME("(%p)->(%p)\n", This, p);
565 return E_NOTIMPL;
568 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
570 HTMLElement *This = impl_from_IHTMLElement(iface);
572 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
574 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
577 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
579 HTMLElement *This = impl_from_IHTMLElement(iface);
581 TRACE("(%p)->(%p)\n", This, p);
583 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
586 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
588 HTMLElement *This = impl_from_IHTMLElement(iface);
590 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
592 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
595 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
597 HTMLElement *This = impl_from_IHTMLElement(iface);
599 TRACE("(%p)->(%p)\n", This, p);
601 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
604 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
606 HTMLElement *This = impl_from_IHTMLElement(iface);
608 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
610 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
613 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
615 HTMLElement *This = impl_from_IHTMLElement(iface);
617 TRACE("(%p)->(%p)\n", This, p);
619 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
622 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
624 HTMLElement *This = impl_from_IHTMLElement(iface);
626 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
628 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
631 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
633 HTMLElement *This = impl_from_IHTMLElement(iface);
635 TRACE("(%p)->(%p)\n", This, p);
637 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
640 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
642 HTMLElement *This = impl_from_IHTMLElement(iface);
644 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
646 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
649 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
651 HTMLElement *This = impl_from_IHTMLElement(iface);
653 TRACE("(%p)->(%p)\n", This, p);
655 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
658 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
660 HTMLElement *This = impl_from_IHTMLElement(iface);
662 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
664 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
667 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
669 HTMLElement *This = impl_from_IHTMLElement(iface);
671 TRACE("(%p)->(%p)\n", This, p);
673 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
676 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
678 HTMLElement *This = impl_from_IHTMLElement(iface);
680 TRACE("(%p)->(%p)\n", This, p);
682 if(!p)
683 return E_POINTER;
685 if(This->node.vtbl->get_document)
686 return This->node.vtbl->get_document(&This->node, p);
688 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
689 IDispatch_AddRef(*p);
690 return S_OK;
693 static const WCHAR titleW[] = {'t','i','t','l','e',0};
695 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
697 HTMLElement *This = impl_from_IHTMLElement(iface);
698 nsAString title_str;
699 nsresult nsres;
701 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
703 if(!This->nselem) {
704 VARIANT *var;
705 HRESULT hres;
707 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
708 if(FAILED(hres))
709 return hres;
711 VariantClear(var);
712 V_VT(var) = VT_BSTR;
713 V_BSTR(var) = v ? SysAllocString(v) : NULL;
714 return S_OK;
717 nsAString_InitDepend(&title_str, v);
718 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
719 nsAString_Finish(&title_str);
720 if(NS_FAILED(nsres))
721 ERR("SetTitle failed: %08x\n", nsres);
723 return S_OK;
726 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
728 HTMLElement *This = impl_from_IHTMLElement(iface);
729 nsAString title_str;
730 nsresult nsres;
732 TRACE("(%p)->(%p)\n", This, p);
734 if(!This->nselem) {
735 VARIANT *var;
736 HRESULT hres;
738 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
739 if(hres == DISP_E_UNKNOWNNAME) {
740 *p = NULL;
741 }else if(V_VT(var) != VT_BSTR) {
742 FIXME("title = %s\n", debugstr_variant(var));
743 return E_FAIL;
744 }else {
745 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
748 return S_OK;
751 nsAString_Init(&title_str, NULL);
752 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
753 return return_nsstr(nsres, &title_str, p);
756 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
758 HTMLElement *This = impl_from_IHTMLElement(iface);
759 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
760 return E_NOTIMPL;
763 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
765 HTMLElement *This = impl_from_IHTMLElement(iface);
766 FIXME("(%p)->(%p)\n", This, p);
767 return E_NOTIMPL;
770 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
772 HTMLElement *This = impl_from_IHTMLElement(iface);
774 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
776 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
779 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
781 HTMLElement *This = impl_from_IHTMLElement(iface);
783 TRACE("(%p)->(%p)\n", This, p);
785 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
788 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
790 HTMLElement *This = impl_from_IHTMLElement(iface);
791 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
792 return E_NOTIMPL;
795 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
796 VARIANT_BOOL *pfResult)
798 HTMLElement *This = impl_from_IHTMLElement(iface);
799 FIXME("(%p)->(%p %p)\n", This, pChild, pfResult);
800 return E_NOTIMPL;
803 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
805 HTMLElement *This = impl_from_IHTMLElement(iface);
806 FIXME("(%p)->(%p)\n", This, p);
807 return E_NOTIMPL;
810 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
812 HTMLElement *This = impl_from_IHTMLElement(iface);
813 FIXME("(%p)->(%p)\n", This, p);
814 return E_NOTIMPL;
817 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
819 HTMLElement *This = impl_from_IHTMLElement(iface);
820 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
821 return E_NOTIMPL;
824 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
826 HTMLElement *This = impl_from_IHTMLElement(iface);
827 FIXME("(%p)->(%p)\n", This, p);
828 return E_NOTIMPL;
831 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
833 HTMLElement *This = impl_from_IHTMLElement(iface);
834 PRInt32 off_left = 0;
835 nsresult nsres;
837 TRACE("(%p)->(%p)\n", This, p);
839 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, &off_left);
840 if(NS_FAILED(nsres)) {
841 ERR("GetOffsetLeft failed: %08x\n", nsres);
842 return E_FAIL;
845 *p = off_left;
846 return S_OK;
849 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
851 HTMLElement *This = impl_from_IHTMLElement(iface);
852 PRInt32 top = 0;
853 nsresult nsres;
855 TRACE("(%p)->(%p)\n", This, p);
857 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, &top);
858 if(NS_FAILED(nsres)) {
859 ERR("GetOffsetTop failed: %08x\n", nsres);
860 return E_FAIL;
863 *p = top;
864 return S_OK;
867 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
869 HTMLElement *This = impl_from_IHTMLElement(iface);
870 PRInt32 offset = 0;
871 nsresult nsres;
873 TRACE("(%p)->(%p)\n", This, p);
875 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, &offset);
876 if(NS_FAILED(nsres)) {
877 ERR("GetOffsetWidth failed: %08x\n", nsres);
878 return E_FAIL;
881 *p = offset;
882 return S_OK;
885 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
887 HTMLElement *This = impl_from_IHTMLElement(iface);
888 PRInt32 offset = 0;
889 nsresult nsres;
891 TRACE("(%p)->(%p)\n", This, p);
893 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, &offset);
894 if(NS_FAILED(nsres)) {
895 ERR("GetOffsetHeight failed: %08x\n", nsres);
896 return E_FAIL;
899 *p = offset;
900 return S_OK;
903 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
905 HTMLElement *This = impl_from_IHTMLElement(iface);
906 nsIDOMElement *nsparent;
907 nsresult nsres;
908 HRESULT hres;
910 TRACE("(%p)->(%p)\n", This, p);
912 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
913 if(NS_FAILED(nsres)) {
914 ERR("GetOffsetParent failed: %08x\n", nsres);
915 return E_FAIL;
918 if(nsparent) {
919 HTMLDOMNode *node;
921 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
922 nsIDOMElement_Release(nsparent);
923 if(FAILED(hres))
924 return hres;
926 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
927 node_release(node);
928 }else {
929 *p = NULL;
930 hres = S_OK;
933 return hres;
936 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
938 HTMLElement *This = impl_from_IHTMLElement(iface);
939 nsAString html_str;
940 nsresult nsres;
942 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
944 if(!This->nselem) {
945 FIXME("NULL nselem\n");
946 return E_NOTIMPL;
949 nsAString_InitDepend(&html_str, v);
950 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
951 nsAString_Finish(&html_str);
952 if(NS_FAILED(nsres)) {
953 FIXME("SetInnerHtml failed %08x\n", nsres);
954 return E_FAIL;
957 return S_OK;
960 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
962 HTMLElement *This = impl_from_IHTMLElement(iface);
963 nsAString html_str;
964 nsresult nsres;
966 TRACE("(%p)->(%p)\n", This, p);
968 if(!This->nselem) {
969 FIXME("NULL nselem\n");
970 return E_NOTIMPL;
973 nsAString_Init(&html_str, NULL);
974 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
975 return return_nsstr(nsres, &html_str, p);
978 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
980 HTMLElement *This = impl_from_IHTMLElement(iface);
981 nsIDOMNode *nschild, *tmp;
982 nsIDOMText *text_node;
983 nsAString text_str;
984 nsresult nsres;
986 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
988 while(1) {
989 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
990 if(NS_FAILED(nsres)) {
991 ERR("GetLastChild failed: %08x\n", nsres);
992 return E_FAIL;
994 if(!nschild)
995 break;
997 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
998 nsIDOMNode_Release(nschild);
999 if(NS_FAILED(nsres)) {
1000 ERR("RemoveChild failed: %08x\n", nsres);
1001 return E_FAIL;
1003 nsIDOMNode_Release(tmp);
1006 nsAString_InitDepend(&text_str, v);
1007 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1008 nsAString_Finish(&text_str);
1009 if(NS_FAILED(nsres)) {
1010 ERR("CreateTextNode failed: %08x\n", nsres);
1011 return E_FAIL;
1014 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1015 if(NS_FAILED(nsres)) {
1016 ERR("AppendChild failed: %08x\n", nsres);
1017 return E_FAIL;
1020 nsIDOMNode_Release(tmp);
1021 return S_OK;
1024 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1026 HTMLElement *This = impl_from_IHTMLElement(iface);
1028 TRACE("(%p)->(%p)\n", This, p);
1030 return get_node_text(&This->node, p);
1033 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1035 HTMLElement *This = impl_from_IHTMLElement(iface);
1037 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1039 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1042 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1044 HTMLElement *This = impl_from_IHTMLElement(iface);
1045 nsAString html_str;
1046 HRESULT hres;
1048 WARN("(%p)->(%p) semi-stub\n", This, p);
1050 nsAString_Init(&html_str, NULL);
1051 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1052 if(SUCCEEDED(hres)) {
1053 const PRUnichar *html;
1055 nsAString_GetData(&html_str, &html);
1056 *p = SysAllocString(html);
1057 if(!*p)
1058 hres = E_OUTOFMEMORY;
1061 nsAString_Finish(&html_str);
1063 TRACE("ret %s\n", debugstr_w(*p));
1064 return hres;
1067 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1069 HTMLElement *This = impl_from_IHTMLElement(iface);
1070 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1071 return E_NOTIMPL;
1074 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1076 HTMLElement *This = impl_from_IHTMLElement(iface);
1077 FIXME("(%p)->(%p)\n", This, p);
1078 return E_NOTIMPL;
1081 static HRESULT HTMLElement_InsertAdjacentNode(HTMLElement *This, BSTR where, nsIDOMNode *nsnode)
1083 static const WCHAR wszBeforeBegin[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
1084 static const WCHAR wszAfterBegin[] = {'a','f','t','e','r','B','e','g','i','n',0};
1085 static const WCHAR wszBeforeEnd[] = {'b','e','f','o','r','e','E','n','d',0};
1086 static const WCHAR wszAfterEnd[] = {'a','f','t','e','r','E','n','d',0};
1087 nsresult nsres;
1089 if (!strcmpiW(where, wszBeforeBegin))
1091 nsIDOMNode *unused;
1092 nsIDOMNode *parent;
1093 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1094 if (!parent) return E_INVALIDARG;
1095 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &unused);
1096 if (unused) nsIDOMNode_Release(unused);
1097 nsIDOMNode_Release(parent);
1099 else if (!strcmpiW(where, wszAfterBegin))
1101 nsIDOMNode *unused;
1102 nsIDOMNode *first_child;
1103 nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1104 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &unused);
1105 if (unused) nsIDOMNode_Release(unused);
1106 if (first_child) nsIDOMNode_Release(first_child);
1108 else if (!strcmpiW(where, wszBeforeEnd))
1110 nsIDOMNode *unused;
1111 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &unused);
1112 if (unused) nsIDOMNode_Release(unused);
1114 else if (!strcmpiW(where, wszAfterEnd))
1116 nsIDOMNode *unused;
1117 nsIDOMNode *next_sibling;
1118 nsIDOMNode *parent;
1119 nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1120 if (!parent) return E_INVALIDARG;
1122 nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1123 if (next_sibling)
1125 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &unused);
1126 nsIDOMNode_Release(next_sibling);
1128 else
1129 nsres = nsIDOMNode_AppendChild(parent, nsnode, &unused);
1130 nsIDOMNode_Release(parent);
1131 if (unused) nsIDOMNode_Release(unused);
1133 else
1135 ERR("invalid where: %s\n", debugstr_w(where));
1136 return E_INVALIDARG;
1139 if (NS_FAILED(nsres))
1140 return E_FAIL;
1141 else
1142 return S_OK;
1145 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1146 BSTR html)
1148 HTMLElement *This = impl_from_IHTMLElement(iface);
1149 nsIDOMRange *range;
1150 nsIDOMNode *nsnode;
1151 nsAString ns_html;
1152 nsresult nsres;
1153 HRESULT hr;
1155 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1157 if(!This->node.doc->nsdoc) {
1158 WARN("NULL nsdoc\n");
1159 return E_UNEXPECTED;
1162 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1163 if(NS_FAILED(nsres))
1165 ERR("CreateRange failed: %08x\n", nsres);
1166 return E_FAIL;
1169 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1171 nsAString_InitDepend(&ns_html, html);
1172 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1173 nsAString_Finish(&ns_html);
1174 nsIDOMRange_Release(range);
1176 if(NS_FAILED(nsres) || !nsnode)
1178 ERR("CreateTextNode failed: %08x\n", nsres);
1179 return E_FAIL;
1182 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1183 nsIDOMNode_Release(nsnode);
1185 return hr;
1188 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1189 BSTR text)
1191 HTMLElement *This = impl_from_IHTMLElement(iface);
1192 nsIDOMNode *nsnode;
1193 nsAString ns_text;
1194 nsresult nsres;
1195 HRESULT hr;
1197 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1199 if(!This->node.doc->nsdoc) {
1200 WARN("NULL nsdoc\n");
1201 return E_UNEXPECTED;
1205 nsAString_InitDepend(&ns_text, text);
1206 nsres = nsIDOMDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1207 nsAString_Finish(&ns_text);
1209 if(NS_FAILED(nsres) || !nsnode)
1211 ERR("CreateTextNode failed: %08x\n", nsres);
1212 return E_FAIL;
1215 hr = HTMLElement_InsertAdjacentNode(This, where, nsnode);
1216 nsIDOMNode_Release(nsnode);
1218 return hr;
1221 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1223 HTMLElement *This = impl_from_IHTMLElement(iface);
1224 FIXME("(%p)->(%p)\n", This, p);
1225 return E_NOTIMPL;
1228 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1230 HTMLElement *This = impl_from_IHTMLElement(iface);
1231 FIXME("(%p)->(%p)\n", This, p);
1232 return E_NOTIMPL;
1235 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1237 HTMLElement *This = impl_from_IHTMLElement(iface);
1239 TRACE("(%p)\n", This);
1241 return call_fire_event(&This->node, EVENTID_CLICK);
1244 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1245 IHTMLFiltersCollection **p)
1247 HTMLElement *This = impl_from_IHTMLElement(iface);
1248 TRACE("(%p)->(%p)\n", This, p);
1250 if(!p)
1251 return E_POINTER;
1253 *p = HTMLFiltersCollection_Create();
1255 return S_OK;
1258 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1260 HTMLElement *This = impl_from_IHTMLElement(iface);
1261 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1262 return E_NOTIMPL;
1265 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1267 HTMLElement *This = impl_from_IHTMLElement(iface);
1268 FIXME("(%p)->(%p)\n", This, p);
1269 return E_NOTIMPL;
1272 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1274 HTMLElement *This = impl_from_IHTMLElement(iface);
1275 FIXME("(%p)->(%p)\n", This, String);
1276 return E_NOTIMPL;
1279 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1281 HTMLElement *This = impl_from_IHTMLElement(iface);
1282 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1283 return E_NOTIMPL;
1286 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1288 HTMLElement *This = impl_from_IHTMLElement(iface);
1289 FIXME("(%p)->(%p)\n", This, p);
1290 return E_NOTIMPL;
1293 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1295 HTMLElement *This = impl_from_IHTMLElement(iface);
1296 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1297 return E_NOTIMPL;
1300 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1302 HTMLElement *This = impl_from_IHTMLElement(iface);
1303 FIXME("(%p)->(%p)\n", This, p);
1304 return E_NOTIMPL;
1307 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1309 HTMLElement *This = impl_from_IHTMLElement(iface);
1310 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1311 return E_NOTIMPL;
1314 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1316 HTMLElement *This = impl_from_IHTMLElement(iface);
1317 FIXME("(%p)->(%p)\n", This, p);
1318 return E_NOTIMPL;
1321 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1323 HTMLElement *This = impl_from_IHTMLElement(iface);
1324 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1325 return E_NOTIMPL;
1328 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1330 HTMLElement *This = impl_from_IHTMLElement(iface);
1331 FIXME("(%p)->(%p)\n", This, p);
1332 return E_NOTIMPL;
1335 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1337 HTMLElement *This = impl_from_IHTMLElement(iface);
1338 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1339 return E_NOTIMPL;
1342 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1344 HTMLElement *This = impl_from_IHTMLElement(iface);
1345 FIXME("(%p)->(%p)\n", This, p);
1346 return E_NOTIMPL;
1349 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1351 HTMLElement *This = impl_from_IHTMLElement(iface);
1352 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1353 return E_NOTIMPL;
1356 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1358 HTMLElement *This = impl_from_IHTMLElement(iface);
1359 FIXME("(%p)->(%p)\n", This, p);
1360 return E_NOTIMPL;
1363 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1365 HTMLElement *This = impl_from_IHTMLElement(iface);
1366 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1367 return E_NOTIMPL;
1370 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1372 HTMLElement *This = impl_from_IHTMLElement(iface);
1373 FIXME("(%p)->(%p)\n", This, p);
1374 return E_NOTIMPL;
1377 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1379 HTMLElement *This = impl_from_IHTMLElement(iface);
1380 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1381 return E_NOTIMPL;
1384 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1386 HTMLElement *This = impl_from_IHTMLElement(iface);
1387 FIXME("(%p)->(%p)\n", This, p);
1388 return E_NOTIMPL;
1391 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1393 HTMLElement *This = impl_from_IHTMLElement(iface);
1394 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1395 return E_NOTIMPL;
1398 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1400 HTMLElement *This = impl_from_IHTMLElement(iface);
1401 FIXME("(%p)->(%p)\n", This, p);
1402 return E_NOTIMPL;
1405 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1407 HTMLElement *This = impl_from_IHTMLElement(iface);
1408 nsIDOMNodeList *nsnode_list;
1409 nsresult nsres;
1411 TRACE("(%p)->(%p)\n", This, p);
1413 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1414 if(NS_FAILED(nsres)) {
1415 ERR("GetChildNodes failed: %08x\n", nsres);
1416 return E_FAIL;
1419 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1421 nsIDOMNodeList_Release(nsnode_list);
1422 return S_OK;
1425 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1427 HTMLElement *This = impl_from_IHTMLElement(iface);
1429 TRACE("(%p)->(%p)\n", This, p);
1431 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1432 return S_OK;
1435 static const IHTMLElementVtbl HTMLElementVtbl = {
1436 HTMLElement_QueryInterface,
1437 HTMLElement_AddRef,
1438 HTMLElement_Release,
1439 HTMLElement_GetTypeInfoCount,
1440 HTMLElement_GetTypeInfo,
1441 HTMLElement_GetIDsOfNames,
1442 HTMLElement_Invoke,
1443 HTMLElement_setAttribute,
1444 HTMLElement_getAttribute,
1445 HTMLElement_removeAttribute,
1446 HTMLElement_put_className,
1447 HTMLElement_get_className,
1448 HTMLElement_put_id,
1449 HTMLElement_get_id,
1450 HTMLElement_get_tagName,
1451 HTMLElement_get_parentElement,
1452 HTMLElement_get_style,
1453 HTMLElement_put_onhelp,
1454 HTMLElement_get_onhelp,
1455 HTMLElement_put_onclick,
1456 HTMLElement_get_onclick,
1457 HTMLElement_put_ondblclick,
1458 HTMLElement_get_ondblclick,
1459 HTMLElement_put_onkeydown,
1460 HTMLElement_get_onkeydown,
1461 HTMLElement_put_onkeyup,
1462 HTMLElement_get_onkeyup,
1463 HTMLElement_put_onkeypress,
1464 HTMLElement_get_onkeypress,
1465 HTMLElement_put_onmouseout,
1466 HTMLElement_get_onmouseout,
1467 HTMLElement_put_onmouseover,
1468 HTMLElement_get_onmouseover,
1469 HTMLElement_put_onmousemove,
1470 HTMLElement_get_onmousemove,
1471 HTMLElement_put_onmousedown,
1472 HTMLElement_get_onmousedown,
1473 HTMLElement_put_onmouseup,
1474 HTMLElement_get_onmouseup,
1475 HTMLElement_get_document,
1476 HTMLElement_put_title,
1477 HTMLElement_get_title,
1478 HTMLElement_put_language,
1479 HTMLElement_get_language,
1480 HTMLElement_put_onselectstart,
1481 HTMLElement_get_onselectstart,
1482 HTMLElement_scrollIntoView,
1483 HTMLElement_contains,
1484 HTMLElement_get_sourceIndex,
1485 HTMLElement_get_recordNumber,
1486 HTMLElement_put_lang,
1487 HTMLElement_get_lang,
1488 HTMLElement_get_offsetLeft,
1489 HTMLElement_get_offsetTop,
1490 HTMLElement_get_offsetWidth,
1491 HTMLElement_get_offsetHeight,
1492 HTMLElement_get_offsetParent,
1493 HTMLElement_put_innerHTML,
1494 HTMLElement_get_innerHTML,
1495 HTMLElement_put_innerText,
1496 HTMLElement_get_innerText,
1497 HTMLElement_put_outerHTML,
1498 HTMLElement_get_outerHTML,
1499 HTMLElement_put_outerText,
1500 HTMLElement_get_outerText,
1501 HTMLElement_insertAdjacentHTML,
1502 HTMLElement_insertAdjacentText,
1503 HTMLElement_get_parentTextEdit,
1504 HTMLElement_get_isTextEdit,
1505 HTMLElement_click,
1506 HTMLElement_get_filters,
1507 HTMLElement_put_ondragstart,
1508 HTMLElement_get_ondragstart,
1509 HTMLElement_toString,
1510 HTMLElement_put_onbeforeupdate,
1511 HTMLElement_get_onbeforeupdate,
1512 HTMLElement_put_onafterupdate,
1513 HTMLElement_get_onafterupdate,
1514 HTMLElement_put_onerrorupdate,
1515 HTMLElement_get_onerrorupdate,
1516 HTMLElement_put_onrowexit,
1517 HTMLElement_get_onrowexit,
1518 HTMLElement_put_onrowenter,
1519 HTMLElement_get_onrowenter,
1520 HTMLElement_put_ondatasetchanged,
1521 HTMLElement_get_ondatasetchanged,
1522 HTMLElement_put_ondataavailable,
1523 HTMLElement_get_ondataavailable,
1524 HTMLElement_put_ondatasetcomplete,
1525 HTMLElement_get_ondatasetcomplete,
1526 HTMLElement_put_onfilterchange,
1527 HTMLElement_get_onfilterchange,
1528 HTMLElement_get_children,
1529 HTMLElement_get_all
1532 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1534 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1537 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1539 return CONTAINING_RECORD(iface, HTMLElement, node);
1542 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1544 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1546 *ppv = NULL;
1548 if(IsEqualGUID(&IID_IUnknown, riid)) {
1549 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1550 *ppv = &This->IHTMLElement_iface;
1551 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1552 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1553 *ppv = &This->IHTMLElement_iface;
1554 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1555 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1556 *ppv = &This->IHTMLElement_iface;
1557 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1558 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1559 *ppv = &This->IHTMLElement2_iface;
1560 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1561 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1562 *ppv = &This->IHTMLElement3_iface;
1563 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1564 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1565 *ppv = &This->IHTMLElement4_iface;
1566 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1567 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1568 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1571 if(*ppv) {
1572 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1573 return S_OK;
1576 return HTMLDOMNode_QI(&This->node, riid, ppv);
1579 void HTMLElement_destructor(HTMLDOMNode *iface)
1581 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1583 ConnectionPointContainer_Destroy(&This->cp_container);
1585 if(This->style) {
1586 This->style->elem = NULL;
1587 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1589 if(This->attrs) {
1590 HTMLDOMAttribute *attr;
1592 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1593 attr->elem = NULL;
1595 This->attrs->elem = NULL;
1596 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1599 heap_free(This->filter);
1601 HTMLDOMNode_destructor(&This->node);
1604 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1606 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1607 HTMLElement *new_elem;
1608 HRESULT hres;
1610 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1611 if(FAILED(hres))
1612 return hres;
1614 if(This->filter) {
1615 new_elem->filter = heap_strdupW(This->filter);
1616 if(!new_elem->filter) {
1617 IHTMLElement_Release(&This->IHTMLElement_iface);
1618 return E_OUTOFMEMORY;
1622 *ret = &new_elem->node;
1623 return S_OK;
1626 static const NodeImplVtbl HTMLElementImplVtbl = {
1627 HTMLElement_QI,
1628 HTMLElement_destructor,
1629 HTMLElement_clone,
1630 HTMLElement_get_attr_col
1633 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1635 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1638 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1639 DWORD grfdex, DISPID *pid)
1641 HTMLElement *This = impl_from_DispatchEx(dispex);
1643 if(This->node.vtbl->get_dispid)
1644 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1646 return DISP_E_UNKNOWNNAME;
1649 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1650 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1651 IServiceProvider *caller)
1653 HTMLElement *This = impl_from_DispatchEx(dispex);
1655 if(This->node.vtbl->invoke)
1656 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1657 params, res, ei, caller);
1659 ERR("(%p): element has no invoke method\n", This);
1660 return E_NOTIMPL;
1663 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1665 HTMLElement *This = impl_from_DispatchEx(dispex);
1666 nsIDOMNamedNodeMap *attrs;
1667 nsIDOMNode *node;
1668 nsAString nsstr;
1669 const PRUnichar *str;
1670 BSTR name;
1671 VARIANT value;
1672 unsigned i;
1673 PRUint32 len;
1674 DISPID id;
1675 nsresult nsres;
1676 HRESULT hres;
1678 if(!This->nselem)
1679 return S_FALSE;
1681 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1682 if(NS_FAILED(nsres))
1683 return E_FAIL;
1685 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1686 if(NS_FAILED(nsres)) {
1687 nsIDOMNamedNodeMap_Release(attrs);
1688 return E_FAIL;
1691 nsAString_Init(&nsstr, NULL);
1692 for(i=0; i<len; i++) {
1693 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1694 if(NS_FAILED(nsres))
1695 continue;
1697 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1698 if(NS_FAILED(nsres)) {
1699 nsIDOMNode_Release(node);
1700 continue;
1703 nsAString_GetData(&nsstr, &str);
1704 name = SysAllocString(str);
1705 if(!name) {
1706 nsIDOMNode_Release(node);
1707 continue;
1710 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1711 if(hres != DISP_E_UNKNOWNNAME) {
1712 nsIDOMNode_Release(node);
1713 SysFreeString(name);
1714 continue;
1717 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1718 nsIDOMNode_Release(node);
1719 if(NS_FAILED(nsres)) {
1720 SysFreeString(name);
1721 continue;
1724 nsAString_GetData(&nsstr, &str);
1725 V_VT(&value) = VT_BSTR;
1726 if(*str) {
1727 V_BSTR(&value) = SysAllocString(str);
1728 if(!V_BSTR(&value)) {
1729 SysFreeString(name);
1730 continue;
1732 } else
1733 V_BSTR(&value) = NULL;
1735 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1736 SysFreeString(name);
1737 VariantClear(&value);
1739 nsAString_Finish(&nsstr);
1741 nsIDOMNamedNodeMap_Release(attrs);
1742 return S_OK;
1745 static const tid_t HTMLElement_iface_tids[] = {
1746 HTMLELEMENT_TIDS,
1750 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1751 NULL,
1752 HTMLElement_get_dispid,
1753 HTMLElement_invoke,
1754 HTMLElement_populate_props
1757 static dispex_static_data_t HTMLElement_dispex = {
1758 &HTMLElement_dispex_vtbl,
1759 DispHTMLUnknownElement_tid,
1760 NULL,
1761 HTMLElement_iface_tids
1764 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1766 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1768 HTMLElement2_Init(This);
1769 HTMLElement3_Init(This);
1771 if(dispex_data && !dispex_data->vtbl)
1772 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1773 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1774 dispex_data ? dispex_data : &HTMLElement_dispex);
1776 if(nselem) {
1777 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1779 /* No AddRef, share reference with HTMLDOMNode */
1780 assert((nsIDOMNode*)nselem == This->node.nsnode);
1781 This->nselem = nselem;
1784 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1787 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1789 nsIDOMHTMLElement *nselem;
1790 nsAString class_name_str;
1791 const PRUnichar *class_name;
1792 const tag_desc_t *tag;
1793 HTMLElement *elem;
1794 nsresult nsres;
1795 HRESULT hres;
1797 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1798 if(NS_FAILED(nsres))
1799 return E_FAIL;
1801 nsAString_Init(&class_name_str, NULL);
1802 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1804 nsAString_GetData(&class_name_str, &class_name);
1806 tag = get_tag_desc(class_name);
1807 if(tag) {
1808 hres = tag->constructor(doc, nselem, &elem);
1809 }else if(use_generic) {
1810 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1811 }else {
1812 elem = heap_alloc_zero(sizeof(HTMLElement));
1813 if(elem) {
1814 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1815 elem->node.vtbl = &HTMLElementImplVtbl;
1816 hres = S_OK;
1817 }else {
1818 hres = E_OUTOFMEMORY;
1822 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1824 nsIDOMElement_Release(nselem);
1825 nsAString_Finish(&class_name_str);
1826 if(FAILED(hres))
1827 return hres;
1829 *ret = elem;
1830 return S_OK;
1833 /* interface IHTMLFiltersCollection */
1834 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1836 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1838 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1840 if(IsEqualGUID(&IID_IUnknown, riid)) {
1841 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1842 *ppv = &This->IHTMLFiltersCollection_iface;
1843 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1844 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1845 *ppv = &This->IHTMLFiltersCollection_iface;
1846 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1847 return *ppv ? S_OK : E_NOINTERFACE;
1850 if(*ppv) {
1851 IUnknown_AddRef((IUnknown*)*ppv);
1852 return S_OK;
1855 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1856 return E_NOINTERFACE;
1859 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1861 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1862 LONG ref = InterlockedIncrement(&This->ref);
1864 TRACE("(%p) ref=%d\n", This, ref);
1866 return ref;
1869 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1871 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1872 LONG ref = InterlockedDecrement(&This->ref);
1874 TRACE("(%p) ref=%d\n", This, ref);
1876 if(!ref)
1878 heap_free(This);
1881 return ref;
1884 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1886 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1887 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1890 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1891 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1893 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1894 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1897 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1898 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1899 LCID lcid, DISPID *rgDispId)
1901 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1902 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1903 lcid, rgDispId);
1906 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1907 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1908 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1910 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1911 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1912 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1915 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1917 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1919 if(!p)
1920 return E_POINTER;
1922 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1923 *p = 0;
1925 return S_OK;
1928 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1930 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1931 FIXME("(%p)->(%p)\n", This, p);
1932 return E_NOTIMPL;
1935 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1937 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1938 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
1939 return E_NOTIMPL;
1942 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
1943 HTMLFiltersCollection_QueryInterface,
1944 HTMLFiltersCollection_AddRef,
1945 HTMLFiltersCollection_Release,
1946 HTMLFiltersCollection_GetTypeInfoCount,
1947 HTMLFiltersCollection_GetTypeInfo,
1948 HTMLFiltersCollection_GetIDsOfNames,
1949 HTMLFiltersCollection_Invoke,
1950 HTMLFiltersCollection_get_length,
1951 HTMLFiltersCollection_get__newEnum,
1952 HTMLFiltersCollection_item
1955 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
1957 WCHAR *ptr;
1958 int idx = 0;
1960 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
1961 idx = idx*10 + (*ptr-'0');
1962 if(*ptr)
1963 return DISP_E_UNKNOWNNAME;
1965 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
1966 TRACE("ret %x\n", *dispid);
1967 return S_OK;
1970 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
1971 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
1973 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
1975 V_VT(res) = VT_DISPATCH;
1976 V_DISPATCH(res) = NULL;
1978 FIXME("always returning NULL\n");
1980 return S_OK;
1983 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
1984 NULL,
1985 HTMLFiltersCollection_get_dispid,
1986 HTMLFiltersCollection_invoke,
1987 NULL
1990 static const tid_t HTMLFiltersCollection_iface_tids[] = {
1991 IHTMLFiltersCollection_tid,
1994 static dispex_static_data_t HTMLFiltersCollection_dispex = {
1995 &HTMLFiltersCollection_dispex_vtbl,
1996 IHTMLFiltersCollection_tid,
1997 NULL,
1998 HTMLFiltersCollection_iface_tids
2001 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2003 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2005 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2006 ret->ref = 1;
2008 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2009 &HTMLFiltersCollection_dispex);
2011 return &ret->IHTMLFiltersCollection_iface;
2014 /* interface IHTMLAttributeCollection */
2015 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2017 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2020 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2022 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2024 *ppv = NULL;
2026 if(IsEqualGUID(&IID_IUnknown, riid)) {
2027 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2028 *ppv = &This->IHTMLAttributeCollection_iface;
2029 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2030 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2031 *ppv = &This->IHTMLAttributeCollection_iface;
2032 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2033 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2034 *ppv = &This->IHTMLAttributeCollection2_iface;
2035 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2036 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2037 *ppv = &This->IHTMLAttributeCollection3_iface;
2038 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2039 return *ppv ? S_OK : E_NOINTERFACE;
2042 if(*ppv) {
2043 IUnknown_AddRef((IUnknown*)*ppv);
2044 return S_OK;
2047 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2048 return E_NOINTERFACE;
2051 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2053 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2054 LONG ref = InterlockedIncrement(&This->ref);
2056 TRACE("(%p) ref=%d\n", This, ref);
2058 return ref;
2061 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2063 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2064 LONG ref = InterlockedDecrement(&This->ref);
2066 TRACE("(%p) ref=%d\n", This, ref);
2068 if(!ref) {
2069 while(!list_empty(&This->attrs)) {
2070 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2072 list_remove(&attr->entry);
2073 attr->elem = NULL;
2074 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2077 heap_free(This);
2080 return ref;
2083 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2085 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2086 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2089 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2090 LCID lcid, ITypeInfo **ppTInfo)
2092 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2093 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2096 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2097 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2099 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2100 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2101 lcid, rgDispId);
2104 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2105 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2106 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2108 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2109 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2110 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2113 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2115 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2116 DISPID id = DISPID_STARTENUM;
2117 LONG len = -1;
2118 HRESULT hres;
2120 FIXME("filter non-enumerable attributes out\n");
2122 while(1) {
2123 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2124 if(FAILED(hres))
2125 return hres;
2126 else if(hres == S_FALSE)
2127 break;
2129 len++;
2130 if(len == *idx)
2131 break;
2134 if(dispid) {
2135 *dispid = id;
2136 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2139 *idx = len+1;
2140 return S_OK;
2143 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2145 HRESULT hres;
2147 if(name[0]>='0' && name[0]<='9') {
2148 WCHAR *end_ptr;
2149 LONG idx;
2151 idx = strtoulW(name, &end_ptr, 10);
2152 if(!*end_ptr) {
2153 hres = get_attr_dispid_by_idx(This, &idx, id);
2154 if(SUCCEEDED(hres))
2155 return hres;
2159 if(!This->elem) {
2160 WARN("NULL elem\n");
2161 return E_UNEXPECTED;
2164 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2165 name, fdexNameCaseInsensitive, id);
2166 return hres;
2169 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2171 HTMLDOMAttribute *iter;
2172 LONG pos = 0;
2173 HRESULT hres;
2175 *attr = NULL;
2176 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2177 if(iter->dispid == id) {
2178 *attr = iter;
2179 break;
2181 pos++;
2184 if(!*attr) {
2185 if(!This->elem) {
2186 WARN("NULL elem\n");
2187 return E_UNEXPECTED;
2190 pos++;
2191 hres = HTMLDOMAttribute_Create(This->elem, id, attr);
2192 if(FAILED(hres))
2193 return hres;
2196 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2197 if(list_pos)
2198 *list_pos = pos;
2199 return S_OK;
2202 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2204 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2205 HRESULT hres;
2207 TRACE("(%p)->(%p)\n", This, p);
2209 *p = -1;
2210 hres = get_attr_dispid_by_idx(This, p, NULL);
2211 return hres;
2214 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2216 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2217 FIXME("(%p)->(%p)\n", This, p);
2218 return E_NOTIMPL;
2221 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2223 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2224 HTMLDOMAttribute *attr;
2225 DISPID id;
2226 HRESULT hres;
2228 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2230 switch(V_VT(name)) {
2231 case VT_I4:
2232 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2233 break;
2234 case VT_BSTR:
2235 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2236 break;
2237 default:
2238 FIXME("unsupported name %s\n", debugstr_variant(name));
2239 hres = E_NOTIMPL;
2241 if(hres == DISP_E_UNKNOWNNAME)
2242 return E_INVALIDARG;
2243 if(FAILED(hres))
2244 return hres;
2246 hres = get_domattr(This, id, NULL, &attr);
2247 if(FAILED(hres))
2248 return hres;
2250 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2251 return S_OK;
2254 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2255 HTMLAttributeCollection_QueryInterface,
2256 HTMLAttributeCollection_AddRef,
2257 HTMLAttributeCollection_Release,
2258 HTMLAttributeCollection_GetTypeInfoCount,
2259 HTMLAttributeCollection_GetTypeInfo,
2260 HTMLAttributeCollection_GetIDsOfNames,
2261 HTMLAttributeCollection_Invoke,
2262 HTMLAttributeCollection_get_length,
2263 HTMLAttributeCollection__newEnum,
2264 HTMLAttributeCollection_item
2267 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2269 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2272 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2274 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2275 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2278 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2280 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2281 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2284 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2286 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2287 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2290 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2292 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2293 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2296 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2297 LCID lcid, ITypeInfo **ppTInfo)
2299 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2300 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2303 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2304 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2306 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2307 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2308 lcid, rgDispId);
2311 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2312 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2313 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2315 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2316 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2317 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2320 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2321 IHTMLDOMAttribute **newretNode)
2323 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2324 HTMLDOMAttribute *attr;
2325 DISPID id;
2326 HRESULT hres;
2328 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2330 hres = get_attr_dispid_by_name(This, bstrName, &id);
2331 if(hres == DISP_E_UNKNOWNNAME) {
2332 *newretNode = NULL;
2333 return S_OK;
2334 } else if(FAILED(hres)) {
2335 return hres;
2338 hres = get_domattr(This, id, NULL, &attr);
2339 if(FAILED(hres))
2340 return hres;
2342 *newretNode = &attr->IHTMLDOMAttribute_iface;
2343 return S_OK;
2346 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2347 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2349 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2350 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2351 return E_NOTIMPL;
2354 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2355 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2357 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2358 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2359 return E_NOTIMPL;
2362 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2363 HTMLAttributeCollection2_QueryInterface,
2364 HTMLAttributeCollection2_AddRef,
2365 HTMLAttributeCollection2_Release,
2366 HTMLAttributeCollection2_GetTypeInfoCount,
2367 HTMLAttributeCollection2_GetTypeInfo,
2368 HTMLAttributeCollection2_GetIDsOfNames,
2369 HTMLAttributeCollection2_Invoke,
2370 HTMLAttributeCollection2_getNamedItem,
2371 HTMLAttributeCollection2_setNamedItem,
2372 HTMLAttributeCollection2_removeNamedItem
2375 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2377 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2380 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2382 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2383 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2386 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2388 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2389 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2392 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2394 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2395 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2398 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2400 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2401 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2404 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2405 LCID lcid, ITypeInfo **ppTInfo)
2407 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2408 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2411 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2412 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2414 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2415 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2416 lcid, rgDispId);
2419 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2420 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2421 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2423 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2424 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2425 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2428 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2429 IHTMLDOMAttribute **ppNodeOut)
2431 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2432 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2435 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2436 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2438 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2439 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2440 return E_NOTIMPL;
2443 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2444 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2446 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2447 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2448 return E_NOTIMPL;
2451 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2453 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2454 HTMLDOMAttribute *attr;
2455 DISPID id;
2456 HRESULT hres;
2458 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2460 hres = get_attr_dispid_by_idx(This, &index, &id);
2461 if(hres == DISP_E_UNKNOWNNAME)
2462 return E_INVALIDARG;
2463 if(FAILED(hres))
2464 return hres;
2466 hres = get_domattr(This, id, NULL, &attr);
2467 if(FAILED(hres))
2468 return hres;
2470 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2471 return S_OK;
2474 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2476 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2477 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2480 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2481 HTMLAttributeCollection3_QueryInterface,
2482 HTMLAttributeCollection3_AddRef,
2483 HTMLAttributeCollection3_Release,
2484 HTMLAttributeCollection3_GetTypeInfoCount,
2485 HTMLAttributeCollection3_GetTypeInfo,
2486 HTMLAttributeCollection3_GetIDsOfNames,
2487 HTMLAttributeCollection3_Invoke,
2488 HTMLAttributeCollection3_getNamedItem,
2489 HTMLAttributeCollection3_setNamedItem,
2490 HTMLAttributeCollection3_removeNamedItem,
2491 HTMLAttributeCollection3_item,
2492 HTMLAttributeCollection3_get_length
2495 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2497 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2500 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2502 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2503 HTMLDOMAttribute *attr;
2504 LONG pos;
2505 HRESULT hres;
2507 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2509 hres = get_attr_dispid_by_name(This, name, dispid);
2510 if(FAILED(hres))
2511 return hres;
2513 hres = get_domattr(This, *dispid, &pos, &attr);
2514 if(FAILED(hres))
2515 return hres;
2516 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2518 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2519 return S_OK;
2522 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2523 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2525 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2527 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2529 switch(flags) {
2530 case DISPATCH_PROPERTYGET: {
2531 HTMLDOMAttribute *iter;
2533 id = id-MSHTML_DISPID_CUSTOM_MIN+1;
2535 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2536 if(!(--id))
2537 break;
2539 if(id)
2540 return E_INVALIDARG;
2542 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2543 V_VT(res) = VT_DISPATCH;
2544 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2545 return S_OK;
2548 default:
2549 FIXME("unimplemented flags %x\n", flags);
2550 return E_NOTIMPL;
2554 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2555 NULL,
2556 HTMLAttributeCollection_get_dispid,
2557 HTMLAttributeCollection_invoke,
2558 NULL
2561 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2562 IHTMLAttributeCollection_tid,
2563 IHTMLAttributeCollection2_tid,
2564 IHTMLAttributeCollection3_tid,
2568 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2569 &HTMLAttributeCollection_dispex_vtbl,
2570 DispHTMLAttributeCollection_tid,
2571 NULL,
2572 HTMLAttributeCollection_iface_tids
2575 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2577 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2579 if(This->attrs) {
2580 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2581 *ac = This->attrs;
2582 return S_OK;
2585 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2586 if(!This->attrs)
2587 return E_OUTOFMEMORY;
2589 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2590 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2591 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2592 This->attrs->ref = 2;
2594 This->attrs->elem = This;
2595 list_init(&This->attrs->attrs);
2596 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2597 &HTMLAttributeCollection_dispex);
2599 *ac = This->attrs;
2600 return S_OK;