mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmlstyle.c
1 /*
2  * Copyright 2006 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20 #include <assert.h>
21 #include <math.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "mshtmdid.h"
30
31 #include "mshtml_private.h"
32 #include "htmlstyle.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37
38 static const WCHAR attrBackground[] =
39     {'b','a','c','k','g','r','o','u','n','d',0};
40 static const WCHAR attrBackgroundColor[] =
41     {'b','a','c','k','g','r','o','u','n','d','-','c','o','l','o','r',0};
42 static const WCHAR attrBackgroundImage[] =
43     {'b','a','c','k','g','r','o','u','n','d','-','i','m','a','g','e',0};
44 static const WCHAR attrBackgroundPosition[] =
45     {'b','a','c','k','g','r','o','u','n','d','-','p','o','s','i','t','i','o','n',0};
46 static const WCHAR attrBackgroundPositionX[] =
47     {'b','a','c','k','g','r','o','u','n','d','-','p','o','s','i','t','i','o','n','-','x',0};
48 static const WCHAR attrBackgroundPositionY[] =
49     {'b','a','c','k','g','r','o','u','n','d','-','p','o','s','i','t','i','o','n','-','y',0};
50 static const WCHAR attrBackgroundRepeat[] =
51     {'b','a','c','k','g','r','o','u','n','d','-','r','e','p','e','a','t',0};
52 static const WCHAR attrBorder[] =
53     {'b','o','r','d','e','r',0};
54 static const WCHAR attrBorderBottom[] =
55     {'b','o','r','d','e','r','-','b','o','t','t','o','m',0};
56 static const WCHAR attrBorderBottomColor[] =
57     {'b','o','r','d','e','r','-','b','o','t','t','o','m','-','c','o','l','o','r',0};
58 static const WCHAR attrBorderBottomStyle[] =
59     {'b','o','r','d','e','r','-','b','o','t','t','o','m','-','s','t','y','l','e',0};
60 static const WCHAR attrBorderBottomWidth[] =
61     {'b','o','r','d','e','r','-','b','o','t','t','o','m','-','w','i','d','t','h',0};
62 static const WCHAR attrBorderColor[] =
63     {'b','o','r','d','e','r','-','c','o','l','o','r',0};
64 static const WCHAR attrBorderLeft[] =
65     {'b','o','r','d','e','r','-','l','e','f','t',0};
66 static const WCHAR attrBorderLeftColor[] =
67     {'b','o','r','d','e','r','-','l','e','f','t','-','c','o','l','o','r',0};
68 static const WCHAR attrBorderLeftStyle[] =
69     {'b','o','r','d','e','r','-','l','e','f','t','-','s','t','y','l','e',0};
70 static const WCHAR attrBorderLeftWidth[] =
71     {'b','o','r','d','e','r','-','l','e','f','t','-','w','i','d','t','h',0};
72 static const WCHAR attrBorderRight[] =
73     {'b','o','r','d','e','r','-','r','i','g','h','t',0};
74 static const WCHAR attrBorderRightColor[] =
75     {'b','o','r','d','e','r','-','r','i','g','h','t','-','c','o','l','o','r',0};
76 static const WCHAR attrBorderRightStyle[] =
77     {'b','o','r','d','e','r','-','r','i','g','h','t','-','s','t','y','l','e',0};
78 static const WCHAR attrBorderRightWidth[] =
79     {'b','o','r','d','e','r','-','r','i','g','h','t','-','w','i','d','t','h',0};
80 static const WCHAR attrBorderTop[] =
81     {'b','o','r','d','e','r','-','t','o','p',0};
82 static const WCHAR attrBorderTopColor[] =
83     {'b','o','r','d','e','r','-','t','o','p','-','c','o','l','o','r',0};
84 static const WCHAR attrBorderStyle[] =
85     {'b','o','r','d','e','r','-','s','t','y','l','e',0};
86 static const WCHAR attrBorderTopStyle[] =
87     {'b','o','r','d','e','r','-','t','o','p','-','s','t','y','l','e',0};
88 static const WCHAR attrBorderTopWidth[] =
89     {'b','o','r','d','e','r','-','t','o','p','-','w','i','d','t','h',0};
90 static const WCHAR attrBorderWidth[] =
91     {'b','o','r','d','e','r','-','w','i','d','t','h',0};
92 static const WCHAR attrBottom[] =
93     {'b','o','t','t','o','m',0};
94 static const WCHAR attrClip[] =
95     {'c','l','i','p',0};
96 static const WCHAR attrColor[] =
97     {'c','o','l','o','r',0};
98 static const WCHAR attrCursor[] =
99     {'c','u','r','s','o','r',0};
100 static const WCHAR attrDirection[] =
101     {'d','i','r','e','c','t','i','o','n',0};
102 static const WCHAR attrDisplay[] =
103     {'d','i','s','p','l','a','y',0};
104 static const WCHAR attrFilter[] =
105     {'f','i','l','e','t','e','r',0};
106 static const WCHAR attrFontFamily[] =
107     {'f','o','n','t','-','f','a','m','i','l','y',0};
108 static const WCHAR attrFontSize[] =
109     {'f','o','n','t','-','s','i','z','e',0};
110 static const WCHAR attrFontStyle[] =
111     {'f','o','n','t','-','s','t','y','l','e',0};
112 static const WCHAR attrFontVariant[] =
113     {'f','o','n','t','-','v','a','r','i','a','n','t',0};
114 static const WCHAR attrFontWeight[] =
115     {'f','o','n','t','-','w','e','i','g','h','t',0};
116 static const WCHAR attrHeight[] =
117     {'h','e','i','g','h','t',0};
118 static const WCHAR attrLeft[] =
119     {'l','e','f','t',0};
120 static const WCHAR attrLetterSpacing[] =
121     {'l','e','t','t','e','r','-','s','p','a','c','i','n','g',0};
122 static const WCHAR attrLineHeight[] =
123     {'l','i','n','e','-','h','e','i','g','h','t',0};
124 static const WCHAR attrMargin[] =
125     {'m','a','r','g','i','n',0};
126 static const WCHAR attrMarginBottom[] =
127     {'m','a','r','g','i','n','-','b','o','t','t','o','m',0};
128 static const WCHAR attrMarginLeft[] =
129     {'m','a','r','g','i','n','-','l','e','f','t',0};
130 static const WCHAR attrMarginRight[] =
131     {'m','a','r','g','i','n','-','r','i','g','h','t',0};
132 static const WCHAR attrMarginTop[] =
133     {'m','a','r','g','i','n','-','t','o','p',0};
134 static const WCHAR attrMinHeight[] =
135     {'m','i','n','-','h','e','i','g','h','t',0};
136 static const WCHAR attrOverflow[] =
137     {'o','v','e','r','f','l','o','w',0};
138 static const WCHAR attrOverflowX[] =
139     {'o','v','e','r','f','l','o','w','-','x',0};
140 static const WCHAR attrOverflowY[] =
141     {'o','v','e','r','f','l','o','w','-','y',0};
142 static const WCHAR attrPadding[] =
143     {'p','a','d','d','i','n','g',0};
144 static const WCHAR attrPaddingBottom[] =
145     {'p','a','d','d','i','n','g','-','b','o','t','t','o','m',0};
146 static const WCHAR attrPaddingLeft[] =
147     {'p','a','d','d','i','n','g','-','l','e','f','t',0};
148 static const WCHAR attrPaddingRight[] =
149     {'p','a','d','d','i','n','g','-','r','i','g','h','t',0};
150 static const WCHAR attrPaddingTop[] =
151     {'p','a','d','d','i','n','g','-','t','o','p',0};
152 static const WCHAR attrPageBreakAfter[] =
153     {'p','a','g','e','-','b','r','e','a','k','-','a','f','t','e','r',0};
154 static const WCHAR attrPageBreakBefore[] =
155     {'p','a','g','e','-','b','r','e','a','k','-','b','e','f','o','r','e',0};
156 static const WCHAR attrPosition[] =
157     {'p','o','s','i','t','i','o','n',0};
158 static const WCHAR attrRight[] =
159     {'r','i','g','h','t',0};
160 static const WCHAR attrTextAlign[] =
161     {'t','e','x','t','-','a','l','i','g','n',0};
162 static const WCHAR attrTextDecoration[] =
163     {'t','e','x','t','-','d','e','c','o','r','a','t','i','o','n',0};
164 static const WCHAR attrTextIndent[] =
165     {'t','e','x','t','-','i','n','d','e','n','t',0};
166 static const WCHAR attrTop[] =
167     {'t','o','p',0};
168 static const WCHAR attrVerticalAlign[] =
169     {'v','e','r','t','i','c','a','l','-','a','l','i','g','n',0};
170 static const WCHAR attrVisibility[] =
171     {'v','i','s','i','b','i','l','i','t','y',0};
172 static const WCHAR attrWidth[] =
173     {'w','i','d','t','h',0};
174 static const WCHAR attrWordSpacing[] =
175     {'w','o','r','d','-','s','p','a','c','i','n','g',0};
176 static const WCHAR attrWordWrap[] =
177     {'w','o','r','d','-','w','r','a','p',0};
178 static const WCHAR attrZIndex[] =
179     {'z','-','i','n','d','e','x',0};
180
181 typedef struct {
182     const WCHAR *name;
183     DISPID dispid;
184 } style_tbl_entry_t;
185
186 static const style_tbl_entry_t style_tbl[] = {
187     {attrBackground,           DISPID_IHTMLSTYLE_BACKGROUND},
188     {attrBackgroundColor,      DISPID_IHTMLSTYLE_BACKGROUNDCOLOR},
189     {attrBackgroundImage,      DISPID_IHTMLSTYLE_BACKGROUNDIMAGE},
190     {attrBackgroundPosition,   DISPID_IHTMLSTYLE_BACKGROUNDPOSITION},
191     {attrBackgroundPositionX,  DISPID_IHTMLSTYLE_BACKGROUNDPOSITIONX},
192     {attrBackgroundPositionY,  DISPID_IHTMLSTYLE_BACKGROUNDPOSITIONY},
193     {attrBackgroundRepeat,     DISPID_IHTMLSTYLE_BACKGROUNDREPEAT},
194     {attrBorder,               DISPID_IHTMLSTYLE_BORDER},
195     {attrBorderBottom,         DISPID_IHTMLSTYLE_BORDERBOTTOM},
196     {attrBorderBottomColor,    DISPID_IHTMLSTYLE_BORDERBOTTOMCOLOR},
197     {attrBorderBottomStyle,    DISPID_IHTMLSTYLE_BORDERBOTTOMSTYLE},
198     {attrBorderBottomWidth,    DISPID_IHTMLSTYLE_BORDERBOTTOMWIDTH},
199     {attrBorderColor,          DISPID_IHTMLSTYLE_BORDERCOLOR},
200     {attrBorderLeft,           DISPID_IHTMLSTYLE_BORDERLEFT},
201     {attrBorderLeftColor,      DISPID_IHTMLSTYLE_BORDERLEFTCOLOR},
202     {attrBorderLeftStyle,      DISPID_IHTMLSTYLE_BORDERLEFTSTYLE},
203     {attrBorderLeftWidth,      DISPID_IHTMLSTYLE_BORDERLEFTWIDTH},
204     {attrBorderRight,          DISPID_IHTMLSTYLE_BORDERRIGHT},
205     {attrBorderRightColor,     DISPID_IHTMLSTYLE_BORDERRIGHTCOLOR},
206     {attrBorderRightStyle,     DISPID_IHTMLSTYLE_BORDERRIGHTSTYLE},
207     {attrBorderRightWidth,     DISPID_IHTMLSTYLE_BORDERRIGHTWIDTH},
208     {attrBorderStyle,          DISPID_IHTMLSTYLE_BORDERSTYLE},
209     {attrBorderTop,            DISPID_IHTMLSTYLE_BORDERTOP},
210     {attrBorderTopColor,       DISPID_IHTMLSTYLE_BORDERTOPCOLOR},
211     {attrBorderTopStyle,       DISPID_IHTMLSTYLE_BORDERTOPSTYLE},
212     {attrBorderTopWidth,       DISPID_IHTMLSTYLE_BORDERTOPWIDTH},
213     {attrBorderWidth,          DISPID_IHTMLSTYLE_BORDERWIDTH},
214     {attrBottom,               DISPID_IHTMLSTYLE2_BOTTOM},
215     {attrClip,                 DISPID_IHTMLSTYLE_CLIP},
216     {attrColor,                DISPID_IHTMLSTYLE_COLOR},
217     {attrCursor,               DISPID_IHTMLSTYLE_CURSOR},
218     {attrDirection,            DISPID_IHTMLSTYLE2_DIRECTION},
219     {attrDisplay,              DISPID_IHTMLSTYLE_DISPLAY},
220     {attrFilter,               DISPID_IHTMLSTYLE_FILTER},
221     {attrFontFamily,           DISPID_IHTMLSTYLE_FONTFAMILY},
222     {attrFontSize,             DISPID_IHTMLSTYLE_FONTSIZE},
223     {attrFontStyle,            DISPID_IHTMLSTYLE_FONTSTYLE},
224     {attrFontVariant,          DISPID_IHTMLSTYLE_FONTVARIANT},
225     {attrFontWeight,           DISPID_IHTMLSTYLE_FONTWEIGHT},
226     {attrHeight,               DISPID_IHTMLSTYLE_HEIGHT},
227     {attrLeft,                 DISPID_IHTMLSTYLE_LEFT},
228     {attrLetterSpacing,        DISPID_IHTMLSTYLE_LETTERSPACING},
229     {attrLineHeight,           DISPID_IHTMLSTYLE_LINEHEIGHT},
230     {attrMargin,               DISPID_IHTMLSTYLE_MARGIN},
231     {attrMarginBottom,         DISPID_IHTMLSTYLE_MARGINBOTTOM},
232     {attrMarginLeft,           DISPID_IHTMLSTYLE_MARGINLEFT},
233     {attrMarginRight,          DISPID_IHTMLSTYLE_MARGINRIGHT},
234     {attrMarginTop,            DISPID_IHTMLSTYLE_MARGINTOP},
235     {attrMinHeight,            DISPID_IHTMLSTYLE4_MINHEIGHT},
236     {attrOverflow,             DISPID_IHTMLSTYLE_OVERFLOW},
237     {attrOverflowX,            DISPID_IHTMLSTYLE2_OVERFLOWX},
238     {attrOverflowY,            DISPID_IHTMLSTYLE2_OVERFLOWY},
239     {attrPadding,              DISPID_IHTMLSTYLE_PADDING},
240     {attrPaddingBottom,        DISPID_IHTMLSTYLE_PADDINGBOTTOM},
241     {attrPaddingLeft,          DISPID_IHTMLSTYLE_PADDINGLEFT},
242     {attrPaddingRight,         DISPID_IHTMLSTYLE_PADDINGRIGHT},
243     {attrPaddingTop,           DISPID_IHTMLSTYLE_PADDINGTOP},
244     {attrPageBreakAfter,       DISPID_IHTMLSTYLE_PAGEBREAKAFTER},
245     {attrPageBreakBefore,      DISPID_IHTMLSTYLE_PAGEBREAKBEFORE},
246     {attrPosition,             DISPID_IHTMLSTYLE2_POSITION},
247     {attrRight,                DISPID_IHTMLSTYLE2_RIGHT},
248     {attrTextAlign,            DISPID_IHTMLSTYLE_TEXTALIGN},
249     {attrTextDecoration,       DISPID_IHTMLSTYLE_TEXTDECORATION},
250     {attrTextIndent,           DISPID_IHTMLSTYLE_TEXTINDENT},
251     {attrTop,                  DISPID_IHTMLSTYLE_TOP},
252     {attrVerticalAlign,        DISPID_IHTMLSTYLE_VERTICALALIGN},
253     {attrVisibility,           DISPID_IHTMLSTYLE_VISIBILITY},
254     {attrWidth,                DISPID_IHTMLSTYLE_WIDTH},
255     {attrWordSpacing,          DISPID_IHTMLSTYLE_WORDSPACING},
256     {attrWordWrap,             DISPID_IHTMLSTYLE3_WORDWRAP},
257     {attrZIndex,               DISPID_IHTMLSTYLE_ZINDEX}
258 };
259
260 static const WCHAR valLineThrough[] =
261     {'l','i','n','e','-','t','h','r','o','u','g','h',0};
262 static const WCHAR valUnderline[] =
263     {'u','n','d','e','r','l','i','n','e',0};
264 static const WCHAR szNormal[] =
265     {'n','o','r','m','a','l',0};
266 static const WCHAR styleNone[] =
267     {'n','o','n','e',0};
268 static const WCHAR valOverline[] =
269     {'o','v','e','r','l','i','n','e',0};
270 static const WCHAR valBlink[] =
271     {'b','l','i','n','k',0};
272
273 static const WCHAR px_formatW[] = {'%','d','p','x',0};
274 static const WCHAR emptyW[] = {0};
275
276 static const style_tbl_entry_t *lookup_style_tbl(const WCHAR *name)
277 {
278     int c, i, min = 0, max = sizeof(style_tbl)/sizeof(*style_tbl)-1;
279
280     while(min <= max) {
281         i = (min+max)/2;
282
283         c = strcmpW(style_tbl[i].name, name);
284         if(!c)
285             return style_tbl+i;
286
287         if(c > 0)
288             max = i-1;
289         else
290             min = i+1;
291     }
292
293     return NULL;
294 }
295
296 static LPWSTR fix_px_value(LPCWSTR val)
297 {
298     LPCWSTR ptr = val;
299
300     while(*ptr) {
301         while(*ptr && isspaceW(*ptr))
302             ptr++;
303         if(!*ptr)
304             break;
305
306         while(*ptr && isdigitW(*ptr))
307             ptr++;
308
309         if(!*ptr || isspaceW(*ptr)) {
310             LPWSTR ret, p;
311             int len = strlenW(val)+1;
312
313             ret = heap_alloc((len+2)*sizeof(WCHAR));
314             memcpy(ret, val, (ptr-val)*sizeof(WCHAR));
315             p = ret + (ptr-val);
316             *p++ = 'p';
317             *p++ = 'x';
318             strcpyW(p, ptr);
319
320             TRACE("fixed %s -> %s\n", debugstr_w(val), debugstr_w(ret));
321
322             return ret;
323         }
324
325         while(*ptr && !isspaceW(*ptr))
326             ptr++;
327     }
328
329     return NULL;
330 }
331
332 static LPWSTR fix_url_value(LPCWSTR val)
333 {
334     WCHAR *ret, *ptr;
335
336     static const WCHAR urlW[] = {'u','r','l','('};
337
338     if(strncmpW(val, urlW, sizeof(urlW)/sizeof(WCHAR)) || !strchrW(val, '\\'))
339         return NULL;
340
341     ret = heap_strdupW(val);
342
343     for(ptr = ret; *ptr; ptr++) {
344         if(*ptr == '\\')
345             *ptr = '/';
346     }
347
348     return ret;
349 }
350
351 HRESULT set_nsstyle_attr(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, LPCWSTR value, DWORD flags)
352 {
353     nsAString str_name, str_value, str_empty;
354     LPWSTR val = NULL;
355     nsresult nsres;
356
357     if(flags & ATTR_FIX_PX)
358         val = fix_px_value(value);
359     if(flags & ATTR_FIX_URL)
360         val = fix_url_value(value);
361
362     nsAString_InitDepend(&str_name, style_tbl[sid].name);
363     nsAString_InitDepend(&str_value, val ? val : value);
364     nsAString_InitDepend(&str_empty, emptyW);
365
366     nsres = nsIDOMCSSStyleDeclaration_SetProperty(nsstyle, &str_name, &str_value, &str_empty);
367     if(NS_FAILED(nsres))
368         ERR("SetProperty failed: %08x\n", nsres);
369
370     nsAString_Finish(&str_name);
371     nsAString_Finish(&str_value);
372     nsAString_Finish(&str_empty);
373     heap_free(val);
374
375     return S_OK;
376 }
377
378 static HRESULT var_to_styleval(const VARIANT *v, WCHAR *buf, DWORD flags, const WCHAR **ret)
379 {
380     switch(V_VT(v)) {
381     case VT_NULL:
382         *ret = emptyW;
383         return S_OK;
384
385     case VT_BSTR:
386         *ret = V_BSTR(v);
387         return S_OK;
388
389     case VT_BSTR|VT_BYREF:
390         *ret = *V_BSTRREF(v);
391         return S_OK;
392
393     case VT_I4: {
394         static const WCHAR formatW[] = {'%','d',0};
395         static const WCHAR hex_formatW[] = {'#','%','0','6','x',0};
396
397         if(flags & ATTR_HEX_INT)
398             wsprintfW(buf, hex_formatW, V_I4(v));
399         else if(flags & ATTR_FIX_PX)
400             wsprintfW(buf, px_formatW, V_I4(v));
401         else
402             wsprintfW(buf, formatW, V_I4(v));
403
404         *ret = buf;
405         return S_OK;
406     }
407     default:
408         FIXME("not implemented for %s\n", debugstr_variant(v));
409         return E_NOTIMPL;
410
411     }
412 }
413
414 HRESULT set_nsstyle_attr_var(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, VARIANT *value, DWORD flags)
415 {
416     const WCHAR *val;
417     WCHAR buf[14];
418     HRESULT hres;
419
420     hres = var_to_styleval(value, buf, flags, &val);
421     if(FAILED(hres))
422         return hres;
423
424     return set_nsstyle_attr(nsstyle, sid, val, flags);
425 }
426
427 static inline HRESULT set_style_attr(HTMLStyle *This, styleid_t sid, LPCWSTR value, DWORD flags)
428 {
429     return set_nsstyle_attr(This->nsstyle, sid, value, flags);
430 }
431
432 static HRESULT get_nsstyle_attr_nsval(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, nsAString *value)
433 {
434     nsAString str_name;
435     nsresult nsres;
436
437     nsAString_InitDepend(&str_name, style_tbl[sid].name);
438
439     nsres = nsIDOMCSSStyleDeclaration_GetPropertyValue(nsstyle, &str_name, value);
440     if(NS_FAILED(nsres)) {
441         ERR("SetProperty failed: %08x\n", nsres);
442         return E_FAIL;
443     }
444
445     nsAString_Finish(&str_name);
446
447     return NS_OK;
448 }
449
450 static HRESULT nsstyle_to_bstr(const WCHAR *val, DWORD flags, BSTR *p)
451 {
452     BSTR ret;
453     DWORD len;
454
455     if(!*val) {
456         *p = NULL;
457         return S_OK;
458     }
459
460     ret = SysAllocString(val);
461     if(!ret)
462         return E_OUTOFMEMORY;
463
464     len = SysStringLen(ret);
465
466     if(flags & ATTR_REMOVE_COMMA) {
467         DWORD new_len = len;
468         WCHAR *ptr, *ptr2;
469
470         for(ptr = ret; (ptr = strchrW(ptr, ',')); ptr++)
471             new_len--;
472
473         if(new_len != len) {
474             BSTR new_ret;
475
476             new_ret = SysAllocStringLen(NULL, new_len);
477             if(!new_ret) {
478                 SysFreeString(ret);
479                 return E_OUTOFMEMORY;
480             }
481
482             for(ptr2 = new_ret, ptr = ret; *ptr; ptr++) {
483                 if(*ptr != ',')
484                     *ptr2++ = *ptr;
485             }
486
487             SysFreeString(ret);
488             ret = new_ret;
489         }
490     }
491
492     *p = ret;
493     return S_OK;
494 }
495
496 HRESULT get_nsstyle_attr(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, BSTR *p, DWORD flags)
497 {
498     nsAString str_value;
499     const PRUnichar *value;
500     HRESULT hres;
501
502     nsAString_Init(&str_value, NULL);
503
504     get_nsstyle_attr_nsval(nsstyle, sid, &str_value);
505
506     nsAString_GetData(&str_value, &value);
507     hres = nsstyle_to_bstr(value, flags, p);
508     nsAString_Finish(&str_value);
509
510     TRACE("%s -> %s\n", debugstr_w(style_tbl[sid].name), debugstr_w(*p));
511     return hres;
512 }
513
514 HRESULT get_nsstyle_attr_var(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, VARIANT *p, DWORD flags)
515 {
516     nsAString str_value;
517     const PRUnichar *value;
518     BOOL set = FALSE;
519     HRESULT hres = S_OK;
520
521     nsAString_Init(&str_value, NULL);
522
523     get_nsstyle_attr_nsval(nsstyle, sid, &str_value);
524
525     nsAString_GetData(&str_value, &value);
526
527     if(flags & ATTR_STR_TO_INT) {
528         const PRUnichar *ptr = value;
529         BOOL neg = FALSE;
530         INT i = 0;
531
532         if(*ptr == '-') {
533             neg = TRUE;
534             ptr++;
535         }
536
537         while(isdigitW(*ptr))
538             i = i*10 + (*ptr++ - '0');
539
540         if(!*ptr) {
541             V_VT(p) = VT_I4;
542             V_I4(p) = neg ? -i : i;
543             set = TRUE;
544         }
545     }
546
547     if(!set) {
548         BSTR str;
549
550         hres = nsstyle_to_bstr(value, flags, &str);
551         if(SUCCEEDED(hres)) {
552             V_VT(p) = VT_BSTR;
553             V_BSTR(p) = str;
554         }
555     }
556
557     nsAString_Finish(&str_value);
558
559     TRACE("%s -> %s\n", debugstr_w(style_tbl[sid].name), debugstr_variant(p));
560     return S_OK;
561 }
562
563 static inline HRESULT get_style_attr(HTMLStyle *This, styleid_t sid, BSTR *p)
564 {
565     return get_nsstyle_attr(This->nsstyle, sid, p, 0);
566 }
567
568 static HRESULT check_style_attr_value(HTMLStyle *This, styleid_t sid, LPCWSTR exval, VARIANT_BOOL *p)
569 {
570     nsAString str_value;
571     const PRUnichar *value;
572
573     nsAString_Init(&str_value, NULL);
574
575     get_nsstyle_attr_nsval(This->nsstyle, sid, &str_value);
576
577     nsAString_GetData(&str_value, &value);
578     *p = strcmpW(value, exval) ? VARIANT_FALSE : VARIANT_TRUE;
579     nsAString_Finish(&str_value);
580
581     TRACE("%s -> %x\n", debugstr_w(style_tbl[sid].name), *p);
582     return S_OK;
583 }
584
585 static inline HRESULT set_style_pos(HTMLStyle *This, styleid_t sid, float value)
586 {
587     WCHAR szValue[25];
588     WCHAR szFormat[] = {'%','.','0','f','p','x',0};
589
590     value = floor(value);
591
592     sprintfW(szValue, szFormat, value);
593
594     return set_style_attr(This, sid, szValue, 0);
595 }
596
597 static HRESULT set_style_pxattr(nsIDOMCSSStyleDeclaration *nsstyle, styleid_t sid, LONG value)
598 {
599     WCHAR value_str[16];
600
601     sprintfW(value_str, px_formatW, value);
602
603     return set_nsstyle_attr(nsstyle, sid, value_str, 0);
604 }
605
606 static HRESULT get_nsstyle_pos(HTMLStyle *This, styleid_t sid, float *p)
607 {
608     nsAString str_value;
609     HRESULT hres;
610     WCHAR pxW[] = {'p','x',0};
611
612     TRACE("%p %d %p\n", This, sid, p);
613
614     *p = 0.0f;
615
616     nsAString_Init(&str_value, NULL);
617
618     hres = get_nsstyle_attr_nsval(This->nsstyle, sid, &str_value);
619     if(hres == S_OK)
620     {
621         WCHAR *ptr;
622         const PRUnichar *value;
623
624         nsAString_GetData(&str_value, &value);
625         if(value)
626         {
627             *p = strtolW(value, &ptr, 10);
628
629             if(*ptr && strcmpW(ptr, pxW))
630             {
631                 nsAString_Finish(&str_value);
632                 FIXME("only px values are currently supported\n");
633                 return E_FAIL;
634             }
635         }
636     }
637
638     TRACE("ret %f\n", *p);
639
640     nsAString_Finish(&str_value);
641
642     return hres;
643 }
644
645 static BOOL is_valid_border_style(BSTR v)
646 {
647     static const WCHAR styleDotted[] = {'d','o','t','t','e','d',0};
648     static const WCHAR styleDashed[] = {'d','a','s','h','e','d',0};
649     static const WCHAR styleSolid[]  = {'s','o','l','i','d',0};
650     static const WCHAR styleDouble[] = {'d','o','u','b','l','e',0};
651     static const WCHAR styleGroove[] = {'g','r','o','o','v','e',0};
652     static const WCHAR styleRidge[]  = {'r','i','d','g','e',0};
653     static const WCHAR styleInset[]  = {'i','n','s','e','t',0};
654     static const WCHAR styleOutset[] = {'o','u','t','s','e','t',0};
655
656     TRACE("%s\n", debugstr_w(v));
657
658     if(!v || strcmpiW(v, styleNone)   == 0 || strcmpiW(v, styleDotted) == 0 ||
659              strcmpiW(v, styleDashed) == 0 || strcmpiW(v, styleSolid)  == 0 ||
660              strcmpiW(v, styleDouble) == 0 || strcmpiW(v, styleGroove) == 0 ||
661              strcmpiW(v, styleRidge)  == 0 || strcmpiW(v, styleInset)  == 0 ||
662              strcmpiW(v, styleOutset) == 0 )
663     {
664         return TRUE;
665     }
666
667     return FALSE;
668 }
669
670 static inline HTMLStyle *impl_from_IHTMLStyle(IHTMLStyle *iface)
671 {
672     return CONTAINING_RECORD(iface, HTMLStyle, IHTMLStyle_iface);
673 }
674
675 static HRESULT WINAPI HTMLStyle_QueryInterface(IHTMLStyle *iface, REFIID riid, void **ppv)
676 {
677     HTMLStyle *This = impl_from_IHTMLStyle(iface);
678
679     *ppv = NULL;
680
681     if(IsEqualGUID(&IID_IUnknown, riid)) {
682         TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
683         *ppv = &This->IHTMLStyle_iface;
684     }else if(IsEqualGUID(&IID_IHTMLStyle, riid)) {
685         TRACE("(%p)->(IID_IHTMLStyle %p)\n", This, ppv);
686         *ppv = &This->IHTMLStyle_iface;
687     }else if(IsEqualGUID(&IID_IHTMLStyle2, riid)) {
688         TRACE("(%p)->(IID_IHTMLStyle2 %p)\n", This, ppv);
689         *ppv = &This->IHTMLStyle2_iface;
690     }else if(IsEqualGUID(&IID_IHTMLStyle3, riid)) {
691         TRACE("(%p)->(IID_IHTMLStyle3 %p)\n", This, ppv);
692         *ppv = &This->IHTMLStyle3_iface;
693     }else if(IsEqualGUID(&IID_IHTMLStyle4, riid)) {
694         TRACE("(%p)->(IID_IHTMLStyle4 %p)\n", This, ppv);
695         *ppv = &This->IHTMLStyle4_iface;
696     }else if(IsEqualGUID(&IID_IHTMLStyle5, riid)) {
697         TRACE("(%p)->(IID_IHTMLStyle5 %p)\n", This, ppv);
698         *ppv = &This->IHTMLStyle5_iface;
699     }else if(IsEqualGUID(&IID_IHTMLStyle6, riid)) {
700         TRACE("(%p)->(IID_IHTMLStyle6 %p)\n", This, ppv);
701         *ppv = &This->IHTMLStyle6_iface;
702     }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
703         return *ppv ? S_OK : E_NOINTERFACE;
704     }
705
706     if(*ppv) {
707         IUnknown_AddRef((IUnknown*)*ppv);
708         return S_OK;
709     }
710
711     WARN("unsupported %s\n", debugstr_guid(riid));
712     return E_NOINTERFACE;
713 }
714
715 static ULONG WINAPI HTMLStyle_AddRef(IHTMLStyle *iface)
716 {
717     HTMLStyle *This = impl_from_IHTMLStyle(iface);
718     LONG ref = InterlockedIncrement(&This->ref);
719
720     TRACE("(%p) ref=%d\n", This, ref);
721
722     return ref;
723 }
724
725 static ULONG WINAPI HTMLStyle_Release(IHTMLStyle *iface)
726 {
727     HTMLStyle *This = impl_from_IHTMLStyle(iface);
728     LONG ref = InterlockedDecrement(&This->ref);
729
730     TRACE("(%p) ref=%d\n", This, ref);
731
732     if(!ref) {
733         assert(!This->elem);
734         if(This->nsstyle)
735             nsIDOMCSSStyleDeclaration_Release(This->nsstyle);
736         release_dispex(&This->dispex);
737         heap_free(This);
738     }
739
740     return ref;
741 }
742
743 static HRESULT WINAPI HTMLStyle_GetTypeInfoCount(IHTMLStyle *iface, UINT *pctinfo)
744 {
745     HTMLStyle *This = impl_from_IHTMLStyle(iface);
746     return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
747 }
748
749 static HRESULT WINAPI HTMLStyle_GetTypeInfo(IHTMLStyle *iface, UINT iTInfo,
750                                               LCID lcid, ITypeInfo **ppTInfo)
751 {
752     HTMLStyle *This = impl_from_IHTMLStyle(iface);
753     return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
754 }
755
756 static HRESULT WINAPI HTMLStyle_GetIDsOfNames(IHTMLStyle *iface, REFIID riid,
757                                                 LPOLESTR *rgszNames, UINT cNames,
758                                                 LCID lcid, DISPID *rgDispId)
759 {
760     HTMLStyle *This = impl_from_IHTMLStyle(iface);
761     return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
762             lcid, rgDispId);
763 }
764
765 static HRESULT WINAPI HTMLStyle_Invoke(IHTMLStyle *iface, DISPID dispIdMember,
766                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
767                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
768 {
769     HTMLStyle *This = impl_from_IHTMLStyle(iface);
770     return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
771             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
772 }
773
774 static HRESULT WINAPI HTMLStyle_put_fontFamily(IHTMLStyle *iface, BSTR v)
775 {
776     HTMLStyle *This = impl_from_IHTMLStyle(iface);
777
778     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
779
780     return set_style_attr(This, STYLEID_FONT_FAMILY, v, 0);
781 }
782
783 static HRESULT WINAPI HTMLStyle_get_fontFamily(IHTMLStyle *iface, BSTR *p)
784 {
785     HTMLStyle *This = impl_from_IHTMLStyle(iface);
786
787     TRACE("(%p)->(%p)\n", This, p);
788
789     return get_style_attr(This, STYLEID_FONT_FAMILY, p);
790 }
791
792 static HRESULT WINAPI HTMLStyle_put_fontStyle(IHTMLStyle *iface, BSTR v)
793 {
794     HTMLStyle *This = impl_from_IHTMLStyle(iface);
795     static const WCHAR szItalic[]  = {'i','t','a','l','i','c',0};
796     static const WCHAR szOblique[]  = {'o','b','l','i','q','u','e',0};
797
798     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
799
800     /* fontStyle can only be one of the follow values. */
801     if(!v || strcmpiW(szNormal, v) == 0 || strcmpiW(szItalic, v) == 0 ||
802              strcmpiW(szOblique, v) == 0)
803     {
804         return set_nsstyle_attr(This->nsstyle, STYLEID_FONT_STYLE, v, 0);
805     }
806
807     return E_INVALIDARG;
808 }
809
810 static HRESULT WINAPI HTMLStyle_get_fontStyle(IHTMLStyle *iface, BSTR *p)
811 {
812     HTMLStyle *This = impl_from_IHTMLStyle(iface);
813
814     TRACE("(%p)->(%p)\n", This, p);
815
816     return get_style_attr(This, STYLEID_FONT_STYLE, p);
817 }
818
819 static HRESULT WINAPI HTMLStyle_put_fontVariant(IHTMLStyle *iface, BSTR v)
820 {
821     HTMLStyle *This = impl_from_IHTMLStyle(iface);
822     static const WCHAR szCaps[]  = {'s','m','a','l','l','-','c','a','p','s',0};
823
824     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
825
826     /* fontVariant can only be one of the follow values. */
827     if(!v || strcmpiW(szNormal, v) == 0 || strcmpiW(szCaps, v) == 0)
828     {
829         return set_nsstyle_attr(This->nsstyle, STYLEID_FONT_VARIANT, v, 0);
830     }
831
832     return E_INVALIDARG;
833 }
834
835 static HRESULT WINAPI HTMLStyle_get_fontVariant(IHTMLStyle *iface, BSTR *p)
836 {
837     HTMLStyle *This = impl_from_IHTMLStyle(iface);
838     TRACE("(%p)->(%p)\n", This, p);
839
840     if(!p)
841        return E_INVALIDARG;
842
843     return get_style_attr(This, STYLEID_FONT_VARIANT, p);
844 }
845
846 static HRESULT WINAPI HTMLStyle_put_fontWeight(IHTMLStyle *iface, BSTR v)
847 {
848     HTMLStyle *This = impl_from_IHTMLStyle(iface);
849     static const WCHAR styleBold[] = {'b','o','l','d',0};
850     static const WCHAR styleBolder[] = {'b','o','l','d','e','r',0};
851     static const WCHAR styleLighter[]  = {'l','i','g','h','t','e','r',0};
852     static const WCHAR style100[] = {'1','0','0',0};
853     static const WCHAR style200[] = {'2','0','0',0};
854     static const WCHAR style300[] = {'3','0','0',0};
855     static const WCHAR style400[] = {'4','0','0',0};
856     static const WCHAR style500[] = {'5','0','0',0};
857     static const WCHAR style600[] = {'6','0','0',0};
858     static const WCHAR style700[] = {'7','0','0',0};
859     static const WCHAR style800[] = {'8','0','0',0};
860     static const WCHAR style900[] = {'9','0','0',0};
861
862     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
863
864     /* fontWeight can only be one of the following */
865     if(!v || strcmpiW(szNormal, v) == 0    || strcmpiW(styleBold, v) == 0    ||
866              strcmpiW(styleBolder, v) == 0 || strcmpiW(styleLighter, v) == 0 ||
867              strcmpiW(style100, v) == 0    || strcmpiW(style200, v) == 0     ||
868              strcmpiW(style300, v) == 0    || strcmpiW(style400, v) == 0     ||
869              strcmpiW(style500, v) == 0    || strcmpiW(style600, v) == 0     ||
870              strcmpiW(style700, v) == 0    || strcmpiW(style800, v) == 0     ||
871              strcmpiW(style900, v) == 0
872              )
873     {
874         return set_nsstyle_attr(This->nsstyle, STYLEID_FONT_WEIGHT, v, 0);
875     }
876
877     return E_INVALIDARG;
878 }
879
880 static HRESULT WINAPI HTMLStyle_get_fontWeight(IHTMLStyle *iface, BSTR *p)
881 {
882     HTMLStyle *This = impl_from_IHTMLStyle(iface);
883
884     TRACE("(%p)->(%p)\n", This, p);
885
886     return get_style_attr(This, STYLEID_FONT_WEIGHT, p);
887 }
888
889 static HRESULT WINAPI HTMLStyle_put_fontSize(IHTMLStyle *iface, VARIANT v)
890 {
891     HTMLStyle *This = impl_from_IHTMLStyle(iface);
892
893     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
894
895     return set_nsstyle_attr_var(This->nsstyle, STYLEID_FONT_SIZE, &v, ATTR_FIX_PX);
896 }
897
898 static HRESULT WINAPI HTMLStyle_get_fontSize(IHTMLStyle *iface, VARIANT *p)
899 {
900     HTMLStyle *This = impl_from_IHTMLStyle(iface);
901
902     TRACE("(%p)->(%p)\n", This, p);
903
904     return get_nsstyle_attr_var(This->nsstyle, STYLEID_FONT_SIZE, p, 0);
905 }
906
907 static HRESULT WINAPI HTMLStyle_put_font(IHTMLStyle *iface, BSTR v)
908 {
909     HTMLStyle *This = impl_from_IHTMLStyle(iface);
910     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
911     return E_NOTIMPL;
912 }
913
914 static HRESULT WINAPI HTMLStyle_get_font(IHTMLStyle *iface, BSTR *p)
915 {
916     HTMLStyle *This = impl_from_IHTMLStyle(iface);
917     FIXME("(%p)->(%p)\n", This, p);
918     return E_NOTIMPL;
919 }
920
921 static HRESULT WINAPI HTMLStyle_put_color(IHTMLStyle *iface, VARIANT v)
922 {
923     HTMLStyle *This = impl_from_IHTMLStyle(iface);
924
925     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
926
927     return set_nsstyle_attr_var(This->nsstyle, STYLEID_COLOR, &v, ATTR_HEX_INT);
928 }
929
930 static HRESULT WINAPI HTMLStyle_get_color(IHTMLStyle *iface, VARIANT *p)
931 {
932     HTMLStyle *This = impl_from_IHTMLStyle(iface);
933
934     TRACE("(%p)->(%p)\n", This, p);
935
936     return get_nsstyle_attr_var(This->nsstyle, STYLEID_COLOR, p, 0);
937 }
938
939 static HRESULT WINAPI HTMLStyle_put_background(IHTMLStyle *iface, BSTR v)
940 {
941     HTMLStyle *This = impl_from_IHTMLStyle(iface);
942
943     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
944
945     return set_style_attr(This, STYLEID_BACKGROUND, v, 0);
946 }
947
948 static HRESULT WINAPI HTMLStyle_get_background(IHTMLStyle *iface, BSTR *p)
949 {
950     HTMLStyle *This = impl_from_IHTMLStyle(iface);
951
952     TRACE("(%p)->(%p)\n", This, p);
953
954     return get_style_attr(This, STYLEID_BACKGROUND, p);
955 }
956
957 static HRESULT WINAPI HTMLStyle_put_backgroundColor(IHTMLStyle *iface, VARIANT v)
958 {
959     HTMLStyle *This = impl_from_IHTMLStyle(iface);
960
961     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
962
963     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BACKGROUND_COLOR, &v, ATTR_HEX_INT);
964 }
965
966 static HRESULT WINAPI HTMLStyle_get_backgroundColor(IHTMLStyle *iface, VARIANT *p)
967 {
968     HTMLStyle *This = impl_from_IHTMLStyle(iface);
969
970     TRACE("(%p)->(%p)\n", This, p);
971
972     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BACKGROUND_COLOR, p, 0);
973 }
974
975 static HRESULT WINAPI HTMLStyle_put_backgroundImage(IHTMLStyle *iface, BSTR v)
976 {
977     HTMLStyle *This = impl_from_IHTMLStyle(iface);
978
979     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
980
981     return set_style_attr(This, STYLEID_BACKGROUND_IMAGE, v, ATTR_FIX_URL);
982 }
983
984 static HRESULT WINAPI HTMLStyle_get_backgroundImage(IHTMLStyle *iface, BSTR *p)
985 {
986     HTMLStyle *This = impl_from_IHTMLStyle(iface);
987
988     TRACE("(%p)->(%p)\n", This, p);
989
990     return get_style_attr(This, STYLEID_BACKGROUND_IMAGE, p);
991 }
992
993 static HRESULT WINAPI HTMLStyle_put_backgroundRepeat(IHTMLStyle *iface, BSTR v)
994 {
995     HTMLStyle *This = impl_from_IHTMLStyle(iface);
996     static const WCHAR styleRepeat[]   = {'r','e','p','e','a','t',0};
997     static const WCHAR styleNoRepeat[] = {'n','o','-','r','e','p','e','a','t',0};
998     static const WCHAR styleRepeatX[]  = {'r','e','p','e','a','t','-','x',0};
999     static const WCHAR styleRepeatY[]  = {'r','e','p','e','a','t','-','y',0};
1000
1001     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1002
1003     /* fontWeight can only be one of the following */
1004     if(!v || strcmpiW(styleRepeat, v) == 0    || strcmpiW(styleNoRepeat, v) == 0    ||
1005              strcmpiW(styleRepeatX, v) == 0 || strcmpiW(styleRepeatY, v) == 0 )
1006     {
1007         return set_style_attr(This, STYLEID_BACKGROUND_REPEAT , v, 0);
1008     }
1009
1010     return E_INVALIDARG;
1011 }
1012
1013 static HRESULT WINAPI HTMLStyle_get_backgroundRepeat(IHTMLStyle *iface, BSTR *p)
1014 {
1015     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1016
1017     TRACE("(%p)->(%p)\n", This, p);
1018
1019     return get_style_attr(This, STYLEID_BACKGROUND_REPEAT, p);
1020 }
1021
1022 static HRESULT WINAPI HTMLStyle_put_backgroundAttachment(IHTMLStyle *iface, BSTR v)
1023 {
1024     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1025     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1026     return E_NOTIMPL;
1027 }
1028
1029 static HRESULT WINAPI HTMLStyle_get_backgroundAttachment(IHTMLStyle *iface, BSTR *p)
1030 {
1031     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1032     FIXME("(%p)->(%p)\n", This, p);
1033     return E_NOTIMPL;
1034 }
1035
1036 static HRESULT WINAPI HTMLStyle_put_backgroundPosition(IHTMLStyle *iface, BSTR v)
1037 {
1038     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1039
1040     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1041
1042     return set_style_attr(This, STYLEID_BACKGROUND_POSITION, v, 0);
1043 }
1044
1045 static HRESULT WINAPI HTMLStyle_get_backgroundPosition(IHTMLStyle *iface, BSTR *p)
1046 {
1047     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1048
1049     TRACE("(%p)->(%p)\n", This, p);
1050
1051     return get_style_attr(This, STYLEID_BACKGROUND_POSITION, p);
1052 }
1053
1054 static HRESULT WINAPI HTMLStyle_put_backgroundPositionX(IHTMLStyle *iface, VARIANT v)
1055 {
1056     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1057     WCHAR buf[14], *pos_val;
1058     nsAString pos_str;
1059     const WCHAR *val;
1060     DWORD val_len;
1061     HRESULT hres;
1062
1063     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1064
1065     hres = var_to_styleval(&v, buf, ATTR_FIX_PX, &val);
1066     if(FAILED(hres))
1067         return hres;
1068
1069     val_len = val ? strlenW(val) : 0;
1070
1071     nsAString_Init(&pos_str, NULL);
1072     hres = get_nsstyle_attr_nsval(This->nsstyle, STYLEID_BACKGROUND_POSITION, &pos_str);
1073     if(SUCCEEDED(hres)) {
1074         const PRUnichar *pos, *posy;
1075         DWORD posy_len;
1076
1077         nsAString_GetData(&pos_str, &pos);
1078         posy = strchrW(pos, ' ');
1079         if(!posy) {
1080             static const WCHAR zero_pxW[] = {' ','0','p','x',0};
1081
1082             TRACE("no space in %s\n", debugstr_w(pos));
1083             posy = zero_pxW;
1084         }
1085
1086         posy_len = strlenW(posy);
1087         pos_val = heap_alloc((val_len+posy_len+1)*sizeof(WCHAR));
1088         if(pos_val) {
1089             if(val_len)
1090                 memcpy(pos_val, val, val_len*sizeof(WCHAR));
1091             if(posy_len)
1092                 memcpy(pos_val+val_len, posy, posy_len*sizeof(WCHAR));
1093             pos_val[val_len+posy_len] = 0;
1094         }else {
1095             hres = E_OUTOFMEMORY;
1096         }
1097     }
1098     nsAString_Finish(&pos_str);
1099     if(FAILED(hres))
1100         return hres;
1101
1102     TRACE("setting position to %s\n", debugstr_w(pos_val));
1103     hres = set_nsstyle_attr(This->nsstyle, STYLEID_BACKGROUND_POSITION, pos_val, ATTR_FIX_PX);
1104     heap_free(pos_val);
1105     return hres;
1106 }
1107
1108 static HRESULT WINAPI HTMLStyle_get_backgroundPositionX(IHTMLStyle *iface, VARIANT *p)
1109 {
1110     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1111     nsAString pos_str;
1112     BSTR ret;
1113     HRESULT hres;
1114
1115     TRACE("(%p)->(%p)\n", This, p);
1116
1117     nsAString_Init(&pos_str, NULL);
1118     hres = get_nsstyle_attr_nsval(This->nsstyle, STYLEID_BACKGROUND_POSITION, &pos_str);
1119     if(SUCCEEDED(hres)) {
1120         const PRUnichar *pos, *space;
1121
1122         nsAString_GetData(&pos_str, &pos);
1123         space = strchrW(pos, ' ');
1124         if(!space) {
1125             WARN("no space in %s\n", debugstr_w(pos));
1126             space = pos + strlenW(pos);
1127         }
1128
1129         if(space != pos) {
1130             ret = SysAllocStringLen(pos, space-pos);
1131             if(!ret)
1132                 hres = E_OUTOFMEMORY;
1133         }else {
1134             ret = NULL;
1135         }
1136     }
1137     nsAString_Finish(&pos_str);
1138     if(FAILED(hres))
1139         return hres;
1140
1141     TRACE("returning %s\n", debugstr_w(ret));
1142     V_VT(p) = VT_BSTR;
1143     V_BSTR(p) = ret;
1144     return S_OK;
1145 }
1146
1147 static HRESULT WINAPI HTMLStyle_put_backgroundPositionY(IHTMLStyle *iface, VARIANT v)
1148 {
1149     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1150     WCHAR buf[14], *pos_val;
1151     nsAString pos_str;
1152     const WCHAR *val;
1153     DWORD val_len;
1154     HRESULT hres;
1155
1156     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1157
1158     hres = var_to_styleval(&v, buf, ATTR_FIX_PX, &val);
1159     if(FAILED(hres))
1160         return hres;
1161
1162     val_len = val ? strlenW(val) : 0;
1163
1164     nsAString_Init(&pos_str, NULL);
1165     hres = get_nsstyle_attr_nsval(This->nsstyle, STYLEID_BACKGROUND_POSITION, &pos_str);
1166     if(SUCCEEDED(hres)) {
1167         const PRUnichar *pos, *space;
1168         DWORD posx_len;
1169
1170         nsAString_GetData(&pos_str, &pos);
1171         space = strchrW(pos, ' ');
1172         if(space) {
1173             space++;
1174         }else {
1175             static const WCHAR zero_pxW[] = {'0','p','x',' ',0};
1176
1177             TRACE("no space in %s\n", debugstr_w(pos));
1178             pos = zero_pxW;
1179             space = pos + sizeof(zero_pxW)/sizeof(WCHAR)-1;
1180         }
1181
1182         posx_len = space-pos;
1183
1184         pos_val = heap_alloc((posx_len+val_len+1)*sizeof(WCHAR));
1185         if(pos_val) {
1186             memcpy(pos_val, pos, posx_len*sizeof(WCHAR));
1187             if(val_len)
1188                 memcpy(pos_val+posx_len, val, val_len*sizeof(WCHAR));
1189             pos_val[posx_len+val_len] = 0;
1190         }else {
1191             hres = E_OUTOFMEMORY;
1192         }
1193     }
1194     nsAString_Finish(&pos_str);
1195     if(FAILED(hres))
1196         return hres;
1197
1198     TRACE("setting position to %s\n", debugstr_w(pos_val));
1199     hres = set_nsstyle_attr(This->nsstyle, STYLEID_BACKGROUND_POSITION, pos_val, ATTR_FIX_PX);
1200     heap_free(pos_val);
1201     return hres;
1202 }
1203
1204 static HRESULT WINAPI HTMLStyle_get_backgroundPositionY(IHTMLStyle *iface, VARIANT *p)
1205 {
1206     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1207     nsAString pos_str;
1208     BSTR ret;
1209     HRESULT hres;
1210
1211     TRACE("(%p)->(%p)\n", This, p);
1212
1213     nsAString_Init(&pos_str, NULL);
1214     hres = get_nsstyle_attr_nsval(This->nsstyle, STYLEID_BACKGROUND_POSITION, &pos_str);
1215     if(SUCCEEDED(hres)) {
1216         const PRUnichar *pos, *posy;
1217
1218         nsAString_GetData(&pos_str, &pos);
1219         posy = strchrW(pos, ' ');
1220         if(posy) {
1221             ret = SysAllocString(posy+1);
1222             if(!ret)
1223                 hres = E_OUTOFMEMORY;
1224         }else {
1225             ret = NULL;
1226         }
1227     }
1228     nsAString_Finish(&pos_str);
1229     if(FAILED(hres))
1230         return hres;
1231
1232     TRACE("returning %s\n", debugstr_w(ret));
1233     V_VT(p) = VT_BSTR;
1234     V_BSTR(p) = ret;
1235     return S_OK;
1236 }
1237
1238 static HRESULT WINAPI HTMLStyle_put_wordSpacing(IHTMLStyle *iface, VARIANT v)
1239 {
1240     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1241
1242     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1243
1244     return set_nsstyle_attr_var(This->nsstyle, STYLEID_WORD_SPACING, &v, 0);
1245 }
1246
1247 static HRESULT WINAPI HTMLStyle_get_wordSpacing(IHTMLStyle *iface, VARIANT *p)
1248 {
1249     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1250     TRACE("(%p)->(%p)\n", This, p);
1251     return get_nsstyle_attr_var(This->nsstyle, STYLEID_WORD_SPACING, p, 0);
1252 }
1253
1254 static HRESULT WINAPI HTMLStyle_put_letterSpacing(IHTMLStyle *iface, VARIANT v)
1255 {
1256     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1257
1258     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1259
1260     return set_nsstyle_attr_var(This->nsstyle, STYLEID_LETTER_SPACING, &v, 0);
1261 }
1262
1263 static HRESULT WINAPI HTMLStyle_get_letterSpacing(IHTMLStyle *iface, VARIANT *p)
1264 {
1265     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1266     TRACE("(%p)->(%p)\n", This, p);
1267     return get_nsstyle_attr_var(This->nsstyle, STYLEID_LETTER_SPACING, p, 0);
1268 }
1269
1270 static HRESULT WINAPI HTMLStyle_put_textDecoration(IHTMLStyle *iface, BSTR v)
1271 {
1272     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1273
1274     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1275
1276     /* textDecoration can only be one of the following */
1277     if(!v || strcmpiW(styleNone, v)   == 0 || strcmpiW(valUnderline, v)   == 0 ||
1278              strcmpiW(valOverline, v) == 0 || strcmpiW(valLineThrough, v) == 0 ||
1279              strcmpiW(valBlink, v)    == 0)
1280     {
1281         return set_style_attr(This, STYLEID_TEXT_DECORATION , v, 0);
1282     }
1283
1284     return E_INVALIDARG;
1285 }
1286
1287 static HRESULT WINAPI HTMLStyle_get_textDecoration(IHTMLStyle *iface, BSTR *p)
1288 {
1289     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1290
1291     TRACE("(%p)->(%p)\n", This, p);
1292
1293     return get_style_attr(This, STYLEID_TEXT_DECORATION, p);
1294 }
1295
1296 static HRESULT WINAPI HTMLStyle_put_textDecorationNone(IHTMLStyle *iface, VARIANT_BOOL v)
1297 {
1298     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1299
1300     TRACE("(%p)->(%x)\n", This, v);
1301
1302     return set_style_attr(This, STYLEID_TEXT_DECORATION, v ? styleNone : emptyW, 0);
1303 }
1304
1305 static HRESULT WINAPI HTMLStyle_get_textDecorationNone(IHTMLStyle *iface, VARIANT_BOOL *p)
1306 {
1307     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1308
1309     TRACE("(%p)->(%p)\n", This, p);
1310
1311     return check_style_attr_value(This, STYLEID_TEXT_DECORATION, styleNone, p);
1312 }
1313
1314 static HRESULT WINAPI HTMLStyle_put_textDecorationUnderline(IHTMLStyle *iface, VARIANT_BOOL v)
1315 {
1316     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1317
1318     TRACE("(%p)->(%x)\n", This, v);
1319
1320     return set_style_attr(This, STYLEID_TEXT_DECORATION, v ? valUnderline : emptyW, 0);
1321 }
1322
1323 static HRESULT WINAPI HTMLStyle_get_textDecorationUnderline(IHTMLStyle *iface, VARIANT_BOOL *p)
1324 {
1325     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1326
1327     TRACE("(%p)->(%p)\n", This, p);
1328
1329     return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valUnderline, p);
1330 }
1331
1332 static HRESULT WINAPI HTMLStyle_put_textDecorationOverline(IHTMLStyle *iface, VARIANT_BOOL v)
1333 {
1334     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1335
1336     TRACE("(%p)->(%x)\n", This, v);
1337
1338     return set_style_attr(This, STYLEID_TEXT_DECORATION, v ? valOverline : emptyW, 0);
1339 }
1340
1341 static HRESULT WINAPI HTMLStyle_get_textDecorationOverline(IHTMLStyle *iface, VARIANT_BOOL *p)
1342 {
1343     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1344
1345     TRACE("(%p)->(%p)\n", This, p);
1346
1347     return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valOverline, p);
1348 }
1349
1350 static HRESULT WINAPI HTMLStyle_put_textDecorationLineThrough(IHTMLStyle *iface, VARIANT_BOOL v)
1351 {
1352     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1353
1354     TRACE("(%p)->(%x)\n", This, v);
1355
1356     return set_style_attr(This, STYLEID_TEXT_DECORATION, v ? valLineThrough : emptyW, 0);
1357 }
1358
1359 static HRESULT WINAPI HTMLStyle_get_textDecorationLineThrough(IHTMLStyle *iface, VARIANT_BOOL *p)
1360 {
1361     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1362
1363     TRACE("(%p)->(%p)\n", This, p);
1364
1365     return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valLineThrough, p);
1366 }
1367
1368 static HRESULT WINAPI HTMLStyle_put_textDecorationBlink(IHTMLStyle *iface, VARIANT_BOOL v)
1369 {
1370     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1371
1372     TRACE("(%p)->(%x)\n", This, v);
1373
1374     return set_style_attr(This, STYLEID_TEXT_DECORATION, v ? valBlink : emptyW, 0);
1375 }
1376
1377 static HRESULT WINAPI HTMLStyle_get_textDecorationBlink(IHTMLStyle *iface, VARIANT_BOOL *p)
1378 {
1379     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1380
1381     TRACE("(%p)->(%p)\n", This, p);
1382
1383     return check_style_attr_value(This, STYLEID_TEXT_DECORATION, valBlink, p);
1384 }
1385
1386 static HRESULT WINAPI HTMLStyle_put_verticalAlign(IHTMLStyle *iface, VARIANT v)
1387 {
1388     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1389
1390     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1391
1392     return set_nsstyle_attr_var(This->nsstyle, STYLEID_VERTICAL_ALIGN, &v, ATTR_FIX_PX);
1393 }
1394
1395 static HRESULT WINAPI HTMLStyle_get_verticalAlign(IHTMLStyle *iface, VARIANT *p)
1396 {
1397     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1398
1399     TRACE("(%p)->(%p)\n", This, p);
1400
1401     return get_nsstyle_attr_var(This->nsstyle, STYLEID_VERTICAL_ALIGN, p, 0);
1402 }
1403
1404 static HRESULT WINAPI HTMLStyle_put_textTransform(IHTMLStyle *iface, BSTR v)
1405 {
1406     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1407     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1408     return E_NOTIMPL;
1409 }
1410
1411 static HRESULT WINAPI HTMLStyle_get_textTransform(IHTMLStyle *iface, BSTR *p)
1412 {
1413     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1414     FIXME("(%p)->(%p)\n", This, p);
1415     return E_NOTIMPL;
1416 }
1417
1418 static HRESULT WINAPI HTMLStyle_put_textAlign(IHTMLStyle *iface, BSTR v)
1419 {
1420     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1421
1422     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1423
1424     return set_style_attr(This, STYLEID_TEXT_ALIGN, v, 0);
1425 }
1426
1427 static HRESULT WINAPI HTMLStyle_get_textAlign(IHTMLStyle *iface, BSTR *p)
1428 {
1429     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1430
1431     TRACE("(%p)->(%p)\n", This, p);
1432
1433     return get_style_attr(This, STYLEID_TEXT_ALIGN, p);
1434 }
1435
1436 static HRESULT WINAPI HTMLStyle_put_textIndent(IHTMLStyle *iface, VARIANT v)
1437 {
1438     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1439     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1440     return E_NOTIMPL;
1441 }
1442
1443 static HRESULT WINAPI HTMLStyle_get_textIndent(IHTMLStyle *iface, VARIANT *p)
1444 {
1445     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1446     FIXME("(%p)->(%p)\n", This, p);
1447     return E_NOTIMPL;
1448 }
1449
1450 static HRESULT WINAPI HTMLStyle_put_lineHeight(IHTMLStyle *iface, VARIANT v)
1451 {
1452     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1453     FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1454     return E_NOTIMPL;
1455 }
1456
1457 static HRESULT WINAPI HTMLStyle_get_lineHeight(IHTMLStyle *iface, VARIANT *p)
1458 {
1459     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1460     FIXME("(%p)->(%p)\n", This, p);
1461     return E_NOTIMPL;
1462 }
1463
1464 static HRESULT WINAPI HTMLStyle_put_marginTop(IHTMLStyle *iface, VARIANT v)
1465 {
1466     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1467
1468     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1469
1470     return set_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_TOP, &v, ATTR_FIX_PX);
1471 }
1472
1473 static HRESULT WINAPI HTMLStyle_get_marginTop(IHTMLStyle *iface, VARIANT *p)
1474 {
1475     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1476
1477     TRACE("(%p)->(%p)\n", This, p);
1478
1479     return get_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_TOP, p, 0);
1480 }
1481
1482 static HRESULT WINAPI HTMLStyle_put_marginRight(IHTMLStyle *iface, VARIANT v)
1483 {
1484     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1485
1486     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1487
1488     return set_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_RIGHT, &v, ATTR_FIX_PX);
1489 }
1490
1491 static HRESULT WINAPI HTMLStyle_get_marginRight(IHTMLStyle *iface, VARIANT *p)
1492 {
1493     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1494     TRACE("(%p)->(%p)\n", This, p);
1495     return get_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_RIGHT, p, 0);
1496 }
1497
1498 static HRESULT WINAPI HTMLStyle_put_marginBottom(IHTMLStyle *iface, VARIANT v)
1499 {
1500     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1501
1502     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1503
1504     return set_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_BOTTOM, &v, ATTR_FIX_PX);
1505 }
1506
1507 static HRESULT WINAPI HTMLStyle_get_marginBottom(IHTMLStyle *iface, VARIANT *p)
1508 {
1509     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1510
1511     TRACE("(%p)->(%p)\n", This, p);
1512
1513     return get_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_BOTTOM, p, 0);
1514 }
1515
1516 static HRESULT WINAPI HTMLStyle_put_marginLeft(IHTMLStyle *iface, VARIANT v)
1517 {
1518     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1519
1520     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1521
1522     return set_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_LEFT, &v, ATTR_FIX_PX);
1523 }
1524
1525 static HRESULT WINAPI HTMLStyle_put_margin(IHTMLStyle *iface, BSTR v)
1526 {
1527     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1528
1529     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1530
1531     return set_style_attr(This, STYLEID_MARGIN, v, 0);
1532 }
1533
1534 static HRESULT WINAPI HTMLStyle_get_margin(IHTMLStyle *iface, BSTR *p)
1535 {
1536     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1537
1538     TRACE("(%p)->(%p)\n", This, p);
1539
1540     return get_style_attr(This, STYLEID_MARGIN, p);
1541 }
1542
1543 static HRESULT WINAPI HTMLStyle_get_marginLeft(IHTMLStyle *iface, VARIANT *p)
1544 {
1545     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1546     TRACE("(%p)->(%p)\n", This, p);
1547     return get_nsstyle_attr_var(This->nsstyle, STYLEID_MARGIN_LEFT, p, 0);
1548 }
1549
1550 static HRESULT WINAPI HTMLStyle_put_paddingTop(IHTMLStyle *iface, VARIANT v)
1551 {
1552     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1553
1554     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1555
1556     return set_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_TOP, &v, ATTR_FIX_PX);
1557 }
1558
1559 static HRESULT WINAPI HTMLStyle_get_paddingTop(IHTMLStyle *iface, VARIANT *p)
1560 {
1561     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1562
1563     TRACE("(%p)->(%p)\n", This, p);
1564
1565     return get_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_TOP, p, 0);
1566 }
1567
1568 static HRESULT WINAPI HTMLStyle_put_paddingRight(IHTMLStyle *iface, VARIANT v)
1569 {
1570     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1571
1572     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1573
1574     return set_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_RIGHT, &v, ATTR_FIX_PX);
1575 }
1576
1577 static HRESULT WINAPI HTMLStyle_get_paddingRight(IHTMLStyle *iface, VARIANT *p)
1578 {
1579     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1580
1581     TRACE("(%p)->(%p)\n", This, p);
1582
1583     return get_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_RIGHT, p, 0);
1584 }
1585
1586 static HRESULT WINAPI HTMLStyle_put_paddingBottom(IHTMLStyle *iface, VARIANT v)
1587 {
1588     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1589
1590     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1591
1592     return set_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_BOTTOM, &v, ATTR_FIX_PX);
1593 }
1594
1595 static HRESULT WINAPI HTMLStyle_get_paddingBottom(IHTMLStyle *iface, VARIANT *p)
1596 {
1597     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1598
1599     TRACE("(%p)->(%p)\n", This, p);
1600
1601     return get_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_BOTTOM, p, 0);
1602 }
1603
1604 static HRESULT WINAPI HTMLStyle_put_paddingLeft(IHTMLStyle *iface, VARIANT v)
1605 {
1606     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1607
1608     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1609
1610     return set_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_LEFT, &v, ATTR_FIX_PX);
1611 }
1612
1613 static HRESULT WINAPI HTMLStyle_get_paddingLeft(IHTMLStyle *iface, VARIANT *p)
1614 {
1615     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1616
1617     TRACE("(%p)->(%p)\n", This, p);
1618
1619     return get_nsstyle_attr_var(This->nsstyle, STYLEID_PADDING_LEFT, p, 0);
1620 }
1621
1622 static HRESULT WINAPI HTMLStyle_put_padding(IHTMLStyle *iface, BSTR v)
1623 {
1624     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1625
1626     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1627
1628     return set_style_attr(This, STYLEID_PADDING, v, 0);
1629 }
1630
1631 static HRESULT WINAPI HTMLStyle_get_padding(IHTMLStyle *iface, BSTR *p)
1632 {
1633     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1634
1635     TRACE("(%p)->(%p)\n", This, p);
1636
1637     return get_style_attr(This, STYLEID_PADDING, p);
1638 }
1639
1640 static HRESULT WINAPI HTMLStyle_put_border(IHTMLStyle *iface, BSTR v)
1641 {
1642     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1643
1644     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1645
1646     return set_style_attr(This, STYLEID_BORDER, v, 0);
1647 }
1648
1649 static HRESULT WINAPI HTMLStyle_get_border(IHTMLStyle *iface, BSTR *p)
1650 {
1651     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1652
1653     TRACE("(%p)->(%p)\n", This, p);
1654
1655     return get_style_attr(This, STYLEID_BORDER, p);
1656 }
1657
1658 static HRESULT WINAPI HTMLStyle_put_borderTop(IHTMLStyle *iface, BSTR v)
1659 {
1660     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1661     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1662     return set_style_attr(This, STYLEID_BORDER_TOP, v, ATTR_FIX_PX);
1663 }
1664
1665 static HRESULT WINAPI HTMLStyle_get_borderTop(IHTMLStyle *iface, BSTR *p)
1666 {
1667     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1668     TRACE("(%p)->(%p)\n", This, p);
1669     return get_style_attr(This, STYLEID_BORDER_TOP, p);
1670 }
1671
1672 static HRESULT WINAPI HTMLStyle_put_borderRight(IHTMLStyle *iface, BSTR v)
1673 {
1674     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1675     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1676     return set_style_attr(This, STYLEID_BORDER_RIGHT, v, ATTR_FIX_PX);
1677 }
1678
1679 static HRESULT WINAPI HTMLStyle_get_borderRight(IHTMLStyle *iface, BSTR *p)
1680 {
1681     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1682     TRACE("(%p)->(%p)\n", This, p);
1683     return get_style_attr(This, STYLEID_BORDER_RIGHT, p);
1684 }
1685
1686 static HRESULT WINAPI HTMLStyle_put_borderBottom(IHTMLStyle *iface, BSTR v)
1687 {
1688     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1689     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1690     return set_style_attr(This, STYLEID_BORDER_BOTTOM, v, ATTR_FIX_PX);
1691 }
1692
1693 static HRESULT WINAPI HTMLStyle_get_borderBottom(IHTMLStyle *iface, BSTR *p)
1694 {
1695     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1696     TRACE("(%p)->(%p)\n", This, p);
1697     return get_style_attr(This, STYLEID_BORDER_BOTTOM, p);
1698 }
1699
1700 static HRESULT WINAPI HTMLStyle_put_borderLeft(IHTMLStyle *iface, BSTR v)
1701 {
1702     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1703
1704     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1705
1706     return set_style_attr(This, STYLEID_BORDER_LEFT, v, ATTR_FIX_PX);
1707 }
1708
1709 static HRESULT WINAPI HTMLStyle_get_borderLeft(IHTMLStyle *iface, BSTR *p)
1710 {
1711     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1712
1713     TRACE("(%p)->(%p)\n", This, p);
1714
1715     return get_style_attr(This, STYLEID_BORDER_LEFT, p);
1716 }
1717
1718 static HRESULT WINAPI HTMLStyle_put_borderColor(IHTMLStyle *iface, BSTR v)
1719 {
1720     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1721
1722     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1723
1724     return set_style_attr(This, STYLEID_BORDER_COLOR, v, 0);
1725 }
1726
1727 static HRESULT WINAPI HTMLStyle_get_borderColor(IHTMLStyle *iface, BSTR *p)
1728 {
1729     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1730
1731     TRACE("(%p)->(%p)\n", This, p);
1732
1733     return get_style_attr(This, STYLEID_BORDER_COLOR, p);
1734 }
1735
1736 static HRESULT WINAPI HTMLStyle_put_borderTopColor(IHTMLStyle *iface, VARIANT v)
1737 {
1738     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1739
1740     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1741
1742     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_TOP_COLOR, &v, ATTR_HEX_INT);
1743 }
1744
1745 static HRESULT WINAPI HTMLStyle_get_borderTopColor(IHTMLStyle *iface, VARIANT *p)
1746 {
1747     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1748
1749     TRACE("(%p)->(%p)\n", This, p);
1750
1751     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_TOP_COLOR, p, 0);
1752 }
1753
1754 static HRESULT WINAPI HTMLStyle_put_borderRightColor(IHTMLStyle *iface, VARIANT v)
1755 {
1756     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1757
1758     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1759
1760     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_RIGHT_COLOR, &v, ATTR_HEX_INT);
1761 }
1762
1763 static HRESULT WINAPI HTMLStyle_get_borderRightColor(IHTMLStyle *iface, VARIANT *p)
1764 {
1765     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1766
1767     TRACE("(%p)->(%p)\n", This, p);
1768
1769     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_RIGHT_COLOR, p, 0);
1770 }
1771
1772 static HRESULT WINAPI HTMLStyle_put_borderBottomColor(IHTMLStyle *iface, VARIANT v)
1773 {
1774     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1775
1776     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1777
1778     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_BOTTOM_COLOR, &v, ATTR_HEX_INT);
1779 }
1780
1781 static HRESULT WINAPI HTMLStyle_get_borderBottomColor(IHTMLStyle *iface, VARIANT *p)
1782 {
1783     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1784
1785     TRACE("(%p)->(%p)\n", This, p);
1786
1787     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_BOTTOM_COLOR, p, 0);
1788 }
1789
1790 static HRESULT WINAPI HTMLStyle_put_borderLeftColor(IHTMLStyle *iface, VARIANT v)
1791 {
1792     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1793
1794     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1795
1796     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_LEFT_COLOR, &v, ATTR_HEX_INT);
1797 }
1798
1799 static HRESULT WINAPI HTMLStyle_get_borderLeftColor(IHTMLStyle *iface, VARIANT *p)
1800 {
1801     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1802
1803     TRACE("(%p)->(%p)\n", This, p);
1804
1805     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_LEFT_COLOR, p, 0);
1806 }
1807
1808 static HRESULT WINAPI HTMLStyle_put_borderWidth(IHTMLStyle *iface, BSTR v)
1809 {
1810     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1811     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1812     return set_style_attr(This, STYLEID_BORDER_WIDTH, v, ATTR_FIX_PX);
1813 }
1814
1815 static HRESULT WINAPI HTMLStyle_get_borderWidth(IHTMLStyle *iface, BSTR *p)
1816 {
1817     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1818     TRACE("(%p)->(%p)\n", This, p);
1819     return get_style_attr(This, STYLEID_BORDER_WIDTH, p);
1820 }
1821
1822 static HRESULT WINAPI HTMLStyle_put_borderTopWidth(IHTMLStyle *iface, VARIANT v)
1823 {
1824     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1825
1826     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1827
1828     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_TOP_WIDTH, &v, 0);
1829 }
1830
1831 static HRESULT WINAPI HTMLStyle_get_borderTopWidth(IHTMLStyle *iface, VARIANT *p)
1832 {
1833     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1834
1835     TRACE("(%p)->(%p)\n", This, p);
1836
1837     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_TOP_WIDTH, p, 0);
1838 }
1839
1840 static HRESULT WINAPI HTMLStyle_put_borderRightWidth(IHTMLStyle *iface, VARIANT v)
1841 {
1842     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1843
1844     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1845
1846     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_RIGHT_WIDTH, &v, 0);
1847 }
1848
1849 static HRESULT WINAPI HTMLStyle_get_borderRightWidth(IHTMLStyle *iface, VARIANT *p)
1850 {
1851     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1852
1853     TRACE("(%p)->(%p)\n", This, p);
1854
1855     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_RIGHT_WIDTH, p, 0);
1856 }
1857
1858 static HRESULT WINAPI HTMLStyle_put_borderBottomWidth(IHTMLStyle *iface, VARIANT v)
1859 {
1860     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1861
1862     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1863
1864     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_BOTTOM_WIDTH, &v, 0);
1865 }
1866
1867 static HRESULT WINAPI HTMLStyle_get_borderBottomWidth(IHTMLStyle *iface, VARIANT *p)
1868 {
1869     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1870     TRACE("(%p)->(%p)\n", This, p);
1871     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_BOTTOM_WIDTH, p, 0);
1872 }
1873
1874 static HRESULT WINAPI HTMLStyle_put_borderLeftWidth(IHTMLStyle *iface, VARIANT v)
1875 {
1876     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1877
1878     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
1879
1880     return set_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_LEFT_WIDTH, &v, 0);
1881 }
1882
1883 static HRESULT WINAPI HTMLStyle_get_borderLeftWidth(IHTMLStyle *iface, VARIANT *p)
1884 {
1885     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1886     TRACE("(%p)->(%p)\n", This, p);
1887     return get_nsstyle_attr_var(This->nsstyle, STYLEID_BORDER_LEFT_WIDTH, p, 0);
1888 }
1889
1890 static HRESULT WINAPI HTMLStyle_put_borderStyle(IHTMLStyle *iface, BSTR v)
1891 {
1892     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1893     static const WCHAR styleWindowInset[]  = {'w','i','n','d','o','w','-','i','n','s','e','t',0};
1894     HRESULT hres = S_OK;
1895     BSTR pstyle;
1896     int i=0;
1897     int last = 0;
1898
1899     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1900
1901     while(v[i] && hres == S_OK)
1902     {
1903         if(v[i] == (WCHAR)' ')
1904         {
1905             pstyle = SysAllocStringLen(&v[last], (i-last));
1906             if( !(is_valid_border_style(pstyle) || strcmpiW(styleWindowInset, pstyle) == 0))
1907             {
1908                 TRACE("1. Invalid style (%s)\n", debugstr_w(pstyle));
1909                 hres = E_INVALIDARG;
1910             }
1911             SysFreeString(pstyle);
1912             last = i+1;
1913         }
1914         i++;
1915     }
1916
1917     if(hres == S_OK)
1918     {
1919         pstyle = SysAllocStringLen(&v[last], i-last);
1920         if( !(is_valid_border_style(pstyle) || strcmpiW(styleWindowInset, pstyle) == 0))
1921         {
1922             TRACE("2. Invalid style (%s)\n", debugstr_w(pstyle));
1923             hres = E_INVALIDARG;
1924         }
1925         SysFreeString(pstyle);
1926     }
1927
1928     if(hres == S_OK)
1929         hres = set_nsstyle_attr(This->nsstyle, STYLEID_BORDER_STYLE, v, 0);
1930
1931     return hres;
1932 }
1933
1934 static HRESULT WINAPI HTMLStyle_get_borderStyle(IHTMLStyle *iface, BSTR *p)
1935 {
1936     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1937     TRACE("(%p)->(%p)\n", This, p);
1938     return get_style_attr(This, STYLEID_BORDER_STYLE, p);
1939 }
1940
1941 static HRESULT WINAPI HTMLStyle_put_borderTopStyle(IHTMLStyle *iface, BSTR v)
1942 {
1943     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1944     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1945
1946     if(!is_valid_border_style(v))
1947         return E_INVALIDARG;
1948
1949     return set_style_attr(This, STYLEID_BORDER_TOP_STYLE, v, 0);
1950 }
1951
1952 static HRESULT WINAPI HTMLStyle_get_borderTopStyle(IHTMLStyle *iface, BSTR *p)
1953 {
1954     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1955     TRACE("(%p)->(%p)\n", This, p);
1956     return get_style_attr(This, STYLEID_BORDER_TOP_STYLE, p);
1957 }
1958
1959 static HRESULT WINAPI HTMLStyle_put_borderRightStyle(IHTMLStyle *iface, BSTR v)
1960 {
1961     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1962     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1963
1964     if(!is_valid_border_style(v))
1965         return E_INVALIDARG;
1966
1967     return set_style_attr(This, STYLEID_BORDER_RIGHT_STYLE, v, 0);
1968 }
1969
1970 static HRESULT WINAPI HTMLStyle_get_borderRightStyle(IHTMLStyle *iface, BSTR *p)
1971 {
1972     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1973     TRACE("(%p)->(%p)\n", This, p);
1974     return get_style_attr(This, STYLEID_BORDER_RIGHT_STYLE, p);
1975 }
1976
1977 static HRESULT WINAPI HTMLStyle_put_borderBottomStyle(IHTMLStyle *iface, BSTR v)
1978 {
1979     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1980     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1981
1982     if(!is_valid_border_style(v))
1983         return E_INVALIDARG;
1984
1985     return set_style_attr(This, STYLEID_BORDER_BOTTOM_STYLE, v, 0);
1986 }
1987
1988 static HRESULT WINAPI HTMLStyle_get_borderBottomStyle(IHTMLStyle *iface, BSTR *p)
1989 {
1990     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1991     TRACE("(%p)->(%p)\n", This, p);
1992     return get_style_attr(This, STYLEID_BORDER_BOTTOM_STYLE, p);
1993 }
1994
1995 static HRESULT WINAPI HTMLStyle_put_borderLeftStyle(IHTMLStyle *iface, BSTR v)
1996 {
1997     HTMLStyle *This = impl_from_IHTMLStyle(iface);
1998     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1999
2000     if(!is_valid_border_style(v))
2001         return E_INVALIDARG;
2002
2003     return set_style_attr(This, STYLEID_BORDER_LEFT_STYLE, v, 0);
2004 }
2005
2006 static HRESULT WINAPI HTMLStyle_get_borderLeftStyle(IHTMLStyle *iface, BSTR *p)
2007 {
2008     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2009     TRACE("(%p)->(%p)\n", This, p);
2010     return get_style_attr(This, STYLEID_BORDER_LEFT_STYLE, p);
2011 }
2012
2013 static HRESULT WINAPI HTMLStyle_put_width(IHTMLStyle *iface, VARIANT v)
2014 {
2015     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2016
2017     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2018
2019     return set_nsstyle_attr_var(This->nsstyle, STYLEID_WIDTH, &v, ATTR_FIX_PX);
2020 }
2021
2022 static HRESULT WINAPI HTMLStyle_get_width(IHTMLStyle *iface, VARIANT *p)
2023 {
2024     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2025
2026     TRACE("(%p)->(%p)\n", This, p);
2027
2028     return get_nsstyle_attr_var(This->nsstyle, STYLEID_WIDTH, p, 0);
2029 }
2030
2031 static HRESULT WINAPI HTMLStyle_put_height(IHTMLStyle *iface, VARIANT v)
2032 {
2033     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2034
2035     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2036
2037     return set_nsstyle_attr_var(This->nsstyle, STYLEID_HEIGHT, &v, ATTR_FIX_PX);
2038 }
2039
2040 static HRESULT WINAPI HTMLStyle_get_height(IHTMLStyle *iface, VARIANT *p)
2041 {
2042     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2043
2044     TRACE("(%p)->(%p)\n", This, p);
2045
2046     return get_nsstyle_attr_var(This->nsstyle, STYLEID_HEIGHT, p, 0);
2047 }
2048
2049 static HRESULT WINAPI HTMLStyle_put_styleFloat(IHTMLStyle *iface, BSTR v)
2050 {
2051     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2052     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2053     return E_NOTIMPL;
2054 }
2055
2056 static HRESULT WINAPI HTMLStyle_get_styleFloat(IHTMLStyle *iface, BSTR *p)
2057 {
2058     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2059     FIXME("(%p)->(%p)\n", This, p);
2060     return E_NOTIMPL;
2061 }
2062
2063 static HRESULT WINAPI HTMLStyle_put_clear(IHTMLStyle *iface, BSTR v)
2064 {
2065     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2066     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2067     return E_NOTIMPL;
2068 }
2069
2070 static HRESULT WINAPI HTMLStyle_get_clear(IHTMLStyle *iface, BSTR *p)
2071 {
2072     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2073     FIXME("(%p)->(%p)\n", This, p);
2074     return E_NOTIMPL;
2075 }
2076
2077 static HRESULT WINAPI HTMLStyle_put_display(IHTMLStyle *iface, BSTR v)
2078 {
2079     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2080
2081     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2082
2083     return set_style_attr(This, STYLEID_DISPLAY, v, 0);
2084 }
2085
2086 static HRESULT WINAPI HTMLStyle_get_display(IHTMLStyle *iface, BSTR *p)
2087 {
2088     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2089
2090     TRACE("(%p)->(%p)\n", This, p);
2091
2092     return get_style_attr(This, STYLEID_DISPLAY, p);
2093 }
2094
2095 static HRESULT WINAPI HTMLStyle_put_visibility(IHTMLStyle *iface, BSTR v)
2096 {
2097     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2098
2099     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2100
2101     return set_style_attr(This, STYLEID_VISIBILITY, v, 0);
2102 }
2103
2104 static HRESULT WINAPI HTMLStyle_get_visibility(IHTMLStyle *iface, BSTR *p)
2105 {
2106     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2107
2108     TRACE("(%p)->(%p)\n", This, p);
2109
2110     return get_style_attr(This, STYLEID_VISIBILITY, p);
2111 }
2112
2113 static HRESULT WINAPI HTMLStyle_put_listStyleType(IHTMLStyle *iface, BSTR v)
2114 {
2115     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2116     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2117     return E_NOTIMPL;
2118 }
2119
2120 static HRESULT WINAPI HTMLStyle_get_listStyleType(IHTMLStyle *iface, BSTR *p)
2121 {
2122     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2123     FIXME("(%p)->(%p)\n", This, p);
2124     return E_NOTIMPL;
2125 }
2126
2127 static HRESULT WINAPI HTMLStyle_put_listStylePosition(IHTMLStyle *iface, BSTR v)
2128 {
2129     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2130     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2131     return E_NOTIMPL;
2132 }
2133
2134 static HRESULT WINAPI HTMLStyle_get_listStylePosition(IHTMLStyle *iface, BSTR *p)
2135 {
2136     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2137     FIXME("(%p)->(%p)\n", This, p);
2138     return E_NOTIMPL;
2139 }
2140
2141 static HRESULT WINAPI HTMLStyle_put_listStyleImage(IHTMLStyle *iface, BSTR v)
2142 {
2143     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2144     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2145     return E_NOTIMPL;
2146 }
2147
2148 static HRESULT WINAPI HTMLStyle_get_listStyleImage(IHTMLStyle *iface, BSTR *p)
2149 {
2150     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2151     FIXME("(%p)->(%p)\n", This, p);
2152     return E_NOTIMPL;
2153 }
2154
2155 static HRESULT WINAPI HTMLStyle_put_listStyle(IHTMLStyle *iface, BSTR v)
2156 {
2157     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2158     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2159     return E_NOTIMPL;
2160 }
2161
2162 static HRESULT WINAPI HTMLStyle_get_listStyle(IHTMLStyle *iface, BSTR *p)
2163 {
2164     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2165     FIXME("(%p)->(%p)\n", This, p);
2166     return E_NOTIMPL;
2167 }
2168
2169 static HRESULT WINAPI HTMLStyle_put_whiteSpace(IHTMLStyle *iface, BSTR v)
2170 {
2171     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2172     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
2173     return E_NOTIMPL;
2174 }
2175
2176 static HRESULT WINAPI HTMLStyle_get_whiteSpace(IHTMLStyle *iface, BSTR *p)
2177 {
2178     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2179     FIXME("(%p)->(%p)\n", This, p);
2180     return E_NOTIMPL;
2181 }
2182
2183 static HRESULT WINAPI HTMLStyle_put_top(IHTMLStyle *iface, VARIANT v)
2184 {
2185     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2186
2187     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2188
2189     return set_nsstyle_attr_var(This->nsstyle, STYLEID_TOP, &v, 0);
2190 }
2191
2192 static HRESULT WINAPI HTMLStyle_get_top(IHTMLStyle *iface, VARIANT *p)
2193 {
2194     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2195
2196     TRACE("(%p)->(%p)\n", This, p);
2197
2198     return get_nsstyle_attr_var(This->nsstyle, STYLEID_TOP, p, 0);
2199 }
2200
2201 static HRESULT WINAPI HTMLStyle_put_left(IHTMLStyle *iface, VARIANT v)
2202 {
2203     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2204
2205     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2206
2207     return set_nsstyle_attr_var(This->nsstyle, STYLEID_LEFT, &v, 0);
2208 }
2209
2210 static HRESULT WINAPI HTMLStyle_get_left(IHTMLStyle *iface, VARIANT *p)
2211 {
2212     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2213
2214     TRACE("(%p)->(%p)\n", This, p);
2215
2216     return get_nsstyle_attr_var(This->nsstyle, STYLEID_LEFT, p, 0);
2217 }
2218
2219 static HRESULT WINAPI HTMLStyle_get_position(IHTMLStyle *iface, BSTR *p)
2220 {
2221     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2222     TRACE("(%p)->(%p)\n", This, p);
2223     return IHTMLStyle2_get_position(&This->IHTMLStyle2_iface, p);
2224 }
2225
2226 static HRESULT WINAPI HTMLStyle_put_zIndex(IHTMLStyle *iface, VARIANT v)
2227 {
2228     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2229
2230     TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
2231
2232     return set_nsstyle_attr_var(This->nsstyle, STYLEID_Z_INDEX, &v, 0);
2233 }
2234
2235 static HRESULT WINAPI HTMLStyle_get_zIndex(IHTMLStyle *iface, VARIANT *p)
2236 {
2237     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2238
2239     TRACE("(%p)->(%p)\n", This, p);
2240
2241     return get_nsstyle_attr_var(This->nsstyle, STYLEID_Z_INDEX, p, ATTR_STR_TO_INT);
2242 }
2243
2244 static HRESULT WINAPI HTMLStyle_put_overflow(IHTMLStyle *iface, BSTR v)
2245 {
2246     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2247     static const WCHAR szVisible[] = {'v','i','s','i','b','l','e',0};
2248     static const WCHAR szScroll[]  = {'s','c','r','o','l','l',0};
2249     static const WCHAR szHidden[]  = {'h','i','d','d','e','n',0};
2250     static const WCHAR szAuto[]    = {'a','u','t','o',0};
2251
2252     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2253
2254     /* overflow can only be one of the follow values. */
2255     if(!v || !*v || strcmpiW(szVisible, v) == 0 || strcmpiW(szScroll, v) == 0 ||
2256              strcmpiW(szHidden, v) == 0  || strcmpiW(szAuto, v) == 0)
2257     {
2258         return set_nsstyle_attr(This->nsstyle, STYLEID_OVERFLOW, v, 0);
2259     }
2260
2261     return E_INVALIDARG;
2262 }
2263
2264
2265 static HRESULT WINAPI HTMLStyle_get_overflow(IHTMLStyle *iface, BSTR *p)
2266 {
2267     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2268
2269     TRACE("(%p)->(%p)\n", This, p);
2270
2271     if(!p)
2272        return E_INVALIDARG;
2273
2274     return get_style_attr(This, STYLEID_OVERFLOW, p);
2275 }
2276
2277 static HRESULT WINAPI HTMLStyle_put_pageBreakBefore(IHTMLStyle *iface, BSTR v)
2278 {
2279     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2280
2281     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2282
2283     return set_nsstyle_attr(This->nsstyle, STYLEID_PAGE_BREAK_BEFORE, v, 0);
2284 }
2285
2286 static HRESULT WINAPI HTMLStyle_get_pageBreakBefore(IHTMLStyle *iface, BSTR *p)
2287 {
2288     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2289
2290     TRACE("(%p)->(%p)\n", This, p);
2291
2292     return get_nsstyle_attr(This->nsstyle, STYLEID_PAGE_BREAK_BEFORE, p, 0);
2293 }
2294
2295 static HRESULT WINAPI HTMLStyle_put_pageBreakAfter(IHTMLStyle *iface, BSTR v)
2296 {
2297     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2298
2299     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2300
2301     return set_nsstyle_attr(This->nsstyle, STYLEID_PAGE_BREAK_AFTER, v, 0);
2302 }
2303
2304 static HRESULT WINAPI HTMLStyle_get_pageBreakAfter(IHTMLStyle *iface, BSTR *p)
2305 {
2306     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2307
2308     TRACE("(%p)->(%p)\n", This, p);
2309
2310     return get_nsstyle_attr(This->nsstyle, STYLEID_PAGE_BREAK_AFTER, p, 0);
2311 }
2312
2313 static HRESULT WINAPI HTMLStyle_put_cssText(IHTMLStyle *iface, BSTR v)
2314 {
2315     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2316     nsAString text_str;
2317     nsresult nsres;
2318
2319     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2320
2321     nsAString_InitDepend(&text_str, v);
2322     nsres = nsIDOMCSSStyleDeclaration_SetCssText(This->nsstyle, &text_str);
2323     nsAString_Finish(&text_str);
2324     if(NS_FAILED(nsres)) {
2325         FIXME("SetCssStyle failed: %08x\n", nsres);
2326         return E_FAIL;
2327     }
2328
2329     return S_OK;
2330 }
2331
2332 static HRESULT WINAPI HTMLStyle_get_cssText(IHTMLStyle *iface, BSTR *p)
2333 {
2334     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2335     nsAString text_str;
2336     nsresult nsres;
2337
2338     TRACE("(%p)->(%p)\n", This, p);
2339
2340     /* FIXME: Gecko style formatting is different than IE (uppercase). */
2341     nsAString_Init(&text_str, NULL);
2342     nsres = nsIDOMCSSStyleDeclaration_GetCssText(This->nsstyle, &text_str);
2343     if(NS_SUCCEEDED(nsres)) {
2344         const PRUnichar *text;
2345
2346         nsAString_GetData(&text_str, &text);
2347         *p = *text ? SysAllocString(text) : NULL;
2348     }else {
2349         FIXME("GetCssStyle failed: %08x\n", nsres);
2350         *p = NULL;
2351     }
2352
2353     nsAString_Finish(&text_str);
2354     return S_OK;
2355 }
2356
2357 static HRESULT WINAPI HTMLStyle_put_pixelTop(IHTMLStyle *iface, LONG v)
2358 {
2359     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2360     FIXME("(%p)->()\n", This);
2361     return E_NOTIMPL;
2362 }
2363
2364 static HRESULT WINAPI HTMLStyle_get_pixelTop(IHTMLStyle *iface, LONG *p)
2365 {
2366     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2367     FIXME("(%p)->()\n", This);
2368     return E_NOTIMPL;
2369 }
2370
2371 static HRESULT WINAPI HTMLStyle_put_pixelLeft(IHTMLStyle *iface, LONG v)
2372 {
2373     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2374     FIXME("(%p)->()\n", This);
2375     return E_NOTIMPL;
2376 }
2377
2378 static HRESULT WINAPI HTMLStyle_get_pixelLeft(IHTMLStyle *iface, LONG *p)
2379 {
2380     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2381     FIXME("(%p)->()\n", This);
2382     return E_NOTIMPL;
2383 }
2384
2385 static HRESULT WINAPI HTMLStyle_put_pixelWidth(IHTMLStyle *iface, LONG v)
2386 {
2387     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2388
2389     TRACE("(%p)->()\n", This);
2390
2391     return set_style_pxattr(This->nsstyle, STYLEID_WIDTH, v);
2392 }
2393
2394 static HRESULT WINAPI HTMLStyle_get_pixelWidth(IHTMLStyle *iface, LONG *p)
2395 {
2396     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2397     FIXME("(%p)->()\n", This);
2398     return E_NOTIMPL;
2399 }
2400
2401 static HRESULT WINAPI HTMLStyle_put_pixelHeight(IHTMLStyle *iface, LONG v)
2402 {
2403     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2404     FIXME("(%p)->()\n", This);
2405     return E_NOTIMPL;
2406 }
2407
2408 static HRESULT WINAPI HTMLStyle_get_pixelHeight(IHTMLStyle *iface, LONG *p)
2409 {
2410     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2411     FIXME("(%p)->()\n", This);
2412     return E_NOTIMPL;
2413 }
2414
2415 static HRESULT WINAPI HTMLStyle_put_posTop(IHTMLStyle *iface, float v)
2416 {
2417     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2418
2419     TRACE("(%p)->(%f)\n", This, v);
2420
2421     return set_style_pos(This, STYLEID_TOP, v);
2422 }
2423
2424 static HRESULT WINAPI HTMLStyle_get_posTop(IHTMLStyle *iface, float *p)
2425 {
2426     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2427
2428     TRACE("(%p)->(%p)\n", This, p);
2429
2430     if(!p)
2431         return E_POINTER;
2432
2433     return get_nsstyle_pos(This, STYLEID_TOP, p);
2434 }
2435
2436 static HRESULT WINAPI HTMLStyle_put_posLeft(IHTMLStyle *iface, float v)
2437 {
2438     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2439
2440     TRACE("(%p)->(%f)\n", This, v);
2441
2442     return set_style_pos(This, STYLEID_LEFT, v);
2443 }
2444
2445 static HRESULT WINAPI HTMLStyle_get_posLeft(IHTMLStyle *iface, float *p)
2446 {
2447     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2448
2449     TRACE("(%p)->(%p)\n", This, p);
2450
2451     if(!p)
2452         return E_POINTER;
2453
2454     return get_nsstyle_pos(This, STYLEID_LEFT, p);
2455 }
2456
2457 static HRESULT WINAPI HTMLStyle_put_posWidth(IHTMLStyle *iface, float v)
2458 {
2459     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2460
2461     TRACE("(%p)->(%f)\n", This, v);
2462
2463     return set_style_pos(This, STYLEID_WIDTH, v);
2464 }
2465
2466 static HRESULT WINAPI HTMLStyle_get_posWidth(IHTMLStyle *iface, float *p)
2467 {
2468     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2469
2470     TRACE("(%p)->(%p)\n", This, p);
2471
2472     if(!p)
2473         return E_POINTER;
2474
2475     if(get_nsstyle_pos(This, STYLEID_WIDTH, p) != S_OK)
2476         *p = 0.0f;
2477
2478     return S_OK;
2479 }
2480
2481 static HRESULT WINAPI HTMLStyle_put_posHeight(IHTMLStyle *iface, float v)
2482 {
2483     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2484
2485     TRACE("(%p)->(%f)\n", This, v);
2486
2487     return set_style_pos(This, STYLEID_HEIGHT, v);
2488 }
2489
2490 static HRESULT WINAPI HTMLStyle_get_posHeight(IHTMLStyle *iface, float *p)
2491 {
2492     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2493
2494     TRACE("(%p)->(%p)\n", This, p);
2495
2496     if(!p)
2497         return E_POINTER;
2498
2499     if(get_nsstyle_pos(This, STYLEID_HEIGHT, p) != S_OK)
2500         *p = 0.0f;
2501
2502     return S_OK;
2503 }
2504
2505 static HRESULT WINAPI HTMLStyle_put_cursor(IHTMLStyle *iface, BSTR v)
2506 {
2507     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2508
2509     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2510
2511     return set_style_attr(This, STYLEID_CURSOR, v, 0);
2512 }
2513
2514 static HRESULT WINAPI HTMLStyle_get_cursor(IHTMLStyle *iface, BSTR *p)
2515 {
2516     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2517
2518     TRACE("(%p)->(%p)\n", This, p);
2519
2520     return get_style_attr(This, STYLEID_CURSOR, p);
2521 }
2522
2523 static HRESULT WINAPI HTMLStyle_put_clip(IHTMLStyle *iface, BSTR v)
2524 {
2525     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2526
2527     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2528
2529     return set_style_attr(This, STYLEID_CLIP, v, 0);
2530 }
2531
2532 static HRESULT WINAPI HTMLStyle_get_clip(IHTMLStyle *iface, BSTR *p)
2533 {
2534     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2535
2536     TRACE("(%p)->(%p)\n", This, p);
2537
2538     return get_nsstyle_attr(This->nsstyle, STYLEID_CLIP, p, ATTR_REMOVE_COMMA);
2539 }
2540
2541 static void set_opacity(HTMLStyle *This, const WCHAR *val)
2542 {
2543     nsAString name_str, val_str, empty_str;
2544     nsresult nsres;
2545
2546     static const WCHAR opacityW[] = {'o','p','a','c','i','t','y',0};
2547
2548     TRACE("%s\n", debugstr_w(val));
2549
2550     nsAString_InitDepend(&name_str, opacityW);
2551     nsAString_InitDepend(&val_str, val);
2552     nsAString_InitDepend(&empty_str, emptyW);
2553
2554     nsres = nsIDOMCSSStyleDeclaration_SetProperty(This->nsstyle, &name_str, &val_str, &empty_str);
2555     if(NS_FAILED(nsres))
2556         ERR("SetProperty failed: %08x\n", nsres);
2557
2558     nsAString_Finish(&name_str);
2559     nsAString_Finish(&val_str);
2560     nsAString_Finish(&empty_str);
2561 }
2562
2563 static void update_filter(HTMLStyle *This)
2564 {
2565     const WCHAR *ptr = This->elem->filter, *ptr2;
2566
2567     static const WCHAR alphaW[] = {'a','l','p','h','a'};
2568
2569     if(!ptr) {
2570         set_opacity(This, emptyW);
2571         return;
2572     }
2573
2574     while(1) {
2575         while(isspaceW(*ptr))
2576             ptr++;
2577         if(!*ptr)
2578             break;
2579
2580         ptr2 = ptr;
2581         while(isalnumW(*ptr))
2582             ptr++;
2583         if(ptr == ptr2) {
2584             WARN("unexpected char '%c'\n", *ptr);
2585             break;
2586         }
2587         if(*ptr != '(') {
2588             WARN("expected '('\n");
2589             continue;
2590         }
2591
2592         if(ptr2 + sizeof(alphaW)/sizeof(WCHAR) == ptr && !memcmp(ptr2, alphaW, sizeof(alphaW))) {
2593             static const WCHAR formatW[] = {'%','f',0};
2594             static const WCHAR opacityW[] = {'o','p','a','c','i','t','y','='};
2595
2596             ptr++;
2597             do {
2598                 while(isspaceW(*ptr))
2599                     ptr++;
2600
2601                 ptr2 = ptr;
2602                 while(*ptr && *ptr != ',' && *ptr != ')')
2603                     ptr++;
2604                 if(!*ptr) {
2605                     WARN("unexpected end of string\n");
2606                     break;
2607                 }
2608
2609                 if(ptr-ptr2 > sizeof(opacityW)/sizeof(WCHAR) && !memcmp(ptr2, opacityW, sizeof(opacityW))) {
2610                     float fval = 0.0f, e = 0.1f;
2611                     WCHAR buf[32];
2612
2613                     ptr2 += sizeof(opacityW)/sizeof(WCHAR);
2614
2615                     while(isdigitW(*ptr2))
2616                         fval = fval*10.0f + (float)(*ptr2++ - '0');
2617
2618                     if(*ptr2 == '.') {
2619                         while(isdigitW(*++ptr2)) {
2620                             fval += e * (float)(*ptr2++ - '0');
2621                             e *= 0.1f;
2622                         }
2623                     }
2624
2625                     sprintfW(buf, formatW, fval * 0.01f);
2626                     set_opacity(This, buf);
2627                 }else {
2628                     FIXME("unknown param %s\n", debugstr_wn(ptr2, ptr-ptr2));
2629                 }
2630
2631                 if(*ptr == ',')
2632                     ptr++;
2633             }while(*ptr != ')');
2634         }else {
2635             FIXME("unknown filter %s\n", debugstr_wn(ptr2, ptr-ptr2));
2636             ptr = strchrW(ptr, ')');
2637             if(!ptr)
2638                 break;
2639             ptr++;
2640         }
2641     }
2642 }
2643
2644 static HRESULT WINAPI HTMLStyle_put_filter(IHTMLStyle *iface, BSTR v)
2645 {
2646     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2647     WCHAR *new_filter = NULL;
2648
2649     TRACE("(%p)->(%s)\n", This, debugstr_w(v));
2650
2651     if(!This->elem) {
2652         FIXME("Element already destroyed\n");
2653         return E_UNEXPECTED;
2654     }
2655
2656     if(v) {
2657         new_filter = heap_strdupW(v);
2658         if(!new_filter)
2659             return E_OUTOFMEMORY;
2660     }
2661
2662     heap_free(This->elem->filter);
2663     This->elem->filter = new_filter;
2664
2665     update_filter(This);
2666     return S_OK;
2667 }
2668
2669 static HRESULT WINAPI HTMLStyle_get_filter(IHTMLStyle *iface, BSTR *p)
2670 {
2671     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2672
2673     TRACE("(%p)->(%p)\n", This, p);
2674
2675     if(!This->elem) {
2676         FIXME("Element already destroyed\n");
2677         return E_UNEXPECTED;
2678     }
2679
2680     if(This->elem->filter) {
2681         *p = SysAllocString(This->elem->filter);
2682         if(!*p)
2683             return E_OUTOFMEMORY;
2684     }else {
2685         *p = NULL;
2686     }
2687
2688     return S_OK;
2689 }
2690
2691 static HRESULT WINAPI HTMLStyle_setAttribute(IHTMLStyle *iface, BSTR strAttributeName,
2692         VARIANT AttributeValue, LONG lFlags)
2693 {
2694     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2695     HRESULT hres;
2696     DISPID dispid;
2697
2698     TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName),
2699           debugstr_variant(&AttributeValue), lFlags);
2700
2701     if(!strAttributeName)
2702         return E_INVALIDARG;
2703
2704     if(lFlags == 1)
2705         FIXME("Parameter lFlags ignored\n");
2706
2707     hres = HTMLStyle_GetIDsOfNames(iface, &IID_NULL, &strAttributeName, 1,
2708                         LOCALE_USER_DEFAULT, &dispid);
2709     if(hres == S_OK)
2710     {
2711         VARIANT ret;
2712         DISPID dispidNamed = DISPID_PROPERTYPUT;
2713         DISPPARAMS params;
2714
2715         params.cArgs = 1;
2716         params.rgvarg = &AttributeValue;
2717         params.cNamedArgs = 1;
2718         params.rgdispidNamedArgs = &dispidNamed;
2719
2720         hres = HTMLStyle_Invoke(iface, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2721             DISPATCH_PROPERTYPUT, &params, &ret, NULL, NULL);
2722     }
2723     else
2724     {
2725         FIXME("Custom attributes not supported.\n");
2726     }
2727
2728     TRACE("ret: %08x\n", hres);
2729
2730     return hres;
2731 }
2732
2733 static HRESULT WINAPI HTMLStyle_getAttribute(IHTMLStyle *iface, BSTR strAttributeName,
2734         LONG lFlags, VARIANT *AttributeValue)
2735 {
2736     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2737     HRESULT hres;
2738     DISPID dispid;
2739
2740     TRACE("(%p)->(%s v%p %08x)\n", This, debugstr_w(strAttributeName),
2741           AttributeValue, lFlags);
2742
2743     if(!AttributeValue || !strAttributeName)
2744         return E_INVALIDARG;
2745
2746     if(lFlags == 1)
2747         FIXME("Parameter lFlags ignored\n");
2748
2749     hres = HTMLStyle_GetIDsOfNames(iface, &IID_NULL, &strAttributeName, 1,
2750                         LOCALE_USER_DEFAULT, &dispid);
2751     if(hres == S_OK)
2752     {
2753         DISPPARAMS params = {NULL, NULL, 0, 0 };
2754
2755         hres = HTMLStyle_Invoke(iface, dispid, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
2756             DISPATCH_PROPERTYGET, &params, AttributeValue, NULL, NULL);
2757     }
2758     else
2759     {
2760         FIXME("Custom attributes not supported.\n");
2761     }
2762
2763     return hres;
2764 }
2765
2766 static HRESULT WINAPI HTMLStyle_removeAttribute(IHTMLStyle *iface, BSTR strAttributeName,
2767                                                 LONG lFlags, VARIANT_BOOL *pfSuccess)
2768 {
2769     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2770     const style_tbl_entry_t *style_entry;
2771     nsAString name_str, ret_str;
2772     nsresult nsres;
2773     HRESULT hres;
2774
2775     TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
2776
2777     style_entry = lookup_style_tbl(strAttributeName);
2778     if(!style_entry) {
2779         DISPID dispid;
2780         unsigned i;
2781
2782         hres = IDispatchEx_GetDispID(&This->dispex.IDispatchEx_iface, strAttributeName,
2783                 (lFlags&1) ? fdexNameCaseSensitive : fdexNameCaseInsensitive, &dispid);
2784         if(hres != S_OK) {
2785             *pfSuccess = VARIANT_FALSE;
2786             return S_OK;
2787         }
2788
2789         for(i=0; i < sizeof(style_tbl)/sizeof(*style_tbl); i++) {
2790             if(dispid == style_tbl[i].dispid)
2791                 break;
2792         }
2793
2794         if(i == sizeof(style_tbl)/sizeof(*style_tbl))
2795             return remove_prop(&This->dispex, strAttributeName, pfSuccess);
2796         style_entry = style_tbl+i;
2797     }
2798
2799     /* filter property is a special case */
2800     if(style_entry->dispid == DISPID_IHTMLSTYLE_FILTER) {
2801         *pfSuccess = This->elem->filter && *This->elem->filter ? VARIANT_TRUE : VARIANT_FALSE;
2802         heap_free(This->elem->filter);
2803         This->elem->filter = NULL;
2804         update_filter(This);
2805         return S_OK;
2806     }
2807
2808     nsAString_InitDepend(&name_str, style_entry->name);
2809     nsAString_Init(&ret_str, NULL);
2810     nsres = nsIDOMCSSStyleDeclaration_RemoveProperty(This->nsstyle, &name_str, &ret_str);
2811     if(NS_SUCCEEDED(nsres)) {
2812         const PRUnichar *ret;
2813         nsAString_GetData(&ret_str, &ret);
2814         *pfSuccess = *ret ? VARIANT_TRUE : VARIANT_FALSE;
2815     }else {
2816         ERR("RemoveProperty failed: %08x\n", nsres);
2817     }
2818     nsAString_Finish(&name_str);
2819     nsAString_Finish(&ret_str);
2820     return NS_SUCCEEDED(nsres) ? S_OK : E_FAIL;
2821 }
2822
2823 static HRESULT WINAPI HTMLStyle_toString(IHTMLStyle *iface, BSTR *String)
2824 {
2825     HTMLStyle *This = impl_from_IHTMLStyle(iface);
2826     FIXME("(%p)->(%p)\n", This, String);
2827     return E_NOTIMPL;
2828 }
2829
2830 static const IHTMLStyleVtbl HTMLStyleVtbl = {
2831     HTMLStyle_QueryInterface,
2832     HTMLStyle_AddRef,
2833     HTMLStyle_Release,
2834     HTMLStyle_GetTypeInfoCount,
2835     HTMLStyle_GetTypeInfo,
2836     HTMLStyle_GetIDsOfNames,
2837     HTMLStyle_Invoke,
2838     HTMLStyle_put_fontFamily,
2839     HTMLStyle_get_fontFamily,
2840     HTMLStyle_put_fontStyle,
2841     HTMLStyle_get_fontStyle,
2842     HTMLStyle_put_fontVariant,
2843     HTMLStyle_get_fontVariant,
2844     HTMLStyle_put_fontWeight,
2845     HTMLStyle_get_fontWeight,
2846     HTMLStyle_put_fontSize,
2847     HTMLStyle_get_fontSize,
2848     HTMLStyle_put_font,
2849     HTMLStyle_get_font,
2850     HTMLStyle_put_color,
2851     HTMLStyle_get_color,
2852     HTMLStyle_put_background,
2853     HTMLStyle_get_background,
2854     HTMLStyle_put_backgroundColor,
2855     HTMLStyle_get_backgroundColor,
2856     HTMLStyle_put_backgroundImage,
2857     HTMLStyle_get_backgroundImage,
2858     HTMLStyle_put_backgroundRepeat,
2859     HTMLStyle_get_backgroundRepeat,
2860     HTMLStyle_put_backgroundAttachment,
2861     HTMLStyle_get_backgroundAttachment,
2862     HTMLStyle_put_backgroundPosition,
2863     HTMLStyle_get_backgroundPosition,
2864     HTMLStyle_put_backgroundPositionX,
2865     HTMLStyle_get_backgroundPositionX,
2866     HTMLStyle_put_backgroundPositionY,
2867     HTMLStyle_get_backgroundPositionY,
2868     HTMLStyle_put_wordSpacing,
2869     HTMLStyle_get_wordSpacing,
2870     HTMLStyle_put_letterSpacing,
2871     HTMLStyle_get_letterSpacing,
2872     HTMLStyle_put_textDecoration,
2873     HTMLStyle_get_textDecoration,
2874     HTMLStyle_put_textDecorationNone,
2875     HTMLStyle_get_textDecorationNone,
2876     HTMLStyle_put_textDecorationUnderline,
2877     HTMLStyle_get_textDecorationUnderline,
2878     HTMLStyle_put_textDecorationOverline,
2879     HTMLStyle_get_textDecorationOverline,
2880     HTMLStyle_put_textDecorationLineThrough,
2881     HTMLStyle_get_textDecorationLineThrough,
2882     HTMLStyle_put_textDecorationBlink,
2883     HTMLStyle_get_textDecorationBlink,
2884     HTMLStyle_put_verticalAlign,
2885     HTMLStyle_get_verticalAlign,
2886     HTMLStyle_put_textTransform,
2887     HTMLStyle_get_textTransform,
2888     HTMLStyle_put_textAlign,
2889     HTMLStyle_get_textAlign,
2890     HTMLStyle_put_textIndent,
2891     HTMLStyle_get_textIndent,
2892     HTMLStyle_put_lineHeight,
2893     HTMLStyle_get_lineHeight,
2894     HTMLStyle_put_marginTop,
2895     HTMLStyle_get_marginTop,
2896     HTMLStyle_put_marginRight,
2897     HTMLStyle_get_marginRight,
2898     HTMLStyle_put_marginBottom,
2899     HTMLStyle_get_marginBottom,
2900     HTMLStyle_put_marginLeft,
2901     HTMLStyle_get_marginLeft,
2902     HTMLStyle_put_margin,
2903     HTMLStyle_get_margin,
2904     HTMLStyle_put_paddingTop,
2905     HTMLStyle_get_paddingTop,
2906     HTMLStyle_put_paddingRight,
2907     HTMLStyle_get_paddingRight,
2908     HTMLStyle_put_paddingBottom,
2909     HTMLStyle_get_paddingBottom,
2910     HTMLStyle_put_paddingLeft,
2911     HTMLStyle_get_paddingLeft,
2912     HTMLStyle_put_padding,
2913     HTMLStyle_get_padding,
2914     HTMLStyle_put_border,
2915     HTMLStyle_get_border,
2916     HTMLStyle_put_borderTop,
2917     HTMLStyle_get_borderTop,
2918     HTMLStyle_put_borderRight,
2919     HTMLStyle_get_borderRight,
2920     HTMLStyle_put_borderBottom,
2921     HTMLStyle_get_borderBottom,
2922     HTMLStyle_put_borderLeft,
2923     HTMLStyle_get_borderLeft,
2924     HTMLStyle_put_borderColor,
2925     HTMLStyle_get_borderColor,
2926     HTMLStyle_put_borderTopColor,
2927     HTMLStyle_get_borderTopColor,
2928     HTMLStyle_put_borderRightColor,
2929     HTMLStyle_get_borderRightColor,
2930     HTMLStyle_put_borderBottomColor,
2931     HTMLStyle_get_borderBottomColor,
2932     HTMLStyle_put_borderLeftColor,
2933     HTMLStyle_get_borderLeftColor,
2934     HTMLStyle_put_borderWidth,
2935     HTMLStyle_get_borderWidth,
2936     HTMLStyle_put_borderTopWidth,
2937     HTMLStyle_get_borderTopWidth,
2938     HTMLStyle_put_borderRightWidth,
2939     HTMLStyle_get_borderRightWidth,
2940     HTMLStyle_put_borderBottomWidth,
2941     HTMLStyle_get_borderBottomWidth,
2942     HTMLStyle_put_borderLeftWidth,
2943     HTMLStyle_get_borderLeftWidth,
2944     HTMLStyle_put_borderStyle,
2945     HTMLStyle_get_borderStyle,
2946     HTMLStyle_put_borderTopStyle,
2947     HTMLStyle_get_borderTopStyle,
2948     HTMLStyle_put_borderRightStyle,
2949     HTMLStyle_get_borderRightStyle,
2950     HTMLStyle_put_borderBottomStyle,
2951     HTMLStyle_get_borderBottomStyle,
2952     HTMLStyle_put_borderLeftStyle,
2953     HTMLStyle_get_borderLeftStyle,
2954     HTMLStyle_put_width,
2955     HTMLStyle_get_width,
2956     HTMLStyle_put_height,
2957     HTMLStyle_get_height,
2958     HTMLStyle_put_styleFloat,
2959     HTMLStyle_get_styleFloat,
2960     HTMLStyle_put_clear,
2961     HTMLStyle_get_clear,
2962     HTMLStyle_put_display,
2963     HTMLStyle_get_display,
2964     HTMLStyle_put_visibility,
2965     HTMLStyle_get_visibility,
2966     HTMLStyle_put_listStyleType,
2967     HTMLStyle_get_listStyleType,
2968     HTMLStyle_put_listStylePosition,
2969     HTMLStyle_get_listStylePosition,
2970     HTMLStyle_put_listStyleImage,
2971     HTMLStyle_get_listStyleImage,
2972     HTMLStyle_put_listStyle,
2973     HTMLStyle_get_listStyle,
2974     HTMLStyle_put_whiteSpace,
2975     HTMLStyle_get_whiteSpace,
2976     HTMLStyle_put_top,
2977     HTMLStyle_get_top,
2978     HTMLStyle_put_left,
2979     HTMLStyle_get_left,
2980     HTMLStyle_get_position,
2981     HTMLStyle_put_zIndex,
2982     HTMLStyle_get_zIndex,
2983     HTMLStyle_put_overflow,
2984     HTMLStyle_get_overflow,
2985     HTMLStyle_put_pageBreakBefore,
2986     HTMLStyle_get_pageBreakBefore,
2987     HTMLStyle_put_pageBreakAfter,
2988     HTMLStyle_get_pageBreakAfter,
2989     HTMLStyle_put_cssText,
2990     HTMLStyle_get_cssText,
2991     HTMLStyle_put_pixelTop,
2992     HTMLStyle_get_pixelTop,
2993     HTMLStyle_put_pixelLeft,
2994     HTMLStyle_get_pixelLeft,
2995     HTMLStyle_put_pixelWidth,
2996     HTMLStyle_get_pixelWidth,
2997     HTMLStyle_put_pixelHeight,
2998     HTMLStyle_get_pixelHeight,
2999     HTMLStyle_put_posTop,
3000     HTMLStyle_get_posTop,
3001     HTMLStyle_put_posLeft,
3002     HTMLStyle_get_posLeft,
3003     HTMLStyle_put_posWidth,
3004     HTMLStyle_get_posWidth,
3005     HTMLStyle_put_posHeight,
3006     HTMLStyle_get_posHeight,
3007     HTMLStyle_put_cursor,
3008     HTMLStyle_get_cursor,
3009     HTMLStyle_put_clip,
3010     HTMLStyle_get_clip,
3011     HTMLStyle_put_filter,
3012     HTMLStyle_get_filter,
3013     HTMLStyle_setAttribute,
3014     HTMLStyle_getAttribute,
3015     HTMLStyle_removeAttribute,
3016     HTMLStyle_toString
3017 };
3018
3019 static HRESULT HTMLStyle_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
3020 {
3021     const style_tbl_entry_t *style_entry;
3022
3023     style_entry = lookup_style_tbl(name);
3024     if(style_entry) {
3025         *dispid = style_entry->dispid;
3026         return S_OK;
3027     }
3028
3029     return DISP_E_UNKNOWNNAME;
3030 }
3031
3032 static const dispex_static_data_vtbl_t HTMLStyle_dispex_vtbl = {
3033     NULL,
3034     HTMLStyle_get_dispid,
3035     NULL,
3036     NULL
3037 };
3038
3039 static const tid_t HTMLStyle_iface_tids[] = {
3040     IHTMLStyle_tid,
3041     IHTMLStyle2_tid,
3042     IHTMLStyle3_tid,
3043     IHTMLStyle4_tid,
3044     IHTMLStyle5_tid,
3045     IHTMLStyle6_tid,
3046     0
3047 };
3048 static dispex_static_data_t HTMLStyle_dispex = {
3049     &HTMLStyle_dispex_vtbl,
3050     DispHTMLStyle_tid,
3051     NULL,
3052     HTMLStyle_iface_tids
3053 };
3054
3055 HRESULT HTMLStyle_Create(HTMLElement *elem, HTMLStyle **ret)
3056 {
3057     nsIDOMElementCSSInlineStyle *nselemstyle;
3058     nsIDOMCSSStyleDeclaration *nsstyle;
3059     HTMLStyle *style;
3060     nsresult nsres;
3061
3062     if(!elem->nselem) {
3063         FIXME("NULL nselem\n");
3064         return E_NOTIMPL;
3065     }
3066
3067     nsres = nsIDOMHTMLElement_QueryInterface(elem->nselem, &IID_nsIDOMElementCSSInlineStyle,
3068             (void**)&nselemstyle);
3069     assert(nsres == NS_OK);
3070
3071     nsres = nsIDOMElementCSSInlineStyle_GetStyle(nselemstyle, &nsstyle);
3072     nsIDOMElementCSSInlineStyle_Release(nselemstyle);
3073     if(NS_FAILED(nsres)) {
3074         ERR("GetStyle failed: %08x\n", nsres);
3075         return E_FAIL;
3076     }
3077
3078     style = heap_alloc_zero(sizeof(HTMLStyle));
3079     if(!style) {
3080         nsIDOMCSSStyleDeclaration_Release(nsstyle);
3081         return E_OUTOFMEMORY;
3082     }
3083
3084     style->IHTMLStyle_iface.lpVtbl = &HTMLStyleVtbl;
3085     style->ref = 1;
3086     style->nsstyle = nsstyle;
3087     style->elem = elem;
3088     HTMLStyle2_Init(style);
3089     HTMLStyle3_Init(style);
3090
3091     nsIDOMCSSStyleDeclaration_AddRef(nsstyle);
3092
3093     init_dispex(&style->dispex, (IUnknown*)&style->IHTMLStyle_iface, &HTMLStyle_dispex);
3094
3095     *ret = style;
3096     return S_OK;
3097 }