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 DISPEX_IDISPATCH_IMPL(HTMLDOMTextNode
, IHTMLDOMTextNode
,
49 impl_from_IHTMLDOMTextNode(iface
)->node
.event_target
.dispex
)
51 static HRESULT WINAPI
HTMLDOMTextNode_put_data(IHTMLDOMTextNode
*iface
, BSTR v
)
53 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
57 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
59 nsAString_InitDepend(&nsstr
, v
);
60 nsres
= nsIDOMText_SetData(This
->nstext
, &nsstr
);
61 nsAString_Finish(&nsstr
);
62 return NS_SUCCEEDED(nsres
) ? S_OK
: E_FAIL
;
65 static HRESULT WINAPI
HTMLDOMTextNode_get_data(IHTMLDOMTextNode
*iface
, BSTR
*p
)
67 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
71 TRACE("(%p)->(%p)\n", This
, p
);
73 nsAString_Init(&nsstr
, NULL
);
74 nsres
= nsIDOMText_GetData(This
->nstext
, &nsstr
);
75 return return_nsstr(nsres
, &nsstr
, p
);
78 static HRESULT WINAPI
HTMLDOMTextNode_toString(IHTMLDOMTextNode
*iface
, BSTR
*String
)
80 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
82 TRACE("(%p)->(%p)\n", This
, String
);
87 if(dispex_compat_mode(&This
->node
.event_target
.dispex
) < COMPAT_MODE_IE9
)
88 return IHTMLDOMTextNode_get_data(&This
->IHTMLDOMTextNode_iface
, String
);
90 return dispex_to_string(&This
->node
.event_target
.dispex
, String
);
93 static HRESULT WINAPI
HTMLDOMTextNode_get_length(IHTMLDOMTextNode
*iface
, LONG
*p
)
95 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
99 TRACE("(%p)->(%p)\n", This
, p
);
101 nsres
= nsIDOMText_GetLength(This
->nstext
, &length
);
103 ERR("GetLength failed: %08lx\n", nsres
);
109 static HRESULT WINAPI
HTMLDOMTextNode_splitText(IHTMLDOMTextNode
*iface
, LONG offset
, IHTMLDOMNode
**pRetNode
)
111 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode(iface
);
117 TRACE("(%p)->(%ld %p)\n", This
, offset
, pRetNode
);
119 nsres
= nsIDOMText_SplitText(This
->nstext
, offset
, &text
);
120 if(NS_FAILED(nsres
)) {
121 ERR("SplitText failed: %lx08x\n", nsres
);
130 hres
= get_node((nsIDOMNode
*)text
, TRUE
, &node
);
131 nsIDOMText_Release(text
);
135 *pRetNode
= &node
->IHTMLDOMNode_iface
;
139 static const IHTMLDOMTextNodeVtbl HTMLDOMTextNodeVtbl
= {
140 HTMLDOMTextNode_QueryInterface
,
141 HTMLDOMTextNode_AddRef
,
142 HTMLDOMTextNode_Release
,
143 HTMLDOMTextNode_GetTypeInfoCount
,
144 HTMLDOMTextNode_GetTypeInfo
,
145 HTMLDOMTextNode_GetIDsOfNames
,
146 HTMLDOMTextNode_Invoke
,
147 HTMLDOMTextNode_put_data
,
148 HTMLDOMTextNode_get_data
,
149 HTMLDOMTextNode_toString
,
150 HTMLDOMTextNode_get_length
,
151 HTMLDOMTextNode_splitText
154 static inline HTMLDOMTextNode
*impl_from_IHTMLDOMTextNode2(IHTMLDOMTextNode2
*iface
)
156 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, IHTMLDOMTextNode2_iface
);
159 DISPEX_IDISPATCH_IMPL(HTMLDOMTextNode2
, IHTMLDOMTextNode2
,
160 impl_from_IHTMLDOMTextNode2(iface
)->node
.event_target
.dispex
)
162 static HRESULT WINAPI
HTMLDOMTextNode2_substringData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
, BSTR
*string
)
164 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
165 FIXME("(%p)->(%ld %ld %p)\n", This
, offset
, count
, string
);
169 static HRESULT WINAPI
HTMLDOMTextNode2_appendData(IHTMLDOMTextNode2
*iface
, BSTR string
)
171 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
175 TRACE("(%p)->(%s)\n", This
, debugstr_w(string
));
177 nsAString_InitDepend(&nsstr
, string
);
178 nsres
= nsIDOMText_AppendData(This
->nstext
, &nsstr
);
179 nsAString_Finish(&nsstr
);
180 if(NS_FAILED(nsres
)) {
181 ERR("AppendData failed: %08lx\n", nsres
);
188 static HRESULT WINAPI
HTMLDOMTextNode2_insertData(IHTMLDOMTextNode2
*iface
, LONG offset
, BSTR string
)
190 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
191 FIXME("(%p)->(%ld %s)\n", This
, offset
, debugstr_w(string
));
195 static HRESULT WINAPI
HTMLDOMTextNode2_deleteData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
)
197 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
198 FIXME("(%p)->(%ld %ld)\n", This
, offset
, count
);
202 static HRESULT WINAPI
HTMLDOMTextNode2_replaceData(IHTMLDOMTextNode2
*iface
, LONG offset
, LONG count
, BSTR string
)
204 HTMLDOMTextNode
*This
= impl_from_IHTMLDOMTextNode2(iface
);
205 FIXME("(%p)->(%ld %ld %s)\n", This
, offset
, count
, debugstr_w(string
));
209 static const IHTMLDOMTextNode2Vtbl HTMLDOMTextNode2Vtbl
= {
210 HTMLDOMTextNode2_QueryInterface
,
211 HTMLDOMTextNode2_AddRef
,
212 HTMLDOMTextNode2_Release
,
213 HTMLDOMTextNode2_GetTypeInfoCount
,
214 HTMLDOMTextNode2_GetTypeInfo
,
215 HTMLDOMTextNode2_GetIDsOfNames
,
216 HTMLDOMTextNode2_Invoke
,
217 HTMLDOMTextNode2_substringData
,
218 HTMLDOMTextNode2_appendData
,
219 HTMLDOMTextNode2_insertData
,
220 HTMLDOMTextNode2_deleteData
,
221 HTMLDOMTextNode2_replaceData
224 static inline HTMLDOMTextNode
*impl_from_HTMLDOMNode(HTMLDOMNode
*iface
)
226 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, node
);
229 static HRESULT
HTMLDOMTextNode_clone(HTMLDOMNode
*iface
, nsIDOMNode
*nsnode
, HTMLDOMNode
**ret
)
231 HTMLDOMTextNode
*This
= impl_from_HTMLDOMNode(iface
);
233 return HTMLDOMTextNode_Create(This
->node
.doc
, nsnode
, ret
);
236 static inline HTMLDOMTextNode
*impl_from_DispatchEx(DispatchEx
*iface
)
238 return CONTAINING_RECORD(iface
, HTMLDOMTextNode
, node
.event_target
.dispex
);
241 static void *HTMLDOMTextNode_query_interface(DispatchEx
*dispex
, REFIID riid
)
243 HTMLDOMTextNode
*This
= impl_from_DispatchEx(dispex
);
245 if(IsEqualGUID(&IID_IHTMLDOMTextNode
, riid
))
246 return &This
->IHTMLDOMTextNode_iface
;
247 if(IsEqualGUID(&IID_IHTMLDOMTextNode2
, riid
))
248 return &This
->IHTMLDOMTextNode2_iface
;
250 return HTMLDOMNode_query_interface(&This
->node
.event_target
.dispex
, riid
);
253 static const cpc_entry_t HTMLDOMTextNode_cpc
[] = {{NULL
}};
255 static const NodeImplVtbl HTMLDOMTextNodeImplVtbl
= {
256 .cpc_entries
= HTMLDOMTextNode_cpc
,
257 .clone
= HTMLDOMTextNode_clone
260 static const dispex_static_data_vtbl_t HTMLDOMTextNode_dispex_vtbl
= {
261 .query_interface
= HTMLDOMTextNode_query_interface
,
262 .destructor
= HTMLDOMNode_destructor
,
263 .traverse
= HTMLDOMNode_traverse
,
264 .unlink
= HTMLDOMNode_unlink
267 static const tid_t HTMLDOMTextNode_iface_tids
[] = {
270 IHTMLDOMTextNode_tid
,
271 IHTMLDOMTextNode2_tid
,
274 static dispex_static_data_t HTMLDOMTextNode_dispex
= {
276 &HTMLDOMTextNode_dispex_vtbl
,
277 DispHTMLDOMTextNode_tid
,
278 HTMLDOMTextNode_iface_tids
,
279 HTMLDOMNode_init_dispex_info
282 HRESULT
HTMLDOMTextNode_Create(HTMLDocumentNode
*doc
, nsIDOMNode
*nsnode
, HTMLDOMNode
**node
)
284 HTMLDOMTextNode
*ret
;
287 ret
= calloc(1, sizeof(*ret
));
289 return E_OUTOFMEMORY
;
291 ret
->node
.vtbl
= &HTMLDOMTextNodeImplVtbl
;
292 ret
->IHTMLDOMTextNode_iface
.lpVtbl
= &HTMLDOMTextNodeVtbl
;
293 ret
->IHTMLDOMTextNode2_iface
.lpVtbl
= &HTMLDOMTextNode2Vtbl
;
295 HTMLDOMNode_Init(doc
, &ret
->node
, nsnode
, &HTMLDOMTextNode_dispex
);
297 nsres
= nsIDOMNode_QueryInterface(nsnode
, &IID_nsIDOMText
, (void**)&ret
->nstext
);
298 assert(nsres
== NS_OK
&& (nsIDOMNode
*)ret
->nstext
== ret
->node
.nsnode
);
300 /* Share reference with nsnode */
301 nsIDOMNode_Release(ret
->node
.nsnode
);