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