Sync with trunk r64509.
[reactos.git] / dll / win32 / mshtml / htmltablecell.c
index e18a99c..b8b81c5 100644 (file)
@@ -22,6 +22,8 @@ typedef struct {
     HTMLElement element;
 
     IHTMLTableCell IHTMLTableCell_iface;
+
+    nsIDOMHTMLTableCellElement *nscell;
 } HTMLTableCell;
 
 static inline HTMLTableCell *impl_from_IHTMLTableCell(IHTMLTableCell *iface)
@@ -112,15 +114,33 @@ static HRESULT WINAPI HTMLTableCell_get_colSpan(IHTMLTableCell *iface, LONG *p)
 static HRESULT WINAPI HTMLTableCell_put_align(IHTMLTableCell *iface, BSTR v)
 {
     HTMLTableCell *This = impl_from_IHTMLTableCell(iface);
-    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
-    return E_NOTIMPL;
+    nsAString str;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(v));
+
+    nsAString_InitDepend(&str, v);
+    nsres = nsIDOMHTMLTableCellElement_SetAlign(This->nscell, &str);
+    nsAString_Finish(&str);
+    if (NS_FAILED(nsres)) {
+        ERR("Set Align failed: %08x\n", nsres);
+        return E_FAIL;
+    }
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLTableCell_get_align(IHTMLTableCell *iface, BSTR *p)
 {
     HTMLTableCell *This = impl_from_IHTMLTableCell(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsAString str;
+    nsresult nsres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    nsAString_Init(&str, NULL);
+    nsres = nsIDOMHTMLTableCellElement_GetAlign(This->nscell, &str);
+
+    return return_nsstr(nsres, &str, p);
 }
 
 static HRESULT WINAPI HTMLTableCell_put_vAlign(IHTMLTableCell *iface, BSTR v)
@@ -140,15 +160,47 @@ static HRESULT WINAPI HTMLTableCell_get_vAlign(IHTMLTableCell *iface, BSTR *p)
 static HRESULT WINAPI HTMLTableCell_put_bgColor(IHTMLTableCell *iface, VARIANT v)
 {
     HTMLTableCell *This = impl_from_IHTMLTableCell(iface);
-    FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
-    return E_NOTIMPL;
+    nsAString strColor;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
+
+    if(!variant_to_nscolor(&v, &strColor))
+        return S_OK;
+
+    nsres = nsIDOMHTMLTableCellElement_SetBgColor(This->nscell, &strColor);
+    nsAString_Finish(&strColor);
+    if(NS_FAILED(nsres)) {
+        ERR("SetBgColor(%s) failed: %08x\n", debugstr_variant(&v), nsres);
+        return E_FAIL;
+    }
+
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLTableCell_get_bgColor(IHTMLTableCell *iface, VARIANT *p)
 {
     HTMLTableCell *This = impl_from_IHTMLTableCell(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsAString strColor;
+    nsresult nsres;
+    HRESULT hres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    nsAString_Init(&strColor, NULL);
+    nsres = nsIDOMHTMLTableCellElement_GetBgColor(This->nscell, &strColor);
+
+    if(NS_SUCCEEDED(nsres)) {
+        const PRUnichar *color;
+        nsAString_GetData(&strColor, &color);
+        V_VT(p) = VT_BSTR;
+        hres = nscolor_to_str(color, &V_BSTR(p));
+    }else {
+        ERR("GetBgColor failed: %08x\n", nsres);
+        hres = E_FAIL;
+    }
+    nsAString_Finish(&strColor);
+    return hres;
 }
 
 static HRESULT WINAPI HTMLTableCell_put_noWrap(IHTMLTableCell *iface, VARIANT_BOOL v)
@@ -252,8 +304,16 @@ static HRESULT WINAPI HTMLTableCell_get_height(IHTMLTableCell *iface, VARIANT *p
 static HRESULT WINAPI HTMLTableCell_get_cellIndex(IHTMLTableCell *iface, LONG *p)
 {
     HTMLTableCell *This = impl_from_IHTMLTableCell(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsresult nsres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+    nsres = nsIDOMHTMLTableCellElement_GetCellIndex(This->nscell, p);
+    if (NS_FAILED(nsres)) {
+        ERR("Get CellIndex failed: %08x\n", nsres);
+        return E_FAIL;
+    }
+
+    return S_OK;
 }
 
 static const IHTMLTableCellVtbl HTMLTableCellVtbl = {
@@ -349,6 +409,7 @@ static dispex_static_data_t HTMLTableCell_dispex = {
 HRESULT HTMLTableCell_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
 {
     HTMLTableCell *ret;
+    nsresult nsres;
 
     ret = heap_alloc_zero(sizeof(*ret));
     if(!ret)
@@ -359,6 +420,12 @@ HRESULT HTMLTableCell_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, H
 
     HTMLElement_Init(&ret->element, doc, nselem, &HTMLTableCell_dispex);
 
+    nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLTableCellElement, (void**)&ret->nscell);
+
+    /* Share nscell reference with nsnode */
+    assert(nsres == NS_OK && (nsIDOMNode*)ret->nscell == ret->element.node.nsnode);
+    nsIDOMNode_Release(ret->element.node.nsnode);
+
     *elem = &ret->element;
     return S_OK;
 }