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