2 * Copyright 2008 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
29 #include "mshtml_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
35 struct HTMLDOMTextNode
{
37 IHTMLDOMTextNode IHTMLDOMTextNode_iface
;
38 IHTMLDOMTextNode2 IHTMLDOMTextNode2_iface
;
43 static inline HTMLDOMTextNode
*impl_from_IHTMLDOMTextNode(IHTMLDOMTextNode
*iface
)
45 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, IHTMLDOMTextNode_iface
);
48 static HRESULT WINAPI
HTMLDOMTextNode_QueryInterface(IHTMLDOMTextNode
*iface
,
49 REFIID riid
, void **ppv
)
51 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
53 return IHTMLDOMNode_QueryInterface(&This
->node
.IHTMLDOMNode_iface
, riid
, ppv
);
56 static ULONG WINAPI
HTMLDOMTextNode_AddRef(IHTMLDOMTextNode
*iface
)
58 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
60 return IHTMLDOMNode_AddRef(&This
->node
.IHTMLDOMNode_iface
);
63 static ULONG WINAPI
HTMLDOMTextNode_Release(IHTMLDOMTextNode
*iface
)
65 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
67 return IHTMLDOMNode_Release(&This
->node
.IHTMLDOMNode_iface
);
70 static HRESULT WINAPI
HTMLDOMTextNode_GetTypeInfoCount(IHTMLDOMTextNode
*iface
, UINT
*pctinfo
)
72 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
73 return IDispatchEx_GetTypeInfoCount(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
76 static HRESULT WINAPI
HTMLDOMTextNode_GetTypeInfo(IHTMLDOMTextNode
*iface
, UINT iTInfo
,
77 LCID lcid
, ITypeInfo
**ppTInfo
)
79 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
80 return IDispatchEx_GetTypeInfo(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
83 static HRESULT WINAPI
HTMLDOMTextNode_GetIDsOfNames(IHTMLDOMTextNode
*iface
, REFIID riid
,
84 LPOLESTR
*rgszNames
, UINT cNames
,
85 LCID lcid
, DISPID
*rgDispId
)
87 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
88 return IDispatchEx_GetIDsOfNames(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
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
)
96 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
97 return IDispatchEx_Invoke(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
98 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
101 static HRESULT WINAPI
HTMLDOMTextNode_put_data(IHTMLDOMTextNode
*iface
, BSTR v
)
103 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
107 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
109 nsAString_InitDepend(&nsstr
, v
);
110 nsres
= nsIDOMText_SetData(This
->nstext
, &nsstr
);
111 nsAString_Finish(&nsstr
);
112 return NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
115 static HRESULT WINAPI
HTMLDOMTextNode_get_data(IHTMLDOMTextNode
*iface
, BSTR
*p
)
117 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
121 TRACE("(%p)->(%p)\n", This
, p
);
123 nsAString_Init(&nsstr
, NULL
);
124 nsres
= nsIDOMText_GetData(This
->nstext
, &nsstr
);
125 return return_nsstr(nsres
, &nsstr
, p
);
128 static HRESULT WINAPI
HTMLDOMTextNode_toString(IHTMLDOMTextNode
*iface
, BSTR
*String
)
130 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
132 TRACE("(%p)->(%p)\n", This
, String
);
137 if(dispex_compat_mode(&This
->node
.event_target
.dispex
) < COMPAT_MODE_IE9
)
138 return IHTMLDOMTextNode_get_data(&This
->IHTMLDOMTextNode_iface
, String
);
140 return dispex_to_string(&This
->node
.event_target
.dispex
, String
);
143 static HRESULT WINAPI
HTMLDOMTextNode_get_length(IHTMLDOMTextNode
*iface
, LONG
*p
)
145 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
149 TRACE("(%p)->(%p)\n", This
, p
);
151 nsres
= nsIDOMText_GetLength(This
->nstext
, &length
);
153 ERR("GetLength failed: %08lx\n", nsres
);
159 static HRESULT WINAPI
HTMLDOMTextNode_splitText(IHTMLDOMTextNode
*iface
, LONG offset
, IHTMLDOMNode
**pRetNode
)
161 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
167 TRACE("(%p)->(%ld %p)\n", This
, offset
, pRetNode
);
169 nsres
= nsIDOMText_SplitText(This
->nstext
, offset
, &text
);
170 if(NS_FAILED(nsres
)) {
171 ERR("SplitText failed: %lx08x\n", nsres
);
180 hres
= get_node((nsIDOMNode
*)text
, TRUE
, &node
);
181 nsIDOMText_Release(text
);
185 *pRetNode
= &node
->IHTMLDOMNode_iface
;
189 static const IHTMLDOMTextNodeVtbl HTMLDOMTextNodeVtbl
= {
190 HTMLDOMTextNode_QueryInterface
,
191 HTMLDOMTextNode_AddRef
,
192 HTMLDOMTextNode_Release
,
193 HTMLDOMTextNode_GetTypeInfoCount
,
194 HTMLDOMTextNode_GetTypeInfo
,
195 HTMLDOMTextNode_GetIDsOfNames
,
196 HTMLDOMTextNode_Invoke
,
197 HTMLDOMTextNode_put_data
,
198 HTMLDOMTextNode_get_data
,
199 HTMLDOMTextNode_toString
,
200 HTMLDOMTextNode_get_length
,
201 HTMLDOMTextNode_splitText
204 static inline HTMLDOMTextNode
*impl_from_IHTMLDOMTextNode2(IHTMLDOMTextNode2
*iface
)
206 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, IHTMLDOMTextNode2_iface
);
209 static HRESULT WINAPI
HTMLDOMTextNode2_QueryInterface(IHTMLDOMTextNode2
*iface
, REFIID riid
, void **ppv
)
211 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
213 return IHTMLDOMNode_QueryInterface(&This
->node
.IHTMLDOMNode_iface
, riid
, ppv
);
216 static ULONG WINAPI
HTMLDOMTextNode2_AddRef(IHTMLDOMTextNode2
*iface
)
218 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
220 return IHTMLDOMNode_AddRef(&This
->node
.IHTMLDOMNode_iface
);
223 static ULONG WINAPI
HTMLDOMTextNode2_Release(IHTMLDOMTextNode2
*iface
)
225 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
227 return IHTMLDOMNode_Release(&This
->node
.IHTMLDOMNode_iface
);
230 static HRESULT WINAPI
HTMLDOMTextNode2_GetTypeInfoCount(IHTMLDOMTextNode2
*iface
, UINT
*pctinfo
)
232 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
233 return IDispatchEx_GetTypeInfoCount(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, pctinfo
);
236 static HRESULT WINAPI
HTMLDOMTextNode2_GetTypeInfo(IHTMLDOMTextNode2
*iface
, UINT iTInfo
,
237 LCID lcid
, ITypeInfo
**ppTInfo
)
239 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
240 return IDispatchEx_GetTypeInfo(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, iTInfo
, lcid
, ppTInfo
);
243 static HRESULT WINAPI
HTMLDOMTextNode2_GetIDsOfNames(IHTMLDOMTextNode2
*iface
, REFIID riid
,
244 LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
246 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
247 return IDispatchEx_GetIDsOfNames(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, riid
, rgszNames
, cNames
,
251 static HRESULT WINAPI
HTMLDOMTextNode2_Invoke(IHTMLDOMTextNode2
*iface
, DISPID dispIdMember
,
252 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
,
253 EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
255 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
256 return IDispatchEx_Invoke(&This
->node
.event_target
.dispex
.IDispatchEx_iface
, dispIdMember
, riid
, lcid
,
257 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
260 static HRESULT WINAPI
HTMLDOMTextNode2_substringData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
, BSTR
*string
)
262 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
263 FIXME("(%p)->(%ld %ld %p)\n", This
, offset
, count
, string
);
267 static HRESULT WINAPI
HTMLDOMTextNode2_appendData(IHTMLDOMTextNode2
*iface
, BSTR string
)
269 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
273 TRACE("(%p)->(%s)\n", This
, debugstr_w(string
));
275 nsAString_InitDepend(&nsstr
, string
);
276 nsres
= nsIDOMText_AppendData(This
->nstext
, &nsstr
);
277 nsAString_Finish(&nsstr
);
278 if(NS_FAILED(nsres
)) {
279 ERR("AppendData failed: %08lx\n", nsres
);
286 static HRESULT WINAPI
HTMLDOMTextNode2_insertData(IHTMLDOMTextNode2
*iface
, LONG offset
, BSTR string
)
288 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
289 FIXME("(%p)->(%ld %s)\n", This
, offset
, debugstr_w(string
));
293 static HRESULT WINAPI
HTMLDOMTextNode2_deleteData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
)
295 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
296 FIXME("(%p)->(%ld %ld)\n", This
, offset
, count
);
300 static HRESULT WINAPI
HTMLDOMTextNode2_replaceData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
, BSTR string
)
302 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
303 FIXME("(%p)->(%ld %ld %s)\n", This
, offset
, count
, debugstr_w(string
));
307 static const IHTMLDOMTextNode2Vtbl HTMLDOMTextNode2Vtbl
= {
308 HTMLDOMTextNode2_QueryInterface
,
309 HTMLDOMTextNode2_AddRef
,
310 HTMLDOMTextNode2_Release
,
311 HTMLDOMTextNode2_GetTypeInfoCount
,
312 HTMLDOMTextNode2_GetTypeInfo
,
313 HTMLDOMTextNode2_GetIDsOfNames
,
314 HTMLDOMTextNode2_Invoke
,
315 HTMLDOMTextNode2_substringData
,
316 HTMLDOMTextNode2_appendData
,
317 HTMLDOMTextNode2_insertData
,
318 HTMLDOMTextNode2_deleteData
,
319 HTMLDOMTextNode2_replaceData
322 static inline HTMLDOMTextNode
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
324 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, node
);
327 static HRESULT
HTMLDOMTextNode_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
329 HTMLDOMTextNode
*This
= impl_from_HTMLDOMNode(iface
);
331 TRACE("(%p)->(%s %p)\n", This
, debugstr_mshtml_guid(riid
), ppv
);
333 if(IsEqualGUID(&IID_IHTMLDOMTextNode
, riid
))
334 *ppv
= &This
->IHTMLDOMTextNode_iface
;
335 else if(IsEqualGUID(&IID_IHTMLDOMTextNode2
, riid
))
336 *ppv
= &This
->IHTMLDOMTextNode2_iface
;
338 return HTMLDOMNode_QI(&This
->node
, riid
, ppv
);
340 IUnknown_AddRef((IUnknown
*)*ppv
);
344 static HRESULT
HTMLDOMTextNode_clone(HTMLDOMNode
*iface
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
346 HTMLDOMTextNode
*This
= impl_from_HTMLDOMNode(iface
);
348 return HTMLDOMTextNode_Create(This
->node
.doc
, nsnode
, ret
);
351 static const cpc_entry_t HTMLDOMTextNode_cpc
[] = {{NULL
}};
353 static const NodeImplVtbl HTMLDOMTextNodeImplVtbl
= {
356 HTMLDOMNode_destructor
,
358 HTMLDOMTextNode_clone
361 static const tid_t HTMLDOMTextNode_iface_tids
[] = {
364 IHTMLDOMTextNode_tid
,
365 IHTMLDOMTextNode2_tid
,
368 static dispex_static_data_t HTMLDOMTextNode_dispex
= {
371 DispHTMLDOMTextNode_tid
,
372 HTMLDOMTextNode_iface_tids
,
373 HTMLDOMNode_init_dispex_info
376 HRESULT
HTMLDOMTextNode_Create(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**node
)
378 HTMLDOMTextNode
*ret
;
381 ret
= calloc(1, sizeof(*ret
));
383 return E_OUTOFMEMORY
;
385 ret
->node
.vtbl
= &HTMLDOMTextNodeImplVtbl
;
386 ret
->IHTMLDOMTextNode_iface
.lpVtbl
= &HTMLDOMTextNodeVtbl
;
387 ret
->IHTMLDOMTextNode2_iface
.lpVtbl
= &HTMLDOMTextNode2Vtbl
;
389 HTMLDOMNode_Init(doc
, &ret
->node
, nsnode
, &HTMLDOMTextNode_dispex
);
391 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&ret
->nstext
);
392 assert(nsres
== NS_OK
&& (nsIDOMNode
*)ret
->nstext
== ret
->node
.nsnode
);
394 /* Share reference with nsnode */
395 nsIDOMNode_Release(ret
->node
.nsnode
);