2008-09-30 17:41:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2006-2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
DispatchEx dispex;
|
2010-12-30 01:36:57 +01:00
|
|
|
IHTMLElementCollection IHTMLElementCollection_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
HTMLElement **elems;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
} HTMLElementCollection;
|
|
|
|
|
2014-04-21 13:48:23 +02:00
|
|
|
typedef struct {
|
|
|
|
IEnumVARIANT IEnumVARIANT_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
ULONG iter;
|
|
|
|
HTMLElementCollection *col;
|
|
|
|
} HTMLElementCollectionEnum;
|
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
typedef struct {
|
|
|
|
HTMLElement **buf;
|
|
|
|
DWORD len;
|
|
|
|
DWORD size;
|
|
|
|
} elem_vector_t;
|
|
|
|
|
2010-12-27 20:13:09 +01:00
|
|
|
/* FIXME: Handle it better way */
|
|
|
|
static inline HTMLElement *elem_from_HTMLDOMNode(HTMLDOMNode *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLElement, node);
|
|
|
|
}
|
|
|
|
|
2018-02-08 20:53:55 +01:00
|
|
|
static IHTMLElementCollection *HTMLElementCollection_Create(HTMLElement**,DWORD,compat_mode_t);
|
2009-01-08 22:30:57 +01:00
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
static void elem_vector_add(elem_vector_t *buf, HTMLElement *elem)
|
|
|
|
{
|
|
|
|
if(buf->len == buf->size) {
|
|
|
|
buf->size <<= 1;
|
2011-10-18 05:05:51 +02:00
|
|
|
buf->buf = heap_realloc(buf->buf, buf->size*sizeof(HTMLElement*));
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buf->buf[buf->len++] = elem;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void elem_vector_normalize(elem_vector_t *buf)
|
|
|
|
{
|
|
|
|
if(!buf->len) {
|
|
|
|
heap_free(buf->buf);
|
|
|
|
buf->buf = NULL;
|
|
|
|
}else if(buf->size > buf->len) {
|
2011-10-18 05:05:51 +02:00
|
|
|
buf->buf = heap_realloc(buf->buf, buf->len*sizeof(HTMLElement*));
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
buf->size = buf->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL is_elem_node(nsIDOMNode *node)
|
|
|
|
{
|
2013-01-23 18:43:55 +01:00
|
|
|
UINT16 type=0;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
nsIDOMNode_GetNodeType(node, &type);
|
|
|
|
|
|
|
|
return type == ELEMENT_NODE || type == COMMENT_NODE;
|
|
|
|
}
|
|
|
|
|
2014-04-21 13:48:23 +02:00
|
|
|
static inline HTMLElementCollectionEnum *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLElementCollectionEnum, IEnumVARIANT_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollectionEnum_QueryInterface(IEnumVARIANT *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
2014-05-06 10:41:19 +02:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
|
|
|
|
2014-04-21 13:48:23 +02:00
|
|
|
if(IsEqualGUID(riid, &IID_IUnknown)) {
|
|
|
|
*ppv = &This->IEnumVARIANT_iface;
|
|
|
|
}else if(IsEqualGUID(riid, &IID_IEnumVARIANT)) {
|
|
|
|
*ppv = &This->IEnumVARIANT_iface;
|
|
|
|
}else {
|
2014-05-06 10:41:19 +02:00
|
|
|
FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid));
|
2014-04-21 13:48:23 +02:00
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLElementCollectionEnum_AddRef(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2014-04-21 13:48:23 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLElementCollectionEnum_Release(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2014-04-21 13:48:23 +02:00
|
|
|
|
|
|
|
if(!ref) {
|
|
|
|
IHTMLElementCollection_Release(&This->col->IHTMLElementCollection_iface);
|
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
ULONG fetched = 0;
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p)->(%ld %p %p)\n", This, celt, rgVar, pCeltFetched);
|
2014-04-21 13:48:23 +02:00
|
|
|
|
|
|
|
while(This->iter+fetched < This->col->len && fetched < celt) {
|
|
|
|
V_VT(rgVar+fetched) = VT_DISPATCH;
|
|
|
|
V_DISPATCH(rgVar+fetched) = (IDispatch*)&This->col->elems[This->iter+fetched]->IHTMLElement_iface;
|
|
|
|
IDispatch_AddRef(V_DISPATCH(rgVar+fetched));
|
|
|
|
fetched++;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->iter += fetched;
|
2014-04-22 16:23:01 +02:00
|
|
|
if(pCeltFetched)
|
|
|
|
*pCeltFetched = fetched;
|
2014-04-21 13:48:23 +02:00
|
|
|
return fetched == celt ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p)->(%ld)\n", This, celt);
|
2014-04-21 13:48:23 +02:00
|
|
|
|
|
|
|
if(This->iter + celt > This->col->len) {
|
|
|
|
This->iter = This->col->len;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->iter += celt;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollectionEnum_Reset(IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
This->iter = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollectionEnum_Clone(IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
|
|
|
|
{
|
|
|
|
HTMLElementCollectionEnum *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, ppEnum);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumVARIANTVtbl HTMLElementCollectionEnumVtbl = {
|
|
|
|
HTMLElementCollectionEnum_QueryInterface,
|
|
|
|
HTMLElementCollectionEnum_AddRef,
|
|
|
|
HTMLElementCollectionEnum_Release,
|
|
|
|
HTMLElementCollectionEnum_Next,
|
|
|
|
HTMLElementCollectionEnum_Skip,
|
|
|
|
HTMLElementCollectionEnum_Reset,
|
|
|
|
HTMLElementCollectionEnum_Clone
|
|
|
|
};
|
|
|
|
|
2010-12-30 01:36:57 +01:00
|
|
|
static inline HTMLElementCollection *impl_from_IHTMLElementCollection(IHTMLElementCollection *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLElementCollection, IHTMLElementCollection_iface);
|
|
|
|
}
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_QueryInterface(IHTMLElementCollection *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2015-01-20 16:24:27 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
2010-12-30 01:36:57 +01:00
|
|
|
*ppv = &This->IHTMLElementCollection_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IHTMLElementCollection, riid)) {
|
2010-12-30 01:36:57 +01:00
|
|
|
*ppv = &This->IHTMLElementCollection_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
}else if(dispex_query_interface(&This->dispex, riid, ppv)) {
|
|
|
|
return *ppv ? S_OK : E_NOINTERFACE;
|
2014-05-06 10:41:19 +02:00
|
|
|
}else {
|
|
|
|
*ppv = NULL;
|
|
|
|
FIXME("Unsupported iface %s\n", debugstr_mshtml_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2014-05-06 10:41:19 +02:00
|
|
|
IHTMLElementCollection_AddRef(&This->IHTMLElementCollection_iface);
|
|
|
|
return S_OK;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLElementCollection_AddRef(IHTMLElementCollection *iface)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLElementCollection_Release(IHTMLElementCollection *iface)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p) ref=%ld\n", This, ref);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
if(!ref) {
|
2012-06-27 10:55:32 +02:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for(i=0; i < This->len; i++)
|
|
|
|
node_release(&This->elems[i]->node);
|
2008-09-30 17:41:45 +02:00
|
|
|
heap_free(This->elems);
|
2012-06-27 10:55:48 +02:00
|
|
|
|
|
|
|
release_dispex(&This->dispex);
|
2008-09-30 17:41:45 +02:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_GetTypeInfoCount(IHTMLElementCollection *iface,
|
|
|
|
UINT *pctinfo)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2010-12-31 11:07:33 +01:00
|
|
|
return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_GetTypeInfo(IHTMLElementCollection *iface,
|
|
|
|
UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2010-12-31 11:07:33 +01:00
|
|
|
return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_GetIDsOfNames(IHTMLElementCollection *iface,
|
|
|
|
REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2010-12-31 11:07:33 +01:00
|
|
|
return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
|
|
|
|
lcid, rgDispId);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_Invoke(IHTMLElementCollection *iface,
|
|
|
|
DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2010-12-31 11:07:33 +01:00
|
|
|
return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
|
2008-09-30 17:41:45 +02:00
|
|
|
wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_toString(IHTMLElementCollection *iface,
|
|
|
|
BSTR *String)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2021-10-07 15:52:33 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, String);
|
|
|
|
|
|
|
|
return dispex_to_string(&This->dispex, String);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_put_length(IHTMLElementCollection *iface,
|
2009-03-12 01:43:18 +01:00
|
|
|
LONG v)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2022-02-15 07:29:41 +01:00
|
|
|
FIXME("(%p)->(%ld)\n", This, v);
|
2008-09-30 17:41:45 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_get_length(IHTMLElementCollection *iface,
|
2009-03-12 01:43:18 +01:00
|
|
|
LONG *p)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
|
|
|
*p = This->len;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_get__newEnum(IHTMLElementCollection *iface,
|
|
|
|
IUnknown **p)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2014-04-21 13:48:23 +02:00
|
|
|
HTMLElementCollectionEnum *ret;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
|
|
|
ret = heap_alloc(sizeof(*ret));
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
ret->IEnumVARIANT_iface.lpVtbl = &HTMLElementCollectionEnumVtbl;
|
|
|
|
ret->ref = 1;
|
|
|
|
ret->iter = 0;
|
|
|
|
|
|
|
|
IHTMLElementCollection_AddRef(&This->IHTMLElementCollection_iface);
|
|
|
|
ret->col = This;
|
|
|
|
|
|
|
|
*p = (IUnknown*)&ret->IEnumVARIANT_iface;
|
|
|
|
return S_OK;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2009-11-20 23:21:54 +01:00
|
|
|
static BOOL is_elem_id(HTMLElement *elem, LPCWSTR name)
|
|
|
|
{
|
|
|
|
BSTR elem_id;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2010-12-30 01:24:59 +01:00
|
|
|
hres = IHTMLElement_get_id(&elem->IHTMLElement_iface, &elem_id);
|
2009-11-20 23:21:54 +01:00
|
|
|
if(FAILED(hres)){
|
2022-02-15 07:29:41 +01:00
|
|
|
WARN("IHTMLElement_get_id failed: 0x%08lx\n", hres);
|
2009-11-20 23:21:54 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-13 08:34:29 +02:00
|
|
|
if(elem_id && !wcscmp(elem_id, name)) {
|
2009-11-20 23:21:54 +01:00
|
|
|
SysFreeString(elem_id);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SysFreeString(elem_id);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
static BOOL is_elem_name(HTMLElement *elem, LPCWSTR name)
|
|
|
|
{
|
|
|
|
const PRUnichar *str;
|
2014-05-27 11:29:28 +02:00
|
|
|
nsAString nsstr;
|
2008-09-30 17:41:45 +02:00
|
|
|
BOOL ret = FALSE;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2018-02-12 23:28:15 +01:00
|
|
|
if(!elem->dom_element)
|
2008-09-30 17:41:45 +02:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
nsAString_Init(&nsstr, NULL);
|
2018-02-12 01:28:00 +01:00
|
|
|
nsIDOMElement_GetId(elem->dom_element, &nsstr);
|
2008-09-30 17:41:45 +02:00
|
|
|
nsAString_GetData(&nsstr, &str);
|
2019-06-13 08:34:29 +02:00
|
|
|
if(!wcsicmp(str, name)) {
|
2008-09-30 17:41:45 +02:00
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-11-24 00:49:06 +01:00
|
|
|
nsres = get_elem_attr_value(elem->dom_element, L"name", &nsstr, &str);
|
2008-09-30 17:41:45 +02:00
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
2019-06-13 08:34:29 +02:00
|
|
|
ret = !wcsicmp(str, name);
|
2014-05-27 11:29:28 +02:00
|
|
|
nsAString_Finish(&nsstr);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:01:19 +02:00
|
|
|
static HRESULT get_item_idx(HTMLElementCollection *This, UINT idx, IDispatch **ret)
|
|
|
|
{
|
|
|
|
if(idx < This->len) {
|
2016-09-16 14:16:46 +02:00
|
|
|
*ret = (IDispatch*)&This->elems[idx]->node.event_target.dispex.IDispatchEx_iface;
|
2009-07-07 21:01:19 +02:00
|
|
|
IDispatch_AddRef(*ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
static HRESULT WINAPI HTMLElementCollection_item(IHTMLElementCollection *iface,
|
|
|
|
VARIANT name, VARIANT index, IDispatch **pdisp)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2009-07-07 21:01:19 +02:00
|
|
|
HRESULT hres = S_OK;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2009-07-07 21:01:19 +02:00
|
|
|
TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&name), debugstr_variant(&index), pdisp);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
*pdisp = NULL;
|
|
|
|
|
2009-07-07 21:01:19 +02:00
|
|
|
switch(V_VT(&name)) {
|
|
|
|
case VT_I4:
|
2015-06-01 20:52:04 +02:00
|
|
|
case VT_INT:
|
2008-09-30 17:41:45 +02:00
|
|
|
if(V_I4(&name) < 0)
|
2018-02-08 20:53:55 +01:00
|
|
|
return dispex_compat_mode(&This->dispex) < COMPAT_MODE_IE9 ? E_INVALIDARG : S_OK;
|
2009-07-07 21:01:19 +02:00
|
|
|
hres = get_item_idx(This, V_I4(&name), pdisp);
|
|
|
|
break;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2015-06-01 20:52:04 +02:00
|
|
|
case VT_UI4:
|
2009-07-07 21:01:19 +02:00
|
|
|
case VT_UINT:
|
|
|
|
hres = get_item_idx(This, V_UINT(&name), pdisp);
|
|
|
|
break;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2009-07-07 21:01:19 +02:00
|
|
|
case VT_BSTR: {
|
2008-09-30 17:41:45 +02:00
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if(V_VT(&index) == VT_I4) {
|
|
|
|
LONG idx = V_I4(&index);
|
|
|
|
|
|
|
|
if(idx < 0)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
for(i=0; i<This->len; i++) {
|
|
|
|
if(is_elem_name(This->elems[i], V_BSTR(&name)) && !idx--)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(i != This->len) {
|
2010-12-30 01:24:59 +01:00
|
|
|
*pdisp = (IDispatch*)&This->elems[i]->IHTMLElement_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
IDispatch_AddRef(*pdisp);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
elem_vector_t buf = {NULL, 0, 8};
|
|
|
|
|
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
|
|
|
|
|
|
|
|
for(i=0; i<This->len; i++) {
|
2012-06-27 10:55:32 +02:00
|
|
|
if(is_elem_name(This->elems[i], V_BSTR(&name))) {
|
|
|
|
node_addref(&This->elems[i]->node);
|
2008-09-30 17:41:45 +02:00
|
|
|
elem_vector_add(&buf, This->elems[i]);
|
2012-06-27 10:55:32 +02:00
|
|
|
}
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(buf.len > 1) {
|
|
|
|
elem_vector_normalize(&buf);
|
2018-02-08 20:53:55 +01:00
|
|
|
*pdisp = (IDispatch*)HTMLElementCollection_Create(buf.buf, buf.len,
|
|
|
|
dispex_compat_mode(&This->dispex));
|
2008-09-30 17:41:45 +02:00
|
|
|
}else {
|
|
|
|
if(buf.len == 1) {
|
2012-06-27 10:55:32 +02:00
|
|
|
/* Already AddRef-ed */
|
2010-12-30 01:24:59 +01:00
|
|
|
*pdisp = (IDispatch*)&buf.buf[0]->IHTMLElement_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
heap_free(buf.buf);
|
|
|
|
}
|
|
|
|
}
|
2009-07-07 21:01:19 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported name %s\n", debugstr_variant(&name));
|
|
|
|
hres = E_NOTIMPL;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:01:19 +02:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
TRACE("returning %p\n", *pdisp);
|
|
|
|
return hres;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLElementCollection_tags(IHTMLElementCollection *iface,
|
|
|
|
VARIANT tagName, IDispatch **pdisp)
|
|
|
|
{
|
2010-12-30 01:36:57 +01:00
|
|
|
HTMLElementCollection *This = impl_from_IHTMLElementCollection(iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
DWORD i;
|
|
|
|
nsAString tag_str;
|
|
|
|
const PRUnichar *tag;
|
|
|
|
elem_vector_t buf = {NULL, 0, 8};
|
|
|
|
|
|
|
|
if(V_VT(&tagName) != VT_BSTR) {
|
|
|
|
WARN("Invalid arg\n");
|
|
|
|
return DISP_E_MEMBERNOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(V_BSTR(&tagName)), pdisp);
|
|
|
|
|
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
|
|
|
|
|
|
|
|
nsAString_Init(&tag_str, NULL);
|
|
|
|
|
|
|
|
for(i=0; i<This->len; i++) {
|
2018-02-12 23:28:15 +01:00
|
|
|
if(!This->elems[i]->dom_element)
|
2008-09-30 17:41:45 +02:00
|
|
|
continue;
|
|
|
|
|
2018-02-12 23:28:15 +01:00
|
|
|
nsIDOMElement_GetTagName(This->elems[i]->dom_element, &tag_str);
|
2008-09-30 17:41:45 +02:00
|
|
|
nsAString_GetData(&tag_str, &tag);
|
|
|
|
|
|
|
|
if(CompareStringW(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, tag, -1,
|
2012-06-27 10:55:32 +02:00
|
|
|
V_BSTR(&tagName), -1) == CSTR_EQUAL) {
|
|
|
|
node_addref(&This->elems[i]->node);
|
2008-09-30 17:41:45 +02:00
|
|
|
elem_vector_add(&buf, This->elems[i]);
|
2012-06-27 10:55:32 +02:00
|
|
|
}
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Finish(&tag_str);
|
|
|
|
elem_vector_normalize(&buf);
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("found %ld tags\n", buf.len);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2018-02-08 20:53:55 +01:00
|
|
|
*pdisp = (IDispatch*)HTMLElementCollection_Create(buf.buf, buf.len,
|
|
|
|
dispex_compat_mode(&This->dispex));
|
2008-09-30 17:41:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-27 18:34:39 +01:00
|
|
|
static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
|
|
|
|
HTMLElementCollection_QueryInterface,
|
|
|
|
HTMLElementCollection_AddRef,
|
|
|
|
HTMLElementCollection_Release,
|
|
|
|
HTMLElementCollection_GetTypeInfoCount,
|
|
|
|
HTMLElementCollection_GetTypeInfo,
|
|
|
|
HTMLElementCollection_GetIDsOfNames,
|
|
|
|
HTMLElementCollection_Invoke,
|
|
|
|
HTMLElementCollection_toString,
|
|
|
|
HTMLElementCollection_put_length,
|
|
|
|
HTMLElementCollection_get_length,
|
|
|
|
HTMLElementCollection_get__newEnum,
|
|
|
|
HTMLElementCollection_item,
|
|
|
|
HTMLElementCollection_tags
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline HTMLElementCollection *impl_from_DispatchEx(DispatchEx *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLElementCollection, dispex);
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
#define DISPID_ELEMCOL_0 MSHTML_DISPID_CUSTOM_MIN
|
|
|
|
|
2010-12-27 18:34:39 +01:00
|
|
|
static HRESULT HTMLElementCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
2010-12-27 18:34:39 +01:00
|
|
|
HTMLElementCollection *This = impl_from_DispatchEx(dispex);
|
2008-09-30 17:41:45 +02:00
|
|
|
WCHAR *ptr;
|
|
|
|
DWORD idx=0;
|
|
|
|
|
2008-10-06 16:53:35 +02:00
|
|
|
if(!*name)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
2019-11-12 20:49:03 +01:00
|
|
|
for(ptr = name; *ptr && is_digit(*ptr); ptr++)
|
2008-09-30 17:41:45 +02:00
|
|
|
idx = idx*10 + (*ptr-'0');
|
|
|
|
|
2009-11-20 23:21:54 +01:00
|
|
|
if(*ptr) {
|
|
|
|
/* the name contains alpha characters, so search by name & id */
|
|
|
|
for(idx = 0; idx < This->len; ++idx) {
|
|
|
|
if(is_elem_id(This->elems[idx], name) ||
|
|
|
|
is_elem_name(This->elems[idx], name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(idx >= This->len)
|
2008-09-30 17:41:45 +02:00
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
|
|
|
*dispid = DISPID_ELEMCOL_0 + idx;
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("ret %lx\n", *dispid);
|
2008-09-30 17:41:45 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-27 18:34:39 +01:00
|
|
|
static HRESULT HTMLElementCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
|
2008-09-30 17:41:45 +02:00
|
|
|
VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
|
|
|
|
{
|
2010-12-27 18:34:39 +01:00
|
|
|
HTMLElementCollection *This = impl_from_DispatchEx(dispex);
|
2008-09-30 17:41:45 +02:00
|
|
|
DWORD idx;
|
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("(%p)->(%lx %lx %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
idx = id - DISPID_ELEMCOL_0;
|
|
|
|
if(idx >= This->len)
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
|
|
|
|
switch(flags) {
|
2009-10-13 20:50:02 +02:00
|
|
|
case DISPATCH_PROPERTYGET:
|
2008-09-30 17:41:45 +02:00
|
|
|
V_VT(res) = VT_DISPATCH;
|
2010-12-30 01:24:59 +01:00
|
|
|
V_DISPATCH(res) = (IDispatch*)&This->elems[idx]->IHTMLElement_iface;
|
|
|
|
IHTMLElement_AddRef(&This->elems[idx]->IHTMLElement_iface);
|
2008-09-30 17:41:45 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented flags %x\n", flags);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const dispex_static_data_vtbl_t HTMLElementColection_dispex_vtbl = {
|
2009-08-31 20:43:44 +02:00
|
|
|
NULL,
|
2008-09-30 17:41:45 +02:00
|
|
|
HTMLElementCollection_get_dispid,
|
2011-08-23 11:33:18 +02:00
|
|
|
HTMLElementCollection_invoke,
|
|
|
|
NULL
|
2008-09-30 17:41:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const tid_t HTMLElementCollection_iface_tids[] = {
|
|
|
|
IHTMLElementCollection_tid,
|
|
|
|
0
|
|
|
|
};
|
2010-12-27 18:34:39 +01:00
|
|
|
|
2008-09-30 17:41:45 +02:00
|
|
|
static dispex_static_data_t HTMLElementCollection_dispex = {
|
2021-10-06 17:11:31 +02:00
|
|
|
L"HTMLCollection",
|
2008-09-30 17:41:45 +02:00
|
|
|
&HTMLElementColection_dispex_vtbl,
|
|
|
|
DispHTMLElementCollection_tid,
|
|
|
|
HTMLElementCollection_iface_tids
|
|
|
|
};
|
|
|
|
|
2018-02-19 14:49:50 +01:00
|
|
|
static void create_all_list(HTMLDOMNode *elem, elem_vector_t *buf)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
|
|
|
nsIDOMNodeList *nsnode_list;
|
|
|
|
nsIDOMNode *iter;
|
2013-01-23 18:44:42 +01:00
|
|
|
UINT32 list_len = 0, i;
|
2008-09-30 17:41:45 +02:00
|
|
|
nsresult nsres;
|
2010-12-01 12:52:08 +01:00
|
|
|
HRESULT hres;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
|
|
|
|
if(NS_FAILED(nsres)) {
|
2022-02-15 07:29:41 +01:00
|
|
|
ERR("GetChildNodes failed: %08lx\n", nsres);
|
2008-09-30 17:41:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNodeList_GetLength(nsnode_list, &list_len);
|
|
|
|
if(!list_len)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i=0; i<list_len; i++) {
|
|
|
|
nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
|
|
|
|
if(NS_FAILED(nsres)) {
|
2022-02-15 07:29:41 +01:00
|
|
|
ERR("Item failed: %08lx\n", nsres);
|
2008-09-30 17:41:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_elem_node(iter)) {
|
2010-12-01 12:52:08 +01:00
|
|
|
HTMLDOMNode *node;
|
|
|
|
|
2018-02-19 14:49:07 +01:00
|
|
|
hres = get_node(iter, TRUE, &node);
|
2010-12-01 12:52:08 +01:00
|
|
|
if(FAILED(hres)) {
|
2022-02-15 07:29:41 +01:00
|
|
|
FIXME("get_node failed: %08lx\n", hres);
|
2010-12-01 12:52:08 +01:00
|
|
|
continue;
|
|
|
|
}
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2010-12-27 20:13:09 +01:00
|
|
|
elem_vector_add(buf, elem_from_HTMLDOMNode(node));
|
2018-02-19 14:49:50 +01:00
|
|
|
create_all_list(node, buf);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:45:08 +02:00
|
|
|
IHTMLElementCollection *create_all_collection(HTMLDOMNode *node, BOOL include_root)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
|
|
|
elem_vector_t buf = {NULL, 0, 8};
|
|
|
|
|
2011-10-18 05:05:51 +02:00
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2012-06-27 10:55:32 +02:00
|
|
|
if(include_root) {
|
|
|
|
node_addref(node);
|
2010-12-27 20:13:09 +01:00
|
|
|
elem_vector_add(&buf, elem_from_HTMLDOMNode(node));
|
2012-06-27 10:55:32 +02:00
|
|
|
}
|
2018-02-19 14:49:50 +01:00
|
|
|
create_all_list(node, &buf);
|
2008-09-30 17:41:45 +02:00
|
|
|
elem_vector_normalize(&buf);
|
|
|
|
|
2018-02-08 20:53:55 +01:00
|
|
|
return HTMLElementCollection_Create(buf.buf, buf.len,
|
|
|
|
dispex_compat_mode(&node->event_target.dispex));
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 13:25:06 +01:00
|
|
|
IHTMLElementCollection *create_collection_from_nodelist(nsIDOMNodeList *nslist, compat_mode_t compat_mode)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
2013-01-23 18:44:42 +01:00
|
|
|
UINT32 length = 0, i;
|
2010-12-01 12:52:08 +01:00
|
|
|
HTMLDOMNode *node;
|
2008-09-30 17:41:45 +02:00
|
|
|
elem_vector_t buf;
|
2010-12-01 12:52:08 +01:00
|
|
|
HRESULT hres;
|
2008-09-30 17:41:45 +02:00
|
|
|
|
|
|
|
nsIDOMNodeList_GetLength(nslist, &length);
|
|
|
|
|
2008-10-06 16:53:35 +02:00
|
|
|
buf.len = 0;
|
|
|
|
buf.size = length;
|
|
|
|
if(length) {
|
2008-09-30 17:41:45 +02:00
|
|
|
nsIDOMNode *nsnode;
|
|
|
|
|
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
|
|
|
|
|
|
|
|
for(i=0; i<length; i++) {
|
|
|
|
nsIDOMNodeList_Item(nslist, i, &nsnode);
|
2010-12-01 12:52:08 +01:00
|
|
|
if(is_elem_node(nsnode)) {
|
2018-02-19 14:49:07 +01:00
|
|
|
hres = get_node(nsnode, TRUE, &node);
|
2010-12-01 12:52:08 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
continue;
|
2010-12-27 20:13:09 +01:00
|
|
|
buf.buf[buf.len++] = elem_from_HTMLDOMNode(node);
|
2010-12-01 12:52:08 +01:00
|
|
|
}
|
2008-09-30 17:41:45 +02:00
|
|
|
nsIDOMNode_Release(nsnode);
|
|
|
|
}
|
2008-10-06 16:53:35 +02:00
|
|
|
|
|
|
|
elem_vector_normalize(&buf);
|
2008-09-30 17:41:45 +02:00
|
|
|
}else {
|
|
|
|
buf.buf = NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-20 13:25:06 +01:00
|
|
|
return HTMLElementCollection_Create(buf.buf, buf.len, compat_mode);
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|
|
|
|
|
2018-02-20 13:25:06 +01:00
|
|
|
IHTMLElementCollection *create_collection_from_htmlcol(nsIDOMHTMLCollection *nscol, compat_mode_t compat_mode)
|
2008-09-30 17:45:48 +02:00
|
|
|
{
|
2013-01-23 18:44:42 +01:00
|
|
|
UINT32 length = 0, i;
|
2008-09-30 17:45:48 +02:00
|
|
|
elem_vector_t buf;
|
2010-12-01 12:52:08 +01:00
|
|
|
HTMLDOMNode *node;
|
|
|
|
HRESULT hres = S_OK;
|
2008-09-30 17:45:48 +02:00
|
|
|
|
2016-07-01 11:21:27 +02:00
|
|
|
if(nscol)
|
|
|
|
nsIDOMHTMLCollection_GetLength(nscol, &length);
|
2008-09-30 17:45:48 +02:00
|
|
|
|
|
|
|
buf.len = buf.size = length;
|
|
|
|
if(buf.len) {
|
|
|
|
nsIDOMNode *nsnode;
|
|
|
|
|
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(HTMLElement*));
|
|
|
|
|
|
|
|
for(i=0; i<length; i++) {
|
|
|
|
nsIDOMHTMLCollection_Item(nscol, i, &nsnode);
|
2018-02-19 14:49:07 +01:00
|
|
|
hres = get_node(nsnode, TRUE, &node);
|
2008-09-30 17:45:48 +02:00
|
|
|
nsIDOMNode_Release(nsnode);
|
2010-12-01 12:52:08 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
break;
|
2010-12-27 20:13:09 +01:00
|
|
|
buf.buf[i] = elem_from_HTMLDOMNode(node);
|
2008-09-30 17:45:48 +02:00
|
|
|
}
|
|
|
|
}else {
|
|
|
|
buf.buf = NULL;
|
|
|
|
}
|
|
|
|
|
2010-12-01 12:52:08 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
heap_free(buf.buf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-02-20 13:25:06 +01:00
|
|
|
return HTMLElementCollection_Create(buf.buf, buf.len, compat_mode);
|
2008-09-30 17:45:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:20:02 +02:00
|
|
|
HRESULT get_elem_source_index(HTMLElement *elem, LONG *ret)
|
|
|
|
{
|
|
|
|
elem_vector_t buf = {NULL, 0, 8};
|
|
|
|
nsIDOMNode *parent_node, *iter;
|
|
|
|
UINT16 parent_type;
|
|
|
|
HTMLDOMNode *node;
|
|
|
|
int i;
|
|
|
|
nsresult nsres;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
iter = elem->node.nsnode;
|
|
|
|
nsIDOMNode_AddRef(iter);
|
|
|
|
|
|
|
|
/* Find document or document fragment parent. */
|
|
|
|
while(1) {
|
|
|
|
nsres = nsIDOMNode_GetParentNode(iter, &parent_node);
|
|
|
|
nsIDOMNode_Release(iter);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
if(!parent_node)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_GetNodeType(parent_node, &parent_type);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
if(parent_type != ELEMENT_NODE) {
|
|
|
|
if(parent_type != DOCUMENT_NODE && parent_type != DOCUMENT_FRAGMENT_NODE)
|
|
|
|
FIXME("Unexpected parent_type %d\n", parent_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter = parent_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!parent_node) {
|
|
|
|
*ret = -1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-19 14:49:07 +01:00
|
|
|
hres = get_node(parent_node, TRUE, &node);
|
2014-09-16 20:20:02 +02:00
|
|
|
nsIDOMNode_Release(parent_node);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
/* Create all children collection and find the element in it.
|
|
|
|
* This could be optimized if we ever find the reason. */
|
|
|
|
buf.buf = heap_alloc(buf.size*sizeof(*buf.buf));
|
|
|
|
if(!buf.buf) {
|
|
|
|
IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2018-02-19 14:49:50 +01:00
|
|
|
create_all_list(node, &buf);
|
2014-09-16 20:20:02 +02:00
|
|
|
|
|
|
|
for(i=0; i < buf.len; i++) {
|
|
|
|
if(buf.buf[i] == elem)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
IHTMLDOMNode_Release(&node->IHTMLDOMNode_iface);
|
|
|
|
heap_free(buf.buf);
|
|
|
|
if(i == buf.len) {
|
|
|
|
FIXME("The element is not in parent's child list?\n");
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret = i;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-08 20:53:55 +01:00
|
|
|
static IHTMLElementCollection *HTMLElementCollection_Create(HTMLElement **elems, DWORD len,
|
|
|
|
compat_mode_t compat_mode)
|
2008-09-30 17:41:45 +02:00
|
|
|
{
|
|
|
|
HTMLElementCollection *ret = heap_alloc_zero(sizeof(HTMLElementCollection));
|
|
|
|
|
2015-06-03 13:36:02 +02:00
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-30 01:36:57 +01:00
|
|
|
ret->IHTMLElementCollection_iface.lpVtbl = &HTMLElementCollectionVtbl;
|
2008-09-30 17:41:45 +02:00
|
|
|
ret->ref = 1;
|
|
|
|
ret->elems = elems;
|
|
|
|
ret->len = len;
|
|
|
|
|
2021-03-16 19:57:45 +01:00
|
|
|
init_dispatch(&ret->dispex, (IUnknown*)&ret->IHTMLElementCollection_iface,
|
|
|
|
&HTMLElementCollection_dispex, compat_mode);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2022-02-15 07:29:41 +01:00
|
|
|
TRACE("ret=%p len=%ld\n", ret, len);
|
2008-09-30 17:41:45 +02:00
|
|
|
|
2010-12-30 01:36:57 +01:00
|
|
|
return &ret->IHTMLElementCollection_iface;
|
2008-09-30 17:41:45 +02:00
|
|
|
}
|