wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / mshtml / htmlbody.c
blob9955a8e64987903dbd31394c56deb16427e07a58
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 if(!color || !*color) {
119 *ret = NULL;
120 return S_OK;
123 if(*color != '#') {
124 for(i=0; i < ARRAY_SIZE(keyword_table); i++) {
125 if(!wcsicmp(color, keyword_table[i].keyword))
126 rgb = keyword_table[i].rgb;
129 if(rgb == -1)
130 rgb = loose_hex_to_rgb(color);
132 *ret = SysAllocStringLen(NULL, 7);
133 if(!*ret)
134 return E_OUTOFMEMORY;
136 swprintf(*ret, 8, L"#%02x%02x%02x", rgb>>16, (rgb>>8)&0xff, rgb&0xff);
138 TRACE("%s -> %s\n", debugstr_w(color), debugstr_w(*ret));
139 return S_OK;
142 BOOL variant_to_nscolor(const VARIANT *v, nsAString *nsstr)
144 switch(V_VT(v)) {
145 case VT_BSTR:
146 nsAString_Init(nsstr, V_BSTR(v));
147 return TRUE;
149 case VT_I4: {
150 PRUnichar buf[10];
152 wsprintfW(buf, L"#%x", V_I4(v));
153 nsAString_Init(nsstr, buf);
154 return TRUE;
157 default:
158 FIXME("invalid color %s\n", debugstr_variant(v));
161 return FALSE;
165 static HRESULT return_nscolor(nsresult nsres, nsAString *nsstr, VARIANT *p)
167 const PRUnichar *color;
169 if(NS_FAILED(nsres)) {
170 ERR("failed: %08x\n", nsres);
171 nsAString_Finish(nsstr);
172 return E_FAIL;
175 nsAString_GetData(nsstr, &color);
177 if(*color == '#') {
178 V_VT(p) = VT_I4;
179 V_I4(p) = wcstol(color+1, NULL, 16);
180 }else {
181 V_VT(p) = VT_BSTR;
182 V_BSTR(p) = SysAllocString(color);
183 if(!V_BSTR(p)) {
184 nsAString_Finish(nsstr);
185 return E_OUTOFMEMORY;
189 nsAString_Finish(nsstr);
190 TRACE("ret %s\n", debugstr_variant(p));
191 return S_OK;
194 static inline HTMLBodyElement *impl_from_IHTMLBodyElement(IHTMLBodyElement *iface)
196 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLBodyElement_iface);
199 static HRESULT WINAPI HTMLBodyElement_QueryInterface(IHTMLBodyElement *iface,
200 REFIID riid, void **ppv)
202 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
204 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
207 static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
209 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
211 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
214 static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
216 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
218 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
221 static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
223 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
224 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface,
225 pctinfo);
228 static HRESULT WINAPI HTMLBodyElement_GetTypeInfo(IHTMLBodyElement *iface, UINT iTInfo,
229 LCID lcid, ITypeInfo **ppTInfo)
231 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
232 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo,
233 lcid, ppTInfo);
236 static HRESULT WINAPI HTMLBodyElement_GetIDsOfNames(IHTMLBodyElement *iface, REFIID riid,
237 LPOLESTR *rgszNames, UINT cNames,
238 LCID lcid, DISPID *rgDispId)
240 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
241 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid,
242 rgszNames, cNames, lcid, rgDispId);
245 static HRESULT WINAPI HTMLBodyElement_Invoke(IHTMLBodyElement *iface, DISPID dispIdMember,
246 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
247 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
249 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
250 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember,
251 riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
254 static HRESULT WINAPI HTMLBodyElement_put_background(IHTMLBodyElement *iface, BSTR v)
256 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
257 nsAString nsstr;
258 nsresult nsres;
260 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
262 nsAString_InitDepend(&nsstr, v);
263 nsres = nsIDOMHTMLBodyElement_SetBackground(This->nsbody, &nsstr);
264 nsAString_Finish(&nsstr);
265 if(NS_FAILED(nsres))
266 return E_FAIL;
268 return S_OK;
271 static HRESULT WINAPI HTMLBodyElement_get_background(IHTMLBodyElement *iface, BSTR *p)
273 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
274 nsAString background_str;
275 nsresult nsres;
277 TRACE("(%p)->(%p)\n", This, p);
279 nsAString_Init(&background_str, NULL);
280 nsres = nsIDOMHTMLBodyElement_GetBackground(This->nsbody, &background_str);
281 return return_nsstr(nsres, &background_str, p);
284 static HRESULT WINAPI HTMLBodyElement_put_bgProperties(IHTMLBodyElement *iface, BSTR v)
286 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
287 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
288 return E_NOTIMPL;
291 static HRESULT WINAPI HTMLBodyElement_get_bgProperties(IHTMLBodyElement *iface, BSTR *p)
293 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
294 FIXME("(%p)->(%p)\n", This, p);
295 return E_NOTIMPL;
298 static HRESULT WINAPI HTMLBodyElement_put_leftMargin(IHTMLBodyElement *iface, VARIANT v)
300 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
301 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
302 return E_NOTIMPL;
305 static HRESULT WINAPI HTMLBodyElement_get_leftMargin(IHTMLBodyElement *iface, VARIANT *p)
307 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
308 FIXME("(%p)->(%p)\n", This, p);
309 return E_NOTIMPL;
312 static HRESULT WINAPI HTMLBodyElement_put_topMargin(IHTMLBodyElement *iface, VARIANT v)
314 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
315 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
316 return E_NOTIMPL;
319 static HRESULT WINAPI HTMLBodyElement_get_topMargin(IHTMLBodyElement *iface, VARIANT *p)
321 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
322 FIXME("(%p)->(%p)\n", This, p);
323 return E_NOTIMPL;
326 static HRESULT WINAPI HTMLBodyElement_put_rightMargin(IHTMLBodyElement *iface, VARIANT v)
328 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
329 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
330 return E_NOTIMPL;
333 static HRESULT WINAPI HTMLBodyElement_get_rightMargin(IHTMLBodyElement *iface, VARIANT *p)
335 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
336 FIXME("(%p)->(%p)\n", This, p);
337 return E_NOTIMPL;
340 static HRESULT WINAPI HTMLBodyElement_put_bottomMargin(IHTMLBodyElement *iface, VARIANT v)
342 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
343 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
344 return E_NOTIMPL;
347 static HRESULT WINAPI HTMLBodyElement_get_bottomMargin(IHTMLBodyElement *iface, VARIANT *p)
349 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
350 FIXME("(%p)->(%p)\n", This, p);
351 return E_NOTIMPL;
354 static HRESULT WINAPI HTMLBodyElement_put_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL v)
356 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
357 FIXME("(%p)->(%x)\n", This, v);
358 return E_NOTIMPL;
361 static HRESULT WINAPI HTMLBodyElement_get_noWrap(IHTMLBodyElement *iface, VARIANT_BOOL *p)
363 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
364 FIXME("(%p)->(%p)\n", This, p);
365 return E_NOTIMPL;
368 static HRESULT WINAPI HTMLBodyElement_put_bgColor(IHTMLBodyElement *iface, VARIANT v)
370 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
371 nsAString strColor;
372 nsresult nsres;
374 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
376 if(!variant_to_nscolor(&v, &strColor))
377 return S_OK;
379 nsres = nsIDOMHTMLBodyElement_SetBgColor(This->nsbody, &strColor);
380 nsAString_Finish(&strColor);
381 if(NS_FAILED(nsres))
382 ERR("SetBgColor failed: %08x\n", nsres);
384 return S_OK;
387 static HRESULT WINAPI HTMLBodyElement_get_bgColor(IHTMLBodyElement *iface, VARIANT *p)
389 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
390 nsAString nsstr;
391 nsresult nsres;
393 TRACE("(%p)->(%p)\n", This, p);
395 nsAString_Init(&nsstr, NULL);
396 nsres = nsIDOMHTMLBodyElement_GetBgColor(This->nsbody, &nsstr);
397 return return_nsstr_variant(nsres, &nsstr, NSSTR_COLOR, p);
400 static HRESULT WINAPI HTMLBodyElement_put_text(IHTMLBodyElement *iface, VARIANT v)
402 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
403 nsAString text;
404 nsresult nsres;
406 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
408 if(!variant_to_nscolor(&v, &text))
409 return S_OK;
411 nsres = nsIDOMHTMLBodyElement_SetText(This->nsbody, &text);
412 nsAString_Finish(&text);
413 if(NS_FAILED(nsres)) {
414 ERR("SetText failed: %08x\n", nsres);
415 return E_FAIL;
418 return S_OK;
421 static HRESULT WINAPI HTMLBodyElement_get_text(IHTMLBodyElement *iface, VARIANT *p)
423 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
424 nsAString text;
425 nsresult nsres;
426 HRESULT hres;
428 TRACE("(%p)->(%p)\n", This, p);
430 nsAString_Init(&text, NULL);
431 nsres = nsIDOMHTMLBodyElement_GetText(This->nsbody, &text);
432 if(NS_SUCCEEDED(nsres)) {
433 const PRUnichar *color;
435 nsAString_GetData(&text, &color);
436 V_VT(p) = VT_BSTR;
437 hres = nscolor_to_str(color, &V_BSTR(p));
438 }else {
439 ERR("GetText failed: %08x\n", nsres);
440 hres = E_FAIL;
443 nsAString_Finish(&text);
445 return hres;
448 static HRESULT WINAPI HTMLBodyElement_put_link(IHTMLBodyElement *iface, VARIANT v)
450 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
451 nsAString link_str;
452 nsresult nsres;
454 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
456 if(!variant_to_nscolor(&v, &link_str))
457 return S_OK;
459 nsres = nsIDOMHTMLBodyElement_SetLink(This->nsbody, &link_str);
460 nsAString_Finish(&link_str);
461 if(NS_FAILED(nsres))
462 ERR("SetLink failed: %08x\n", nsres);
464 return S_OK;
467 static HRESULT WINAPI HTMLBodyElement_get_link(IHTMLBodyElement *iface, VARIANT *p)
469 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
470 nsAString link_str;
471 nsresult nsres;
473 TRACE("(%p)->(%p)\n", This, p);
475 nsAString_Init(&link_str, NULL);
476 nsres = nsIDOMHTMLBodyElement_GetLink(This->nsbody, &link_str);
477 return return_nscolor(nsres, &link_str, p);
480 static HRESULT WINAPI HTMLBodyElement_put_vLink(IHTMLBodyElement *iface, VARIANT v)
482 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
483 nsAString vlink_str;
484 nsresult nsres;
486 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
488 if(!variant_to_nscolor(&v, &vlink_str))
489 return S_OK;
491 nsres = nsIDOMHTMLBodyElement_SetVLink(This->nsbody, &vlink_str);
492 nsAString_Finish(&vlink_str);
493 if(NS_FAILED(nsres))
494 ERR("SetLink failed: %08x\n", nsres);
496 return S_OK;
499 static HRESULT WINAPI HTMLBodyElement_get_vLink(IHTMLBodyElement *iface, VARIANT *p)
501 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
502 nsAString vlink_str;
503 nsresult nsres;
505 TRACE("(%p)->(%p)\n", This, p);
507 nsAString_Init(&vlink_str, NULL);
508 nsres = nsIDOMHTMLBodyElement_GetVLink(This->nsbody, &vlink_str);
509 return return_nscolor(nsres, &vlink_str, p);
512 static HRESULT WINAPI HTMLBodyElement_put_aLink(IHTMLBodyElement *iface, VARIANT v)
514 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
515 nsAString alink_str;
516 nsresult nsres;
518 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
520 if(!variant_to_nscolor(&v, &alink_str))
521 return S_OK;
523 nsres = nsIDOMHTMLBodyElement_SetALink(This->nsbody, &alink_str);
524 nsAString_Finish(&alink_str);
525 if(NS_FAILED(nsres))
526 ERR("SetALink failed: %08x\n", nsres);
528 return S_OK;
531 static HRESULT WINAPI HTMLBodyElement_get_aLink(IHTMLBodyElement *iface, VARIANT *p)
533 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
534 nsAString alink_str;
535 nsresult nsres;
537 TRACE("(%p)->(%p)\n", This, p);
539 nsAString_Init(&alink_str, NULL);
540 nsres = nsIDOMHTMLBodyElement_GetALink(This->nsbody, &alink_str);
541 return return_nscolor(nsres, &alink_str, p);
544 static HRESULT WINAPI HTMLBodyElement_put_onload(IHTMLBodyElement *iface, VARIANT v)
546 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
548 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
550 return set_node_event(&This->element.node, EVENTID_LOAD, &v);
553 static HRESULT WINAPI HTMLBodyElement_get_onload(IHTMLBodyElement *iface, VARIANT *p)
555 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
557 TRACE("(%p)->(%p)\n", This, p);
559 return get_node_event(&This->element.node, EVENTID_LOAD, p);
562 static HRESULT WINAPI HTMLBodyElement_put_onunload(IHTMLBodyElement *iface, VARIANT v)
564 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
565 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
566 return E_NOTIMPL;
569 static HRESULT WINAPI HTMLBodyElement_get_onunload(IHTMLBodyElement *iface, VARIANT *p)
571 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
572 FIXME("(%p)->(%p)\n", This, p);
573 return E_NOTIMPL;
576 static HRESULT WINAPI HTMLBodyElement_put_scroll(IHTMLBodyElement *iface, BSTR v)
578 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
579 static const WCHAR *val;
581 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
583 /* Emulate with CSS visibility attribute */
584 if(!wcscmp(v, L"yes")) {
585 val = L"scroll";
586 }else if(!wcscmp(v, L"auto")) {
587 val = L"visible";
588 }else if(!wcscmp(v, L"no")) {
589 val = L"hidden";
590 }else {
591 WARN("Invalid argument %s\n", debugstr_w(v));
592 return E_INVALIDARG;
595 return set_elem_style(&This->element, STYLEID_OVERFLOW, val);
598 static HRESULT WINAPI HTMLBodyElement_get_scroll(IHTMLBodyElement *iface, BSTR *p)
600 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
601 const WCHAR *ret = NULL;
602 BSTR overflow;
603 HRESULT hres;
605 TRACE("(%p)->(%p)\n", This, p);
607 /* Emulate with CSS visibility attribute */
608 hres = get_elem_style(&This->element, STYLEID_OVERFLOW, &overflow);
609 if(FAILED(hres))
610 return hres;
612 if(!overflow || !*overflow) {
613 *p = NULL;
614 hres = S_OK;
615 }else if(!wcscmp(overflow, L"visible") || !wcscmp(overflow, L"auto")) {
616 ret = L"auto";
617 }else if(!wcscmp(overflow, L"scroll")) {
618 ret = L"yes";
619 }else if(!wcscmp(overflow, L"hidden")) {
620 ret = L"no";
621 }else {
622 TRACE("Defaulting %s to NULL\n", debugstr_w(overflow));
623 *p = NULL;
624 hres = S_OK;
627 SysFreeString(overflow);
628 if(ret) {
629 *p = SysAllocString(ret);
630 hres = *p ? S_OK : E_OUTOFMEMORY;
633 return hres;
636 static HRESULT WINAPI HTMLBodyElement_put_onselect(IHTMLBodyElement *iface, VARIANT v)
638 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
639 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
640 return E_NOTIMPL;
643 static HRESULT WINAPI HTMLBodyElement_get_onselect(IHTMLBodyElement *iface, VARIANT *p)
645 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
646 FIXME("(%p)->(%p)\n", This, p);
647 return E_NOTIMPL;
650 static HRESULT WINAPI HTMLBodyElement_put_onbeforeunload(IHTMLBodyElement *iface, VARIANT v)
652 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
653 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
654 return E_NOTIMPL;
657 static HRESULT WINAPI HTMLBodyElement_get_onbeforeunload(IHTMLBodyElement *iface, VARIANT *p)
659 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
660 FIXME("(%p)->(%p)\n", This, p);
661 return E_NOTIMPL;
664 static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, IHTMLTxtRange **range)
666 HTMLBodyElement *This = impl_from_IHTMLBodyElement(iface);
667 nsIDOMRange *nsrange = NULL;
668 nsresult nsres;
669 HRESULT hres;
671 TRACE("(%p)->(%p)\n", This, range);
673 if(!This->element.node.doc->nsdoc) {
674 WARN("No nsdoc\n");
675 return E_UNEXPECTED;
678 nsres = nsIDOMHTMLDocument_CreateRange(This->element.node.doc->nsdoc, &nsrange);
679 if(NS_SUCCEEDED(nsres)) {
680 nsres = nsIDOMRange_SelectNodeContents(nsrange, This->element.node.nsnode);
681 if(NS_FAILED(nsres))
682 ERR("SelectNodeContents failed: %08x\n", nsres);
683 }else {
684 ERR("CreateRange failed: %08x\n", nsres);
687 hres = HTMLTxtRange_Create(This->element.node.doc->basedoc.doc_node, nsrange, range);
689 nsIDOMRange_Release(nsrange);
690 return hres;
693 static const IHTMLBodyElementVtbl HTMLBodyElementVtbl = {
694 HTMLBodyElement_QueryInterface,
695 HTMLBodyElement_AddRef,
696 HTMLBodyElement_Release,
697 HTMLBodyElement_GetTypeInfoCount,
698 HTMLBodyElement_GetTypeInfo,
699 HTMLBodyElement_GetIDsOfNames,
700 HTMLBodyElement_Invoke,
701 HTMLBodyElement_put_background,
702 HTMLBodyElement_get_background,
703 HTMLBodyElement_put_bgProperties,
704 HTMLBodyElement_get_bgProperties,
705 HTMLBodyElement_put_leftMargin,
706 HTMLBodyElement_get_leftMargin,
707 HTMLBodyElement_put_topMargin,
708 HTMLBodyElement_get_topMargin,
709 HTMLBodyElement_put_rightMargin,
710 HTMLBodyElement_get_rightMargin,
711 HTMLBodyElement_put_bottomMargin,
712 HTMLBodyElement_get_bottomMargin,
713 HTMLBodyElement_put_noWrap,
714 HTMLBodyElement_get_noWrap,
715 HTMLBodyElement_put_bgColor,
716 HTMLBodyElement_get_bgColor,
717 HTMLBodyElement_put_text,
718 HTMLBodyElement_get_text,
719 HTMLBodyElement_put_link,
720 HTMLBodyElement_get_link,
721 HTMLBodyElement_put_vLink,
722 HTMLBodyElement_get_vLink,
723 HTMLBodyElement_put_aLink,
724 HTMLBodyElement_get_aLink,
725 HTMLBodyElement_put_onload,
726 HTMLBodyElement_get_onload,
727 HTMLBodyElement_put_onunload,
728 HTMLBodyElement_get_onunload,
729 HTMLBodyElement_put_scroll,
730 HTMLBodyElement_get_scroll,
731 HTMLBodyElement_put_onselect,
732 HTMLBodyElement_get_onselect,
733 HTMLBodyElement_put_onbeforeunload,
734 HTMLBodyElement_get_onbeforeunload,
735 HTMLBodyElement_createTextRange
738 static inline HTMLBodyElement *impl_from_IHTMLTextContainer(IHTMLTextContainer *iface)
740 return CONTAINING_RECORD(iface, HTMLBodyElement, IHTMLTextContainer_iface);
743 static HRESULT WINAPI HTMLTextContainer_QueryInterface(IHTMLTextContainer *iface,
744 REFIID riid, void **ppv)
746 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
747 return IHTMLElement_QueryInterface(&This->element.IHTMLElement_iface, riid, ppv);
750 static ULONG WINAPI HTMLTextContainer_AddRef(IHTMLTextContainer *iface)
752 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
753 return IHTMLElement_AddRef(&This->element.IHTMLElement_iface);
756 static ULONG WINAPI HTMLTextContainer_Release(IHTMLTextContainer *iface)
758 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
759 return IHTMLElement_Release(&This->element.IHTMLElement_iface);
762 static HRESULT WINAPI HTMLTextContainer_GetTypeInfoCount(IHTMLTextContainer *iface, UINT *pctinfo)
764 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
765 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
768 static HRESULT WINAPI HTMLTextContainer_GetTypeInfo(IHTMLTextContainer *iface, UINT iTInfo,
769 LCID lcid, ITypeInfo **ppTInfo)
771 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
772 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
773 ppTInfo);
776 static HRESULT WINAPI HTMLTextContainer_GetIDsOfNames(IHTMLTextContainer *iface, REFIID riid,
777 LPOLESTR *rgszNames, UINT cNames,
778 LCID lcid, DISPID *rgDispId)
780 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
781 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
782 cNames, lcid, rgDispId);
785 static HRESULT WINAPI HTMLTextContainer_Invoke(IHTMLTextContainer *iface, DISPID dispIdMember,
786 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
787 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
789 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
790 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
791 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
794 static HRESULT WINAPI HTMLTextContainer_createControlRange(IHTMLTextContainer *iface,
795 IDispatch **range)
797 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
798 FIXME("(%p)->(%p)\n", This, range);
799 return E_NOTIMPL;
802 static HRESULT WINAPI HTMLTextContainer_get_scrollHeight(IHTMLTextContainer *iface, LONG *p)
804 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
806 TRACE("(%p)->(%p)\n", This, p);
808 return IHTMLElement2_get_scrollHeight(&This->element.IHTMLElement2_iface, p);
811 static HRESULT WINAPI HTMLTextContainer_get_scrollWidth(IHTMLTextContainer *iface, LONG *p)
813 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
815 TRACE("(%p)->(%p)\n", This, p);
817 return IHTMLElement2_get_scrollWidth(&This->element.IHTMLElement2_iface, p);
820 static HRESULT WINAPI HTMLTextContainer_put_scrollTop(IHTMLTextContainer *iface, LONG v)
822 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
824 TRACE("(%p)->(%d)\n", This, v);
826 return IHTMLElement2_put_scrollTop(&This->element.IHTMLElement2_iface, v);
829 static HRESULT WINAPI HTMLTextContainer_get_scrollTop(IHTMLTextContainer *iface, LONG *p)
831 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
833 TRACE("(%p)->(%p)\n", This, p);
835 return IHTMLElement2_get_scrollTop(&This->element.IHTMLElement2_iface, p);
838 static HRESULT WINAPI HTMLTextContainer_put_scrollLeft(IHTMLTextContainer *iface, LONG v)
840 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
842 TRACE("(%p)->(%d)\n", This, v);
844 return IHTMLElement2_put_scrollLeft(&This->element.IHTMLElement2_iface, v);
847 static HRESULT WINAPI HTMLTextContainer_get_scrollLeft(IHTMLTextContainer *iface, LONG *p)
849 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
851 TRACE("(%p)->(%p)\n", This, p);
853 return IHTMLElement2_get_scrollLeft(&This->element.IHTMLElement2_iface, p);
856 static HRESULT WINAPI HTMLTextContainer_put_onscroll(IHTMLTextContainer *iface, VARIANT v)
858 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
859 FIXME("(%p)->()\n", This);
860 return E_NOTIMPL;
863 static HRESULT WINAPI HTMLTextContainer_get_onscroll(IHTMLTextContainer *iface, VARIANT *p)
865 HTMLBodyElement *This = impl_from_IHTMLTextContainer(iface);
866 FIXME("(%p)->(%p)\n", This, p);
867 return E_NOTIMPL;
870 static const IHTMLTextContainerVtbl HTMLTextContainerVtbl = {
871 HTMLTextContainer_QueryInterface,
872 HTMLTextContainer_AddRef,
873 HTMLTextContainer_Release,
874 HTMLTextContainer_GetTypeInfoCount,
875 HTMLTextContainer_GetTypeInfo,
876 HTMLTextContainer_GetIDsOfNames,
877 HTMLTextContainer_Invoke,
878 HTMLTextContainer_createControlRange,
879 HTMLTextContainer_get_scrollHeight,
880 HTMLTextContainer_get_scrollWidth,
881 HTMLTextContainer_put_scrollTop,
882 HTMLTextContainer_get_scrollTop,
883 HTMLTextContainer_put_scrollLeft,
884 HTMLTextContainer_get_scrollLeft,
885 HTMLTextContainer_put_onscroll,
886 HTMLTextContainer_get_onscroll
889 static inline HTMLBodyElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
891 return CONTAINING_RECORD(iface, HTMLBodyElement, element.node);
894 static HRESULT HTMLBodyElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
896 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
898 *ppv = NULL;
900 if(IsEqualGUID(&IID_IUnknown, riid)) {
901 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
902 *ppv = &This->IHTMLBodyElement_iface;
903 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
904 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
905 *ppv = &This->IHTMLBodyElement_iface;
906 }else if(IsEqualGUID(&IID_IHTMLBodyElement, riid)) {
907 TRACE("(%p)->(IID_IHTMLBodyElement %p)\n", This, ppv);
908 *ppv = &This->IHTMLBodyElement_iface;
909 }else if(IsEqualGUID(&IID_IHTMLTextContainer, riid)) {
910 TRACE("(%p)->(IID_IHTMLTextContainer %p)\n", This, ppv);
911 *ppv = &This->IHTMLTextContainer_iface;
914 if(*ppv) {
915 IUnknown_AddRef((IUnknown*)*ppv);
916 return S_OK;
919 return HTMLElement_QI(&This->element.node, riid, ppv);
922 static void HTMLBodyElement_traverse(HTMLDOMNode *iface, nsCycleCollectionTraversalCallback *cb)
924 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
926 if(This->nsbody)
927 note_cc_edge((nsISupports*)This->nsbody, "This->nsbody", cb);
930 static void HTMLBodyElement_unlink(HTMLDOMNode *iface)
932 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
934 if(This->nsbody) {
935 nsIDOMHTMLBodyElement *nsbody = This->nsbody;
936 This->nsbody = NULL;
937 nsIDOMHTMLBodyElement_Release(nsbody);
941 static EventTarget *HTMLBodyElement_get_event_prop_target(HTMLDOMNode *iface, int event_id)
943 HTMLBodyElement *This = impl_from_HTMLDOMNode(iface);
945 switch(event_id) {
946 case EVENTID_BLUR:
947 case EVENTID_ERROR:
948 case EVENTID_FOCUS:
949 case EVENTID_LOAD:
950 case EVENTID_SCROLL:
951 return This->element.node.doc && This->element.node.doc->window
952 ? &This->element.node.doc->window->event_target
953 : &This->element.node.event_target;
954 default:
955 return &This->element.node.event_target;
959 static BOOL HTMLBodyElement_is_text_edit(HTMLDOMNode *iface)
961 return TRUE;
964 static BOOL HTMLBodyElement_is_settable(HTMLDOMNode *iface, DISPID dispid)
966 switch(dispid) {
967 case DISPID_IHTMLELEMENT_OUTERTEXT:
968 return FALSE;
969 default:
970 return TRUE;
974 static const cpc_entry_t HTMLBodyElement_cpc[] = {
975 {&DIID_HTMLTextContainerEvents},
976 {&IID_IPropertyNotifySink},
977 HTMLELEMENT_CPC,
978 {NULL}
981 static const NodeImplVtbl HTMLBodyElementImplVtbl = {
982 &CLSID_HTMLBody,
983 HTMLBodyElement_QI,
984 HTMLElement_destructor,
985 HTMLBodyElement_cpc,
986 HTMLElement_clone,
987 HTMLElement_handle_event,
988 HTMLElement_get_attr_col,
989 HTMLBodyElement_get_event_prop_target,
990 NULL,
991 NULL,
992 NULL,
993 NULL,
994 NULL,
995 NULL,
996 NULL,
997 HTMLBodyElement_traverse,
998 HTMLBodyElement_unlink,
999 HTMLBodyElement_is_text_edit,
1000 HTMLBodyElement_is_settable
1003 static const tid_t HTMLBodyElement_iface_tids[] = {
1004 IHTMLBodyElement_tid,
1005 IHTMLBodyElement2_tid,
1006 HTMLELEMENT_TIDS,
1007 IHTMLTextContainer_tid,
1011 static dispex_static_data_t HTMLBodyElement_dispex = {
1012 NULL,
1013 DispHTMLBody_tid,
1014 HTMLBodyElement_iface_tids,
1015 HTMLElement_init_dispex_info
1018 HRESULT HTMLBodyElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
1020 HTMLBodyElement *ret;
1021 nsresult nsres;
1023 ret = heap_alloc_zero(sizeof(HTMLBodyElement));
1024 if(!ret)
1025 return E_OUTOFMEMORY;
1027 ret->IHTMLBodyElement_iface.lpVtbl = &HTMLBodyElementVtbl;
1028 ret->IHTMLTextContainer_iface.lpVtbl = &HTMLTextContainerVtbl;
1029 ret->element.node.vtbl = &HTMLBodyElementImplVtbl;
1031 HTMLElement_Init(&ret->element, doc, nselem, &HTMLBodyElement_dispex);
1033 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLBodyElement, (void**)&ret->nsbody);
1034 assert(nsres == NS_OK);
1036 *elem = &ret->element;
1037 return S_OK;