winspool: Revise EnumPrinterDriversW to fix the incorrect handling of 'all'. EnumPrin...
[wine] / dlls / mshtml / htmliframe.c
1 /*
2  * Copyright 2008 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
21 #define COBJMACROS
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "ole2.h"
27
28 #include "mshtml_private.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
33
34 typedef struct {
35     HTMLFrameBase framebase;
36
37     LONG ref;
38
39     nsIDOMHTMLIFrameElement *nsiframe;
40 } HTMLIFrame;
41
42 #define HTMLIFRAME_NODE_THIS(iface) DEFINE_THIS2(HTMLIFrame, framebase.element.node, iface)
43
44 static HRESULT HTMLIFrame_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
45 {
46     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
47
48     return HTMLFrameBase_QI(&This->framebase, riid, ppv);
49 }
50
51 static void HTMLIFrame_destructor(HTMLDOMNode *iface)
52 {
53     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
54
55     if(This->nsiframe)
56         nsIDOMHTMLIFrameElement_Release(This->nsiframe);
57
58     HTMLFrameBase_destructor(&This->framebase);
59 }
60
61 static HRESULT HTMLIFrame_get_document(HTMLDOMNode *iface, IDispatch **p)
62 {
63     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
64
65     if(!This->framebase.content_window || !This->framebase.content_window->doc) {
66         *p = NULL;
67         return S_OK;
68     }
69
70     *p = (IDispatch*)HTMLDOC(&This->framebase.content_window->doc->basedoc);
71     IDispatch_AddRef(*p);
72     return S_OK;
73 }
74
75 static HRESULT HTMLIFrame_get_readystate(HTMLDOMNode *iface, BSTR *p)
76 {
77     HTMLIFrame *This = HTMLIFRAME_NODE_THIS(iface);
78
79     return IHTMLFrameBase2_get_readyState(HTMLFRAMEBASE2(&This->framebase), p);
80 }
81
82 #undef HTMLIFRAME_NODE_THIS
83
84 static const NodeImplVtbl HTMLIFrameImplVtbl = {
85     HTMLIFrame_QI,
86     HTMLIFrame_destructor,
87     NULL,
88     NULL,
89     NULL,
90     NULL,
91     HTMLIFrame_get_document,
92     HTMLIFrame_get_readystate
93 };
94
95 static const tid_t HTMLIFrame_iface_tids[] = {
96     IHTMLDOMNode_tid,
97     IHTMLDOMNode2_tid,
98     IHTMLElement_tid,
99     IHTMLElement2_tid,
100     IHTMLElement3_tid,
101     IHTMLFrameBase_tid,
102     IHTMLFrameBase2_tid,
103     0
104 };
105
106 static dispex_static_data_t HTMLIFrame_dispex = {
107     NULL,
108     DispHTMLIFrame_tid,
109     NULL,
110     HTMLIFrame_iface_tids
111 };
112
113 static HTMLWindow *get_content_window(nsIDOMHTMLIFrameElement *nsiframe)
114 {
115     HTMLWindow *ret;
116     nsIDOMWindow *nswindow;
117     nsIDOMDocument *nsdoc;
118     nsresult nsres;
119
120     nsres = nsIDOMHTMLIFrameElement_GetContentDocument(nsiframe, &nsdoc);
121     if(NS_FAILED(nsres)) {
122         ERR("GetContentDocument failed: %08x\n", nsres);
123         return NULL;
124     }
125
126     if(!nsdoc) {
127         FIXME("NULL contentDocument\n");
128         return NULL;
129     }
130
131     nswindow = get_nsdoc_window(nsdoc);
132     nsIDOMDocument_Release(nsdoc);
133     if(!nswindow)
134         return NULL;
135
136     ret = nswindow_to_window(nswindow);
137     nsIDOMWindow_Release(nswindow);
138     if(!ret)
139         ERR("Could not get window object\n");
140
141     return ret;
142 }
143
144 HTMLElement *HTMLIFrame_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLWindow *content_window)
145 {
146     HTMLIFrame *ret;
147     nsresult nsres;
148
149     ret = heap_alloc_zero(sizeof(HTMLIFrame));
150
151     ret->framebase.element.node.vtbl = &HTMLIFrameImplVtbl;
152
153     nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLIFrameElement, (void**)&ret->nsiframe);
154     if(NS_FAILED(nsres))
155         ERR("Could not get nsIDOMHTMLIFrameElement iface: %08x\n", nsres);
156
157     if(!content_window)
158         content_window = get_content_window(ret->nsiframe);
159
160     HTMLFrameBase_Init(&ret->framebase, doc, nselem, content_window, &HTMLIFrame_dispex);
161
162     return &ret->framebase.element;
163 }