[PATCH] Implement IHTMLStyle get/put posLeft

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Tue Oct 14 04:11:25 CDT 2008


---
 dlls/mshtml/htmlstyle.c |   59 +++++++++++++++++++++++++++++++++++++++++++----
 dlls/mshtml/tests/dom.c |   30 ++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/dlls/mshtml/htmlstyle.c b/dlls/mshtml/htmlstyle.c
index e90d723..dcab1c8 100644
--- a/dlls/mshtml/htmlstyle.c
+++ b/dlls/mshtml/htmlstyle.c
@@ -17,6 +17,7 @@
  */
 
 #include <stdarg.h>
+#include <wctype.h>
 
 #define COBJMACROS
 
@@ -1804,18 +1805,66 @@ static HRESULT WINAPI HTMLStyle_get_posTop(IHTMLStyle *iface, float *p)
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI HTMLStyle_put_posLeft(IHTMLStyle *iface, float v)
+static HRESULT WINAPI HTMLStyle_put_posLeft(IHTMLStyle *iface, float f)
 {
     HTMLStyle *This = HTMLSTYLE_THIS(iface);
-    FIXME("(%p)->()\n", This);
-    return E_NOTIMPL;
+    VARIANT v;
+
+    TRACE("(%p)->(%f)\n", This, f);
+
+    V_VT(&v) = VT_R4;
+    V_R4(&v) = f;
+
+    if(VariantChangeType(&v, &v, 0, VT_BSTR) == S_OK)
+    {
+        return set_style_attr(This, STYLEID_LEFT, V_BSTR(&v), ATTR_FIX_PX);
+    }
+
+    return E_FAIL;
 }
 
 static HRESULT WINAPI HTMLStyle_get_posLeft(IHTMLStyle *iface, float *p)
 {
     HTMLStyle *This = HTMLSTYLE_THIS(iface);
-    FIXME("(%p)->()\n", This);
-    return E_NOTIMPL;
+    BSTR ret;
+    HRESULT hres;
+    VARIANT v;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    if(!p)
+        return E_POINTER;
+
+    *p = 0.0f;
+
+    hres = get_style_attr(This, STYLEID_LEFT, &ret);
+    if(SUCCEEDED(hres))
+    {
+        int nLen = SysStringLen(ret);
+        int i=0;
+        V_VT(&v) = VT_BSTR;
+        V_BSTR(&v) = ret;
+
+        /* Terminate at the first non-numeric */
+        for( ; i < nLen; i++)
+        {
+            if(iswalpha(ret[i]))
+            {
+                ret[i] = 0;
+                break;
+            }
+        }
+
+        hres = VariantChangeType(&v, &v, 0, VT_R4);
+        if(hres == S_OK)
+        {
+            *p = V_R4(&v);
+        }
+    }
+
+    TRACE("ret %f\n", *p);
+
+    return S_OK;
 }
 
 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 4388048..3643b5c 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -2233,6 +2233,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);
@@ -2334,12 +2335,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.0f);
+    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);
-- 
1.5.4.3


--------------000601060502060805040307--



More information about the wine-patches mailing list