From 8e0d6619276f3c139defc9461c294a49022d9fc9 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 4 May 2015 19:14:13 +0200 Subject: [PATCH] mshtml: Split getAttribute into helper function and use it in IHTMLDOMAttribute::get_nodeValue implementation. --- dlls/mshtml/htmlattr.c | 6 +--- dlls/mshtml/htmlelem.c | 59 +++++++++++++++++++----------------- dlls/mshtml/mshtml_private.h | 6 ++++ 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/dlls/mshtml/htmlattr.c b/dlls/mshtml/htmlattr.c index 8359847193..bd0630e756 100644 --- a/dlls/mshtml/htmlattr.c +++ b/dlls/mshtml/htmlattr.c @@ -164,8 +164,6 @@ static HRESULT WINAPI HTMLDOMAttribute_put_nodeValue(IHTMLDOMAttribute *iface, V static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p) { HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface); - DISPPARAMS dp = {NULL, NULL, 0, 0}; - EXCEPINFO ei; TRACE("(%p)->(%p)\n", This, p); @@ -174,9 +172,7 @@ static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, V return E_UNEXPECTED; } - memset(&ei, 0, sizeof(ei)); - return IDispatchEx_InvokeEx(&This->elem->node.dispex.IDispatchEx_iface, This->dispid, LOCALE_SYSTEM_DEFAULT, - DISPATCH_PROPERTYGET, &dp, p, &ei, NULL); + return get_elem_attr_value_by_dispid(This->elem, This->dispid, 0, p); } static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p) diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index d2e9f275ba..c70786b1ce 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -606,10 +606,6 @@ static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMembe wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); } -#define ATTRFLAG_CASESENSITIVE 0x0001 -#define ATTRFLAG_ASSTRING 0x0002 -#define ATTRFLAG_EXPANDURL 0x0004 - static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName, VARIANT AttributeValue, LONG lFlags) { @@ -640,14 +636,42 @@ 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) +{ + DISPPARAMS dispParams = {NULL, NULL, 0, 0}; + EXCEPINFO excep; + HRESULT hres; + + hres = IDispatchEx_InvokeEx(&elem->node.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_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; + } + } + + return S_OK; +} + static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName, LONG lFlags, VARIANT *AttributeValue) { HTMLElement *This = impl_from_IHTMLElement(iface); DISPID dispid; HRESULT hres; - DISPPARAMS dispParams = {NULL, NULL, 0, 0}; - EXCEPINFO excep; TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue); @@ -666,28 +690,7 @@ static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttr return hres; } - hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT, - DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL); - if(FAILED(hres)) - return hres; - - if(lFlags & ATTRFLAG_ASSTRING) { - switch(V_VT(AttributeValue)) { - case VT_BSTR: - break; - case VT_DISPATCH: - IDispatch_Release(V_DISPATCH(AttributeValue)); - V_VT(AttributeValue) = VT_BSTR; - V_BSTR(AttributeValue) = SysAllocString(NULL); - break; - default: - hres = VariantChangeType(AttributeValue, AttributeValue, 0, VT_BSTR); - if(FAILED(hres)) - return hres; - } - } - - return S_OK; + return get_elem_attr_value_by_dispid(This, dispid, lFlags, AttributeValue); } static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName, diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 22b8397878..cc1d27be38 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -976,6 +976,12 @@ HRESULT wrap_iface(IUnknown*,IUnknown*,IUnknown**) DECLSPEC_HIDDEN; 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 get_elem_source_index(HTMLElement*,LONG*) DECLSPEC_HIDDEN; nsresult get_elem_attr_value(nsIDOMHTMLElement*,const WCHAR*,nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;