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

mshtml: Use IDs instead of strings in HTMLStyle implementation.

parent 596206f0
......@@ -68,6 +68,26 @@ static const WCHAR attrVisibility[] =
static const WCHAR attrWidth[] =
{'w','i','d','t','h',0};
static const LPCWSTR style_strings[] = {
attrBackground,
attrBackgroundColor,
attrBackgroundImage,
attrBorderLeft,
attrColor,
attrDisplay,
attrFontFamily,
attrFontSize,
attrFontStyle,
attrFontWeight,
attrMargin,
attrMarginLeft,
attrMarginRight,
attrPaddingLeft,
attrTextDecoration,
attrVisibility,
attrWidth,
};
static const WCHAR valLineThrough[] =
{'l','i','n','e','-','t','h','r','o','u','g','h',0};
static const WCHAR valUnderline[] =
......@@ -134,7 +154,7 @@ static LPWSTR fix_url_value(LPCWSTR val)
#define ATTR_FIX_PX 1
#define ATTR_FIX_URL 2
static HRESULT set_style_attr(HTMLStyle *This, LPCWSTR name, LPCWSTR value, DWORD flags)
static HRESULT set_style_attr(HTMLStyle *This, styleid_t sid, LPCWSTR value, DWORD flags)
{
nsAString str_name, str_value, str_empty;
LPWSTR val = NULL;
......@@ -142,14 +162,14 @@ static HRESULT set_style_attr(HTMLStyle *This, LPCWSTR name, LPCWSTR value, DWOR
static const PRUnichar wszEmpty[] = {0};
TRACE("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_w(value));
TRACE("(%p)->(%s %s)\n", This, debugstr_w(style_strings[sid]), debugstr_w(value));
if(flags & ATTR_FIX_PX)
val = fix_px_value(value);
if(flags & ATTR_FIX_URL)
val = fix_url_value(value);
nsAString_Init(&str_name, name);
nsAString_Init(&str_name, style_strings[sid]);
nsAString_Init(&str_value, val ? val : value);
nsAString_Init(&str_empty, wszEmpty);
heap_free(val);
......@@ -165,12 +185,12 @@ static HRESULT set_style_attr(HTMLStyle *This, LPCWSTR name, LPCWSTR value, DWOR
return S_OK;
}
static HRESULT get_style_attr_nsval(HTMLStyle *This, LPCWSTR name, nsAString *value)
static HRESULT get_style_attr_nsval(HTMLStyle *This, styleid_t sid, nsAString *value)
{
nsAString str_name;
nsresult nsres;
nsAString_Init(&str_name, name);
nsAString_Init(&str_name, style_strings[sid]);
nsres = nsIDOMCSSStyleDeclaration_GetPropertyValue(This->nsstyle, &str_name, value);
if(NS_FAILED(nsres)) {
......@@ -183,38 +203,38 @@ static HRESULT get_style_attr_nsval(HTMLStyle *This, LPCWSTR name, nsAString *va
return NS_OK;
}
static HRESULT get_style_attr(HTMLStyle *This, LPCWSTR name, BSTR *p)
static HRESULT get_style_attr(HTMLStyle *This, styleid_t sid, BSTR *p)
{
nsAString str_value;
const PRUnichar *value;
nsAString_Init(&str_value, NULL);
get_style_attr_nsval(This, name, &str_value);
get_style_attr_nsval(This, sid, &str_value);
nsAString_GetData(&str_value, &value);
*p = *value ? SysAllocString(value) : NULL;
nsAString_Finish(&str_value);
TRACE("%s -> %s\n", debugstr_w(name), debugstr_w(*p));
TRACE("%s -> %s\n", debugstr_w(style_strings[sid]), debugstr_w(*p));
return S_OK;
}
static HRESULT check_style_attr_value(HTMLStyle *This, LPCWSTR name, LPCWSTR exval, VARIANT_BOOL *p)
static HRESULT check_style_attr_value(HTMLStyle *This, styleid_t sid, LPCWSTR exval, VARIANT_BOOL *p)
{
nsAString str_value;
const PRUnichar *value;
nsAString_Init(&str_value, NULL);
get_style_attr_nsval(This, name, &str_value);
get_style_attr_nsval(This, sid, &str_value);
nsAString_GetData(&str_value, &value);
*p = strcmpW(value, exval) ? VARIANT_FALSE : VARIANT_TRUE;
nsAString_Finish(&str_value);
TRACE("%s -> %x\n", debugstr_w(name), *p);
TRACE("%s -> %x\n", debugstr_w(style_strings[sid]), *p);
return S_OK;
}
......@@ -307,7 +327,7 @@ static HRESULT WINAPI HTMLStyle_put_fontFamily(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrFontFamily, v, 0);
return set_style_attr(This, STYLEID_FONT_FAMILY, v, 0);
}
static HRESULT WINAPI HTMLStyle_get_fontFamily(IHTMLStyle *iface, BSTR *p)
......@@ -316,7 +336,7 @@ static HRESULT WINAPI HTMLStyle_get_fontFamily(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrFontFamily, p);
return get_style_attr(This, STYLEID_FONT_FAMILY, p);
}
static HRESULT WINAPI HTMLStyle_put_fontStyle(IHTMLStyle *iface, BSTR v)
......@@ -332,7 +352,7 @@ static HRESULT WINAPI HTMLStyle_get_fontStyle(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrFontStyle, p);
return get_style_attr(This, STYLEID_FONT_STYLE, p);
}
static HRESULT WINAPI HTMLStyle_put_fontVariant(IHTMLStyle *iface, BSTR v)
......@@ -362,7 +382,7 @@ static HRESULT WINAPI HTMLStyle_get_fontWeight(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrFontWeight, p);
return get_style_attr(This, STYLEID_FONT_WEIGHT, p);
}
static HRESULT WINAPI HTMLStyle_put_fontSize(IHTMLStyle *iface, VARIANT v)
......@@ -373,7 +393,7 @@ static HRESULT WINAPI HTMLStyle_put_fontSize(IHTMLStyle *iface, VARIANT v)
switch(V_VT(&v)) {
case VT_BSTR:
return set_style_attr(This, attrFontSize, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_FONT_SIZE, V_BSTR(&v), 0);
default:
FIXME("not supported vt %d\n", V_VT(&v));
}
......@@ -388,7 +408,7 @@ static HRESULT WINAPI HTMLStyle_get_fontSize(IHTMLStyle *iface, VARIANT *p)
TRACE("(%p)->(%p)\n", This, p);
V_VT(p) = VT_BSTR;
return get_style_attr(This, attrFontSize, &V_BSTR(p));
return get_style_attr(This, STYLEID_FONT_SIZE, &V_BSTR(p));
}
static HRESULT WINAPI HTMLStyle_put_font(IHTMLStyle *iface, BSTR v)
......@@ -414,7 +434,7 @@ static HRESULT WINAPI HTMLStyle_put_color(IHTMLStyle *iface, VARIANT v)
switch(V_VT(&v)) {
case VT_BSTR:
TRACE("%s\n", debugstr_w(V_BSTR(&v)));
return set_style_attr(This, attrColor, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_COLOR, V_BSTR(&v), 0);
default:
FIXME("unsupported vt=%d\n", V_VT(&v));
......@@ -430,7 +450,7 @@ static HRESULT WINAPI HTMLStyle_get_color(IHTMLStyle *iface, VARIANT *p)
TRACE("(%p)->(%p)\n", This, p);
V_VT(p) = VT_BSTR;
return get_style_attr(This, attrColor, &V_BSTR(p));
return get_style_attr(This, STYLEID_COLOR, &V_BSTR(p));
}
static HRESULT WINAPI HTMLStyle_put_background(IHTMLStyle *iface, BSTR v)
......@@ -439,7 +459,7 @@ static HRESULT WINAPI HTMLStyle_put_background(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrBackground, v, 0);
return set_style_attr(This, STYLEID_BACKGROUND, v, 0);
}
static HRESULT WINAPI HTMLStyle_get_background(IHTMLStyle *iface, BSTR *p)
......@@ -448,7 +468,7 @@ static HRESULT WINAPI HTMLStyle_get_background(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrBackground, p);
return get_style_attr(This, STYLEID_BACKGROUND, p);
}
static HRESULT WINAPI HTMLStyle_put_backgroundColor(IHTMLStyle *iface, VARIANT v)
......@@ -459,13 +479,13 @@ static HRESULT WINAPI HTMLStyle_put_backgroundColor(IHTMLStyle *iface, VARIANT v
switch(V_VT(&v)) {
case VT_BSTR:
return set_style_attr(This, attrBackgroundColor, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_BACKGROUND_COLOR, V_BSTR(&v), 0);
case VT_I4: {
WCHAR value[10];
static const WCHAR format[] = {'#','%','0','6','x',0};
wsprintfW(value, format, V_I4(&v));
return set_style_attr(This, attrBackgroundColor, value, 0);
return set_style_attr(This, STYLEID_BACKGROUND_COLOR, value, 0);
}
default:
FIXME("unsupported vt %d\n", V_VT(&v));
......@@ -487,7 +507,7 @@ static HRESULT WINAPI HTMLStyle_put_backgroundImage(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrBackgroundImage, v, ATTR_FIX_URL);
return set_style_attr(This, STYLEID_BACKGROUND_IMAGE, v, ATTR_FIX_URL);
}
static HRESULT WINAPI HTMLStyle_get_backgroundImage(IHTMLStyle *iface, BSTR *p)
......@@ -608,7 +628,7 @@ static HRESULT WINAPI HTMLStyle_get_textDecoration(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrTextDecoration, p);
return get_style_attr(This, STYLEID_TEXT_DECORATION, p);
}
static HRESULT WINAPI HTMLStyle_put_textDecorationNone(IHTMLStyle *iface, VARIANT_BOOL v)
......@@ -638,7 +658,7 @@ static HRESULT WINAPI HTMLStyle_get_textDecorationUnderline(IHTMLStyle *iface, V
TRACE("(%p)->(%p)\n", This, p);
return check_style_attr_value(This, attrTextDecoration, valUnderline, p);
return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valUnderline, p);
}
static HRESULT WINAPI HTMLStyle_put_textDecorationOverline(IHTMLStyle *iface, VARIANT_BOOL v)
......@@ -668,7 +688,7 @@ static HRESULT WINAPI HTMLStyle_get_textDecorationLineThrough(IHTMLStyle *iface,
TRACE("(%p)->(%p)\n", This, p);
return check_style_attr_value(This, attrTextDecoration, valLineThrough, p);
return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valLineThrough, p);
}
static HRESULT WINAPI HTMLStyle_put_textDecorationBlink(IHTMLStyle *iface, VARIANT_BOOL v)
......@@ -777,15 +797,15 @@ static HRESULT WINAPI HTMLStyle_put_marginRight(IHTMLStyle *iface, VARIANT v)
switch(V_VT(&v)) {
case VT_NULL:
return set_style_attr(This, attrMarginRight, emptyW, 0);
return set_style_attr(This, STYLEID_MARGIN_RIGHT, emptyW, 0);
case VT_I4: {
WCHAR buf[14];
wsprintfW(buf, px_formatW, V_I4(&v));
return set_style_attr(This, attrMarginRight, buf, 0);
return set_style_attr(This, STYLEID_MARGIN_RIGHT, buf, 0);
}
case VT_BSTR:
return set_style_attr(This, attrMarginRight, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_MARGIN_RIGHT, V_BSTR(&v), 0);
default:
FIXME("Unsupported vt=%d\n", V_VT(&v));
}
......@@ -821,18 +841,18 @@ static HRESULT WINAPI HTMLStyle_put_marginLeft(IHTMLStyle *iface, VARIANT v)
switch(V_VT(&v)) {
case VT_NULL:
TRACE("(%p)->(NULL)\n", This);
return set_style_attr(This, attrMarginLeft, emptyW, 0);
return set_style_attr(This, STYLEID_MARGIN_LEFT, emptyW, 0);
case VT_I4: {
WCHAR buf[14];
TRACE("(%p)->(%d)\n", This, V_I4(&v));
wsprintfW(buf, px_formatW, V_I4(&v));
return set_style_attr(This, attrMarginLeft, buf, 0);
return set_style_attr(This, STYLEID_MARGIN_LEFT, buf, 0);
}
case VT_BSTR:
TRACE("(%p)->(%s)\n", This, debugstr_w(V_BSTR(&v)));
return set_style_attr(This, attrMarginLeft, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_MARGIN_LEFT, V_BSTR(&v), 0);
default:
FIXME("Unsupported vt=%d\n", V_VT(&v));
}
......@@ -846,7 +866,7 @@ static HRESULT WINAPI HTMLStyle_put_margin(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrMargin, v, 0);
return set_style_attr(This, STYLEID_MARGIN, v, 0);
}
static HRESULT WINAPI HTMLStyle_get_margin(IHTMLStyle *iface, BSTR *p)
......@@ -855,7 +875,7 @@ static HRESULT WINAPI HTMLStyle_get_margin(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrMargin, p);
return get_style_attr(This, STYLEID_MARGIN, p);
}
static HRESULT WINAPI HTMLStyle_get_marginLeft(IHTMLStyle *iface, VARIANT *p)
......@@ -918,10 +938,10 @@ static HRESULT WINAPI HTMLStyle_put_paddingLeft(IHTMLStyle *iface, VARIANT v)
WCHAR buf[14];
wsprintfW(buf, px_formatW, V_I4(&v));
return set_style_attr(This, attrPaddingLeft, buf, 0);
return set_style_attr(This, STYLEID_PADDING_LEFT, buf, 0);
}
case VT_BSTR:
return set_style_attr(This, attrPaddingLeft, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_PADDING_LEFT, V_BSTR(&v), 0);
default:
FIXME("unsupported vt=%d\n", V_VT(&v));
}
......@@ -1012,7 +1032,7 @@ static HRESULT WINAPI HTMLStyle_put_borderLeft(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrBorderLeft, v, ATTR_FIX_PX);
return set_style_attr(This, STYLEID_BORDER_LEFT, v, ATTR_FIX_PX);
}
static HRESULT WINAPI HTMLStyle_get_borderLeft(IHTMLStyle *iface, BSTR *p)
......@@ -1241,7 +1261,7 @@ static HRESULT WINAPI HTMLStyle_put_width(IHTMLStyle *iface, VARIANT v)
switch(V_VT(&v)) {
case VT_BSTR:
TRACE("%s\n", debugstr_w(V_BSTR(&v)));
return set_style_attr(This, attrWidth, V_BSTR(&v), 0);
return set_style_attr(This, STYLEID_WIDTH, V_BSTR(&v), 0);
default:
FIXME("unsupported vt %d\n", V_VT(&v));
}
......@@ -1256,7 +1276,7 @@ static HRESULT WINAPI HTMLStyle_get_width(IHTMLStyle *iface, VARIANT *p)
TRACE("(%p)->(%p)\n", This, p);
V_VT(p) = VT_BSTR;
return get_style_attr(This, attrWidth, &V_BSTR(p));
return get_style_attr(This, STYLEID_WIDTH, &V_BSTR(p));
}
static HRESULT WINAPI HTMLStyle_put_height(IHTMLStyle *iface, VARIANT v)
......@@ -1307,7 +1327,7 @@ static HRESULT WINAPI HTMLStyle_put_display(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrDisplay, v, 0);
return set_style_attr(This, STYLEID_DISPLAY, v, 0);
}
static HRESULT WINAPI HTMLStyle_get_display(IHTMLStyle *iface, BSTR *p)
......@@ -1316,7 +1336,7 @@ static HRESULT WINAPI HTMLStyle_get_display(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrDisplay, p);
return get_style_attr(This, STYLEID_DISPLAY, p);
}
static HRESULT WINAPI HTMLStyle_put_visibility(IHTMLStyle *iface, BSTR v)
......@@ -1325,7 +1345,7 @@ static HRESULT WINAPI HTMLStyle_put_visibility(IHTMLStyle *iface, BSTR v)
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
return set_style_attr(This, attrVisibility, v, 0);
return set_style_attr(This, STYLEID_VISIBILITY, v, 0);
}
static HRESULT WINAPI HTMLStyle_get_visibility(IHTMLStyle *iface, BSTR *p)
......@@ -1334,7 +1354,7 @@ static HRESULT WINAPI HTMLStyle_get_visibility(IHTMLStyle *iface, BSTR *p)
TRACE("(%p)->(%p)\n", This, p);
return get_style_attr(This, attrVisibility, p);
return get_style_attr(This, STYLEID_VISIBILITY, p);
}
static HRESULT WINAPI HTMLStyle_put_listStyleType(IHTMLStyle *iface, BSTR v)
......
......@@ -29,4 +29,25 @@ typedef struct {
#define HTMLSTYLE(x) ((IHTMLStyle*) &(x)->lpHTMLStyleVtbl)
#define HTMLSTYLE2(x) ((IHTMLStyle2*) &(x)->lpHTMLStyle2Vtbl)
/* NOTE: Make sure to keep in sync with stryle_strings in htmlstrle.c */
typedef enum {
STYLEID_BACKGROUND,
STYLEID_BACKGROUND_COLOR,
STYLEID_BACKGROUND_IMAGE,
STYLEID_BORDER_LEFT,
STYLEID_COLOR,
STYLEID_DISPLAY,
STYLEID_FONT_FAMILY,
STYLEID_FONT_SIZE,
STYLEID_FONT_STYLE,
STYLEID_FONT_WEIGHT,
STYLEID_MARGIN,
STYLEID_MARGIN_LEFT,
STYLEID_MARGIN_RIGHT,
STYLEID_PADDING_LEFT,
STYLEID_TEXT_DECORATION,
STYLEID_VISIBILITY,
STYLEID_WIDTH
} styleid_t;
void HTMLStyle2_Init(HTMLStyle*);
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