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"
32 #include "wine/unicode.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 static IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*,HTMLElement
**,DWORD
);
46 static void elem_vector_add(elem_vector
*buf
, HTMLElement
*elem
)
48 if(buf
->len
== buf
->size
) {
50 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
*sizeof(HTMLElement
**));
53 buf
->buf
[buf
->len
++] = elem
;
56 static void elem_vector_normalize(elem_vector
*buf
)
61 }else if(buf
->size
> buf
->len
) {
62 buf
->buf
= heap_realloc(buf
->buf
, buf
->len
*sizeof(HTMLElement
**));
68 static BOOL
is_elem_node(nsIDOMNode
*node
)
72 nsIDOMNode_GetNodeType(node
, &type
);
74 return type
== ELEMENT_NODE
|| type
== COMMENT_NODE
;
77 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
79 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
81 static HRESULT WINAPI
HTMLElement_QueryInterface(IHTMLElement
*iface
,
82 REFIID riid
, void **ppv
)
84 HTMLElement
*This
= HTMLELEM_THIS(iface
);
86 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->node
), riid
, ppv
);
89 static ULONG WINAPI
HTMLElement_AddRef(IHTMLElement
*iface
)
91 HTMLElement
*This
= HTMLELEM_THIS(iface
);
93 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->node
));
96 static ULONG WINAPI
HTMLElement_Release(IHTMLElement
*iface
)
98 HTMLElement
*This
= HTMLELEM_THIS(iface
);
100 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->node
));
103 static HRESULT WINAPI
HTMLElement_GetTypeInfoCount(IHTMLElement
*iface
, UINT
*pctinfo
)
105 HTMLElement
*This
= HTMLELEM_THIS(iface
);
106 FIXME("(%p)->(%p)\n", This
, pctinfo
);
110 static HRESULT WINAPI
HTMLElement_GetTypeInfo(IHTMLElement
*iface
, UINT iTInfo
,
111 LCID lcid
, ITypeInfo
**ppTInfo
)
113 HTMLElement
*This
= HTMLELEM_THIS(iface
);
114 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
118 static HRESULT WINAPI
HTMLElement_GetIDsOfNames(IHTMLElement
*iface
, REFIID riid
,
119 LPOLESTR
*rgszNames
, UINT cNames
,
120 LCID lcid
, DISPID
*rgDispId
)
122 HTMLElement
*This
= HTMLELEM_THIS(iface
);
123 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
128 static HRESULT WINAPI
HTMLElement_Invoke(IHTMLElement
*iface
, DISPID dispIdMember
,
129 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
130 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
132 HTMLElement
*This
= HTMLELEM_THIS(iface
);
133 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
134 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
138 static HRESULT WINAPI
HTMLElement_setAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
139 VARIANT AttributeValue
, LONG lFlags
)
141 HTMLElement
*This
= HTMLELEM_THIS(iface
);
146 VARIANT AttributeValueChanged
;
148 WARN("(%p)->(%s . %08x)\n", This
, debugstr_w(strAttributeName
), lFlags
);
151 FIXME("NULL nselem\n");
155 VariantInit(&AttributeValueChanged
);
157 hres
= VariantChangeType(&AttributeValueChanged
, &AttributeValue
, 0, VT_BSTR
);
159 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue
));
163 nsAString_Init(&attr_str
, strAttributeName
);
164 nsAString_Init(&value_str
, V_BSTR(&AttributeValueChanged
));
166 TRACE("setting %s to %s\n", debugstr_w(strAttributeName
),
167 debugstr_w(V_BSTR(&AttributeValueChanged
)));
169 nsres
= nsIDOMHTMLElement_SetAttribute(This
->nselem
, &attr_str
, &value_str
);
170 nsAString_Finish(&attr_str
);
171 nsAString_Finish(&value_str
);
173 if(NS_SUCCEEDED(nsres
)) {
176 ERR("SetAttribute failed: %08x\n", nsres
);
183 static HRESULT WINAPI
HTMLElement_getAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
184 LONG lFlags
, VARIANT
*AttributeValue
)
186 HTMLElement
*This
= HTMLELEM_THIS(iface
);
189 const PRUnichar
*value
;
193 WARN("(%p)->(%s %08x %p)\n", This
, debugstr_w(strAttributeName
), lFlags
, AttributeValue
);
196 FIXME("NULL nselem\n");
197 V_VT(AttributeValue
) = VT_NULL
;
201 V_VT(AttributeValue
) = VT_NULL
;
203 nsAString_Init(&attr_str
, strAttributeName
);
204 nsAString_Init(&value_str
, NULL
);
206 nsres
= nsIDOMHTMLElement_GetAttribute(This
->nselem
, &attr_str
, &value_str
);
207 nsAString_Finish(&attr_str
);
209 if(NS_SUCCEEDED(nsres
)) {
210 static const WCHAR wszSRC
[] = {'s','r','c',0};
211 nsAString_GetData(&value_str
, &value
);
212 if(!strcmpiW(strAttributeName
, wszSRC
))
217 hres
= IHTMLDocument2_get_URL(HTMLDOC(This
->node
.doc
), &bstrBaseUrl
);
218 if(SUCCEEDED(hres
)) {
219 hres
= CoInternetCombineUrl(bstrBaseUrl
, value
,
220 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
221 buffer
, sizeof(buffer
)/sizeof(WCHAR
), &len
, 0);
222 SysFreeString(bstrBaseUrl
);
223 if(SUCCEEDED(hres
)) {
224 V_VT(AttributeValue
) = VT_BSTR
;
225 V_BSTR(AttributeValue
) = SysAllocString(buffer
);
226 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
230 V_VT(AttributeValue
) = VT_BSTR
;
231 V_BSTR(AttributeValue
) = SysAllocString(value
);
232 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
235 ERR("GetAttribute failed: %08x\n", nsres
);
239 nsAString_Finish(&value_str
);
244 static HRESULT WINAPI
HTMLElement_removeAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
245 LONG lFlags
, VARIANT_BOOL
*pfSuccess
)
247 HTMLElement
*This
= HTMLELEM_THIS(iface
);
248 FIXME("(%p)->()\n", This
);
252 static HRESULT WINAPI
HTMLElement_put_className(IHTMLElement
*iface
, BSTR v
)
254 HTMLElement
*This
= HTMLELEM_THIS(iface
);
255 nsAString classname_str
;
258 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
261 FIXME("NULL nselem\n");
265 nsAString_Init(&classname_str
, v
);
266 nsres
= nsIDOMHTMLElement_SetClassName(This
->nselem
, &classname_str
);
267 nsAString_Finish(&classname_str
);
269 ERR("SetClassName failed: %08x\n", nsres
);
274 static HRESULT WINAPI
HTMLElement_get_className(IHTMLElement
*iface
, BSTR
*p
)
276 HTMLElement
*This
= HTMLELEM_THIS(iface
);
281 TRACE("(%p)->(%p)\n", This
, p
);
284 FIXME("NULL nselem\n");
288 nsAString_Init(&class_str
, NULL
);
289 nsres
= nsIDOMHTMLElement_GetClassName(This
->nselem
, &class_str
);
291 if(NS_SUCCEEDED(nsres
)) {
292 const PRUnichar
*class;
293 nsAString_GetData(&class_str
, &class);
294 *p
= *class ? SysAllocString(class) : NULL
;
296 ERR("GetClassName failed: %08x\n", nsres
);
300 nsAString_Finish(&class_str
);
302 TRACE("className=%s\n", debugstr_w(*p
));
306 static HRESULT WINAPI
HTMLElement_put_id(IHTMLElement
*iface
, BSTR v
)
308 HTMLElement
*This
= HTMLELEM_THIS(iface
);
312 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
315 FIXME("nselem == NULL\n");
319 nsAString_Init(&id_str
, v
);
320 nsres
= nsIDOMHTMLElement_SetId(This
->nselem
, &id_str
);
321 nsAString_Finish(&id_str
);
323 ERR("SetId failed: %08x\n", nsres
);
328 static HRESULT WINAPI
HTMLElement_get_id(IHTMLElement
*iface
, BSTR
*p
)
330 HTMLElement
*This
= HTMLELEM_THIS(iface
);
335 TRACE("(%p)->(%p)\n", This
, p
);
342 nsAString_Init(&id_str
, NULL
);
343 nsres
= nsIDOMHTMLElement_GetId(This
->nselem
, &id_str
);
344 nsAString_GetData(&id_str
, &id
);
347 ERR("GetId failed: %08x\n", nsres
);
349 *p
= SysAllocString(id
);
351 nsAString_Finish(&id_str
);
355 static HRESULT WINAPI
HTMLElement_get_tagName(IHTMLElement
*iface
, BSTR
*p
)
357 HTMLElement
*This
= HTMLELEM_THIS(iface
);
358 const PRUnichar
*tag
;
362 TRACE("(%p)->(%p)\n", This
, p
);
365 static const WCHAR comment_tagW
[] = {'!',0};
367 WARN("NULL nselem, assuming comment\n");
369 *p
= SysAllocString(comment_tagW
);
373 nsAString_Init(&tag_str
, NULL
);
374 nsres
= nsIDOMHTMLElement_GetTagName(This
->nselem
, &tag_str
);
375 if(NS_SUCCEEDED(nsres
)) {
376 nsAString_GetData(&tag_str
, &tag
);
377 *p
= SysAllocString(tag
);
379 ERR("GetTagName failed: %08x\n", nsres
);
382 nsAString_Finish(&tag_str
);
387 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
389 HTMLElement
*This
= HTMLELEM_THIS(iface
);
390 FIXME("(%p)->(%p)\n", This
, p
);
394 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
396 HTMLElement
*This
= HTMLELEM_THIS(iface
);
397 nsIDOMElementCSSInlineStyle
*nselemstyle
;
398 nsIDOMCSSStyleDeclaration
*nsstyle
;
401 TRACE("(%p)->(%p)\n", This
, p
);
404 FIXME("NULL nselem\n");
408 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
409 (void**)&nselemstyle
);
410 if(NS_FAILED(nsres
)) {
411 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
415 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
416 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
417 if(NS_FAILED(nsres
)) {
418 ERR("GetStyle failed: %08x\n", nsres
);
422 /* FIXME: Store style instead of creating a new instance in each call */
423 *p
= HTMLStyle_Create(nsstyle
);
425 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
429 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
431 HTMLElement
*This
= HTMLELEM_THIS(iface
);
432 FIXME("(%p)->()\n", This
);
436 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
438 HTMLElement
*This
= HTMLELEM_THIS(iface
);
439 FIXME("(%p)->(%p)\n", This
, p
);
443 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
445 HTMLElement
*This
= HTMLELEM_THIS(iface
);
447 TRACE("(%p)->()\n", This
);
449 return set_node_event(&This
->node
, EVENTID_CLICK
, &v
);
452 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
454 HTMLElement
*This
= HTMLELEM_THIS(iface
);
455 FIXME("(%p)->(%p)\n", This
, p
);
459 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
461 HTMLElement
*This
= HTMLELEM_THIS(iface
);
462 FIXME("(%p)->()\n", This
);
466 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
468 HTMLElement
*This
= HTMLELEM_THIS(iface
);
469 FIXME("(%p)->(%p)\n", This
, p
);
473 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
475 HTMLElement
*This
= HTMLELEM_THIS(iface
);
476 FIXME("(%p)->()\n", This
);
480 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
482 HTMLElement
*This
= HTMLELEM_THIS(iface
);
483 FIXME("(%p)->(%p)\n", This
, p
);
487 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
489 HTMLElement
*This
= HTMLELEM_THIS(iface
);
491 TRACE("(%p)->()\n", This
);
493 return set_node_event(&This
->node
, EVENTID_KEYUP
, &v
);
496 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
498 HTMLElement
*This
= HTMLELEM_THIS(iface
);
499 FIXME("(%p)->(%p)\n", This
, p
);
503 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
505 HTMLElement
*This
= HTMLELEM_THIS(iface
);
506 FIXME("(%p)->()\n", This
);
510 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
512 HTMLElement
*This
= HTMLELEM_THIS(iface
);
513 FIXME("(%p)->(%p)\n", This
, p
);
517 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
519 HTMLElement
*This
= HTMLELEM_THIS(iface
);
520 FIXME("(%p)->()\n", This
);
524 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
526 HTMLElement
*This
= HTMLELEM_THIS(iface
);
527 FIXME("(%p)->(%p)\n", This
, p
);
531 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
533 HTMLElement
*This
= HTMLELEM_THIS(iface
);
534 FIXME("(%p)->()\n", This
);
538 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
540 HTMLElement
*This
= HTMLELEM_THIS(iface
);
541 FIXME("(%p)->(%p)\n", This
, p
);
545 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
547 HTMLElement
*This
= HTMLELEM_THIS(iface
);
548 FIXME("(%p)->()\n", This
);
552 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
554 HTMLElement
*This
= HTMLELEM_THIS(iface
);
555 FIXME("(%p)->(%p)\n", This
, p
);
559 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
561 HTMLElement
*This
= HTMLELEM_THIS(iface
);
562 FIXME("(%p)->()\n", This
);
566 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
568 HTMLElement
*This
= HTMLELEM_THIS(iface
);
569 FIXME("(%p)->(%p)\n", This
, p
);
573 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
575 HTMLElement
*This
= HTMLELEM_THIS(iface
);
576 FIXME("(%p)->()\n", This
);
580 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
582 HTMLElement
*This
= HTMLELEM_THIS(iface
);
583 FIXME("(%p)->(%p)\n", This
, p
);
587 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
589 HTMLElement
*This
= HTMLELEM_THIS(iface
);
590 FIXME("(%p)->(%p)\n", This
, p
);
594 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
596 HTMLElement
*This
= HTMLELEM_THIS(iface
);
600 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
602 nsAString_Init(&title_str
, v
);
603 nsres
= nsIDOMHTMLElement_SetTitle(This
->nselem
, &title_str
);
604 nsAString_Finish(&title_str
);
606 ERR("SetTitle failed: %08x\n", nsres
);
611 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
613 HTMLElement
*This
= HTMLELEM_THIS(iface
);
617 TRACE("(%p)->(%p)\n", This
, p
);
619 nsAString_Init(&title_str
, NULL
);
620 nsres
= nsIDOMHTMLElement_GetTitle(This
->nselem
, &title_str
);
621 if(NS_SUCCEEDED(nsres
)) {
622 const PRUnichar
*title
;
624 nsAString_GetData(&title_str
, &title
);
625 *p
= *title
? SysAllocString(title
) : NULL
;
627 ERR("GetTitle failed: %08x\n", nsres
);
634 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
636 HTMLElement
*This
= HTMLELEM_THIS(iface
);
637 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
641 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
643 HTMLElement
*This
= HTMLELEM_THIS(iface
);
644 FIXME("(%p)->(%p)\n", This
, p
);
648 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
650 HTMLElement
*This
= HTMLELEM_THIS(iface
);
651 FIXME("(%p)->()\n", This
);
655 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
657 HTMLElement
*This
= HTMLELEM_THIS(iface
);
658 FIXME("(%p)->(%p)\n", This
, p
);
662 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
664 HTMLElement
*This
= HTMLELEM_THIS(iface
);
665 FIXME("(%p)->()\n", This
);
669 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
670 VARIANT_BOOL
*pfResult
)
672 HTMLElement
*This
= HTMLELEM_THIS(iface
);
673 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
677 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
679 HTMLElement
*This
= HTMLELEM_THIS(iface
);
680 FIXME("(%p)->(%p)\n", This
, p
);
684 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
686 HTMLElement
*This
= HTMLELEM_THIS(iface
);
687 FIXME("(%p)->(%p)\n", This
, p
);
691 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
693 HTMLElement
*This
= HTMLELEM_THIS(iface
);
694 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
698 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
700 HTMLElement
*This
= HTMLELEM_THIS(iface
);
701 FIXME("(%p)->(%p)\n", This
, p
);
705 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
707 HTMLElement
*This
= HTMLELEM_THIS(iface
);
708 FIXME("(%p)->(%p)\n", This
, p
);
712 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
714 HTMLElement
*This
= HTMLELEM_THIS(iface
);
715 nsIDOMNSHTMLElement
*nselem
;
719 TRACE("(%p)->(%p)\n", This
, p
);
721 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
722 if(NS_FAILED(nsres
)) {
723 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
727 nsres
= nsIDOMNSHTMLElement_GetOffsetTop(nselem
, &top
);
728 nsIDOMNSHTMLElement_Release(nselem
);
729 if(NS_FAILED(nsres
)) {
730 ERR("GetOffsetTop failed: %08x\n", nsres
);
738 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
740 HTMLElement
*This
= HTMLELEM_THIS(iface
);
741 FIXME("(%p)->(%p)\n", This
, p
);
745 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
747 HTMLElement
*This
= HTMLELEM_THIS(iface
);
748 FIXME("(%p)->(%p)\n", This
, p
);
752 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
754 HTMLElement
*This
= HTMLELEM_THIS(iface
);
755 FIXME("(%p)->(%p)\n", This
, p
);
759 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
761 HTMLElement
*This
= HTMLELEM_THIS(iface
);
762 nsIDOMNSHTMLElement
*nselem
;
766 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
769 FIXME("NULL nselem\n");
773 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
774 if(NS_FAILED(nsres
)) {
775 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
779 nsAString_Init(&html_str
, v
);
780 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
781 nsAString_Finish(&html_str
);
783 if(NS_FAILED(nsres
)) {
784 FIXME("SetInnerHtml failed %08x\n", nsres
);
791 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
793 HTMLElement
*This
= HTMLELEM_THIS(iface
);
794 FIXME("(%p)->(%p)\n", This
, p
);
798 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
800 HTMLElement
*This
= HTMLELEM_THIS(iface
);
801 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
805 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
807 HTMLElement
*This
= HTMLELEM_THIS(iface
);
808 FIXME("(%p)->(%p)\n", This
, p
);
812 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
814 HTMLElement
*This
= HTMLELEM_THIS(iface
);
815 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
819 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
821 HTMLElement
*This
= HTMLELEM_THIS(iface
);
822 FIXME("(%p)->(%p)\n", This
, p
);
826 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
828 HTMLElement
*This
= HTMLELEM_THIS(iface
);
829 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
833 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
835 HTMLElement
*This
= HTMLELEM_THIS(iface
);
836 FIXME("(%p)->(%p)\n", This
, p
);
840 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
842 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
843 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
844 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
845 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
849 FIXME("NULL nselem\n");
853 if (!strcmpiW(where
, wszBeforeBegin
))
857 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
858 if (!parent
) return E_INVALIDARG
;
859 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
860 (nsIDOMNode
*)This
->nselem
, &unused
);
861 if (unused
) nsIDOMNode_Release(unused
);
862 nsIDOMNode_Release(parent
);
864 else if (!strcmpiW(where
, wszAfterBegin
))
867 nsIDOMNode
*first_child
;
868 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
869 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
870 if (unused
) nsIDOMNode_Release(unused
);
871 if (first_child
) nsIDOMNode_Release(first_child
);
873 else if (!strcmpiW(where
, wszBeforeEnd
))
876 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
877 if (unused
) nsIDOMNode_Release(unused
);
879 else if (!strcmpiW(where
, wszAfterEnd
))
882 nsIDOMNode
*next_sibling
;
884 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
885 if (!parent
) return E_INVALIDARG
;
887 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
890 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
891 nsIDOMNode_Release(next_sibling
);
894 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
895 nsIDOMNode_Release(parent
);
896 if (unused
) nsIDOMNode_Release(unused
);
900 ERR("invalid where: %s\n", debugstr_w(where
));
904 if (NS_FAILED(nsres
))
910 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
913 HTMLElement
*This
= HTMLELEM_THIS(iface
);
915 nsIDOMDocument
*nsdoc
;
916 nsIDOMDocumentRange
*nsdocrange
;
918 nsIDOMNSRange
*nsrange
;
923 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
925 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
928 ERR("GetDocument failed: %08x\n", nsres
);
932 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
933 nsIDOMDocument_Release(nsdoc
);
936 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
939 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
940 nsIDOMDocumentRange_Release(nsdocrange
);
943 ERR("CreateRange failed: %08x\n", nsres
);
947 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
949 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
950 nsIDOMRange_Release(range
);
953 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
957 nsAString_Init(&ns_html
, html
);
959 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
960 nsIDOMNSRange_Release(nsrange
);
961 nsAString_Finish(&ns_html
);
963 if(NS_FAILED(nsres
) || !nsnode
)
965 ERR("CreateTextNode failed: %08x\n", nsres
);
969 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
970 nsIDOMNode_Release(nsnode
);
975 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
978 HTMLElement
*This
= HTMLELEM_THIS(iface
);
980 nsIDOMDocument
*nsdoc
;
985 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
987 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
988 if(NS_FAILED(nsres
) || !nsdoc
)
990 ERR("GetDocument failed: %08x\n", nsres
);
994 nsAString_Init(&ns_text
, text
);
996 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
997 nsIDOMDocument_Release(nsdoc
);
998 nsAString_Finish(&ns_text
);
1000 if(NS_FAILED(nsres
) || !nsnode
)
1002 ERR("CreateTextNode failed: %08x\n", nsres
);
1006 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
1007 nsIDOMNode_Release(nsnode
);
1012 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
1014 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1015 FIXME("(%p)->(%p)\n", This
, p
);
1019 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
1021 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1022 FIXME("(%p)->(%p)\n", This
, p
);
1026 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
1028 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1029 FIXME("(%p)\n", This
);
1033 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
1034 IHTMLFiltersCollection
**p
)
1036 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1037 FIXME("(%p)->(%p)\n", This
, p
);
1041 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
1043 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1044 FIXME("(%p)->()\n", This
);
1048 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
1050 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1051 FIXME("(%p)->(%p)\n", This
, p
);
1055 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
1057 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1058 FIXME("(%p)->(%p)\n", This
, String
);
1062 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
1064 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1065 FIXME("(%p)->()\n", This
);
1069 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
1071 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1072 FIXME("(%p)->(%p)\n", This
, p
);
1076 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
1078 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1079 FIXME("(%p)->()\n", This
);
1083 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
1085 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1086 FIXME("(%p)->(%p)\n", This
, p
);
1090 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
1092 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1093 FIXME("(%p)->()\n", This
);
1097 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
1099 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1100 FIXME("(%p)->(%p)\n", This
, p
);
1104 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
1106 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1107 FIXME("(%p)->()\n", This
);
1111 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
1113 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1114 FIXME("(%p)->(%p)\n", This
, p
);
1118 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
1120 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1121 FIXME("(%p)->()\n", This
);
1125 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
1127 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1128 FIXME("(%p)->(%p)\n", This
, p
);
1132 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
1134 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1135 FIXME("(%p)->()\n", This
);
1139 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
1141 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1142 FIXME("(%p)->(%p)\n", This
, p
);
1146 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
1148 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1149 FIXME("(%p)->()\n", This
);
1153 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
1155 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1156 FIXME("(%p)->(%p)\n", This
, p
);
1160 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
1162 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1163 FIXME("(%p)->()\n", This
);
1167 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1169 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1170 FIXME("(%p)->(%p)\n", This
, p
);
1174 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1176 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1177 FIXME("(%p)->()\n", This
);
1181 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1183 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1184 FIXME("(%p)->(%p)\n", This
, p
);
1188 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1190 nsIDOMNodeList
*nsnode_list
;
1192 PRUint32 list_len
= 0, i
;
1195 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1196 if(NS_FAILED(nsres
)) {
1197 ERR("GetChildNodes failed: %08x\n", nsres
);
1201 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1205 buf
->size
= list_len
;
1206 buf
->buf
= heap_alloc(buf
->size
*sizeof(HTMLElement
**));
1208 for(i
=0; i
<list_len
; i
++) {
1209 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1210 if(NS_FAILED(nsres
)) {
1211 ERR("Item failed: %08x\n", nsres
);
1215 if(is_elem_node(iter
))
1216 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
, TRUE
)));
1220 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1222 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1223 elem_vector buf
= {NULL
, 0, 0};
1225 TRACE("(%p)->(%p)\n", This
, p
);
1227 create_child_list(This
->node
.doc
, This
, &buf
);
1229 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1233 static void create_all_list(HTMLDocument
*doc
, HTMLDOMNode
*elem
, elem_vector
*buf
)
1235 nsIDOMNodeList
*nsnode_list
;
1237 PRUint32 list_len
= 0, i
;
1240 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
1241 if(NS_FAILED(nsres
)) {
1242 ERR("GetChildNodes failed: %08x\n", nsres
);
1246 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1250 for(i
=0; i
<list_len
; i
++) {
1251 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1252 if(NS_FAILED(nsres
)) {
1253 ERR("Item failed: %08x\n", nsres
);
1257 if(is_elem_node(iter
)) {
1258 HTMLDOMNode
*node
= get_node(doc
, iter
, TRUE
);
1260 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1261 create_all_list(doc
, node
, buf
);
1266 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1268 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1269 elem_vector buf
= {NULL
, 0, 8};
1271 TRACE("(%p)->(%p)\n", This
, p
);
1273 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1275 create_all_list(This
->node
.doc
, &This
->node
, &buf
);
1276 elem_vector_normalize(&buf
);
1278 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1282 #undef HTMLELEM_THIS
1284 static const IHTMLElementVtbl HTMLElementVtbl
= {
1285 HTMLElement_QueryInterface
,
1287 HTMLElement_Release
,
1288 HTMLElement_GetTypeInfoCount
,
1289 HTMLElement_GetTypeInfo
,
1290 HTMLElement_GetIDsOfNames
,
1292 HTMLElement_setAttribute
,
1293 HTMLElement_getAttribute
,
1294 HTMLElement_removeAttribute
,
1295 HTMLElement_put_className
,
1296 HTMLElement_get_className
,
1299 HTMLElement_get_tagName
,
1300 HTMLElement_get_parentElement
,
1301 HTMLElement_get_style
,
1302 HTMLElement_put_onhelp
,
1303 HTMLElement_get_onhelp
,
1304 HTMLElement_put_onclick
,
1305 HTMLElement_get_onclick
,
1306 HTMLElement_put_ondblclick
,
1307 HTMLElement_get_ondblclick
,
1308 HTMLElement_put_onkeydown
,
1309 HTMLElement_get_onkeydown
,
1310 HTMLElement_put_onkeyup
,
1311 HTMLElement_get_onkeyup
,
1312 HTMLElement_put_onkeypress
,
1313 HTMLElement_get_onkeypress
,
1314 HTMLElement_put_onmouseout
,
1315 HTMLElement_get_onmouseout
,
1316 HTMLElement_put_onmouseover
,
1317 HTMLElement_get_onmouseover
,
1318 HTMLElement_put_onmousemove
,
1319 HTMLElement_get_onmousemove
,
1320 HTMLElement_put_onmousedown
,
1321 HTMLElement_get_onmousedown
,
1322 HTMLElement_put_onmouseup
,
1323 HTMLElement_get_onmouseup
,
1324 HTMLElement_get_document
,
1325 HTMLElement_put_title
,
1326 HTMLElement_get_title
,
1327 HTMLElement_put_language
,
1328 HTMLElement_get_language
,
1329 HTMLElement_put_onselectstart
,
1330 HTMLElement_get_onselectstart
,
1331 HTMLElement_scrollIntoView
,
1332 HTMLElement_contains
,
1333 HTMLElement_get_sourceIndex
,
1334 HTMLElement_get_recordNumber
,
1335 HTMLElement_put_lang
,
1336 HTMLElement_get_lang
,
1337 HTMLElement_get_offsetLeft
,
1338 HTMLElement_get_offsetTop
,
1339 HTMLElement_get_offsetWidth
,
1340 HTMLElement_get_offsetHeight
,
1341 HTMLElement_get_offsetParent
,
1342 HTMLElement_put_innerHTML
,
1343 HTMLElement_get_innerHTML
,
1344 HTMLElement_put_innerText
,
1345 HTMLElement_get_innerText
,
1346 HTMLElement_put_outerHTML
,
1347 HTMLElement_get_outerHTML
,
1348 HTMLElement_put_outerText
,
1349 HTMLElement_get_outerText
,
1350 HTMLElement_insertAdjacentHTML
,
1351 HTMLElement_insertAdjacentText
,
1352 HTMLElement_get_parentTextEdit
,
1353 HTMLElement_get_isTextEdit
,
1355 HTMLElement_get_filters
,
1356 HTMLElement_put_ondragstart
,
1357 HTMLElement_get_ondragstart
,
1358 HTMLElement_toString
,
1359 HTMLElement_put_onbeforeupdate
,
1360 HTMLElement_get_onbeforeupdate
,
1361 HTMLElement_put_onafterupdate
,
1362 HTMLElement_get_onafterupdate
,
1363 HTMLElement_put_onerrorupdate
,
1364 HTMLElement_get_onerrorupdate
,
1365 HTMLElement_put_onrowexit
,
1366 HTMLElement_get_onrowexit
,
1367 HTMLElement_put_onrowenter
,
1368 HTMLElement_get_onrowenter
,
1369 HTMLElement_put_ondatasetchanged
,
1370 HTMLElement_get_ondatasetchanged
,
1371 HTMLElement_put_ondataavailable
,
1372 HTMLElement_get_ondataavailable
,
1373 HTMLElement_put_ondatasetcomplete
,
1374 HTMLElement_get_ondatasetcomplete
,
1375 HTMLElement_put_onfilterchange
,
1376 HTMLElement_get_onfilterchange
,
1377 HTMLElement_get_children
,
1381 HRESULT
HTMLElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1383 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1387 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1388 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1389 *ppv
= HTMLELEM(This
);
1390 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1391 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1392 *ppv
= HTMLELEM(This
);
1393 }else if(IsEqualGUID(&IID_IHTMLElement
, riid
)) {
1394 TRACE("(%p)->(IID_IHTMLElement %p)\n", This
, ppv
);
1395 *ppv
= HTMLELEM(This
);
1396 }else if(IsEqualGUID(&IID_IHTMLElement2
, riid
)) {
1397 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This
, ppv
);
1398 *ppv
= HTMLELEM2(This
);
1399 }else if(IsEqualGUID(&IID_IConnectionPointContainer
, riid
)) {
1400 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This
, ppv
);
1401 *ppv
= CONPTCONT(&This
->cp_container
);
1405 IHTMLElement_AddRef(HTMLELEM(This
));
1409 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
1412 void HTMLElement_destructor(HTMLDOMNode
*iface
)
1414 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1416 ConnectionPointContainer_Destroy(&This
->cp_container
);
1419 nsIDOMHTMLElement_Release(This
->nselem
);
1421 HTMLDOMNode_destructor(&This
->node
);
1424 static const NodeImplVtbl HTMLElementImplVtbl
= {
1426 HTMLElement_destructor
1429 static const tid_t HTMLElement_iface_tids
[] = {
1437 static dispex_static_data_t HTMLElement_dispex
= {
1439 DispHTMLUnknownElement_tid
,
1441 HTMLElement_iface_tids
1444 void HTMLElement_Init(HTMLElement
*This
)
1446 This
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1448 ConnectionPointContainer_Init(&This
->cp_container
, (IUnknown
*)HTMLELEM(This
));
1450 HTMLElement2_Init(This
);
1452 if(!This
->node
.dispex
.data
)
1453 init_dispex(&This
->node
.dispex
, (IUnknown
*)HTMLELEM(This
), &HTMLElement_dispex
);
1456 HTMLElement
*HTMLElement_Create(HTMLDocument
*doc
, nsIDOMNode
*nsnode
, BOOL use_generic
)
1458 nsIDOMHTMLElement
*nselem
;
1459 HTMLElement
*ret
= NULL
;
1460 nsAString class_name_str
;
1461 const PRUnichar
*class_name
;
1464 static const WCHAR wszA
[] = {'A',0};
1465 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1466 static const WCHAR wszIMG
[] = {'I','M','G',0};
1467 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1468 static const WCHAR wszOPTION
[] = {'O','P','T','I','O','N',0};
1469 static const WCHAR wszSCRIPT
[] = {'S','C','R','I','P','T',0};
1470 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1471 static const WCHAR wszTABLE
[] = {'T','A','B','L','E',0};
1472 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1474 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1475 if(NS_FAILED(nsres
))
1478 nsAString_Init(&class_name_str
, NULL
);
1479 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1481 nsAString_GetData(&class_name_str
, &class_name
);
1483 if(!strcmpW(class_name
, wszA
))
1484 ret
= HTMLAnchorElement_Create(nselem
);
1485 else if(!strcmpW(class_name
, wszBODY
))
1486 ret
= HTMLBodyElement_Create(nselem
);
1487 else if(!strcmpW(class_name
, wszIMG
))
1488 ret
= HTMLImgElement_Create(nselem
);
1489 else if(!strcmpW(class_name
, wszINPUT
))
1490 ret
= HTMLInputElement_Create(nselem
);
1491 else if(!strcmpW(class_name
, wszOPTION
))
1492 ret
= HTMLOptionElement_Create(nselem
);
1493 else if(!strcmpW(class_name
, wszSCRIPT
))
1494 ret
= HTMLScriptElement_Create(nselem
);
1495 else if(!strcmpW(class_name
, wszSELECT
))
1496 ret
= HTMLSelectElement_Create(nselem
);
1497 else if(!strcmpW(class_name
, wszTABLE
))
1498 ret
= HTMLTable_Create(nselem
);
1499 else if(!strcmpW(class_name
, wszTEXTAREA
))
1500 ret
= HTMLTextAreaElement_Create(nselem
);
1501 else if(use_generic
)
1502 ret
= HTMLGenericElement_Create(nselem
);
1505 ret
= heap_alloc_zero(sizeof(HTMLElement
));
1506 HTMLElement_Init(ret
);
1507 ret
->node
.vtbl
= &HTMLElementImplVtbl
;
1510 TRACE("%s ret %p\n", debugstr_w(class_name
), ret
);
1512 nsAString_Finish(&class_name_str
);
1514 ret
->nselem
= nselem
;
1515 HTMLDOMNode_Init(doc
, &ret
->node
, (nsIDOMNode
*)nselem
);
1522 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1525 HTMLElement
**elems
;
1529 } HTMLElementCollection
;
1531 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1533 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1535 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1536 REFIID riid
, void **ppv
)
1538 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1542 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1543 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1544 *ppv
= HTMLELEMCOL(This
);
1545 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1546 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1547 *ppv
= HTMLELEMCOL(This
);
1548 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1549 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1550 *ppv
= DISPATCHEX(&This
->dispex
);
1551 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1552 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1553 *ppv
= HTMLELEMCOL(This
);
1557 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1561 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1562 return E_NOINTERFACE
;
1565 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1567 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1568 LONG ref
= InterlockedIncrement(&This
->ref
);
1570 TRACE("(%p) ref=%d\n", This
, ref
);
1575 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1577 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1578 LONG ref
= InterlockedDecrement(&This
->ref
);
1580 TRACE("(%p) ref=%d\n", This
, ref
);
1583 IUnknown_Release(This
->ref_unk
);
1584 heap_free(This
->elems
);
1591 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1594 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1595 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1599 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1600 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1602 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1603 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1607 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1608 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1610 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1611 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1616 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1617 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1618 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1620 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1621 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1622 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1626 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1629 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1630 FIXME("(%p)->(%p)\n", This
, String
);
1634 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1637 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1638 FIXME("(%p)->(%ld)\n", This
, v
);
1642 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1645 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1647 TRACE("(%p)->(%p)\n", This
, p
);
1653 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1656 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1657 FIXME("(%p)->(%p)\n", This
, p
);
1661 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
1663 const PRUnichar
*str
;
1664 nsAString nsstr
, nsname
;
1668 static const PRUnichar nameW
[] = {'n','a','m','e',0};
1673 nsAString_Init(&nsstr
, NULL
);
1674 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
1675 nsAString_GetData(&nsstr
, &str
);
1676 if(!strcmpiW(str
, name
)) {
1677 nsAString_Finish(&nsstr
);
1681 nsAString_Init(&nsname
, nameW
);
1682 nsres
= nsIDOMHTMLElement_GetAttribute(elem
->nselem
, &nsname
, &nsstr
);
1683 nsAString_Finish(&nsname
);
1684 if(NS_SUCCEEDED(nsres
)) {
1685 nsAString_GetData(&nsstr
, &str
);
1686 ret
= !strcmpiW(str
, name
);
1689 nsAString_Finish(&nsstr
);
1693 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1694 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1696 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1698 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1702 if(V_VT(&name
) == VT_I4
) {
1703 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1706 return E_INVALIDARG
;
1707 if(V_I4(&name
) >= This
->len
)
1710 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1711 IDispatch_AddRef(*pdisp
);
1712 TRACE("Returning pdisp=%p\n", pdisp
);
1716 if(V_VT(&name
) == VT_BSTR
) {
1719 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1721 if(V_VT(&index
) == VT_I4
) {
1722 LONG idx
= V_I4(&index
);
1724 TRACE("index = %d\n", idx
);
1727 return E_INVALIDARG
;
1729 for(i
=0; i
<This
->len
; i
++) {
1730 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
1734 if(i
!= This
->len
) {
1735 *pdisp
= (IDispatch
*)HTMLELEM(This
->elems
[i
]);
1736 IDispatch_AddRef(*pdisp
);
1741 elem_vector buf
= {NULL
, 0, 8};
1743 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1745 for(i
=0; i
<This
->len
; i
++) {
1746 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)))
1747 elem_vector_add(&buf
, This
->elems
[i
]);
1751 elem_vector_normalize(&buf
);
1752 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1755 *pdisp
= (IDispatch
*)HTMLELEM(buf
.buf
[0]);
1756 IDispatch_AddRef(*pdisp
);
1766 FIXME("unsupported arguments\n");
1767 return E_INVALIDARG
;
1770 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1771 VARIANT tagName
, IDispatch
**pdisp
)
1773 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1776 const PRUnichar
*tag
;
1777 elem_vector buf
= {NULL
, 0, 8};
1779 if(V_VT(&tagName
) != VT_BSTR
) {
1780 WARN("Invalid arg\n");
1781 return DISP_E_MEMBERNOTFOUND
;
1784 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1786 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1788 nsAString_Init(&tag_str
, NULL
);
1790 for(i
=0; i
<This
->len
; i
++) {
1791 if(!This
->elems
[i
]->nselem
)
1794 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1795 nsAString_GetData(&tag_str
, &tag
);
1797 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1798 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1799 elem_vector_add(&buf
, This
->elems
[i
]);
1802 nsAString_Finish(&tag_str
);
1803 elem_vector_normalize(&buf
);
1805 TRACE("fount %d tags\n", buf
.len
);
1807 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1811 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1813 static HRESULT
HTMLElementCollection_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1815 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1819 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
1820 idx
= idx
*10 + (*ptr
-'0');
1822 if(*ptr
|| idx
>= This
->len
)
1823 return DISP_E_UNKNOWNNAME
;
1825 *dispid
= DISPID_ELEMCOL_0
+ idx
;
1826 TRACE("ret %x\n", *dispid
);
1830 static HRESULT
HTMLElementCollection_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1831 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1833 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1836 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1838 idx
= id
- DISPID_ELEMCOL_0
;
1839 if(idx
>= This
->len
)
1840 return DISP_E_UNKNOWNNAME
;
1843 case INVOKE_PROPERTYGET
:
1844 V_VT(res
) = VT_DISPATCH
;
1845 V_DISPATCH(res
) = (IDispatch
*)HTMLELEM(This
->elems
[idx
]);
1846 IHTMLElement_AddRef(HTMLELEM(This
->elems
[idx
]));
1849 FIXME("unimplemented flags %x\n", flags
);
1858 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1859 HTMLElementCollection_QueryInterface
,
1860 HTMLElementCollection_AddRef
,
1861 HTMLElementCollection_Release
,
1862 HTMLElementCollection_GetTypeInfoCount
,
1863 HTMLElementCollection_GetTypeInfo
,
1864 HTMLElementCollection_GetIDsOfNames
,
1865 HTMLElementCollection_Invoke
,
1866 HTMLElementCollection_toString
,
1867 HTMLElementCollection_put_length
,
1868 HTMLElementCollection_get_length
,
1869 HTMLElementCollection_get__newEnum
,
1870 HTMLElementCollection_item
,
1871 HTMLElementCollection_tags
1874 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
1875 HTMLElementCollection_get_dispid
,
1876 HTMLElementCollection_invoke
1879 static const tid_t HTMLElementCollection_iface_tids
[] = {
1880 IHTMLElementCollection_tid
,
1883 static dispex_static_data_t HTMLElementCollection_dispex
= {
1884 &HTMLElementColection_dispex_vtbl
,
1885 DispHTMLElementCollection_tid
,
1887 HTMLElementCollection_iface_tids
1890 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
)
1892 elem_vector buf
= {NULL
, 0, 8};
1894 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1896 elem_vector_add(&buf
, HTMLELEM_NODE_THIS(node
));
1897 create_all_list(node
->doc
, node
, &buf
);
1898 elem_vector_normalize(&buf
);
1900 return HTMLElementCollection_Create((IUnknown
*)HTMLDOMNODE(node
), buf
.buf
, buf
.len
);
1903 static IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*ref_unk
,
1904 HTMLElement
**elems
, DWORD len
)
1906 HTMLElementCollection
*ret
= heap_alloc_zero(sizeof(HTMLElementCollection
));
1908 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1913 init_dispex(&ret
->dispex
, (IUnknown
*)HTMLELEMCOL(ret
), &HTMLElementCollection_dispex
);
1915 IUnknown_AddRef(ref_unk
);
1916 ret
->ref_unk
= ref_unk
;
1918 TRACE("ret=%p len=%d\n", ret
, len
);
1920 return HTMLELEMCOL(ret
);