mshtml: Split conversion to string out of get_elem_attr_value_by_dispid.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-03-30 14:38:44 +02:00 committed by Alexandre Julliard
parent 51304cbe72
commit a3ab8d6792
3 changed files with 40 additions and 34 deletions

View File

@ -169,7 +169,7 @@ static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, V
if(!This->elem)
return VariantCopy(p, &This->value);
return get_elem_attr_value_by_dispid(This->elem, This->dispid, 0, p);
return get_elem_attr_value_by_dispid(This->elem, This->dispid, p);
}
static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p)
@ -315,7 +315,9 @@ static HRESULT WINAPI HTMLDOMAttribute2_get_value(IHTMLDOMAttribute2 *iface, BST
return E_UNEXPECTED;
}
hres = get_elem_attr_value_by_dispid(This->elem, This->dispid, ATTRFLAG_ASSTRING, &val);
hres = get_elem_attr_value_by_dispid(This->elem, This->dispid, &val);
if(SUCCEEDED(hres))
hres = attr_value_to_string(&val);
if(FAILED(hres))
return hres;

View File

@ -63,6 +63,10 @@ static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
static const WCHAR trW[] = {'T','R',0};
#define ATTRFLAG_CASESENSITIVE 0x0001
#define ATTRFLAG_ASSTRING 0x0002
#define ATTRFLAG_EXPANDURL 0x0004
typedef struct {
const WCHAR *name;
HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
@ -638,39 +642,39 @@ static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttr
LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
}
HRESULT get_elem_attr_value_by_dispid(HTMLElement *elem, DISPID dispid, DWORD flags, VARIANT *ret)
HRESULT get_elem_attr_value_by_dispid(HTMLElement *elem, DISPID dispid, VARIANT *ret)
{
DISPPARAMS dispParams = {NULL, NULL, 0, 0};
EXCEPINFO excep;
return IDispatchEx_InvokeEx(&elem->node.event_target.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dispParams, ret, &excep, NULL);
}
HRESULT attr_value_to_string(VARIANT *v)
{
HRESULT hres;
static const WCHAR nullW[] = {'n','u','l','l',0};
hres = IDispatchEx_InvokeEx(&elem->node.event_target.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dispParams, ret, &excep, NULL);
if(FAILED(hres))
return hres;
if(flags & ATTRFLAG_ASSTRING) {
switch(V_VT(ret)) {
case VT_BSTR:
break;
case VT_NULL:
V_BSTR(ret) = SysAllocString(nullW);
if(!V_BSTR(ret))
return E_OUTOFMEMORY;
V_VT(ret) = VT_BSTR;
break;
case VT_DISPATCH:
IDispatch_Release(V_DISPATCH(ret));
V_VT(ret) = VT_BSTR;
V_BSTR(ret) = SysAllocString(NULL);
break;
default:
hres = VariantChangeType(ret, ret, 0, VT_BSTR);
if(FAILED(hres))
return hres;
}
switch(V_VT(v)) {
case VT_BSTR:
break;
case VT_NULL:
V_BSTR(v) = SysAllocString(nullW);
if(!V_BSTR(v))
return E_OUTOFMEMORY;
V_VT(v) = VT_BSTR;
break;
case VT_DISPATCH:
IDispatch_Release(V_DISPATCH(v));
V_VT(v) = VT_BSTR;
V_BSTR(v) = SysAllocString(NULL);
break;
default:
hres = VariantChangeType(v, v, 0, VT_BSTR);
if(FAILED(hres))
return hres;
}
return S_OK;
@ -700,7 +704,10 @@ static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttr
return hres;
}
return get_elem_attr_value_by_dispid(This, dispid, lFlags, AttributeValue);
hres = get_elem_attr_value_by_dispid(This, dispid, AttributeValue);
if(SUCCEEDED(hres) && (lFlags & ATTRFLAG_ASSTRING))
hres = attr_value_to_string(AttributeValue);
return hres;
}
static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,

View File

@ -1016,11 +1016,8 @@ IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL) DECLSPEC_HIDDEN
IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,nsIDOMNodeList*) DECLSPEC_HIDDEN;
IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,nsIDOMHTMLCollection*) DECLSPEC_HIDDEN;
#define ATTRFLAG_CASESENSITIVE 0x0001
#define ATTRFLAG_ASSTRING 0x0002
#define ATTRFLAG_EXPANDURL 0x0004
HRESULT get_elem_attr_value_by_dispid(HTMLElement*,DISPID,DWORD,VARIANT*) DECLSPEC_HIDDEN;
HRESULT attr_value_to_string(VARIANT*) DECLSPEC_HIDDEN;
HRESULT get_elem_attr_value_by_dispid(HTMLElement*,DISPID,VARIANT*) DECLSPEC_HIDDEN;
HRESULT get_elem_source_index(HTMLElement*,LONG*) DECLSPEC_HIDDEN;
nsresult get_elem_attr_value(nsIDOMHTMLElement*,const WCHAR*,nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;