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
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35 #include "htmlstyle.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR aW[] = {'A',0};
40 static const WCHAR bodyW[] = {'B','O','D','Y',0};
41 static const WCHAR embedW[] = {'E','M','B','E','D',0};
42 static const WCHAR formW[] = {'F','O','R','M',0};
43 static const WCHAR frameW[] = {'F','R','A','M','E',0};
44 static const WCHAR headW[] = {'H','E','A','D',0};
45 static const WCHAR iframeW[] = {'I','F','R','A','M','E',0};
46 static const WCHAR imgW[] = {'I','M','G',0};
47 static const WCHAR inputW[] = {'I','N','P','U','T',0};
48 static const WCHAR labelW[] = {'L','A','B','E','L',0};
49 static const WCHAR linkW[] = {'L','I','N','K',0};
50 static const WCHAR metaW[] = {'M','E','T','A',0};
51 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
52 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
53 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
54 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
55 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
56 static const WCHAR tableW[] = {'T','A','B','L','E',0};
57 static const WCHAR tdW[] = {'T','D',0};
58 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
59 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
60 static const WCHAR trW[] = {'T','R',0};
64 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
67 static const tag_desc_t tag_descs[] = {
68 {aW, HTMLAnchorElement_Create},
69 {bodyW, HTMLBodyElement_Create},
70 {embedW, HTMLEmbedElement_Create},
71 {formW, HTMLFormElement_Create},
72 {frameW, HTMLFrameElement_Create},
73 {headW, HTMLHeadElement_Create},
74 {iframeW, HTMLIFrame_Create},
75 {imgW, HTMLImgElement_Create},
76 {inputW, HTMLInputElement_Create},
77 {labelW, HTMLLabelElement_Create},
78 {linkW, HTMLLinkElement_Create},
79 {metaW, HTMLMetaElement_Create},
80 {objectW, HTMLObjectElement_Create},
81 {optionW, HTMLOptionElement_Create},
82 {scriptW, HTMLScriptElement_Create},
83 {selectW, HTMLSelectElement_Create},
84 {styleW, HTMLStyleElement_Create},
85 {tableW, HTMLTable_Create},
86 {tdW, HTMLTableCell_Create},
87 {textareaW, HTMLTextAreaElement_Create},
88 {title_tagW, HTMLTitleElement_Create},
89 {trW, HTMLTableRow_Create}
92 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
94 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
99 r = strcmpW(tag_name, tag_descs[i].name);
112 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
114 nsIDOMDocumentFragment *nsfragment;
115 nsIDOMNode *nsparent;
121 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
122 if(NS_FAILED(nsres)) {
123 ERR("CreateRange failed: %08x\n", nsres);
127 nsAString_InitDepend(&html_str, html);
128 nsIDOMRange_CreateContextualFragment(range, &html_str, &nsfragment);
129 nsIDOMRange_Release(range);
130 nsAString_Finish(&html_str);
131 if(NS_FAILED(nsres)) {
132 ERR("CreateContextualFragment failed: %08x\n", nsres);
136 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
137 if(NS_SUCCEEDED(nsres) && nsparent) {
140 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
141 nsIDOMNode_Release(nsparent);
142 if(NS_FAILED(nsres)) {
143 ERR("ReplaceChild failed: %08x\n", nsres);
146 nsIDOMNode_Release(nstmp);
149 ERR("GetParentNode failed: %08x\n", nsres);
153 nsIDOMDocumentFragment_Release(nsfragment);
160 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
163 } HTMLFiltersCollection;
165 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
167 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
170 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
172 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
174 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
177 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
179 nsIDOMElement *nselem;
184 WARN("NULL nsdoc\n");
188 nsAString_InitDepend(&tag_str, tag);
189 nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
190 nsAString_Finish(&tag_str);
191 if(NS_FAILED(nsres)) {
192 ERR("CreateElement failed: %08x\n", nsres);
196 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
197 nsIDOMElement_Release(nselem);
198 if(NS_FAILED(nsres)) {
199 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
206 HRESULT create_element(HTMLDocumentNode *doc, const WCHAR *tag, HTMLElement **ret)
208 nsIDOMHTMLElement *nselem;
211 /* Use owner doc if called on document fragment */
215 hres = create_nselem(doc, tag, &nselem);
219 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, TRUE, ret);
220 nsIDOMHTMLElement_Release(nselem);
224 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
225 REFIID riid, void **ppv)
227 HTMLElement *This = impl_from_IHTMLElement(iface);
229 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
232 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
234 HTMLElement *This = impl_from_IHTMLElement(iface);
236 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
239 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
241 HTMLElement *This = impl_from_IHTMLElement(iface);
243 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
246 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
248 HTMLElement *This = impl_from_IHTMLElement(iface);
249 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
252 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
253 LCID lcid, ITypeInfo **ppTInfo)
255 HTMLElement *This = impl_from_IHTMLElement(iface);
256 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
259 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
260 LPOLESTR *rgszNames, UINT cNames,
261 LCID lcid, DISPID *rgDispId)
263 HTMLElement *This = impl_from_IHTMLElement(iface);
264 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
268 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
269 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
270 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
272 HTMLElement *This = impl_from_IHTMLElement(iface);
273 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
274 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
277 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
278 VARIANT AttributeValue, LONG lFlags)
280 HTMLElement *This = impl_from_IHTMLElement(iface);
282 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
283 DISPPARAMS dispParams;
286 TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
288 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
289 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
293 dispParams.cArgs = 1;
294 dispParams.cNamedArgs = 1;
295 dispParams.rgdispidNamedArgs = &dispidNamed;
296 dispParams.rgvarg = &AttributeValue;
298 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
299 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
303 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
304 LONG lFlags, VARIANT *AttributeValue)
306 HTMLElement *This = impl_from_IHTMLElement(iface);
309 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
312 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
314 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
315 fdexNameCaseInsensitive, &dispid);
316 if(hres == DISP_E_UNKNOWNNAME) {
317 V_VT(AttributeValue) = VT_NULL;
322 V_VT(AttributeValue) = VT_NULL;
326 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
327 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
332 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
333 LONG lFlags, VARIANT_BOOL *pfSuccess)
335 HTMLElement *This = impl_from_IHTMLElement(iface);
337 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
339 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
342 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
344 HTMLElement *This = impl_from_IHTMLElement(iface);
345 nsAString classname_str;
348 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
351 FIXME("NULL nselem\n");
355 nsAString_InitDepend(&classname_str, v);
356 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
357 nsAString_Finish(&classname_str);
359 ERR("SetClassName failed: %08x\n", nsres);
364 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
366 HTMLElement *This = impl_from_IHTMLElement(iface);
370 TRACE("(%p)->(%p)\n", This, p);
373 FIXME("NULL nselem\n");
377 nsAString_Init(&class_str, NULL);
378 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
379 return return_nsstr(nsres, &class_str, p);
382 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
384 HTMLElement *This = impl_from_IHTMLElement(iface);
388 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
391 FIXME("nselem == NULL\n");
395 nsAString_InitDepend(&id_str, v);
396 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
397 nsAString_Finish(&id_str);
399 ERR("SetId failed: %08x\n", nsres);
404 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
406 HTMLElement *This = impl_from_IHTMLElement(iface);
410 TRACE("(%p)->(%p)\n", This, p);
417 nsAString_Init(&id_str, NULL);
418 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
419 return return_nsstr(nsres, &id_str, p);
422 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
424 HTMLElement *This = impl_from_IHTMLElement(iface);
428 TRACE("(%p)->(%p)\n", This, p);
431 static const WCHAR comment_tagW[] = {'!',0};
433 WARN("NULL nselem, assuming comment\n");
435 *p = SysAllocString(comment_tagW);
436 return *p ? S_OK : E_OUTOFMEMORY;
439 nsAString_Init(&tag_str, NULL);
440 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
441 return return_nsstr(nsres, &tag_str, p);
444 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
446 HTMLElement *This = impl_from_IHTMLElement(iface);
450 TRACE("(%p)->(%p)\n", This, p);
452 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
456 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
457 IHTMLDOMNode_Release(node);
464 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
466 HTMLElement *This = impl_from_IHTMLElement(iface);
468 TRACE("(%p)->(%p)\n", This, p);
473 hres = HTMLStyle_Create(This, &This->style);
478 *p = &This->style->IHTMLStyle_iface;
479 IHTMLStyle_AddRef(*p);
483 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
485 HTMLElement *This = impl_from_IHTMLElement(iface);
486 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
490 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
492 HTMLElement *This = impl_from_IHTMLElement(iface);
493 FIXME("(%p)->(%p)\n", This, p);
497 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
499 HTMLElement *This = impl_from_IHTMLElement(iface);
501 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
503 return set_node_event(&This->node, EVENTID_CLICK, &v);
506 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
508 HTMLElement *This = impl_from_IHTMLElement(iface);
510 TRACE("(%p)->(%p)\n", This, p);
512 return get_node_event(&This->node, EVENTID_CLICK, p);
515 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
517 HTMLElement *This = impl_from_IHTMLElement(iface);
519 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
521 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
524 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
526 HTMLElement *This = impl_from_IHTMLElement(iface);
528 TRACE("(%p)->(%p)\n", This, p);
530 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
533 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
535 HTMLElement *This = impl_from_IHTMLElement(iface);
537 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
539 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
542 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
544 HTMLElement *This = impl_from_IHTMLElement(iface);
546 TRACE("(%p)->(%p)\n", This, p);
548 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
551 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
553 HTMLElement *This = impl_from_IHTMLElement(iface);
555 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
557 return set_node_event(&This->node, EVENTID_KEYUP, &v);
560 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
562 HTMLElement *This = impl_from_IHTMLElement(iface);
563 FIXME("(%p)->(%p)\n", This, p);
567 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
569 HTMLElement *This = impl_from_IHTMLElement(iface);
571 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
573 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
576 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
578 HTMLElement *This = impl_from_IHTMLElement(iface);
580 TRACE("(%p)->(%p)\n", This, p);
582 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
585 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
587 HTMLElement *This = impl_from_IHTMLElement(iface);
589 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
591 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
594 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
596 HTMLElement *This = impl_from_IHTMLElement(iface);
598 TRACE("(%p)->(%p)\n", This, p);
600 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
603 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
605 HTMLElement *This = impl_from_IHTMLElement(iface);
607 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
609 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
612 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
614 HTMLElement *This = impl_from_IHTMLElement(iface);
616 TRACE("(%p)->(%p)\n", This, p);
618 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
621 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
623 HTMLElement *This = impl_from_IHTMLElement(iface);
625 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
627 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
630 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
632 HTMLElement *This = impl_from_IHTMLElement(iface);
634 TRACE("(%p)->(%p)\n", This, p);
636 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
639 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
641 HTMLElement *This = impl_from_IHTMLElement(iface);
643 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
645 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
648 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
650 HTMLElement *This = impl_from_IHTMLElement(iface);
652 TRACE("(%p)->(%p)\n", This, p);
654 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
657 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
659 HTMLElement *This = impl_from_IHTMLElement(iface);
661 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
663 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
666 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
668 HTMLElement *This = impl_from_IHTMLElement(iface);
670 TRACE("(%p)->(%p)\n", This, p);
672 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
675 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
677 HTMLElement *This = impl_from_IHTMLElement(iface);
679 TRACE("(%p)->(%p)\n", This, p);
684 if(This->node.vtbl->get_document)
685 return This->node.vtbl->get_document(&This->node, p);
687 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
688 IDispatch_AddRef(*p);
692 static const WCHAR titleW[] = {'t','i','t','l','e',0};
694 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
696 HTMLElement *This = impl_from_IHTMLElement(iface);
700 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
706 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
712 V_BSTR(var) = v ? SysAllocString(v) : NULL;
716 nsAString_InitDepend(&title_str, v);
717 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
718 nsAString_Finish(&title_str);
720 ERR("SetTitle failed: %08x\n", nsres);
725 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
727 HTMLElement *This = impl_from_IHTMLElement(iface);
731 TRACE("(%p)->(%p)\n", This, p);
737 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
738 if(hres == DISP_E_UNKNOWNNAME) {
740 }else if(V_VT(var) != VT_BSTR) {
741 FIXME("title = %s\n", debugstr_variant(var));
744 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
750 nsAString_Init(&title_str, NULL);
751 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
752 return return_nsstr(nsres, &title_str, p);
755 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
757 HTMLElement *This = impl_from_IHTMLElement(iface);
758 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
762 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
764 HTMLElement *This = impl_from_IHTMLElement(iface);
765 FIXME("(%p)->(%p)\n", This, p);
769 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
771 HTMLElement *This = impl_from_IHTMLElement(iface);
773 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
775 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
778 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
780 HTMLElement *This = impl_from_IHTMLElement(iface);
782 TRACE("(%p)->(%p)\n", This, p);
784 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
787 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
789 HTMLElement *This = impl_from_IHTMLElement(iface);
790 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
794 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
795 VARIANT_BOOL *pfResult)
797 HTMLElement *This = impl_from_IHTMLElement(iface);
802 TRACE("(%p)->(%p %p)\n", This, pChild, pfResult);
804 child = unsafe_impl_from_IHTMLElement(pChild);
806 ERR("not our element\n");
810 nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result);
811 if(NS_FAILED(nsres)) {
816 *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE;
820 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
822 HTMLElement *This = impl_from_IHTMLElement(iface);
823 FIXME("(%p)->(%p)\n", This, p);
827 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
829 HTMLElement *This = impl_from_IHTMLElement(iface);
830 FIXME("(%p)->(%p)\n", This, p);
834 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
836 HTMLElement *This = impl_from_IHTMLElement(iface);
837 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
841 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
843 HTMLElement *This = impl_from_IHTMLElement(iface);
844 FIXME("(%p)->(%p)\n", This, p);
848 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
850 HTMLElement *This = impl_from_IHTMLElement(iface);
853 TRACE("(%p)->(%p)\n", This, p);
855 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, p);
856 if(NS_FAILED(nsres)) {
857 ERR("GetOffsetLeft failed: %08x\n", nsres);
864 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
866 HTMLElement *This = impl_from_IHTMLElement(iface);
869 TRACE("(%p)->(%p)\n", This, p);
871 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, p);
872 if(NS_FAILED(nsres)) {
873 ERR("GetOffsetTop failed: %08x\n", nsres);
880 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
882 HTMLElement *This = impl_from_IHTMLElement(iface);
885 TRACE("(%p)->(%p)\n", This, p);
887 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, p);
888 if(NS_FAILED(nsres)) {
889 ERR("GetOffsetWidth failed: %08x\n", nsres);
896 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
898 HTMLElement *This = impl_from_IHTMLElement(iface);
901 TRACE("(%p)->(%p)\n", This, p);
903 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, p);
904 if(NS_FAILED(nsres)) {
905 ERR("GetOffsetHeight failed: %08x\n", nsres);
912 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
914 HTMLElement *This = impl_from_IHTMLElement(iface);
915 nsIDOMElement *nsparent;
919 TRACE("(%p)->(%p)\n", This, p);
921 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
922 if(NS_FAILED(nsres)) {
923 ERR("GetOffsetParent failed: %08x\n", nsres);
930 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
931 nsIDOMElement_Release(nsparent);
935 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
945 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
947 HTMLElement *This = impl_from_IHTMLElement(iface);
951 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
954 FIXME("NULL nselem\n");
958 nsAString_InitDepend(&html_str, v);
959 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
960 nsAString_Finish(&html_str);
961 if(NS_FAILED(nsres)) {
962 FIXME("SetInnerHtml failed %08x\n", nsres);
969 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
971 HTMLElement *This = impl_from_IHTMLElement(iface);
975 TRACE("(%p)->(%p)\n", This, p);
978 FIXME("NULL nselem\n");
982 nsAString_Init(&html_str, NULL);
983 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
984 return return_nsstr(nsres, &html_str, p);
987 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
989 HTMLElement *This = impl_from_IHTMLElement(iface);
990 nsIDOMNode *nschild, *tmp;
991 nsIDOMText *text_node;
995 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
998 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
999 if(NS_FAILED(nsres)) {
1000 ERR("GetLastChild failed: %08x\n", nsres);
1006 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
1007 nsIDOMNode_Release(nschild);
1008 if(NS_FAILED(nsres)) {
1009 ERR("RemoveChild failed: %08x\n", nsres);
1012 nsIDOMNode_Release(tmp);
1015 nsAString_InitDepend(&text_str, v);
1016 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1017 nsAString_Finish(&text_str);
1018 if(NS_FAILED(nsres)) {
1019 ERR("CreateTextNode failed: %08x\n", nsres);
1023 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1024 if(NS_FAILED(nsres)) {
1025 ERR("AppendChild failed: %08x\n", nsres);
1029 nsIDOMNode_Release(tmp);
1033 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1035 HTMLElement *This = impl_from_IHTMLElement(iface);
1037 TRACE("(%p)->(%p)\n", This, p);
1039 return get_node_text(&This->node, p);
1042 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1044 HTMLElement *This = impl_from_IHTMLElement(iface);
1046 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1048 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1051 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1053 HTMLElement *This = impl_from_IHTMLElement(iface);
1057 WARN("(%p)->(%p) semi-stub\n", This, p);
1059 nsAString_Init(&html_str, NULL);
1060 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1061 if(SUCCEEDED(hres)) {
1062 const PRUnichar *html;
1064 nsAString_GetData(&html_str, &html);
1065 *p = SysAllocString(html);
1067 hres = E_OUTOFMEMORY;
1070 nsAString_Finish(&html_str);
1072 TRACE("ret %s\n", debugstr_w(*p));
1076 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1078 HTMLElement *This = impl_from_IHTMLElement(iface);
1079 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1083 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1085 HTMLElement *This = impl_from_IHTMLElement(iface);
1086 FIXME("(%p)->(%p)\n", This, p);
1090 HRESULT insert_adjacent_node(HTMLElement *This, const WCHAR *where, nsIDOMNode *nsnode, HTMLDOMNode **ret_node)
1092 nsIDOMNode *ret_nsnode;
1094 HRESULT hres = S_OK;
1096 static const WCHAR beforebeginW[] = {'b','e','f','o','r','e','b','e','g','i','n',0};
1097 static const WCHAR afterbeginW[] = {'a','f','t','e','r','b','e','g','i','n',0};
1098 static const WCHAR beforeendW[] = {'b','e','f','o','r','e','e','n','d',0};
1099 static const WCHAR afterendW[] = {'a','f','t','e','r','e','n','d',0};
1101 if (!strcmpiW(where, beforebeginW)) {
1104 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1105 if(NS_FAILED(nsres))
1109 return E_INVALIDARG;
1111 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &ret_nsnode);
1112 nsIDOMNode_Release(parent);
1113 }else if(!strcmpiW(where, afterbeginW)) {
1114 nsIDOMNode *first_child;
1116 nsres = nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1117 if(NS_FAILED(nsres))
1120 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &ret_nsnode);
1121 if(NS_FAILED(nsres))
1125 nsIDOMNode_Release(first_child);
1126 }else if (!strcmpiW(where, beforeendW)) {
1127 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &ret_nsnode);
1128 }else if (!strcmpiW(where, afterendW)) {
1129 nsIDOMNode *next_sibling, *parent;
1131 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1132 if(NS_FAILED(nsres))
1135 return E_INVALIDARG;
1137 nsres = nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1138 if(NS_SUCCEEDED(nsres)) {
1140 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &ret_nsnode);
1141 nsIDOMNode_Release(next_sibling);
1143 nsres = nsIDOMNode_AppendChild(parent, nsnode, &ret_nsnode);
1147 nsIDOMNode_Release(parent);
1149 ERR("invalid where: %s\n", debugstr_w(where));
1150 return E_INVALIDARG;
1153 if (NS_FAILED(nsres))
1157 hres = get_node(This->node.doc, ret_nsnode, TRUE, ret_node);
1158 nsIDOMNode_Release(ret_nsnode);
1162 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1165 HTMLElement *This = impl_from_IHTMLElement(iface);
1172 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1174 if(!This->node.doc->nsdoc) {
1175 WARN("NULL nsdoc\n");
1176 return E_UNEXPECTED;
1179 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1180 if(NS_FAILED(nsres))
1182 ERR("CreateRange failed: %08x\n", nsres);
1186 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1188 nsAString_InitDepend(&ns_html, html);
1189 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1190 nsAString_Finish(&ns_html);
1191 nsIDOMRange_Release(range);
1193 if(NS_FAILED(nsres) || !nsnode)
1195 ERR("CreateTextNode failed: %08x\n", nsres);
1199 hr = insert_adjacent_node(This, where, nsnode, NULL);
1200 nsIDOMNode_Release(nsnode);
1204 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1207 HTMLElement *This = impl_from_IHTMLElement(iface);
1213 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1215 if(!This->node.doc->nsdoc) {
1216 WARN("NULL nsdoc\n");
1217 return E_UNEXPECTED;
1221 nsAString_InitDepend(&ns_text, text);
1222 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1223 nsAString_Finish(&ns_text);
1225 if(NS_FAILED(nsres) || !nsnode)
1227 ERR("CreateTextNode failed: %08x\n", nsres);
1231 hr = insert_adjacent_node(This, where, nsnode, NULL);
1232 nsIDOMNode_Release(nsnode);
1237 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1239 HTMLElement *This = impl_from_IHTMLElement(iface);
1240 FIXME("(%p)->(%p)\n", This, p);
1244 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1246 HTMLElement *This = impl_from_IHTMLElement(iface);
1247 FIXME("(%p)->(%p)\n", This, p);
1251 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1253 HTMLElement *This = impl_from_IHTMLElement(iface);
1255 TRACE("(%p)\n", This);
1257 return call_fire_event(&This->node, EVENTID_CLICK);
1260 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1261 IHTMLFiltersCollection **p)
1263 HTMLElement *This = impl_from_IHTMLElement(iface);
1264 TRACE("(%p)->(%p)\n", This, p);
1269 *p = HTMLFiltersCollection_Create();
1274 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1276 HTMLElement *This = impl_from_IHTMLElement(iface);
1277 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1281 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1283 HTMLElement *This = impl_from_IHTMLElement(iface);
1284 FIXME("(%p)->(%p)\n", This, p);
1288 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1290 HTMLElement *This = impl_from_IHTMLElement(iface);
1291 FIXME("(%p)->(%p)\n", This, String);
1295 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1297 HTMLElement *This = impl_from_IHTMLElement(iface);
1298 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1302 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1304 HTMLElement *This = impl_from_IHTMLElement(iface);
1305 FIXME("(%p)->(%p)\n", This, p);
1309 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1311 HTMLElement *This = impl_from_IHTMLElement(iface);
1312 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1316 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1318 HTMLElement *This = impl_from_IHTMLElement(iface);
1319 FIXME("(%p)->(%p)\n", This, p);
1323 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1325 HTMLElement *This = impl_from_IHTMLElement(iface);
1326 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1330 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1332 HTMLElement *This = impl_from_IHTMLElement(iface);
1333 FIXME("(%p)->(%p)\n", This, p);
1337 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1339 HTMLElement *This = impl_from_IHTMLElement(iface);
1340 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1344 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1346 HTMLElement *This = impl_from_IHTMLElement(iface);
1347 FIXME("(%p)->(%p)\n", This, p);
1351 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1353 HTMLElement *This = impl_from_IHTMLElement(iface);
1354 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1358 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1360 HTMLElement *This = impl_from_IHTMLElement(iface);
1361 FIXME("(%p)->(%p)\n", This, p);
1365 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1367 HTMLElement *This = impl_from_IHTMLElement(iface);
1368 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1372 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1374 HTMLElement *This = impl_from_IHTMLElement(iface);
1375 FIXME("(%p)->(%p)\n", This, p);
1379 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1381 HTMLElement *This = impl_from_IHTMLElement(iface);
1383 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1385 return set_node_event(&This->node, EVENTID_DATAAVAILABLE, &v);
1388 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1390 HTMLElement *This = impl_from_IHTMLElement(iface);
1392 TRACE("(%p)->(%p)\n", This, p);
1394 return get_node_event(&This->node, EVENTID_DATAAVAILABLE, p);
1397 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1399 HTMLElement *This = impl_from_IHTMLElement(iface);
1400 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1404 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1406 HTMLElement *This = impl_from_IHTMLElement(iface);
1407 FIXME("(%p)->(%p)\n", This, p);
1411 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1413 HTMLElement *This = impl_from_IHTMLElement(iface);
1414 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1418 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1420 HTMLElement *This = impl_from_IHTMLElement(iface);
1421 FIXME("(%p)->(%p)\n", This, p);
1425 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1427 HTMLElement *This = impl_from_IHTMLElement(iface);
1428 nsIDOMNodeList *nsnode_list;
1431 TRACE("(%p)->(%p)\n", This, p);
1433 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1434 if(NS_FAILED(nsres)) {
1435 ERR("GetChildNodes failed: %08x\n", nsres);
1439 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1441 nsIDOMNodeList_Release(nsnode_list);
1445 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1447 HTMLElement *This = impl_from_IHTMLElement(iface);
1449 TRACE("(%p)->(%p)\n", This, p);
1451 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1455 static const IHTMLElementVtbl HTMLElementVtbl = {
1456 HTMLElement_QueryInterface,
1458 HTMLElement_Release,
1459 HTMLElement_GetTypeInfoCount,
1460 HTMLElement_GetTypeInfo,
1461 HTMLElement_GetIDsOfNames,
1463 HTMLElement_setAttribute,
1464 HTMLElement_getAttribute,
1465 HTMLElement_removeAttribute,
1466 HTMLElement_put_className,
1467 HTMLElement_get_className,
1470 HTMLElement_get_tagName,
1471 HTMLElement_get_parentElement,
1472 HTMLElement_get_style,
1473 HTMLElement_put_onhelp,
1474 HTMLElement_get_onhelp,
1475 HTMLElement_put_onclick,
1476 HTMLElement_get_onclick,
1477 HTMLElement_put_ondblclick,
1478 HTMLElement_get_ondblclick,
1479 HTMLElement_put_onkeydown,
1480 HTMLElement_get_onkeydown,
1481 HTMLElement_put_onkeyup,
1482 HTMLElement_get_onkeyup,
1483 HTMLElement_put_onkeypress,
1484 HTMLElement_get_onkeypress,
1485 HTMLElement_put_onmouseout,
1486 HTMLElement_get_onmouseout,
1487 HTMLElement_put_onmouseover,
1488 HTMLElement_get_onmouseover,
1489 HTMLElement_put_onmousemove,
1490 HTMLElement_get_onmousemove,
1491 HTMLElement_put_onmousedown,
1492 HTMLElement_get_onmousedown,
1493 HTMLElement_put_onmouseup,
1494 HTMLElement_get_onmouseup,
1495 HTMLElement_get_document,
1496 HTMLElement_put_title,
1497 HTMLElement_get_title,
1498 HTMLElement_put_language,
1499 HTMLElement_get_language,
1500 HTMLElement_put_onselectstart,
1501 HTMLElement_get_onselectstart,
1502 HTMLElement_scrollIntoView,
1503 HTMLElement_contains,
1504 HTMLElement_get_sourceIndex,
1505 HTMLElement_get_recordNumber,
1506 HTMLElement_put_lang,
1507 HTMLElement_get_lang,
1508 HTMLElement_get_offsetLeft,
1509 HTMLElement_get_offsetTop,
1510 HTMLElement_get_offsetWidth,
1511 HTMLElement_get_offsetHeight,
1512 HTMLElement_get_offsetParent,
1513 HTMLElement_put_innerHTML,
1514 HTMLElement_get_innerHTML,
1515 HTMLElement_put_innerText,
1516 HTMLElement_get_innerText,
1517 HTMLElement_put_outerHTML,
1518 HTMLElement_get_outerHTML,
1519 HTMLElement_put_outerText,
1520 HTMLElement_get_outerText,
1521 HTMLElement_insertAdjacentHTML,
1522 HTMLElement_insertAdjacentText,
1523 HTMLElement_get_parentTextEdit,
1524 HTMLElement_get_isTextEdit,
1526 HTMLElement_get_filters,
1527 HTMLElement_put_ondragstart,
1528 HTMLElement_get_ondragstart,
1529 HTMLElement_toString,
1530 HTMLElement_put_onbeforeupdate,
1531 HTMLElement_get_onbeforeupdate,
1532 HTMLElement_put_onafterupdate,
1533 HTMLElement_get_onafterupdate,
1534 HTMLElement_put_onerrorupdate,
1535 HTMLElement_get_onerrorupdate,
1536 HTMLElement_put_onrowexit,
1537 HTMLElement_get_onrowexit,
1538 HTMLElement_put_onrowenter,
1539 HTMLElement_get_onrowenter,
1540 HTMLElement_put_ondatasetchanged,
1541 HTMLElement_get_ondatasetchanged,
1542 HTMLElement_put_ondataavailable,
1543 HTMLElement_get_ondataavailable,
1544 HTMLElement_put_ondatasetcomplete,
1545 HTMLElement_get_ondatasetcomplete,
1546 HTMLElement_put_onfilterchange,
1547 HTMLElement_get_onfilterchange,
1548 HTMLElement_get_children,
1552 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1554 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1557 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1559 return CONTAINING_RECORD(iface, HTMLElement, node);
1562 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1564 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1568 if(IsEqualGUID(&IID_IUnknown, riid)) {
1569 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1570 *ppv = &This->IHTMLElement_iface;
1571 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1572 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1573 *ppv = &This->IHTMLElement_iface;
1574 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1575 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1576 *ppv = &This->IHTMLElement_iface;
1577 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1578 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1579 *ppv = &This->IHTMLElement2_iface;
1580 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1581 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1582 *ppv = &This->IHTMLElement3_iface;
1583 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1584 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1585 *ppv = &This->IHTMLElement4_iface;
1586 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1587 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1588 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1592 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1596 return HTMLDOMNode_QI(&This->node, riid, ppv);
1599 void HTMLElement_destructor(HTMLDOMNode *iface)
1601 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1603 ConnectionPointContainer_Destroy(&This->cp_container);
1606 This->style->elem = NULL;
1607 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1609 if(This->runtime_style) {
1610 This->runtime_style->elem = NULL;
1611 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1614 HTMLDOMAttribute *attr;
1616 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1619 This->attrs->elem = NULL;
1620 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1623 heap_free(This->filter);
1625 HTMLDOMNode_destructor(&This->node);
1628 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1630 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1631 HTMLElement *new_elem;
1634 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1639 new_elem->filter = heap_strdupW(This->filter);
1640 if(!new_elem->filter) {
1641 IHTMLElement_Release(&This->IHTMLElement_iface);
1642 return E_OUTOFMEMORY;
1646 *ret = &new_elem->node;
1650 HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *event, BOOL *prevent_default)
1652 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1655 case EVENTID_KEYDOWN: {
1656 nsIDOMKeyEvent *key_event;
1659 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
1660 if(NS_SUCCEEDED(nsres)) {
1663 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
1666 case VK_F1: /* DOM_VK_F1 */
1667 TRACE("F1 pressed\n");
1668 fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL);
1669 *prevent_default = TRUE;
1672 nsIDOMKeyEvent_Release(key_event);
1680 static const NodeImplVtbl HTMLElementImplVtbl = {
1682 HTMLElement_destructor,
1684 HTMLElement_handle_event,
1685 HTMLElement_get_attr_col
1688 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1690 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1693 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1694 DWORD grfdex, DISPID *pid)
1696 HTMLElement *This = impl_from_DispatchEx(dispex);
1698 if(This->node.vtbl->get_dispid)
1699 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1701 return DISP_E_UNKNOWNNAME;
1704 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1705 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1706 IServiceProvider *caller)
1708 HTMLElement *This = impl_from_DispatchEx(dispex);
1710 if(This->node.vtbl->invoke)
1711 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1712 params, res, ei, caller);
1714 ERR("(%p): element has no invoke method\n", This);
1718 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1720 HTMLElement *This = impl_from_DispatchEx(dispex);
1721 nsIDOMNamedNodeMap *attrs;
1724 const PRUnichar *str;
1736 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1737 if(NS_FAILED(nsres))
1740 nsres = nsIDOMNamedNodeMap_GetLength(attrs, &len);
1741 if(NS_FAILED(nsres)) {
1742 nsIDOMNamedNodeMap_Release(attrs);
1746 nsAString_Init(&nsstr, NULL);
1747 for(i=0; i<len; i++) {
1748 nsres = nsIDOMNamedNodeMap_Item(attrs, i, &node);
1749 if(NS_FAILED(nsres))
1752 nsres = nsIDOMNode_GetNodeName(node, &nsstr);
1753 if(NS_FAILED(nsres)) {
1754 nsIDOMNode_Release(node);
1758 nsAString_GetData(&nsstr, &str);
1759 name = SysAllocString(str);
1761 nsIDOMNode_Release(node);
1765 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1766 if(hres != DISP_E_UNKNOWNNAME) {
1767 nsIDOMNode_Release(node);
1768 SysFreeString(name);
1772 nsres = nsIDOMNode_GetNodeValue(node, &nsstr);
1773 nsIDOMNode_Release(node);
1774 if(NS_FAILED(nsres)) {
1775 SysFreeString(name);
1779 nsAString_GetData(&nsstr, &str);
1780 V_VT(&value) = VT_BSTR;
1782 V_BSTR(&value) = SysAllocString(str);
1783 if(!V_BSTR(&value)) {
1784 SysFreeString(name);
1788 V_BSTR(&value) = NULL;
1790 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1791 SysFreeString(name);
1792 VariantClear(&value);
1794 nsAString_Finish(&nsstr);
1796 nsIDOMNamedNodeMap_Release(attrs);
1800 static const tid_t HTMLElement_iface_tids[] = {
1805 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1807 HTMLElement_get_dispid,
1809 HTMLElement_populate_props
1812 static dispex_static_data_t HTMLElement_dispex = {
1813 &HTMLElement_dispex_vtbl,
1814 DispHTMLUnknownElement_tid,
1816 HTMLElement_iface_tids
1819 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1821 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1823 HTMLElement2_Init(This);
1824 HTMLElement3_Init(This);
1826 if(dispex_data && !dispex_data->vtbl)
1827 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1828 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1829 dispex_data ? dispex_data : &HTMLElement_dispex);
1832 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1834 /* No AddRef, share reference with HTMLDOMNode */
1835 assert((nsIDOMNode*)nselem == This->node.nsnode);
1836 This->nselem = nselem;
1839 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface);
1842 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1844 nsIDOMHTMLElement *nselem;
1845 nsAString class_name_str;
1846 const PRUnichar *class_name;
1847 const tag_desc_t *tag;
1852 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1853 if(NS_FAILED(nsres))
1856 nsAString_Init(&class_name_str, NULL);
1857 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1859 nsAString_GetData(&class_name_str, &class_name);
1861 tag = get_tag_desc(class_name);
1863 hres = tag->constructor(doc, nselem, &elem);
1864 }else if(use_generic) {
1865 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1867 elem = heap_alloc_zero(sizeof(HTMLElement));
1869 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1870 elem->node.vtbl = &HTMLElementImplVtbl;
1873 hres = E_OUTOFMEMORY;
1877 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1879 nsIDOMHTMLElement_Release(nselem);
1880 nsAString_Finish(&class_name_str);
1888 HRESULT get_elem(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **ret)
1893 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1897 *ret = impl_from_HTMLDOMNode(node);
1901 /* interface IHTMLFiltersCollection */
1902 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1904 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1906 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1908 if(IsEqualGUID(&IID_IUnknown, riid)) {
1909 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1910 *ppv = &This->IHTMLFiltersCollection_iface;
1911 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1912 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1913 *ppv = &This->IHTMLFiltersCollection_iface;
1914 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1915 return *ppv ? S_OK : E_NOINTERFACE;
1919 IUnknown_AddRef((IUnknown*)*ppv);
1923 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1924 return E_NOINTERFACE;
1927 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1929 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1930 LONG ref = InterlockedIncrement(&This->ref);
1932 TRACE("(%p) ref=%d\n", This, ref);
1937 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1939 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1940 LONG ref = InterlockedDecrement(&This->ref);
1942 TRACE("(%p) ref=%d\n", This, ref);
1952 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1954 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1955 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1958 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1959 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1961 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1962 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1965 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1966 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1967 LCID lcid, DISPID *rgDispId)
1969 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1970 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1974 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1975 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1976 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1978 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1979 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1980 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1983 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1985 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1990 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1996 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1998 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1999 FIXME("(%p)->(%p)\n", This, p);
2003 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
2005 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
2006 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2010 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2011 HTMLFiltersCollection_QueryInterface,
2012 HTMLFiltersCollection_AddRef,
2013 HTMLFiltersCollection_Release,
2014 HTMLFiltersCollection_GetTypeInfoCount,
2015 HTMLFiltersCollection_GetTypeInfo,
2016 HTMLFiltersCollection_GetIDsOfNames,
2017 HTMLFiltersCollection_Invoke,
2018 HTMLFiltersCollection_get_length,
2019 HTMLFiltersCollection_get__newEnum,
2020 HTMLFiltersCollection_item
2023 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2028 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2029 idx = idx*10 + (*ptr-'0');
2031 return DISP_E_UNKNOWNNAME;
2033 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2034 TRACE("ret %x\n", *dispid);
2038 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2039 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2041 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2043 V_VT(res) = VT_DISPATCH;
2044 V_DISPATCH(res) = NULL;
2046 FIXME("always returning NULL\n");
2051 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2053 HTMLFiltersCollection_get_dispid,
2054 HTMLFiltersCollection_invoke,
2058 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2059 IHTMLFiltersCollection_tid,
2062 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2063 &HTMLFiltersCollection_dispex_vtbl,
2064 IHTMLFiltersCollection_tid,
2066 HTMLFiltersCollection_iface_tids
2069 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2071 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2073 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2076 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2077 &HTMLFiltersCollection_dispex);
2079 return &ret->IHTMLFiltersCollection_iface;
2082 /* interface IHTMLAttributeCollection */
2083 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2085 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2088 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2090 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2094 if(IsEqualGUID(&IID_IUnknown, riid)) {
2095 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2096 *ppv = &This->IHTMLAttributeCollection_iface;
2097 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2098 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2099 *ppv = &This->IHTMLAttributeCollection_iface;
2100 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2101 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2102 *ppv = &This->IHTMLAttributeCollection2_iface;
2103 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2104 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2105 *ppv = &This->IHTMLAttributeCollection3_iface;
2106 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2107 return *ppv ? S_OK : E_NOINTERFACE;
2111 IUnknown_AddRef((IUnknown*)*ppv);
2115 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2116 return E_NOINTERFACE;
2119 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2121 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2122 LONG ref = InterlockedIncrement(&This->ref);
2124 TRACE("(%p) ref=%d\n", This, ref);
2129 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2131 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2132 LONG ref = InterlockedDecrement(&This->ref);
2134 TRACE("(%p) ref=%d\n", This, ref);
2137 while(!list_empty(&This->attrs)) {
2138 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2140 list_remove(&attr->entry);
2142 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2151 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2153 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2154 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2157 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2158 LCID lcid, ITypeInfo **ppTInfo)
2160 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2161 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2164 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2165 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2167 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2168 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2172 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2173 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2174 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2176 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2177 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2178 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2181 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2183 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2184 DISPID id = DISPID_STARTENUM;
2188 FIXME("filter non-enumerable attributes out\n");
2191 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2194 else if(hres == S_FALSE)
2204 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2211 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2215 if(name[0]>='0' && name[0]<='9') {
2219 idx = strtoulW(name, &end_ptr, 10);
2221 hres = get_attr_dispid_by_idx(This, &idx, id);
2228 WARN("NULL elem\n");
2229 return E_UNEXPECTED;
2232 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2233 name, fdexNameCaseInsensitive, id);
2237 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2239 HTMLDOMAttribute *iter;
2244 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2245 if(iter->dispid == id) {
2254 WARN("NULL elem\n");
2255 return E_UNEXPECTED;
2258 hres = HTMLDOMAttribute_Create(NULL, This->elem, id, attr);
2263 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2269 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2271 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2274 TRACE("(%p)->(%p)\n", This, p);
2277 hres = get_attr_dispid_by_idx(This, p, NULL);
2281 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2283 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2284 FIXME("(%p)->(%p)\n", This, p);
2288 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2290 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2291 HTMLDOMAttribute *attr;
2295 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2297 switch(V_VT(name)) {
2299 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2302 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2305 FIXME("unsupported name %s\n", debugstr_variant(name));
2308 if(hres == DISP_E_UNKNOWNNAME)
2309 return E_INVALIDARG;
2313 hres = get_domattr(This, id, NULL, &attr);
2317 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2321 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2322 HTMLAttributeCollection_QueryInterface,
2323 HTMLAttributeCollection_AddRef,
2324 HTMLAttributeCollection_Release,
2325 HTMLAttributeCollection_GetTypeInfoCount,
2326 HTMLAttributeCollection_GetTypeInfo,
2327 HTMLAttributeCollection_GetIDsOfNames,
2328 HTMLAttributeCollection_Invoke,
2329 HTMLAttributeCollection_get_length,
2330 HTMLAttributeCollection__newEnum,
2331 HTMLAttributeCollection_item
2334 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2336 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2339 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2341 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2342 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2345 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2347 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2348 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2351 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2353 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2354 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2357 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2359 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2360 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2363 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2364 LCID lcid, ITypeInfo **ppTInfo)
2366 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2367 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2370 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2371 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2373 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2374 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2378 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2379 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2380 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2382 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2383 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2384 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2387 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2388 IHTMLDOMAttribute **newretNode)
2390 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2391 HTMLDOMAttribute *attr;
2395 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2397 hres = get_attr_dispid_by_name(This, bstrName, &id);
2398 if(hres == DISP_E_UNKNOWNNAME) {
2401 } else if(FAILED(hres)) {
2405 hres = get_domattr(This, id, NULL, &attr);
2409 *newretNode = &attr->IHTMLDOMAttribute_iface;
2413 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2414 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2416 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2417 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2421 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2422 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2424 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2425 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2429 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2430 HTMLAttributeCollection2_QueryInterface,
2431 HTMLAttributeCollection2_AddRef,
2432 HTMLAttributeCollection2_Release,
2433 HTMLAttributeCollection2_GetTypeInfoCount,
2434 HTMLAttributeCollection2_GetTypeInfo,
2435 HTMLAttributeCollection2_GetIDsOfNames,
2436 HTMLAttributeCollection2_Invoke,
2437 HTMLAttributeCollection2_getNamedItem,
2438 HTMLAttributeCollection2_setNamedItem,
2439 HTMLAttributeCollection2_removeNamedItem
2442 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2444 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2447 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2449 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2450 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2453 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2455 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2456 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2459 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2461 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2462 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2465 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2467 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2468 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2471 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2472 LCID lcid, ITypeInfo **ppTInfo)
2474 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2475 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2478 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2479 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2481 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2482 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2486 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2487 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2488 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2490 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2491 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2492 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2495 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2496 IHTMLDOMAttribute **ppNodeOut)
2498 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2499 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2502 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2503 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2505 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2506 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2510 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2511 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2513 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2514 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2518 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2520 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2521 HTMLDOMAttribute *attr;
2525 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2527 hres = get_attr_dispid_by_idx(This, &index, &id);
2528 if(hres == DISP_E_UNKNOWNNAME)
2529 return E_INVALIDARG;
2533 hres = get_domattr(This, id, NULL, &attr);
2537 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2541 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2543 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2544 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2547 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2548 HTMLAttributeCollection3_QueryInterface,
2549 HTMLAttributeCollection3_AddRef,
2550 HTMLAttributeCollection3_Release,
2551 HTMLAttributeCollection3_GetTypeInfoCount,
2552 HTMLAttributeCollection3_GetTypeInfo,
2553 HTMLAttributeCollection3_GetIDsOfNames,
2554 HTMLAttributeCollection3_Invoke,
2555 HTMLAttributeCollection3_getNamedItem,
2556 HTMLAttributeCollection3_setNamedItem,
2557 HTMLAttributeCollection3_removeNamedItem,
2558 HTMLAttributeCollection3_item,
2559 HTMLAttributeCollection3_get_length
2562 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2564 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2567 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2569 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2570 HTMLDOMAttribute *attr;
2574 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2576 hres = get_attr_dispid_by_name(This, name, dispid);
2580 hres = get_domattr(This, *dispid, &pos, &attr);
2583 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2585 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2589 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2590 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2592 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2594 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2597 case DISPATCH_PROPERTYGET: {
2598 HTMLDOMAttribute *iter;
2601 pos = id-MSHTML_DISPID_CUSTOM_MIN;
2603 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2605 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2606 V_VT(res) = VT_DISPATCH;
2607 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2613 WARN("invalid arg\n");
2614 return E_INVALIDARG;
2618 FIXME("unimplemented flags %x\n", flags);
2623 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2625 HTMLAttributeCollection_get_dispid,
2626 HTMLAttributeCollection_invoke,
2630 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2631 IHTMLAttributeCollection_tid,
2632 IHTMLAttributeCollection2_tid,
2633 IHTMLAttributeCollection3_tid,
2637 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2638 &HTMLAttributeCollection_dispex_vtbl,
2639 DispHTMLAttributeCollection_tid,
2641 HTMLAttributeCollection_iface_tids
2644 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2646 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2649 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2654 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2656 return E_OUTOFMEMORY;
2658 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2659 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2660 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2661 This->attrs->ref = 2;
2663 This->attrs->elem = This;
2664 list_init(&This->attrs->attrs);
2665 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2666 &HTMLAttributeCollection_dispex);