Commit 60311080 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Added IHTMLMetaElement::charset property implementation.

parent b4c96633
......@@ -175,11 +175,12 @@ nsresult get_elem_attr_value(nsIDOMHTMLElement *nselem, const WCHAR *name, nsASt
return NS_OK;
}
HRESULT elem_string_attr_getter(HTMLElement *elem, const WCHAR *name, BSTR *p)
HRESULT elem_string_attr_getter(HTMLElement *elem, const WCHAR *name, BOOL use_null, BSTR *p)
{
const PRUnichar *val;
nsAString val_str;
nsresult nsres;
HRESULT hres = S_OK;
nsres = get_elem_attr_value(elem->nselem, name, &val_str, &val);
if(NS_FAILED(nsres))
......@@ -187,9 +188,34 @@ HRESULT elem_string_attr_getter(HTMLElement *elem, const WCHAR *name, BSTR *p)
TRACE("%s: returning %s\n", debugstr_w(name), debugstr_w(val));
*p = SysAllocString(val);
if(*val || !use_null) {
*p = SysAllocString(val);
if(!*p)
hres = E_OUTOFMEMORY;
}else {
*p = NULL;
}
nsAString_Finish(&val_str);
return *p ? S_OK : E_OUTOFMEMORY;
return hres;
}
HRESULT elem_string_attr_setter(HTMLElement *elem, const WCHAR *name, const WCHAR *value)
{
nsAString name_str, val_str;
nsresult nsres;
nsAString_InitDepend(&name_str, name);
nsAString_InitDepend(&val_str, value);
nsres = nsIDOMHTMLElement_SetAttribute(elem->nselem, &name_str, &val_str);
nsAString_Finish(&name_str);
nsAString_Finish(&val_str);
if(NS_FAILED(nsres)) {
WARN("SetAttribute failed: %08x\n", nsres);
return E_FAIL;
}
return S_OK;
}
typedef struct
......
......@@ -1337,7 +1337,7 @@ static HRESULT WINAPI HTMLLabelElement_get_htmlFor(IHTMLLabelElement *iface, BST
TRACE("(%p)->(%p)\n", This, p);
return elem_string_attr_getter(&This->element, forW, p);
return elem_string_attr_getter(&This->element, forW, FALSE, p);
}
static HRESULT WINAPI HTMLLabelElement_put_accessKey(IHTMLLabelElement *iface, BSTR v)
......
......@@ -108,7 +108,7 @@ static HRESULT WINAPI HTMLMetaElement_get_httpEquiv(IHTMLMetaElement *iface, BST
TRACE("(%p)->(%p)\n", This, p);
return elem_string_attr_getter(&This->element, httpEquivW, p);
return elem_string_attr_getter(&This->element, httpEquivW, TRUE, p);
}
static HRESULT WINAPI HTMLMetaElement_put_content(IHTMLMetaElement *iface, BSTR v)
......@@ -125,7 +125,7 @@ static HRESULT WINAPI HTMLMetaElement_get_content(IHTMLMetaElement *iface, BSTR
TRACE("(%p)->(%p)\n", This, p);
return elem_string_attr_getter(&This->element, contentW, p);
return elem_string_attr_getter(&This->element, contentW, TRUE, p);
}
static HRESULT WINAPI HTMLMetaElement_put_name(IHTMLMetaElement *iface, BSTR v)
......@@ -142,7 +142,7 @@ static HRESULT WINAPI HTMLMetaElement_get_name(IHTMLMetaElement *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return elem_string_attr_getter(&This->element, nameW, p);
return elem_string_attr_getter(&This->element, nameW, TRUE, p);
}
static HRESULT WINAPI HTMLMetaElement_put_url(IHTMLMetaElement *iface, BSTR v)
......@@ -159,18 +159,24 @@ static HRESULT WINAPI HTMLMetaElement_get_url(IHTMLMetaElement *iface, BSTR *p)
return E_NOTIMPL;
}
static const WCHAR charsetW[] = {'c','h','a','r','s','e','t',0};
static HRESULT WINAPI HTMLMetaElement_put_charset(IHTMLMetaElement *iface, BSTR v)
{
HTMLMetaElement *This = impl_from_IHTMLMetaElement(iface);
FIXME("(%p)->(%s)\n", This, debugstr_w(v));
return E_NOTIMPL;
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return elem_string_attr_setter(&This->element, charsetW, v);
}
static HRESULT WINAPI HTMLMetaElement_get_charset(IHTMLMetaElement *iface, BSTR *p)
{
HTMLMetaElement *This = impl_from_IHTMLMetaElement(iface);
FIXME("(%p)->(%p)\n", This, p);
return E_NOTIMPL;
TRACE("(%p)->(%p)\n", This, p);
return elem_string_attr_getter(&This->element, charsetW, TRUE, p);
}
static const IHTMLMetaElementVtbl HTMLMetaElementVtbl = {
......
......@@ -959,7 +959,8 @@ IHTMLElementCollection *create_collection_from_nodelist(HTMLDocumentNode*,nsIDOM
IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode*,nsIDOMHTMLCollection*) DECLSPEC_HIDDEN;
nsresult get_elem_attr_value(nsIDOMHTMLElement*,const WCHAR*,nsAString*,const PRUnichar**) DECLSPEC_HIDDEN;
HRESULT elem_string_attr_getter(HTMLElement*,const WCHAR*,BSTR*) DECLSPEC_HIDDEN;
HRESULT elem_string_attr_getter(HTMLElement*,const WCHAR*,BOOL,BSTR*) DECLSPEC_HIDDEN;
HRESULT elem_string_attr_setter(HTMLElement*,const WCHAR*,const WCHAR*) DECLSPEC_HIDDEN;
/* commands */
typedef struct {
......
......@@ -3803,7 +3803,6 @@ static void _test_meta_name(unsigned line, IUnknown *unk, const char *exname)
BSTR name = NULL;
HRESULT hres;
meta = _get_metaelem_iface(line, unk);
hres = IHTMLMetaElement_get_name(meta, &name);
ok_(__FILE__,line)(hres == S_OK, "get_name failed: %08x\n", hres);
......@@ -3819,7 +3818,6 @@ static void _test_meta_content(unsigned line, IUnknown *unk, const char *exconte
BSTR content = NULL;
HRESULT hres;
meta = _get_metaelem_iface(line, unk);
hres = IHTMLMetaElement_get_content(meta, &content);
ok_(__FILE__,line)(hres == S_OK, "get_content failed: %08x\n", hres);
......@@ -3835,7 +3833,6 @@ static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const char *exval
BSTR val = NULL;
HRESULT hres;
meta = _get_metaelem_iface(line, unk);
hres = IHTMLMetaElement_get_httpEquiv(meta, &val);
ok_(__FILE__,line)(hres == S_OK, "get_httpEquiv failed: %08x\n", hres);
......@@ -3844,6 +3841,40 @@ static void _test_meta_httpequiv(unsigned line, IUnknown *unk, const char *exval
IHTMLMetaElement_Release(meta);
}
#define test_meta_charset(a,b) _test_meta_charset(__LINE__,a,b)
static void _test_meta_charset(unsigned line, IUnknown *unk, const char *exval)
{
IHTMLMetaElement *meta;
BSTR val = NULL;
HRESULT hres;
meta = _get_metaelem_iface(line, unk);
hres = IHTMLMetaElement_get_charset(meta, &val);
ok_(__FILE__,line)(hres == S_OK, "get_charset failed: %08x\n", hres);
if(exval)
ok_(__FILE__,line)(!strcmp_wa(val, exval), "charset = %s, expected %s\n", wine_dbgstr_w(val), exval);
else
ok_(__FILE__,line)(!val, "charset = %s, expected NULL\n", wine_dbgstr_w(val));
SysFreeString(val);
IHTMLMetaElement_Release(meta);
}
#define set_meta_charset(a,b) _set_meta_charset(__LINE__,a,b)
static void _set_meta_charset(unsigned line, IUnknown *unk, const char *vala)
{
BSTR val = a2bstr(vala);
IHTMLMetaElement *meta;
HRESULT hres;
meta = _get_metaelem_iface(line, unk);
hres = IHTMLMetaElement_put_charset(meta, val);
ok_(__FILE__,line)(hres == S_OK, "put_charset failed: %08x\n", hres);
SysFreeString(val);
IHTMLMetaElement_Release(meta);
_test_meta_charset(line, unk, vala);
}
#define test_link_media(a,b) _test_link_media(__LINE__,a,b)
static void _test_link_media(unsigned line, IHTMLElement *elem, const char *exval)
{
......@@ -6969,6 +7000,8 @@ static void test_elems(IHTMLDocument2 *doc)
test_meta_name((IUnknown*)elem, "meta name");
test_meta_content((IUnknown*)elem, "text/html; charset=utf-8");
test_meta_httpequiv((IUnknown*)elem, "Content-Type");
test_meta_charset((IUnknown*)elem, NULL);
set_meta_charset((IUnknown*)elem, "utf-8");
IHTMLElement_Release(elem);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment