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
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
37 #include "mshtml_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
41 static HRESULT
HTMLElementCollection_Create(IUnknown
*,HTMLElement
**,DWORD
,IDispatch
**);
49 static void elem_vector_add(elem_vector
*buf
, HTMLElement
*elem
)
51 if(buf
->len
== buf
->size
) {
53 buf
->buf
= mshtml_realloc(buf
->buf
, buf
->size
*sizeof(HTMLElement
**));
56 buf
->buf
[buf
->len
++] = elem
;
59 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
61 #define HTMLELEM_NODE_THIS(node) ((HTMLElement *) node)
63 static HRESULT WINAPI
HTMLElement_QueryInterface(IHTMLElement
*iface
,
64 REFIID riid
, void **ppv
)
66 HTMLElement
*This
= HTMLELEM_THIS(iface
);
70 return IUnknown_QueryInterface(This
->impl
, riid
, ppv
);
72 hres
= HTMLElement_QI(This
, riid
, ppv
);
74 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
79 static ULONG WINAPI
HTMLElement_AddRef(IHTMLElement
*iface
)
81 HTMLElement
*This
= HTMLELEM_THIS(iface
);
83 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->node
));
86 static ULONG WINAPI
HTMLElement_Release(IHTMLElement
*iface
)
88 HTMLElement
*This
= HTMLELEM_THIS(iface
);
90 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->node
));
93 static HRESULT WINAPI
HTMLElement_GetTypeInfoCount(IHTMLElement
*iface
, UINT
*pctinfo
)
95 HTMLElement
*This
= HTMLELEM_THIS(iface
);
96 FIXME("(%p)->(%p)\n", This
, pctinfo
);
100 static HRESULT WINAPI
HTMLElement_GetTypeInfo(IHTMLElement
*iface
, UINT iTInfo
,
101 LCID lcid
, ITypeInfo
**ppTInfo
)
103 HTMLElement
*This
= HTMLELEM_THIS(iface
);
104 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
108 static HRESULT WINAPI
HTMLElement_GetIDsOfNames(IHTMLElement
*iface
, REFIID riid
,
109 LPOLESTR
*rgszNames
, UINT cNames
,
110 LCID lcid
, DISPID
*rgDispId
)
112 HTMLElement
*This
= HTMLELEM_THIS(iface
);
113 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
118 static HRESULT WINAPI
HTMLElement_Invoke(IHTMLElement
*iface
, DISPID dispIdMember
,
119 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
120 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
122 HTMLElement
*This
= HTMLELEM_THIS(iface
);
123 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
124 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
128 static HRESULT WINAPI
HTMLElement_setAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
129 VARIANT AttributeValue
, LONG lFlags
)
131 HTMLElement
*This
= HTMLELEM_THIS(iface
);
136 VARIANT AttributeValueChanged
;
138 WARN("(%p)->(%s . %08x)\n", This
, debugstr_w(strAttributeName
), lFlags
);
140 VariantInit(&AttributeValueChanged
);
142 hres
= VariantChangeType(&AttributeValueChanged
, &AttributeValue
, 0, VT_BSTR
);
144 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue
));
148 nsAString_Init(&attr_str
, strAttributeName
);
149 nsAString_Init(&value_str
, V_BSTR(&AttributeValueChanged
));
151 TRACE("setting %s to %s\n", debugstr_w(strAttributeName
),
152 debugstr_w(V_BSTR(&AttributeValueChanged
)));
154 nsres
= nsIDOMHTMLElement_SetAttribute(This
->nselem
, &attr_str
, &value_str
);
155 nsAString_Finish(&attr_str
);
156 nsAString_Finish(&value_str
);
158 if(NS_SUCCEEDED(nsres
)) {
161 ERR("SetAttribute failed: %08x\n", nsres
);
168 static HRESULT WINAPI
HTMLElement_getAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
169 LONG lFlags
, VARIANT
*AttributeValue
)
171 HTMLElement
*This
= HTMLELEM_THIS(iface
);
174 const PRUnichar
*value
;
178 WARN("(%p)->(%s %08x %p)\n", This
, debugstr_w(strAttributeName
), lFlags
, AttributeValue
);
180 VariantInit(AttributeValue
);
182 nsAString_Init(&attr_str
, strAttributeName
);
183 nsAString_Init(&value_str
, NULL
);
185 nsres
= nsIDOMHTMLElement_GetAttribute(This
->nselem
, &attr_str
, &value_str
);
186 nsAString_Finish(&attr_str
);
188 if(NS_SUCCEEDED(nsres
)) {
189 static const WCHAR wszSRC
[] = {'s','r','c',0};
190 nsAString_GetData(&value_str
, &value
, NULL
);
191 if(!strcmpiW(strAttributeName
, wszSRC
))
196 hres
= IHTMLDocument2_get_URL(HTMLDOC(This
->node
.doc
), &bstrBaseUrl
);
197 if(SUCCEEDED(hres
)) {
198 hres
= CoInternetCombineUrl(bstrBaseUrl
, value
,
199 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
200 buffer
, sizeof(buffer
)/sizeof(WCHAR
), &len
, 0);
201 SysFreeString(bstrBaseUrl
);
202 if(SUCCEEDED(hres
)) {
203 V_VT(AttributeValue
) = VT_BSTR
;
204 V_BSTR(AttributeValue
) = SysAllocString(buffer
);
205 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
209 V_VT(AttributeValue
) = VT_BSTR
;
210 V_BSTR(AttributeValue
) = SysAllocString(value
);
211 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
214 ERR("GetAttribute failed: %08x\n", nsres
);
218 nsAString_Finish(&value_str
);
223 static HRESULT WINAPI
HTMLElement_removeAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
224 LONG lFlags
, VARIANT_BOOL
*pfSuccess
)
226 HTMLElement
*This
= HTMLELEM_THIS(iface
);
227 FIXME("(%p)->()\n", This
);
231 static HRESULT WINAPI
HTMLElement_put_className(IHTMLElement
*iface
, BSTR v
)
233 HTMLElement
*This
= HTMLELEM_THIS(iface
);
234 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
238 static HRESULT WINAPI
HTMLElement_get_className(IHTMLElement
*iface
, BSTR
*p
)
240 HTMLElement
*This
= HTMLELEM_THIS(iface
);
245 TRACE("(%p)->(%p)\n", This
, p
);
247 nsAString_Init(&class_str
, NULL
);
248 nsres
= nsIDOMHTMLElement_GetClassName(This
->nselem
, &class_str
);
250 if(NS_SUCCEEDED(nsres
)) {
251 const PRUnichar
*class;
252 nsAString_GetData(&class_str
, &class, NULL
);
253 *p
= SysAllocString(class);
255 ERR("GetClassName failed: %08x\n", nsres
);
259 nsAString_Finish(&class_str
);
261 TRACE("className=%s\n", debugstr_w(*p
));
265 static HRESULT WINAPI
HTMLElement_put_id(IHTMLElement
*iface
, BSTR v
)
267 HTMLElement
*This
= HTMLELEM_THIS(iface
);
268 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
272 static HRESULT WINAPI
HTMLElement_get_id(IHTMLElement
*iface
, BSTR
*p
)
274 HTMLElement
*This
= HTMLELEM_THIS(iface
);
275 FIXME("(%p)->(%p)\n", This
, p
);
279 static HRESULT WINAPI
HTMLElement_get_tagName(IHTMLElement
*iface
, BSTR
*p
)
281 HTMLElement
*This
= HTMLELEM_THIS(iface
);
282 FIXME("(%p)->(%p)\n", This
, p
);
286 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
288 HTMLElement
*This
= HTMLELEM_THIS(iface
);
289 FIXME("(%p)->(%p)\n", This
, p
);
293 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
295 HTMLElement
*This
= HTMLELEM_THIS(iface
);
296 nsIDOMElementCSSInlineStyle
*nselemstyle
;
297 nsIDOMCSSStyleDeclaration
*nsstyle
;
300 TRACE("(%p)->(%p)\n", This
, p
);
302 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
303 (void**)&nselemstyle
);
304 if(NS_FAILED(nsres
)) {
305 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
309 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
310 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
311 if(NS_FAILED(nsres
)) {
312 ERR("GetStyle failed: %08x\n", nsres
);
316 /* FIXME: Store style instead of creating a new instance in each call */
317 *p
= HTMLStyle_Create(nsstyle
);
319 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
323 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
325 HTMLElement
*This
= HTMLELEM_THIS(iface
);
326 FIXME("(%p)->()\n", This
);
330 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
332 HTMLElement
*This
= HTMLELEM_THIS(iface
);
333 FIXME("(%p)->(%p)\n", This
, p
);
337 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
339 HTMLElement
*This
= HTMLELEM_THIS(iface
);
340 FIXME("(%p)->()\n", This
);
344 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
346 HTMLElement
*This
= HTMLELEM_THIS(iface
);
347 FIXME("(%p)->(%p)\n", This
, p
);
351 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
353 HTMLElement
*This
= HTMLELEM_THIS(iface
);
354 FIXME("(%p)->()\n", This
);
358 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
360 HTMLElement
*This
= HTMLELEM_THIS(iface
);
361 FIXME("(%p)->(%p)\n", This
, p
);
365 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
367 HTMLElement
*This
= HTMLELEM_THIS(iface
);
368 FIXME("(%p)->()\n", This
);
372 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
374 HTMLElement
*This
= HTMLELEM_THIS(iface
);
375 FIXME("(%p)->(%p)\n", This
, p
);
379 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
381 HTMLElement
*This
= HTMLELEM_THIS(iface
);
382 FIXME("(%p)->()\n", This
);
386 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
388 HTMLElement
*This
= HTMLELEM_THIS(iface
);
389 FIXME("(%p)->(%p)\n", This
, p
);
393 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
395 HTMLElement
*This
= HTMLELEM_THIS(iface
);
396 FIXME("(%p)->()\n", This
);
400 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
402 HTMLElement
*This
= HTMLELEM_THIS(iface
);
403 FIXME("(%p)->(%p)\n", This
, p
);
407 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
409 HTMLElement
*This
= HTMLELEM_THIS(iface
);
410 FIXME("(%p)->()\n", This
);
414 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
416 HTMLElement
*This
= HTMLELEM_THIS(iface
);
417 FIXME("(%p)->(%p)\n", This
, p
);
421 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
423 HTMLElement
*This
= HTMLELEM_THIS(iface
);
424 FIXME("(%p)->()\n", This
);
428 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
430 HTMLElement
*This
= HTMLELEM_THIS(iface
);
431 FIXME("(%p)->(%p)\n", This
, p
);
435 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
437 HTMLElement
*This
= HTMLELEM_THIS(iface
);
438 FIXME("(%p)->()\n", This
);
442 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
444 HTMLElement
*This
= HTMLELEM_THIS(iface
);
445 FIXME("(%p)->(%p)\n", This
, p
);
449 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
451 HTMLElement
*This
= HTMLELEM_THIS(iface
);
452 FIXME("(%p)->()\n", This
);
456 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
458 HTMLElement
*This
= HTMLELEM_THIS(iface
);
459 FIXME("(%p)->(%p)\n", This
, p
);
463 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
465 HTMLElement
*This
= HTMLELEM_THIS(iface
);
466 FIXME("(%p)->()\n", This
);
470 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
472 HTMLElement
*This
= HTMLELEM_THIS(iface
);
473 FIXME("(%p)->(%p)\n", This
, p
);
477 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
479 HTMLElement
*This
= HTMLELEM_THIS(iface
);
480 FIXME("(%p)->(%p)\n", This
, p
);
484 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
486 HTMLElement
*This
= HTMLELEM_THIS(iface
);
487 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
491 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
493 HTMLElement
*This
= HTMLELEM_THIS(iface
);
494 FIXME("(%p)->(%p)\n", This
, p
);
498 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
500 HTMLElement
*This
= HTMLELEM_THIS(iface
);
501 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
505 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
507 HTMLElement
*This
= HTMLELEM_THIS(iface
);
508 FIXME("(%p)->(%p)\n", This
, p
);
512 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
514 HTMLElement
*This
= HTMLELEM_THIS(iface
);
515 FIXME("(%p)->()\n", This
);
519 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
521 HTMLElement
*This
= HTMLELEM_THIS(iface
);
522 FIXME("(%p)->(%p)\n", This
, p
);
526 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
528 HTMLElement
*This
= HTMLELEM_THIS(iface
);
529 FIXME("(%p)->()\n", This
);
533 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
534 VARIANT_BOOL
*pfResult
)
536 HTMLElement
*This
= HTMLELEM_THIS(iface
);
537 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
541 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
543 HTMLElement
*This
= HTMLELEM_THIS(iface
);
544 FIXME("(%p)->(%p)\n", This
, p
);
548 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
550 HTMLElement
*This
= HTMLELEM_THIS(iface
);
551 FIXME("(%p)->(%p)\n", This
, p
);
555 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
557 HTMLElement
*This
= HTMLELEM_THIS(iface
);
558 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
562 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
564 HTMLElement
*This
= HTMLELEM_THIS(iface
);
565 FIXME("(%p)->(%p)\n", This
, p
);
569 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
571 HTMLElement
*This
= HTMLELEM_THIS(iface
);
572 FIXME("(%p)->(%p)\n", This
, p
);
576 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
578 HTMLElement
*This
= HTMLELEM_THIS(iface
);
579 FIXME("(%p)->(%p)\n", This
, p
);
583 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
585 HTMLElement
*This
= HTMLELEM_THIS(iface
);
586 FIXME("(%p)->(%p)\n", This
, p
);
590 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
592 HTMLElement
*This
= HTMLELEM_THIS(iface
);
593 FIXME("(%p)->(%p)\n", This
, p
);
597 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
599 HTMLElement
*This
= HTMLELEM_THIS(iface
);
600 FIXME("(%p)->(%p)\n", This
, p
);
604 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
606 HTMLElement
*This
= HTMLELEM_THIS(iface
);
607 nsIDOMNSHTMLElement
*nselem
;
611 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
613 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
614 if(NS_FAILED(nsres
)) {
615 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
619 nsAString_Init(&html_str
, v
);
620 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
621 nsAString_Finish(&html_str
);
623 if(NS_FAILED(nsres
)) {
624 FIXME("SetInnerHtml failed %08x\n", nsres
);
631 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
633 HTMLElement
*This
= HTMLELEM_THIS(iface
);
634 FIXME("(%p)->(%p)\n", This
, p
);
638 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
640 HTMLElement
*This
= HTMLELEM_THIS(iface
);
641 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
645 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
647 HTMLElement
*This
= HTMLELEM_THIS(iface
);
648 FIXME("(%p)->(%p)\n", This
, p
);
652 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
654 HTMLElement
*This
= HTMLELEM_THIS(iface
);
655 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
659 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
661 HTMLElement
*This
= HTMLELEM_THIS(iface
);
662 FIXME("(%p)->(%p)\n", This
, p
);
666 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
668 HTMLElement
*This
= HTMLELEM_THIS(iface
);
669 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
673 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
675 HTMLElement
*This
= HTMLELEM_THIS(iface
);
676 FIXME("(%p)->(%p)\n", This
, p
);
680 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
682 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
683 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
684 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
685 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
688 if (!strcmpiW(where
, wszBeforeBegin
))
692 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
693 if (!parent
) return E_INVALIDARG
;
694 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
695 (nsIDOMNode
*)This
->nselem
, &unused
);
696 if (unused
) nsIDOMNode_Release(unused
);
697 nsIDOMNode_Release(parent
);
699 else if (!strcmpiW(where
, wszAfterBegin
))
702 nsIDOMNode
*first_child
;
703 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
704 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
705 if (unused
) nsIDOMNode_Release(unused
);
706 if (first_child
) nsIDOMNode_Release(first_child
);
708 else if (!strcmpiW(where
, wszBeforeEnd
))
711 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
712 if (unused
) nsIDOMNode_Release(unused
);
714 else if (!strcmpiW(where
, wszAfterEnd
))
717 nsIDOMNode
*next_sibling
;
719 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
720 if (!parent
) return E_INVALIDARG
;
722 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
725 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
726 nsIDOMNode_Release(next_sibling
);
729 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
730 nsIDOMNode_Release(parent
);
731 if (unused
) nsIDOMNode_Release(unused
);
735 ERR("invalid where: %s\n", debugstr_w(where
));
739 if (NS_FAILED(nsres
))
745 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
748 HTMLElement
*This
= HTMLELEM_THIS(iface
);
750 nsIDOMDocument
*nsdoc
;
751 nsIDOMDocumentRange
*nsdocrange
;
753 nsIDOMNSRange
*nsrange
;
758 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
760 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
763 ERR("GetDocument failed: %08x\n", nsres
);
767 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
768 nsIDOMDocument_Release(nsdoc
);
771 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
774 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
775 nsIDOMDocumentRange_Release(nsdocrange
);
778 ERR("CreateRange failed: %08x\n", nsres
);
782 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
784 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
785 nsIDOMRange_Release(range
);
788 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
792 nsAString_Init(&ns_html
, html
);
794 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
795 nsIDOMNSRange_Release(nsrange
);
796 nsAString_Finish(&ns_html
);
798 if(NS_FAILED(nsres
) || !nsnode
)
800 ERR("CreateTextNode failed: %08x\n", nsres
);
804 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
805 nsIDOMNode_Release(nsnode
);
810 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
813 HTMLElement
*This
= HTMLELEM_THIS(iface
);
815 nsIDOMDocument
*nsdoc
;
820 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
822 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
823 if(NS_FAILED(nsres
) || !nsdoc
)
825 ERR("GetDocument failed: %08x\n", nsres
);
829 nsAString_Init(&ns_text
, text
);
831 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
832 nsIDOMDocument_Release(nsdoc
);
833 nsAString_Finish(&ns_text
);
835 if(NS_FAILED(nsres
) || !nsnode
)
837 ERR("CreateTextNode failed: %08x\n", nsres
);
841 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
842 nsIDOMNode_Release(nsnode
);
847 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
849 HTMLElement
*This
= HTMLELEM_THIS(iface
);
850 FIXME("(%p)->(%p)\n", This
, p
);
854 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
856 HTMLElement
*This
= HTMLELEM_THIS(iface
);
857 FIXME("(%p)->(%p)\n", This
, p
);
861 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
863 HTMLElement
*This
= HTMLELEM_THIS(iface
);
864 FIXME("(%p)\n", This
);
868 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
869 IHTMLFiltersCollection
**p
)
871 HTMLElement
*This
= HTMLELEM_THIS(iface
);
872 FIXME("(%p)->(%p)\n", This
, p
);
876 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
878 HTMLElement
*This
= HTMLELEM_THIS(iface
);
879 FIXME("(%p)->()\n", This
);
883 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
885 HTMLElement
*This
= HTMLELEM_THIS(iface
);
886 FIXME("(%p)->(%p)\n", This
, p
);
890 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
892 HTMLElement
*This
= HTMLELEM_THIS(iface
);
893 FIXME("(%p)->(%p)\n", This
, String
);
897 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
899 HTMLElement
*This
= HTMLELEM_THIS(iface
);
900 FIXME("(%p)->()\n", This
);
904 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
906 HTMLElement
*This
= HTMLELEM_THIS(iface
);
907 FIXME("(%p)->(%p)\n", This
, p
);
911 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
913 HTMLElement
*This
= HTMLELEM_THIS(iface
);
914 FIXME("(%p)->()\n", This
);
918 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
920 HTMLElement
*This
= HTMLELEM_THIS(iface
);
921 FIXME("(%p)->(%p)\n", This
, p
);
925 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
927 HTMLElement
*This
= HTMLELEM_THIS(iface
);
928 FIXME("(%p)->()\n", This
);
932 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
934 HTMLElement
*This
= HTMLELEM_THIS(iface
);
935 FIXME("(%p)->(%p)\n", This
, p
);
939 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
941 HTMLElement
*This
= HTMLELEM_THIS(iface
);
942 FIXME("(%p)->()\n", This
);
946 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
948 HTMLElement
*This
= HTMLELEM_THIS(iface
);
949 FIXME("(%p)->(%p)\n", This
, p
);
953 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
955 HTMLElement
*This
= HTMLELEM_THIS(iface
);
956 FIXME("(%p)->()\n", This
);
960 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
962 HTMLElement
*This
= HTMLELEM_THIS(iface
);
963 FIXME("(%p)->(%p)\n", This
, p
);
967 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
969 HTMLElement
*This
= HTMLELEM_THIS(iface
);
970 FIXME("(%p)->()\n", This
);
974 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
976 HTMLElement
*This
= HTMLELEM_THIS(iface
);
977 FIXME("(%p)->(%p)\n", This
, p
);
981 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
983 HTMLElement
*This
= HTMLELEM_THIS(iface
);
984 FIXME("(%p)->()\n", This
);
988 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
990 HTMLElement
*This
= HTMLELEM_THIS(iface
);
991 FIXME("(%p)->(%p)\n", This
, p
);
995 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
997 HTMLElement
*This
= HTMLELEM_THIS(iface
);
998 FIXME("(%p)->()\n", This
);
1002 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1004 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1005 FIXME("(%p)->(%p)\n", This
, p
);
1009 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1011 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1012 FIXME("(%p)->()\n", This
);
1016 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1018 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1019 FIXME("(%p)->(%p)\n", This
, p
);
1023 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1025 nsIDOMNodeList
*nsnode_list
;
1027 PRUint32 list_len
= 0, i
;
1031 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1032 if(NS_FAILED(nsres
)) {
1033 ERR("GetChildNodes failed: %08x\n", nsres
);
1037 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1041 buf
->size
= list_len
;
1042 buf
->buf
= mshtml_alloc(buf
->size
*sizeof(HTMLElement
**));
1044 for(i
=0; i
<list_len
; i
++) {
1045 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1046 if(NS_FAILED(nsres
)) {
1047 ERR("Item failed: %08x\n", nsres
);
1051 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1052 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
)
1053 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
)));
1057 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1059 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1060 elem_vector buf
= {NULL
, 0, 0};
1062 TRACE("(%p)->(%p)\n", This
, p
);
1064 create_child_list(This
->node
.doc
, This
, &buf
);
1066 return HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
, p
);
1069 static void create_all_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1071 nsIDOMNodeList
*nsnode_list
;
1073 PRUint32 list_len
= 0, i
;
1077 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1078 if(NS_FAILED(nsres
)) {
1079 ERR("GetChildNodes failed: %08x\n", nsres
);
1083 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1087 for(i
=0; i
<list_len
; i
++) {
1088 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1089 if(NS_FAILED(nsres
)) {
1090 ERR("Item failed: %08x\n", nsres
);
1094 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1095 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
) {
1096 HTMLDOMNode
*node
= get_node(doc
, iter
);
1098 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1099 create_all_list(doc
, HTMLELEM_NODE_THIS(node
), buf
);
1104 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1106 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1107 elem_vector buf
= {NULL
, 0, 8};
1109 TRACE("(%p)->(%p)\n", This
, p
);
1111 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
**));
1113 create_all_list(This
->node
.doc
, This
, &buf
);
1118 mshtml_free(buf
.buf
);
1120 }else if(buf
.size
> buf
.len
) {
1121 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
**));
1124 return HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
, p
);
1127 static void HTMLElement_destructor(IUnknown
*iface
)
1129 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1131 if(This
->destructor
)
1132 This
->destructor(This
->impl
);
1135 nsIDOMHTMLElement_Release(This
->nselem
);
1140 #undef HTMLELEM_THIS
1142 static const IHTMLElementVtbl HTMLElementVtbl
= {
1143 HTMLElement_QueryInterface
,
1145 HTMLElement_Release
,
1146 HTMLElement_GetTypeInfoCount
,
1147 HTMLElement_GetTypeInfo
,
1148 HTMLElement_GetIDsOfNames
,
1150 HTMLElement_setAttribute
,
1151 HTMLElement_getAttribute
,
1152 HTMLElement_removeAttribute
,
1153 HTMLElement_put_className
,
1154 HTMLElement_get_className
,
1157 HTMLElement_get_tagName
,
1158 HTMLElement_get_parentElement
,
1159 HTMLElement_get_style
,
1160 HTMLElement_put_onhelp
,
1161 HTMLElement_get_onhelp
,
1162 HTMLElement_put_onclick
,
1163 HTMLElement_get_onclick
,
1164 HTMLElement_put_ondblclick
,
1165 HTMLElement_get_ondblclick
,
1166 HTMLElement_put_onkeydown
,
1167 HTMLElement_get_onkeydown
,
1168 HTMLElement_put_onkeyup
,
1169 HTMLElement_get_onkeyup
,
1170 HTMLElement_put_onkeypress
,
1171 HTMLElement_get_onkeypress
,
1172 HTMLElement_put_onmouseout
,
1173 HTMLElement_get_onmouseout
,
1174 HTMLElement_put_onmouseover
,
1175 HTMLElement_get_onmouseover
,
1176 HTMLElement_put_onmousemove
,
1177 HTMLElement_get_onmousemove
,
1178 HTMLElement_put_onmousedown
,
1179 HTMLElement_get_onmousedown
,
1180 HTMLElement_put_onmouseup
,
1181 HTMLElement_get_onmouseup
,
1182 HTMLElement_get_document
,
1183 HTMLElement_put_title
,
1184 HTMLElement_get_title
,
1185 HTMLElement_put_language
,
1186 HTMLElement_get_language
,
1187 HTMLElement_put_onselectstart
,
1188 HTMLElement_get_onselectstart
,
1189 HTMLElement_scrollIntoView
,
1190 HTMLElement_contains
,
1191 HTMLElement_get_sourceIndex
,
1192 HTMLElement_get_recordNumber
,
1193 HTMLElement_put_lang
,
1194 HTMLElement_get_lang
,
1195 HTMLElement_get_offsetLeft
,
1196 HTMLElement_get_offsetTop
,
1197 HTMLElement_get_offsetWidth
,
1198 HTMLElement_get_offsetHeight
,
1199 HTMLElement_get_offsetParent
,
1200 HTMLElement_put_innerHTML
,
1201 HTMLElement_get_innerHTML
,
1202 HTMLElement_put_innerText
,
1203 HTMLElement_get_innerText
,
1204 HTMLElement_put_outerHTML
,
1205 HTMLElement_get_outerHTML
,
1206 HTMLElement_put_outerText
,
1207 HTMLElement_get_outerText
,
1208 HTMLElement_insertAdjacentHTML
,
1209 HTMLElement_insertAdjacentText
,
1210 HTMLElement_get_parentTextEdit
,
1211 HTMLElement_get_isTextEdit
,
1213 HTMLElement_get_filters
,
1214 HTMLElement_put_ondragstart
,
1215 HTMLElement_get_ondragstart
,
1216 HTMLElement_toString
,
1217 HTMLElement_put_onbeforeupdate
,
1218 HTMLElement_get_onbeforeupdate
,
1219 HTMLElement_put_onafterupdate
,
1220 HTMLElement_get_onafterupdate
,
1221 HTMLElement_put_onerrorupdate
,
1222 HTMLElement_get_onerrorupdate
,
1223 HTMLElement_put_onrowexit
,
1224 HTMLElement_get_onrowexit
,
1225 HTMLElement_put_onrowenter
,
1226 HTMLElement_get_onrowenter
,
1227 HTMLElement_put_ondatasetchanged
,
1228 HTMLElement_get_ondatasetchanged
,
1229 HTMLElement_put_ondataavailable
,
1230 HTMLElement_get_ondataavailable
,
1231 HTMLElement_put_ondatasetcomplete
,
1232 HTMLElement_get_ondatasetcomplete
,
1233 HTMLElement_put_onfilterchange
,
1234 HTMLElement_get_onfilterchange
,
1235 HTMLElement_get_children
,
1239 HRESULT
HTMLElement_QI(HTMLElement
*This
, REFIID riid
, void **ppv
)
1243 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1244 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1245 *ppv
= HTMLELEM(This
);
1246 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1247 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1248 *ppv
= HTMLELEM(This
);
1249 }else if(IsEqualGUID(&IID_IHTMLElement
, riid
)) {
1250 TRACE("(%p)->(IID_IHTMLElement %p)\n", This
, ppv
);
1251 *ppv
= HTMLELEM(This
);
1252 }else if(IsEqualGUID(&IID_IHTMLElement2
, riid
)) {
1253 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This
, ppv
);
1254 *ppv
= HTMLELEM2(This
);
1258 IHTMLElement_AddRef(HTMLELEM(This
));
1262 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
1265 HTMLElement
*HTMLElement_Create(nsIDOMNode
*nsnode
)
1267 nsIDOMHTMLElement
*nselem
;
1268 HTMLElement
*ret
= NULL
;
1269 nsAString class_name_str
;
1270 const PRUnichar
*class_name
;
1273 static const WCHAR wszA
[] = {'A',0};
1274 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1275 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1276 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1277 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1279 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1280 if(NS_FAILED(nsres
))
1283 nsAString_Init(&class_name_str
, NULL
);
1284 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1286 nsAString_GetData(&class_name_str
, &class_name
, NULL
);
1288 if(!strcmpW(class_name
, wszA
))
1289 ret
= HTMLAnchorElement_Create(nselem
);
1290 else if(!strcmpW(class_name
, wszBODY
))
1291 ret
= HTMLBodyElement_Create(nselem
);
1292 else if(!strcmpW(class_name
, wszINPUT
))
1293 ret
= HTMLInputElement_Create(nselem
);
1294 if(!strcmpW(class_name
, wszSELECT
))
1295 ret
= HTMLSelectElement_Create(nselem
);
1296 else if(!strcmpW(class_name
, wszTEXTAREA
))
1297 ret
= HTMLTextAreaElement_Create(nselem
);
1300 ret
= mshtml_alloc(sizeof(HTMLElement
));
1303 ret
->destructor
= NULL
;
1306 nsAString_Finish(&class_name_str
);
1308 ret
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1309 ret
->nselem
= nselem
;
1311 HTMLElement2_Init(ret
);
1313 ret
->node
.impl
.elem
= HTMLELEM(ret
);
1314 ret
->node
.destructor
= HTMLElement_destructor
;
1320 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1323 HTMLElement
**elems
;
1327 } HTMLElementCollection
;
1329 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1331 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1333 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1334 REFIID riid
, void **ppv
)
1336 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1340 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1341 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1342 *ppv
= HTMLELEMCOL(This
);
1343 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1344 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1345 *ppv
= HTMLELEMCOL(This
);
1346 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1347 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1348 *ppv
= HTMLELEMCOL(This
);
1352 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1356 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1357 return E_NOINTERFACE
;
1360 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1362 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1363 LONG ref
= InterlockedIncrement(&This
->ref
);
1365 TRACE("(%p) ref=%d\n", This
, ref
);
1370 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1372 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1373 LONG ref
= InterlockedDecrement(&This
->ref
);
1375 TRACE("(%p) ref=%d\n", This
, ref
);
1378 IUnknown_Release(This
->ref_unk
);
1379 mshtml_free(This
->elems
);
1386 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1389 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1390 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1394 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1395 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1397 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1398 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1402 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1403 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1405 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1406 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1411 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1412 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1413 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1415 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1416 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1417 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1421 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1424 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1425 FIXME("(%p)->(%p)\n", This
, String
);
1429 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1432 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1433 FIXME("(%p)->(%ld)\n", This
, v
);
1437 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1440 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1442 TRACE("(%p)->(%p)\n", This
, p
);
1448 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1451 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1452 FIXME("(%p)->(%p)\n", This
, p
);
1456 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1457 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1459 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1461 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1463 if(V_VT(&name
) == VT_I4
) {
1464 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1465 if(V_I4(&name
) < 0 || V_I4(&name
) >= This
->len
) {
1466 ERR("Invalid name! name=%d\n", V_I4(&name
));
1467 return E_INVALIDARG
;
1470 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1471 IDispatch_AddRef(*pdisp
);
1472 TRACE("Returning pdisp=%p\n", pdisp
);
1476 if(V_VT(&name
) == VT_BSTR
) {
1479 const PRUnichar
*tag
;
1480 elem_vector buf
= {NULL
, 0, 8};
1482 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1484 nsAString_Init(&tag_str
, NULL
);
1485 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1487 for(i
=0; i
<This
->len
; i
++) {
1488 if(!This
->elems
[i
]->nselem
) continue;
1490 nsIDOMHTMLElement_GetId(This
->elems
[i
]->nselem
, &tag_str
);
1491 nsAString_GetData(&tag_str
, &tag
, NULL
);
1493 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1494 V_BSTR(&name
), -1) == CSTR_EQUAL
) {
1495 TRACE("Found name. elem=%d\n", i
);
1496 if (V_VT(&index
) == VT_I4
)
1497 if (buf
.len
== V_I4(&index
)) {
1498 nsAString_Finish(&tag_str
);
1499 mshtml_free(buf
.buf
);
1501 *pdisp
= (IDispatch
*)This
->elems
[i
];
1502 TRACE("Returning element %d pdisp=%p\n", i
, pdisp
);
1503 IDispatch_AddRef(*pdisp
);
1506 elem_vector_add(&buf
, This
->elems
[i
]);
1509 nsAString_Finish(&tag_str
);
1510 if (V_VT(&index
) == VT_I4
) {
1511 mshtml_free(buf
.buf
);
1513 ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index
), buf
.len
);
1514 return E_INVALIDARG
;
1517 mshtml_free(buf
.buf
);
1519 } else if(buf
.size
> buf
.len
) {
1520 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
*));
1522 TRACE("Returning %d element(s).\n", buf
.len
);
1523 return HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
, pdisp
);
1526 FIXME("unsupported arguments\n");
1527 return E_INVALIDARG
;
1530 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1531 VARIANT tagName
, IDispatch
**pdisp
)
1533 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1536 const PRUnichar
*tag
;
1537 elem_vector buf
= {NULL
, 0, 8};
1539 if(V_VT(&tagName
) != VT_BSTR
) {
1540 WARN("Invalid arg\n");
1541 return DISP_E_MEMBERNOTFOUND
;
1544 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1546 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1548 nsAString_Init(&tag_str
, NULL
);
1550 for(i
=0; i
<This
->len
; i
++) {
1551 if(!This
->elems
[i
]->nselem
)
1554 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1555 nsAString_GetData(&tag_str
, &tag
, NULL
);
1557 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1558 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1559 elem_vector_add(&buf
, This
->elems
[i
]);
1562 nsAString_Finish(&tag_str
);
1564 TRACE("fount %d tags\n", buf
.len
);
1567 mshtml_free(buf
.buf
);
1569 }else if(buf
.size
> buf
.len
) {
1570 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
*));
1573 return HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
, pdisp
);
1578 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1579 HTMLElementCollection_QueryInterface
,
1580 HTMLElementCollection_AddRef
,
1581 HTMLElementCollection_Release
,
1582 HTMLElementCollection_GetTypeInfoCount
,
1583 HTMLElementCollection_GetTypeInfo
,
1584 HTMLElementCollection_GetIDsOfNames
,
1585 HTMLElementCollection_Invoke
,
1586 HTMLElementCollection_toString
,
1587 HTMLElementCollection_put_length
,
1588 HTMLElementCollection_get_length
,
1589 HTMLElementCollection_get__newEnum
,
1590 HTMLElementCollection_item
,
1591 HTMLElementCollection_tags
1594 static HRESULT
HTMLElementCollection_Create(IUnknown
*ref_unk
, HTMLElement
**elems
, DWORD len
,
1597 HTMLElementCollection
*ret
= mshtml_alloc(sizeof(HTMLElementCollection
));
1599 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1604 IUnknown_AddRef(ref_unk
);
1605 ret
->ref_unk
= ref_unk
;
1607 TRACE("ret=%p len=%d\n", ret
, len
);
1609 *p
= (IDispatch
*)ret
;