msvcrt: Pass pthreadlocinfo to update_threadlocinfo_category helper function.
[wine.git] / dlls / mshtml / htmlbody.c
blobe4b7990f3a5de803d6e4c74cff51274b3ea895c1
1 /*
2 * Copyright 2006 Jacek Caban for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
32 #include "htmlevent.h"
33 #include "htmlstyle.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 typedef struct {
38 HTMLTextContainer textcont;
40 IHTMLBodyElement IHTMLBodyElement_iface;
42 nsIDOMHTMLBodyElement *nsbody;
43 } HTMLBodyElement;
45 static const WCHAR aquaW[] = {'a','q','u','a',0};
46 static const WCHAR blackW[] = {'b','l','a','c','k',0};
47 static const WCHAR blueW[] = {'b','l','u','e',0};
48 static const WCHAR fuchsiaW[] = {'f','u','s','h','s','i','a',0};
49 static const WCHAR grayW[] = {'g','r','a','y',0};
50 static const WCHAR greenW[] = {'g','r','e','e','n',0};
51 static const WCHAR limeW[] = {'l','i','m','e',0};
52 static const WCHAR maroonW[] = {'m','a','r','o','o','n',0};
53 static const WCHAR navyW[] = {'n','a','v','y',0};
54 static const WCHAR oliveW[] = {'o','l','i','v','e',0};
55 static const WCHAR purpleW[] = {'p','u','r','p','l','e',0};
56 static const WCHAR redW[] = {'r','e','d',0};
57 static const WCHAR silverW[] = {'s','i','l','v','e','r',0};
58 static const WCHAR tealW[] = {'t','e','a','l',0};
59 static const WCHAR whiteW[] = {'w','h','i','t','e',0};
60 static const WCHAR yellowW[] = {'y','e','l','l','o','w',0};
62 static const struct {
63 LPCWSTR keyword;
64 DWORD rgb;
65 } keyword_table[] = {
66 {aquaW, 0x00ffff},
67 {blackW, 0x000000},
68 {blueW, 0x0000ff},
69 {fuchsiaW, 0xff00ff},
70 {grayW, 0x808080},
71 {greenW, 0x008000},
72 {limeW, 0x00ff00},
73 {maroonW, 0x800000},
74 {navyW, 0x000080},
75 {oliveW, 0x808000},
76 {purpleW, 0x800080},
77 {redW, 0xff0000},
78 {silverW, 0xc0c0c0},
79 {tealW, 0x008080},
80 {whiteW, 0xffffff},
81 {yellowW, 0xffff00}
84 static int comp_value(const WCHAR *ptr, int dpc)
86 int ret = 0;
87 WCHAR ch;
89 if(dpc > 2)
90 dpc = 2;
92 while(dpc--) {
93 if(!*ptr)
94 ret *= 16;
95 else if(isdigitW(ch = *ptr++))
96 ret = ret*16 + (ch-'0');
97 else if('a' <= ch && ch <= 'f')
98 ret = ret*16 + (ch-'a') + 10;
99 else if('A' <= ch && ch <= 'F')
100 ret = ret*16 + (ch-'A') + 10;
101 else
102 ret *= 16;
105 return ret;
108 /* Based on Gecko NS_LooseHexToRGB */
109 static int loose_hex_to_rgb(const WCHAR *hex)
111 int len, dpc;
113 len = strlenW(hex);
114 if(*hex == '#') {
115 hex++;
116 len--;
118 if(len <= 3)
119 return 0;
121 dpc = min(len/3 + (len%3 ? 1 : 0), 4);
122 return (comp_value(hex, dpc) << 16)
123 | (comp_value(hex+dpc, dpc) << 8)
124 | comp_value(hex+2*dpc, dpc);
127 HRESULT nscolor_to_str(LPCWSTR color, BSTR *ret)
129 unsigned int i;
130 int rgb = -1;
132 static const WCHAR formatW[] = {'#','%','0','2','x','%','0','2','x','%','0','2','x',0};
134 if(!color || !*color) {
135 *ret = NULL;
136 return S_OK;
139 if(*color != '#') {
140 for(i=0; i < sizeof(keyword_table)/sizeof(keyword_table[0]); i++) {
141 if(!strcmpiW(color, keyword_table[i].keyword))
142 rgb = keyword_table[i].rgb;
145 if(rgb == -1)
146 rgb = loose_hex_to_rgb(color);
148 *ret = SysAllocStringLen(NULL, 7);
149 if(!*ret)
150 return E_OUTOFMEMORY;
152 sprintfW(*ret, formatW, rgb>>16, (rgb>>8)&0xff, rgb&0xff);
154 TRACE("%s -> %s\n", debugstr_w(color), debugstr_w(*ret));
155 return S_OK;
158 BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
160 switch(V_VT(v)) {
161 case VT_BSTR:
162 nsAString_Init(nsstr, V_BSTR(v));
163 return TRUE;
165 case VT_I4: {
166 PRUnichar buf[10];
167 static const WCHAR formatW[] = {'#','%','x',0};
169 wsprintfW(buf, formatW, V_I4(v));
170 nsAString_Init(nsstr, buf);
171 return TRUE;
174 default:
175 FIXME("invalid color %s\n", debugstr_variant(v));
178 return FALSE;
182 static HRESULT return_nscolor(nsresult nsres, nsAString *nsstr, VARIANT *p)
184 const PRUnichar *color;
186 if(NS_FAILED(nsres)) {
187 ERR("failed: %08x\n", nsres);
188 nsAString_Finish(nsstr);
189 return E_FAIL;
192 nsAString_GetData(nsstr, &color);
194 if(*color == '#') {
195 V_VT(p) = VT_I4;
196 V_I4(p) = strtolW(color+1, NULL, 16);
197 }else {
198 V_VT(p) = VT_BSTR;
199 V_BSTR(p) = SysAllocString(color);
200 if(!V_BSTR(p)) {
201 nsAString_Finish(nsstr);
202 return E_OUTOFMEMORY;
206 nsAString_Finish(nsstr);
207 TRACE("ret %s\n", debugstr_variant(p));
208 return S_OK;
211 static inline HTMLBodyElement *impl_from_IHTMLBodyElement(IHTMLBodyElement *iface)
213 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLBodyElement_iface);
216 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
217 REFIID riid, void **ppv)
219 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
221 return IHTMLDOMNode_QueryInterface(&This->textcont.element.node.IHTMLDOMNode_iface, riid, ppv);
224 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
226 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
228 return IHTMLDOMNode_AddRef(&This->textcont.element.node.IHTMLDOMNode_iface);
231 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
233 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
235 return IHTMLDOMNode_Release(&This->textcont.element.node.IHTMLDOMNode_iface);
238 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
240 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
241 return IDispatchEx_GetTypeInfoCount(&This->textcont.element.node.event_target.dispex.IDispatchEx_iface,
242 pctinfo);
245 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
246 LCID lcid, ITypeInfo **ppTInfo)
248 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
249 return IDispatchEx_GetTypeInfo(&This->textcont.element.node.event_target.dispex.IDispatchEx_iface, iTInfo,
250 lcid, ppTInfo);
253 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
254 LPOLESTR *rgszNames, UINT cNames,
255 LCID lcid, DISPID *rgDispId)
257 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
258 return IDispatchEx_GetIDsOfNames(&This->textcont.element.node.event_target.dispex.IDispatchEx_iface, riid,
259 rgszNames, cNames, lcid, rgDispId);
262 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
263 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
264 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
266 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
267 return IDispatchEx_Invoke(&This->textcont.element.node.event_target.dispex.IDispatchEx_iface, dispIdMember,
268 riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
271 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
273 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
274 nsAString nsstr;
275 nsresult nsres;
277 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
279 nsAString_InitDepend(&nsstr, v);
280 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
281 nsAString_Finish(&nsstr);
282 if(NS_FAILED(nsres))
283 return E_FAIL;
285 return S_OK;
288 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
290 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
291 nsAString background_str;
292 nsresult nsres;
294 TRACE("(%p)->(%p)\n", This, p);
296 nsAString_Init(&background_str, NULL);
297 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
298 return return_nsstr(nsres, &background_str, p);
301 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
303 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
304 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
310 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
311 FIXME("(%p)->(%p)\n", This, p);
312 return E_NOTIMPL;
315 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
317 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
318 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
319 return E_NOTIMPL;
322 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
324 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
325 FIXME("(%p)->(%p)\n", This, p);
326 return E_NOTIMPL;
329 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
331 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
332 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
333 return E_NOTIMPL;
336 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
338 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
339 FIXME("(%p)->(%p)\n", This, p);
340 return E_NOTIMPL;
343 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
345 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
346 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
347 return E_NOTIMPL;
350 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
352 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
353 FIXME("(%p)->(%p)\n", This, p);
354 return E_NOTIMPL;
357 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
359 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
360 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
361 return E_NOTIMPL;
364 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
366 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
367 FIXME("(%p)->(%p)\n", This, p);
368 return E_NOTIMPL;
371 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
373 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
374 FIXME("(%p)->(%x)\n", This, v);
375 return E_NOTIMPL;
378 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
380 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
381 FIXME("(%p)->(%p)\n", This, p);
382 return E_NOTIMPL;
385 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
387 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
388 nsAString strColor;
389 nsresult nsres;
391 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
393 if(!variant_to_nscolor(&v, &strColor))
394 return S_OK;
396 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
397 nsAString_Finish(&strColor);
398 if(NS_FAILED(nsres))
399 ERR("SetBgColor failed: %08x\n", nsres);
401 return S_OK;
404 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
406 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
407 nsAString strColor;
408 nsresult nsres;
409 HRESULT hres;
411 TRACE("(%p)->(%p)\n", This, p);
413 nsAString_Init(&strColor, NULL);
414 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &strColor);
415 if(NS_SUCCEEDED(nsres)) {
416 const PRUnichar *color;
418 nsAString_GetData(&strColor, &color);
419 V_VT(p) = VT_BSTR;
420 hres = nscolor_to_str(color, &V_BSTR(p));
421 }else {
422 ERR("SetBgColor failed: %08x\n", nsres);
423 hres = E_FAIL;
426 nsAString_Finish(&strColor);
427 return hres;
430 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
432 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
433 nsAString text;
434 nsresult nsres;
436 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
438 if(!variant_to_nscolor(&v, &text))
439 return S_OK;
441 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
442 nsAString_Finish(&text);
443 if(NS_FAILED(nsres)) {
444 ERR("SetText failed: %08x\n", nsres);
445 return E_FAIL;
448 return S_OK;
451 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
453 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
454 nsAString text;
455 nsresult nsres;
456 HRESULT hres;
458 TRACE("(%p)->(%p)\n", This, p);
460 nsAString_Init(&text, NULL);
461 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
462 if(NS_SUCCEEDED(nsres)) {
463 const PRUnichar *color;
465 nsAString_GetData(&text, &color);
466 V_VT(p) = VT_BSTR;
467 hres = nscolor_to_str(color, &V_BSTR(p));
468 }else {
469 ERR("GetText failed: %08x\n", nsres);
470 hres = E_FAIL;
473 nsAString_Finish(&text);
475 return hres;
478 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
480 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
481 nsAString link_str;
482 nsresult nsres;
484 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
486 if(!variant_to_nscolor(&v, &link_str))
487 return S_OK;
489 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
490 nsAString_Finish(&link_str);
491 if(NS_FAILED(nsres))
492 ERR("SetLink failed: %08x\n", nsres);
494 return S_OK;
497 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
499 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
500 nsAString link_str;
501 nsresult nsres;
503 TRACE("(%p)->(%p)\n", This, p);
505 nsAString_Init(&link_str, NULL);
506 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
507 return return_nscolor(nsres, &link_str, p);
510 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
512 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
513 nsAString vlink_str;
514 nsresult nsres;
516 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
518 if(!variant_to_nscolor(&v, &vlink_str))
519 return S_OK;
521 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
522 nsAString_Finish(&vlink_str);
523 if(NS_FAILED(nsres))
524 ERR("SetLink failed: %08x\n", nsres);
526 return S_OK;
529 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
531 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
532 nsAString vlink_str;
533 nsresult nsres;
535 TRACE("(%p)->(%p)\n", This, p);
537 nsAString_Init(&vlink_str, NULL);
538 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
539 return return_nscolor(nsres, &vlink_str, p);
542 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
544 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
545 nsAString alink_str;
546 nsresult nsres;
548 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
550 if(!variant_to_nscolor(&v, &alink_str))
551 return S_OK;
553 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
554 nsAString_Finish(&alink_str);
555 if(NS_FAILED(nsres))
556 ERR("SetALink failed: %08x\n", nsres);
558 return S_OK;
561 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
563 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
564 nsAString alink_str;
565 nsresult nsres;
567 TRACE("(%p)->(%p)\n", This, p);
569 nsAString_Init(&alink_str, NULL);
570 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
571 return return_nscolor(nsres, &alink_str, p);
574 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
576 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
578 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
580 return set_node_event(&This->textcont.element.node, EVENTID_LOAD, &v);
583 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
585 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
587 TRACE("(%p)->(%p)\n", This, p);
589 return get_node_event(&This->textcont.element.node, EVENTID_LOAD, p);
592 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
594 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
595 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
596 return E_NOTIMPL;
599 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
601 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
602 FIXME("(%p)->(%p)\n", This, p);
603 return E_NOTIMPL;
606 static const WCHAR autoW[] = {'a','u','t','o',0};
607 static const WCHAR hiddenW[] = {'h','i','d','d','e','n',0};
608 static const WCHAR scrollW[] = {'s','c','r','o','l','l',0};
609 static const WCHAR visibleW[] = {'v','i','s','i','b','l','e',0};
610 static const WCHAR yesW[] = {'y','e','s',0};
611 static const WCHAR noW[] = {'n','o',0};
613 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
615 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
616 static const WCHAR *val;
618 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
620 /* Emulate with CSS visibility attribute */
621 if(!strcmpW(v, yesW)) {
622 val = scrollW;
623 }else if(!strcmpW(v, autoW)) {
624 val = visibleW;
625 }else if(!strcmpW(v, noW)) {
626 val = hiddenW;
627 }else {
628 WARN("Invalid argument %s\n", debugstr_w(v));
629 return E_INVALIDARG;
632 return set_elem_style(&This->textcont.element, STYLEID_OVERFLOW, val);
635 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
637 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
638 const WCHAR *ret = NULL;
639 BSTR overflow;
640 HRESULT hres;
642 TRACE("(%p)->(%p)\n", This, p);
644 /* Emulate with CSS visibility attribute */
645 hres = get_elem_style(&This->textcont.element, STYLEID_OVERFLOW, &overflow);
646 if(FAILED(hres))
647 return hres;
649 if(!overflow || !*overflow) {
650 *p = NULL;
651 hres = S_OK;
652 }else if(!strcmpW(overflow, visibleW) || !strcmpW(overflow, autoW)) {
653 ret = autoW;
654 }else if(!strcmpW(overflow, scrollW)) {
655 ret = yesW;
656 }else if(!strcmpW(overflow, hiddenW)) {
657 ret = noW;
658 }else {
659 TRACE("Defaulting %s to NULL\n", debugstr_w(overflow));
660 *p = NULL;
661 hres = S_OK;
664 SysFreeString(overflow);
665 if(ret) {
666 *p = SysAllocString(ret);
667 hres = *p ? S_OK : E_OUTOFMEMORY;
670 return hres;
673 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
675 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
676 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
677 return E_NOTIMPL;
680 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
682 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
683 FIXME("(%p)->(%p)\n", This, p);
684 return E_NOTIMPL;
687 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
689 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
690 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
691 return E_NOTIMPL;
694 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
696 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
697 FIXME("(%p)->(%p)\n", This, p);
698 return E_NOTIMPL;
701 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
703 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
704 nsIDOMRange *nsrange = NULL;
705 nsresult nsres;
706 HRESULT hres;
708 TRACE("(%p)->(%p)\n", This, range);
710 if(!This->textcont.element.node.doc->nsdoc) {
711 WARN("No nsdoc\n");
712 return E_UNEXPECTED;
715 nsres = nsIDOMHTMLDocument_CreateRange(This->textcont.element.node.doc->nsdoc, &nsrange);
716 if(NS_SUCCEEDED(nsres)) {
717 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->textcont.element.node.nsnode);
718 if(NS_FAILED(nsres))
719 ERR("SelectNodeContents failed: %08x\n", nsres);
720 }else {
721 ERR("CreateRange failed: %08x\n", nsres);
724 hres = HTMLTxtRange_Create(This->textcont.element.node.doc->basedoc.doc_node, nsrange, range);
726 nsIDOMRange_Release(nsrange);
727 return hres;
730 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
731 HTMLBodyElement_QueryInterface,
732 HTMLBodyElement_AddRef,
733 HTMLBodyElement_Release,
734 HTMLBodyElement_GetTypeInfoCount,
735 HTMLBodyElement_GetTypeInfo,
736 HTMLBodyElement_GetIDsOfNames,
737 HTMLBodyElement_Invoke,
738 HTMLBodyElement_put_background,
739 HTMLBodyElement_get_background,
740 HTMLBodyElement_put_bgProperties,
741 HTMLBodyElement_get_bgProperties,
742 HTMLBodyElement_put_leftMargin,
743 HTMLBodyElement_get_leftMargin,
744 HTMLBodyElement_put_topMargin,
745 HTMLBodyElement_get_topMargin,
746 HTMLBodyElement_put_rightMargin,
747 HTMLBodyElement_get_rightMargin,
748 HTMLBodyElement_put_bottomMargin,
749 HTMLBodyElement_get_bottomMargin,
750 HTMLBodyElement_put_noWrap,
751 HTMLBodyElement_get_noWrap,
752 HTMLBodyElement_put_bgColor,
753 HTMLBodyElement_get_bgColor,
754 HTMLBodyElement_put_text,
755 HTMLBodyElement_get_text,
756 HTMLBodyElement_put_link,
757 HTMLBodyElement_get_link,
758 HTMLBodyElement_put_vLink,
759 HTMLBodyElement_get_vLink,
760 HTMLBodyElement_put_aLink,
761 HTMLBodyElement_get_aLink,
762 HTMLBodyElement_put_onload,
763 HTMLBodyElement_get_onload,
764 HTMLBodyElement_put_onunload,
765 HTMLBodyElement_get_onunload,
766 HTMLBodyElement_put_scroll,
767 HTMLBodyElement_get_scroll,
768 HTMLBodyElement_put_onselect,
769 HTMLBodyElement_get_onselect,
770 HTMLBodyElement_put_onbeforeunload,
771 HTMLBodyElement_get_onbeforeunload,
772 HTMLBodyElement_createTextRange
775 static inline HTMLBodyElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
777 return CONTAINING_RECORD(iface, HTMLBodyElement, textcont.element.node);
780 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
782 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
784 *ppv = NULL;
786 if(IsEqualGUID(&IID_IUnknown, riid)) {
787 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
788 *ppv = &This->IHTMLBodyElement_iface;
789 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
790 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
791 *ppv = &This->IHTMLBodyElement_iface;
792 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
793 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
794 *ppv = &This->IHTMLBodyElement_iface;
795 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
796 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", &This->textcont, ppv);
797 *ppv = &This->textcont.IHTMLTextContainer_iface;
800 if(*ppv) {
801 IUnknown_AddRef((IUnknown*)*ppv);
802 return S_OK;
805 return HTMLElement_QI(&This->textcont.element.node, riid, ppv);
808 static void HTMLBodyElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
810 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
812 if(This->nsbody)
813 note_cc_edge((nsISupports*)This->nsbody, "This->nsbody", cb);
816 static void HTMLBodyElement_unlink(HTMLDOMNode *iface)
818 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
820 if(This->nsbody) {
821 nsIDOMHTMLBodyElement *nsbody = This->nsbody;
822 This->nsbody = NULL;
823 nsIDOMHTMLBodyElement_Release(nsbody);
827 static event_target_t **HTMLBodyElement_get_event_target_ptr(HTMLDOMNode *iface)
829 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
831 return This->textcont.element.node.doc
832 ? &This->textcont.element.node.doc->body_event_target
833 : &This->textcont.element.node.event_target.ptr;
836 static BOOL HTMLBodyElement_is_text_edit(HTMLDOMNode *iface)
838 return TRUE;
841 static const cpc_entry_t HTMLBodyElement_cpc[] = {
842 {&DIID_HTMLTextContainerEvents},
843 {&IID_IPropertyNotifySink},
844 HTMLELEMENT_CPC,
845 {NULL}
848 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
849 HTMLBodyElement_QI,
850 HTMLElement_destructor,
851 HTMLBodyElement_cpc,
852 HTMLElement_clone,
853 HTMLElement_handle_event,
854 HTMLElement_get_attr_col,
855 HTMLBodyElement_get_event_target_ptr,
856 NULL,
857 NULL,
858 NULL,
859 NULL,
860 NULL,
861 NULL,
862 NULL,
863 NULL,
864 HTMLBodyElement_traverse,
865 HTMLBodyElement_unlink,
866 HTMLBodyElement_is_text_edit
869 static const tid_t HTMLBodyElement_iface_tids[] = {
870 IHTMLBodyElement_tid,
871 IHTMLBodyElement2_tid,
872 HTMLELEMENT_TIDS,
873 IHTMLTextContainer_tid,
874 IHTMLUniqueName_tid,
878 static dispex_static_data_t HTMLBodyElement_dispex = {
879 NULL,
880 DispHTMLBody_tid,
881 NULL,
882 HTMLBodyElement_iface_tids
885 HRESULT HTMLBodyElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
887 HTMLBodyElement *ret;
888 nsresult nsres;
890 ret = heap_alloc_zero(sizeof(HTMLBodyElement));
891 if(!ret)
892 return E_OUTOFMEMORY;
894 ret->IHTMLBodyElement_iface.lpVtbl = &HTMLBodyElementVtbl;
895 ret->textcont.element.node.vtbl = &HTMLBodyElementImplVtbl;
897 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement, (void**)&ret->nsbody);
898 if(NS_FAILED(nsres)) {
899 ERR("Could not get nsDOMHTMLBodyElement: %08x\n", nsres);
900 heap_free(ret);
901 return E_OUTOFMEMORY;
904 HTMLTextContainer_Init(&ret->textcont, doc, nselem, &HTMLBodyElement_dispex);
906 *elem = &ret->textcont.element;
907 return S_OK;