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");
200 V_VT(AttributeValue
) = VT_NULL
;
202 nsAString_Init(&attr_str
, strAttributeName
);
203 nsAString_Init(&value_str
, NULL
);
205 nsres
= nsIDOMHTMLElement_GetAttribute(This
->nselem
, &attr_str
, &value_str
);
206 nsAString_Finish(&attr_str
);
208 if(NS_SUCCEEDED(nsres
)) {
209 static const WCHAR wszSRC
[] = {'s','r','c',0};
210 nsAString_GetData(&value_str
, &value
);
211 if(!strcmpiW(strAttributeName
, wszSRC
))
216 hres
= IHTMLDocument2_get_URL(HTMLDOC(This
->node
.doc
), &bstrBaseUrl
);
217 if(SUCCEEDED(hres
)) {
218 hres
= CoInternetCombineUrl(bstrBaseUrl
, value
,
219 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
220 buffer
, sizeof(buffer
)/sizeof(WCHAR
), &len
, 0);
221 SysFreeString(bstrBaseUrl
);
222 if(SUCCEEDED(hres
)) {
223 V_VT(AttributeValue
) = VT_BSTR
;
224 V_BSTR(AttributeValue
) = SysAllocString(buffer
);
225 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
229 V_VT(AttributeValue
) = VT_BSTR
;
230 V_BSTR(AttributeValue
) = SysAllocString(value
);
231 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
234 ERR("GetAttribute failed: %08x\n", nsres
);
238 nsAString_Finish(&value_str
);
243 static HRESULT WINAPI
HTMLElement_removeAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
244 LONG lFlags
, VARIANT_BOOL
*pfSuccess
)
246 HTMLElement
*This
= HTMLELEM_THIS(iface
);
247 FIXME("(%p)->()\n", This
);
251 static HRESULT WINAPI
HTMLElement_put_className(IHTMLElement
*iface
, BSTR v
)
253 HTMLElement
*This
= HTMLELEM_THIS(iface
);
254 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
258 static HRESULT WINAPI
HTMLElement_get_className(IHTMLElement
*iface
, BSTR
*p
)
260 HTMLElement
*This
= HTMLELEM_THIS(iface
);
265 TRACE("(%p)->(%p)\n", This
, p
);
268 FIXME("NULL nselem\n");
272 nsAString_Init(&class_str
, NULL
);
273 nsres
= nsIDOMHTMLElement_GetClassName(This
->nselem
, &class_str
);
275 if(NS_SUCCEEDED(nsres
)) {
276 const PRUnichar
*class;
277 nsAString_GetData(&class_str
, &class);
278 *p
= SysAllocString(class);
280 ERR("GetClassName failed: %08x\n", nsres
);
284 nsAString_Finish(&class_str
);
286 TRACE("className=%s\n", debugstr_w(*p
));
290 static HRESULT WINAPI
HTMLElement_put_id(IHTMLElement
*iface
, BSTR v
)
292 HTMLElement
*This
= HTMLELEM_THIS(iface
);
296 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
299 FIXME("nselem == NULL\n");
303 nsAString_Init(&id_str
, v
);
304 nsres
= nsIDOMHTMLElement_SetId(This
->nselem
, &id_str
);
305 nsAString_Finish(&id_str
);
307 ERR("SetId failed: %08x\n", nsres
);
312 static HRESULT WINAPI
HTMLElement_get_id(IHTMLElement
*iface
, BSTR
*p
)
314 HTMLElement
*This
= HTMLELEM_THIS(iface
);
319 TRACE("(%p)->(%p)\n", This
, p
);
326 nsAString_Init(&id_str
, NULL
);
327 nsres
= nsIDOMHTMLElement_GetId(This
->nselem
, &id_str
);
328 nsAString_GetData(&id_str
, &id
);
331 ERR("GetId failed: %08x\n", nsres
);
333 *p
= SysAllocString(id
);
335 nsAString_Finish(&id_str
);
339 static HRESULT WINAPI
HTMLElement_get_tagName(IHTMLElement
*iface
, BSTR
*p
)
341 HTMLElement
*This
= HTMLELEM_THIS(iface
);
342 const PRUnichar
*tag
;
346 TRACE("(%p)->(%p)\n", This
, p
);
349 static const WCHAR comment_tagW
[] = {'!',0};
351 WARN("NULL nselem, assuming comment\n");
353 *p
= SysAllocString(comment_tagW
);
357 nsAString_Init(&tag_str
, NULL
);
358 nsres
= nsIDOMHTMLElement_GetTagName(This
->nselem
, &tag_str
);
359 if(NS_SUCCEEDED(nsres
)) {
360 nsAString_GetData(&tag_str
, &tag
);
361 *p
= SysAllocString(tag
);
363 ERR("GetTagName failed: %08x\n", nsres
);
366 nsAString_Finish(&tag_str
);
371 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
373 HTMLElement
*This
= HTMLELEM_THIS(iface
);
374 FIXME("(%p)->(%p)\n", This
, p
);
378 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
380 HTMLElement
*This
= HTMLELEM_THIS(iface
);
381 nsIDOMElementCSSInlineStyle
*nselemstyle
;
382 nsIDOMCSSStyleDeclaration
*nsstyle
;
385 TRACE("(%p)->(%p)\n", This
, p
);
388 FIXME("NULL nselem\n");
392 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
393 (void**)&nselemstyle
);
394 if(NS_FAILED(nsres
)) {
395 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
399 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
400 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
401 if(NS_FAILED(nsres
)) {
402 ERR("GetStyle failed: %08x\n", nsres
);
406 /* FIXME: Store style instead of creating a new instance in each call */
407 *p
= HTMLStyle_Create(nsstyle
);
409 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
413 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
415 HTMLElement
*This
= HTMLELEM_THIS(iface
);
416 FIXME("(%p)->()\n", This
);
420 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
422 HTMLElement
*This
= HTMLELEM_THIS(iface
);
423 FIXME("(%p)->(%p)\n", This
, p
);
427 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
429 HTMLElement
*This
= HTMLELEM_THIS(iface
);
430 FIXME("(%p)->()\n", This
);
434 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
436 HTMLElement
*This
= HTMLELEM_THIS(iface
);
437 FIXME("(%p)->(%p)\n", This
, p
);
441 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
443 HTMLElement
*This
= HTMLELEM_THIS(iface
);
444 FIXME("(%p)->()\n", This
);
448 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
450 HTMLElement
*This
= HTMLELEM_THIS(iface
);
451 FIXME("(%p)->(%p)\n", This
, p
);
455 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
457 HTMLElement
*This
= HTMLELEM_THIS(iface
);
458 FIXME("(%p)->()\n", This
);
462 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
464 HTMLElement
*This
= HTMLELEM_THIS(iface
);
465 FIXME("(%p)->(%p)\n", This
, p
);
469 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
471 HTMLElement
*This
= HTMLELEM_THIS(iface
);
472 FIXME("(%p)->()\n", This
);
476 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
478 HTMLElement
*This
= HTMLELEM_THIS(iface
);
479 FIXME("(%p)->(%p)\n", This
, p
);
483 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
485 HTMLElement
*This
= HTMLELEM_THIS(iface
);
486 FIXME("(%p)->()\n", This
);
490 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
492 HTMLElement
*This
= HTMLELEM_THIS(iface
);
493 FIXME("(%p)->(%p)\n", This
, p
);
497 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
499 HTMLElement
*This
= HTMLELEM_THIS(iface
);
500 FIXME("(%p)->()\n", This
);
504 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
506 HTMLElement
*This
= HTMLELEM_THIS(iface
);
507 FIXME("(%p)->(%p)\n", This
, p
);
511 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
513 HTMLElement
*This
= HTMLELEM_THIS(iface
);
514 FIXME("(%p)->()\n", This
);
518 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
520 HTMLElement
*This
= HTMLELEM_THIS(iface
);
521 FIXME("(%p)->(%p)\n", This
, p
);
525 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
527 HTMLElement
*This
= HTMLELEM_THIS(iface
);
528 FIXME("(%p)->()\n", This
);
532 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
534 HTMLElement
*This
= HTMLELEM_THIS(iface
);
535 FIXME("(%p)->(%p)\n", This
, p
);
539 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
541 HTMLElement
*This
= HTMLELEM_THIS(iface
);
542 FIXME("(%p)->()\n", This
);
546 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
548 HTMLElement
*This
= HTMLELEM_THIS(iface
);
549 FIXME("(%p)->(%p)\n", This
, p
);
553 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
555 HTMLElement
*This
= HTMLELEM_THIS(iface
);
556 FIXME("(%p)->()\n", This
);
560 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
562 HTMLElement
*This
= HTMLELEM_THIS(iface
);
563 FIXME("(%p)->(%p)\n", This
, p
);
567 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
569 HTMLElement
*This
= HTMLELEM_THIS(iface
);
570 FIXME("(%p)->(%p)\n", This
, p
);
574 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
576 HTMLElement
*This
= HTMLELEM_THIS(iface
);
577 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
581 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
583 HTMLElement
*This
= HTMLELEM_THIS(iface
);
584 FIXME("(%p)->(%p)\n", This
, p
);
588 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
590 HTMLElement
*This
= HTMLELEM_THIS(iface
);
591 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
595 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
597 HTMLElement
*This
= HTMLELEM_THIS(iface
);
598 FIXME("(%p)->(%p)\n", This
, p
);
602 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
604 HTMLElement
*This
= HTMLELEM_THIS(iface
);
605 FIXME("(%p)->()\n", This
);
609 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
611 HTMLElement
*This
= HTMLELEM_THIS(iface
);
612 FIXME("(%p)->(%p)\n", This
, p
);
616 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
618 HTMLElement
*This
= HTMLELEM_THIS(iface
);
619 FIXME("(%p)->()\n", This
);
623 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
624 VARIANT_BOOL
*pfResult
)
626 HTMLElement
*This
= HTMLELEM_THIS(iface
);
627 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
631 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
633 HTMLElement
*This
= HTMLELEM_THIS(iface
);
634 FIXME("(%p)->(%p)\n", This
, p
);
638 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
640 HTMLElement
*This
= HTMLELEM_THIS(iface
);
641 FIXME("(%p)->(%p)\n", This
, p
);
645 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
647 HTMLElement
*This
= HTMLELEM_THIS(iface
);
648 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
652 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
654 HTMLElement
*This
= HTMLELEM_THIS(iface
);
655 FIXME("(%p)->(%p)\n", This
, p
);
659 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
661 HTMLElement
*This
= HTMLELEM_THIS(iface
);
662 FIXME("(%p)->(%p)\n", This
, p
);
666 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
668 HTMLElement
*This
= HTMLELEM_THIS(iface
);
669 FIXME("(%p)->(%p)\n", This
, p
);
673 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
675 HTMLElement
*This
= HTMLELEM_THIS(iface
);
676 FIXME("(%p)->(%p)\n", This
, p
);
680 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
682 HTMLElement
*This
= HTMLELEM_THIS(iface
);
683 FIXME("(%p)->(%p)\n", This
, p
);
687 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
689 HTMLElement
*This
= HTMLELEM_THIS(iface
);
690 FIXME("(%p)->(%p)\n", This
, p
);
694 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
696 HTMLElement
*This
= HTMLELEM_THIS(iface
);
697 nsIDOMNSHTMLElement
*nselem
;
701 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
704 FIXME("NULL nselem\n");
708 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
709 if(NS_FAILED(nsres
)) {
710 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
714 nsAString_Init(&html_str
, v
);
715 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
716 nsAString_Finish(&html_str
);
718 if(NS_FAILED(nsres
)) {
719 FIXME("SetInnerHtml failed %08x\n", nsres
);
726 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
728 HTMLElement
*This
= HTMLELEM_THIS(iface
);
729 FIXME("(%p)->(%p)\n", This
, p
);
733 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
735 HTMLElement
*This
= HTMLELEM_THIS(iface
);
736 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
740 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
742 HTMLElement
*This
= HTMLELEM_THIS(iface
);
743 FIXME("(%p)->(%p)\n", This
, p
);
747 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
749 HTMLElement
*This
= HTMLELEM_THIS(iface
);
750 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
754 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
756 HTMLElement
*This
= HTMLELEM_THIS(iface
);
757 FIXME("(%p)->(%p)\n", This
, p
);
761 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
763 HTMLElement
*This
= HTMLELEM_THIS(iface
);
764 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
768 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
770 HTMLElement
*This
= HTMLELEM_THIS(iface
);
771 FIXME("(%p)->(%p)\n", This
, p
);
775 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
777 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
778 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
779 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
780 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
784 FIXME("NULL nselem\n");
788 if (!strcmpiW(where
, wszBeforeBegin
))
792 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
793 if (!parent
) return E_INVALIDARG
;
794 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
795 (nsIDOMNode
*)This
->nselem
, &unused
);
796 if (unused
) nsIDOMNode_Release(unused
);
797 nsIDOMNode_Release(parent
);
799 else if (!strcmpiW(where
, wszAfterBegin
))
802 nsIDOMNode
*first_child
;
803 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
804 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
805 if (unused
) nsIDOMNode_Release(unused
);
806 if (first_child
) nsIDOMNode_Release(first_child
);
808 else if (!strcmpiW(where
, wszBeforeEnd
))
811 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
812 if (unused
) nsIDOMNode_Release(unused
);
814 else if (!strcmpiW(where
, wszAfterEnd
))
817 nsIDOMNode
*next_sibling
;
819 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
820 if (!parent
) return E_INVALIDARG
;
822 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
825 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
826 nsIDOMNode_Release(next_sibling
);
829 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
830 nsIDOMNode_Release(parent
);
831 if (unused
) nsIDOMNode_Release(unused
);
835 ERR("invalid where: %s\n", debugstr_w(where
));
839 if (NS_FAILED(nsres
))
845 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
848 HTMLElement
*This
= HTMLELEM_THIS(iface
);
850 nsIDOMDocument
*nsdoc
;
851 nsIDOMDocumentRange
*nsdocrange
;
853 nsIDOMNSRange
*nsrange
;
858 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
860 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
863 ERR("GetDocument failed: %08x\n", nsres
);
867 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
868 nsIDOMDocument_Release(nsdoc
);
871 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
874 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
875 nsIDOMDocumentRange_Release(nsdocrange
);
878 ERR("CreateRange failed: %08x\n", nsres
);
882 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
884 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
885 nsIDOMRange_Release(range
);
888 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
892 nsAString_Init(&ns_html
, html
);
894 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
895 nsIDOMNSRange_Release(nsrange
);
896 nsAString_Finish(&ns_html
);
898 if(NS_FAILED(nsres
) || !nsnode
)
900 ERR("CreateTextNode failed: %08x\n", nsres
);
904 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
905 nsIDOMNode_Release(nsnode
);
910 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
913 HTMLElement
*This
= HTMLELEM_THIS(iface
);
915 nsIDOMDocument
*nsdoc
;
920 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
922 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
923 if(NS_FAILED(nsres
) || !nsdoc
)
925 ERR("GetDocument failed: %08x\n", nsres
);
929 nsAString_Init(&ns_text
, text
);
931 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
932 nsIDOMDocument_Release(nsdoc
);
933 nsAString_Finish(&ns_text
);
935 if(NS_FAILED(nsres
) || !nsnode
)
937 ERR("CreateTextNode failed: %08x\n", nsres
);
941 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
942 nsIDOMNode_Release(nsnode
);
947 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
949 HTMLElement
*This
= HTMLELEM_THIS(iface
);
950 FIXME("(%p)->(%p)\n", This
, p
);
954 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
956 HTMLElement
*This
= HTMLELEM_THIS(iface
);
957 FIXME("(%p)->(%p)\n", This
, p
);
961 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
963 HTMLElement
*This
= HTMLELEM_THIS(iface
);
964 FIXME("(%p)\n", This
);
968 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
969 IHTMLFiltersCollection
**p
)
971 HTMLElement
*This
= HTMLELEM_THIS(iface
);
972 FIXME("(%p)->(%p)\n", This
, p
);
976 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
978 HTMLElement
*This
= HTMLELEM_THIS(iface
);
979 FIXME("(%p)->()\n", This
);
983 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
985 HTMLElement
*This
= HTMLELEM_THIS(iface
);
986 FIXME("(%p)->(%p)\n", This
, p
);
990 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
992 HTMLElement
*This
= HTMLELEM_THIS(iface
);
993 FIXME("(%p)->(%p)\n", This
, String
);
997 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
999 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1000 FIXME("(%p)->()\n", This
);
1004 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
1006 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1007 FIXME("(%p)->(%p)\n", This
, p
);
1011 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
1013 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1014 FIXME("(%p)->()\n", This
);
1018 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
1020 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1021 FIXME("(%p)->(%p)\n", This
, p
);
1025 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
1027 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1028 FIXME("(%p)->()\n", This
);
1032 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
1034 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1035 FIXME("(%p)->(%p)\n", This
, p
);
1039 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
1041 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1042 FIXME("(%p)->()\n", This
);
1046 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
1048 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1049 FIXME("(%p)->(%p)\n", This
, p
);
1053 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
1055 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1056 FIXME("(%p)->()\n", This
);
1060 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
1062 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1063 FIXME("(%p)->(%p)\n", This
, p
);
1067 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
1069 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1070 FIXME("(%p)->()\n", This
);
1074 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
1076 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1077 FIXME("(%p)->(%p)\n", This
, p
);
1081 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
1083 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1084 FIXME("(%p)->()\n", This
);
1088 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
1090 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1091 FIXME("(%p)->(%p)\n", This
, p
);
1095 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
1097 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1098 FIXME("(%p)->()\n", This
);
1102 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1104 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1105 FIXME("(%p)->(%p)\n", This
, p
);
1109 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1111 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1112 FIXME("(%p)->()\n", This
);
1116 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1118 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1119 FIXME("(%p)->(%p)\n", This
, p
);
1123 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1125 nsIDOMNodeList
*nsnode_list
;
1127 PRUint32 list_len
= 0, i
;
1130 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1131 if(NS_FAILED(nsres
)) {
1132 ERR("GetChildNodes failed: %08x\n", nsres
);
1136 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1140 buf
->size
= list_len
;
1141 buf
->buf
= heap_alloc(buf
->size
*sizeof(HTMLElement
**));
1143 for(i
=0; i
<list_len
; i
++) {
1144 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1145 if(NS_FAILED(nsres
)) {
1146 ERR("Item failed: %08x\n", nsres
);
1150 if(is_elem_node(iter
))
1151 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
, TRUE
)));
1155 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1157 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1158 elem_vector buf
= {NULL
, 0, 0};
1160 TRACE("(%p)->(%p)\n", This
, p
);
1162 create_child_list(This
->node
.doc
, This
, &buf
);
1164 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1168 static void create_all_list(HTMLDocument
*doc
, HTMLDOMNode
*elem
, elem_vector
*buf
)
1170 nsIDOMNodeList
*nsnode_list
;
1172 PRUint32 list_len
= 0, i
;
1175 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
1176 if(NS_FAILED(nsres
)) {
1177 ERR("GetChildNodes failed: %08x\n", nsres
);
1181 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1185 for(i
=0; i
<list_len
; i
++) {
1186 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1187 if(NS_FAILED(nsres
)) {
1188 ERR("Item failed: %08x\n", nsres
);
1192 if(is_elem_node(iter
)) {
1193 HTMLDOMNode
*node
= get_node(doc
, iter
, TRUE
);
1195 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1196 create_all_list(doc
, node
, buf
);
1201 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1203 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1204 elem_vector buf
= {NULL
, 0, 8};
1206 TRACE("(%p)->(%p)\n", This
, p
);
1208 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1210 create_all_list(This
->node
.doc
, &This
->node
, &buf
);
1211 elem_vector_normalize(&buf
);
1213 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1217 #undef HTMLELEM_THIS
1219 static const IHTMLElementVtbl HTMLElementVtbl
= {
1220 HTMLElement_QueryInterface
,
1222 HTMLElement_Release
,
1223 HTMLElement_GetTypeInfoCount
,
1224 HTMLElement_GetTypeInfo
,
1225 HTMLElement_GetIDsOfNames
,
1227 HTMLElement_setAttribute
,
1228 HTMLElement_getAttribute
,
1229 HTMLElement_removeAttribute
,
1230 HTMLElement_put_className
,
1231 HTMLElement_get_className
,
1234 HTMLElement_get_tagName
,
1235 HTMLElement_get_parentElement
,
1236 HTMLElement_get_style
,
1237 HTMLElement_put_onhelp
,
1238 HTMLElement_get_onhelp
,
1239 HTMLElement_put_onclick
,
1240 HTMLElement_get_onclick
,
1241 HTMLElement_put_ondblclick
,
1242 HTMLElement_get_ondblclick
,
1243 HTMLElement_put_onkeydown
,
1244 HTMLElement_get_onkeydown
,
1245 HTMLElement_put_onkeyup
,
1246 HTMLElement_get_onkeyup
,
1247 HTMLElement_put_onkeypress
,
1248 HTMLElement_get_onkeypress
,
1249 HTMLElement_put_onmouseout
,
1250 HTMLElement_get_onmouseout
,
1251 HTMLElement_put_onmouseover
,
1252 HTMLElement_get_onmouseover
,
1253 HTMLElement_put_onmousemove
,
1254 HTMLElement_get_onmousemove
,
1255 HTMLElement_put_onmousedown
,
1256 HTMLElement_get_onmousedown
,
1257 HTMLElement_put_onmouseup
,
1258 HTMLElement_get_onmouseup
,
1259 HTMLElement_get_document
,
1260 HTMLElement_put_title
,
1261 HTMLElement_get_title
,
1262 HTMLElement_put_language
,
1263 HTMLElement_get_language
,
1264 HTMLElement_put_onselectstart
,
1265 HTMLElement_get_onselectstart
,
1266 HTMLElement_scrollIntoView
,
1267 HTMLElement_contains
,
1268 HTMLElement_get_sourceIndex
,
1269 HTMLElement_get_recordNumber
,
1270 HTMLElement_put_lang
,
1271 HTMLElement_get_lang
,
1272 HTMLElement_get_offsetLeft
,
1273 HTMLElement_get_offsetTop
,
1274 HTMLElement_get_offsetWidth
,
1275 HTMLElement_get_offsetHeight
,
1276 HTMLElement_get_offsetParent
,
1277 HTMLElement_put_innerHTML
,
1278 HTMLElement_get_innerHTML
,
1279 HTMLElement_put_innerText
,
1280 HTMLElement_get_innerText
,
1281 HTMLElement_put_outerHTML
,
1282 HTMLElement_get_outerHTML
,
1283 HTMLElement_put_outerText
,
1284 HTMLElement_get_outerText
,
1285 HTMLElement_insertAdjacentHTML
,
1286 HTMLElement_insertAdjacentText
,
1287 HTMLElement_get_parentTextEdit
,
1288 HTMLElement_get_isTextEdit
,
1290 HTMLElement_get_filters
,
1291 HTMLElement_put_ondragstart
,
1292 HTMLElement_get_ondragstart
,
1293 HTMLElement_toString
,
1294 HTMLElement_put_onbeforeupdate
,
1295 HTMLElement_get_onbeforeupdate
,
1296 HTMLElement_put_onafterupdate
,
1297 HTMLElement_get_onafterupdate
,
1298 HTMLElement_put_onerrorupdate
,
1299 HTMLElement_get_onerrorupdate
,
1300 HTMLElement_put_onrowexit
,
1301 HTMLElement_get_onrowexit
,
1302 HTMLElement_put_onrowenter
,
1303 HTMLElement_get_onrowenter
,
1304 HTMLElement_put_ondatasetchanged
,
1305 HTMLElement_get_ondatasetchanged
,
1306 HTMLElement_put_ondataavailable
,
1307 HTMLElement_get_ondataavailable
,
1308 HTMLElement_put_ondatasetcomplete
,
1309 HTMLElement_get_ondatasetcomplete
,
1310 HTMLElement_put_onfilterchange
,
1311 HTMLElement_get_onfilterchange
,
1312 HTMLElement_get_children
,
1316 HRESULT
HTMLElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1318 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1322 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1323 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1324 *ppv
= HTMLELEM(This
);
1325 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1326 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1327 *ppv
= HTMLELEM(This
);
1328 }else if(IsEqualGUID(&IID_IHTMLElement
, riid
)) {
1329 TRACE("(%p)->(IID_IHTMLElement %p)\n", This
, ppv
);
1330 *ppv
= HTMLELEM(This
);
1331 }else if(IsEqualGUID(&IID_IHTMLElement2
, riid
)) {
1332 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This
, ppv
);
1333 *ppv
= HTMLELEM2(This
);
1334 }else if(IsEqualGUID(&IID_IConnectionPointContainer
, riid
)) {
1335 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This
, ppv
);
1336 *ppv
= CONPTCONT(&This
->cp_container
);
1340 IHTMLElement_AddRef(HTMLELEM(This
));
1344 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
1347 void HTMLElement_destructor(HTMLDOMNode
*iface
)
1349 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1351 ConnectionPointContainer_Destroy(&This
->cp_container
);
1354 nsIDOMHTMLElement_Release(This
->nselem
);
1356 HTMLDOMNode_destructor(&This
->node
);
1359 static const NodeImplVtbl HTMLElementImplVtbl
= {
1361 HTMLElement_destructor
1364 static const tid_t HTMLElement_iface_tids
[] = {
1371 static dispex_static_data_t HTMLElement_dispex
= {
1373 DispHTMLUnknownElement_tid
,
1375 HTMLElement_iface_tids
1378 void HTMLElement_Init(HTMLElement
*This
)
1380 This
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1382 ConnectionPointContainer_Init(&This
->cp_container
, (IUnknown
*)HTMLELEM(This
));
1384 HTMLElement2_Init(This
);
1386 if(!This
->node
.dispex
.data
)
1387 init_dispex(&This
->node
.dispex
, (IUnknown
*)HTMLELEM(This
), &HTMLElement_dispex
);
1390 HTMLElement
*HTMLElement_Create(nsIDOMNode
*nsnode
)
1392 nsIDOMHTMLElement
*nselem
;
1393 HTMLElement
*ret
= NULL
;
1394 nsAString class_name_str
;
1395 const PRUnichar
*class_name
;
1398 static const WCHAR wszA
[] = {'A',0};
1399 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1400 static const WCHAR wszIMG
[] = {'I','M','G',0};
1401 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1402 static const WCHAR wszOPTION
[] = {'O','P','T','I','O','N',0};
1403 static const WCHAR wszSCRIPT
[] = {'S','C','R','I','P','T',0};
1404 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1405 static const WCHAR wszTABLE
[] = {'T','A','B','L','E',0};
1406 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1408 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1409 if(NS_FAILED(nsres
))
1412 nsAString_Init(&class_name_str
, NULL
);
1413 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1415 nsAString_GetData(&class_name_str
, &class_name
);
1417 if(!strcmpW(class_name
, wszA
))
1418 ret
= HTMLAnchorElement_Create(nselem
);
1419 else if(!strcmpW(class_name
, wszBODY
))
1420 ret
= HTMLBodyElement_Create(nselem
);
1421 else if(!strcmpW(class_name
, wszIMG
))
1422 ret
= HTMLImgElement_Create(nselem
);
1423 else if(!strcmpW(class_name
, wszINPUT
))
1424 ret
= HTMLInputElement_Create(nselem
);
1425 else if(!strcmpW(class_name
, wszOPTION
))
1426 ret
= HTMLOptionElement_Create(nselem
);
1427 else if(!strcmpW(class_name
, wszSCRIPT
))
1428 ret
= HTMLScriptElement_Create(nselem
);
1429 else if(!strcmpW(class_name
, wszSELECT
))
1430 ret
= HTMLSelectElement_Create(nselem
);
1431 else if(!strcmpW(class_name
, wszTABLE
))
1432 ret
= HTMLTable_Create(nselem
);
1433 else if(!strcmpW(class_name
, wszTEXTAREA
))
1434 ret
= HTMLTextAreaElement_Create(nselem
);
1437 ret
= heap_alloc_zero(sizeof(HTMLElement
));
1438 HTMLElement_Init(ret
);
1439 ret
->node
.vtbl
= &HTMLElementImplVtbl
;
1442 nsAString_Finish(&class_name_str
);
1444 ret
->nselem
= nselem
;
1451 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1454 HTMLElement
**elems
;
1458 } HTMLElementCollection
;
1460 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1462 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1464 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1465 REFIID riid
, void **ppv
)
1467 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1471 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1472 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1473 *ppv
= HTMLELEMCOL(This
);
1474 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1475 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1476 *ppv
= HTMLELEMCOL(This
);
1477 }else if(IsEqualGUID(&IID_IDispatchEx
, riid
)) {
1478 TRACE("(%p)->(IID_IDispatchEx %p)\n", This
, ppv
);
1479 *ppv
= DISPATCHEX(&This
->dispex
);
1480 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1481 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1482 *ppv
= HTMLELEMCOL(This
);
1486 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1490 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1491 return E_NOINTERFACE
;
1494 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1496 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1497 LONG ref
= InterlockedIncrement(&This
->ref
);
1499 TRACE("(%p) ref=%d\n", This
, ref
);
1504 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1506 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1507 LONG ref
= InterlockedDecrement(&This
->ref
);
1509 TRACE("(%p) ref=%d\n", This
, ref
);
1512 IUnknown_Release(This
->ref_unk
);
1513 heap_free(This
->elems
);
1520 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1523 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1524 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1528 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1529 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1531 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1532 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1536 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1537 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1539 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1540 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1545 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1546 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1547 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1549 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1550 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1551 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1555 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1558 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1559 FIXME("(%p)->(%p)\n", This
, String
);
1563 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1566 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1567 FIXME("(%p)->(%ld)\n", This
, v
);
1571 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1574 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1576 TRACE("(%p)->(%p)\n", This
, p
);
1582 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1585 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1586 FIXME("(%p)->(%p)\n", This
, p
);
1590 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
1592 const PRUnichar
*str
;
1593 nsAString nsstr
, nsname
;
1597 static const PRUnichar nameW
[] = {'n','a','m','e',0};
1602 nsAString_Init(&nsstr
, NULL
);
1603 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
1604 nsAString_GetData(&nsstr
, &str
);
1605 if(!strcmpiW(str
, name
)) {
1606 nsAString_Finish(&nsstr
);
1610 nsAString_Init(&nsname
, nameW
);
1611 nsres
= nsIDOMHTMLElement_GetAttribute(elem
->nselem
, &nsname
, &nsstr
);
1612 nsAString_Finish(&nsname
);
1613 if(NS_SUCCEEDED(nsres
)) {
1614 nsAString_GetData(&nsstr
, &str
);
1615 ret
= !strcmpiW(str
, name
);
1618 nsAString_Finish(&nsstr
);
1622 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1623 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1625 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1627 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1631 if(V_VT(&name
) == VT_I4
) {
1632 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1635 return E_INVALIDARG
;
1636 if(V_I4(&name
) >= This
->len
)
1639 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1640 IDispatch_AddRef(*pdisp
);
1641 TRACE("Returning pdisp=%p\n", pdisp
);
1645 if(V_VT(&name
) == VT_BSTR
) {
1648 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1650 if(V_VT(&index
) == VT_I4
) {
1651 LONG idx
= V_I4(&index
);
1653 TRACE("index = %d\n", idx
);
1656 return E_INVALIDARG
;
1658 for(i
=0; i
<This
->len
; i
++) {
1659 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
1663 if(i
!= This
->len
) {
1664 *pdisp
= (IDispatch
*)HTMLELEM(This
->elems
[i
]);
1665 IDispatch_AddRef(*pdisp
);
1670 elem_vector buf
= {NULL
, 0, 8};
1672 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1674 for(i
=0; i
<This
->len
; i
++) {
1675 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)))
1676 elem_vector_add(&buf
, This
->elems
[i
]);
1680 elem_vector_normalize(&buf
);
1681 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1684 *pdisp
= (IDispatch
*)HTMLELEM(buf
.buf
[0]);
1685 IDispatch_AddRef(*pdisp
);
1695 FIXME("unsupported arguments\n");
1696 return E_INVALIDARG
;
1699 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1700 VARIANT tagName
, IDispatch
**pdisp
)
1702 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1705 const PRUnichar
*tag
;
1706 elem_vector buf
= {NULL
, 0, 8};
1708 if(V_VT(&tagName
) != VT_BSTR
) {
1709 WARN("Invalid arg\n");
1710 return DISP_E_MEMBERNOTFOUND
;
1713 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1715 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
*));
1717 nsAString_Init(&tag_str
, NULL
);
1719 for(i
=0; i
<This
->len
; i
++) {
1720 if(!This
->elems
[i
]->nselem
)
1723 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1724 nsAString_GetData(&tag_str
, &tag
);
1726 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1727 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1728 elem_vector_add(&buf
, This
->elems
[i
]);
1731 nsAString_Finish(&tag_str
);
1732 elem_vector_normalize(&buf
);
1734 TRACE("fount %d tags\n", buf
.len
);
1736 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1740 #define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
1742 static HRESULT
HTMLElementCollection_get_dispid(IUnknown
*iface
, BSTR name
, DWORD flags
, DISPID
*dispid
)
1744 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1748 for(ptr
= name
; *ptr
&& isdigitW(*ptr
); ptr
++)
1749 idx
= idx
*10 + (*ptr
-'0');
1751 if(*ptr
|| idx
>= This
->len
)
1752 return DISP_E_UNKNOWNNAME
;
1754 *dispid
= DISPID_ELEMCOL_0
+ idx
;
1755 TRACE("ret %x\n", *dispid
);
1759 static HRESULT
HTMLElementCollection_invoke(IUnknown
*iface
, DISPID id
, LCID lcid
, WORD flags
, DISPPARAMS
*params
,
1760 VARIANT
*res
, EXCEPINFO
*ei
, IServiceProvider
*caller
)
1762 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1765 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This
, id
, lcid
, flags
, params
, res
, ei
, caller
);
1767 idx
= id
- DISPID_ELEMCOL_0
;
1768 if(idx
>= This
->len
)
1769 return DISP_E_UNKNOWNNAME
;
1772 case INVOKE_PROPERTYGET
:
1773 V_VT(res
) = VT_DISPATCH
;
1774 V_DISPATCH(res
) = (IDispatch
*)HTMLELEM(This
->elems
[idx
]);
1775 IHTMLElement_AddRef(HTMLELEM(This
->elems
[idx
]));
1778 FIXME("unimplemented flags %x\n", flags
);
1787 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1788 HTMLElementCollection_QueryInterface
,
1789 HTMLElementCollection_AddRef
,
1790 HTMLElementCollection_Release
,
1791 HTMLElementCollection_GetTypeInfoCount
,
1792 HTMLElementCollection_GetTypeInfo
,
1793 HTMLElementCollection_GetIDsOfNames
,
1794 HTMLElementCollection_Invoke
,
1795 HTMLElementCollection_toString
,
1796 HTMLElementCollection_put_length
,
1797 HTMLElementCollection_get_length
,
1798 HTMLElementCollection_get__newEnum
,
1799 HTMLElementCollection_item
,
1800 HTMLElementCollection_tags
1803 static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl
= {
1804 HTMLElementCollection_get_dispid
,
1805 HTMLElementCollection_invoke
1808 static const tid_t HTMLElementCollection_iface_tids
[] = {
1809 IHTMLElementCollection_tid
,
1812 static dispex_static_data_t HTMLElementCollection_dispex
= {
1813 &HTMLElementColection_dispex_vtbl
,
1814 DispHTMLElementCollection_tid
,
1816 HTMLElementCollection_iface_tids
1819 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
)
1821 elem_vector buf
= {NULL
, 0, 8};
1823 buf
.buf
= heap_alloc(buf
.size
*sizeof(HTMLElement
**));
1825 elem_vector_add(&buf
, HTMLELEM_NODE_THIS(node
));
1826 create_all_list(node
->doc
, node
, &buf
);
1827 elem_vector_normalize(&buf
);
1829 return HTMLElementCollection_Create((IUnknown
*)HTMLDOMNODE(node
), buf
.buf
, buf
.len
);
1832 static IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*ref_unk
,
1833 HTMLElement
**elems
, DWORD len
)
1835 HTMLElementCollection
*ret
= heap_alloc(sizeof(HTMLElementCollection
));
1837 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1842 init_dispex(&ret
->dispex
, (IUnknown
*)HTMLELEMCOL(ret
), &HTMLElementCollection_dispex
);
1844 IUnknown_AddRef(ref_unk
);
1845 ret
->ref_unk
= ref_unk
;
1847 TRACE("ret=%p len=%d\n", ret
, len
);
1849 return HTMLELEMCOL(ret
);