kernel32/tests: Add additional tests for multithreaded partial reads from named pipes.
[wine/multimedia.git] / dlls / mshtml / htmlelem.c
blob363a89add07e1b26f3dee87831fb65ca29f6f89c
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 cpp_bool start = TRUE;
855 nsresult nsres;
857 TRACE("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
859 switch(V_VT(&varargStart)) {
860 case VT_EMPTY:
861 case VT_ERROR:
862 break;
863 case VT_BOOL:
864 start = V_BOOL(&varargStart) != VARIANT_FALSE;
865 break;
866 default:
867 FIXME("Unsupported argument %s\n", debugstr_variant(&varargStart));
870 if(!This->nselem) {
871 FIXME("Unsupported for comments\n");
872 return E_NOTIMPL;
875 nsres = nsIDOMHTMLElement_ScrollIntoView(This->nselem, start, 1);
876 assert(nsres == NS_OK);
878 return S_OK;
881 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
882 VARIANT_BOOL *pfResult)
884 HTMLElement *This = impl_from_IHTMLElement(iface);
885 cpp_bool result = FALSE;
887 TRACE("(%p)->(%p %p)\n", This, pChild, pfResult);
889 if(pChild) {
890 HTMLElement *child;
891 nsresult nsres;
893 child = unsafe_impl_from_IHTMLElement(pChild);
894 if(!child) {
895 ERR("not our element\n");
896 return E_FAIL;
899 nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result);
900 assert(nsres == NS_OK);
903 *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE;
904 return S_OK;
907 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
909 HTMLElement *This = impl_from_IHTMLElement(iface);
910 FIXME("(%p)->(%p)\n", This, p);
911 return E_NOTIMPL;
914 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
916 HTMLElement *This = impl_from_IHTMLElement(iface);
917 FIXME("(%p)->(%p)\n", This, p);
918 return E_NOTIMPL;
921 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
923 HTMLElement *This = impl_from_IHTMLElement(iface);
924 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
925 return E_NOTIMPL;
928 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
930 HTMLElement *This = impl_from_IHTMLElement(iface);
931 FIXME("(%p)->(%p)\n", This, p);
932 return E_NOTIMPL;
935 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
937 HTMLElement *This = impl_from_IHTMLElement(iface);
938 nsresult nsres;
940 TRACE("(%p)->(%p)\n", This, p);
942 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, p);
943 if(NS_FAILED(nsres)) {
944 ERR("GetOffsetLeft failed: %08x\n", nsres);
945 return E_FAIL;
948 return S_OK;
951 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
953 HTMLElement *This = impl_from_IHTMLElement(iface);
954 nsresult nsres;
956 TRACE("(%p)->(%p)\n", This, p);
958 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, p);
959 if(NS_FAILED(nsres)) {
960 ERR("GetOffsetTop failed: %08x\n", nsres);
961 return E_FAIL;
964 return S_OK;
967 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
969 HTMLElement *This = impl_from_IHTMLElement(iface);
970 nsresult nsres;
972 TRACE("(%p)->(%p)\n", This, p);
974 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, p);
975 if(NS_FAILED(nsres)) {
976 ERR("GetOffsetWidth failed: %08x\n", nsres);
977 return E_FAIL;
980 return S_OK;
983 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
985 HTMLElement *This = impl_from_IHTMLElement(iface);
986 nsresult nsres;
988 TRACE("(%p)->(%p)\n", This, p);
990 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, p);
991 if(NS_FAILED(nsres)) {
992 ERR("GetOffsetHeight failed: %08x\n", nsres);
993 return E_FAIL;
996 return S_OK;
999 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
1001 HTMLElement *This = impl_from_IHTMLElement(iface);
1002 nsIDOMElement *nsparent;
1003 nsresult nsres;
1004 HRESULT hres;
1006 TRACE("(%p)->(%p)\n", This, p);
1008 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
1009 if(NS_FAILED(nsres)) {
1010 ERR("GetOffsetParent failed: %08x\n", nsres);
1011 return E_FAIL;
1014 if(nsparent) {
1015 HTMLDOMNode *node;
1017 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
1018 nsIDOMElement_Release(nsparent);
1019 if(FAILED(hres))
1020 return hres;
1022 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
1023 node_release(node);
1024 }else {
1025 *p = NULL;
1026 hres = S_OK;
1029 return hres;
1032 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
1034 HTMLElement *This = impl_from_IHTMLElement(iface);
1035 nsAString html_str;
1036 nsresult nsres;
1038 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1040 if(!This->nselem) {
1041 FIXME("NULL nselem\n");
1042 return E_NOTIMPL;
1045 nsAString_InitDepend(&html_str, v);
1046 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
1047 nsAString_Finish(&html_str);
1048 if(NS_FAILED(nsres)) {
1049 FIXME("SetInnerHtml failed %08x\n", nsres);
1050 return E_FAIL;
1053 return S_OK;
1056 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
1058 HTMLElement *This = impl_from_IHTMLElement(iface);
1059 nsAString html_str;
1060 nsresult nsres;
1062 TRACE("(%p)->(%p)\n", This, p);
1064 if(!This->nselem) {
1065 FIXME("NULL nselem\n");
1066 return E_NOTIMPL;
1069 nsAString_Init(&html_str, NULL);
1070 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
1071 return return_nsstr(nsres, &html_str, p);
1074 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
1076 HTMLElement *This = impl_from_IHTMLElement(iface);
1077 nsIDOMNode *nschild, *tmp;
1078 nsIDOMText *text_node;
1079 nsAString text_str;
1080 nsresult nsres;
1082 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1084 while(1) {
1085 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
1086 if(NS_FAILED(nsres)) {
1087 ERR("GetLastChild failed: %08x\n", nsres);
1088 return E_FAIL;
1090 if(!nschild)
1091 break;
1093 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1094 nsIDOMNode_Release(nschild);
1095 if(NS_FAILED(nsres)) {
1096 ERR("RemoveChild failed: %08x\n", nsres);
1097 return E_FAIL;
1099 nsIDOMNode_Release(tmp);
1102 nsAString_InitDepend(&text_str, v);
1103 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1104 nsAString_Finish(&text_str);
1105 if(NS_FAILED(nsres)) {
1106 ERR("CreateTextNode failed: %08x\n", nsres);
1107 return E_FAIL;
1110 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1111 if(NS_FAILED(nsres)) {
1112 ERR("AppendChild failed: %08x\n", nsres);
1113 return E_FAIL;
1116 nsIDOMNode_Release(tmp);
1117 return S_OK;
1120 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1122 HTMLElement *This = impl_from_IHTMLElement(iface);
1124 TRACE("(%p)->(%p)\n", This, p);
1126 return get_node_text(&This->node, p);
1129 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1131 HTMLElement *This = impl_from_IHTMLElement(iface);
1133 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1135 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1138 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1140 HTMLElement *This = impl_from_IHTMLElement(iface);
1141 nsAString html_str;
1142 HRESULT hres;
1144 WARN("(%p)->(%p) semi-stub\n", This, p);
1146 nsAString_Init(&html_str, NULL);
1147 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1148 if(SUCCEEDED(hres)) {
1149 const PRUnichar *html;
1151 nsAString_GetData(&html_str, &html);
1152 *p = SysAllocString(html);
1153 if(!*p)
1154 hres = E_OUTOFMEMORY;
1157 nsAString_Finish(&html_str);
1159 TRACE("ret %s\n", debugstr_w(*p));
1160 return hres;
1163 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1165 HTMLElement *This = impl_from_IHTMLElement(iface);
1166 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1167 return E_NOTIMPL;
1170 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1172 HTMLElement *This = impl_from_IHTMLElement(iface);
1173 FIXME("(%p)->(%p)\n", This, p);
1174 return E_NOTIMPL;
1177 HRESULT insert_adjacent_node(HTMLElement *This, const WCHAR *where, nsIDOMNode *nsnode, HTMLDOMNode **ret_node)
1179 nsIDOMNode *ret_nsnode;
1180 nsresult nsres;
1181 HRESULT hres = S_OK;
1183 static const WCHAR beforebeginW[] = {'b','e','f','o','r','e','b','e','g','i','n',0};
1184 static const WCHAR afterbeginW[] = {'a','f','t','e','r','b','e','g','i','n',0};
1185 static const WCHAR beforeendW[] = {'b','e','f','o','r','e','e','n','d',0};
1186 static const WCHAR afterendW[] = {'a','f','t','e','r','e','n','d',0};
1188 if (!strcmpiW(where, beforebeginW)) {
1189 nsIDOMNode *parent;
1191 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1192 if(NS_FAILED(nsres))
1193 return E_FAIL;
1195 if(!parent)
1196 return E_INVALIDARG;
1198 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &ret_nsnode);
1199 nsIDOMNode_Release(parent);
1200 }else if(!strcmpiW(where, afterbeginW)) {
1201 nsIDOMNode *first_child;
1203 nsres = nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1204 if(NS_FAILED(nsres))
1205 return E_FAIL;
1207 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &ret_nsnode);
1208 if(NS_FAILED(nsres))
1209 return E_FAIL;
1211 if (first_child)
1212 nsIDOMNode_Release(first_child);
1213 }else if (!strcmpiW(where, beforeendW)) {
1214 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &ret_nsnode);
1215 }else if (!strcmpiW(where, afterendW)) {
1216 nsIDOMNode *next_sibling, *parent;
1218 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1219 if(NS_FAILED(nsres))
1220 return E_FAIL;
1221 if(!parent)
1222 return E_INVALIDARG;
1224 nsres = nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1225 if(NS_SUCCEEDED(nsres)) {
1226 if(next_sibling) {
1227 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &ret_nsnode);
1228 nsIDOMNode_Release(next_sibling);
1229 }else {
1230 nsres = nsIDOMNode_AppendChild(parent, nsnode, &ret_nsnode);
1234 nsIDOMNode_Release(parent);
1235 }else {
1236 ERR("invalid where: %s\n", debugstr_w(where));
1237 return E_INVALIDARG;
1240 if (NS_FAILED(nsres))
1241 return E_FAIL;
1243 if(ret_node)
1244 hres = get_node(This->node.doc, ret_nsnode, TRUE, ret_node);
1245 nsIDOMNode_Release(ret_nsnode);
1246 return hres;
1249 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1250 BSTR html)
1252 HTMLElement *This = impl_from_IHTMLElement(iface);
1253 nsIDOMRange *range;
1254 nsIDOMNode *nsnode;
1255 nsAString ns_html;
1256 nsresult nsres;
1257 HRESULT hr;
1259 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1261 if(!This->node.doc->nsdoc) {
1262 WARN("NULL nsdoc\n");
1263 return E_UNEXPECTED;
1266 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1267 if(NS_FAILED(nsres))
1269 ERR("CreateRange failed: %08x\n", nsres);
1270 return E_FAIL;
1273 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1275 nsAString_InitDepend(&ns_html, html);
1276 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1277 nsAString_Finish(&ns_html);
1278 nsIDOMRange_Release(range);
1280 if(NS_FAILED(nsres) || !nsnode)
1282 ERR("CreateTextNode failed: %08x\n", nsres);
1283 return E_FAIL;
1286 hr = insert_adjacent_node(This, where, nsnode, NULL);
1287 nsIDOMNode_Release(nsnode);
1288 return hr;
1291 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1292 BSTR text)
1294 HTMLElement *This = impl_from_IHTMLElement(iface);
1295 nsIDOMNode *nsnode;
1296 nsAString ns_text;
1297 nsresult nsres;
1298 HRESULT hr;
1300 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1302 if(!This->node.doc->nsdoc) {
1303 WARN("NULL nsdoc\n");
1304 return E_UNEXPECTED;
1308 nsAString_InitDepend(&ns_text, text);
1309 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1310 nsAString_Finish(&ns_text);
1312 if(NS_FAILED(nsres) || !nsnode)
1314 ERR("CreateTextNode failed: %08x\n", nsres);
1315 return E_FAIL;
1318 hr = insert_adjacent_node(This, where, nsnode, NULL);
1319 nsIDOMNode_Release(nsnode);
1321 return hr;
1324 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1326 HTMLElement *This = impl_from_IHTMLElement(iface);
1327 FIXME("(%p)->(%p)\n", This, p);
1328 return E_NOTIMPL;
1331 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1333 HTMLElement *This = impl_from_IHTMLElement(iface);
1334 FIXME("(%p)->(%p)\n", This, p);
1335 return E_NOTIMPL;
1338 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1340 HTMLElement *This = impl_from_IHTMLElement(iface);
1342 TRACE("(%p)\n", This);
1344 return call_fire_event(&This->node, EVENTID_CLICK);
1347 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1348 IHTMLFiltersCollection **p)
1350 HTMLElement *This = impl_from_IHTMLElement(iface);
1351 TRACE("(%p)->(%p)\n", This, p);
1353 if(!p)
1354 return E_POINTER;
1356 *p = HTMLFiltersCollection_Create();
1358 return S_OK;
1361 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1363 HTMLElement *This = impl_from_IHTMLElement(iface);
1364 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1365 return E_NOTIMPL;
1368 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1370 HTMLElement *This = impl_from_IHTMLElement(iface);
1371 FIXME("(%p)->(%p)\n", This, p);
1372 return E_NOTIMPL;
1375 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1377 HTMLElement *This = impl_from_IHTMLElement(iface);
1378 FIXME("(%p)->(%p)\n", This, String);
1379 return E_NOTIMPL;
1382 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1384 HTMLElement *This = impl_from_IHTMLElement(iface);
1385 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1386 return E_NOTIMPL;
1389 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1391 HTMLElement *This = impl_from_IHTMLElement(iface);
1392 FIXME("(%p)->(%p)\n", This, p);
1393 return E_NOTIMPL;
1396 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1398 HTMLElement *This = impl_from_IHTMLElement(iface);
1399 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1400 return E_NOTIMPL;
1403 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1405 HTMLElement *This = impl_from_IHTMLElement(iface);
1406 FIXME("(%p)->(%p)\n", This, p);
1407 return E_NOTIMPL;
1410 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1412 HTMLElement *This = impl_from_IHTMLElement(iface);
1413 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1414 return E_NOTIMPL;
1417 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1419 HTMLElement *This = impl_from_IHTMLElement(iface);
1420 FIXME("(%p)->(%p)\n", This, p);
1421 return E_NOTIMPL;
1424 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1426 HTMLElement *This = impl_from_IHTMLElement(iface);
1427 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1428 return E_NOTIMPL;
1431 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1433 HTMLElement *This = impl_from_IHTMLElement(iface);
1434 FIXME("(%p)->(%p)\n", This, p);
1435 return E_NOTIMPL;
1438 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1440 HTMLElement *This = impl_from_IHTMLElement(iface);
1441 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1442 return E_NOTIMPL;
1445 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1447 HTMLElement *This = impl_from_IHTMLElement(iface);
1448 FIXME("(%p)->(%p)\n", This, p);
1449 return E_NOTIMPL;
1452 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1454 HTMLElement *This = impl_from_IHTMLElement(iface);
1455 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1456 return E_NOTIMPL;
1459 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1461 HTMLElement *This = impl_from_IHTMLElement(iface);
1462 FIXME("(%p)->(%p)\n", This, p);
1463 return E_NOTIMPL;
1466 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1468 HTMLElement *This = impl_from_IHTMLElement(iface);
1470 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1472 return set_node_event(&This->node, EVENTID_DATAAVAILABLE, &v);
1475 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1477 HTMLElement *This = impl_from_IHTMLElement(iface);
1479 TRACE("(%p)->(%p)\n", This, p);
1481 return get_node_event(&This->node, EVENTID_DATAAVAILABLE, p);
1484 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1486 HTMLElement *This = impl_from_IHTMLElement(iface);
1487 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1488 return E_NOTIMPL;
1491 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1493 HTMLElement *This = impl_from_IHTMLElement(iface);
1494 FIXME("(%p)->(%p)\n", This, p);
1495 return E_NOTIMPL;
1498 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1500 HTMLElement *This = impl_from_IHTMLElement(iface);
1501 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1502 return E_NOTIMPL;
1505 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1507 HTMLElement *This = impl_from_IHTMLElement(iface);
1508 FIXME("(%p)->(%p)\n", This, p);
1509 return E_NOTIMPL;
1512 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1514 HTMLElement *This = impl_from_IHTMLElement(iface);
1515 nsIDOMNodeList *nsnode_list;
1516 nsresult nsres;
1518 TRACE("(%p)->(%p)\n", This, p);
1520 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1521 if(NS_FAILED(nsres)) {
1522 ERR("GetChildNodes failed: %08x\n", nsres);
1523 return E_FAIL;
1526 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1528 nsIDOMNodeList_Release(nsnode_list);
1529 return S_OK;
1532 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1534 HTMLElement *This = impl_from_IHTMLElement(iface);
1536 TRACE("(%p)->(%p)\n", This, p);
1538 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1539 return S_OK;
1542 static const IHTMLElementVtbl HTMLElementVtbl = {
1543 HTMLElement_QueryInterface,
1544 HTMLElement_AddRef,
1545 HTMLElement_Release,
1546 HTMLElement_GetTypeInfoCount,
1547 HTMLElement_GetTypeInfo,
1548 HTMLElement_GetIDsOfNames,
1549 HTMLElement_Invoke,
1550 HTMLElement_setAttribute,
1551 HTMLElement_getAttribute,
1552 HTMLElement_removeAttribute,
1553 HTMLElement_put_className,
1554 HTMLElement_get_className,
1555 HTMLElement_put_id,
1556 HTMLElement_get_id,
1557 HTMLElement_get_tagName,
1558 HTMLElement_get_parentElement,
1559 HTMLElement_get_style,
1560 HTMLElement_put_onhelp,
1561 HTMLElement_get_onhelp,
1562 HTMLElement_put_onclick,
1563 HTMLElement_get_onclick,
1564 HTMLElement_put_ondblclick,
1565 HTMLElement_get_ondblclick,
1566 HTMLElement_put_onkeydown,
1567 HTMLElement_get_onkeydown,
1568 HTMLElement_put_onkeyup,
1569 HTMLElement_get_onkeyup,
1570 HTMLElement_put_onkeypress,
1571 HTMLElement_get_onkeypress,
1572 HTMLElement_put_onmouseout,
1573 HTMLElement_get_onmouseout,
1574 HTMLElement_put_onmouseover,
1575 HTMLElement_get_onmouseover,
1576 HTMLElement_put_onmousemove,
1577 HTMLElement_get_onmousemove,
1578 HTMLElement_put_onmousedown,
1579 HTMLElement_get_onmousedown,
1580 HTMLElement_put_onmouseup,
1581 HTMLElement_get_onmouseup,
1582 HTMLElement_get_document,
1583 HTMLElement_put_title,
1584 HTMLElement_get_title,
1585 HTMLElement_put_language,
1586 HTMLElement_get_language,
1587 HTMLElement_put_onselectstart,
1588 HTMLElement_get_onselectstart,
1589 HTMLElement_scrollIntoView,
1590 HTMLElement_contains,
1591 HTMLElement_get_sourceIndex,
1592 HTMLElement_get_recordNumber,
1593 HTMLElement_put_lang,
1594 HTMLElement_get_lang,
1595 HTMLElement_get_offsetLeft,
1596 HTMLElement_get_offsetTop,
1597 HTMLElement_get_offsetWidth,
1598 HTMLElement_get_offsetHeight,
1599 HTMLElement_get_offsetParent,
1600 HTMLElement_put_innerHTML,
1601 HTMLElement_get_innerHTML,
1602 HTMLElement_put_innerText,
1603 HTMLElement_get_innerText,
1604 HTMLElement_put_outerHTML,
1605 HTMLElement_get_outerHTML,
1606 HTMLElement_put_outerText,
1607 HTMLElement_get_outerText,
1608 HTMLElement_insertAdjacentHTML,
1609 HTMLElement_insertAdjacentText,
1610 HTMLElement_get_parentTextEdit,
1611 HTMLElement_get_isTextEdit,
1612 HTMLElement_click,
1613 HTMLElement_get_filters,
1614 HTMLElement_put_ondragstart,
1615 HTMLElement_get_ondragstart,
1616 HTMLElement_toString,
1617 HTMLElement_put_onbeforeupdate,
1618 HTMLElement_get_onbeforeupdate,
1619 HTMLElement_put_onafterupdate,
1620 HTMLElement_get_onafterupdate,
1621 HTMLElement_put_onerrorupdate,
1622 HTMLElement_get_onerrorupdate,
1623 HTMLElement_put_onrowexit,
1624 HTMLElement_get_onrowexit,
1625 HTMLElement_put_onrowenter,
1626 HTMLElement_get_onrowenter,
1627 HTMLElement_put_ondatasetchanged,
1628 HTMLElement_get_ondatasetchanged,
1629 HTMLElement_put_ondataavailable,
1630 HTMLElement_get_ondataavailable,
1631 HTMLElement_put_ondatasetcomplete,
1632 HTMLElement_get_ondatasetcomplete,
1633 HTMLElement_put_onfilterchange,
1634 HTMLElement_get_onfilterchange,
1635 HTMLElement_get_children,
1636 HTMLElement_get_all
1639 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1641 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1644 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1646 return CONTAINING_RECORD(iface, HTMLElement, node);
1649 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1651 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1653 if(IsEqualGUID(&IID_IUnknown, riid)) {
1654 *ppv = &This->IHTMLElement_iface;
1655 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1656 *ppv = &This->IHTMLElement_iface;
1657 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1658 *ppv = &This->IHTMLElement_iface;
1659 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1660 *ppv = &This->IHTMLElement2_iface;
1661 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1662 *ppv = &This->IHTMLElement3_iface;
1663 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1664 *ppv = &This->IHTMLElement4_iface;
1665 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1666 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1667 }else {
1668 return HTMLDOMNode_QI(&This->node, riid, ppv);
1671 IUnknown_AddRef((IUnknown*)*ppv);
1672 return S_OK;
1675 void HTMLElement_destructor(HTMLDOMNode *iface)
1677 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1679 ConnectionPointContainer_Destroy(&This->cp_container);
1681 if(This->style) {
1682 This->style->elem = NULL;
1683 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1685 if(This->runtime_style) {
1686 This->runtime_style->elem = NULL;
1687 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1689 if(This->attrs) {
1690 HTMLDOMAttribute *attr;
1692 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1693 attr->elem = NULL;
1695 This->attrs->elem = NULL;
1696 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1699 heap_free(This->filter);
1701 HTMLDOMNode_destructor(&This->node);
1704 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1706 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1707 HTMLElement *new_elem;
1708 HRESULT hres;
1710 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1711 if(FAILED(hres))
1712 return hres;
1714 if(This->filter) {
1715 new_elem->filter = heap_strdupW(This->filter);
1716 if(!new_elem->filter) {
1717 IHTMLElement_Release(&This->IHTMLElement_iface);
1718 return E_OUTOFMEMORY;
1722 *ret = &new_elem->node;
1723 return S_OK;
1726 HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *event, BOOL *prevent_default)
1728 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1730 switch(eid) {
1731 case EVENTID_KEYDOWN: {
1732 nsIDOMKeyEvent *key_event;
1733 nsresult nsres;
1735 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
1736 if(NS_SUCCEEDED(nsres)) {
1737 UINT32 code = 0;
1739 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
1741 switch(code) {
1742 case VK_F1: /* DOM_VK_F1 */
1743 TRACE("F1 pressed\n");
1744 fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL);
1745 *prevent_default = TRUE;
1748 nsIDOMKeyEvent_Release(key_event);
1753 return S_OK;
1756 cp_static_data_t HTMLElementEvents2_data = { HTMLElementEvents2_tid, NULL /* FIXME */, TRUE };
1758 const cpc_entry_t HTMLElement_cpc[] = {
1759 HTMLELEMENT_CPC,
1760 {NULL}
1763 static const NodeImplVtbl HTMLElementImplVtbl = {
1764 HTMLElement_QI,
1765 HTMLElement_destructor,
1766 HTMLElement_cpc,
1767 HTMLElement_clone,
1768 HTMLElement_handle_event,
1769 HTMLElement_get_attr_col
1772 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1774 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1777 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1778 DWORD grfdex, DISPID *pid)
1780 HTMLElement *This = impl_from_DispatchEx(dispex);
1782 if(This->node.vtbl->get_dispid)
1783 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1785 return DISP_E_UNKNOWNNAME;
1788 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1789 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1790 IServiceProvider *caller)
1792 HTMLElement *This = impl_from_DispatchEx(dispex);
1794 if(This->node.vtbl->invoke)
1795 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1796 params, res, ei, caller);
1798 ERR("(%p): element has no invoke method\n", This);
1799 return E_NOTIMPL;
1802 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1804 HTMLElement *This = impl_from_DispatchEx(dispex);
1805 nsIDOMMozNamedAttrMap *attrs;
1806 nsIDOMAttr *attr;
1807 nsAString nsstr;
1808 const PRUnichar *str;
1809 BSTR name;
1810 VARIANT value;
1811 unsigned i;
1812 UINT32 len;
1813 DISPID id;
1814 nsresult nsres;
1815 HRESULT hres;
1817 if(!This->nselem)
1818 return S_FALSE;
1820 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1821 if(NS_FAILED(nsres))
1822 return E_FAIL;
1824 nsres = nsIDOMMozNamedAttrMap_GetLength(attrs, &len);
1825 if(NS_FAILED(nsres)) {
1826 nsIDOMMozNamedAttrMap_Release(attrs);
1827 return E_FAIL;
1830 nsAString_Init(&nsstr, NULL);
1831 for(i=0; i<len; i++) {
1832 nsres = nsIDOMMozNamedAttrMap_Item(attrs, i, &attr);
1833 if(NS_FAILED(nsres))
1834 continue;
1836 nsres = nsIDOMAttr_GetNodeName(attr, &nsstr);
1837 if(NS_FAILED(nsres)) {
1838 nsIDOMAttr_Release(attr);
1839 continue;
1842 nsAString_GetData(&nsstr, &str);
1843 name = SysAllocString(str);
1844 if(!name) {
1845 nsIDOMAttr_Release(attr);
1846 continue;
1849 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1850 if(hres != DISP_E_UNKNOWNNAME) {
1851 nsIDOMAttr_Release(attr);
1852 SysFreeString(name);
1853 continue;
1856 nsres = nsIDOMAttr_GetNodeValue(attr, &nsstr);
1857 nsIDOMAttr_Release(attr);
1858 if(NS_FAILED(nsres)) {
1859 SysFreeString(name);
1860 continue;
1863 nsAString_GetData(&nsstr, &str);
1864 V_VT(&value) = VT_BSTR;
1865 if(*str) {
1866 V_BSTR(&value) = SysAllocString(str);
1867 if(!V_BSTR(&value)) {
1868 SysFreeString(name);
1869 continue;
1871 } else
1872 V_BSTR(&value) = NULL;
1874 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1875 SysFreeString(name);
1876 VariantClear(&value);
1878 nsAString_Finish(&nsstr);
1880 nsIDOMMozNamedAttrMap_Release(attrs);
1881 return S_OK;
1884 static const tid_t HTMLElement_iface_tids[] = {
1885 HTMLELEMENT_TIDS,
1889 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1890 NULL,
1891 HTMLElement_get_dispid,
1892 HTMLElement_invoke,
1893 HTMLElement_populate_props
1896 static dispex_static_data_t HTMLElement_dispex = {
1897 &HTMLElement_dispex_vtbl,
1898 DispHTMLUnknownElement_tid,
1899 NULL,
1900 HTMLElement_iface_tids
1903 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1905 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1907 HTMLElement2_Init(This);
1908 HTMLElement3_Init(This);
1910 if(dispex_data && !dispex_data->vtbl)
1911 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1912 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1913 dispex_data ? dispex_data : &HTMLElement_dispex);
1915 if(nselem) {
1916 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1918 /* No AddRef, share reference with HTMLDOMNode */
1919 assert((nsIDOMNode*)nselem == This->node.nsnode);
1920 This->nselem = nselem;
1923 This->node.cp_container = &This->cp_container;
1924 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface, This->node.vtbl->cpc_entries);
1927 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1929 nsIDOMHTMLElement *nselem;
1930 nsAString class_name_str;
1931 const PRUnichar *class_name;
1932 const tag_desc_t *tag;
1933 HTMLElement *elem;
1934 nsresult nsres;
1935 HRESULT hres;
1937 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1938 if(NS_FAILED(nsres))
1939 return E_FAIL;
1941 nsAString_Init(&class_name_str, NULL);
1942 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1944 nsAString_GetData(&class_name_str, &class_name);
1946 tag = get_tag_desc(class_name);
1947 if(tag) {
1948 hres = tag->constructor(doc, nselem, &elem);
1949 }else if(use_generic) {
1950 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1951 }else {
1952 elem = heap_alloc_zero(sizeof(HTMLElement));
1953 if(elem) {
1954 elem->node.vtbl = &HTMLElementImplVtbl;
1955 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1956 hres = S_OK;
1957 }else {
1958 hres = E_OUTOFMEMORY;
1962 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1964 nsIDOMHTMLElement_Release(nselem);
1965 nsAString_Finish(&class_name_str);
1966 if(FAILED(hres))
1967 return hres;
1969 *ret = elem;
1970 return S_OK;
1973 HRESULT get_elem(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **ret)
1975 HTMLDOMNode *node;
1976 HRESULT hres;
1978 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1979 if(FAILED(hres))
1980 return hres;
1982 *ret = impl_from_HTMLDOMNode(node);
1983 return S_OK;
1986 /* interface IHTMLFiltersCollection */
1987 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1989 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1991 TRACE("%p %s %p\n", This, debugstr_mshtml_guid(riid), ppv );
1993 if(IsEqualGUID(&IID_IUnknown, riid)) {
1994 *ppv = &This->IHTMLFiltersCollection_iface;
1995 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1996 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1997 *ppv = &This->IHTMLFiltersCollection_iface;
1998 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1999 return *ppv ? S_OK : E_NOINTERFACE;
2000 }else {
2001 *ppv = NULL;
2002 FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
2003 return E_NOINTERFACE;
2006 IUnknown_AddRef((IUnknown*)*ppv);
2007 return S_OK;
2010 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
2012 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2013 LONG ref = InterlockedIncrement(&This->ref);
2015 TRACE("(%p) ref=%d\n", This, ref);
2017 return ref;
2020 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
2022 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2023 LONG ref = InterlockedDecrement(&This->ref);
2025 TRACE("(%p) ref=%d\n", This, ref);
2027 if(!ref)
2029 heap_free(This);
2032 return ref;
2035 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
2037 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2038 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2041 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
2042 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
2044 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2045 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2048 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
2049 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
2050 LCID lcid, DISPID *rgDispId)
2052 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2053 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2054 lcid, rgDispId);
2057 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
2058 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
2059 EXCEPINFO *pExcepInfo, UINT *puArgErr)
2061 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2062 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2063 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2066 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
2068 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2070 if(!p)
2071 return E_POINTER;
2073 FIXME("(%p)->(%p) Always returning 0\n", This, p);
2074 *p = 0;
2076 return S_OK;
2079 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
2081 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2082 FIXME("(%p)->(%p)\n", This, p);
2083 return E_NOTIMPL;
2086 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
2088 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2089 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2090 return E_NOTIMPL;
2093 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2094 HTMLFiltersCollection_QueryInterface,
2095 HTMLFiltersCollection_AddRef,
2096 HTMLFiltersCollection_Release,
2097 HTMLFiltersCollection_GetTypeInfoCount,
2098 HTMLFiltersCollection_GetTypeInfo,
2099 HTMLFiltersCollection_GetIDsOfNames,
2100 HTMLFiltersCollection_Invoke,
2101 HTMLFiltersCollection_get_length,
2102 HTMLFiltersCollection_get__newEnum,
2103 HTMLFiltersCollection_item
2106 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2108 WCHAR *ptr;
2109 int idx = 0;
2111 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2112 idx = idx*10 + (*ptr-'0');
2113 if(*ptr)
2114 return DISP_E_UNKNOWNNAME;
2116 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2117 TRACE("ret %x\n", *dispid);
2118 return S_OK;
2121 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2122 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2124 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2126 V_VT(res) = VT_DISPATCH;
2127 V_DISPATCH(res) = NULL;
2129 FIXME("always returning NULL\n");
2131 return S_OK;
2134 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2135 NULL,
2136 HTMLFiltersCollection_get_dispid,
2137 HTMLFiltersCollection_invoke,
2138 NULL
2141 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2142 IHTMLFiltersCollection_tid,
2145 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2146 &HTMLFiltersCollection_dispex_vtbl,
2147 IHTMLFiltersCollection_tid,
2148 NULL,
2149 HTMLFiltersCollection_iface_tids
2152 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2154 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2156 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2157 ret->ref = 1;
2159 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2160 &HTMLFiltersCollection_dispex);
2162 return &ret->IHTMLFiltersCollection_iface;
2165 /* interface IHTMLAttributeCollection */
2166 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2168 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2171 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2173 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2175 if(IsEqualGUID(&IID_IUnknown, riid)) {
2176 *ppv = &This->IHTMLAttributeCollection_iface;
2177 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2178 *ppv = &This->IHTMLAttributeCollection_iface;
2179 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2180 *ppv = &This->IHTMLAttributeCollection2_iface;
2181 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2182 *ppv = &This->IHTMLAttributeCollection3_iface;
2183 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2184 return *ppv ? S_OK : E_NOINTERFACE;
2185 }else {
2186 *ppv = NULL;
2187 WARN("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
2188 return E_NOINTERFACE;
2191 IUnknown_AddRef((IUnknown*)*ppv);
2192 return S_OK;
2195 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2197 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2198 LONG ref = InterlockedIncrement(&This->ref);
2200 TRACE("(%p) ref=%d\n", This, ref);
2202 return ref;
2205 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2207 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2208 LONG ref = InterlockedDecrement(&This->ref);
2210 TRACE("(%p) ref=%d\n", This, ref);
2212 if(!ref) {
2213 while(!list_empty(&This->attrs)) {
2214 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2216 list_remove(&attr->entry);
2217 attr->elem = NULL;
2218 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2221 heap_free(This);
2224 return ref;
2227 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2229 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2230 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2233 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2234 LCID lcid, ITypeInfo **ppTInfo)
2236 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2237 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2240 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2241 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2243 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2244 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2245 lcid, rgDispId);
2248 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2249 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2250 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2252 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2253 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2254 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2257 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2259 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2260 DISPID id = DISPID_STARTENUM;
2261 LONG len = -1;
2262 HRESULT hres;
2264 FIXME("filter non-enumerable attributes out\n");
2266 while(1) {
2267 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2268 if(FAILED(hres))
2269 return hres;
2270 else if(hres == S_FALSE)
2271 break;
2273 len++;
2274 if(len == *idx)
2275 break;
2278 if(dispid) {
2279 *dispid = id;
2280 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2283 *idx = len+1;
2284 return S_OK;
2287 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2289 HRESULT hres;
2291 if(name[0]>='0' && name[0]<='9') {
2292 WCHAR *end_ptr;
2293 LONG idx;
2295 idx = strtoulW(name, &end_ptr, 10);
2296 if(!*end_ptr) {
2297 hres = get_attr_dispid_by_idx(This, &idx, id);
2298 if(SUCCEEDED(hres))
2299 return hres;
2303 if(!This->elem) {
2304 WARN("NULL elem\n");
2305 return E_UNEXPECTED;
2308 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2309 name, fdexNameCaseInsensitive, id);
2310 return hres;
2313 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2315 HTMLDOMAttribute *iter;
2316 LONG pos = 0;
2317 HRESULT hres;
2319 *attr = NULL;
2320 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2321 if(iter->dispid == id) {
2322 *attr = iter;
2323 break;
2325 pos++;
2328 if(!*attr) {
2329 if(!This->elem) {
2330 WARN("NULL elem\n");
2331 return E_UNEXPECTED;
2334 hres = HTMLDOMAttribute_Create(NULL, This->elem, id, attr);
2335 if(FAILED(hres))
2336 return hres;
2339 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2340 if(list_pos)
2341 *list_pos = pos;
2342 return S_OK;
2345 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2347 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2348 HRESULT hres;
2350 TRACE("(%p)->(%p)\n", This, p);
2352 *p = -1;
2353 hres = get_attr_dispid_by_idx(This, p, NULL);
2354 return hres;
2357 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2359 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2360 FIXME("(%p)->(%p)\n", This, p);
2361 return E_NOTIMPL;
2364 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2366 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2367 HTMLDOMAttribute *attr;
2368 DISPID id;
2369 HRESULT hres;
2371 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2373 switch(V_VT(name)) {
2374 case VT_I4:
2375 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2376 break;
2377 case VT_BSTR:
2378 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2379 break;
2380 default:
2381 FIXME("unsupported name %s\n", debugstr_variant(name));
2382 hres = E_NOTIMPL;
2384 if(hres == DISP_E_UNKNOWNNAME)
2385 return E_INVALIDARG;
2386 if(FAILED(hres))
2387 return hres;
2389 hres = get_domattr(This, id, NULL, &attr);
2390 if(FAILED(hres))
2391 return hres;
2393 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2394 return S_OK;
2397 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2398 HTMLAttributeCollection_QueryInterface,
2399 HTMLAttributeCollection_AddRef,
2400 HTMLAttributeCollection_Release,
2401 HTMLAttributeCollection_GetTypeInfoCount,
2402 HTMLAttributeCollection_GetTypeInfo,
2403 HTMLAttributeCollection_GetIDsOfNames,
2404 HTMLAttributeCollection_Invoke,
2405 HTMLAttributeCollection_get_length,
2406 HTMLAttributeCollection__newEnum,
2407 HTMLAttributeCollection_item
2410 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2412 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2415 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2417 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2418 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2421 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2423 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2424 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2427 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2429 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2430 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2433 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2435 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2436 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2439 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2440 LCID lcid, ITypeInfo **ppTInfo)
2442 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2443 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2446 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2447 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2449 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2450 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2451 lcid, rgDispId);
2454 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2455 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2456 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2458 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2459 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2460 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2463 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2464 IHTMLDOMAttribute **newretNode)
2466 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2467 HTMLDOMAttribute *attr;
2468 DISPID id;
2469 HRESULT hres;
2471 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2473 hres = get_attr_dispid_by_name(This, bstrName, &id);
2474 if(hres == DISP_E_UNKNOWNNAME) {
2475 *newretNode = NULL;
2476 return S_OK;
2477 } else if(FAILED(hres)) {
2478 return hres;
2481 hres = get_domattr(This, id, NULL, &attr);
2482 if(FAILED(hres))
2483 return hres;
2485 *newretNode = &attr->IHTMLDOMAttribute_iface;
2486 return S_OK;
2489 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2490 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2492 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2493 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2494 return E_NOTIMPL;
2497 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2498 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2500 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2501 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2502 return E_NOTIMPL;
2505 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2506 HTMLAttributeCollection2_QueryInterface,
2507 HTMLAttributeCollection2_AddRef,
2508 HTMLAttributeCollection2_Release,
2509 HTMLAttributeCollection2_GetTypeInfoCount,
2510 HTMLAttributeCollection2_GetTypeInfo,
2511 HTMLAttributeCollection2_GetIDsOfNames,
2512 HTMLAttributeCollection2_Invoke,
2513 HTMLAttributeCollection2_getNamedItem,
2514 HTMLAttributeCollection2_setNamedItem,
2515 HTMLAttributeCollection2_removeNamedItem
2518 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2520 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2523 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2525 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2526 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2529 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2531 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2532 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2535 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2537 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2538 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2541 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2543 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2544 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2547 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2548 LCID lcid, ITypeInfo **ppTInfo)
2550 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2551 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2554 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2555 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2557 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2558 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2559 lcid, rgDispId);
2562 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2563 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2564 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2566 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2567 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2568 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2571 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2572 IHTMLDOMAttribute **ppNodeOut)
2574 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2575 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2578 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2579 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2581 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2582 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2583 return E_NOTIMPL;
2586 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2587 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2589 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2590 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2591 return E_NOTIMPL;
2594 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2596 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2597 HTMLDOMAttribute *attr;
2598 DISPID id;
2599 HRESULT hres;
2601 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2603 hres = get_attr_dispid_by_idx(This, &index, &id);
2604 if(hres == DISP_E_UNKNOWNNAME)
2605 return E_INVALIDARG;
2606 if(FAILED(hres))
2607 return hres;
2609 hres = get_domattr(This, id, NULL, &attr);
2610 if(FAILED(hres))
2611 return hres;
2613 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2614 return S_OK;
2617 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2619 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2620 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2623 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2624 HTMLAttributeCollection3_QueryInterface,
2625 HTMLAttributeCollection3_AddRef,
2626 HTMLAttributeCollection3_Release,
2627 HTMLAttributeCollection3_GetTypeInfoCount,
2628 HTMLAttributeCollection3_GetTypeInfo,
2629 HTMLAttributeCollection3_GetIDsOfNames,
2630 HTMLAttributeCollection3_Invoke,
2631 HTMLAttributeCollection3_getNamedItem,
2632 HTMLAttributeCollection3_setNamedItem,
2633 HTMLAttributeCollection3_removeNamedItem,
2634 HTMLAttributeCollection3_item,
2635 HTMLAttributeCollection3_get_length
2638 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2640 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2643 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2645 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2646 HTMLDOMAttribute *attr;
2647 LONG pos;
2648 HRESULT hres;
2650 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2652 hres = get_attr_dispid_by_name(This, name, dispid);
2653 if(FAILED(hres))
2654 return hres;
2656 hres = get_domattr(This, *dispid, &pos, &attr);
2657 if(FAILED(hres))
2658 return hres;
2659 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2661 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2662 return S_OK;
2665 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2666 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2668 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2670 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2672 switch(flags) {
2673 case DISPATCH_PROPERTYGET: {
2674 HTMLDOMAttribute *iter;
2675 DWORD pos;
2677 pos = id-MSHTML_DISPID_CUSTOM_MIN;
2679 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2680 if(!pos) {
2681 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2682 V_VT(res) = VT_DISPATCH;
2683 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2684 return S_OK;
2686 pos--;
2689 WARN("invalid arg\n");
2690 return E_INVALIDARG;
2693 default:
2694 FIXME("unimplemented flags %x\n", flags);
2695 return E_NOTIMPL;
2699 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2700 NULL,
2701 HTMLAttributeCollection_get_dispid,
2702 HTMLAttributeCollection_invoke,
2703 NULL
2706 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2707 IHTMLAttributeCollection_tid,
2708 IHTMLAttributeCollection2_tid,
2709 IHTMLAttributeCollection3_tid,
2713 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2714 &HTMLAttributeCollection_dispex_vtbl,
2715 DispHTMLAttributeCollection_tid,
2716 NULL,
2717 HTMLAttributeCollection_iface_tids
2720 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2722 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2724 if(This->attrs) {
2725 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2726 *ac = This->attrs;
2727 return S_OK;
2730 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2731 if(!This->attrs)
2732 return E_OUTOFMEMORY;
2734 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2735 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2736 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2737 This->attrs->ref = 2;
2739 This->attrs->elem = This;
2740 list_init(&This->attrs->attrs);
2741 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2742 &HTMLAttributeCollection_dispex);
2744 *ac = This->attrs;
2745 return S_OK;