Jacek Caban : mshtml: Factor out variant_to_nsstr from var_to_styleval.
Alexandre Julliard
julliard at winehq.org
Fri Apr 19 17:30:46 CDT 2019
Module: wine
Branch: master
Commit: 1593364466b195571c3be71650d113645895aa57
URL: https://source.winehq.org/git/wine.git/?a=commit;h=1593364466b195571c3be71650d113645895aa57
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Apr 19 16:37:16 2019 +0200
mshtml: Factor out variant_to_nsstr from var_to_styleval.
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/mshtml/htmlstyle.c | 37 ++++---------------------------------
dlls/mshtml/mshtml_private.h | 1 +
dlls/mshtml/nsembed.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 33 deletions(-)
diff --git a/dlls/mshtml/htmlstyle.c b/dlls/mshtml/htmlstyle.c
index 2d045db..7f50cb4 100644
--- a/dlls/mshtml/htmlstyle.c
+++ b/dlls/mshtml/htmlstyle.c
@@ -933,43 +933,14 @@ static HRESULT set_nsstyle_property(nsIDOMCSSStyleDeclaration *nsstyle, styleid_
static HRESULT var_to_styleval(CSSStyle *style, VARIANT *v, const style_tbl_entry_t *entry, nsAString *nsstr)
{
+ HRESULT hres;
unsigned flags = entry && dispex_compat_mode(&style->dispex) < COMPAT_MODE_IE9
? entry->flags : 0;
- switch(V_VT(v)) {
- case VT_NULL:
- nsAString_InitDepend(nsstr, NULL);
- return S_OK;
-
- case VT_BSTR:
- nsAString_InitDepend(nsstr, V_BSTR(v));
- break;
-
- case VT_BSTR|VT_BYREF:
- nsAString_InitDepend(nsstr, *V_BSTRREF(v));
- break;
-
- case VT_I4: {
- static const WCHAR formatW[] = {'%','d',0};
- static const WCHAR hex_formatW[] = {'#','%','0','6','x',0};
- WCHAR buf[14];
-
- if(flags & ATTR_HEX_INT)
- wsprintfW(buf, hex_formatW, V_I4(v));
- else
- wsprintfW(buf, formatW, V_I4(v));
-
- nsAString_Init(nsstr, buf);
- break;
- }
- default:
- FIXME("not implemented for %s\n", debugstr_variant(v));
- return E_NOTIMPL;
-
- }
- if(flags & ATTR_FIX_PX)
+ hres = variant_to_nsstr(v, !!(flags & ATTR_HEX_INT), nsstr);
+ if(SUCCEEDED(hres) && (flags & ATTR_FIX_PX))
fix_px_value(nsstr);
- return S_OK;
+ return hres;
}
static inline HRESULT set_style_property(CSSStyle *style, styleid_t sid, const WCHAR *value)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index a44eaf5..f4bbe76 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -975,6 +975,7 @@ void nsAString_Finish(nsAString*) DECLSPEC_HIDDEN;
HRESULT map_nsresult(nsresult) DECLSPEC_HIDDEN;
HRESULT return_nsstr(nsresult,nsAString*,BSTR*) DECLSPEC_HIDDEN;
HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, VARIANT *p) DECLSPEC_HIDDEN;
+HRESULT variant_to_nsstr(VARIANT*,BOOL,nsAString*) DECLSPEC_HIDDEN;
HRESULT return_nsform(nsresult,nsIDOMHTMLFormElement*,IHTMLFormElement**) DECLSPEC_HIDDEN;
nsICommandParams *create_nscommand_params(void) DECLSPEC_HIDDEN;
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index bcfc437..08e6507 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -932,6 +932,44 @@ HRESULT return_nsstr_variant(nsresult nsres, nsAString *nsstr, VARIANT *p)
return S_OK;
}
+/*
+ * Converts VARIANT to string and stores the result in nsAString. To avoid useless
+ * allocations, the function uses an existing string if available, so caller must
+ * ensure that passed VARIANT is unchanged as long as its string representation is used
+ */
+HRESULT variant_to_nsstr(VARIANT *v, BOOL hex_int, nsAString *nsstr)
+{
+ WCHAR buf[32];
+
+ static const WCHAR d_formatW[] = {'%','d',0};
+ static const WCHAR hex_formatW[] = {'#','%','0','6','x',0};
+
+ switch(V_VT(v)) {
+ case VT_NULL:
+ nsAString_InitDepend(nsstr, NULL);
+ return S_OK;
+
+ case VT_BSTR:
+ nsAString_InitDepend(nsstr, V_BSTR(v));
+ break;
+
+ case VT_BSTR|VT_BYREF:
+ nsAString_InitDepend(nsstr, *V_BSTRREF(v));
+ break;
+
+ case VT_I4:
+ wsprintfW(buf, hex_int ? hex_formatW : d_formatW, V_I4(v));
+ nsAString_Init(nsstr, buf);
+ break;
+
+ default:
+ FIXME("not implemented for %s\n", debugstr_variant(v));
+ return E_NOTIMPL;
+
+ }
+ return S_OK;
+}
+
nsICommandParams *create_nscommand_params(void)
{
nsICommandParams *ret = NULL;
More information about the wine-cvs
mailing list