From: Zhenbo Li Subject: mshtml: Added IHTMLTable::width property implementation. Message-Id: <5351D395.6080207@gmail.com> Date: Sat, 19 Apr 2014 09:38:29 +0800 try 2: Thanks for Jacek's suggestions. 1. Convert float to int in getter, instead of setter. 2. Make the helper more generic (var2str) 3. Don't mistake HRESULT/nsresult 4. Don't use return_nsst in the old way 5. More strict in cmp_length origin: As my test case shows, windows would truncate float numbers. I considered VarInt() in oleaut32.dll, but I think to declare var2str_length() is more clear. --- dlls/mshtml/htmltable.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++--- dlls/mshtml/tests/dom.c | 67 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 4 deletions(-) diff --git a/dlls/mshtml/htmltable.c b/dlls/mshtml/htmltable.c index d711ed7..def2fc6 100644 --- a/dlls/mshtml/htmltable.c +++ b/dlls/mshtml/htmltable.c @@ -57,6 +57,33 @@ static inline HTMLTable *impl_from_IHTMLTable3(IHTMLTable3 *iface) return CONTAINING_RECORD(iface, HTMLTable, IHTMLTable3_iface); } +static HRESULT var2str(nsAString *nsstr, const VARIANT *p) +{ + BSTR str; + BOOL ret; + + switch(V_VT(p)) { + case VT_BSTR: + return nsAString_Init(nsstr, V_BSTR(p))? + S_OK : E_FAIL; + case VT_R8: + VarBstrFromR8(V_R8(p), 0, 0, &str); + break; + case VT_R4: + VarBstrFromR4(V_R4(p), 0, 0, &str); + break; + case VT_I4: + VarBstrFromI4(V_I4(p), 0, 0, &str); + break; + default: + FIXME("unsupported arg %s\n", debugstr_variant(p)); + return E_NOTIMPL; + } + ret = nsAString_Init(nsstr, str); + SysFreeString(str); + return ret ? S_OK : E_FAIL; +} + static HRESULT WINAPI HTMLTable_QueryInterface(IHTMLTable *iface, REFIID riid, void **ppv) { @@ -395,15 +422,60 @@ static HRESULT WINAPI HTMLTable_get_rows(IHTMLTable *iface, IHTMLElementCollecti static HRESULT WINAPI HTMLTable_put_width(IHTMLTable *iface, VARIANT v) { HTMLTable *This = impl_from_IHTMLTable(iface); - FIXME("(%p)->(%s)\n", This, debugstr_variant(&v)); - return E_NOTIMPL; + nsAString val; + HRESULT hres; + nsresult nsres; + + TRACE("(%p)->(%s)\n", This, debugstr_variant(&v)); + hres = var2str(&val, &v); + + if (hres != S_OK){ + ERR("Set Width(%s) failed when initializing a nsAString!\n", + debugstr_variant(&v)); + nsAString_Finish(&val); + return hres; + } + + nsres = nsIDOMHTMLTableElement_SetWidth(This->nstable, &val); + nsAString_Finish(&val); + + if (NS_FAILED(nsres)){ + ERR("Set Width(%s) failed!\n", debugstr_variant(&v)); + return E_FAIL; + } + + return S_OK; } static HRESULT WINAPI HTMLTable_get_width(IHTMLTable *iface, VARIANT *p) { HTMLTable *This = impl_from_IHTMLTable(iface); - FIXME("(%p)->(%p)\n", This, p); - return E_NOTIMPL; + nsAString val; + nsresult nsres; + DOUBLE width; + const PRUnichar *str; + + TRACE("(%p)->(%p)\n", This, p); + nsAString_Init(&val, NULL); + nsres = nsIDOMHTMLTableElement_GetWidth(This->nstable, &val); + if (NS_FAILED(nsres)){ + ERR("Get Width(%s) failed!\n", debugstr_variant(p)); + nsAString_Finish(&val); + return E_FAIL; + } + + nsAString_GetData(&val, &str); + nsres = VarR8FromStr(str, 0, 0, &width); + if (nsres == S_OK){ + V_VT(p) = VT_I4; + V_I4(p) = (LONG)width; + } else { /* Symbols are in this string */ + V_VT(p) = VT_BSTR; + V_BSTR(p) = SysAllocString(str); + if (!V_BSTR(p)) + return E_OUTOFMEMORY; + } + return S_OK; } static HRESULT WINAPI HTMLTable_put_height(IHTMLTable *iface, VARIANT v) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 23677f4..10aca6c 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -5721,6 +5721,25 @@ static void _test_table_cell_spacing(unsigned line, IHTMLTable *table, const cha VariantClear(&v); } +#define cmp_length(a,b) _cmp_length(__LINE__,a,b) +static void _cmp_length(unsigned line, VARIANT got, const char * exstr) +{ + static char buf[64]; + ok_(__FILE__,line) (V_VT(&got)==VT_BSTR || V_VT(&got)==VT_I4, + "V_VT is %hu, expected VT_BSTR(%hu) or VT_I4(%hu)\n", + V_VT(&got), VT_BSTR, VT_I4); + + if (V_VT(&got) == VT_BSTR){ + ok_(__FILE__,line) (!strcmp_wa(V_BSTR(&got), exstr), + "Expected %s, got %s\n", exstr, wine_dbgstr_w(V_BSTR(&got))); + } + else { + sprintf(buf, "%d", V_I4(&got)); + ok_(__FILE__,line) (!strcmp(buf, exstr), + "Expected %s, got %d\n", exstr, V_I4(&got)); + } +} + static void test_table_elem(IHTMLElement *elem) { IHTMLElementCollection *col; @@ -5829,6 +5848,54 @@ static void test_table_elem(IHTMLElement *elem) ok(hres == S_OK, "put_bgColor failed: %08x\n", hres); VariantClear(&vDefaultbg); + V_VT(&v) = VT_BSTR; + V_BSTR(&v) = a2bstr("11"); + hres = IHTMLTable_put_width(table, v); + ok(hres == S_OK, "put_width = %08x\n", hres); + VariantClear(&v); + IHTMLTable_get_width(table, &v); + ok(hres == S_OK, "get_width = %08x\n", hres); + cmp_length(v, "11"); + VariantClear(&v); + + V_VT(&v) = VT_BSTR; + V_BSTR(&v) = a2bstr("11.9"); + hres = IHTMLTable_put_width(table, v); + ok(hres == S_OK, "put_width = %08x\n", hres); + VariantClear(&v); + IHTMLTable_get_width(table, &v); + ok(hres == S_OK, "get_width = %08x\n", hres); + cmp_length(v, "11"); + VariantClear(&v); + + V_VT(&v) = VT_BSTR; + V_BSTR(&v) = a2bstr("40.2%"); + hres = IHTMLTable_put_width(table, v); + ok(hres == S_OK, "put_width = %08x\n", hres); + VariantClear(&v); + IHTMLTable_get_width(table, &v); + ok(hres == S_OK, "get_width = %08x\n", hres); + cmp_length(v, "40.2%"); + VariantClear(&v); + + V_VT(&v) = VT_I4; + V_I4(&v) = 11; + hres = IHTMLTable_put_width(table, v); + ok(hres == S_OK, "put_width = %08x\n", hres); + IHTMLTable_get_width(table, &v); + ok(hres == S_OK, "get_width = %08x\n", hres); + cmp_length(v, "11"); + VariantClear(&v); + + V_VT(&v) = VT_R8; + V_R8(&v) = 11.9; + hres = IHTMLTable_put_width(table, v); + ok(hres == S_OK, "put_width = %08x\n", hres); + IHTMLTable_get_width(table, &v); + ok(hres == S_OK, "get_width = %08x\n", hres); + cmp_length(v, "11"); + VariantClear(&v); + IHTMLTable_Release(table); }