From af0aa2832f6aa45ffbff1dd3d0c2120060d79683 Mon Sep 17 00:00:00 2001 From: Alistair Leslie-Hughes Date: Wed, 5 Nov 2008 22:06:45 +1100 Subject: [PATCH] mshtml: Implement IHTMLStyle get/put posLeft. --- dlls/mshtml/htmlstyle.c | 67 ++++++++++++++++++++++++++++++++++++++--- dlls/mshtml/tests/dom.c | 30 ++++++++++++++++++ 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/dlls/mshtml/htmlstyle.c b/dlls/mshtml/htmlstyle.c index e90d723add..b11c8c227a 100644 --- a/dlls/mshtml/htmlstyle.c +++ b/dlls/mshtml/htmlstyle.c @@ -17,6 +17,7 @@ */ #include +#include #define COBJMACROS @@ -353,6 +354,57 @@ static HRESULT check_style_attr_value(HTMLStyle *This, styleid_t sid, LPCWSTR ex return S_OK; } +static inline HRESULT set_style_pos(HTMLStyle *This, styleid_t sid, float value) +{ + WCHAR szValue[25]; + WCHAR szFormat[] = {'%','.','0','f','p','x',0}; + + value = floor(value); + + sprintfW(szValue, szFormat, value); + + return set_style_attr(This, sid, szValue, 0); +} + +HRESULT get_nsstyle_pos(HTMLStyle *This, styleid_t sid, float *p) +{ + nsAString str_value; + HRESULT hres; + WCHAR pxW[] = {'p','x',0}; + + TRACE("%p %d %p\n", This, sid, p); + + *p = 0.0f; + + nsAString_Init(&str_value, NULL); + + hres = get_nsstyle_attr_nsval(This->nsstyle, sid, &str_value); + if(hres == S_OK) + { + WCHAR *ptr; + const PRUnichar *value; + + nsAString_GetData(&str_value, &value); + if(value) + { + *p = strtolW(value, &ptr, 10); + + if(*ptr && strcmpW(ptr, pxW)) + { + nsAString_Finish(&str_value); + FIXME("only px values are currently supported\n"); + return E_FAIL; + } + } + } + + TRACE("ret %f\n", *p); + + nsAString_Finish(&str_value); + + return hres; +} + #define HTMLSTYLE_THIS(iface) DEFINE_THIS(HTMLStyle, HTMLStyle, iface) static HRESULT WINAPI HTMLStyle_QueryInterface(IHTMLStyle *iface, REFIID riid, void **ppv) @@ -1807,15 +1859,22 @@ static HRESULT WINAPI HTMLStyle_get_posTop(IHTMLStyle *iface, float *p) static HRESULT WINAPI HTMLStyle_put_posLeft(IHTMLStyle *iface, float v) { HTMLStyle *This = HTMLSTYLE_THIS(iface); - FIXME("(%p)->()\n", This); - return E_NOTIMPL; + + TRACE("(%p)->(%f)\n", This, v); + + return set_style_pos(This, STYLEID_LEFT, v); } static HRESULT WINAPI HTMLStyle_get_posLeft(IHTMLStyle *iface, float *p) { HTMLStyle *This = HTMLSTYLE_THIS(iface); - FIXME("(%p)->()\n", This); - return E_NOTIMPL; + + TRACE("(%p)->(%p)\n", This, p); + + if(!p) + return E_POINTER; + + return get_nsstyle_pos(This, STYLEID_LEFT, p); } static HRESULT WINAPI HTMLStyle_put_posWidth(IHTMLStyle *iface, float v) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 7a14c295a9..e9d138f253 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -2281,6 +2281,7 @@ static void test_default_style(IHTMLStyle *style) VARIANT v; BSTR str; HRESULT hres; + float f; test_disp((IUnknown*)style, &DIID_DispHTMLStyle); test_ifaces((IUnknown*)style, style_iids); @@ -2382,12 +2383,41 @@ static void test_default_style(IHTMLStyle *style) ok(!V_BSTR(&v), "V_BSTR(v) != NULL\n"); VariantClear(&v); + /* Test posLeft */ + hres = IHTMLStyle_get_posLeft(style, NULL); + ok(hres == E_POINTER, "get_left failed: %08x\n", hres); + + f = 1.0f; + hres = IHTMLStyle_get_posLeft(style, &f); + ok(hres == S_OK, "get_left failed: %08x\n", hres); + ok(f == 0.0, "expected 0.0 got %f\n", f); + + hres = IHTMLStyle_put_posLeft(style, 4.9f); + ok(hres == S_OK, "get_left failed: %08x\n", hres); + + hres = IHTMLStyle_get_posLeft(style, &f); + ok(hres == S_OK, "get_left failed: %08x\n", hres); + ok(f == 4.0, "expected 4.0 got %f\n", f); + + /* Ensure left is updated correctly. */ + V_VT(&v) = VT_EMPTY; + hres = IHTMLStyle_get_left(style, &v); + ok(hres == S_OK, "get_left failed: %08x\n", hres); + ok(V_VT(&v) == VT_BSTR, "V_VT(v)=%d\n", V_VT(&v)); + ok(!strcmp_wa(V_BSTR(&v), "4px"), "V_BSTR(v) = %s\n", dbgstr_w(V_BSTR(&v))); + VariantClear(&v); + + /* Test left */ V_VT(&v) = VT_BSTR; V_BSTR(&v) = a2bstr("3px"); hres = IHTMLStyle_put_left(style, v); ok(hres == S_OK, "put_left failed: %08x\n", hres); VariantClear(&v); + hres = IHTMLStyle_get_posLeft(style, &f); + ok(hres == S_OK, "get_left failed: %08x\n", hres); + ok(f == 3.0, "expected 3.0 got %f\n", f); + V_VT(&v) = VT_EMPTY; hres = IHTMLStyle_get_left(style, &v); ok(hres == S_OK, "get_left failed: %08x\n", hres);