jscript: Don't use builtin property for exposing ActiveXObject constructor.
[wine.git] / dlls / mshtml / htmlelem.c
blob7843ad6d91814b33775317a18aa2c2556f0ccd11
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 HRESULT get_readystate_string(READYSTATE readystate, BSTR *p)
223 static const WCHAR uninitializedW[] = {'u','n','i','n','i','t','i','a','l','i','z','e','d',0};
224 static const WCHAR loadingW[] = {'l','o','a','d','i','n','g',0};
225 static const WCHAR loadedW[] = {'l','o','a','d','e','d',0};
226 static const WCHAR interactiveW[] = {'i','n','t','e','r','a','c','t','i','v','e',0};
227 static const WCHAR completeW[] = {'c','o','m','p','l','e','t','e',0};
229 static const LPCWSTR readystate_strs[] = {
230 uninitializedW,
231 loadingW,
232 loadedW,
233 interactiveW,
234 completeW
237 assert(readystate <= READYSTATE_COMPLETE);
238 *p = SysAllocString(readystate_strs[readystate]);
239 return *p ? S_OK : E_OUTOFMEMORY;
242 typedef struct
244 DispatchEx dispex;
245 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
247 LONG ref;
248 } HTMLFiltersCollection;
250 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
252 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
255 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
257 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
259 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
262 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
264 nsIDOMElement *nselem;
265 nsAString tag_str;
266 nsresult nsres;
268 if(!doc->nsdoc) {
269 WARN("NULL nsdoc\n");
270 return E_UNEXPECTED;
273 nsAString_InitDepend(&tag_str, tag);
274 nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
275 nsAString_Finish(&tag_str);
276 if(NS_FAILED(nsres)) {
277 ERR("CreateElement failed: %08x\n", nsres);
278 return E_FAIL;
281 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
282 nsIDOMElement_Release(nselem);
283 if(NS_FAILED(nsres)) {
284 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
285 return E_FAIL;
288 return S_OK;
291 HRESULT create_element(HTMLDocumentNode *doc, const WCHAR *tag, HTMLElement **ret)
293 nsIDOMHTMLElement *nselem;
294 HRESULT hres;
296 /* Use owner doc if called on document fragment */
297 if(!doc->nsdoc)
298 doc = doc->node.doc;
300 hres = create_nselem(doc, tag, &nselem);
301 if(FAILED(hres))
302 return hres;
304 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, TRUE, ret);
305 nsIDOMHTMLElement_Release(nselem);
306 return hres;
309 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
310 REFIID riid, void **ppv)
312 HTMLElement *This = impl_from_IHTMLElement(iface);
314 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
317 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
319 HTMLElement *This = impl_from_IHTMLElement(iface);
321 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
324 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
326 HTMLElement *This = impl_from_IHTMLElement(iface);
328 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
331 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
333 HTMLElement *This = impl_from_IHTMLElement(iface);
334 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
337 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
338 LCID lcid, ITypeInfo **ppTInfo)
340 HTMLElement *This = impl_from_IHTMLElement(iface);
341 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
344 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
345 LPOLESTR *rgszNames, UINT cNames,
346 LCID lcid, DISPID *rgDispId)
348 HTMLElement *This = impl_from_IHTMLElement(iface);
349 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
350 lcid, rgDispId);
353 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
354 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
355 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
357 HTMLElement *This = impl_from_IHTMLElement(iface);
358 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
359 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
362 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
363 VARIANT AttributeValue, LONG lFlags)
365 HTMLElement *This = impl_from_IHTMLElement(iface);
366 HRESULT hres;
367 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
368 DISPPARAMS dispParams;
369 EXCEPINFO excep;
371 TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
373 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
374 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
375 if(FAILED(hres))
376 return hres;
378 dispParams.cArgs = 1;
379 dispParams.cNamedArgs = 1;
380 dispParams.rgdispidNamedArgs = &dispidNamed;
381 dispParams.rgvarg = &AttributeValue;
383 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
384 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
385 return hres;
388 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
389 LONG lFlags, VARIANT *AttributeValue)
391 HTMLElement *This = impl_from_IHTMLElement(iface);
392 DISPID dispid;
393 HRESULT hres;
394 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
395 EXCEPINFO excep;
397 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
399 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
400 fdexNameCaseInsensitive, &dispid);
401 if(hres == DISP_E_UNKNOWNNAME) {
402 V_VT(AttributeValue) = VT_NULL;
403 return S_OK;
406 if(FAILED(hres)) {
407 V_VT(AttributeValue) = VT_NULL;
408 return hres;
411 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
412 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
414 return hres;
417 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
418 LONG lFlags, VARIANT_BOOL *pfSuccess)
420 HTMLElement *This = impl_from_IHTMLElement(iface);
422 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
424 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
427 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
429 HTMLElement *This = impl_from_IHTMLElement(iface);
430 nsAString classname_str;
431 nsresult nsres;
433 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
435 if(!This->nselem) {
436 FIXME("NULL nselem\n");
437 return E_NOTIMPL;
440 nsAString_InitDepend(&classname_str, v);
441 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
442 nsAString_Finish(&classname_str);
443 if(NS_FAILED(nsres))
444 ERR("SetClassName failed: %08x\n", nsres);
446 return S_OK;
449 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
451 HTMLElement *This = impl_from_IHTMLElement(iface);
452 nsAString class_str;
453 nsresult nsres;
455 TRACE("(%p)->(%p)\n", This, p);
457 if(!This->nselem) {
458 FIXME("NULL nselem\n");
459 return E_NOTIMPL;
462 nsAString_Init(&class_str, NULL);
463 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
464 return return_nsstr(nsres, &class_str, p);
467 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
469 HTMLElement *This = impl_from_IHTMLElement(iface);
470 nsAString id_str;
471 nsresult nsres;
473 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
475 if(!This->nselem) {
476 FIXME("nselem == NULL\n");
477 return S_OK;
480 nsAString_InitDepend(&id_str, v);
481 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
482 nsAString_Finish(&id_str);
483 if(NS_FAILED(nsres))
484 ERR("SetId failed: %08x\n", nsres);
486 return S_OK;
489 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
491 HTMLElement *This = impl_from_IHTMLElement(iface);
492 nsAString id_str;
493 nsresult nsres;
495 TRACE("(%p)->(%p)\n", This, p);
497 if(!This->nselem) {
498 *p = NULL;
499 return S_OK;
502 nsAString_Init(&id_str, NULL);
503 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
504 return return_nsstr(nsres, &id_str, p);
507 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
509 HTMLElement *This = impl_from_IHTMLElement(iface);
510 nsAString tag_str;
511 nsresult nsres;
513 TRACE("(%p)->(%p)\n", This, p);
515 if(!This->nselem) {
516 static const WCHAR comment_tagW[] = {'!',0};
518 WARN("NULL nselem, assuming comment\n");
520 *p = SysAllocString(comment_tagW);
521 return *p ? S_OK : E_OUTOFMEMORY;
524 nsAString_Init(&tag_str, NULL);
525 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
526 return return_nsstr(nsres, &tag_str, p);
529 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
531 HTMLElement *This = impl_from_IHTMLElement(iface);
532 IHTMLDOMNode *node;
533 HRESULT hres;
535 TRACE("(%p)->(%p)\n", This, p);
537 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
538 if(FAILED(hres))
539 return hres;
541 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
542 IHTMLDOMNode_Release(node);
543 if(FAILED(hres))
544 *p = NULL;
546 return S_OK;
549 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
551 HTMLElement *This = impl_from_IHTMLElement(iface);
553 TRACE("(%p)->(%p)\n", This, p);
555 if(!This->style) {
556 HRESULT hres;
558 hres = HTMLStyle_Create(This, &This->style);
559 if(FAILED(hres))
560 return hres;
563 *p = &This->style->IHTMLStyle_iface;
564 IHTMLStyle_AddRef(*p);
565 return S_OK;
568 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
570 HTMLElement *This = impl_from_IHTMLElement(iface);
571 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
572 return E_NOTIMPL;
575 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
577 HTMLElement *This = impl_from_IHTMLElement(iface);
578 FIXME("(%p)->(%p)\n", This, p);
579 return E_NOTIMPL;
582 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
584 HTMLElement *This = impl_from_IHTMLElement(iface);
586 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
588 return set_node_event(&This->node, EVENTID_CLICK, &v);
591 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
593 HTMLElement *This = impl_from_IHTMLElement(iface);
595 TRACE("(%p)->(%p)\n", This, p);
597 return get_node_event(&This->node, EVENTID_CLICK, p);
600 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
602 HTMLElement *This = impl_from_IHTMLElement(iface);
604 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
606 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
609 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
611 HTMLElement *This = impl_from_IHTMLElement(iface);
613 TRACE("(%p)->(%p)\n", This, p);
615 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
618 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
620 HTMLElement *This = impl_from_IHTMLElement(iface);
622 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
624 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
627 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
629 HTMLElement *This = impl_from_IHTMLElement(iface);
631 TRACE("(%p)->(%p)\n", This, p);
633 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
636 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
638 HTMLElement *This = impl_from_IHTMLElement(iface);
640 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
642 return set_node_event(&This->node, EVENTID_KEYUP, &v);
645 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
647 HTMLElement *This = impl_from_IHTMLElement(iface);
648 FIXME("(%p)->(%p)\n", This, p);
649 return E_NOTIMPL;
652 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
654 HTMLElement *This = impl_from_IHTMLElement(iface);
656 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
658 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
661 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
663 HTMLElement *This = impl_from_IHTMLElement(iface);
665 TRACE("(%p)->(%p)\n", This, p);
667 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
670 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
672 HTMLElement *This = impl_from_IHTMLElement(iface);
674 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
676 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
679 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
681 HTMLElement *This = impl_from_IHTMLElement(iface);
683 TRACE("(%p)->(%p)\n", This, p);
685 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
688 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
690 HTMLElement *This = impl_from_IHTMLElement(iface);
692 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
694 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
697 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
699 HTMLElement *This = impl_from_IHTMLElement(iface);
701 TRACE("(%p)->(%p)\n", This, p);
703 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
706 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
708 HTMLElement *This = impl_from_IHTMLElement(iface);
710 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
712 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
715 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
717 HTMLElement *This = impl_from_IHTMLElement(iface);
719 TRACE("(%p)->(%p)\n", This, p);
721 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
724 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
726 HTMLElement *This = impl_from_IHTMLElement(iface);
728 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
730 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
733 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
735 HTMLElement *This = impl_from_IHTMLElement(iface);
737 TRACE("(%p)->(%p)\n", This, p);
739 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
742 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
744 HTMLElement *This = impl_from_IHTMLElement(iface);
746 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
748 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
751 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
753 HTMLElement *This = impl_from_IHTMLElement(iface);
755 TRACE("(%p)->(%p)\n", This, p);
757 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
760 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
762 HTMLElement *This = impl_from_IHTMLElement(iface);
764 TRACE("(%p)->(%p)\n", This, p);
766 if(!p)
767 return E_POINTER;
769 if(This->node.vtbl->get_document)
770 return This->node.vtbl->get_document(&This->node, p);
772 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
773 IDispatch_AddRef(*p);
774 return S_OK;
777 static const WCHAR titleW[] = {'t','i','t','l','e',0};
779 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
781 HTMLElement *This = impl_from_IHTMLElement(iface);
782 nsAString title_str;
783 nsresult nsres;
785 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
787 if(!This->nselem) {
788 VARIANT *var;
789 HRESULT hres;
791 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
792 if(FAILED(hres))
793 return hres;
795 VariantClear(var);
796 V_VT(var) = VT_BSTR;
797 V_BSTR(var) = v ? SysAllocString(v) : NULL;
798 return S_OK;
801 nsAString_InitDepend(&title_str, v);
802 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
803 nsAString_Finish(&title_str);
804 if(NS_FAILED(nsres))
805 ERR("SetTitle failed: %08x\n", nsres);
807 return S_OK;
810 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
812 HTMLElement *This = impl_from_IHTMLElement(iface);
813 nsAString title_str;
814 nsresult nsres;
816 TRACE("(%p)->(%p)\n", This, p);
818 if(!This->nselem) {
819 VARIANT *var;
820 HRESULT hres;
822 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
823 if(hres == DISP_E_UNKNOWNNAME) {
824 *p = NULL;
825 }else if(V_VT(var) != VT_BSTR) {
826 FIXME("title = %s\n", debugstr_variant(var));
827 return E_FAIL;
828 }else {
829 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
832 return S_OK;
835 nsAString_Init(&title_str, NULL);
836 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
837 return return_nsstr(nsres, &title_str, p);
840 static const WCHAR languageW[] = {'l','a','n','g','u','a','g','e',0};
842 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
844 HTMLElement *This = impl_from_IHTMLElement(iface);
846 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
848 return elem_string_attr_setter(This, languageW, v);
851 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
853 HTMLElement *This = impl_from_IHTMLElement(iface);
855 TRACE("(%p)->(%p)\n", This, p);
857 return elem_string_attr_getter(This, languageW, TRUE, p);
860 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
862 HTMLElement *This = impl_from_IHTMLElement(iface);
864 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
866 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
869 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
871 HTMLElement *This = impl_from_IHTMLElement(iface);
873 TRACE("(%p)->(%p)\n", This, p);
875 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
878 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
880 HTMLElement *This = impl_from_IHTMLElement(iface);
881 cpp_bool start = TRUE;
882 nsresult nsres;
884 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
886 switch(V_VT(&varargStart)) {
887 case VT_EMPTY:
888 case VT_ERROR:
889 break;
890 case VT_BOOL:
891 start = V_BOOL(&varargStart) != VARIANT_FALSE;
892 break;
893 default:
894 FIXME("Unsupported argument %s\n", debugstr_variant(&varargStart));
897 if(!This->nselem) {
898 FIXME("Unsupported for comments\n");
899 return E_NOTIMPL;
902 nsres = nsIDOMHTMLElement_ScrollIntoView(This->nselem, start, 1);
903 assert(nsres == NS_OK);
905 return S_OK;
908 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
909 VARIANT_BOOL *pfResult)
911 HTMLElement *This = impl_from_IHTMLElement(iface);
912 cpp_bool result = FALSE;
914 TRACE("(%p)->(%p %p)\n", This, pChild, pfResult);
916 if(pChild) {
917 HTMLElement *child;
918 nsresult nsres;
920 child = unsafe_impl_from_IHTMLElement(pChild);
921 if(!child) {
922 ERR("not our element\n");
923 return E_FAIL;
926 nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result);
927 assert(nsres == NS_OK);
930 *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE;
931 return S_OK;
934 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
936 HTMLElement *This = impl_from_IHTMLElement(iface);
938 TRACE("(%p)->(%p)\n", This, p);
940 return get_elem_source_index(This, p);
943 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
945 HTMLElement *This = impl_from_IHTMLElement(iface);
946 FIXME("(%p)->(%p)\n", This, p);
947 return E_NOTIMPL;
950 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
952 HTMLElement *This = impl_from_IHTMLElement(iface);
953 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
954 return E_NOTIMPL;
957 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
959 HTMLElement *This = impl_from_IHTMLElement(iface);
960 FIXME("(%p)->(%p)\n", This, p);
961 return E_NOTIMPL;
964 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
966 HTMLElement *This = impl_from_IHTMLElement(iface);
967 nsresult nsres;
969 TRACE("(%p)->(%p)\n", This, p);
971 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, p);
972 if(NS_FAILED(nsres)) {
973 ERR("GetOffsetLeft failed: %08x\n", nsres);
974 return E_FAIL;
977 return S_OK;
980 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
982 HTMLElement *This = impl_from_IHTMLElement(iface);
983 nsresult nsres;
985 TRACE("(%p)->(%p)\n", This, p);
987 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, p);
988 if(NS_FAILED(nsres)) {
989 ERR("GetOffsetTop failed: %08x\n", nsres);
990 return E_FAIL;
993 return S_OK;
996 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
998 HTMLElement *This = impl_from_IHTMLElement(iface);
999 nsresult nsres;
1001 TRACE("(%p)->(%p)\n", This, p);
1003 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, p);
1004 if(NS_FAILED(nsres)) {
1005 ERR("GetOffsetWidth failed: %08x\n", nsres);
1006 return E_FAIL;
1009 return S_OK;
1012 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
1014 HTMLElement *This = impl_from_IHTMLElement(iface);
1015 nsresult nsres;
1017 TRACE("(%p)->(%p)\n", This, p);
1019 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, p);
1020 if(NS_FAILED(nsres)) {
1021 ERR("GetOffsetHeight failed: %08x\n", nsres);
1022 return E_FAIL;
1025 return S_OK;
1028 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
1030 HTMLElement *This = impl_from_IHTMLElement(iface);
1031 nsIDOMElement *nsparent;
1032 nsresult nsres;
1033 HRESULT hres;
1035 TRACE("(%p)->(%p)\n", This, p);
1037 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
1038 if(NS_FAILED(nsres)) {
1039 ERR("GetOffsetParent failed: %08x\n", nsres);
1040 return E_FAIL;
1043 if(nsparent) {
1044 HTMLDOMNode *node;
1046 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
1047 nsIDOMElement_Release(nsparent);
1048 if(FAILED(hres))
1049 return hres;
1051 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
1052 node_release(node);
1053 }else {
1054 *p = NULL;
1055 hres = S_OK;
1058 return hres;
1061 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
1063 HTMLElement *This = impl_from_IHTMLElement(iface);
1064 nsAString html_str;
1065 nsresult nsres;
1067 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1069 if(!This->nselem) {
1070 FIXME("NULL nselem\n");
1071 return E_NOTIMPL;
1074 nsAString_InitDepend(&html_str, v);
1075 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
1076 nsAString_Finish(&html_str);
1077 if(NS_FAILED(nsres)) {
1078 FIXME("SetInnerHtml failed %08x\n", nsres);
1079 return E_FAIL;
1082 return S_OK;
1085 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1087 HTMLElement *This = impl_from_IHTMLElement(iface);
1088 nsAString html_str;
1089 nsresult nsres;
1091 TRACE("(%p)->(%p)\n", This, p);
1093 if(!This->nselem) {
1094 FIXME("NULL nselem\n");
1095 return E_NOTIMPL;
1098 nsAString_Init(&html_str, NULL);
1099 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
1100 return return_nsstr(nsres, &html_str, p);
1103 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1105 HTMLElement *This = impl_from_IHTMLElement(iface);
1106 nsIDOMNode *nschild, *tmp;
1107 nsIDOMText *text_node;
1108 nsAString text_str;
1109 nsresult nsres;
1111 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1113 while(1) {
1114 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1115 if(NS_FAILED(nsres)) {
1116 ERR("GetLastChild failed: %08x\n", nsres);
1117 return E_FAIL;
1119 if(!nschild)
1120 break;
1122 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1123 nsIDOMNode_Release(nschild);
1124 if(NS_FAILED(nsres)) {
1125 ERR("RemoveChild failed: %08x\n", nsres);
1126 return E_FAIL;
1128 nsIDOMNode_Release(tmp);
1131 nsAString_InitDepend(&text_str, v);
1132 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1133 nsAString_Finish(&text_str);
1134 if(NS_FAILED(nsres)) {
1135 ERR("CreateTextNode failed: %08x\n", nsres);
1136 return E_FAIL;
1139 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1140 if(NS_FAILED(nsres)) {
1141 ERR("AppendChild failed: %08x\n", nsres);
1142 return E_FAIL;
1145 nsIDOMNode_Release(tmp);
1146 return S_OK;
1149 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1151 HTMLElement *This = impl_from_IHTMLElement(iface);
1153 TRACE("(%p)->(%p)\n", This, p);
1155 return get_node_text(&This->node, p);
1158 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1160 HTMLElement *This = impl_from_IHTMLElement(iface);
1162 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1164 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1167 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1169 HTMLElement *This = impl_from_IHTMLElement(iface);
1170 nsAString html_str;
1171 HRESULT hres;
1173 WARN("(%p)->(%p) semi-stub\n", This, p);
1175 nsAString_Init(&html_str, NULL);
1176 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1177 if(SUCCEEDED(hres)) {
1178 const PRUnichar *html;
1180 nsAString_GetData(&html_str, &html);
1181 *p = SysAllocString(html);
1182 if(!*p)
1183 hres = E_OUTOFMEMORY;
1186 nsAString_Finish(&html_str);
1188 TRACE("ret %s\n", debugstr_w(*p));
1189 return hres;
1192 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1194 HTMLElement *This = impl_from_IHTMLElement(iface);
1195 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1196 return E_NOTIMPL;
1199 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1201 HTMLElement *This = impl_from_IHTMLElement(iface);
1202 FIXME("(%p)->(%p)\n", This, p);
1203 return E_NOTIMPL;
1206 HRESULT insert_adjacent_node(HTMLElement *This, const WCHAR *where, nsIDOMNode *nsnode, HTMLDOMNode **ret_node)
1208 nsIDOMNode *ret_nsnode;
1209 nsresult nsres;
1210 HRESULT hres = S_OK;
1212 static const WCHAR beforebeginW[] = {'b','e','f','o','r','e','b','e','g','i','n',0};
1213 static const WCHAR afterbeginW[] = {'a','f','t','e','r','b','e','g','i','n',0};
1214 static const WCHAR beforeendW[] = {'b','e','f','o','r','e','e','n','d',0};
1215 static const WCHAR afterendW[] = {'a','f','t','e','r','e','n','d',0};
1217 if (!strcmpiW(where, beforebeginW)) {
1218 nsIDOMNode *parent;
1220 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1221 if(NS_FAILED(nsres))
1222 return E_FAIL;
1224 if(!parent)
1225 return E_INVALIDARG;
1227 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &ret_nsnode);
1228 nsIDOMNode_Release(parent);
1229 }else if(!strcmpiW(where, afterbeginW)) {
1230 nsIDOMNode *first_child;
1232 nsres = nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1233 if(NS_FAILED(nsres))
1234 return E_FAIL;
1236 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &ret_nsnode);
1237 if(NS_FAILED(nsres))
1238 return E_FAIL;
1240 if (first_child)
1241 nsIDOMNode_Release(first_child);
1242 }else if (!strcmpiW(where, beforeendW)) {
1243 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &ret_nsnode);
1244 }else if (!strcmpiW(where, afterendW)) {
1245 nsIDOMNode *next_sibling, *parent;
1247 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1248 if(NS_FAILED(nsres))
1249 return E_FAIL;
1250 if(!parent)
1251 return E_INVALIDARG;
1253 nsres = nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1254 if(NS_SUCCEEDED(nsres)) {
1255 if(next_sibling) {
1256 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &ret_nsnode);
1257 nsIDOMNode_Release(next_sibling);
1258 }else {
1259 nsres = nsIDOMNode_AppendChild(parent, nsnode, &ret_nsnode);
1263 nsIDOMNode_Release(parent);
1264 }else {
1265 ERR("invalid where: %s\n", debugstr_w(where));
1266 return E_INVALIDARG;
1269 if (NS_FAILED(nsres))
1270 return E_FAIL;
1272 if(ret_node)
1273 hres = get_node(This->node.doc, ret_nsnode, TRUE, ret_node);
1274 nsIDOMNode_Release(ret_nsnode);
1275 return hres;
1278 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1279 BSTR html)
1281 HTMLElement *This = impl_from_IHTMLElement(iface);
1282 nsIDOMRange *range;
1283 nsIDOMNode *nsnode;
1284 nsAString ns_html;
1285 nsresult nsres;
1286 HRESULT hr;
1288 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1290 if(!This->node.doc->nsdoc) {
1291 WARN("NULL nsdoc\n");
1292 return E_UNEXPECTED;
1295 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1296 if(NS_FAILED(nsres))
1298 ERR("CreateRange failed: %08x\n", nsres);
1299 return E_FAIL;
1302 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1304 nsAString_InitDepend(&ns_html, html);
1305 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1306 nsAString_Finish(&ns_html);
1307 nsIDOMRange_Release(range);
1309 if(NS_FAILED(nsres) || !nsnode)
1311 ERR("CreateTextNode failed: %08x\n", nsres);
1312 return E_FAIL;
1315 hr = insert_adjacent_node(This, where, nsnode, NULL);
1316 nsIDOMNode_Release(nsnode);
1317 return hr;
1320 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1321 BSTR text)
1323 HTMLElement *This = impl_from_IHTMLElement(iface);
1324 nsIDOMNode *nsnode;
1325 nsAString ns_text;
1326 nsresult nsres;
1327 HRESULT hr;
1329 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1331 if(!This->node.doc->nsdoc) {
1332 WARN("NULL nsdoc\n");
1333 return E_UNEXPECTED;
1337 nsAString_InitDepend(&ns_text, text);
1338 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1339 nsAString_Finish(&ns_text);
1341 if(NS_FAILED(nsres) || !nsnode)
1343 ERR("CreateTextNode failed: %08x\n", nsres);
1344 return E_FAIL;
1347 hr = insert_adjacent_node(This, where, nsnode, NULL);
1348 nsIDOMNode_Release(nsnode);
1350 return hr;
1353 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1355 HTMLElement *This = impl_from_IHTMLElement(iface);
1356 FIXME("(%p)->(%p)\n", This, p);
1357 return E_NOTIMPL;
1360 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1362 HTMLElement *This = impl_from_IHTMLElement(iface);
1363 FIXME("(%p)->(%p)\n", This, p);
1364 return E_NOTIMPL;
1367 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1369 HTMLElement *This = impl_from_IHTMLElement(iface);
1371 TRACE("(%p)\n", This);
1373 return call_fire_event(&This->node, EVENTID_CLICK);
1376 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1377 IHTMLFiltersCollection **p)
1379 HTMLElement *This = impl_from_IHTMLElement(iface);
1380 TRACE("(%p)->(%p)\n", This, p);
1382 if(!p)
1383 return E_POINTER;
1385 *p = HTMLFiltersCollection_Create();
1387 return S_OK;
1390 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1392 HTMLElement *This = impl_from_IHTMLElement(iface);
1393 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1394 return E_NOTIMPL;
1397 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1399 HTMLElement *This = impl_from_IHTMLElement(iface);
1400 FIXME("(%p)->(%p)\n", This, p);
1401 return E_NOTIMPL;
1404 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1406 HTMLElement *This = impl_from_IHTMLElement(iface);
1407 FIXME("(%p)->(%p)\n", This, String);
1408 return E_NOTIMPL;
1411 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1413 HTMLElement *This = impl_from_IHTMLElement(iface);
1414 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1415 return E_NOTIMPL;
1418 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1420 HTMLElement *This = impl_from_IHTMLElement(iface);
1421 FIXME("(%p)->(%p)\n", This, p);
1422 return E_NOTIMPL;
1425 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1427 HTMLElement *This = impl_from_IHTMLElement(iface);
1428 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1429 return E_NOTIMPL;
1432 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1434 HTMLElement *This = impl_from_IHTMLElement(iface);
1435 FIXME("(%p)->(%p)\n", This, p);
1436 return E_NOTIMPL;
1439 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1441 HTMLElement *This = impl_from_IHTMLElement(iface);
1442 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1443 return E_NOTIMPL;
1446 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1448 HTMLElement *This = impl_from_IHTMLElement(iface);
1449 FIXME("(%p)->(%p)\n", This, p);
1450 return E_NOTIMPL;
1453 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1455 HTMLElement *This = impl_from_IHTMLElement(iface);
1456 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1457 return E_NOTIMPL;
1460 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1462 HTMLElement *This = impl_from_IHTMLElement(iface);
1463 FIXME("(%p)->(%p)\n", This, p);
1464 return E_NOTIMPL;
1467 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1469 HTMLElement *This = impl_from_IHTMLElement(iface);
1470 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1471 return E_NOTIMPL;
1474 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1476 HTMLElement *This = impl_from_IHTMLElement(iface);
1477 FIXME("(%p)->(%p)\n", This, p);
1478 return E_NOTIMPL;
1481 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1483 HTMLElement *This = impl_from_IHTMLElement(iface);
1484 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1485 return E_NOTIMPL;
1488 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1490 HTMLElement *This = impl_from_IHTMLElement(iface);
1491 FIXME("(%p)->(%p)\n", This, p);
1492 return E_NOTIMPL;
1495 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1497 HTMLElement *This = impl_from_IHTMLElement(iface);
1499 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1501 return set_node_event(&This->node, EVENTID_DATAAVAILABLE, &v);
1504 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1506 HTMLElement *This = impl_from_IHTMLElement(iface);
1508 TRACE("(%p)->(%p)\n", This, p);
1510 return get_node_event(&This->node, EVENTID_DATAAVAILABLE, p);
1513 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1515 HTMLElement *This = impl_from_IHTMLElement(iface);
1516 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1517 return E_NOTIMPL;
1520 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1522 HTMLElement *This = impl_from_IHTMLElement(iface);
1523 FIXME("(%p)->(%p)\n", This, p);
1524 return E_NOTIMPL;
1527 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1529 HTMLElement *This = impl_from_IHTMLElement(iface);
1530 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1531 return E_NOTIMPL;
1534 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1536 HTMLElement *This = impl_from_IHTMLElement(iface);
1537 FIXME("(%p)->(%p)\n", This, p);
1538 return E_NOTIMPL;
1541 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1543 HTMLElement *This = impl_from_IHTMLElement(iface);
1544 nsIDOMNodeList *nsnode_list;
1545 nsresult nsres;
1547 TRACE("(%p)->(%p)\n", This, p);
1549 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1550 if(NS_FAILED(nsres)) {
1551 ERR("GetChildNodes failed: %08x\n", nsres);
1552 return E_FAIL;
1555 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1557 nsIDOMNodeList_Release(nsnode_list);
1558 return S_OK;
1561 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1563 HTMLElement *This = impl_from_IHTMLElement(iface);
1565 TRACE("(%p)->(%p)\n", This, p);
1567 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1568 return S_OK;
1571 static const IHTMLElementVtbl HTMLElementVtbl = {
1572 HTMLElement_QueryInterface,
1573 HTMLElement_AddRef,
1574 HTMLElement_Release,
1575 HTMLElement_GetTypeInfoCount,
1576 HTMLElement_GetTypeInfo,
1577 HTMLElement_GetIDsOfNames,
1578 HTMLElement_Invoke,
1579 HTMLElement_setAttribute,
1580 HTMLElement_getAttribute,
1581 HTMLElement_removeAttribute,
1582 HTMLElement_put_className,
1583 HTMLElement_get_className,
1584 HTMLElement_put_id,
1585 HTMLElement_get_id,
1586 HTMLElement_get_tagName,
1587 HTMLElement_get_parentElement,
1588 HTMLElement_get_style,
1589 HTMLElement_put_onhelp,
1590 HTMLElement_get_onhelp,
1591 HTMLElement_put_onclick,
1592 HTMLElement_get_onclick,
1593 HTMLElement_put_ondblclick,
1594 HTMLElement_get_ondblclick,
1595 HTMLElement_put_onkeydown,
1596 HTMLElement_get_onkeydown,
1597 HTMLElement_put_onkeyup,
1598 HTMLElement_get_onkeyup,
1599 HTMLElement_put_onkeypress,
1600 HTMLElement_get_onkeypress,
1601 HTMLElement_put_onmouseout,
1602 HTMLElement_get_onmouseout,
1603 HTMLElement_put_onmouseover,
1604 HTMLElement_get_onmouseover,
1605 HTMLElement_put_onmousemove,
1606 HTMLElement_get_onmousemove,
1607 HTMLElement_put_onmousedown,
1608 HTMLElement_get_onmousedown,
1609 HTMLElement_put_onmouseup,
1610 HTMLElement_get_onmouseup,
1611 HTMLElement_get_document,
1612 HTMLElement_put_title,
1613 HTMLElement_get_title,
1614 HTMLElement_put_language,
1615 HTMLElement_get_language,
1616 HTMLElement_put_onselectstart,
1617 HTMLElement_get_onselectstart,
1618 HTMLElement_scrollIntoView,
1619 HTMLElement_contains,
1620 HTMLElement_get_sourceIndex,
1621 HTMLElement_get_recordNumber,
1622 HTMLElement_put_lang,
1623 HTMLElement_get_lang,
1624 HTMLElement_get_offsetLeft,
1625 HTMLElement_get_offsetTop,
1626 HTMLElement_get_offsetWidth,
1627 HTMLElement_get_offsetHeight,
1628 HTMLElement_get_offsetParent,
1629 HTMLElement_put_innerHTML,
1630 HTMLElement_get_innerHTML,
1631 HTMLElement_put_innerText,
1632 HTMLElement_get_innerText,
1633 HTMLElement_put_outerHTML,
1634 HTMLElement_get_outerHTML,
1635 HTMLElement_put_outerText,
1636 HTMLElement_get_outerText,
1637 HTMLElement_insertAdjacentHTML,
1638 HTMLElement_insertAdjacentText,
1639 HTMLElement_get_parentTextEdit,
1640 HTMLElement_get_isTextEdit,
1641 HTMLElement_click,
1642 HTMLElement_get_filters,
1643 HTMLElement_put_ondragstart,
1644 HTMLElement_get_ondragstart,
1645 HTMLElement_toString,
1646 HTMLElement_put_onbeforeupdate,
1647 HTMLElement_get_onbeforeupdate,
1648 HTMLElement_put_onafterupdate,
1649 HTMLElement_get_onafterupdate,
1650 HTMLElement_put_onerrorupdate,
1651 HTMLElement_get_onerrorupdate,
1652 HTMLElement_put_onrowexit,
1653 HTMLElement_get_onrowexit,
1654 HTMLElement_put_onrowenter,
1655 HTMLElement_get_onrowenter,
1656 HTMLElement_put_ondatasetchanged,
1657 HTMLElement_get_ondatasetchanged,
1658 HTMLElement_put_ondataavailable,
1659 HTMLElement_get_ondataavailable,
1660 HTMLElement_put_ondatasetcomplete,
1661 HTMLElement_get_ondatasetcomplete,
1662 HTMLElement_put_onfilterchange,
1663 HTMLElement_get_onfilterchange,
1664 HTMLElement_get_children,
1665 HTMLElement_get_all
1668 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1670 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1673 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1675 return CONTAINING_RECORD(iface, HTMLElement, node);
1678 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1680 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1682 if(IsEqualGUID(&IID_IUnknown, riid)) {
1683 *ppv = &This->IHTMLElement_iface;
1684 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1685 *ppv = &This->IHTMLElement_iface;
1686 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1687 *ppv = &This->IHTMLElement_iface;
1688 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1689 *ppv = &This->IHTMLElement2_iface;
1690 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1691 *ppv = &This->IHTMLElement3_iface;
1692 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1693 *ppv = &This->IHTMLElement4_iface;
1694 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1695 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1696 }else {
1697 return HTMLDOMNode_QI(&This->node, riid, ppv);
1700 IUnknown_AddRef((IUnknown*)*ppv);
1701 return S_OK;
1704 void HTMLElement_destructor(HTMLDOMNode *iface)
1706 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1708 ConnectionPointContainer_Destroy(&This->cp_container);
1710 if(This->style) {
1711 This->style->elem = NULL;
1712 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1714 if(This->runtime_style) {
1715 This->runtime_style->elem = NULL;
1716 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1718 if(This->attrs) {
1719 HTMLDOMAttribute *attr;
1721 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1722 attr->elem = NULL;
1724 This->attrs->elem = NULL;
1725 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1728 heap_free(This->filter);
1730 HTMLDOMNode_destructor(&This->node);
1733 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1735 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1736 HTMLElement *new_elem;
1737 HRESULT hres;
1739 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1740 if(FAILED(hres))
1741 return hres;
1743 if(This->filter) {
1744 new_elem->filter = heap_strdupW(This->filter);
1745 if(!new_elem->filter) {
1746 IHTMLElement_Release(&This->IHTMLElement_iface);
1747 return E_OUTOFMEMORY;
1751 *ret = &new_elem->node;
1752 return S_OK;
1755 HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *event, BOOL *prevent_default)
1757 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1759 switch(eid) {
1760 case EVENTID_KEYDOWN: {
1761 nsIDOMKeyEvent *key_event;
1762 nsresult nsres;
1764 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
1765 if(NS_SUCCEEDED(nsres)) {
1766 UINT32 code = 0;
1768 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
1770 switch(code) {
1771 case VK_F1: /* DOM_VK_F1 */
1772 TRACE("F1 pressed\n");
1773 fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL);
1774 *prevent_default = TRUE;
1777 nsIDOMKeyEvent_Release(key_event);
1782 return S_OK;
1785 cp_static_data_t HTMLElementEvents2_data = { HTMLElementEvents2_tid, NULL /* FIXME */, TRUE };
1787 const cpc_entry_t HTMLElement_cpc[] = {
1788 HTMLELEMENT_CPC,
1789 {NULL}
1792 static const NodeImplVtbl HTMLElementImplVtbl = {
1793 HTMLElement_QI,
1794 HTMLElement_destructor,
1795 HTMLElement_cpc,
1796 HTMLElement_clone,
1797 HTMLElement_handle_event,
1798 HTMLElement_get_attr_col
1801 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1803 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1806 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1807 DWORD grfdex, DISPID *pid)
1809 HTMLElement *This = impl_from_DispatchEx(dispex);
1811 if(This->node.vtbl->get_dispid)
1812 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1814 return DISP_E_UNKNOWNNAME;
1817 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1818 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1819 IServiceProvider *caller)
1821 HTMLElement *This = impl_from_DispatchEx(dispex);
1823 if(This->node.vtbl->invoke)
1824 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1825 params, res, ei, caller);
1827 ERR("(%p): element has no invoke method\n", This);
1828 return E_NOTIMPL;
1831 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1833 HTMLElement *This = impl_from_DispatchEx(dispex);
1834 nsIDOMMozNamedAttrMap *attrs;
1835 nsIDOMAttr *attr;
1836 nsAString nsstr;
1837 const PRUnichar *str;
1838 BSTR name;
1839 VARIANT value;
1840 unsigned i;
1841 UINT32 len;
1842 DISPID id;
1843 nsresult nsres;
1844 HRESULT hres;
1846 if(!This->nselem)
1847 return S_FALSE;
1849 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1850 if(NS_FAILED(nsres))
1851 return E_FAIL;
1853 nsres = nsIDOMMozNamedAttrMap_GetLength(attrs, &len);
1854 if(NS_FAILED(nsres)) {
1855 nsIDOMMozNamedAttrMap_Release(attrs);
1856 return E_FAIL;
1859 nsAString_Init(&nsstr, NULL);
1860 for(i=0; i<len; i++) {
1861 nsres = nsIDOMMozNamedAttrMap_Item(attrs, i, &attr);
1862 if(NS_FAILED(nsres))
1863 continue;
1865 nsres = nsIDOMAttr_GetNodeName(attr, &nsstr);
1866 if(NS_FAILED(nsres)) {
1867 nsIDOMAttr_Release(attr);
1868 continue;
1871 nsAString_GetData(&nsstr, &str);
1872 name = SysAllocString(str);
1873 if(!name) {
1874 nsIDOMAttr_Release(attr);
1875 continue;
1878 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1879 if(hres != DISP_E_UNKNOWNNAME) {
1880 nsIDOMAttr_Release(attr);
1881 SysFreeString(name);
1882 continue;
1885 nsres = nsIDOMAttr_GetNodeValue(attr, &nsstr);
1886 nsIDOMAttr_Release(attr);
1887 if(NS_FAILED(nsres)) {
1888 SysFreeString(name);
1889 continue;
1892 nsAString_GetData(&nsstr, &str);
1893 V_VT(&value) = VT_BSTR;
1894 if(*str) {
1895 V_BSTR(&value) = SysAllocString(str);
1896 if(!V_BSTR(&value)) {
1897 SysFreeString(name);
1898 continue;
1900 } else
1901 V_BSTR(&value) = NULL;
1903 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1904 SysFreeString(name);
1905 VariantClear(&value);
1907 nsAString_Finish(&nsstr);
1909 nsIDOMMozNamedAttrMap_Release(attrs);
1910 return S_OK;
1913 static const tid_t HTMLElement_iface_tids[] = {
1914 HTMLELEMENT_TIDS,
1918 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1919 NULL,
1920 HTMLElement_get_dispid,
1921 HTMLElement_invoke,
1922 HTMLElement_populate_props
1925 static dispex_static_data_t HTMLElement_dispex = {
1926 &HTMLElement_dispex_vtbl,
1927 DispHTMLUnknownElement_tid,
1928 NULL,
1929 HTMLElement_iface_tids
1932 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1934 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1936 HTMLElement2_Init(This);
1937 HTMLElement3_Init(This);
1939 if(dispex_data && !dispex_data->vtbl)
1940 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1941 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1942 dispex_data ? dispex_data : &HTMLElement_dispex);
1944 if(nselem) {
1945 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1947 /* No AddRef, share reference with HTMLDOMNode */
1948 assert((nsIDOMNode*)nselem == This->node.nsnode);
1949 This->nselem = nselem;
1952 This->node.cp_container = &This->cp_container;
1953 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface, This->node.vtbl->cpc_entries);
1956 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1958 nsIDOMHTMLElement *nselem;
1959 nsAString class_name_str;
1960 const PRUnichar *class_name;
1961 const tag_desc_t *tag;
1962 HTMLElement *elem;
1963 nsresult nsres;
1964 HRESULT hres;
1966 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1967 if(NS_FAILED(nsres))
1968 return E_FAIL;
1970 nsAString_Init(&class_name_str, NULL);
1971 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1973 nsAString_GetData(&class_name_str, &class_name);
1975 tag = get_tag_desc(class_name);
1976 if(tag) {
1977 hres = tag->constructor(doc, nselem, &elem);
1978 }else if(use_generic) {
1979 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1980 }else {
1981 elem = heap_alloc_zero(sizeof(HTMLElement));
1982 if(elem) {
1983 elem->node.vtbl = &HTMLElementImplVtbl;
1984 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1985 hres = S_OK;
1986 }else {
1987 hres = E_OUTOFMEMORY;
1991 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1993 nsIDOMHTMLElement_Release(nselem);
1994 nsAString_Finish(&class_name_str);
1995 if(FAILED(hres))
1996 return hres;
1998 *ret = elem;
1999 return S_OK;
2002 HRESULT get_elem(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **ret)
2004 HTMLDOMNode *node;
2005 HRESULT hres;
2007 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
2008 if(FAILED(hres))
2009 return hres;
2011 *ret = impl_from_HTMLDOMNode(node);
2012 return S_OK;
2015 /* interface IHTMLFiltersCollection */
2016 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
2018 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2020 TRACE("%p %s %p\n", This, debugstr_mshtml_guid(riid), ppv );
2022 if(IsEqualGUID(&IID_IUnknown, riid)) {
2023 *ppv = &This->IHTMLFiltersCollection_iface;
2024 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
2025 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
2026 *ppv = &This->IHTMLFiltersCollection_iface;
2027 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2028 return *ppv ? S_OK : E_NOINTERFACE;
2029 }else {
2030 *ppv = NULL;
2031 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
2032 return E_NOINTERFACE;
2035 IUnknown_AddRef((IUnknown*)*ppv);
2036 return S_OK;
2039 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
2041 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2042 LONG ref = InterlockedIncrement(&This->ref);
2044 TRACE("(%p) ref=%d\n", This, ref);
2046 return ref;
2049 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
2051 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2052 LONG ref = InterlockedDecrement(&This->ref);
2054 TRACE("(%p) ref=%d\n", This, ref);
2056 if(!ref)
2058 heap_free(This);
2061 return ref;
2064 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
2066 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2067 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2070 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
2071 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
2073 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2074 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2077 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
2078 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
2079 LCID lcid, DISPID *rgDispId)
2081 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2082 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2083 lcid, rgDispId);
2086 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
2087 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2088 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2090 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2091 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2092 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2095 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
2097 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2099 if(!p)
2100 return E_POINTER;
2102 FIXME("(%p)->(%p) Always returning 0\n", This, p);
2103 *p = 0;
2105 return S_OK;
2108 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
2110 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2111 FIXME("(%p)->(%p)\n", This, p);
2112 return E_NOTIMPL;
2115 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
2117 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2118 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2119 return E_NOTIMPL;
2122 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2123 HTMLFiltersCollection_QueryInterface,
2124 HTMLFiltersCollection_AddRef,
2125 HTMLFiltersCollection_Release,
2126 HTMLFiltersCollection_GetTypeInfoCount,
2127 HTMLFiltersCollection_GetTypeInfo,
2128 HTMLFiltersCollection_GetIDsOfNames,
2129 HTMLFiltersCollection_Invoke,
2130 HTMLFiltersCollection_get_length,
2131 HTMLFiltersCollection_get__newEnum,
2132 HTMLFiltersCollection_item
2135 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2137 WCHAR *ptr;
2138 int idx = 0;
2140 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2141 idx = idx*10 + (*ptr-'0');
2142 if(*ptr)
2143 return DISP_E_UNKNOWNNAME;
2145 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2146 TRACE("ret %x\n", *dispid);
2147 return S_OK;
2150 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2151 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2153 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2155 V_VT(res) = VT_DISPATCH;
2156 V_DISPATCH(res) = NULL;
2158 FIXME("always returning NULL\n");
2160 return S_OK;
2163 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2164 NULL,
2165 HTMLFiltersCollection_get_dispid,
2166 HTMLFiltersCollection_invoke,
2167 NULL
2170 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2171 IHTMLFiltersCollection_tid,
2174 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2175 &HTMLFiltersCollection_dispex_vtbl,
2176 IHTMLFiltersCollection_tid,
2177 NULL,
2178 HTMLFiltersCollection_iface_tids
2181 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2183 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2185 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2186 ret->ref = 1;
2188 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2189 &HTMLFiltersCollection_dispex);
2191 return &ret->IHTMLFiltersCollection_iface;
2194 /* interface IHTMLAttributeCollection */
2195 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2197 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2200 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2202 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2204 if(IsEqualGUID(&IID_IUnknown, riid)) {
2205 *ppv = &This->IHTMLAttributeCollection_iface;
2206 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2207 *ppv = &This->IHTMLAttributeCollection_iface;
2208 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2209 *ppv = &This->IHTMLAttributeCollection2_iface;
2210 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2211 *ppv = &This->IHTMLAttributeCollection3_iface;
2212 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2213 return *ppv ? S_OK : E_NOINTERFACE;
2214 }else {
2215 *ppv = NULL;
2216 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
2217 return E_NOINTERFACE;
2220 IUnknown_AddRef((IUnknown*)*ppv);
2221 return S_OK;
2224 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2226 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2227 LONG ref = InterlockedIncrement(&This->ref);
2229 TRACE("(%p) ref=%d\n", This, ref);
2231 return ref;
2234 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2236 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2237 LONG ref = InterlockedDecrement(&This->ref);
2239 TRACE("(%p) ref=%d\n", This, ref);
2241 if(!ref) {
2242 while(!list_empty(&This->attrs)) {
2243 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2245 list_remove(&attr->entry);
2246 attr->elem = NULL;
2247 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2250 heap_free(This);
2253 return ref;
2256 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2258 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2259 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2262 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2263 LCID lcid, ITypeInfo **ppTInfo)
2265 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2266 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2269 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2270 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2272 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2273 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2274 lcid, rgDispId);
2277 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2278 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2279 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2281 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2282 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2283 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2286 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2288 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2289 DISPID id = DISPID_STARTENUM;
2290 LONG len = -1;
2291 HRESULT hres;
2293 FIXME("filter non-enumerable attributes out\n");
2295 while(1) {
2296 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2297 if(FAILED(hres))
2298 return hres;
2299 else if(hres == S_FALSE)
2300 break;
2302 len++;
2303 if(len == *idx)
2304 break;
2307 if(dispid) {
2308 *dispid = id;
2309 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2312 *idx = len+1;
2313 return S_OK;
2316 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2318 HRESULT hres;
2320 if(name[0]>='0' && name[0]<='9') {
2321 WCHAR *end_ptr;
2322 LONG idx;
2324 idx = strtoulW(name, &end_ptr, 10);
2325 if(!*end_ptr) {
2326 hres = get_attr_dispid_by_idx(This, &idx, id);
2327 if(SUCCEEDED(hres))
2328 return hres;
2332 if(!This->elem) {
2333 WARN("NULL elem\n");
2334 return E_UNEXPECTED;
2337 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2338 name, fdexNameCaseInsensitive, id);
2339 return hres;
2342 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2344 HTMLDOMAttribute *iter;
2345 LONG pos = 0;
2346 HRESULT hres;
2348 *attr = NULL;
2349 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2350 if(iter->dispid == id) {
2351 *attr = iter;
2352 break;
2354 pos++;
2357 if(!*attr) {
2358 if(!This->elem) {
2359 WARN("NULL elem\n");
2360 return E_UNEXPECTED;
2363 hres = HTMLDOMAttribute_Create(NULL, This->elem, id, attr);
2364 if(FAILED(hres))
2365 return hres;
2368 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2369 if(list_pos)
2370 *list_pos = pos;
2371 return S_OK;
2374 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2376 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2377 HRESULT hres;
2379 TRACE("(%p)->(%p)\n", This, p);
2381 *p = -1;
2382 hres = get_attr_dispid_by_idx(This, p, NULL);
2383 return hres;
2386 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2388 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2389 FIXME("(%p)->(%p)\n", This, p);
2390 return E_NOTIMPL;
2393 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2395 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2396 HTMLDOMAttribute *attr;
2397 DISPID id;
2398 HRESULT hres;
2400 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2402 switch(V_VT(name)) {
2403 case VT_I4:
2404 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2405 break;
2406 case VT_BSTR:
2407 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2408 break;
2409 default:
2410 FIXME("unsupported name %s\n", debugstr_variant(name));
2411 hres = E_NOTIMPL;
2413 if(hres == DISP_E_UNKNOWNNAME)
2414 return E_INVALIDARG;
2415 if(FAILED(hres))
2416 return hres;
2418 hres = get_domattr(This, id, NULL, &attr);
2419 if(FAILED(hres))
2420 return hres;
2422 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2423 return S_OK;
2426 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2427 HTMLAttributeCollection_QueryInterface,
2428 HTMLAttributeCollection_AddRef,
2429 HTMLAttributeCollection_Release,
2430 HTMLAttributeCollection_GetTypeInfoCount,
2431 HTMLAttributeCollection_GetTypeInfo,
2432 HTMLAttributeCollection_GetIDsOfNames,
2433 HTMLAttributeCollection_Invoke,
2434 HTMLAttributeCollection_get_length,
2435 HTMLAttributeCollection__newEnum,
2436 HTMLAttributeCollection_item
2439 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2441 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2444 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2446 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2447 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2450 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2452 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2453 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2456 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2458 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2459 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2462 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2464 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2465 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2468 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2469 LCID lcid, ITypeInfo **ppTInfo)
2471 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2472 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2475 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2476 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2478 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2479 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2480 lcid, rgDispId);
2483 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2484 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2485 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2487 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2488 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2489 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2492 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2493 IHTMLDOMAttribute **newretNode)
2495 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2496 HTMLDOMAttribute *attr;
2497 DISPID id;
2498 HRESULT hres;
2500 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2502 hres = get_attr_dispid_by_name(This, bstrName, &id);
2503 if(hres == DISP_E_UNKNOWNNAME) {
2504 *newretNode = NULL;
2505 return S_OK;
2506 } else if(FAILED(hres)) {
2507 return hres;
2510 hres = get_domattr(This, id, NULL, &attr);
2511 if(FAILED(hres))
2512 return hres;
2514 *newretNode = &attr->IHTMLDOMAttribute_iface;
2515 return S_OK;
2518 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2519 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2521 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2522 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2523 return E_NOTIMPL;
2526 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2527 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2529 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2530 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2531 return E_NOTIMPL;
2534 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2535 HTMLAttributeCollection2_QueryInterface,
2536 HTMLAttributeCollection2_AddRef,
2537 HTMLAttributeCollection2_Release,
2538 HTMLAttributeCollection2_GetTypeInfoCount,
2539 HTMLAttributeCollection2_GetTypeInfo,
2540 HTMLAttributeCollection2_GetIDsOfNames,
2541 HTMLAttributeCollection2_Invoke,
2542 HTMLAttributeCollection2_getNamedItem,
2543 HTMLAttributeCollection2_setNamedItem,
2544 HTMLAttributeCollection2_removeNamedItem
2547 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2549 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2552 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2554 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2555 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2558 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2560 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2561 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2564 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2566 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2567 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2570 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2572 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2573 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2576 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2577 LCID lcid, ITypeInfo **ppTInfo)
2579 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2580 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2583 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2584 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2586 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2587 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2588 lcid, rgDispId);
2591 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2592 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2593 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2595 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2596 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2597 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2600 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2601 IHTMLDOMAttribute **ppNodeOut)
2603 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2604 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2607 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2608 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2610 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2611 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2612 return E_NOTIMPL;
2615 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2616 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2618 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2619 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2620 return E_NOTIMPL;
2623 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2625 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2626 HTMLDOMAttribute *attr;
2627 DISPID id;
2628 HRESULT hres;
2630 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2632 hres = get_attr_dispid_by_idx(This, &index, &id);
2633 if(hres == DISP_E_UNKNOWNNAME)
2634 return E_INVALIDARG;
2635 if(FAILED(hres))
2636 return hres;
2638 hres = get_domattr(This, id, NULL, &attr);
2639 if(FAILED(hres))
2640 return hres;
2642 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2643 return S_OK;
2646 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2648 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2649 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2652 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2653 HTMLAttributeCollection3_QueryInterface,
2654 HTMLAttributeCollection3_AddRef,
2655 HTMLAttributeCollection3_Release,
2656 HTMLAttributeCollection3_GetTypeInfoCount,
2657 HTMLAttributeCollection3_GetTypeInfo,
2658 HTMLAttributeCollection3_GetIDsOfNames,
2659 HTMLAttributeCollection3_Invoke,
2660 HTMLAttributeCollection3_getNamedItem,
2661 HTMLAttributeCollection3_setNamedItem,
2662 HTMLAttributeCollection3_removeNamedItem,
2663 HTMLAttributeCollection3_item,
2664 HTMLAttributeCollection3_get_length
2667 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2669 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2672 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2674 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2675 HTMLDOMAttribute *attr;
2676 LONG pos;
2677 HRESULT hres;
2679 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2681 hres = get_attr_dispid_by_name(This, name, dispid);
2682 if(FAILED(hres))
2683 return hres;
2685 hres = get_domattr(This, *dispid, &pos, &attr);
2686 if(FAILED(hres))
2687 return hres;
2688 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2690 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2691 return S_OK;
2694 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2695 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2697 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2699 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2701 switch(flags) {
2702 case DISPATCH_PROPERTYGET: {
2703 HTMLDOMAttribute *iter;
2704 DWORD pos;
2706 pos = id-MSHTML_DISPID_CUSTOM_MIN;
2708 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2709 if(!pos) {
2710 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2711 V_VT(res) = VT_DISPATCH;
2712 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2713 return S_OK;
2715 pos--;
2718 WARN("invalid arg\n");
2719 return E_INVALIDARG;
2722 default:
2723 FIXME("unimplemented flags %x\n", flags);
2724 return E_NOTIMPL;
2728 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2729 NULL,
2730 HTMLAttributeCollection_get_dispid,
2731 HTMLAttributeCollection_invoke,
2732 NULL
2735 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2736 IHTMLAttributeCollection_tid,
2737 IHTMLAttributeCollection2_tid,
2738 IHTMLAttributeCollection3_tid,
2742 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2743 &HTMLAttributeCollection_dispex_vtbl,
2744 DispHTMLAttributeCollection_tid,
2745 NULL,
2746 HTMLAttributeCollection_iface_tids
2749 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2751 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2753 if(This->attrs) {
2754 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2755 *ac = This->attrs;
2756 return S_OK;
2759 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2760 if(!This->attrs)
2761 return E_OUTOFMEMORY;
2763 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2764 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2765 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2766 This->attrs->ref = 2;
2768 This->attrs->elem = This;
2769 list_init(&This->attrs->attrs);
2770 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2771 &HTMLAttributeCollection_dispex);
2773 *ac = This->attrs;
2774 return S_OK;