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(iface) DEFINE_THIS2(HTMLElement, node, iface)
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 const PRUnichar
*tag
;
286 TRACE("(%p)->(%p)\n", This
, p
);
288 nsAString_Init(&tag_str
, NULL
);
289 nsres
= nsIDOMHTMLElement_GetTagName(This
->nselem
, &tag_str
);
290 if(NS_SUCCEEDED(nsres
)) {
291 nsAString_GetData(&tag_str
, &tag
, NULL
);
292 *p
= SysAllocString(tag
);
294 ERR("GetTagName failed: %08x\n", nsres
);
297 nsAString_Finish(&tag_str
);
302 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
304 HTMLElement
*This
= HTMLELEM_THIS(iface
);
305 FIXME("(%p)->(%p)\n", This
, p
);
309 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
311 HTMLElement
*This
= HTMLELEM_THIS(iface
);
312 nsIDOMElementCSSInlineStyle
*nselemstyle
;
313 nsIDOMCSSStyleDeclaration
*nsstyle
;
316 TRACE("(%p)->(%p)\n", This
, p
);
318 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
319 (void**)&nselemstyle
);
320 if(NS_FAILED(nsres
)) {
321 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
325 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
326 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
327 if(NS_FAILED(nsres
)) {
328 ERR("GetStyle failed: %08x\n", nsres
);
332 /* FIXME: Store style instead of creating a new instance in each call */
333 *p
= HTMLStyle_Create(nsstyle
);
335 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
339 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
341 HTMLElement
*This
= HTMLELEM_THIS(iface
);
342 FIXME("(%p)->()\n", This
);
346 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
348 HTMLElement
*This
= HTMLELEM_THIS(iface
);
349 FIXME("(%p)->(%p)\n", This
, p
);
353 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
355 HTMLElement
*This
= HTMLELEM_THIS(iface
);
356 FIXME("(%p)->()\n", This
);
360 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
362 HTMLElement
*This
= HTMLELEM_THIS(iface
);
363 FIXME("(%p)->(%p)\n", This
, p
);
367 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
369 HTMLElement
*This
= HTMLELEM_THIS(iface
);
370 FIXME("(%p)->()\n", This
);
374 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
376 HTMLElement
*This
= HTMLELEM_THIS(iface
);
377 FIXME("(%p)->(%p)\n", This
, p
);
381 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
383 HTMLElement
*This
= HTMLELEM_THIS(iface
);
384 FIXME("(%p)->()\n", This
);
388 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
390 HTMLElement
*This
= HTMLELEM_THIS(iface
);
391 FIXME("(%p)->(%p)\n", This
, p
);
395 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
397 HTMLElement
*This
= HTMLELEM_THIS(iface
);
398 FIXME("(%p)->()\n", This
);
402 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
404 HTMLElement
*This
= HTMLELEM_THIS(iface
);
405 FIXME("(%p)->(%p)\n", This
, p
);
409 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
411 HTMLElement
*This
= HTMLELEM_THIS(iface
);
412 FIXME("(%p)->()\n", This
);
416 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
418 HTMLElement
*This
= HTMLELEM_THIS(iface
);
419 FIXME("(%p)->(%p)\n", This
, p
);
423 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
425 HTMLElement
*This
= HTMLELEM_THIS(iface
);
426 FIXME("(%p)->()\n", This
);
430 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
432 HTMLElement
*This
= HTMLELEM_THIS(iface
);
433 FIXME("(%p)->(%p)\n", This
, p
);
437 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
439 HTMLElement
*This
= HTMLELEM_THIS(iface
);
440 FIXME("(%p)->()\n", This
);
444 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
446 HTMLElement
*This
= HTMLELEM_THIS(iface
);
447 FIXME("(%p)->(%p)\n", This
, p
);
451 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
453 HTMLElement
*This
= HTMLELEM_THIS(iface
);
454 FIXME("(%p)->()\n", This
);
458 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
460 HTMLElement
*This
= HTMLELEM_THIS(iface
);
461 FIXME("(%p)->(%p)\n", This
, p
);
465 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
467 HTMLElement
*This
= HTMLELEM_THIS(iface
);
468 FIXME("(%p)->()\n", This
);
472 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
474 HTMLElement
*This
= HTMLELEM_THIS(iface
);
475 FIXME("(%p)->(%p)\n", This
, p
);
479 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
481 HTMLElement
*This
= HTMLELEM_THIS(iface
);
482 FIXME("(%p)->()\n", This
);
486 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
488 HTMLElement
*This
= HTMLELEM_THIS(iface
);
489 FIXME("(%p)->(%p)\n", This
, p
);
493 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
495 HTMLElement
*This
= HTMLELEM_THIS(iface
);
496 FIXME("(%p)->(%p)\n", This
, p
);
500 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
502 HTMLElement
*This
= HTMLELEM_THIS(iface
);
503 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
507 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
509 HTMLElement
*This
= HTMLELEM_THIS(iface
);
510 FIXME("(%p)->(%p)\n", This
, p
);
514 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
516 HTMLElement
*This
= HTMLELEM_THIS(iface
);
517 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
521 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
523 HTMLElement
*This
= HTMLELEM_THIS(iface
);
524 FIXME("(%p)->(%p)\n", This
, p
);
528 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
530 HTMLElement
*This
= HTMLELEM_THIS(iface
);
531 FIXME("(%p)->()\n", This
);
535 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
537 HTMLElement
*This
= HTMLELEM_THIS(iface
);
538 FIXME("(%p)->(%p)\n", This
, p
);
542 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
544 HTMLElement
*This
= HTMLELEM_THIS(iface
);
545 FIXME("(%p)->()\n", This
);
549 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
550 VARIANT_BOOL
*pfResult
)
552 HTMLElement
*This
= HTMLELEM_THIS(iface
);
553 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
557 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
559 HTMLElement
*This
= HTMLELEM_THIS(iface
);
560 FIXME("(%p)->(%p)\n", This
, p
);
564 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
566 HTMLElement
*This
= HTMLELEM_THIS(iface
);
567 FIXME("(%p)->(%p)\n", This
, p
);
571 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
573 HTMLElement
*This
= HTMLELEM_THIS(iface
);
574 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
578 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
580 HTMLElement
*This
= HTMLELEM_THIS(iface
);
581 FIXME("(%p)->(%p)\n", This
, p
);
585 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
587 HTMLElement
*This
= HTMLELEM_THIS(iface
);
588 FIXME("(%p)->(%p)\n", This
, p
);
592 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
594 HTMLElement
*This
= HTMLELEM_THIS(iface
);
595 FIXME("(%p)->(%p)\n", This
, p
);
599 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
601 HTMLElement
*This
= HTMLELEM_THIS(iface
);
602 FIXME("(%p)->(%p)\n", This
, p
);
606 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
608 HTMLElement
*This
= HTMLELEM_THIS(iface
);
609 FIXME("(%p)->(%p)\n", This
, p
);
613 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
615 HTMLElement
*This
= HTMLELEM_THIS(iface
);
616 FIXME("(%p)->(%p)\n", This
, p
);
620 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
622 HTMLElement
*This
= HTMLELEM_THIS(iface
);
623 nsIDOMNSHTMLElement
*nselem
;
627 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
629 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
630 if(NS_FAILED(nsres
)) {
631 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
635 nsAString_Init(&html_str
, v
);
636 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
637 nsAString_Finish(&html_str
);
639 if(NS_FAILED(nsres
)) {
640 FIXME("SetInnerHtml failed %08x\n", nsres
);
647 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
649 HTMLElement
*This
= HTMLELEM_THIS(iface
);
650 FIXME("(%p)->(%p)\n", This
, p
);
654 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
656 HTMLElement
*This
= HTMLELEM_THIS(iface
);
657 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
661 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
663 HTMLElement
*This
= HTMLELEM_THIS(iface
);
664 FIXME("(%p)->(%p)\n", This
, p
);
668 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
670 HTMLElement
*This
= HTMLELEM_THIS(iface
);
671 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
675 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
677 HTMLElement
*This
= HTMLELEM_THIS(iface
);
678 FIXME("(%p)->(%p)\n", This
, p
);
682 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
684 HTMLElement
*This
= HTMLELEM_THIS(iface
);
685 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
689 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
691 HTMLElement
*This
= HTMLELEM_THIS(iface
);
692 FIXME("(%p)->(%p)\n", This
, p
);
696 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
698 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
699 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
700 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
701 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
704 if (!strcmpiW(where
, wszBeforeBegin
))
708 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
709 if (!parent
) return E_INVALIDARG
;
710 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
711 (nsIDOMNode
*)This
->nselem
, &unused
);
712 if (unused
) nsIDOMNode_Release(unused
);
713 nsIDOMNode_Release(parent
);
715 else if (!strcmpiW(where
, wszAfterBegin
))
718 nsIDOMNode
*first_child
;
719 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
720 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
721 if (unused
) nsIDOMNode_Release(unused
);
722 if (first_child
) nsIDOMNode_Release(first_child
);
724 else if (!strcmpiW(where
, wszBeforeEnd
))
727 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
728 if (unused
) nsIDOMNode_Release(unused
);
730 else if (!strcmpiW(where
, wszAfterEnd
))
733 nsIDOMNode
*next_sibling
;
735 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
736 if (!parent
) return E_INVALIDARG
;
738 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
741 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
742 nsIDOMNode_Release(next_sibling
);
745 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
746 nsIDOMNode_Release(parent
);
747 if (unused
) nsIDOMNode_Release(unused
);
751 ERR("invalid where: %s\n", debugstr_w(where
));
755 if (NS_FAILED(nsres
))
761 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
764 HTMLElement
*This
= HTMLELEM_THIS(iface
);
766 nsIDOMDocument
*nsdoc
;
767 nsIDOMDocumentRange
*nsdocrange
;
769 nsIDOMNSRange
*nsrange
;
774 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
776 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
779 ERR("GetDocument failed: %08x\n", nsres
);
783 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
784 nsIDOMDocument_Release(nsdoc
);
787 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
790 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
791 nsIDOMDocumentRange_Release(nsdocrange
);
794 ERR("CreateRange failed: %08x\n", nsres
);
798 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
800 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
801 nsIDOMRange_Release(range
);
804 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
808 nsAString_Init(&ns_html
, html
);
810 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
811 nsIDOMNSRange_Release(nsrange
);
812 nsAString_Finish(&ns_html
);
814 if(NS_FAILED(nsres
) || !nsnode
)
816 ERR("CreateTextNode failed: %08x\n", nsres
);
820 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
821 nsIDOMNode_Release(nsnode
);
826 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
829 HTMLElement
*This
= HTMLELEM_THIS(iface
);
831 nsIDOMDocument
*nsdoc
;
836 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
838 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
839 if(NS_FAILED(nsres
) || !nsdoc
)
841 ERR("GetDocument failed: %08x\n", nsres
);
845 nsAString_Init(&ns_text
, text
);
847 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
848 nsIDOMDocument_Release(nsdoc
);
849 nsAString_Finish(&ns_text
);
851 if(NS_FAILED(nsres
) || !nsnode
)
853 ERR("CreateTextNode failed: %08x\n", nsres
);
857 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
858 nsIDOMNode_Release(nsnode
);
863 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
865 HTMLElement
*This
= HTMLELEM_THIS(iface
);
866 FIXME("(%p)->(%p)\n", This
, p
);
870 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
872 HTMLElement
*This
= HTMLELEM_THIS(iface
);
873 FIXME("(%p)->(%p)\n", This
, p
);
877 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
879 HTMLElement
*This
= HTMLELEM_THIS(iface
);
880 FIXME("(%p)\n", This
);
884 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
885 IHTMLFiltersCollection
**p
)
887 HTMLElement
*This
= HTMLELEM_THIS(iface
);
888 FIXME("(%p)->(%p)\n", This
, p
);
892 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
894 HTMLElement
*This
= HTMLELEM_THIS(iface
);
895 FIXME("(%p)->()\n", This
);
899 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
901 HTMLElement
*This
= HTMLELEM_THIS(iface
);
902 FIXME("(%p)->(%p)\n", This
, p
);
906 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
908 HTMLElement
*This
= HTMLELEM_THIS(iface
);
909 FIXME("(%p)->(%p)\n", This
, String
);
913 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
915 HTMLElement
*This
= HTMLELEM_THIS(iface
);
916 FIXME("(%p)->()\n", This
);
920 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
922 HTMLElement
*This
= HTMLELEM_THIS(iface
);
923 FIXME("(%p)->(%p)\n", This
, p
);
927 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
929 HTMLElement
*This
= HTMLELEM_THIS(iface
);
930 FIXME("(%p)->()\n", This
);
934 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
936 HTMLElement
*This
= HTMLELEM_THIS(iface
);
937 FIXME("(%p)->(%p)\n", This
, p
);
941 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
943 HTMLElement
*This
= HTMLELEM_THIS(iface
);
944 FIXME("(%p)->()\n", This
);
948 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
950 HTMLElement
*This
= HTMLELEM_THIS(iface
);
951 FIXME("(%p)->(%p)\n", This
, p
);
955 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
957 HTMLElement
*This
= HTMLELEM_THIS(iface
);
958 FIXME("(%p)->()\n", This
);
962 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
964 HTMLElement
*This
= HTMLELEM_THIS(iface
);
965 FIXME("(%p)->(%p)\n", This
, p
);
969 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
971 HTMLElement
*This
= HTMLELEM_THIS(iface
);
972 FIXME("(%p)->()\n", This
);
976 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
978 HTMLElement
*This
= HTMLELEM_THIS(iface
);
979 FIXME("(%p)->(%p)\n", This
, p
);
983 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
985 HTMLElement
*This
= HTMLELEM_THIS(iface
);
986 FIXME("(%p)->()\n", This
);
990 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
992 HTMLElement
*This
= HTMLELEM_THIS(iface
);
993 FIXME("(%p)->(%p)\n", This
, p
);
997 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
999 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1000 FIXME("(%p)->()\n", This
);
1004 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
1006 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1007 FIXME("(%p)->(%p)\n", This
, p
);
1011 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
1013 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1014 FIXME("(%p)->()\n", This
);
1018 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1020 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1021 FIXME("(%p)->(%p)\n", This
, p
);
1025 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1027 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1028 FIXME("(%p)->()\n", This
);
1032 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1034 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1035 FIXME("(%p)->(%p)\n", This
, p
);
1039 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1041 nsIDOMNodeList
*nsnode_list
;
1043 PRUint32 list_len
= 0, i
;
1047 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1048 if(NS_FAILED(nsres
)) {
1049 ERR("GetChildNodes failed: %08x\n", nsres
);
1053 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1057 buf
->size
= list_len
;
1058 buf
->buf
= mshtml_alloc(buf
->size
*sizeof(HTMLElement
**));
1060 for(i
=0; i
<list_len
; i
++) {
1061 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1062 if(NS_FAILED(nsres
)) {
1063 ERR("Item failed: %08x\n", nsres
);
1067 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1068 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
)
1069 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
)));
1073 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1075 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1076 elem_vector buf
= {NULL
, 0, 0};
1078 TRACE("(%p)->(%p)\n", This
, p
);
1080 create_child_list(This
->node
.doc
, This
, &buf
);
1082 return HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
, p
);
1085 static void create_all_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1087 nsIDOMNodeList
*nsnode_list
;
1089 PRUint32 list_len
= 0, i
;
1093 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1094 if(NS_FAILED(nsres
)) {
1095 ERR("GetChildNodes failed: %08x\n", nsres
);
1099 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1103 for(i
=0; i
<list_len
; i
++) {
1104 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1105 if(NS_FAILED(nsres
)) {
1106 ERR("Item failed: %08x\n", nsres
);
1110 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1111 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
) {
1112 HTMLDOMNode
*node
= get_node(doc
, iter
);
1114 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1115 create_all_list(doc
, HTMLELEM_NODE_THIS(node
), buf
);
1120 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1122 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1123 elem_vector buf
= {NULL
, 0, 8};
1125 TRACE("(%p)->(%p)\n", This
, p
);
1127 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
**));
1129 create_all_list(This
->node
.doc
, This
, &buf
);
1134 mshtml_free(buf
.buf
);
1136 }else if(buf
.size
> buf
.len
) {
1137 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
**));
1140 return HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
, p
);
1143 #undef HTMLELEM_THIS
1145 static const IHTMLElementVtbl HTMLElementVtbl
= {
1146 HTMLElement_QueryInterface
,
1148 HTMLElement_Release
,
1149 HTMLElement_GetTypeInfoCount
,
1150 HTMLElement_GetTypeInfo
,
1151 HTMLElement_GetIDsOfNames
,
1153 HTMLElement_setAttribute
,
1154 HTMLElement_getAttribute
,
1155 HTMLElement_removeAttribute
,
1156 HTMLElement_put_className
,
1157 HTMLElement_get_className
,
1160 HTMLElement_get_tagName
,
1161 HTMLElement_get_parentElement
,
1162 HTMLElement_get_style
,
1163 HTMLElement_put_onhelp
,
1164 HTMLElement_get_onhelp
,
1165 HTMLElement_put_onclick
,
1166 HTMLElement_get_onclick
,
1167 HTMLElement_put_ondblclick
,
1168 HTMLElement_get_ondblclick
,
1169 HTMLElement_put_onkeydown
,
1170 HTMLElement_get_onkeydown
,
1171 HTMLElement_put_onkeyup
,
1172 HTMLElement_get_onkeyup
,
1173 HTMLElement_put_onkeypress
,
1174 HTMLElement_get_onkeypress
,
1175 HTMLElement_put_onmouseout
,
1176 HTMLElement_get_onmouseout
,
1177 HTMLElement_put_onmouseover
,
1178 HTMLElement_get_onmouseover
,
1179 HTMLElement_put_onmousemove
,
1180 HTMLElement_get_onmousemove
,
1181 HTMLElement_put_onmousedown
,
1182 HTMLElement_get_onmousedown
,
1183 HTMLElement_put_onmouseup
,
1184 HTMLElement_get_onmouseup
,
1185 HTMLElement_get_document
,
1186 HTMLElement_put_title
,
1187 HTMLElement_get_title
,
1188 HTMLElement_put_language
,
1189 HTMLElement_get_language
,
1190 HTMLElement_put_onselectstart
,
1191 HTMLElement_get_onselectstart
,
1192 HTMLElement_scrollIntoView
,
1193 HTMLElement_contains
,
1194 HTMLElement_get_sourceIndex
,
1195 HTMLElement_get_recordNumber
,
1196 HTMLElement_put_lang
,
1197 HTMLElement_get_lang
,
1198 HTMLElement_get_offsetLeft
,
1199 HTMLElement_get_offsetTop
,
1200 HTMLElement_get_offsetWidth
,
1201 HTMLElement_get_offsetHeight
,
1202 HTMLElement_get_offsetParent
,
1203 HTMLElement_put_innerHTML
,
1204 HTMLElement_get_innerHTML
,
1205 HTMLElement_put_innerText
,
1206 HTMLElement_get_innerText
,
1207 HTMLElement_put_outerHTML
,
1208 HTMLElement_get_outerHTML
,
1209 HTMLElement_put_outerText
,
1210 HTMLElement_get_outerText
,
1211 HTMLElement_insertAdjacentHTML
,
1212 HTMLElement_insertAdjacentText
,
1213 HTMLElement_get_parentTextEdit
,
1214 HTMLElement_get_isTextEdit
,
1216 HTMLElement_get_filters
,
1217 HTMLElement_put_ondragstart
,
1218 HTMLElement_get_ondragstart
,
1219 HTMLElement_toString
,
1220 HTMLElement_put_onbeforeupdate
,
1221 HTMLElement_get_onbeforeupdate
,
1222 HTMLElement_put_onafterupdate
,
1223 HTMLElement_get_onafterupdate
,
1224 HTMLElement_put_onerrorupdate
,
1225 HTMLElement_get_onerrorupdate
,
1226 HTMLElement_put_onrowexit
,
1227 HTMLElement_get_onrowexit
,
1228 HTMLElement_put_onrowenter
,
1229 HTMLElement_get_onrowenter
,
1230 HTMLElement_put_ondatasetchanged
,
1231 HTMLElement_get_ondatasetchanged
,
1232 HTMLElement_put_ondataavailable
,
1233 HTMLElement_get_ondataavailable
,
1234 HTMLElement_put_ondatasetcomplete
,
1235 HTMLElement_get_ondatasetcomplete
,
1236 HTMLElement_put_onfilterchange
,
1237 HTMLElement_get_onfilterchange
,
1238 HTMLElement_get_children
,
1242 HRESULT
HTMLElement_QI(HTMLElement
*This
, REFIID riid
, void **ppv
)
1246 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1247 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1248 *ppv
= HTMLELEM(This
);
1249 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1250 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1251 *ppv
= HTMLELEM(This
);
1252 }else if(IsEqualGUID(&IID_IHTMLElement
, riid
)) {
1253 TRACE("(%p)->(IID_IHTMLElement %p)\n", This
, ppv
);
1254 *ppv
= HTMLELEM(This
);
1255 }else if(IsEqualGUID(&IID_IHTMLElement2
, riid
)) {
1256 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This
, ppv
);
1257 *ppv
= HTMLELEM2(This
);
1261 IHTMLElement_AddRef(HTMLELEM(This
));
1265 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
1268 static void HTMLElement_destructor(HTMLDOMNode
*iface
)
1270 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1272 if(This
->destructor
)
1273 This
->destructor(This
->impl
);
1276 nsIDOMHTMLElement_Release(This
->nselem
);
1281 HTMLElement
*HTMLElement_Create(nsIDOMNode
*nsnode
)
1283 nsIDOMHTMLElement
*nselem
;
1284 HTMLElement
*ret
= NULL
;
1285 nsAString class_name_str
;
1286 const PRUnichar
*class_name
;
1289 static const WCHAR wszA
[] = {'A',0};
1290 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1291 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1292 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1293 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1295 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1296 if(NS_FAILED(nsres
))
1299 nsAString_Init(&class_name_str
, NULL
);
1300 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1302 nsAString_GetData(&class_name_str
, &class_name
, NULL
);
1304 if(!strcmpW(class_name
, wszA
))
1305 ret
= HTMLAnchorElement_Create(nselem
);
1306 else if(!strcmpW(class_name
, wszBODY
))
1307 ret
= HTMLBodyElement_Create(nselem
);
1308 else if(!strcmpW(class_name
, wszINPUT
))
1309 ret
= HTMLInputElement_Create(nselem
);
1310 else if(!strcmpW(class_name
, wszSELECT
))
1311 ret
= HTMLSelectElement_Create(nselem
);
1312 else if(!strcmpW(class_name
, wszTEXTAREA
))
1313 ret
= HTMLTextAreaElement_Create(nselem
);
1316 ret
= mshtml_alloc(sizeof(HTMLElement
));
1319 ret
->destructor
= NULL
;
1322 nsAString_Finish(&class_name_str
);
1324 ret
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1325 ret
->nselem
= nselem
;
1327 HTMLElement2_Init(ret
);
1329 ret
->node
.impl
.elem
= HTMLELEM(ret
);
1330 ret
->node
.destructor
= HTMLElement_destructor
;
1336 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1339 HTMLElement
**elems
;
1343 } HTMLElementCollection
;
1345 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1347 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1349 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1350 REFIID riid
, void **ppv
)
1352 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1356 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1357 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1358 *ppv
= HTMLELEMCOL(This
);
1359 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1360 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1361 *ppv
= HTMLELEMCOL(This
);
1362 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1363 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1364 *ppv
= HTMLELEMCOL(This
);
1368 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1372 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1373 return E_NOINTERFACE
;
1376 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1378 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1379 LONG ref
= InterlockedIncrement(&This
->ref
);
1381 TRACE("(%p) ref=%d\n", This
, ref
);
1386 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1388 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1389 LONG ref
= InterlockedDecrement(&This
->ref
);
1391 TRACE("(%p) ref=%d\n", This
, ref
);
1394 IUnknown_Release(This
->ref_unk
);
1395 mshtml_free(This
->elems
);
1402 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1405 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1406 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1410 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1411 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1413 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1414 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1418 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1419 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1421 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1422 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1427 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1428 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1429 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1431 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1432 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1433 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1437 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1440 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1441 FIXME("(%p)->(%p)\n", This
, String
);
1445 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1448 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1449 FIXME("(%p)->(%ld)\n", This
, v
);
1453 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1456 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1458 TRACE("(%p)->(%p)\n", This
, p
);
1464 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1467 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1468 FIXME("(%p)->(%p)\n", This
, p
);
1472 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1473 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1475 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1477 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1479 if(V_VT(&name
) == VT_I4
) {
1480 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1481 if(V_I4(&name
) < 0 || V_I4(&name
) >= This
->len
) {
1482 ERR("Invalid name! name=%d\n", V_I4(&name
));
1483 return E_INVALIDARG
;
1486 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1487 IDispatch_AddRef(*pdisp
);
1488 TRACE("Returning pdisp=%p\n", pdisp
);
1492 if(V_VT(&name
) == VT_BSTR
) {
1495 const PRUnichar
*tag
;
1496 elem_vector buf
= {NULL
, 0, 8};
1498 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1500 nsAString_Init(&tag_str
, NULL
);
1501 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1503 for(i
=0; i
<This
->len
; i
++) {
1504 if(!This
->elems
[i
]->nselem
) continue;
1506 nsIDOMHTMLElement_GetId(This
->elems
[i
]->nselem
, &tag_str
);
1507 nsAString_GetData(&tag_str
, &tag
, NULL
);
1509 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1510 V_BSTR(&name
), -1) == CSTR_EQUAL
) {
1511 TRACE("Found name. elem=%d\n", i
);
1512 if (V_VT(&index
) == VT_I4
)
1513 if (buf
.len
== V_I4(&index
)) {
1514 nsAString_Finish(&tag_str
);
1515 mshtml_free(buf
.buf
);
1517 *pdisp
= (IDispatch
*)This
->elems
[i
];
1518 TRACE("Returning element %d pdisp=%p\n", i
, pdisp
);
1519 IDispatch_AddRef(*pdisp
);
1522 elem_vector_add(&buf
, This
->elems
[i
]);
1525 nsAString_Finish(&tag_str
);
1526 if (V_VT(&index
) == VT_I4
) {
1527 mshtml_free(buf
.buf
);
1529 ERR("Invalid index. index=%d >= buf.len=%d\n",V_I4(&index
), buf
.len
);
1530 return E_INVALIDARG
;
1533 mshtml_free(buf
.buf
);
1535 } else if(buf
.size
> buf
.len
) {
1536 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
*));
1538 TRACE("Returning %d element(s).\n", buf
.len
);
1539 return HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
, pdisp
);
1542 FIXME("unsupported arguments\n");
1543 return E_INVALIDARG
;
1546 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1547 VARIANT tagName
, IDispatch
**pdisp
)
1549 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1552 const PRUnichar
*tag
;
1553 elem_vector buf
= {NULL
, 0, 8};
1555 if(V_VT(&tagName
) != VT_BSTR
) {
1556 WARN("Invalid arg\n");
1557 return DISP_E_MEMBERNOTFOUND
;
1560 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1562 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1564 nsAString_Init(&tag_str
, NULL
);
1566 for(i
=0; i
<This
->len
; i
++) {
1567 if(!This
->elems
[i
]->nselem
)
1570 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1571 nsAString_GetData(&tag_str
, &tag
, NULL
);
1573 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1574 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1575 elem_vector_add(&buf
, This
->elems
[i
]);
1578 nsAString_Finish(&tag_str
);
1580 TRACE("fount %d tags\n", buf
.len
);
1583 mshtml_free(buf
.buf
);
1585 }else if(buf
.size
> buf
.len
) {
1586 buf
.buf
= mshtml_realloc(buf
.buf
, buf
.len
*sizeof(HTMLElement
*));
1589 return HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
, pdisp
);
1594 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1595 HTMLElementCollection_QueryInterface
,
1596 HTMLElementCollection_AddRef
,
1597 HTMLElementCollection_Release
,
1598 HTMLElementCollection_GetTypeInfoCount
,
1599 HTMLElementCollection_GetTypeInfo
,
1600 HTMLElementCollection_GetIDsOfNames
,
1601 HTMLElementCollection_Invoke
,
1602 HTMLElementCollection_toString
,
1603 HTMLElementCollection_put_length
,
1604 HTMLElementCollection_get_length
,
1605 HTMLElementCollection_get__newEnum
,
1606 HTMLElementCollection_item
,
1607 HTMLElementCollection_tags
1610 static HRESULT
HTMLElementCollection_Create(IUnknown
*ref_unk
, HTMLElement
**elems
, DWORD len
,
1613 HTMLElementCollection
*ret
= mshtml_alloc(sizeof(HTMLElementCollection
));
1615 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1620 IUnknown_AddRef(ref_unk
);
1621 ret
->ref_unk
= ref_unk
;
1623 TRACE("ret=%p len=%d\n", ret
, len
);
1625 *p
= (IDispatch
*)ret
;