mshtml: Fix spelling of fuchsia.
[wine.git] / dlls / mshtml / htmlbody.c
blob4209fd2cc2e98977538380774ca62c85f13014ed
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>
21 #include <assert.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29 #include "mshtmdid.h"
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
34 #include "htmlevent.h"
35 #include "htmlstyle.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 typedef struct {
40 HTMLElement element;
42 IHTMLBodyElement IHTMLBodyElement_iface;
43 IHTMLTextContainer IHTMLTextContainer_iface;
45 nsIDOMHTMLBodyElement *nsbody;
46 } HTMLBodyElement;
48 static const struct {
49 LPCWSTR keyword;
50 DWORD rgb;
51 } keyword_table[] = {
52 {L"aqua", 0x00ffff},
53 {L"black", 0x000000},
54 {L"blue", 0x0000ff},
55 {L"fuchsia", 0xff00ff},
56 {L"gray", 0x808080},
57 {L"green", 0x008000},
58 {L"lime", 0x00ff00},
59 {L"maroon", 0x800000},
60 {L"navy", 0x000080},
61 {L"olive", 0x808000},
62 {L"purple", 0x800080},
63 {L"red", 0xff0000},
64 {L"silver", 0xc0c0c0},
65 {L"teal", 0x008080},
66 {L"white", 0xffffff},
67 {L"yellow", 0xffff00}
70 static int comp_value(const WCHAR *ptr, int dpc)
72 int ret = 0;
73 WCHAR ch;
75 if(dpc > 2)
76 dpc = 2;
78 while(dpc--) {
79 if(!*ptr)
80 ret *= 16;
81 else if(is_digit(ch = *ptr++))
82 ret = ret*16 + (ch-'0');
83 else if('a' <= ch && ch <= 'f')
84 ret = ret*16 + (ch-'a') + 10;
85 else if('A' <= ch && ch <= 'F')
86 ret = ret*16 + (ch-'A') + 10;
87 else
88 ret *= 16;
91 return ret;
94 /* Based on Gecko NS_LooseHexToRGB */
95 static int loose_hex_to_rgb(const WCHAR *hex)
97 int len, dpc;
99 len = lstrlenW(hex);
100 if(*hex == '#') {
101 hex++;
102 len--;
104 if(len <= 3)
105 return 0;
107 dpc = min(len/3 + (len%3 ? 1 : 0), 4);
108 return (comp_value(hex, dpc) << 16)
109 | (comp_value(hex+dpc, dpc) << 8)
110 | comp_value(hex+2*dpc, dpc);
113 HRESULT nscolor_to_str(LPCWSTR color, BSTR *ret)
115 unsigned int i;
116 int rgb = -1;
118 static const WCHAR formatW[] = {'#','%','0','2','x','%','0','2','x','%','0','2','x',0};
120 if(!color || !*color) {
121 *ret = NULL;
122 return S_OK;
125 if(*color != '#') {
126 for(i=0; i < ARRAY_SIZE(keyword_table); i++) {
127 if(!wcsicmp(color, keyword_table[i].keyword))
128 rgb = keyword_table[i].rgb;
131 if(rgb == -1)
132 rgb = loose_hex_to_rgb(color);
134 *ret = SysAllocStringLen(NULL, 7);
135 if(!*ret)
136 return E_OUTOFMEMORY;
138 swprintf(*ret, 8, formatW, rgb>>16, (rgb>>8)&0xff, rgb&0xff);
140 TRACE("%s -> %s\n", debugstr_w(color), debugstr_w(*ret));
141 return S_OK;
144 BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
146 switch(V_VT(v)) {
147 case VT_BSTR:
148 nsAString_Init(nsstr, V_BSTR(v));
149 return TRUE;
151 case VT_I4: {
152 PRUnichar buf[10];
153 static const WCHAR formatW[] = {'#','%','x',0};
155 wsprintfW(buf, formatW, V_I4(v));
156 nsAString_Init(nsstr, buf);
157 return TRUE;
160 default:
161 FIXME("invalid color %s\n", debugstr_variant(v));
164 return FALSE;
168 static HRESULT return_nscolor(nsresult nsres, nsAString *nsstr, VARIANT *p)
170 const PRUnichar *color;
172 if(NS_FAILED(nsres)) {
173 ERR("failed: %08x\n", nsres);
174 nsAString_Finish(nsstr);
175 return E_FAIL;
178 nsAString_GetData(nsstr, &color);
180 if(*color == '#') {
181 V_VT(p) = VT_I4;
182 V_I4(p) = wcstol(color+1, NULL, 16);
183 }else {
184 V_VT(p) = VT_BSTR;
185 V_BSTR(p) = SysAllocString(color);
186 if(!V_BSTR(p)) {
187 nsAString_Finish(nsstr);
188 return E_OUTOFMEMORY;
192 nsAString_Finish(nsstr);
193 TRACE("ret %s\n", debugstr_variant(p));
194 return S_OK;
197 static inline HTMLBodyElement *impl_from_IHTMLBodyElement(IHTMLBodyElement *iface)
199 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLBodyElement_iface);
202 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
203 REFIID riid, void **ppv)
205 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
207 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
210 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
212 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
214 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
217 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
219 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
221 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
224 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
226 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
227 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface,
228 pctinfo);
231 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
232 LCID lcid, ITypeInfo **ppTInfo)
234 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
235 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo,
236 lcid, ppTInfo);
239 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
240 LPOLESTR *rgszNames, UINT cNames,
241 LCID lcid, DISPID *rgDispId)
243 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
244 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid,
245 rgszNames, cNames, lcid, rgDispId);
248 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
249 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
250 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
252 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
253 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember,
254 riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
257 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
259 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
260 nsAString nsstr;
261 nsresult nsres;
263 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
265 nsAString_InitDepend(&nsstr, v);
266 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
267 nsAString_Finish(&nsstr);
268 if(NS_FAILED(nsres))
269 return E_FAIL;
271 return S_OK;
274 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
276 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
277 nsAString background_str;
278 nsresult nsres;
280 TRACE("(%p)->(%p)\n", This, p);
282 nsAString_Init(&background_str, NULL);
283 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
284 return return_nsstr(nsres, &background_str, p);
287 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
289 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
290 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
291 return E_NOTIMPL;
294 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
296 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
297 FIXME("(%p)->(%p)\n", This, p);
298 return E_NOTIMPL;
301 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
303 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
304 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *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_topMargin(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_topMargin(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_rightMargin(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_rightMargin(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_bottomMargin(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_bottomMargin(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_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
359 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
360 FIXME("(%p)->(%x)\n", This, v);
361 return E_NOTIMPL;
364 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *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_bgColor(IHTMLBodyElement *iface, VARIANT v)
373 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
374 nsAString strColor;
375 nsresult nsres;
377 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
379 if(!variant_to_nscolor(&v, &strColor))
380 return S_OK;
382 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
383 nsAString_Finish(&strColor);
384 if(NS_FAILED(nsres))
385 ERR("SetBgColor failed: %08x\n", nsres);
387 return S_OK;
390 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
392 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
393 nsAString nsstr;
394 nsresult nsres;
396 TRACE("(%p)->(%p)\n", This, p);
398 nsAString_Init(&nsstr, NULL);
399 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &nsstr);
400 return return_nsstr_variant(nsres, &nsstr, NSSTR_COLOR, p);
403 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
405 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
406 nsAString text;
407 nsresult nsres;
409 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
411 if(!variant_to_nscolor(&v, &text))
412 return S_OK;
414 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
415 nsAString_Finish(&text);
416 if(NS_FAILED(nsres)) {
417 ERR("SetText failed: %08x\n", nsres);
418 return E_FAIL;
421 return S_OK;
424 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
426 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
427 nsAString text;
428 nsresult nsres;
429 HRESULT hres;
431 TRACE("(%p)->(%p)\n", This, p);
433 nsAString_Init(&text, NULL);
434 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
435 if(NS_SUCCEEDED(nsres)) {
436 const PRUnichar *color;
438 nsAString_GetData(&text, &color);
439 V_VT(p) = VT_BSTR;
440 hres = nscolor_to_str(color, &V_BSTR(p));
441 }else {
442 ERR("GetText failed: %08x\n", nsres);
443 hres = E_FAIL;
446 nsAString_Finish(&text);
448 return hres;
451 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
453 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
454 nsAString link_str;
455 nsresult nsres;
457 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
459 if(!variant_to_nscolor(&v, &link_str))
460 return S_OK;
462 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
463 nsAString_Finish(&link_str);
464 if(NS_FAILED(nsres))
465 ERR("SetLink failed: %08x\n", nsres);
467 return S_OK;
470 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
472 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
473 nsAString link_str;
474 nsresult nsres;
476 TRACE("(%p)->(%p)\n", This, p);
478 nsAString_Init(&link_str, NULL);
479 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
480 return return_nscolor(nsres, &link_str, p);
483 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
485 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
486 nsAString vlink_str;
487 nsresult nsres;
489 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
491 if(!variant_to_nscolor(&v, &vlink_str))
492 return S_OK;
494 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
495 nsAString_Finish(&vlink_str);
496 if(NS_FAILED(nsres))
497 ERR("SetLink failed: %08x\n", nsres);
499 return S_OK;
502 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
504 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
505 nsAString vlink_str;
506 nsresult nsres;
508 TRACE("(%p)->(%p)\n", This, p);
510 nsAString_Init(&vlink_str, NULL);
511 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
512 return return_nscolor(nsres, &vlink_str, p);
515 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
517 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
518 nsAString alink_str;
519 nsresult nsres;
521 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
523 if(!variant_to_nscolor(&v, &alink_str))
524 return S_OK;
526 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
527 nsAString_Finish(&alink_str);
528 if(NS_FAILED(nsres))
529 ERR("SetALink failed: %08x\n", nsres);
531 return S_OK;
534 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
536 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
537 nsAString alink_str;
538 nsresult nsres;
540 TRACE("(%p)->(%p)\n", This, p);
542 nsAString_Init(&alink_str, NULL);
543 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
544 return return_nscolor(nsres, &alink_str, p);
547 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
549 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
551 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
553 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
556 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
558 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
560 TRACE("(%p)->(%p)\n", This, p);
562 return get_node_event(&This->element.node, EVENTID_LOAD, p);
565 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
567 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
568 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
569 return E_NOTIMPL;
572 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
574 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
575 FIXME("(%p)->(%p)\n", This, p);
576 return E_NOTIMPL;
579 static const WCHAR autoW[] = {'a','u','t','o',0};
580 static const WCHAR hiddenW[] = {'h','i','d','d','e','n',0};
581 static const WCHAR scrollW[] = {'s','c','r','o','l','l',0};
582 static const WCHAR visibleW[] = {'v','i','s','i','b','l','e',0};
583 static const WCHAR yesW[] = {'y','e','s',0};
584 static const WCHAR noW[] = {'n','o',0};
586 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
588 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
589 static const WCHAR *val;
591 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
593 /* Emulate with CSS visibility attribute */
594 if(!wcscmp(v, yesW)) {
595 val = scrollW;
596 }else if(!wcscmp(v, autoW)) {
597 val = visibleW;
598 }else if(!wcscmp(v, noW)) {
599 val = hiddenW;
600 }else {
601 WARN("Invalid argument %s\n", debugstr_w(v));
602 return E_INVALIDARG;
605 return set_elem_style(&This->element, STYLEID_OVERFLOW, val);
608 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
610 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
611 const WCHAR *ret = NULL;
612 BSTR overflow;
613 HRESULT hres;
615 TRACE("(%p)->(%p)\n", This, p);
617 /* Emulate with CSS visibility attribute */
618 hres = get_elem_style(&This->element, STYLEID_OVERFLOW, &overflow);
619 if(FAILED(hres))
620 return hres;
622 if(!overflow || !*overflow) {
623 *p = NULL;
624 hres = S_OK;
625 }else if(!wcscmp(overflow, visibleW) || !wcscmp(overflow, autoW)) {
626 ret = autoW;
627 }else if(!wcscmp(overflow, scrollW)) {
628 ret = yesW;
629 }else if(!wcscmp(overflow, hiddenW)) {
630 ret = noW;
631 }else {
632 TRACE("Defaulting %s to NULL\n", debugstr_w(overflow));
633 *p = NULL;
634 hres = S_OK;
637 SysFreeString(overflow);
638 if(ret) {
639 *p = SysAllocString(ret);
640 hres = *p ? S_OK : E_OUTOFMEMORY;
643 return hres;
646 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
648 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
649 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
650 return E_NOTIMPL;
653 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
655 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
656 FIXME("(%p)->(%p)\n", This, p);
657 return E_NOTIMPL;
660 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
662 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
663 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
664 return E_NOTIMPL;
667 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
669 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
670 FIXME("(%p)->(%p)\n", This, p);
671 return E_NOTIMPL;
674 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
676 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
677 nsIDOMRange *nsrange = NULL;
678 nsresult nsres;
679 HRESULT hres;
681 TRACE("(%p)->(%p)\n", This, range);
683 if(!This->element.node.doc->nsdoc) {
684 WARN("No nsdoc\n");
685 return E_UNEXPECTED;
688 nsres = nsIDOMHTMLDocument_CreateRange(This->element.node.doc->nsdoc, &nsrange);
689 if(NS_SUCCEEDED(nsres)) {
690 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->element.node.nsnode);
691 if(NS_FAILED(nsres))
692 ERR("SelectNodeContents failed: %08x\n", nsres);
693 }else {
694 ERR("CreateRange failed: %08x\n", nsres);
697 hres = HTMLTxtRange_Create(This->element.node.doc->basedoc.doc_node, nsrange, range);
699 nsIDOMRange_Release(nsrange);
700 return hres;
703 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
704 HTMLBodyElement_QueryInterface,
705 HTMLBodyElement_AddRef,
706 HTMLBodyElement_Release,
707 HTMLBodyElement_GetTypeInfoCount,
708 HTMLBodyElement_GetTypeInfo,
709 HTMLBodyElement_GetIDsOfNames,
710 HTMLBodyElement_Invoke,
711 HTMLBodyElement_put_background,
712 HTMLBodyElement_get_background,
713 HTMLBodyElement_put_bgProperties,
714 HTMLBodyElement_get_bgProperties,
715 HTMLBodyElement_put_leftMargin,
716 HTMLBodyElement_get_leftMargin,
717 HTMLBodyElement_put_topMargin,
718 HTMLBodyElement_get_topMargin,
719 HTMLBodyElement_put_rightMargin,
720 HTMLBodyElement_get_rightMargin,
721 HTMLBodyElement_put_bottomMargin,
722 HTMLBodyElement_get_bottomMargin,
723 HTMLBodyElement_put_noWrap,
724 HTMLBodyElement_get_noWrap,
725 HTMLBodyElement_put_bgColor,
726 HTMLBodyElement_get_bgColor,
727 HTMLBodyElement_put_text,
728 HTMLBodyElement_get_text,
729 HTMLBodyElement_put_link,
730 HTMLBodyElement_get_link,
731 HTMLBodyElement_put_vLink,
732 HTMLBodyElement_get_vLink,
733 HTMLBodyElement_put_aLink,
734 HTMLBodyElement_get_aLink,
735 HTMLBodyElement_put_onload,
736 HTMLBodyElement_get_onload,
737 HTMLBodyElement_put_onunload,
738 HTMLBodyElement_get_onunload,
739 HTMLBodyElement_put_scroll,
740 HTMLBodyElement_get_scroll,
741 HTMLBodyElement_put_onselect,
742 HTMLBodyElement_get_onselect,
743 HTMLBodyElement_put_onbeforeunload,
744 HTMLBodyElement_get_onbeforeunload,
745 HTMLBodyElement_createTextRange
748 static inline HTMLBodyElement *impl_from_IHTMLTextContainer(IHTMLTextContainer *iface)
750 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLTextContainer_iface);
753 static HRESULT WINAPI HTMLTextContainer_QueryInterface(IHTMLTextContainer *iface,
754 REFIID riid, void **ppv)
756 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
757 return IHTMLElement_QueryInterface(&This->element.IHTMLElement_iface, riid, ppv);
760 static ULONG WINAPI HTMLTextContainer_AddRef(IHTMLTextContainer *iface)
762 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
763 return IHTMLElement_AddRef(&This->element.IHTMLElement_iface);
766 static ULONG WINAPI HTMLTextContainer_Release(IHTMLTextContainer *iface)
768 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
769 return IHTMLElement_Release(&This->element.IHTMLElement_iface);
772 static HRESULT WINAPI HTMLTextContainer_GetTypeInfoCount(IHTMLTextContainer *iface, UINT *pctinfo)
774 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
775 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
778 static HRESULT WINAPI HTMLTextContainer_GetTypeInfo(IHTMLTextContainer *iface, UINT iTInfo,
779 LCID lcid, ITypeInfo **ppTInfo)
781 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
782 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
783 ppTInfo);
786 static HRESULT WINAPI HTMLTextContainer_GetIDsOfNames(IHTMLTextContainer *iface, REFIID riid,
787 LPOLESTR *rgszNames, UINT cNames,
788 LCID lcid, DISPID *rgDispId)
790 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
791 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
792 cNames, lcid, rgDispId);
795 static HRESULT WINAPI HTMLTextContainer_Invoke(IHTMLTextContainer *iface, DISPID dispIdMember,
796 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
797 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
799 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
800 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
801 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
804 static HRESULT WINAPI HTMLTextContainer_createControlRange(IHTMLTextContainer *iface,
805 IDispatch **range)
807 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
808 FIXME("(%p)->(%p)\n", This, range);
809 return E_NOTIMPL;
812 static HRESULT WINAPI HTMLTextContainer_get_scrollHeight(IHTMLTextContainer *iface, LONG *p)
814 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
816 TRACE("(%p)->(%p)\n", This, p);
818 return IHTMLElement2_get_scrollHeight(&This->element.IHTMLElement2_iface, p);
821 static HRESULT WINAPI HTMLTextContainer_get_scrollWidth(IHTMLTextContainer *iface, LONG *p)
823 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
825 TRACE("(%p)->(%p)\n", This, p);
827 return IHTMLElement2_get_scrollWidth(&This->element.IHTMLElement2_iface, p);
830 static HRESULT WINAPI HTMLTextContainer_put_scrollTop(IHTMLTextContainer *iface, LONG v)
832 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
834 TRACE("(%p)->(%d)\n", This, v);
836 return IHTMLElement2_put_scrollTop(&This->element.IHTMLElement2_iface, v);
839 static HRESULT WINAPI HTMLTextContainer_get_scrollTop(IHTMLTextContainer *iface, LONG *p)
841 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
843 TRACE("(%p)->(%p)\n", This, p);
845 return IHTMLElement2_get_scrollTop(&This->element.IHTMLElement2_iface, p);
848 static HRESULT WINAPI HTMLTextContainer_put_scrollLeft(IHTMLTextContainer *iface, LONG v)
850 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
852 TRACE("(%p)->(%d)\n", This, v);
854 return IHTMLElement2_put_scrollLeft(&This->element.IHTMLElement2_iface, v);
857 static HRESULT WINAPI HTMLTextContainer_get_scrollLeft(IHTMLTextContainer *iface, LONG *p)
859 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
861 TRACE("(%p)->(%p)\n", This, p);
863 return IHTMLElement2_get_scrollLeft(&This->element.IHTMLElement2_iface, p);
866 static HRESULT WINAPI HTMLTextContainer_put_onscroll(IHTMLTextContainer *iface, VARIANT v)
868 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
869 FIXME("(%p)->()\n", This);
870 return E_NOTIMPL;
873 static HRESULT WINAPI HTMLTextContainer_get_onscroll(IHTMLTextContainer *iface, VARIANT *p)
875 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
876 FIXME("(%p)->(%p)\n", This, p);
877 return E_NOTIMPL;
880 static const IHTMLTextContainerVtbl HTMLTextContainerVtbl = {
881 HTMLTextContainer_QueryInterface,
882 HTMLTextContainer_AddRef,
883 HTMLTextContainer_Release,
884 HTMLTextContainer_GetTypeInfoCount,
885 HTMLTextContainer_GetTypeInfo,
886 HTMLTextContainer_GetIDsOfNames,
887 HTMLTextContainer_Invoke,
888 HTMLTextContainer_createControlRange,
889 HTMLTextContainer_get_scrollHeight,
890 HTMLTextContainer_get_scrollWidth,
891 HTMLTextContainer_put_scrollTop,
892 HTMLTextContainer_get_scrollTop,
893 HTMLTextContainer_put_scrollLeft,
894 HTMLTextContainer_get_scrollLeft,
895 HTMLTextContainer_put_onscroll,
896 HTMLTextContainer_get_onscroll
899 static inline HTMLBodyElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
901 return CONTAINING_RECORD(iface, HTMLBodyElement, element.node);
904 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
906 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
908 *ppv = NULL;
910 if(IsEqualGUID(&IID_IUnknown, riid)) {
911 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
912 *ppv = &This->IHTMLBodyElement_iface;
913 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
914 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
915 *ppv = &This->IHTMLBodyElement_iface;
916 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
917 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
918 *ppv = &This->IHTMLBodyElement_iface;
919 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
920 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", This, ppv);
921 *ppv = &This->IHTMLTextContainer_iface;
924 if(*ppv) {
925 IUnknown_AddRef((IUnknown*)*ppv);
926 return S_OK;
929 return HTMLElement_QI(&This->element.node, riid, ppv);
932 static void HTMLBodyElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
934 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
936 if(This->nsbody)
937 note_cc_edge((nsISupports*)This->nsbody, "This->nsbody", cb);
940 static void HTMLBodyElement_unlink(HTMLDOMNode *iface)
942 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
944 if(This->nsbody) {
945 nsIDOMHTMLBodyElement *nsbody = This->nsbody;
946 This->nsbody = NULL;
947 nsIDOMHTMLBodyElement_Release(nsbody);
951 static EventTarget *HTMLBodyElement_get_event_prop_target(HTMLDOMNode *iface, int event_id)
953 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
955 switch(event_id) {
956 case EVENTID_BLUR:
957 case EVENTID_ERROR:
958 case EVENTID_FOCUS:
959 case EVENTID_LOAD:
960 case EVENTID_SCROLL:
961 return This->element.node.doc && This->element.node.doc->window
962 ? &This->element.node.doc->window->event_target
963 : &This->element.node.event_target;
964 default:
965 return &This->element.node.event_target;
969 static BOOL HTMLBodyElement_is_text_edit(HTMLDOMNode *iface)
971 return TRUE;
974 static BOOL HTMLBodyElement_is_settable(HTMLDOMNode *iface, DISPID dispid)
976 switch(dispid) {
977 case DISPID_IHTMLELEMENT_OUTERTEXT:
978 return FALSE;
979 default:
980 return TRUE;
984 static const cpc_entry_t HTMLBodyElement_cpc[] = {
985 {&DIID_HTMLTextContainerEvents},
986 {&IID_IPropertyNotifySink},
987 HTMLELEMENT_CPC,
988 {NULL}
991 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
992 &CLSID_HTMLBody,
993 HTMLBodyElement_QI,
994 HTMLElement_destructor,
995 HTMLBodyElement_cpc,
996 HTMLElement_clone,
997 HTMLElement_handle_event,
998 HTMLElement_get_attr_col,
999 HTMLBodyElement_get_event_prop_target,
1000 NULL,
1001 NULL,
1002 NULL,
1003 NULL,
1004 NULL,
1005 NULL,
1006 NULL,
1007 HTMLBodyElement_traverse,
1008 HTMLBodyElement_unlink,
1009 HTMLBodyElement_is_text_edit,
1010 HTMLBodyElement_is_settable
1013 static const tid_t HTMLBodyElement_iface_tids[] = {
1014 IHTMLBodyElement_tid,
1015 IHTMLBodyElement2_tid,
1016 HTMLELEMENT_TIDS,
1017 IHTMLTextContainer_tid,
1021 static dispex_static_data_t HTMLBodyElement_dispex = {
1022 NULL,
1023 DispHTMLBody_tid,
1024 HTMLBodyElement_iface_tids,
1025 HTMLElement_init_dispex_info
1028 HRESULT HTMLBodyElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
1030 HTMLBodyElement *ret;
1031 nsresult nsres;
1033 ret = heap_alloc_zero(sizeof(HTMLBodyElement));
1034 if(!ret)
1035 return E_OUTOFMEMORY;
1037 ret->IHTMLBodyElement_iface.lpVtbl = &HTMLBodyElementVtbl;
1038 ret->IHTMLTextContainer_iface.lpVtbl = &HTMLTextContainerVtbl;
1039 ret->element.node.vtbl = &HTMLBodyElementImplVtbl;
1041 HTMLElement_Init(&ret->element, doc, nselem, &HTMLBodyElement_dispex);
1043 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement, (void**)&ret->nsbody);
1044 assert(nsres == NS_OK);
1046 *elem = &ret->element;
1047 return S_OK;