From: Gabriel Ivăncescu gabrielopcode@gmail.com
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com --- dlls/mshtml/htmlelem.c | 112 +++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 44 deletions(-)
diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index e4afbd42574..661c12428fa 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -41,14 +41,22 @@ WINE_DEFAULT_DEBUG_CHANNEL(mshtml); #define ATTRFLAG_ASSTRING 0x0002 #define ATTRFLAG_EXPANDURL 0x0004
+struct attr_id { + DISPID dispid; +}; + +struct attr_enum_id { + DISPID dispid; +}; + typedef struct { const WCHAR *name; HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMElement*,HTMLElement**); } tag_desc_t;
static HRESULT HTMLElement_Ctor(HTMLDocumentNode*,nsIDOMElement*,HTMLElement**); -static HRESULT get_attr_dispid_by_name(HTMLAttributeCollection*,const WCHAR*,BOOL,DISPID*); -static HRESULT get_domattr(HTMLAttributeCollection*,DISPID,LONG*,HTMLDOMAttribute**); +static HRESULT get_attr_id_by_name(HTMLAttributeCollection*,const WCHAR*,BOOL,struct attr_id*); +static HRESULT get_domattr(HTMLAttributeCollection*,struct attr_id,LONG*,HTMLDOMAttribute**);
static const tag_desc_t tag_descs[] = { {L"A", HTMLAnchorElement_Create}, @@ -4756,8 +4764,8 @@ static HRESULT WINAPI HTMLElement6_getAttributeNode(IHTMLElement6 *iface, BSTR s HTMLElement *This = impl_from_IHTMLElement6(iface); HTMLAttributeCollection *attrs; HTMLDOMAttribute *attr; + struct attr_id attr_id; HRESULT hres; - DISPID id;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(strAttributeName), ppretAttribute);
@@ -4765,9 +4773,9 @@ static HRESULT WINAPI HTMLElement6_getAttributeNode(IHTMLElement6 *iface, BSTR s if(FAILED(hres)) return hres;
- hres = get_attr_dispid_by_name(attrs, strAttributeName, TRUE, &id); + hres = get_attr_id_by_name(attrs, strAttributeName, TRUE, &attr_id); if(hres == S_OK) { - hres = get_domattr(attrs, id, NULL, &attr); + hres = get_domattr(attrs, attr_id, NULL, &attr); if(hres == S_OK) *ppretAttribute = &attr->IHTMLDOMAttribute2_iface; }else if(hres == DISP_E_UNKNOWNNAME) { @@ -7796,10 +7804,16 @@ static inline BOOL is_valid_attr_dispid(HTMLAttributeCollection *col, DISPID id, return TRUE; }
-static HRESULT get_attr_dispid_by_relative_idx(HTMLAttributeCollection *This, LONG *idx, DISPID start, - BOOL specified_only, DISPID *dispid) +static struct attr_id attr_enum_id_to_attr_id(HTMLAttributeCollection *This, struct attr_enum_id enum_id) +{ + struct attr_id ret = { .dispid = enum_id.dispid }; + return ret; +} + +static HRESULT get_attr_enum_id_by_relative_idx(HTMLAttributeCollection *This, LONG *idx, struct attr_enum_id start, + BOOL specified_only, struct attr_enum_id *ret) { - DISPID id = start; + DISPID id = start.dispid; LONG len = -1; HRESULT hres;
@@ -7819,8 +7833,8 @@ static HRESULT get_attr_dispid_by_relative_idx(HTMLAttributeCollection *This, LO break; }
- if(dispid) { - *dispid = id; + if(ret) { + ret->dispid = id; return *idx==len ? S_OK : DISP_E_UNKNOWNNAME; }
@@ -7828,12 +7842,21 @@ static HRESULT get_attr_dispid_by_relative_idx(HTMLAttributeCollection *This, LO return S_OK; }
-static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, BOOL specified_only, DISPID *dispid) +static HRESULT get_attr_id_by_idx(HTMLAttributeCollection *This, LONG *idx, BOOL specified_only, struct attr_id *ret) { - return get_attr_dispid_by_relative_idx(This, idx, DISPID_STARTENUM, specified_only, dispid); + struct attr_enum_id enum_id, start = { .dispid = DISPID_STARTENUM }; + HRESULT hres; + + if(!ret) + return get_attr_enum_id_by_relative_idx(This, idx, start, specified_only, NULL); + + hres = get_attr_enum_id_by_relative_idx(This, idx, start, specified_only, &enum_id); + if(SUCCEEDED(hres)) + *ret = attr_enum_id_to_attr_id(This, enum_id); + return hres; }
-static HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, const WCHAR *name, BOOL specified_only, DISPID *id) +static HRESULT get_attr_id_by_name(HTMLAttributeCollection *This, const WCHAR *name, BOOL specified_only, struct attr_id *ret) { HRESULT hres;
@@ -7843,22 +7866,22 @@ static HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, const WCHA
idx = wcstoul(name, &end_ptr, 10); if(!*end_ptr) { - hres = get_attr_dispid_by_idx(This, &idx, specified_only, id); + hres = get_attr_id_by_idx(This, &idx, specified_only, ret); if(SUCCEEDED(hres)) return hres; } }
- hres = dispex_get_id(&This->elem->node.event_target.dispex, name, fdexNameCaseInsensitive, id); - return (FAILED(hres) || is_valid_attr_dispid(This, *id, specified_only)) ? hres : DISP_E_UNKNOWNNAME; + hres = dispex_get_id(&This->elem->node.event_target.dispex, name, fdexNameCaseInsensitive, &ret->dispid); + return (FAILED(hres) || is_valid_attr_dispid(This, ret->dispid, specified_only)) ? hres : DISP_E_UNKNOWNNAME; }
-static HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr) +static HRESULT get_domattr(HTMLAttributeCollection *This, struct attr_id attr_id, LONG *list_pos, HTMLDOMAttribute **attr) { HRESULT hres;
- if(!(*attr = find_attr_in_list(This, id, list_pos))) { - hres = HTMLDOMAttribute_Create(NULL, This->elem, id, This->elem->node.doc, attr); + if(!(*attr = find_attr_in_list(This, attr_id.dispid, list_pos))) { + hres = HTMLDOMAttribute_Create(NULL, This->elem, attr_id.dispid, This->elem->node.doc, attr); if(FAILED(hres)) return hres; } @@ -7872,7 +7895,7 @@ typedef struct {
LONG ref;
- DISPID iter_dispid; + struct attr_enum_id iter_attr_id; HTMLAttributeCollection *col; } HTMLAttributeCollectionEnum;
@@ -7929,7 +7952,7 @@ static ULONG WINAPI HTMLAttributeCollectionEnum_Release(IEnumVARIANT *iface) static HRESULT WINAPI HTMLAttributeCollectionEnum_Next(IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *pCeltFetched) { HTMLAttributeCollectionEnum *This = HTMLAttributeCollectionEnum_from_IEnumVARIANT(iface); - DISPID tmp, dispid = This->iter_dispid; + struct attr_enum_id tmp, enum_id = This->iter_attr_id; HTMLDOMAttribute *attr; LONG rel_index = 0; HRESULT hres; @@ -7938,10 +7961,10 @@ static HRESULT WINAPI HTMLAttributeCollectionEnum_Next(IEnumVARIANT *iface, ULON TRACE("(%p)->(%lu %p %p)\n", This, celt, rgVar, pCeltFetched);
for(i = 0; i < celt; i++) { - hres = get_attr_dispid_by_relative_idx(This->col, &rel_index, dispid, FALSE, &tmp); + hres = get_attr_enum_id_by_relative_idx(This->col, &rel_index, enum_id, FALSE, &tmp); if(SUCCEEDED(hres)) { - dispid = tmp; - hres = get_domattr(This->col, dispid, NULL, &attr); + enum_id = tmp; + hres = get_domattr(This->col, attr_enum_id_to_attr_id(This->col, enum_id), NULL, &attr); } else if(hres == DISP_E_UNKNOWNNAME) break; @@ -7956,7 +7979,7 @@ static HRESULT WINAPI HTMLAttributeCollectionEnum_Next(IEnumVARIANT *iface, ULON V_DISPATCH(&rgVar[i]) = (IDispatch*)&attr->IHTMLDOMAttribute_iface; }
- This->iter_dispid = dispid; + This->iter_attr_id = enum_id; if(pCeltFetched) *pCeltFetched = i; return i == celt ? S_OK : S_FALSE; @@ -7965,8 +7988,8 @@ static HRESULT WINAPI HTMLAttributeCollectionEnum_Next(IEnumVARIANT *iface, ULON static HRESULT WINAPI HTMLAttributeCollectionEnum_Skip(IEnumVARIANT *iface, ULONG celt) { HTMLAttributeCollectionEnum *This = HTMLAttributeCollectionEnum_from_IEnumVARIANT(iface); + struct attr_enum_id enum_id; LONG remaining, rel_index; - DISPID dispid; HRESULT hres;
TRACE("(%p)->(%lu)\n", This, celt); @@ -7975,17 +7998,17 @@ static HRESULT WINAPI HTMLAttributeCollectionEnum_Skip(IEnumVARIANT *iface, ULON return S_OK;
rel_index = -1; - hres = get_attr_dispid_by_relative_idx(This->col, &rel_index, This->iter_dispid, FALSE, NULL); + hres = get_attr_enum_id_by_relative_idx(This->col, &rel_index, This->iter_attr_id, FALSE, NULL); if(FAILED(hres)) return hres; remaining = min(celt, rel_index);
if(remaining) { rel_index = remaining - 1; - hres = get_attr_dispid_by_relative_idx(This->col, &rel_index, This->iter_dispid, FALSE, &dispid); + hres = get_attr_enum_id_by_relative_idx(This->col, &rel_index, This->iter_attr_id, FALSE, &enum_id); if(FAILED(hres)) return hres; - This->iter_dispid = dispid; + This->iter_attr_id = enum_id; } return celt > remaining ? S_FALSE : S_OK; } @@ -7996,7 +8019,7 @@ static HRESULT WINAPI HTMLAttributeCollectionEnum_Reset(IEnumVARIANT *iface)
TRACE("(%p)->()\n", This);
- This->iter_dispid = DISPID_STARTENUM; + This->iter_attr_id.dispid = DISPID_STARTENUM; return S_OK; }
@@ -8034,7 +8057,7 @@ static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollectio TRACE("(%p)->(%p)\n", This, p);
*p = -1; - hres = get_attr_dispid_by_idx(This, p, FALSE, NULL); + hres = get_attr_id_by_idx(This, p, FALSE, NULL); return hres; }
@@ -8051,7 +8074,7 @@ static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection
ret->IEnumVARIANT_iface.lpVtbl = &HTMLAttributeCollectionEnumVtbl; ret->ref = 1; - ret->iter_dispid = DISPID_STARTENUM; + ret->iter_attr_id.dispid = DISPID_STARTENUM;
HTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface); ret->col = This; @@ -8064,17 +8087,17 @@ static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *ifa { HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface); HTMLDOMAttribute *attr; - DISPID id; + struct attr_id attr_id; HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
switch(V_VT(name)) { case VT_I4: - hres = get_attr_dispid_by_idx(This, &V_I4(name), FALSE, &id); + hres = get_attr_id_by_idx(This, &V_I4(name), FALSE, &attr_id); break; case VT_BSTR: - hres = get_attr_dispid_by_name(This, V_BSTR(name), FALSE, &id); + hres = get_attr_id_by_name(This, V_BSTR(name), FALSE, &attr_id); break; default: FIXME("unsupported name %s\n", debugstr_variant(name)); @@ -8085,7 +8108,7 @@ static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *ifa if(FAILED(hres)) return hres;
- hres = get_domattr(This, id, NULL, &attr); + hres = get_domattr(This, attr_id, NULL, &attr); if(FAILED(hres)) return hres;
@@ -8119,12 +8142,12 @@ static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollec { HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface); HTMLDOMAttribute *attr; - DISPID id; + struct attr_id attr_id; HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
- hres = get_attr_dispid_by_name(This, bstrName, FALSE, &id); + hres = get_attr_id_by_name(This, bstrName, FALSE, &attr_id); if(hres == DISP_E_UNKNOWNNAME) { *newretNode = NULL; return S_OK; @@ -8132,7 +8155,7 @@ static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollec return hres; }
- hres = get_domattr(This, id, NULL, &attr); + hres = get_domattr(This, attr_id, NULL, &attr); if(FAILED(hres)) return hres;
@@ -8204,18 +8227,18 @@ static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *i { HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface); HTMLDOMAttribute *attr; - DISPID id; + struct attr_id attr_id; HRESULT hres;
TRACE("(%p)->(%ld %p)\n", This, index, ppNodeOut);
- hres = get_attr_dispid_by_idx(This, &index, FALSE, &id); + hres = get_attr_id_by_idx(This, &index, FALSE, &attr_id); if(hres == DISP_E_UNKNOWNNAME) return E_INVALIDARG; if(FAILED(hres)) return hres;
- hres = get_domattr(This, id, NULL, &attr); + hres = get_domattr(This, attr_id, NULL, &attr); if(FAILED(hres)) return hres;
@@ -8300,16 +8323,17 @@ static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, const WCHA { HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex); HTMLDOMAttribute *attr; + struct attr_id attr_id; LONG pos; HRESULT hres;
TRACE("(%p)->(%s %lx %p)\n", This, debugstr_w(name), flags, dispid);
- hres = get_attr_dispid_by_name(This, name, FALSE, dispid); + hres = get_attr_id_by_name(This, name, FALSE, &attr_id); if(FAILED(hres)) return hres;
- hres = get_domattr(This, *dispid, &pos, &attr); + hres = get_domattr(This, attr_id, &pos, &attr); if(FAILED(hres)) return hres; IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);