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