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 IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*,HTMLElement
**,DWORD
);
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 static void elem_vector_normalize(elem_vector
*buf
)
62 mshtml_free(buf
->buf
);
64 }else if(buf
->size
> buf
->len
) {
65 buf
->buf
= mshtml_realloc(buf
->buf
, buf
->len
*sizeof(HTMLElement
**));
71 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
73 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
75 static HRESULT WINAPI
HTMLElement_QueryInterface(IHTMLElement
*iface
,
76 REFIID riid
, void **ppv
)
78 HTMLElement
*This
= HTMLELEM_THIS(iface
);
80 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(&This
->node
), riid
, ppv
);
83 static ULONG WINAPI
HTMLElement_AddRef(IHTMLElement
*iface
)
85 HTMLElement
*This
= HTMLELEM_THIS(iface
);
87 return IHTMLDOMNode_AddRef(HTMLDOMNODE(&This
->node
));
90 static ULONG WINAPI
HTMLElement_Release(IHTMLElement
*iface
)
92 HTMLElement
*This
= HTMLELEM_THIS(iface
);
94 return IHTMLDOMNode_Release(HTMLDOMNODE(&This
->node
));
97 static HRESULT WINAPI
HTMLElement_GetTypeInfoCount(IHTMLElement
*iface
, UINT
*pctinfo
)
99 HTMLElement
*This
= HTMLELEM_THIS(iface
);
100 FIXME("(%p)->(%p)\n", This
, pctinfo
);
104 static HRESULT WINAPI
HTMLElement_GetTypeInfo(IHTMLElement
*iface
, UINT iTInfo
,
105 LCID lcid
, ITypeInfo
**ppTInfo
)
107 HTMLElement
*This
= HTMLELEM_THIS(iface
);
108 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
112 static HRESULT WINAPI
HTMLElement_GetIDsOfNames(IHTMLElement
*iface
, REFIID riid
,
113 LPOLESTR
*rgszNames
, UINT cNames
,
114 LCID lcid
, DISPID
*rgDispId
)
116 HTMLElement
*This
= HTMLELEM_THIS(iface
);
117 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
122 static HRESULT WINAPI
HTMLElement_Invoke(IHTMLElement
*iface
, DISPID dispIdMember
,
123 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
124 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
126 HTMLElement
*This
= HTMLELEM_THIS(iface
);
127 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
128 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
132 static HRESULT WINAPI
HTMLElement_setAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
133 VARIANT AttributeValue
, LONG lFlags
)
135 HTMLElement
*This
= HTMLELEM_THIS(iface
);
140 VARIANT AttributeValueChanged
;
142 WARN("(%p)->(%s . %08x)\n", This
, debugstr_w(strAttributeName
), lFlags
);
144 VariantInit(&AttributeValueChanged
);
146 hres
= VariantChangeType(&AttributeValueChanged
, &AttributeValue
, 0, VT_BSTR
);
148 WARN("couldn't convert input attribute value %d to VT_BSTR\n", V_VT(&AttributeValue
));
152 nsAString_Init(&attr_str
, strAttributeName
);
153 nsAString_Init(&value_str
, V_BSTR(&AttributeValueChanged
));
155 TRACE("setting %s to %s\n", debugstr_w(strAttributeName
),
156 debugstr_w(V_BSTR(&AttributeValueChanged
)));
158 nsres
= nsIDOMHTMLElement_SetAttribute(This
->nselem
, &attr_str
, &value_str
);
159 nsAString_Finish(&attr_str
);
160 nsAString_Finish(&value_str
);
162 if(NS_SUCCEEDED(nsres
)) {
165 ERR("SetAttribute failed: %08x\n", nsres
);
172 static HRESULT WINAPI
HTMLElement_getAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
173 LONG lFlags
, VARIANT
*AttributeValue
)
175 HTMLElement
*This
= HTMLELEM_THIS(iface
);
178 const PRUnichar
*value
;
182 WARN("(%p)->(%s %08x %p)\n", This
, debugstr_w(strAttributeName
), lFlags
, AttributeValue
);
184 VariantInit(AttributeValue
);
186 nsAString_Init(&attr_str
, strAttributeName
);
187 nsAString_Init(&value_str
, NULL
);
189 nsres
= nsIDOMHTMLElement_GetAttribute(This
->nselem
, &attr_str
, &value_str
);
190 nsAString_Finish(&attr_str
);
192 if(NS_SUCCEEDED(nsres
)) {
193 static const WCHAR wszSRC
[] = {'s','r','c',0};
194 nsAString_GetData(&value_str
, &value
, NULL
);
195 if(!strcmpiW(strAttributeName
, wszSRC
))
200 hres
= IHTMLDocument2_get_URL(HTMLDOC(This
->node
.doc
), &bstrBaseUrl
);
201 if(SUCCEEDED(hres
)) {
202 hres
= CoInternetCombineUrl(bstrBaseUrl
, value
,
203 URL_ESCAPE_SPACES_ONLY
|URL_DONT_ESCAPE_EXTRA_INFO
,
204 buffer
, sizeof(buffer
)/sizeof(WCHAR
), &len
, 0);
205 SysFreeString(bstrBaseUrl
);
206 if(SUCCEEDED(hres
)) {
207 V_VT(AttributeValue
) = VT_BSTR
;
208 V_BSTR(AttributeValue
) = SysAllocString(buffer
);
209 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
213 V_VT(AttributeValue
) = VT_BSTR
;
214 V_BSTR(AttributeValue
) = SysAllocString(value
);
215 TRACE("attr_value=%s\n", debugstr_w(V_BSTR(AttributeValue
)));
218 ERR("GetAttribute failed: %08x\n", nsres
);
222 nsAString_Finish(&value_str
);
227 static HRESULT WINAPI
HTMLElement_removeAttribute(IHTMLElement
*iface
, BSTR strAttributeName
,
228 LONG lFlags
, VARIANT_BOOL
*pfSuccess
)
230 HTMLElement
*This
= HTMLELEM_THIS(iface
);
231 FIXME("(%p)->()\n", This
);
235 static HRESULT WINAPI
HTMLElement_put_className(IHTMLElement
*iface
, BSTR v
)
237 HTMLElement
*This
= HTMLELEM_THIS(iface
);
238 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
242 static HRESULT WINAPI
HTMLElement_get_className(IHTMLElement
*iface
, BSTR
*p
)
244 HTMLElement
*This
= HTMLELEM_THIS(iface
);
249 TRACE("(%p)->(%p)\n", This
, p
);
251 nsAString_Init(&class_str
, NULL
);
252 nsres
= nsIDOMHTMLElement_GetClassName(This
->nselem
, &class_str
);
254 if(NS_SUCCEEDED(nsres
)) {
255 const PRUnichar
*class;
256 nsAString_GetData(&class_str
, &class, NULL
);
257 *p
= SysAllocString(class);
259 ERR("GetClassName failed: %08x\n", nsres
);
263 nsAString_Finish(&class_str
);
265 TRACE("className=%s\n", debugstr_w(*p
));
269 static HRESULT WINAPI
HTMLElement_put_id(IHTMLElement
*iface
, BSTR v
)
271 HTMLElement
*This
= HTMLELEM_THIS(iface
);
272 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
276 static HRESULT WINAPI
HTMLElement_get_id(IHTMLElement
*iface
, BSTR
*p
)
278 HTMLElement
*This
= HTMLELEM_THIS(iface
);
279 FIXME("(%p)->(%p)\n", This
, p
);
283 static HRESULT WINAPI
HTMLElement_get_tagName(IHTMLElement
*iface
, BSTR
*p
)
285 HTMLElement
*This
= HTMLELEM_THIS(iface
);
286 const PRUnichar
*tag
;
290 TRACE("(%p)->(%p)\n", This
, p
);
292 nsAString_Init(&tag_str
, NULL
);
293 nsres
= nsIDOMHTMLElement_GetTagName(This
->nselem
, &tag_str
);
294 if(NS_SUCCEEDED(nsres
)) {
295 nsAString_GetData(&tag_str
, &tag
, NULL
);
296 *p
= SysAllocString(tag
);
298 ERR("GetTagName failed: %08x\n", nsres
);
301 nsAString_Finish(&tag_str
);
306 static HRESULT WINAPI
HTMLElement_get_parentElement(IHTMLElement
*iface
, IHTMLElement
**p
)
308 HTMLElement
*This
= HTMLELEM_THIS(iface
);
309 FIXME("(%p)->(%p)\n", This
, p
);
313 static HRESULT WINAPI
HTMLElement_get_style(IHTMLElement
*iface
, IHTMLStyle
**p
)
315 HTMLElement
*This
= HTMLELEM_THIS(iface
);
316 nsIDOMElementCSSInlineStyle
*nselemstyle
;
317 nsIDOMCSSStyleDeclaration
*nsstyle
;
320 TRACE("(%p)->(%p)\n", This
, p
);
322 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMElementCSSInlineStyle
,
323 (void**)&nselemstyle
);
324 if(NS_FAILED(nsres
)) {
325 ERR("Coud not get nsIDOMCSSStyleDeclaration interface: %08x\n", nsres
);
329 nsres
= nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle
, &nsstyle
);
330 nsIDOMElementCSSInlineStyle_Release(nselemstyle
);
331 if(NS_FAILED(nsres
)) {
332 ERR("GetStyle failed: %08x\n", nsres
);
336 /* FIXME: Store style instead of creating a new instance in each call */
337 *p
= HTMLStyle_Create(nsstyle
);
339 nsIDOMCSSStyleDeclaration_Release(nsstyle
);
343 static HRESULT WINAPI
HTMLElement_put_onhelp(IHTMLElement
*iface
, VARIANT v
)
345 HTMLElement
*This
= HTMLELEM_THIS(iface
);
346 FIXME("(%p)->()\n", This
);
350 static HRESULT WINAPI
HTMLElement_get_onhelp(IHTMLElement
*iface
, VARIANT
*p
)
352 HTMLElement
*This
= HTMLELEM_THIS(iface
);
353 FIXME("(%p)->(%p)\n", This
, p
);
357 static HRESULT WINAPI
HTMLElement_put_onclick(IHTMLElement
*iface
, VARIANT v
)
359 HTMLElement
*This
= HTMLELEM_THIS(iface
);
360 FIXME("(%p)->()\n", This
);
364 static HRESULT WINAPI
HTMLElement_get_onclick(IHTMLElement
*iface
, VARIANT
*p
)
366 HTMLElement
*This
= HTMLELEM_THIS(iface
);
367 FIXME("(%p)->(%p)\n", This
, p
);
371 static HRESULT WINAPI
HTMLElement_put_ondblclick(IHTMLElement
*iface
, VARIANT v
)
373 HTMLElement
*This
= HTMLELEM_THIS(iface
);
374 FIXME("(%p)->()\n", This
);
378 static HRESULT WINAPI
HTMLElement_get_ondblclick(IHTMLElement
*iface
, VARIANT
*p
)
380 HTMLElement
*This
= HTMLELEM_THIS(iface
);
381 FIXME("(%p)->(%p)\n", This
, p
);
385 static HRESULT WINAPI
HTMLElement_put_onkeydown(IHTMLElement
*iface
, VARIANT v
)
387 HTMLElement
*This
= HTMLELEM_THIS(iface
);
388 FIXME("(%p)->()\n", This
);
392 static HRESULT WINAPI
HTMLElement_get_onkeydown(IHTMLElement
*iface
, VARIANT
*p
)
394 HTMLElement
*This
= HTMLELEM_THIS(iface
);
395 FIXME("(%p)->(%p)\n", This
, p
);
399 static HRESULT WINAPI
HTMLElement_put_onkeyup(IHTMLElement
*iface
, VARIANT v
)
401 HTMLElement
*This
= HTMLELEM_THIS(iface
);
402 FIXME("(%p)->()\n", This
);
406 static HRESULT WINAPI
HTMLElement_get_onkeyup(IHTMLElement
*iface
, VARIANT
*p
)
408 HTMLElement
*This
= HTMLELEM_THIS(iface
);
409 FIXME("(%p)->(%p)\n", This
, p
);
413 static HRESULT WINAPI
HTMLElement_put_onkeypress(IHTMLElement
*iface
, VARIANT v
)
415 HTMLElement
*This
= HTMLELEM_THIS(iface
);
416 FIXME("(%p)->()\n", This
);
420 static HRESULT WINAPI
HTMLElement_get_onkeypress(IHTMLElement
*iface
, VARIANT
*p
)
422 HTMLElement
*This
= HTMLELEM_THIS(iface
);
423 FIXME("(%p)->(%p)\n", This
, p
);
427 static HRESULT WINAPI
HTMLElement_put_onmouseout(IHTMLElement
*iface
, VARIANT v
)
429 HTMLElement
*This
= HTMLELEM_THIS(iface
);
430 FIXME("(%p)->()\n", This
);
434 static HRESULT WINAPI
HTMLElement_get_onmouseout(IHTMLElement
*iface
, VARIANT
*p
)
436 HTMLElement
*This
= HTMLELEM_THIS(iface
);
437 FIXME("(%p)->(%p)\n", This
, p
);
441 static HRESULT WINAPI
HTMLElement_put_onmouseover(IHTMLElement
*iface
, VARIANT v
)
443 HTMLElement
*This
= HTMLELEM_THIS(iface
);
444 FIXME("(%p)->()\n", This
);
448 static HRESULT WINAPI
HTMLElement_get_onmouseover(IHTMLElement
*iface
, VARIANT
*p
)
450 HTMLElement
*This
= HTMLELEM_THIS(iface
);
451 FIXME("(%p)->(%p)\n", This
, p
);
455 static HRESULT WINAPI
HTMLElement_put_onmousemove(IHTMLElement
*iface
, VARIANT v
)
457 HTMLElement
*This
= HTMLELEM_THIS(iface
);
458 FIXME("(%p)->()\n", This
);
462 static HRESULT WINAPI
HTMLElement_get_onmousemove(IHTMLElement
*iface
, VARIANT
*p
)
464 HTMLElement
*This
= HTMLELEM_THIS(iface
);
465 FIXME("(%p)->(%p)\n", This
, p
);
469 static HRESULT WINAPI
HTMLElement_put_onmousedown(IHTMLElement
*iface
, VARIANT v
)
471 HTMLElement
*This
= HTMLELEM_THIS(iface
);
472 FIXME("(%p)->()\n", This
);
476 static HRESULT WINAPI
HTMLElement_get_onmousedown(IHTMLElement
*iface
, VARIANT
*p
)
478 HTMLElement
*This
= HTMLELEM_THIS(iface
);
479 FIXME("(%p)->(%p)\n", This
, p
);
483 static HRESULT WINAPI
HTMLElement_put_onmouseup(IHTMLElement
*iface
, VARIANT v
)
485 HTMLElement
*This
= HTMLELEM_THIS(iface
);
486 FIXME("(%p)->()\n", This
);
490 static HRESULT WINAPI
HTMLElement_get_onmouseup(IHTMLElement
*iface
, VARIANT
*p
)
492 HTMLElement
*This
= HTMLELEM_THIS(iface
);
493 FIXME("(%p)->(%p)\n", This
, p
);
497 static HRESULT WINAPI
HTMLElement_get_document(IHTMLElement
*iface
, IDispatch
**p
)
499 HTMLElement
*This
= HTMLELEM_THIS(iface
);
500 FIXME("(%p)->(%p)\n", This
, p
);
504 static HRESULT WINAPI
HTMLElement_put_title(IHTMLElement
*iface
, BSTR v
)
506 HTMLElement
*This
= HTMLELEM_THIS(iface
);
507 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
511 static HRESULT WINAPI
HTMLElement_get_title(IHTMLElement
*iface
, BSTR
*p
)
513 HTMLElement
*This
= HTMLELEM_THIS(iface
);
514 FIXME("(%p)->(%p)\n", This
, p
);
518 static HRESULT WINAPI
HTMLElement_put_language(IHTMLElement
*iface
, BSTR v
)
520 HTMLElement
*This
= HTMLELEM_THIS(iface
);
521 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
525 static HRESULT WINAPI
HTMLElement_get_language(IHTMLElement
*iface
, BSTR
*p
)
527 HTMLElement
*This
= HTMLELEM_THIS(iface
);
528 FIXME("(%p)->(%p)\n", This
, p
);
532 static HRESULT WINAPI
HTMLElement_put_onselectstart(IHTMLElement
*iface
, VARIANT v
)
534 HTMLElement
*This
= HTMLELEM_THIS(iface
);
535 FIXME("(%p)->()\n", This
);
539 static HRESULT WINAPI
HTMLElement_get_onselectstart(IHTMLElement
*iface
, VARIANT
*p
)
541 HTMLElement
*This
= HTMLELEM_THIS(iface
);
542 FIXME("(%p)->(%p)\n", This
, p
);
546 static HRESULT WINAPI
HTMLElement_scrollIntoView(IHTMLElement
*iface
, VARIANT varargStart
)
548 HTMLElement
*This
= HTMLELEM_THIS(iface
);
549 FIXME("(%p)->()\n", This
);
553 static HRESULT WINAPI
HTMLElement_contains(IHTMLElement
*iface
, IHTMLElement
*pChild
,
554 VARIANT_BOOL
*pfResult
)
556 HTMLElement
*This
= HTMLELEM_THIS(iface
);
557 FIXME("(%p)->(%p %p)\n", This
, pChild
, pfResult
);
561 static HRESULT WINAPI
HTMLElement_get_sourceIndex(IHTMLElement
*iface
, long *p
)
563 HTMLElement
*This
= HTMLELEM_THIS(iface
);
564 FIXME("(%p)->(%p)\n", This
, p
);
568 static HRESULT WINAPI
HTMLElement_get_recordNumber(IHTMLElement
*iface
, VARIANT
*p
)
570 HTMLElement
*This
= HTMLELEM_THIS(iface
);
571 FIXME("(%p)->(%p)\n", This
, p
);
575 static HRESULT WINAPI
HTMLElement_put_lang(IHTMLElement
*iface
, BSTR v
)
577 HTMLElement
*This
= HTMLELEM_THIS(iface
);
578 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
582 static HRESULT WINAPI
HTMLElement_get_lang(IHTMLElement
*iface
, BSTR
*p
)
584 HTMLElement
*This
= HTMLELEM_THIS(iface
);
585 FIXME("(%p)->(%p)\n", This
, p
);
589 static HRESULT WINAPI
HTMLElement_get_offsetLeft(IHTMLElement
*iface
, long *p
)
591 HTMLElement
*This
= HTMLELEM_THIS(iface
);
592 FIXME("(%p)->(%p)\n", This
, p
);
596 static HRESULT WINAPI
HTMLElement_get_offsetTop(IHTMLElement
*iface
, long *p
)
598 HTMLElement
*This
= HTMLELEM_THIS(iface
);
599 FIXME("(%p)->(%p)\n", This
, p
);
603 static HRESULT WINAPI
HTMLElement_get_offsetWidth(IHTMLElement
*iface
, long *p
)
605 HTMLElement
*This
= HTMLELEM_THIS(iface
);
606 FIXME("(%p)->(%p)\n", This
, p
);
610 static HRESULT WINAPI
HTMLElement_get_offsetHeight(IHTMLElement
*iface
, long *p
)
612 HTMLElement
*This
= HTMLELEM_THIS(iface
);
613 FIXME("(%p)->(%p)\n", This
, p
);
617 static HRESULT WINAPI
HTMLElement_get_offsetParent(IHTMLElement
*iface
, IHTMLElement
**p
)
619 HTMLElement
*This
= HTMLELEM_THIS(iface
);
620 FIXME("(%p)->(%p)\n", This
, p
);
624 static HRESULT WINAPI
HTMLElement_put_innerHTML(IHTMLElement
*iface
, BSTR v
)
626 HTMLElement
*This
= HTMLELEM_THIS(iface
);
627 nsIDOMNSHTMLElement
*nselem
;
631 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
633 nsres
= nsIDOMHTMLElement_QueryInterface(This
->nselem
, &IID_nsIDOMNSHTMLElement
, (void**)&nselem
);
634 if(NS_FAILED(nsres
)) {
635 ERR("Could not get nsIDOMNSHTMLElement: %08x\n", nsres
);
639 nsAString_Init(&html_str
, v
);
640 nsres
= nsIDOMNSHTMLElement_SetInnerHTML(nselem
, &html_str
);
641 nsAString_Finish(&html_str
);
643 if(NS_FAILED(nsres
)) {
644 FIXME("SetInnerHtml failed %08x\n", nsres
);
651 static HRESULT WINAPI
HTMLElement_get_innerHTML(IHTMLElement
*iface
, BSTR
*p
)
653 HTMLElement
*This
= HTMLELEM_THIS(iface
);
654 FIXME("(%p)->(%p)\n", This
, p
);
658 static HRESULT WINAPI
HTMLElement_put_innerText(IHTMLElement
*iface
, BSTR v
)
660 HTMLElement
*This
= HTMLELEM_THIS(iface
);
661 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
665 static HRESULT WINAPI
HTMLElement_get_innerText(IHTMLElement
*iface
, BSTR
*p
)
667 HTMLElement
*This
= HTMLELEM_THIS(iface
);
668 FIXME("(%p)->(%p)\n", This
, p
);
672 static HRESULT WINAPI
HTMLElement_put_outerHTML(IHTMLElement
*iface
, BSTR v
)
674 HTMLElement
*This
= HTMLELEM_THIS(iface
);
675 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
679 static HRESULT WINAPI
HTMLElement_get_outerHTML(IHTMLElement
*iface
, BSTR
*p
)
681 HTMLElement
*This
= HTMLELEM_THIS(iface
);
682 FIXME("(%p)->(%p)\n", This
, p
);
686 static HRESULT WINAPI
HTMLElement_put_outerText(IHTMLElement
*iface
, BSTR v
)
688 HTMLElement
*This
= HTMLELEM_THIS(iface
);
689 FIXME("(%p)->(%s)\n", This
, debugstr_w(v
));
693 static HRESULT WINAPI
HTMLElement_get_outerText(IHTMLElement
*iface
, BSTR
*p
)
695 HTMLElement
*This
= HTMLELEM_THIS(iface
);
696 FIXME("(%p)->(%p)\n", This
, p
);
700 static HRESULT
HTMLElement_InsertAdjacentNode(HTMLElement
*This
, BSTR where
, nsIDOMNode
*nsnode
)
702 static const WCHAR wszBeforeBegin
[] = {'b','e','f','o','r','e','B','e','g','i','n',0};
703 static const WCHAR wszAfterBegin
[] = {'a','f','t','e','r','B','e','g','i','n',0};
704 static const WCHAR wszBeforeEnd
[] = {'b','e','f','o','r','e','E','n','d',0};
705 static const WCHAR wszAfterEnd
[] = {'a','f','t','e','r','E','n','d',0};
708 if (!strcmpiW(where
, wszBeforeBegin
))
712 nsres
= nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
713 if (!parent
) return E_INVALIDARG
;
714 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
,
715 (nsIDOMNode
*)This
->nselem
, &unused
);
716 if (unused
) nsIDOMNode_Release(unused
);
717 nsIDOMNode_Release(parent
);
719 else if (!strcmpiW(where
, wszAfterBegin
))
722 nsIDOMNode
*first_child
;
723 nsIDOMNode_GetFirstChild(This
->nselem
, &first_child
);
724 nsres
= nsIDOMNode_InsertBefore(This
->nselem
, nsnode
, first_child
, &unused
);
725 if (unused
) nsIDOMNode_Release(unused
);
726 if (first_child
) nsIDOMNode_Release(first_child
);
728 else if (!strcmpiW(where
, wszBeforeEnd
))
731 nsres
= nsIDOMNode_AppendChild(This
->nselem
, nsnode
, &unused
);
732 if (unused
) nsIDOMNode_Release(unused
);
734 else if (!strcmpiW(where
, wszAfterEnd
))
737 nsIDOMNode
*next_sibling
;
739 nsIDOMNode_GetParentNode(This
->nselem
, &parent
);
740 if (!parent
) return E_INVALIDARG
;
742 nsIDOMNode_GetNextSibling(This
->nselem
, &next_sibling
);
745 nsres
= nsIDOMNode_InsertBefore(parent
, nsnode
, next_sibling
, &unused
);
746 nsIDOMNode_Release(next_sibling
);
749 nsres
= nsIDOMNode_AppendChild(parent
, nsnode
, &unused
);
750 nsIDOMNode_Release(parent
);
751 if (unused
) nsIDOMNode_Release(unused
);
755 ERR("invalid where: %s\n", debugstr_w(where
));
759 if (NS_FAILED(nsres
))
765 static HRESULT WINAPI
HTMLElement_insertAdjacentHTML(IHTMLElement
*iface
, BSTR where
,
768 HTMLElement
*This
= HTMLELEM_THIS(iface
);
770 nsIDOMDocument
*nsdoc
;
771 nsIDOMDocumentRange
*nsdocrange
;
773 nsIDOMNSRange
*nsrange
;
778 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(html
));
780 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
783 ERR("GetDocument failed: %08x\n", nsres
);
787 nsres
= nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMDocumentRange
, (void **)&nsdocrange
);
788 nsIDOMDocument_Release(nsdoc
);
791 ERR("getting nsIDOMDocumentRange failed: %08x\n", nsres
);
794 nsres
= nsIDOMDocumentRange_CreateRange(nsdocrange
, &range
);
795 nsIDOMDocumentRange_Release(nsdocrange
);
798 ERR("CreateRange failed: %08x\n", nsres
);
802 nsIDOMRange_SetStartBefore(range
, (nsIDOMNode
*)This
->nselem
);
804 nsIDOMRange_QueryInterface(range
, &IID_nsIDOMNSRange
, (void **)&nsrange
);
805 nsIDOMRange_Release(range
);
808 ERR("getting nsIDOMNSRange failed: %08x\n", nsres
);
812 nsAString_Init(&ns_html
, html
);
814 nsres
= nsIDOMNSRange_CreateContextualFragment(nsrange
, &ns_html
, (nsIDOMDocumentFragment
**)&nsnode
);
815 nsIDOMNSRange_Release(nsrange
);
816 nsAString_Finish(&ns_html
);
818 if(NS_FAILED(nsres
) || !nsnode
)
820 ERR("CreateTextNode failed: %08x\n", nsres
);
824 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
825 nsIDOMNode_Release(nsnode
);
830 static HRESULT WINAPI
HTMLElement_insertAdjacentText(IHTMLElement
*iface
, BSTR where
,
833 HTMLElement
*This
= HTMLELEM_THIS(iface
);
835 nsIDOMDocument
*nsdoc
;
840 TRACE("(%p)->(%s %s)\n", This
, debugstr_w(where
), debugstr_w(text
));
842 nsres
= nsIWebNavigation_GetDocument(This
->node
.doc
->nscontainer
->navigation
, &nsdoc
);
843 if(NS_FAILED(nsres
) || !nsdoc
)
845 ERR("GetDocument failed: %08x\n", nsres
);
849 nsAString_Init(&ns_text
, text
);
851 nsres
= nsIDOMDocument_CreateTextNode(nsdoc
, &ns_text
, (nsIDOMText
**)&nsnode
);
852 nsIDOMDocument_Release(nsdoc
);
853 nsAString_Finish(&ns_text
);
855 if(NS_FAILED(nsres
) || !nsnode
)
857 ERR("CreateTextNode failed: %08x\n", nsres
);
861 hr
= HTMLElement_InsertAdjacentNode(This
, where
, nsnode
);
862 nsIDOMNode_Release(nsnode
);
867 static HRESULT WINAPI
HTMLElement_get_parentTextEdit(IHTMLElement
*iface
, IHTMLElement
**p
)
869 HTMLElement
*This
= HTMLELEM_THIS(iface
);
870 FIXME("(%p)->(%p)\n", This
, p
);
874 static HRESULT WINAPI
HTMLElement_get_isTextEdit(IHTMLElement
*iface
, VARIANT_BOOL
*p
)
876 HTMLElement
*This
= HTMLELEM_THIS(iface
);
877 FIXME("(%p)->(%p)\n", This
, p
);
881 static HRESULT WINAPI
HTMLElement_click(IHTMLElement
*iface
)
883 HTMLElement
*This
= HTMLELEM_THIS(iface
);
884 FIXME("(%p)\n", This
);
888 static HRESULT WINAPI
HTMLElement_get_filters(IHTMLElement
*iface
,
889 IHTMLFiltersCollection
**p
)
891 HTMLElement
*This
= HTMLELEM_THIS(iface
);
892 FIXME("(%p)->(%p)\n", This
, p
);
896 static HRESULT WINAPI
HTMLElement_put_ondragstart(IHTMLElement
*iface
, VARIANT v
)
898 HTMLElement
*This
= HTMLELEM_THIS(iface
);
899 FIXME("(%p)->()\n", This
);
903 static HRESULT WINAPI
HTMLElement_get_ondragstart(IHTMLElement
*iface
, VARIANT
*p
)
905 HTMLElement
*This
= HTMLELEM_THIS(iface
);
906 FIXME("(%p)->(%p)\n", This
, p
);
910 static HRESULT WINAPI
HTMLElement_toString(IHTMLElement
*iface
, BSTR
*String
)
912 HTMLElement
*This
= HTMLELEM_THIS(iface
);
913 FIXME("(%p)->(%p)\n", This
, String
);
917 static HRESULT WINAPI
HTMLElement_put_onbeforeupdate(IHTMLElement
*iface
, VARIANT v
)
919 HTMLElement
*This
= HTMLELEM_THIS(iface
);
920 FIXME("(%p)->()\n", This
);
924 static HRESULT WINAPI
HTMLElement_get_onbeforeupdate(IHTMLElement
*iface
, VARIANT
*p
)
926 HTMLElement
*This
= HTMLELEM_THIS(iface
);
927 FIXME("(%p)->(%p)\n", This
, p
);
931 static HRESULT WINAPI
HTMLElement_put_onafterupdate(IHTMLElement
*iface
, VARIANT v
)
933 HTMLElement
*This
= HTMLELEM_THIS(iface
);
934 FIXME("(%p)->()\n", This
);
938 static HRESULT WINAPI
HTMLElement_get_onafterupdate(IHTMLElement
*iface
, VARIANT
*p
)
940 HTMLElement
*This
= HTMLELEM_THIS(iface
);
941 FIXME("(%p)->(%p)\n", This
, p
);
945 static HRESULT WINAPI
HTMLElement_put_onerrorupdate(IHTMLElement
*iface
, VARIANT v
)
947 HTMLElement
*This
= HTMLELEM_THIS(iface
);
948 FIXME("(%p)->()\n", This
);
952 static HRESULT WINAPI
HTMLElement_get_onerrorupdate(IHTMLElement
*iface
, VARIANT
*p
)
954 HTMLElement
*This
= HTMLELEM_THIS(iface
);
955 FIXME("(%p)->(%p)\n", This
, p
);
959 static HRESULT WINAPI
HTMLElement_put_onrowexit(IHTMLElement
*iface
, VARIANT v
)
961 HTMLElement
*This
= HTMLELEM_THIS(iface
);
962 FIXME("(%p)->()\n", This
);
966 static HRESULT WINAPI
HTMLElement_get_onrowexit(IHTMLElement
*iface
, VARIANT
*p
)
968 HTMLElement
*This
= HTMLELEM_THIS(iface
);
969 FIXME("(%p)->(%p)\n", This
, p
);
973 static HRESULT WINAPI
HTMLElement_put_onrowenter(IHTMLElement
*iface
, VARIANT v
)
975 HTMLElement
*This
= HTMLELEM_THIS(iface
);
976 FIXME("(%p)->()\n", This
);
980 static HRESULT WINAPI
HTMLElement_get_onrowenter(IHTMLElement
*iface
, VARIANT
*p
)
982 HTMLElement
*This
= HTMLELEM_THIS(iface
);
983 FIXME("(%p)->(%p)\n", This
, p
);
987 static HRESULT WINAPI
HTMLElement_put_ondatasetchanged(IHTMLElement
*iface
, VARIANT v
)
989 HTMLElement
*This
= HTMLELEM_THIS(iface
);
990 FIXME("(%p)->()\n", This
);
994 static HRESULT WINAPI
HTMLElement_get_ondatasetchanged(IHTMLElement
*iface
, VARIANT
*p
)
996 HTMLElement
*This
= HTMLELEM_THIS(iface
);
997 FIXME("(%p)->(%p)\n", This
, p
);
1001 static HRESULT WINAPI
HTMLElement_put_ondataavailable(IHTMLElement
*iface
, VARIANT v
)
1003 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1004 FIXME("(%p)->()\n", This
);
1008 static HRESULT WINAPI
HTMLElement_get_ondataavailable(IHTMLElement
*iface
, VARIANT
*p
)
1010 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1011 FIXME("(%p)->(%p)\n", This
, p
);
1015 static HRESULT WINAPI
HTMLElement_put_ondatasetcomplete(IHTMLElement
*iface
, VARIANT v
)
1017 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1018 FIXME("(%p)->()\n", This
);
1022 static HRESULT WINAPI
HTMLElement_get_ondatasetcomplete(IHTMLElement
*iface
, VARIANT
*p
)
1024 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1025 FIXME("(%p)->(%p)\n", This
, p
);
1029 static HRESULT WINAPI
HTMLElement_put_onfilterchange(IHTMLElement
*iface
, VARIANT v
)
1031 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1032 FIXME("(%p)->()\n", This
);
1036 static HRESULT WINAPI
HTMLElement_get_onfilterchange(IHTMLElement
*iface
, VARIANT
*p
)
1038 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1039 FIXME("(%p)->(%p)\n", This
, p
);
1043 static void create_child_list(HTMLDocument
*doc
, HTMLElement
*elem
, elem_vector
*buf
)
1045 nsIDOMNodeList
*nsnode_list
;
1047 PRUint32 list_len
= 0, i
;
1051 nsres
= nsIDOMNode_GetChildNodes(elem
->node
.nsnode
, &nsnode_list
);
1052 if(NS_FAILED(nsres
)) {
1053 ERR("GetChildNodes failed: %08x\n", nsres
);
1057 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1061 buf
->size
= list_len
;
1062 buf
->buf
= mshtml_alloc(buf
->size
*sizeof(HTMLElement
**));
1064 for(i
=0; i
<list_len
; i
++) {
1065 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1066 if(NS_FAILED(nsres
)) {
1067 ERR("Item failed: %08x\n", nsres
);
1071 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1072 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
)
1073 elem_vector_add(buf
, HTMLELEM_NODE_THIS(get_node(doc
, iter
)));
1077 static HRESULT WINAPI
HTMLElement_get_children(IHTMLElement
*iface
, IDispatch
**p
)
1079 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1080 elem_vector buf
= {NULL
, 0, 0};
1082 TRACE("(%p)->(%p)\n", This
, p
);
1084 create_child_list(This
->node
.doc
, This
, &buf
);
1086 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1090 static void create_all_list(HTMLDocument
*doc
, HTMLDOMNode
*elem
, elem_vector
*buf
)
1092 nsIDOMNodeList
*nsnode_list
;
1094 PRUint32 list_len
= 0, i
;
1098 nsres
= nsIDOMNode_GetChildNodes(elem
->nsnode
, &nsnode_list
);
1099 if(NS_FAILED(nsres
)) {
1100 ERR("GetChildNodes failed: %08x\n", nsres
);
1104 nsIDOMNodeList_GetLength(nsnode_list
, &list_len
);
1108 for(i
=0; i
<list_len
; i
++) {
1109 nsres
= nsIDOMNodeList_Item(nsnode_list
, i
, &iter
);
1110 if(NS_FAILED(nsres
)) {
1111 ERR("Item failed: %08x\n", nsres
);
1115 nsres
= nsIDOMNode_GetNodeType(iter
, &node_type
);
1116 if(NS_SUCCEEDED(nsres
) && node_type
== ELEMENT_NODE
) {
1117 HTMLDOMNode
*node
= get_node(doc
, iter
);
1119 elem_vector_add(buf
, HTMLELEM_NODE_THIS(node
));
1120 create_all_list(doc
, node
, buf
);
1125 static HRESULT WINAPI
HTMLElement_get_all(IHTMLElement
*iface
, IDispatch
**p
)
1127 HTMLElement
*This
= HTMLELEM_THIS(iface
);
1128 elem_vector buf
= {NULL
, 0, 8};
1130 TRACE("(%p)->(%p)\n", This
, p
);
1132 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
**));
1134 create_all_list(This
->node
.doc
, &This
->node
, &buf
);
1135 elem_vector_normalize(&buf
);
1137 *p
= (IDispatch
*)HTMLElementCollection_Create((IUnknown
*)HTMLELEM(This
), buf
.buf
, buf
.len
);
1141 #undef HTMLELEM_THIS
1143 static const IHTMLElementVtbl HTMLElementVtbl
= {
1144 HTMLElement_QueryInterface
,
1146 HTMLElement_Release
,
1147 HTMLElement_GetTypeInfoCount
,
1148 HTMLElement_GetTypeInfo
,
1149 HTMLElement_GetIDsOfNames
,
1151 HTMLElement_setAttribute
,
1152 HTMLElement_getAttribute
,
1153 HTMLElement_removeAttribute
,
1154 HTMLElement_put_className
,
1155 HTMLElement_get_className
,
1158 HTMLElement_get_tagName
,
1159 HTMLElement_get_parentElement
,
1160 HTMLElement_get_style
,
1161 HTMLElement_put_onhelp
,
1162 HTMLElement_get_onhelp
,
1163 HTMLElement_put_onclick
,
1164 HTMLElement_get_onclick
,
1165 HTMLElement_put_ondblclick
,
1166 HTMLElement_get_ondblclick
,
1167 HTMLElement_put_onkeydown
,
1168 HTMLElement_get_onkeydown
,
1169 HTMLElement_put_onkeyup
,
1170 HTMLElement_get_onkeyup
,
1171 HTMLElement_put_onkeypress
,
1172 HTMLElement_get_onkeypress
,
1173 HTMLElement_put_onmouseout
,
1174 HTMLElement_get_onmouseout
,
1175 HTMLElement_put_onmouseover
,
1176 HTMLElement_get_onmouseover
,
1177 HTMLElement_put_onmousemove
,
1178 HTMLElement_get_onmousemove
,
1179 HTMLElement_put_onmousedown
,
1180 HTMLElement_get_onmousedown
,
1181 HTMLElement_put_onmouseup
,
1182 HTMLElement_get_onmouseup
,
1183 HTMLElement_get_document
,
1184 HTMLElement_put_title
,
1185 HTMLElement_get_title
,
1186 HTMLElement_put_language
,
1187 HTMLElement_get_language
,
1188 HTMLElement_put_onselectstart
,
1189 HTMLElement_get_onselectstart
,
1190 HTMLElement_scrollIntoView
,
1191 HTMLElement_contains
,
1192 HTMLElement_get_sourceIndex
,
1193 HTMLElement_get_recordNumber
,
1194 HTMLElement_put_lang
,
1195 HTMLElement_get_lang
,
1196 HTMLElement_get_offsetLeft
,
1197 HTMLElement_get_offsetTop
,
1198 HTMLElement_get_offsetWidth
,
1199 HTMLElement_get_offsetHeight
,
1200 HTMLElement_get_offsetParent
,
1201 HTMLElement_put_innerHTML
,
1202 HTMLElement_get_innerHTML
,
1203 HTMLElement_put_innerText
,
1204 HTMLElement_get_innerText
,
1205 HTMLElement_put_outerHTML
,
1206 HTMLElement_get_outerHTML
,
1207 HTMLElement_put_outerText
,
1208 HTMLElement_get_outerText
,
1209 HTMLElement_insertAdjacentHTML
,
1210 HTMLElement_insertAdjacentText
,
1211 HTMLElement_get_parentTextEdit
,
1212 HTMLElement_get_isTextEdit
,
1214 HTMLElement_get_filters
,
1215 HTMLElement_put_ondragstart
,
1216 HTMLElement_get_ondragstart
,
1217 HTMLElement_toString
,
1218 HTMLElement_put_onbeforeupdate
,
1219 HTMLElement_get_onbeforeupdate
,
1220 HTMLElement_put_onafterupdate
,
1221 HTMLElement_get_onafterupdate
,
1222 HTMLElement_put_onerrorupdate
,
1223 HTMLElement_get_onerrorupdate
,
1224 HTMLElement_put_onrowexit
,
1225 HTMLElement_get_onrowexit
,
1226 HTMLElement_put_onrowenter
,
1227 HTMLElement_get_onrowenter
,
1228 HTMLElement_put_ondatasetchanged
,
1229 HTMLElement_get_ondatasetchanged
,
1230 HTMLElement_put_ondataavailable
,
1231 HTMLElement_get_ondataavailable
,
1232 HTMLElement_put_ondatasetcomplete
,
1233 HTMLElement_get_ondatasetcomplete
,
1234 HTMLElement_put_onfilterchange
,
1235 HTMLElement_get_onfilterchange
,
1236 HTMLElement_get_children
,
1240 HRESULT
HTMLElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
1242 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
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 void HTMLElement_destructor(HTMLDOMNode
*iface
)
1270 HTMLElement
*This
= HTMLELEM_NODE_THIS(iface
);
1273 nsIDOMHTMLElement_Release(This
->nselem
);
1275 HTMLDOMNode_destructor(&This
->node
);
1278 static const NodeImplVtbl HTMLElementImplVtbl
= {
1280 HTMLElement_destructor
1283 HTMLElement
*HTMLElement_Create(nsIDOMNode
*nsnode
)
1285 nsIDOMHTMLElement
*nselem
;
1286 HTMLElement
*ret
= NULL
;
1287 nsAString class_name_str
;
1288 const PRUnichar
*class_name
;
1291 static const WCHAR wszA
[] = {'A',0};
1292 static const WCHAR wszBODY
[] = {'B','O','D','Y',0};
1293 static const WCHAR wszINPUT
[] = {'I','N','P','U','T',0};
1294 static const WCHAR wszOPTION
[] = {'O','P','T','I','O','N',0};
1295 static const WCHAR wszSELECT
[] = {'S','E','L','E','C','T',0};
1296 static const WCHAR wszTABLE
[] = {'T','A','B','L','E',0};
1297 static const WCHAR wszTEXTAREA
[] = {'T','E','X','T','A','R','E','A',0};
1299 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
1300 if(NS_FAILED(nsres
))
1303 nsAString_Init(&class_name_str
, NULL
);
1304 nsIDOMHTMLElement_GetTagName(nselem
, &class_name_str
);
1306 nsAString_GetData(&class_name_str
, &class_name
, NULL
);
1308 if(!strcmpW(class_name
, wszA
))
1309 ret
= HTMLAnchorElement_Create(nselem
);
1310 else if(!strcmpW(class_name
, wszBODY
))
1311 ret
= HTMLBodyElement_Create(nselem
);
1312 else if(!strcmpW(class_name
, wszINPUT
))
1313 ret
= HTMLInputElement_Create(nselem
);
1314 else if(!strcmpW(class_name
, wszOPTION
))
1315 ret
= HTMLOptionElement_Create(nselem
);
1316 else if(!strcmpW(class_name
, wszSELECT
))
1317 ret
= HTMLSelectElement_Create(nselem
);
1318 else if(!strcmpW(class_name
, wszTABLE
))
1319 ret
= HTMLTable_Create(nselem
);
1320 else if(!strcmpW(class_name
, wszTEXTAREA
))
1321 ret
= HTMLTextAreaElement_Create(nselem
);
1324 ret
= mshtml_alloc(sizeof(HTMLElement
));
1325 ret
->node
.vtbl
= &HTMLElementImplVtbl
;
1328 nsAString_Finish(&class_name_str
);
1330 ret
->lpHTMLElementVtbl
= &HTMLElementVtbl
;
1331 ret
->nselem
= nselem
;
1333 HTMLElement2_Init(ret
);
1339 const IHTMLElementCollectionVtbl
*lpHTMLElementCollectionVtbl
;
1342 HTMLElement
**elems
;
1346 } HTMLElementCollection
;
1348 #define HTMLELEMCOL(x) ((IHTMLElementCollection*) &(x)->lpHTMLElementCollectionVtbl)
1350 #define ELEMCOL_THIS(iface) DEFINE_THIS(HTMLElementCollection, HTMLElementCollection, iface)
1352 static HRESULT WINAPI
HTMLElementCollection_QueryInterface(IHTMLElementCollection
*iface
,
1353 REFIID riid
, void **ppv
)
1355 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1359 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1360 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
1361 *ppv
= HTMLELEMCOL(This
);
1362 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
1363 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
1364 *ppv
= HTMLELEMCOL(This
);
1365 }else if(IsEqualGUID(&IID_IHTMLElementCollection
, riid
)) {
1366 TRACE("(%p)->(IID_IHTMLElementCollection %p)\n", This
, ppv
);
1367 *ppv
= HTMLELEMCOL(This
);
1371 IHTMLElementCollection_AddRef(HTMLELEMCOL(This
));
1375 FIXME("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
1376 return E_NOINTERFACE
;
1379 static ULONG WINAPI
HTMLElementCollection_AddRef(IHTMLElementCollection
*iface
)
1381 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1382 LONG ref
= InterlockedIncrement(&This
->ref
);
1384 TRACE("(%p) ref=%d\n", This
, ref
);
1389 static ULONG WINAPI
HTMLElementCollection_Release(IHTMLElementCollection
*iface
)
1391 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1392 LONG ref
= InterlockedDecrement(&This
->ref
);
1394 TRACE("(%p) ref=%d\n", This
, ref
);
1397 IUnknown_Release(This
->ref_unk
);
1398 mshtml_free(This
->elems
);
1405 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection
*iface
,
1408 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1409 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1413 static HRESULT WINAPI
HTMLElementCollection_GetTypeInfo(IHTMLElementCollection
*iface
,
1414 UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1416 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1417 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1421 static HRESULT WINAPI
HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection
*iface
,
1422 REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1424 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1425 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1430 static HRESULT WINAPI
HTMLElementCollection_Invoke(IHTMLElementCollection
*iface
,
1431 DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1432 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1434 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1435 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1436 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1440 static HRESULT WINAPI
HTMLElementCollection_toString(IHTMLElementCollection
*iface
,
1443 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1444 FIXME("(%p)->(%p)\n", This
, String
);
1448 static HRESULT WINAPI
HTMLElementCollection_put_length(IHTMLElementCollection
*iface
,
1451 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1452 FIXME("(%p)->(%ld)\n", This
, v
);
1456 static HRESULT WINAPI
HTMLElementCollection_get_length(IHTMLElementCollection
*iface
,
1459 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1461 TRACE("(%p)->(%p)\n", This
, p
);
1467 static HRESULT WINAPI
HTMLElementCollection_get__newEnum(IHTMLElementCollection
*iface
,
1470 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1471 FIXME("(%p)->(%p)\n", This
, p
);
1475 static BOOL
is_elem_name(HTMLElement
*elem
, LPCWSTR name
)
1477 const PRUnichar
*str
;
1478 nsAString nsstr
, nsname
;
1482 static const PRUnichar nameW
[] = {'n','a','m','e',0};
1484 nsAString_Init(&nsstr
, NULL
);
1485 nsIDOMHTMLElement_GetId(elem
->nselem
, &nsstr
);
1486 nsAString_GetData(&nsstr
, &str
, NULL
);
1487 if(!strcmpiW(str
, name
)) {
1488 nsAString_Finish(&nsstr
);
1492 nsAString_Init(&nsname
, nameW
);
1493 nsres
= nsIDOMHTMLElement_GetAttribute(elem
->nselem
, &nsname
, &nsstr
);
1494 nsAString_Finish(&nsname
);
1495 if(NS_SUCCEEDED(nsres
)) {
1496 nsAString_GetData(&nsstr
, &str
, NULL
);
1497 ret
= !strcmpiW(str
, name
);
1500 nsAString_Finish(&nsstr
);
1504 static HRESULT WINAPI
HTMLElementCollection_item(IHTMLElementCollection
*iface
,
1505 VARIANT name
, VARIANT index
, IDispatch
**pdisp
)
1507 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1509 TRACE("(%p)->(v(%d) v(%d) %p)\n", This
, V_VT(&name
), V_VT(&index
), pdisp
);
1513 if(V_VT(&name
) == VT_I4
) {
1514 TRACE("name is VT_I4: %d\n", V_I4(&name
));
1517 return E_INVALIDARG
;
1518 if(V_I4(&name
) >= This
->len
)
1521 *pdisp
= (IDispatch
*)This
->elems
[V_I4(&name
)];
1522 IDispatch_AddRef(*pdisp
);
1523 TRACE("Returning pdisp=%p\n", pdisp
);
1527 if(V_VT(&name
) == VT_BSTR
) {
1530 TRACE("name is VT_BSTR: %s\n", debugstr_w(V_BSTR(&name
)));
1532 if(V_VT(&index
) == VT_I4
) {
1533 LONG idx
= V_I4(&index
);
1535 TRACE("index = %d\n", idx
);
1538 return E_INVALIDARG
;
1540 for(i
=0; i
<This
->len
; i
++) {
1541 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)) && !idx
--)
1545 if(i
!= This
->len
) {
1546 *pdisp
= (IDispatch
*)HTMLELEM(This
->elems
[i
]);
1547 IDispatch_AddRef(*pdisp
);
1552 elem_vector buf
= {NULL
, 0, 8};
1554 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1556 for(i
=0; i
<This
->len
; i
++) {
1557 if(is_elem_name(This
->elems
[i
], V_BSTR(&name
)))
1558 elem_vector_add(&buf
, This
->elems
[i
]);
1562 elem_vector_normalize(&buf
);
1563 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1566 *pdisp
= (IDispatch
*)HTMLELEM(buf
.buf
[0]);
1567 IDispatch_AddRef(*pdisp
);
1570 mshtml_free(buf
.buf
);
1577 FIXME("unsupported arguments\n");
1578 return E_INVALIDARG
;
1581 static HRESULT WINAPI
HTMLElementCollection_tags(IHTMLElementCollection
*iface
,
1582 VARIANT tagName
, IDispatch
**pdisp
)
1584 HTMLElementCollection
*This
= ELEMCOL_THIS(iface
);
1587 const PRUnichar
*tag
;
1588 elem_vector buf
= {NULL
, 0, 8};
1590 if(V_VT(&tagName
) != VT_BSTR
) {
1591 WARN("Invalid arg\n");
1592 return DISP_E_MEMBERNOTFOUND
;
1595 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(V_BSTR(&tagName
)), pdisp
);
1597 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
*));
1599 nsAString_Init(&tag_str
, NULL
);
1601 for(i
=0; i
<This
->len
; i
++) {
1602 if(!This
->elems
[i
]->nselem
)
1605 nsIDOMElement_GetTagName(This
->elems
[i
]->nselem
, &tag_str
);
1606 nsAString_GetData(&tag_str
, &tag
, NULL
);
1608 if(CompareStringW(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, tag
, -1,
1609 V_BSTR(&tagName
), -1) == CSTR_EQUAL
)
1610 elem_vector_add(&buf
, This
->elems
[i
]);
1613 nsAString_Finish(&tag_str
);
1614 elem_vector_normalize(&buf
);
1616 TRACE("fount %d tags\n", buf
.len
);
1618 *pdisp
= (IDispatch
*)HTMLElementCollection_Create(This
->ref_unk
, buf
.buf
, buf
.len
);
1624 static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl
= {
1625 HTMLElementCollection_QueryInterface
,
1626 HTMLElementCollection_AddRef
,
1627 HTMLElementCollection_Release
,
1628 HTMLElementCollection_GetTypeInfoCount
,
1629 HTMLElementCollection_GetTypeInfo
,
1630 HTMLElementCollection_GetIDsOfNames
,
1631 HTMLElementCollection_Invoke
,
1632 HTMLElementCollection_toString
,
1633 HTMLElementCollection_put_length
,
1634 HTMLElementCollection_get_length
,
1635 HTMLElementCollection_get__newEnum
,
1636 HTMLElementCollection_item
,
1637 HTMLElementCollection_tags
1640 IHTMLElementCollection
*create_all_collection(HTMLDOMNode
*node
)
1642 elem_vector buf
= {NULL
, 0, 8};
1644 buf
.buf
= mshtml_alloc(buf
.size
*sizeof(HTMLElement
**));
1646 elem_vector_add(&buf
, HTMLELEM_NODE_THIS(node
));
1647 create_all_list(node
->doc
, node
, &buf
);
1648 elem_vector_normalize(&buf
);
1650 return HTMLElementCollection_Create((IUnknown
*)HTMLDOMNODE(node
), buf
.buf
, buf
.len
);
1653 static IHTMLElementCollection
*HTMLElementCollection_Create(IUnknown
*ref_unk
,
1654 HTMLElement
**elems
, DWORD len
)
1656 HTMLElementCollection
*ret
= mshtml_alloc(sizeof(HTMLElementCollection
));
1658 ret
->lpHTMLElementCollectionVtbl
= &HTMLElementCollectionVtbl
;
1663 IUnknown_AddRef(ref_unk
);
1664 ret
->ref_unk
= ref_unk
;
1666 TRACE("ret=%p len=%d\n", ret
, len
);
1668 return HTMLELEMCOL(ret
);