mshtml: Added IHTMLMetaElement::charset property implementation.
[wine.git] / dlls / mshtml / htmlelem.c
blob8378d74d092119ac305530c6b95e21b6613335ec
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 buttonW[] = {'B','U','T','T','O','N',0};
42 static const WCHAR embedW[] = {'E','M','B','E','D',0};
43 static const WCHAR formW[] = {'F','O','R','M',0};
44 static const WCHAR frameW[] = {'F','R','A','M','E',0};
45 static const WCHAR headW[] = {'H','E','A','D',0};
46 static const WCHAR iframeW[] = {'I','F','R','A','M','E',0};
47 static const WCHAR imgW[] = {'I','M','G',0};
48 static const WCHAR inputW[] = {'I','N','P','U','T',0};
49 static const WCHAR labelW[] = {'L','A','B','E','L',0};
50 static const WCHAR linkW[] = {'L','I','N','K',0};
51 static const WCHAR metaW[] = {'M','E','T','A',0};
52 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
53 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
54 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
55 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
56 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
57 static const WCHAR tableW[] = {'T','A','B','L','E',0};
58 static const WCHAR tdW[] = {'T','D',0};
59 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
60 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
61 static const WCHAR trW[] = {'T','R',0};
63 typedef struct {
64 const WCHAR *name;
65 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
66 } tag_desc_t;
68 static const tag_desc_t tag_descs[] = {
69 {aW, HTMLAnchorElement_Create},
70 {bodyW, HTMLBodyElement_Create},
71 {buttonW, HTMLButtonElement_Create},
72 {embedW, HTMLEmbedElement_Create},
73 {formW, HTMLFormElement_Create},
74 {frameW, HTMLFrameElement_Create},
75 {headW, HTMLHeadElement_Create},
76 {iframeW, HTMLIFrame_Create},
77 {imgW, HTMLImgElement_Create},
78 {inputW, HTMLInputElement_Create},
79 {labelW, HTMLLabelElement_Create},
80 {linkW, HTMLLinkElement_Create},
81 {metaW, HTMLMetaElement_Create},
82 {objectW, HTMLObjectElement_Create},
83 {optionW, HTMLOptionElement_Create},
84 {scriptW, HTMLScriptElement_Create},
85 {selectW, HTMLSelectElement_Create},
86 {styleW, HTMLStyleElement_Create},
87 {tableW, HTMLTable_Create},
88 {tdW, HTMLTableCell_Create},
89 {textareaW, HTMLTextAreaElement_Create},
90 {title_tagW, HTMLTitleElement_Create},
91 {trW, HTMLTableRow_Create}
94 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
96 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
97 int r;
99 while(min <= max) {
100 i = (min+max)/2;
101 r = strcmpW(tag_name, tag_descs[i].name);
102 if(!r)
103 return tag_descs+i;
105 if(r < 0)
106 max = i-1;
107 else
108 min = i+1;
111 return NULL;
114 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
116 nsIDOMDocumentFragment *nsfragment;
117 nsIDOMNode *nsparent;
118 nsIDOMRange *range;
119 nsAString html_str;
120 nsresult nsres;
121 HRESULT hres = S_OK;
123 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
124 if(NS_FAILED(nsres)) {
125 ERR("CreateRange failed: %08x\n", nsres);
126 return E_FAIL;
129 nsAString_InitDepend(&html_str, html);
130 nsIDOMRange_CreateContextualFragment(range, &html_str, &nsfragment);
131 nsIDOMRange_Release(range);
132 nsAString_Finish(&html_str);
133 if(NS_FAILED(nsres)) {
134 ERR("CreateContextualFragment failed: %08x\n", nsres);
135 return E_FAIL;
138 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
139 if(NS_SUCCEEDED(nsres) && nsparent) {
140 nsIDOMNode *nstmp;
142 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
143 nsIDOMNode_Release(nsparent);
144 if(NS_FAILED(nsres)) {
145 ERR("ReplaceChild failed: %08x\n", nsres);
146 hres = E_FAIL;
147 }else if(nstmp) {
148 nsIDOMNode_Release(nstmp);
150 }else {
151 ERR("GetParentNode failed: %08x\n", nsres);
152 hres = E_FAIL;
155 nsIDOMDocumentFragment_Release(nsfragment);
156 return hres;
159 nsresult get_elem_attr_value(nsIDOMHTMLElement *nselem, const WCHAR *name, nsAString *val_str, const PRUnichar **val)
161 nsAString name_str;
162 nsresult nsres;
164 nsAString_InitDepend(&name_str, name);
165 nsAString_Init(val_str, NULL);
166 nsres = nsIDOMHTMLElement_GetAttribute(nselem, &name_str, val_str);
167 nsAString_Finish(&name_str);
168 if(NS_FAILED(nsres)) {
169 ERR("GetAttribute(%s) failed: %08x\n", debugstr_w(name), nsres);
170 nsAString_Finish(val_str);
171 return nsres;
174 nsAString_GetData(val_str, val);
175 return NS_OK;
178 HRESULT elem_string_attr_getter(HTMLElement *elem, const WCHAR *name, BOOL use_null, BSTR *p)
180 const PRUnichar *val;
181 nsAString val_str;
182 nsresult nsres;
183 HRESULT hres = S_OK;
185 nsres = get_elem_attr_value(elem->nselem, name, &val_str, &val);
186 if(NS_FAILED(nsres))
187 return E_FAIL;
189 TRACE("%s: returning %s\n", debugstr_w(name), debugstr_w(val));
191 if(*val || !use_null) {
192 *p = SysAllocString(val);
193 if(!*p)
194 hres = E_OUTOFMEMORY;
195 }else {
196 *p = NULL;
198 nsAString_Finish(&val_str);
199 return hres;
202 HRESULT elem_string_attr_setter(HTMLElement *elem, const WCHAR *name, const WCHAR *value)
204 nsAString name_str, val_str;
205 nsresult nsres;
207 nsAString_InitDepend(&name_str, name);
208 nsAString_InitDepend(&val_str, value);
209 nsres = nsIDOMHTMLElement_SetAttribute(elem->nselem, &name_str, &val_str);
210 nsAString_Finish(&name_str);
211 nsAString_Finish(&val_str);
213 if(NS_FAILED(nsres)) {
214 WARN("SetAttribute failed: %08x\n", nsres);
215 return E_FAIL;
218 return S_OK;
221 typedef struct
223 DispatchEx dispex;
224 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
226 LONG ref;
227 } HTMLFiltersCollection;
229 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
231 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
234 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
236 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
238 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
241 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
243 nsIDOMElement *nselem;
244 nsAString tag_str;
245 nsresult nsres;
247 if(!doc->nsdoc) {
248 WARN("NULL nsdoc\n");
249 return E_UNEXPECTED;
252 nsAString_InitDepend(&tag_str, tag);
253 nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
254 nsAString_Finish(&tag_str);
255 if(NS_FAILED(nsres)) {
256 ERR("CreateElement failed: %08x\n", nsres);
257 return E_FAIL;
260 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
261 nsIDOMElement_Release(nselem);
262 if(NS_FAILED(nsres)) {
263 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
264 return E_FAIL;
267 return S_OK;
270 HRESULT create_element(HTMLDocumentNode *doc, const WCHAR *tag, HTMLElement **ret)
272 nsIDOMHTMLElement *nselem;
273 HRESULT hres;
275 /* Use owner doc if called on document fragment */
276 if(!doc->nsdoc)
277 doc = doc->node.doc;
279 hres = create_nselem(doc, tag, &nselem);
280 if(FAILED(hres))
281 return hres;
283 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, TRUE, ret);
284 nsIDOMHTMLElement_Release(nselem);
285 return hres;
288 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
289 REFIID riid, void **ppv)
291 HTMLElement *This = impl_from_IHTMLElement(iface);
293 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
296 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
298 HTMLElement *This = impl_from_IHTMLElement(iface);
300 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
303 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
305 HTMLElement *This = impl_from_IHTMLElement(iface);
307 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
310 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
312 HTMLElement *This = impl_from_IHTMLElement(iface);
313 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
316 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
317 LCID lcid, ITypeInfo **ppTInfo)
319 HTMLElement *This = impl_from_IHTMLElement(iface);
320 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
323 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
324 LPOLESTR *rgszNames, UINT cNames,
325 LCID lcid, DISPID *rgDispId)
327 HTMLElement *This = impl_from_IHTMLElement(iface);
328 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
329 lcid, rgDispId);
332 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
333 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
334 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
336 HTMLElement *This = impl_from_IHTMLElement(iface);
337 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
338 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
341 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
342 VARIANT AttributeValue, LONG lFlags)
344 HTMLElement *This = impl_from_IHTMLElement(iface);
345 HRESULT hres;
346 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
347 DISPPARAMS dispParams;
348 EXCEPINFO excep;
350 TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
352 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
353 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
354 if(FAILED(hres))
355 return hres;
357 dispParams.cArgs = 1;
358 dispParams.cNamedArgs = 1;
359 dispParams.rgdispidNamedArgs = &dispidNamed;
360 dispParams.rgvarg = &AttributeValue;
362 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
363 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
364 return hres;
367 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
368 LONG lFlags, VARIANT *AttributeValue)
370 HTMLElement *This = impl_from_IHTMLElement(iface);
371 DISPID dispid;
372 HRESULT hres;
373 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
374 EXCEPINFO excep;
376 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
378 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
379 fdexNameCaseInsensitive, &dispid);
380 if(hres == DISP_E_UNKNOWNNAME) {
381 V_VT(AttributeValue) = VT_NULL;
382 return S_OK;
385 if(FAILED(hres)) {
386 V_VT(AttributeValue) = VT_NULL;
387 return hres;
390 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
391 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
393 return hres;
396 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
397 LONG lFlags, VARIANT_BOOL *pfSuccess)
399 HTMLElement *This = impl_from_IHTMLElement(iface);
401 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
403 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
406 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
408 HTMLElement *This = impl_from_IHTMLElement(iface);
409 nsAString classname_str;
410 nsresult nsres;
412 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
414 if(!This->nselem) {
415 FIXME("NULL nselem\n");
416 return E_NOTIMPL;
419 nsAString_InitDepend(&classname_str, v);
420 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
421 nsAString_Finish(&classname_str);
422 if(NS_FAILED(nsres))
423 ERR("SetClassName failed: %08x\n", nsres);
425 return S_OK;
428 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
430 HTMLElement *This = impl_from_IHTMLElement(iface);
431 nsAString class_str;
432 nsresult nsres;
434 TRACE("(%p)->(%p)\n", This, p);
436 if(!This->nselem) {
437 FIXME("NULL nselem\n");
438 return E_NOTIMPL;
441 nsAString_Init(&class_str, NULL);
442 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
443 return return_nsstr(nsres, &class_str, p);
446 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
448 HTMLElement *This = impl_from_IHTMLElement(iface);
449 nsAString id_str;
450 nsresult nsres;
452 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
454 if(!This->nselem) {
455 FIXME("nselem == NULL\n");
456 return S_OK;
459 nsAString_InitDepend(&id_str, v);
460 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
461 nsAString_Finish(&id_str);
462 if(NS_FAILED(nsres))
463 ERR("SetId failed: %08x\n", nsres);
465 return S_OK;
468 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
470 HTMLElement *This = impl_from_IHTMLElement(iface);
471 nsAString id_str;
472 nsresult nsres;
474 TRACE("(%p)->(%p)\n", This, p);
476 if(!This->nselem) {
477 *p = NULL;
478 return S_OK;
481 nsAString_Init(&id_str, NULL);
482 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
483 return return_nsstr(nsres, &id_str, p);
486 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
488 HTMLElement *This = impl_from_IHTMLElement(iface);
489 nsAString tag_str;
490 nsresult nsres;
492 TRACE("(%p)->(%p)\n", This, p);
494 if(!This->nselem) {
495 static const WCHAR comment_tagW[] = {'!',0};
497 WARN("NULL nselem, assuming comment\n");
499 *p = SysAllocString(comment_tagW);
500 return *p ? S_OK : E_OUTOFMEMORY;
503 nsAString_Init(&tag_str, NULL);
504 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
505 return return_nsstr(nsres, &tag_str, p);
508 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
510 HTMLElement *This = impl_from_IHTMLElement(iface);
511 IHTMLDOMNode *node;
512 HRESULT hres;
514 TRACE("(%p)->(%p)\n", This, p);
516 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
517 if(FAILED(hres))
518 return hres;
520 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
521 IHTMLDOMNode_Release(node);
522 if(FAILED(hres))
523 *p = NULL;
525 return S_OK;
528 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
530 HTMLElement *This = impl_from_IHTMLElement(iface);
532 TRACE("(%p)->(%p)\n", This, p);
534 if(!This->style) {
535 HRESULT hres;
537 hres = HTMLStyle_Create(This, &This->style);
538 if(FAILED(hres))
539 return hres;
542 *p = &This->style->IHTMLStyle_iface;
543 IHTMLStyle_AddRef(*p);
544 return S_OK;
547 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
549 HTMLElement *This = impl_from_IHTMLElement(iface);
550 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
551 return E_NOTIMPL;
554 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
556 HTMLElement *This = impl_from_IHTMLElement(iface);
557 FIXME("(%p)->(%p)\n", This, p);
558 return E_NOTIMPL;
561 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
563 HTMLElement *This = impl_from_IHTMLElement(iface);
565 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
567 return set_node_event(&This->node, EVENTID_CLICK, &v);
570 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
572 HTMLElement *This = impl_from_IHTMLElement(iface);
574 TRACE("(%p)->(%p)\n", This, p);
576 return get_node_event(&This->node, EVENTID_CLICK, p);
579 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
581 HTMLElement *This = impl_from_IHTMLElement(iface);
583 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
585 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
588 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
590 HTMLElement *This = impl_from_IHTMLElement(iface);
592 TRACE("(%p)->(%p)\n", This, p);
594 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
597 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
599 HTMLElement *This = impl_from_IHTMLElement(iface);
601 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
603 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
606 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
608 HTMLElement *This = impl_from_IHTMLElement(iface);
610 TRACE("(%p)->(%p)\n", This, p);
612 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
615 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
617 HTMLElement *This = impl_from_IHTMLElement(iface);
619 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
621 return set_node_event(&This->node, EVENTID_KEYUP, &v);
624 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
626 HTMLElement *This = impl_from_IHTMLElement(iface);
627 FIXME("(%p)->(%p)\n", This, p);
628 return E_NOTIMPL;
631 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
633 HTMLElement *This = impl_from_IHTMLElement(iface);
635 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
637 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
640 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
642 HTMLElement *This = impl_from_IHTMLElement(iface);
644 TRACE("(%p)->(%p)\n", This, p);
646 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
649 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
651 HTMLElement *This = impl_from_IHTMLElement(iface);
653 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
655 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
658 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
660 HTMLElement *This = impl_from_IHTMLElement(iface);
662 TRACE("(%p)->(%p)\n", This, p);
664 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
667 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
669 HTMLElement *This = impl_from_IHTMLElement(iface);
671 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
673 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
676 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
678 HTMLElement *This = impl_from_IHTMLElement(iface);
680 TRACE("(%p)->(%p)\n", This, p);
682 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
685 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
687 HTMLElement *This = impl_from_IHTMLElement(iface);
689 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
691 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
694 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
696 HTMLElement *This = impl_from_IHTMLElement(iface);
698 TRACE("(%p)->(%p)\n", This, p);
700 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
703 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
705 HTMLElement *This = impl_from_IHTMLElement(iface);
707 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
709 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
712 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
714 HTMLElement *This = impl_from_IHTMLElement(iface);
716 TRACE("(%p)->(%p)\n", This, p);
718 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
721 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
723 HTMLElement *This = impl_from_IHTMLElement(iface);
725 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
727 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
730 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
732 HTMLElement *This = impl_from_IHTMLElement(iface);
734 TRACE("(%p)->(%p)\n", This, p);
736 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
739 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
741 HTMLElement *This = impl_from_IHTMLElement(iface);
743 TRACE("(%p)->(%p)\n", This, p);
745 if(!p)
746 return E_POINTER;
748 if(This->node.vtbl->get_document)
749 return This->node.vtbl->get_document(&This->node, p);
751 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
752 IDispatch_AddRef(*p);
753 return S_OK;
756 static const WCHAR titleW[] = {'t','i','t','l','e',0};
758 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
760 HTMLElement *This = impl_from_IHTMLElement(iface);
761 nsAString title_str;
762 nsresult nsres;
764 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
766 if(!This->nselem) {
767 VARIANT *var;
768 HRESULT hres;
770 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
771 if(FAILED(hres))
772 return hres;
774 VariantClear(var);
775 V_VT(var) = VT_BSTR;
776 V_BSTR(var) = v ? SysAllocString(v) : NULL;
777 return S_OK;
780 nsAString_InitDepend(&title_str, v);
781 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
782 nsAString_Finish(&title_str);
783 if(NS_FAILED(nsres))
784 ERR("SetTitle failed: %08x\n", nsres);
786 return S_OK;
789 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
791 HTMLElement *This = impl_from_IHTMLElement(iface);
792 nsAString title_str;
793 nsresult nsres;
795 TRACE("(%p)->(%p)\n", This, p);
797 if(!This->nselem) {
798 VARIANT *var;
799 HRESULT hres;
801 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
802 if(hres == DISP_E_UNKNOWNNAME) {
803 *p = NULL;
804 }else if(V_VT(var) != VT_BSTR) {
805 FIXME("title = %s\n", debugstr_variant(var));
806 return E_FAIL;
807 }else {
808 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
811 return S_OK;
814 nsAString_Init(&title_str, NULL);
815 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
816 return return_nsstr(nsres, &title_str, p);
819 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
821 HTMLElement *This = impl_from_IHTMLElement(iface);
822 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
823 return E_NOTIMPL;
826 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
828 HTMLElement *This = impl_from_IHTMLElement(iface);
829 FIXME("(%p)->(%p)\n", This, p);
830 return E_NOTIMPL;
833 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
835 HTMLElement *This = impl_from_IHTMLElement(iface);
837 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
839 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
842 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
844 HTMLElement *This = impl_from_IHTMLElement(iface);
846 TRACE("(%p)->(%p)\n", This, p);
848 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
851 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
853 HTMLElement *This = impl_from_IHTMLElement(iface);
854 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
855 return E_NOTIMPL;
858 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
859 VARIANT_BOOL *pfResult)
861 HTMLElement *This = impl_from_IHTMLElement(iface);
862 HTMLElement *child;
863 cpp_bool result;
864 nsresult nsres;
866 TRACE("(%p)->(%p %p)\n", This, pChild, pfResult);
868 child = unsafe_impl_from_IHTMLElement(pChild);
869 if(!child) {
870 ERR("not our element\n");
871 return E_FAIL;
874 nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result);
875 if(NS_FAILED(nsres)) {
876 ERR("failed\n");
877 return E_FAIL;
880 *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE;
881 return S_OK;
884 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
886 HTMLElement *This = impl_from_IHTMLElement(iface);
887 FIXME("(%p)->(%p)\n", This, p);
888 return E_NOTIMPL;
891 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
893 HTMLElement *This = impl_from_IHTMLElement(iface);
894 FIXME("(%p)->(%p)\n", This, p);
895 return E_NOTIMPL;
898 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
900 HTMLElement *This = impl_from_IHTMLElement(iface);
901 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
902 return E_NOTIMPL;
905 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
907 HTMLElement *This = impl_from_IHTMLElement(iface);
908 FIXME("(%p)->(%p)\n", This, p);
909 return E_NOTIMPL;
912 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
914 HTMLElement *This = impl_from_IHTMLElement(iface);
915 nsresult nsres;
917 TRACE("(%p)->(%p)\n", This, p);
919 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, p);
920 if(NS_FAILED(nsres)) {
921 ERR("GetOffsetLeft failed: %08x\n", nsres);
922 return E_FAIL;
925 return S_OK;
928 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
930 HTMLElement *This = impl_from_IHTMLElement(iface);
931 nsresult nsres;
933 TRACE("(%p)->(%p)\n", This, p);
935 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, p);
936 if(NS_FAILED(nsres)) {
937 ERR("GetOffsetTop failed: %08x\n", nsres);
938 return E_FAIL;
941 return S_OK;
944 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
946 HTMLElement *This = impl_from_IHTMLElement(iface);
947 nsresult nsres;
949 TRACE("(%p)->(%p)\n", This, p);
951 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, p);
952 if(NS_FAILED(nsres)) {
953 ERR("GetOffsetWidth failed: %08x\n", nsres);
954 return E_FAIL;
957 return S_OK;
960 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
962 HTMLElement *This = impl_from_IHTMLElement(iface);
963 nsresult nsres;
965 TRACE("(%p)->(%p)\n", This, p);
967 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, p);
968 if(NS_FAILED(nsres)) {
969 ERR("GetOffsetHeight failed: %08x\n", nsres);
970 return E_FAIL;
973 return S_OK;
976 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
978 HTMLElement *This = impl_from_IHTMLElement(iface);
979 nsIDOMElement *nsparent;
980 nsresult nsres;
981 HRESULT hres;
983 TRACE("(%p)->(%p)\n", This, p);
985 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
986 if(NS_FAILED(nsres)) {
987 ERR("GetOffsetParent failed: %08x\n", nsres);
988 return E_FAIL;
991 if(nsparent) {
992 HTMLDOMNode *node;
994 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
995 nsIDOMElement_Release(nsparent);
996 if(FAILED(hres))
997 return hres;
999 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
1000 node_release(node);
1001 }else {
1002 *p = NULL;
1003 hres = S_OK;
1006 return hres;
1009 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
1011 HTMLElement *This = impl_from_IHTMLElement(iface);
1012 nsAString html_str;
1013 nsresult nsres;
1015 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1017 if(!This->nselem) {
1018 FIXME("NULL nselem\n");
1019 return E_NOTIMPL;
1022 nsAString_InitDepend(&html_str, v);
1023 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
1024 nsAString_Finish(&html_str);
1025 if(NS_FAILED(nsres)) {
1026 FIXME("SetInnerHtml failed %08x\n", nsres);
1027 return E_FAIL;
1030 return S_OK;
1033 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1035 HTMLElement *This = impl_from_IHTMLElement(iface);
1036 nsAString html_str;
1037 nsresult nsres;
1039 TRACE("(%p)->(%p)\n", This, p);
1041 if(!This->nselem) {
1042 FIXME("NULL nselem\n");
1043 return E_NOTIMPL;
1046 nsAString_Init(&html_str, NULL);
1047 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
1048 return return_nsstr(nsres, &html_str, p);
1051 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1053 HTMLElement *This = impl_from_IHTMLElement(iface);
1054 nsIDOMNode *nschild, *tmp;
1055 nsIDOMText *text_node;
1056 nsAString text_str;
1057 nsresult nsres;
1059 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1061 while(1) {
1062 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1063 if(NS_FAILED(nsres)) {
1064 ERR("GetLastChild failed: %08x\n", nsres);
1065 return E_FAIL;
1067 if(!nschild)
1068 break;
1070 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1071 nsIDOMNode_Release(nschild);
1072 if(NS_FAILED(nsres)) {
1073 ERR("RemoveChild failed: %08x\n", nsres);
1074 return E_FAIL;
1076 nsIDOMNode_Release(tmp);
1079 nsAString_InitDepend(&text_str, v);
1080 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1081 nsAString_Finish(&text_str);
1082 if(NS_FAILED(nsres)) {
1083 ERR("CreateTextNode failed: %08x\n", nsres);
1084 return E_FAIL;
1087 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1088 if(NS_FAILED(nsres)) {
1089 ERR("AppendChild failed: %08x\n", nsres);
1090 return E_FAIL;
1093 nsIDOMNode_Release(tmp);
1094 return S_OK;
1097 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1099 HTMLElement *This = impl_from_IHTMLElement(iface);
1101 TRACE("(%p)->(%p)\n", This, p);
1103 return get_node_text(&This->node, p);
1106 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1108 HTMLElement *This = impl_from_IHTMLElement(iface);
1110 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1112 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1115 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1117 HTMLElement *This = impl_from_IHTMLElement(iface);
1118 nsAString html_str;
1119 HRESULT hres;
1121 WARN("(%p)->(%p) semi-stub\n", This, p);
1123 nsAString_Init(&html_str, NULL);
1124 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1125 if(SUCCEEDED(hres)) {
1126 const PRUnichar *html;
1128 nsAString_GetData(&html_str, &html);
1129 *p = SysAllocString(html);
1130 if(!*p)
1131 hres = E_OUTOFMEMORY;
1134 nsAString_Finish(&html_str);
1136 TRACE("ret %s\n", debugstr_w(*p));
1137 return hres;
1140 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1142 HTMLElement *This = impl_from_IHTMLElement(iface);
1143 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1144 return E_NOTIMPL;
1147 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1149 HTMLElement *This = impl_from_IHTMLElement(iface);
1150 FIXME("(%p)->(%p)\n", This, p);
1151 return E_NOTIMPL;
1154 HRESULT insert_adjacent_node(HTMLElement *This, const WCHAR *where, nsIDOMNode *nsnode, HTMLDOMNode **ret_node)
1156 nsIDOMNode *ret_nsnode;
1157 nsresult nsres;
1158 HRESULT hres = S_OK;
1160 static const WCHAR beforebeginW[] = {'b','e','f','o','r','e','b','e','g','i','n',0};
1161 static const WCHAR afterbeginW[] = {'a','f','t','e','r','b','e','g','i','n',0};
1162 static const WCHAR beforeendW[] = {'b','e','f','o','r','e','e','n','d',0};
1163 static const WCHAR afterendW[] = {'a','f','t','e','r','e','n','d',0};
1165 if (!strcmpiW(where, beforebeginW)) {
1166 nsIDOMNode *parent;
1168 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1169 if(NS_FAILED(nsres))
1170 return E_FAIL;
1172 if(!parent)
1173 return E_INVALIDARG;
1175 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &ret_nsnode);
1176 nsIDOMNode_Release(parent);
1177 }else if(!strcmpiW(where, afterbeginW)) {
1178 nsIDOMNode *first_child;
1180 nsres = nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1181 if(NS_FAILED(nsres))
1182 return E_FAIL;
1184 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &ret_nsnode);
1185 if(NS_FAILED(nsres))
1186 return E_FAIL;
1188 if (first_child)
1189 nsIDOMNode_Release(first_child);
1190 }else if (!strcmpiW(where, beforeendW)) {
1191 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &ret_nsnode);
1192 }else if (!strcmpiW(where, afterendW)) {
1193 nsIDOMNode *next_sibling, *parent;
1195 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1196 if(NS_FAILED(nsres))
1197 return E_FAIL;
1198 if(!parent)
1199 return E_INVALIDARG;
1201 nsres = nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1202 if(NS_SUCCEEDED(nsres)) {
1203 if(next_sibling) {
1204 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &ret_nsnode);
1205 nsIDOMNode_Release(next_sibling);
1206 }else {
1207 nsres = nsIDOMNode_AppendChild(parent, nsnode, &ret_nsnode);
1211 nsIDOMNode_Release(parent);
1212 }else {
1213 ERR("invalid where: %s\n", debugstr_w(where));
1214 return E_INVALIDARG;
1217 if (NS_FAILED(nsres))
1218 return E_FAIL;
1220 if(ret_node)
1221 hres = get_node(This->node.doc, ret_nsnode, TRUE, ret_node);
1222 nsIDOMNode_Release(ret_nsnode);
1223 return hres;
1226 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1227 BSTR html)
1229 HTMLElement *This = impl_from_IHTMLElement(iface);
1230 nsIDOMRange *range;
1231 nsIDOMNode *nsnode;
1232 nsAString ns_html;
1233 nsresult nsres;
1234 HRESULT hr;
1236 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1238 if(!This->node.doc->nsdoc) {
1239 WARN("NULL nsdoc\n");
1240 return E_UNEXPECTED;
1243 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1244 if(NS_FAILED(nsres))
1246 ERR("CreateRange failed: %08x\n", nsres);
1247 return E_FAIL;
1250 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1252 nsAString_InitDepend(&ns_html, html);
1253 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1254 nsAString_Finish(&ns_html);
1255 nsIDOMRange_Release(range);
1257 if(NS_FAILED(nsres) || !nsnode)
1259 ERR("CreateTextNode failed: %08x\n", nsres);
1260 return E_FAIL;
1263 hr = insert_adjacent_node(This, where, nsnode, NULL);
1264 nsIDOMNode_Release(nsnode);
1265 return hr;
1268 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1269 BSTR text)
1271 HTMLElement *This = impl_from_IHTMLElement(iface);
1272 nsIDOMNode *nsnode;
1273 nsAString ns_text;
1274 nsresult nsres;
1275 HRESULT hr;
1277 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1279 if(!This->node.doc->nsdoc) {
1280 WARN("NULL nsdoc\n");
1281 return E_UNEXPECTED;
1285 nsAString_InitDepend(&ns_text, text);
1286 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1287 nsAString_Finish(&ns_text);
1289 if(NS_FAILED(nsres) || !nsnode)
1291 ERR("CreateTextNode failed: %08x\n", nsres);
1292 return E_FAIL;
1295 hr = insert_adjacent_node(This, where, nsnode, NULL);
1296 nsIDOMNode_Release(nsnode);
1298 return hr;
1301 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1303 HTMLElement *This = impl_from_IHTMLElement(iface);
1304 FIXME("(%p)->(%p)\n", This, p);
1305 return E_NOTIMPL;
1308 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1310 HTMLElement *This = impl_from_IHTMLElement(iface);
1311 FIXME("(%p)->(%p)\n", This, p);
1312 return E_NOTIMPL;
1315 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1317 HTMLElement *This = impl_from_IHTMLElement(iface);
1319 TRACE("(%p)\n", This);
1321 return call_fire_event(&This->node, EVENTID_CLICK);
1324 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1325 IHTMLFiltersCollection **p)
1327 HTMLElement *This = impl_from_IHTMLElement(iface);
1328 TRACE("(%p)->(%p)\n", This, p);
1330 if(!p)
1331 return E_POINTER;
1333 *p = HTMLFiltersCollection_Create();
1335 return S_OK;
1338 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1340 HTMLElement *This = impl_from_IHTMLElement(iface);
1341 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1342 return E_NOTIMPL;
1345 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1347 HTMLElement *This = impl_from_IHTMLElement(iface);
1348 FIXME("(%p)->(%p)\n", This, p);
1349 return E_NOTIMPL;
1352 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1354 HTMLElement *This = impl_from_IHTMLElement(iface);
1355 FIXME("(%p)->(%p)\n", This, String);
1356 return E_NOTIMPL;
1359 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1361 HTMLElement *This = impl_from_IHTMLElement(iface);
1362 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1363 return E_NOTIMPL;
1366 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1368 HTMLElement *This = impl_from_IHTMLElement(iface);
1369 FIXME("(%p)->(%p)\n", This, p);
1370 return E_NOTIMPL;
1373 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1375 HTMLElement *This = impl_from_IHTMLElement(iface);
1376 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1377 return E_NOTIMPL;
1380 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1382 HTMLElement *This = impl_from_IHTMLElement(iface);
1383 FIXME("(%p)->(%p)\n", This, p);
1384 return E_NOTIMPL;
1387 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1389 HTMLElement *This = impl_from_IHTMLElement(iface);
1390 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1391 return E_NOTIMPL;
1394 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1396 HTMLElement *This = impl_from_IHTMLElement(iface);
1397 FIXME("(%p)->(%p)\n", This, p);
1398 return E_NOTIMPL;
1401 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1403 HTMLElement *This = impl_from_IHTMLElement(iface);
1404 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1405 return E_NOTIMPL;
1408 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1410 HTMLElement *This = impl_from_IHTMLElement(iface);
1411 FIXME("(%p)->(%p)\n", This, p);
1412 return E_NOTIMPL;
1415 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1417 HTMLElement *This = impl_from_IHTMLElement(iface);
1418 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1419 return E_NOTIMPL;
1422 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1424 HTMLElement *This = impl_from_IHTMLElement(iface);
1425 FIXME("(%p)->(%p)\n", This, p);
1426 return E_NOTIMPL;
1429 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1431 HTMLElement *This = impl_from_IHTMLElement(iface);
1432 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1433 return E_NOTIMPL;
1436 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1438 HTMLElement *This = impl_from_IHTMLElement(iface);
1439 FIXME("(%p)->(%p)\n", This, p);
1440 return E_NOTIMPL;
1443 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1445 HTMLElement *This = impl_from_IHTMLElement(iface);
1447 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1449 return set_node_event(&This->node, EVENTID_DATAAVAILABLE, &v);
1452 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1454 HTMLElement *This = impl_from_IHTMLElement(iface);
1456 TRACE("(%p)->(%p)\n", This, p);
1458 return get_node_event(&This->node, EVENTID_DATAAVAILABLE, p);
1461 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1463 HTMLElement *This = impl_from_IHTMLElement(iface);
1464 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1465 return E_NOTIMPL;
1468 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1470 HTMLElement *This = impl_from_IHTMLElement(iface);
1471 FIXME("(%p)->(%p)\n", This, p);
1472 return E_NOTIMPL;
1475 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1477 HTMLElement *This = impl_from_IHTMLElement(iface);
1478 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1479 return E_NOTIMPL;
1482 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1484 HTMLElement *This = impl_from_IHTMLElement(iface);
1485 FIXME("(%p)->(%p)\n", This, p);
1486 return E_NOTIMPL;
1489 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1491 HTMLElement *This = impl_from_IHTMLElement(iface);
1492 nsIDOMNodeList *nsnode_list;
1493 nsresult nsres;
1495 TRACE("(%p)->(%p)\n", This, p);
1497 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1498 if(NS_FAILED(nsres)) {
1499 ERR("GetChildNodes failed: %08x\n", nsres);
1500 return E_FAIL;
1503 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1505 nsIDOMNodeList_Release(nsnode_list);
1506 return S_OK;
1509 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1511 HTMLElement *This = impl_from_IHTMLElement(iface);
1513 TRACE("(%p)->(%p)\n", This, p);
1515 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1516 return S_OK;
1519 static const IHTMLElementVtbl HTMLElementVtbl = {
1520 HTMLElement_QueryInterface,
1521 HTMLElement_AddRef,
1522 HTMLElement_Release,
1523 HTMLElement_GetTypeInfoCount,
1524 HTMLElement_GetTypeInfo,
1525 HTMLElement_GetIDsOfNames,
1526 HTMLElement_Invoke,
1527 HTMLElement_setAttribute,
1528 HTMLElement_getAttribute,
1529 HTMLElement_removeAttribute,
1530 HTMLElement_put_className,
1531 HTMLElement_get_className,
1532 HTMLElement_put_id,
1533 HTMLElement_get_id,
1534 HTMLElement_get_tagName,
1535 HTMLElement_get_parentElement,
1536 HTMLElement_get_style,
1537 HTMLElement_put_onhelp,
1538 HTMLElement_get_onhelp,
1539 HTMLElement_put_onclick,
1540 HTMLElement_get_onclick,
1541 HTMLElement_put_ondblclick,
1542 HTMLElement_get_ondblclick,
1543 HTMLElement_put_onkeydown,
1544 HTMLElement_get_onkeydown,
1545 HTMLElement_put_onkeyup,
1546 HTMLElement_get_onkeyup,
1547 HTMLElement_put_onkeypress,
1548 HTMLElement_get_onkeypress,
1549 HTMLElement_put_onmouseout,
1550 HTMLElement_get_onmouseout,
1551 HTMLElement_put_onmouseover,
1552 HTMLElement_get_onmouseover,
1553 HTMLElement_put_onmousemove,
1554 HTMLElement_get_onmousemove,
1555 HTMLElement_put_onmousedown,
1556 HTMLElement_get_onmousedown,
1557 HTMLElement_put_onmouseup,
1558 HTMLElement_get_onmouseup,
1559 HTMLElement_get_document,
1560 HTMLElement_put_title,
1561 HTMLElement_get_title,
1562 HTMLElement_put_language,
1563 HTMLElement_get_language,
1564 HTMLElement_put_onselectstart,
1565 HTMLElement_get_onselectstart,
1566 HTMLElement_scrollIntoView,
1567 HTMLElement_contains,
1568 HTMLElement_get_sourceIndex,
1569 HTMLElement_get_recordNumber,
1570 HTMLElement_put_lang,
1571 HTMLElement_get_lang,
1572 HTMLElement_get_offsetLeft,
1573 HTMLElement_get_offsetTop,
1574 HTMLElement_get_offsetWidth,
1575 HTMLElement_get_offsetHeight,
1576 HTMLElement_get_offsetParent,
1577 HTMLElement_put_innerHTML,
1578 HTMLElement_get_innerHTML,
1579 HTMLElement_put_innerText,
1580 HTMLElement_get_innerText,
1581 HTMLElement_put_outerHTML,
1582 HTMLElement_get_outerHTML,
1583 HTMLElement_put_outerText,
1584 HTMLElement_get_outerText,
1585 HTMLElement_insertAdjacentHTML,
1586 HTMLElement_insertAdjacentText,
1587 HTMLElement_get_parentTextEdit,
1588 HTMLElement_get_isTextEdit,
1589 HTMLElement_click,
1590 HTMLElement_get_filters,
1591 HTMLElement_put_ondragstart,
1592 HTMLElement_get_ondragstart,
1593 HTMLElement_toString,
1594 HTMLElement_put_onbeforeupdate,
1595 HTMLElement_get_onbeforeupdate,
1596 HTMLElement_put_onafterupdate,
1597 HTMLElement_get_onafterupdate,
1598 HTMLElement_put_onerrorupdate,
1599 HTMLElement_get_onerrorupdate,
1600 HTMLElement_put_onrowexit,
1601 HTMLElement_get_onrowexit,
1602 HTMLElement_put_onrowenter,
1603 HTMLElement_get_onrowenter,
1604 HTMLElement_put_ondatasetchanged,
1605 HTMLElement_get_ondatasetchanged,
1606 HTMLElement_put_ondataavailable,
1607 HTMLElement_get_ondataavailable,
1608 HTMLElement_put_ondatasetcomplete,
1609 HTMLElement_get_ondatasetcomplete,
1610 HTMLElement_put_onfilterchange,
1611 HTMLElement_get_onfilterchange,
1612 HTMLElement_get_children,
1613 HTMLElement_get_all
1616 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1618 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1621 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1623 return CONTAINING_RECORD(iface, HTMLElement, node);
1626 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1628 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1630 if(IsEqualGUID(&IID_IUnknown, riid)) {
1631 *ppv = &This->IHTMLElement_iface;
1632 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1633 *ppv = &This->IHTMLElement_iface;
1634 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1635 *ppv = &This->IHTMLElement_iface;
1636 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1637 *ppv = &This->IHTMLElement2_iface;
1638 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1639 *ppv = &This->IHTMLElement3_iface;
1640 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1641 *ppv = &This->IHTMLElement4_iface;
1642 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1643 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1644 }else {
1645 return HTMLDOMNode_QI(&This->node, riid, ppv);
1648 IUnknown_AddRef((IUnknown*)*ppv);
1649 return S_OK;
1652 void HTMLElement_destructor(HTMLDOMNode *iface)
1654 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1656 ConnectionPointContainer_Destroy(&This->cp_container);
1658 if(This->style) {
1659 This->style->elem = NULL;
1660 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1662 if(This->runtime_style) {
1663 This->runtime_style->elem = NULL;
1664 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1666 if(This->attrs) {
1667 HTMLDOMAttribute *attr;
1669 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1670 attr->elem = NULL;
1672 This->attrs->elem = NULL;
1673 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1676 heap_free(This->filter);
1678 HTMLDOMNode_destructor(&This->node);
1681 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1683 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1684 HTMLElement *new_elem;
1685 HRESULT hres;
1687 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1688 if(FAILED(hres))
1689 return hres;
1691 if(This->filter) {
1692 new_elem->filter = heap_strdupW(This->filter);
1693 if(!new_elem->filter) {
1694 IHTMLElement_Release(&This->IHTMLElement_iface);
1695 return E_OUTOFMEMORY;
1699 *ret = &new_elem->node;
1700 return S_OK;
1703 HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *event, BOOL *prevent_default)
1705 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1707 switch(eid) {
1708 case EVENTID_KEYDOWN: {
1709 nsIDOMKeyEvent *key_event;
1710 nsresult nsres;
1712 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
1713 if(NS_SUCCEEDED(nsres)) {
1714 UINT32 code = 0;
1716 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
1718 switch(code) {
1719 case VK_F1: /* DOM_VK_F1 */
1720 TRACE("F1 pressed\n");
1721 fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL);
1722 *prevent_default = TRUE;
1725 nsIDOMKeyEvent_Release(key_event);
1730 return S_OK;
1733 cp_static_data_t HTMLElementEvents2_data = { HTMLElementEvents2_tid, NULL /* FIXME */, TRUE };
1735 const cpc_entry_t HTMLElement_cpc[] = {
1736 HTMLELEMENT_CPC,
1737 {NULL}
1740 static const NodeImplVtbl HTMLElementImplVtbl = {
1741 HTMLElement_QI,
1742 HTMLElement_destructor,
1743 HTMLElement_cpc,
1744 HTMLElement_clone,
1745 HTMLElement_handle_event,
1746 HTMLElement_get_attr_col
1749 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1751 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1754 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1755 DWORD grfdex, DISPID *pid)
1757 HTMLElement *This = impl_from_DispatchEx(dispex);
1759 if(This->node.vtbl->get_dispid)
1760 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1762 return DISP_E_UNKNOWNNAME;
1765 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1766 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1767 IServiceProvider *caller)
1769 HTMLElement *This = impl_from_DispatchEx(dispex);
1771 if(This->node.vtbl->invoke)
1772 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1773 params, res, ei, caller);
1775 ERR("(%p): element has no invoke method\n", This);
1776 return E_NOTIMPL;
1779 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1781 HTMLElement *This = impl_from_DispatchEx(dispex);
1782 nsIDOMMozNamedAttrMap *attrs;
1783 nsIDOMAttr *attr;
1784 nsAString nsstr;
1785 const PRUnichar *str;
1786 BSTR name;
1787 VARIANT value;
1788 unsigned i;
1789 UINT32 len;
1790 DISPID id;
1791 nsresult nsres;
1792 HRESULT hres;
1794 if(!This->nselem)
1795 return S_FALSE;
1797 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1798 if(NS_FAILED(nsres))
1799 return E_FAIL;
1801 nsres = nsIDOMMozNamedAttrMap_GetLength(attrs, &len);
1802 if(NS_FAILED(nsres)) {
1803 nsIDOMMozNamedAttrMap_Release(attrs);
1804 return E_FAIL;
1807 nsAString_Init(&nsstr, NULL);
1808 for(i=0; i<len; i++) {
1809 nsres = nsIDOMMozNamedAttrMap_Item(attrs, i, &attr);
1810 if(NS_FAILED(nsres))
1811 continue;
1813 nsres = nsIDOMAttr_GetNodeName(attr, &nsstr);
1814 if(NS_FAILED(nsres)) {
1815 nsIDOMAttr_Release(attr);
1816 continue;
1819 nsAString_GetData(&nsstr, &str);
1820 name = SysAllocString(str);
1821 if(!name) {
1822 nsIDOMAttr_Release(attr);
1823 continue;
1826 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1827 if(hres != DISP_E_UNKNOWNNAME) {
1828 nsIDOMAttr_Release(attr);
1829 SysFreeString(name);
1830 continue;
1833 nsres = nsIDOMAttr_GetNodeValue(attr, &nsstr);
1834 nsIDOMAttr_Release(attr);
1835 if(NS_FAILED(nsres)) {
1836 SysFreeString(name);
1837 continue;
1840 nsAString_GetData(&nsstr, &str);
1841 V_VT(&value) = VT_BSTR;
1842 if(*str) {
1843 V_BSTR(&value) = SysAllocString(str);
1844 if(!V_BSTR(&value)) {
1845 SysFreeString(name);
1846 continue;
1848 } else
1849 V_BSTR(&value) = NULL;
1851 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1852 SysFreeString(name);
1853 VariantClear(&value);
1855 nsAString_Finish(&nsstr);
1857 nsIDOMMozNamedAttrMap_Release(attrs);
1858 return S_OK;
1861 static const tid_t HTMLElement_iface_tids[] = {
1862 HTMLELEMENT_TIDS,
1866 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1867 NULL,
1868 HTMLElement_get_dispid,
1869 HTMLElement_invoke,
1870 HTMLElement_populate_props
1873 static dispex_static_data_t HTMLElement_dispex = {
1874 &HTMLElement_dispex_vtbl,
1875 DispHTMLUnknownElement_tid,
1876 NULL,
1877 HTMLElement_iface_tids
1880 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1882 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1884 HTMLElement2_Init(This);
1885 HTMLElement3_Init(This);
1887 if(dispex_data && !dispex_data->vtbl)
1888 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1889 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1890 dispex_data ? dispex_data : &HTMLElement_dispex);
1892 if(nselem) {
1893 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1895 /* No AddRef, share reference with HTMLDOMNode */
1896 assert((nsIDOMNode*)nselem == This->node.nsnode);
1897 This->nselem = nselem;
1900 This->node.cp_container = &This->cp_container;
1901 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface, This->node.vtbl->cpc_entries);
1904 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1906 nsIDOMHTMLElement *nselem;
1907 nsAString class_name_str;
1908 const PRUnichar *class_name;
1909 const tag_desc_t *tag;
1910 HTMLElement *elem;
1911 nsresult nsres;
1912 HRESULT hres;
1914 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1915 if(NS_FAILED(nsres))
1916 return E_FAIL;
1918 nsAString_Init(&class_name_str, NULL);
1919 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1921 nsAString_GetData(&class_name_str, &class_name);
1923 tag = get_tag_desc(class_name);
1924 if(tag) {
1925 hres = tag->constructor(doc, nselem, &elem);
1926 }else if(use_generic) {
1927 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1928 }else {
1929 elem = heap_alloc_zero(sizeof(HTMLElement));
1930 if(elem) {
1931 elem->node.vtbl = &HTMLElementImplVtbl;
1932 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1933 hres = S_OK;
1934 }else {
1935 hres = E_OUTOFMEMORY;
1939 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1941 nsIDOMHTMLElement_Release(nselem);
1942 nsAString_Finish(&class_name_str);
1943 if(FAILED(hres))
1944 return hres;
1946 *ret = elem;
1947 return S_OK;
1950 HRESULT get_elem(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **ret)
1952 HTMLDOMNode *node;
1953 HRESULT hres;
1955 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1956 if(FAILED(hres))
1957 return hres;
1959 *ret = impl_from_HTMLDOMNode(node);
1960 return S_OK;
1963 /* interface IHTMLFiltersCollection */
1964 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1966 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1968 TRACE("%p %s %p\n", This, debugstr_mshtml_guid(riid), ppv );
1970 if(IsEqualGUID(&IID_IUnknown, riid)) {
1971 *ppv = &This->IHTMLFiltersCollection_iface;
1972 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1973 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1974 *ppv = &This->IHTMLFiltersCollection_iface;
1975 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1976 return *ppv ? S_OK : E_NOINTERFACE;
1977 }else {
1978 *ppv = NULL;
1979 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
1980 return E_NOINTERFACE;
1983 IUnknown_AddRef((IUnknown*)*ppv);
1984 return S_OK;
1987 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1989 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1990 LONG ref = InterlockedIncrement(&This->ref);
1992 TRACE("(%p) ref=%d\n", This, ref);
1994 return ref;
1997 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1999 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2000 LONG ref = InterlockedDecrement(&This->ref);
2002 TRACE("(%p) ref=%d\n", This, ref);
2004 if(!ref)
2006 heap_free(This);
2009 return ref;
2012 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
2014 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2015 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2018 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
2019 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
2021 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2022 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2025 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
2026 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
2027 LCID lcid, DISPID *rgDispId)
2029 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2030 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2031 lcid, rgDispId);
2034 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
2035 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2036 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2038 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2039 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2040 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2043 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
2045 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2047 if(!p)
2048 return E_POINTER;
2050 FIXME("(%p)->(%p) Always returning 0\n", This, p);
2051 *p = 0;
2053 return S_OK;
2056 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
2058 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2059 FIXME("(%p)->(%p)\n", This, p);
2060 return E_NOTIMPL;
2063 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
2065 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2066 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2067 return E_NOTIMPL;
2070 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2071 HTMLFiltersCollection_QueryInterface,
2072 HTMLFiltersCollection_AddRef,
2073 HTMLFiltersCollection_Release,
2074 HTMLFiltersCollection_GetTypeInfoCount,
2075 HTMLFiltersCollection_GetTypeInfo,
2076 HTMLFiltersCollection_GetIDsOfNames,
2077 HTMLFiltersCollection_Invoke,
2078 HTMLFiltersCollection_get_length,
2079 HTMLFiltersCollection_get__newEnum,
2080 HTMLFiltersCollection_item
2083 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2085 WCHAR *ptr;
2086 int idx = 0;
2088 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2089 idx = idx*10 + (*ptr-'0');
2090 if(*ptr)
2091 return DISP_E_UNKNOWNNAME;
2093 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2094 TRACE("ret %x\n", *dispid);
2095 return S_OK;
2098 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2099 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2101 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2103 V_VT(res) = VT_DISPATCH;
2104 V_DISPATCH(res) = NULL;
2106 FIXME("always returning NULL\n");
2108 return S_OK;
2111 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2112 NULL,
2113 HTMLFiltersCollection_get_dispid,
2114 HTMLFiltersCollection_invoke,
2115 NULL
2118 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2119 IHTMLFiltersCollection_tid,
2122 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2123 &HTMLFiltersCollection_dispex_vtbl,
2124 IHTMLFiltersCollection_tid,
2125 NULL,
2126 HTMLFiltersCollection_iface_tids
2129 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2131 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2133 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2134 ret->ref = 1;
2136 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2137 &HTMLFiltersCollection_dispex);
2139 return &ret->IHTMLFiltersCollection_iface;
2142 /* interface IHTMLAttributeCollection */
2143 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2145 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2148 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2150 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2152 if(IsEqualGUID(&IID_IUnknown, riid)) {
2153 *ppv = &This->IHTMLAttributeCollection_iface;
2154 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2155 *ppv = &This->IHTMLAttributeCollection_iface;
2156 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2157 *ppv = &This->IHTMLAttributeCollection2_iface;
2158 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2159 *ppv = &This->IHTMLAttributeCollection3_iface;
2160 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2161 return *ppv ? S_OK : E_NOINTERFACE;
2162 }else {
2163 *ppv = NULL;
2164 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
2165 return E_NOINTERFACE;
2168 IUnknown_AddRef((IUnknown*)*ppv);
2169 return S_OK;
2172 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2174 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2175 LONG ref = InterlockedIncrement(&This->ref);
2177 TRACE("(%p) ref=%d\n", This, ref);
2179 return ref;
2182 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2184 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2185 LONG ref = InterlockedDecrement(&This->ref);
2187 TRACE("(%p) ref=%d\n", This, ref);
2189 if(!ref) {
2190 while(!list_empty(&This->attrs)) {
2191 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2193 list_remove(&attr->entry);
2194 attr->elem = NULL;
2195 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2198 heap_free(This);
2201 return ref;
2204 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2206 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2207 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2210 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2211 LCID lcid, ITypeInfo **ppTInfo)
2213 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2214 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2217 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2218 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2220 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2221 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2222 lcid, rgDispId);
2225 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2226 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2227 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2229 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2230 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2231 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2234 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2236 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2237 DISPID id = DISPID_STARTENUM;
2238 LONG len = -1;
2239 HRESULT hres;
2241 FIXME("filter non-enumerable attributes out\n");
2243 while(1) {
2244 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2245 if(FAILED(hres))
2246 return hres;
2247 else if(hres == S_FALSE)
2248 break;
2250 len++;
2251 if(len == *idx)
2252 break;
2255 if(dispid) {
2256 *dispid = id;
2257 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2260 *idx = len+1;
2261 return S_OK;
2264 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2266 HRESULT hres;
2268 if(name[0]>='0' && name[0]<='9') {
2269 WCHAR *end_ptr;
2270 LONG idx;
2272 idx = strtoulW(name, &end_ptr, 10);
2273 if(!*end_ptr) {
2274 hres = get_attr_dispid_by_idx(This, &idx, id);
2275 if(SUCCEEDED(hres))
2276 return hres;
2280 if(!This->elem) {
2281 WARN("NULL elem\n");
2282 return E_UNEXPECTED;
2285 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2286 name, fdexNameCaseInsensitive, id);
2287 return hres;
2290 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2292 HTMLDOMAttribute *iter;
2293 LONG pos = 0;
2294 HRESULT hres;
2296 *attr = NULL;
2297 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2298 if(iter->dispid == id) {
2299 *attr = iter;
2300 break;
2302 pos++;
2305 if(!*attr) {
2306 if(!This->elem) {
2307 WARN("NULL elem\n");
2308 return E_UNEXPECTED;
2311 hres = HTMLDOMAttribute_Create(NULL, This->elem, id, attr);
2312 if(FAILED(hres))
2313 return hres;
2316 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2317 if(list_pos)
2318 *list_pos = pos;
2319 return S_OK;
2322 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2324 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2325 HRESULT hres;
2327 TRACE("(%p)->(%p)\n", This, p);
2329 *p = -1;
2330 hres = get_attr_dispid_by_idx(This, p, NULL);
2331 return hres;
2334 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2336 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2337 FIXME("(%p)->(%p)\n", This, p);
2338 return E_NOTIMPL;
2341 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2343 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2344 HTMLDOMAttribute *attr;
2345 DISPID id;
2346 HRESULT hres;
2348 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2350 switch(V_VT(name)) {
2351 case VT_I4:
2352 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2353 break;
2354 case VT_BSTR:
2355 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2356 break;
2357 default:
2358 FIXME("unsupported name %s\n", debugstr_variant(name));
2359 hres = E_NOTIMPL;
2361 if(hres == DISP_E_UNKNOWNNAME)
2362 return E_INVALIDARG;
2363 if(FAILED(hres))
2364 return hres;
2366 hres = get_domattr(This, id, NULL, &attr);
2367 if(FAILED(hres))
2368 return hres;
2370 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2371 return S_OK;
2374 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2375 HTMLAttributeCollection_QueryInterface,
2376 HTMLAttributeCollection_AddRef,
2377 HTMLAttributeCollection_Release,
2378 HTMLAttributeCollection_GetTypeInfoCount,
2379 HTMLAttributeCollection_GetTypeInfo,
2380 HTMLAttributeCollection_GetIDsOfNames,
2381 HTMLAttributeCollection_Invoke,
2382 HTMLAttributeCollection_get_length,
2383 HTMLAttributeCollection__newEnum,
2384 HTMLAttributeCollection_item
2387 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2389 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2392 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2394 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2395 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2398 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2400 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2401 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2404 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2406 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2407 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2410 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2412 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2413 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2416 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2417 LCID lcid, ITypeInfo **ppTInfo)
2419 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2420 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2423 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2424 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2426 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2427 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2428 lcid, rgDispId);
2431 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2432 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2433 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2435 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2436 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2437 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2440 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2441 IHTMLDOMAttribute **newretNode)
2443 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2444 HTMLDOMAttribute *attr;
2445 DISPID id;
2446 HRESULT hres;
2448 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2450 hres = get_attr_dispid_by_name(This, bstrName, &id);
2451 if(hres == DISP_E_UNKNOWNNAME) {
2452 *newretNode = NULL;
2453 return S_OK;
2454 } else if(FAILED(hres)) {
2455 return hres;
2458 hres = get_domattr(This, id, NULL, &attr);
2459 if(FAILED(hres))
2460 return hres;
2462 *newretNode = &attr->IHTMLDOMAttribute_iface;
2463 return S_OK;
2466 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2467 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2469 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2470 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2471 return E_NOTIMPL;
2474 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2475 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2477 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2478 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2479 return E_NOTIMPL;
2482 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2483 HTMLAttributeCollection2_QueryInterface,
2484 HTMLAttributeCollection2_AddRef,
2485 HTMLAttributeCollection2_Release,
2486 HTMLAttributeCollection2_GetTypeInfoCount,
2487 HTMLAttributeCollection2_GetTypeInfo,
2488 HTMLAttributeCollection2_GetIDsOfNames,
2489 HTMLAttributeCollection2_Invoke,
2490 HTMLAttributeCollection2_getNamedItem,
2491 HTMLAttributeCollection2_setNamedItem,
2492 HTMLAttributeCollection2_removeNamedItem
2495 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2497 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2500 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2502 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2503 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2506 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2508 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2509 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2512 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2514 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2515 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2518 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2520 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2521 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2524 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2525 LCID lcid, ITypeInfo **ppTInfo)
2527 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2528 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2531 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2532 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2534 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2535 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2536 lcid, rgDispId);
2539 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2540 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2541 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2543 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2544 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2545 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2548 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2549 IHTMLDOMAttribute **ppNodeOut)
2551 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2552 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2555 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2556 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2558 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2559 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2560 return E_NOTIMPL;
2563 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2564 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2566 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2567 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2568 return E_NOTIMPL;
2571 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2573 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2574 HTMLDOMAttribute *attr;
2575 DISPID id;
2576 HRESULT hres;
2578 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2580 hres = get_attr_dispid_by_idx(This, &index, &id);
2581 if(hres == DISP_E_UNKNOWNNAME)
2582 return E_INVALIDARG;
2583 if(FAILED(hres))
2584 return hres;
2586 hres = get_domattr(This, id, NULL, &attr);
2587 if(FAILED(hres))
2588 return hres;
2590 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2591 return S_OK;
2594 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2596 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2597 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2600 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2601 HTMLAttributeCollection3_QueryInterface,
2602 HTMLAttributeCollection3_AddRef,
2603 HTMLAttributeCollection3_Release,
2604 HTMLAttributeCollection3_GetTypeInfoCount,
2605 HTMLAttributeCollection3_GetTypeInfo,
2606 HTMLAttributeCollection3_GetIDsOfNames,
2607 HTMLAttributeCollection3_Invoke,
2608 HTMLAttributeCollection3_getNamedItem,
2609 HTMLAttributeCollection3_setNamedItem,
2610 HTMLAttributeCollection3_removeNamedItem,
2611 HTMLAttributeCollection3_item,
2612 HTMLAttributeCollection3_get_length
2615 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2617 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2620 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2622 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2623 HTMLDOMAttribute *attr;
2624 LONG pos;
2625 HRESULT hres;
2627 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2629 hres = get_attr_dispid_by_name(This, name, dispid);
2630 if(FAILED(hres))
2631 return hres;
2633 hres = get_domattr(This, *dispid, &pos, &attr);
2634 if(FAILED(hres))
2635 return hres;
2636 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2638 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2639 return S_OK;
2642 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2643 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2645 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2647 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2649 switch(flags) {
2650 case DISPATCH_PROPERTYGET: {
2651 HTMLDOMAttribute *iter;
2652 DWORD pos;
2654 pos = id-MSHTML_DISPID_CUSTOM_MIN;
2656 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2657 if(!pos) {
2658 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2659 V_VT(res) = VT_DISPATCH;
2660 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2661 return S_OK;
2663 pos--;
2666 WARN("invalid arg\n");
2667 return E_INVALIDARG;
2670 default:
2671 FIXME("unimplemented flags %x\n", flags);
2672 return E_NOTIMPL;
2676 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2677 NULL,
2678 HTMLAttributeCollection_get_dispid,
2679 HTMLAttributeCollection_invoke,
2680 NULL
2683 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2684 IHTMLAttributeCollection_tid,
2685 IHTMLAttributeCollection2_tid,
2686 IHTMLAttributeCollection3_tid,
2690 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2691 &HTMLAttributeCollection_dispex_vtbl,
2692 DispHTMLAttributeCollection_tid,
2693 NULL,
2694 HTMLAttributeCollection_iface_tids
2697 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2699 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2701 if(This->attrs) {
2702 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2703 *ac = This->attrs;
2704 return S_OK;
2707 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2708 if(!This->attrs)
2709 return E_OUTOFMEMORY;
2711 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2712 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2713 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2714 This->attrs->ref = 2;
2716 This->attrs->elem = This;
2717 list_init(&This->attrs->attrs);
2718 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2719 &HTMLAttributeCollection_dispex);
2721 *ac = This->attrs;
2722 return S_OK;