mshtml: Added noscript tag handling tests.
[wine] / dlls / mshtml / htmltextnode.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
20 #include <stdarg.h>
21 #include <assert.h>
22
23 #define COBJMACROS
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
29
30 #include "mshtml_private.h"
31
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35
36 struct HTMLDOMTextNode {
37     HTMLDOMNode node;
38     IHTMLDOMTextNode IHTMLDOMTextNode_iface;
39
40     nsIDOMText *nstext;
41 };
42
43 static inline HTMLDOMTextNode *impl_from_IHTMLDOMTextNode(IHTMLDOMTextNode *iface)
44 {
45     return CONTAINING_RECORD(iface, HTMLDOMTextNode, IHTMLDOMTextNode_iface);
46 }
47
48 static HRESULT WINAPI HTMLDOMTextNode_QueryInterface(IHTMLDOMTextNode *iface,
49                                                  REFIID riid, void **ppv)
50 {
51     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
52
53     return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
54 }
55
56 static ULONG WINAPI HTMLDOMTextNode_AddRef(IHTMLDOMTextNode *iface)
57 {
58     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
59
60     return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
61 }
62
63 static ULONG WINAPI HTMLDOMTextNode_Release(IHTMLDOMTextNode *iface)
64 {
65     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
66
67     return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
68 }
69
70 static HRESULT WINAPI HTMLDOMTextNode_GetTypeInfoCount(IHTMLDOMTextNode *iface, UINT *pctinfo)
71 {
72     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
73     return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
74 }
75
76 static HRESULT WINAPI HTMLDOMTextNode_GetTypeInfo(IHTMLDOMTextNode *iface, UINT iTInfo,
77                                               LCID lcid, ITypeInfo **ppTInfo)
78 {
79     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
80     return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
81 }
82
83 static HRESULT WINAPI HTMLDOMTextNode_GetIDsOfNames(IHTMLDOMTextNode *iface, REFIID riid,
84                                                 LPOLESTR *rgszNames, UINT cNames,
85                                                 LCID lcid, DISPID *rgDispId)
86 {
87     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
88     return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
89             lcid, rgDispId);
90 }
91
92 static HRESULT WINAPI HTMLDOMTextNode_Invoke(IHTMLDOMTextNode *iface, DISPID dispIdMember,
93                             REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
94                             VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
95 {
96     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
97     return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
98             wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
99 }
100
101 static HRESULT WINAPI HTMLDOMTextNode_put_data(IHTMLDOMTextNode *iface, BSTR v)
102 {
103     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
104     FIXME("(%p)->(%s)\n", This, debugstr_w(v));
105     return E_NOTIMPL;
106 }
107
108 static HRESULT WINAPI HTMLDOMTextNode_get_data(IHTMLDOMTextNode *iface, BSTR *p)
109 {
110     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
111     FIXME("(%p)->(%p)\n", This, p);
112     return E_NOTIMPL;
113 }
114
115 static HRESULT WINAPI HTMLDOMTextNode_toString(IHTMLDOMTextNode *iface, BSTR *String)
116 {
117     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
118     FIXME("(%p)->(%p)\n", This, String);
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI HTMLDOMTextNode_get_length(IHTMLDOMTextNode *iface, LONG *p)
123 {
124     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
125     PRUint32 length = 0;
126     nsresult nsres;
127
128     TRACE("(%p)->(%p)\n", This, p);
129
130     nsres = nsIDOMText_GetLength(This->nstext, &length);
131     if(NS_FAILED(nsres))
132         ERR("GetLength failed: %08x\n", nsres);
133
134     *p = length;
135     return S_OK;
136 }
137
138 static HRESULT WINAPI HTMLDOMTextNode_splitText(IHTMLDOMTextNode *iface, LONG offset, IHTMLDOMNode **pRetNode)
139 {
140     HTMLDOMTextNode *This = impl_from_IHTMLDOMTextNode(iface);
141     FIXME("(%p)->(%d %p)\n", This, offset, pRetNode);
142     return E_NOTIMPL;
143 }
144
145 static const IHTMLDOMTextNodeVtbl HTMLDOMTextNodeVtbl = {
146     HTMLDOMTextNode_QueryInterface,
147     HTMLDOMTextNode_AddRef,
148     HTMLDOMTextNode_Release,
149     HTMLDOMTextNode_GetTypeInfoCount,
150     HTMLDOMTextNode_GetTypeInfo,
151     HTMLDOMTextNode_GetIDsOfNames,
152     HTMLDOMTextNode_Invoke,
153     HTMLDOMTextNode_put_data,
154     HTMLDOMTextNode_get_data,
155     HTMLDOMTextNode_toString,
156     HTMLDOMTextNode_get_length,
157     HTMLDOMTextNode_splitText
158 };
159
160 static inline HTMLDOMTextNode *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
161 {
162     return CONTAINING_RECORD(iface, HTMLDOMTextNode, node);
163 }
164
165 static HRESULT HTMLDOMTextNode_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
166 {
167     HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
168
169     *ppv =  NULL;
170
171     if(IsEqualGUID(&IID_IHTMLDOMTextNode, riid)) {
172         TRACE("(%p)->(IID_IHTMLDOMTextNode %p)\n", This, ppv);
173         *ppv = &This->IHTMLDOMTextNode_iface;
174     }else {
175         return HTMLDOMNode_QI(&This->node, riid, ppv);
176     }
177
178     IUnknown_AddRef((IUnknown*)*ppv);
179     return S_OK;
180 }
181
182 static HRESULT HTMLDOMTextNode_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
183 {
184     HTMLDOMTextNode *This = impl_from_HTMLDOMNode(iface);
185
186     return HTMLDOMTextNode_Create(This->node.doc, nsnode, ret);
187 }
188
189 static const NodeImplVtbl HTMLDOMTextNodeImplVtbl = {
190     HTMLDOMTextNode_QI,
191     HTMLDOMNode_destructor,
192     HTMLDOMTextNode_clone
193 };
194
195 static const tid_t HTMLDOMTextNode_iface_tids[] = {
196     IHTMLDOMNode_tid,
197     IHTMLDOMNode2_tid,
198     IHTMLDOMTextNode_tid,
199     0
200 };
201 static dispex_static_data_t HTMLDOMTextNode_dispex = {
202     NULL,
203     DispHTMLDOMTextNode_tid,
204     0,
205     HTMLDOMTextNode_iface_tids
206 };
207
208 HRESULT HTMLDOMTextNode_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, HTMLDOMNode **node)
209 {
210     HTMLDOMTextNode *ret;
211     nsresult nsres;
212
213     ret = heap_alloc_zero(sizeof(*ret));
214     if(!ret)
215         return E_OUTOFMEMORY;
216
217     ret->node.vtbl = &HTMLDOMTextNodeImplVtbl;
218     ret->IHTMLDOMTextNode_iface.lpVtbl = &HTMLDOMTextNodeVtbl;
219
220     init_dispex(&ret->node.dispex, (IUnknown*)&ret->IHTMLDOMTextNode_iface,
221             &HTMLDOMTextNode_dispex);
222
223     HTMLDOMNode_Init(doc, &ret->node, nsnode);
224
225     nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMText, (void**)&ret->nstext);
226     assert(nsres == NS_OK && (nsIDOMNode*)ret->nstext == ret->node.nsnode);
227
228     /* Share reference with nsnode */
229     nsIDOMNode_Release(ret->node.nsnode);
230
231     *node = &ret->node;
232     return S_OK;
233 }