mshtml: Implement IHTMLStyle get/put posLeft.

This commit is contained in:
Alistair Leslie-Hughes 2008-11-05 22:06:45 +11:00 committed by Alexandre Julliard
parent 2e25b859ea
commit af0aa2832f
2 changed files with 93 additions and 4 deletions

View File

@ -17,6 +17,7 @@
*/
#include <stdarg.h>
#include <math.h>
#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)

View File

@ -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);