2 * Copyright 2006-2007 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 "wine/debug.h"
30 #include "wine/unicode.h"
32 #include "mshtml_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
36 static const WCHAR brW
[] = {'b','r',0};
37 static const WCHAR hrW
[] = {'h','r',0};
40 const IHTMLTxtRangeVtbl
*lpHTMLTxtRangeVtbl
;
41 const IOleCommandTargetVtbl
*lpOleCommandTargetVtbl
;
51 #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
75 static HTMLTxtRange
*get_range_object(HTMLDocument
*doc
, IHTMLTxtRange
*iface
)
79 LIST_FOR_EACH_ENTRY(iter
, &doc
->range_list
, HTMLTxtRange
, entry
) {
80 if(HTMLTXTRANGE(iter
) == iface
)
84 ERR("Could not find range in document\n");
88 static range_unit_t
string_to_unit(LPCWSTR str
)
90 static const WCHAR characterW
[] =
91 {'c','h','a','r','a','c','t','e','r',0};
92 static const WCHAR wordW
[] =
94 static const WCHAR sentenceW
[] =
95 {'s','e','n','t','e','n','c','e',0};
96 static const WCHAR texteditW
[] =
97 {'t','e','x','t','e','d','i','t',0};
99 if(!strcmpiW(str
, characterW
)) return RU_CHAR
;
100 if(!strcmpiW(str
, wordW
)) return RU_WORD
;
101 if(!strcmpiW(str
, sentenceW
)) return RU_SENTENCE
;
102 if(!strcmpiW(str
, texteditW
)) return RU_TEXTEDIT
;
107 static int string_to_nscmptype(LPCWSTR str
)
109 static const WCHAR seW
[] = {'S','t','a','r','t','T','o','E','n','d',0};
110 static const WCHAR ssW
[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
111 static const WCHAR esW
[] = {'E','n','d','T','o','S','t','a','r','t',0};
112 static const WCHAR eeW
[] = {'E','n','d','T','o','E','n','d',0};
114 if(!strcmpiW(str
, seW
)) return NS_START_TO_END
;
115 if(!strcmpiW(str
, ssW
)) return NS_START_TO_START
;
116 if(!strcmpiW(str
, esW
)) return NS_END_TO_START
;
117 if(!strcmpiW(str
, eeW
)) return NS_END_TO_END
;
122 static PRUint16
get_node_type(nsIDOMNode
*node
)
127 nsIDOMNode_GetNodeType(node
, &type
);
132 static BOOL
is_elem_tag(nsIDOMNode
*node
, LPCWSTR istag
)
136 const PRUnichar
*tag
;
140 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
144 nsAString_Init(&tag_str
, NULL
);
145 nsIDOMElement_GetTagName(elem
, &tag_str
);
146 nsIDOMElement_Release(elem
);
147 nsAString_GetData(&tag_str
, &tag
);
149 ret
= !strcmpiW(tag
, istag
);
151 nsAString_Finish(&tag_str
);
156 static BOOL
is_space_elem(nsIDOMNode
*node
)
160 const PRUnichar
*tag
;
164 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMElement
, (void**)&elem
);
168 nsAString_Init(&tag_str
, NULL
);
169 nsIDOMElement_GetTagName(elem
, &tag_str
);
170 nsIDOMElement_Release(elem
);
171 nsAString_GetData(&tag_str
, &tag
);
173 ret
= !strcmpiW(tag
, brW
) || !strcmpiW(tag
, hrW
);
175 nsAString_Finish(&tag_str
);
180 static inline void wstrbuf_init(wstrbuf_t
*buf
)
184 buf
->buf
= heap_alloc(buf
->size
* sizeof(WCHAR
));
188 static inline void wstrbuf_finish(wstrbuf_t
*buf
)
193 static void wstrbuf_append_len(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
195 if(buf
->len
+len
>= buf
->size
) {
196 buf
->size
= 2*buf
->len
+len
;
197 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
200 memcpy(buf
->buf
+buf
->len
, str
, len
*sizeof(WCHAR
));
202 buf
->buf
[buf
->len
] = 0;
205 static void wstrbuf_append_nodetxt(wstrbuf_t
*buf
, LPCWSTR str
, int len
)
207 const WCHAR
*s
= str
;
210 TRACE("%s\n", debugstr_wn(str
, len
));
212 if(buf
->len
+len
>= buf
->size
) {
213 buf
->size
= 2*buf
->len
+len
;
214 buf
->buf
= heap_realloc(buf
->buf
, buf
->size
* sizeof(WCHAR
));
217 if(buf
->len
&& isspaceW(buf
->buf
[buf
->len
-1])) {
218 while(s
< str
+len
&& isspaceW(*s
))
222 d
= buf
->buf
+buf
->len
;
227 while(s
< str
+len
&& isspaceW(*s
))
234 buf
->len
= d
- buf
->buf
;
238 static void wstrbuf_append_node(wstrbuf_t
*buf
, nsIDOMNode
*node
)
241 switch(get_node_type(node
)) {
245 const PRUnichar
*data
;
247 nsIDOMNode_QueryInterface(node
, &IID_nsIDOMText
, (void**)&nstext
);
249 nsAString_Init(&data_str
, NULL
);
250 nsIDOMText_GetData(nstext
, &data_str
);
251 nsAString_GetData(&data_str
, &data
);
252 wstrbuf_append_nodetxt(buf
, data
, strlenW(data
));
253 nsAString_Finish(&data_str
);
255 nsIDOMText_Release(nstext
);
260 if(is_elem_tag(node
, brW
)) {
261 static const WCHAR endlW
[] = {'\r','\n'};
262 wstrbuf_append_len(buf
, endlW
, 2);
263 }else if(is_elem_tag(node
, hrW
)) {
264 static const WCHAR endl2W
[] = {'\r','\n','\r','\n'};
265 wstrbuf_append_len(buf
, endl2W
, 4);
270 static BOOL
fill_nodestr(dompos_t
*pos
)
275 if(pos
->type
!= TEXT_NODE
)
278 nsres
= nsIDOMNode_QueryInterface(pos
->node
, &IID_nsIDOMText
, (void**)&text
);
282 nsAString_Init(&pos
->str
, NULL
);
283 nsIDOMText_GetData(text
, &pos
->str
);
284 nsIDOMText_Release(text
);
285 nsAString_GetData(&pos
->str
, &pos
->p
);
288 pos
->off
= *pos
->p
? strlenW(pos
->p
)-1 : 0;
293 static nsIDOMNode
*next_node(nsIDOMNode
*iter
)
295 nsIDOMNode
*ret
, *tmp
;
301 nsres
= nsIDOMNode_GetFirstChild(iter
, &ret
);
302 if(NS_SUCCEEDED(nsres
) && ret
)
305 nsIDOMNode_AddRef(iter
);
308 nsres
= nsIDOMNode_GetNextSibling(iter
, &ret
);
309 if(NS_SUCCEEDED(nsres
) && ret
) {
310 nsIDOMNode_Release(iter
);
314 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
315 nsIDOMNode_Release(iter
);
317 }while(NS_SUCCEEDED(nsres
) && iter
);
322 static nsIDOMNode
*prev_node(HTMLTxtRange
*This
, nsIDOMNode
*iter
)
324 nsIDOMNode
*ret
, *tmp
;
328 nsIDOMHTMLElement
*nselem
;
330 nsIDOMHTMLDocument_GetBody(This
->doc
->nsdoc
, &nselem
);
331 nsIDOMElement_GetLastChild(nselem
, &tmp
);
333 return (nsIDOMNode
*)nselem
;
337 nsIDOMNode_GetLastChild(ret
, &tmp
);
340 nsIDOMElement_Release(nselem
);
345 nsres
= nsIDOMNode_GetLastChild(iter
, &ret
);
346 if(NS_SUCCEEDED(nsres
) && ret
)
349 nsIDOMNode_AddRef(iter
);
352 nsres
= nsIDOMNode_GetPreviousSibling(iter
, &ret
);
353 if(NS_SUCCEEDED(nsres
) && ret
) {
354 nsIDOMNode_Release(iter
);
358 nsres
= nsIDOMNode_GetParentNode(iter
, &tmp
);
359 nsIDOMNode_Release(iter
);
361 }while(NS_SUCCEEDED(nsres
) && iter
);
366 static nsIDOMNode
*get_child_node(nsIDOMNode
*node
, PRUint32 off
)
368 nsIDOMNodeList
*node_list
;
369 nsIDOMNode
*ret
= NULL
;
371 nsIDOMNode_GetChildNodes(node
, &node_list
);
372 nsIDOMNodeList_Item(node_list
, off
, &ret
);
373 nsIDOMNodeList_Release(node_list
);
378 static void get_cur_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
387 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
392 nsIDOMRange_GetStartContainer(This
->nsrange
, &node
);
393 nsIDOMRange_GetStartOffset(This
->nsrange
, &off
);
395 nsIDOMRange_GetEndContainer(This
->nsrange
, &node
);
396 nsIDOMRange_GetEndOffset(This
->nsrange
, &off
);
399 pos
->type
= get_node_type(node
);
400 if(pos
->type
== ELEMENT_NODE
) {
402 pos
->node
= get_child_node(node
, off
);
405 pos
->node
= off
? get_child_node(node
, off
-1) : prev_node(This
, node
);
409 pos
->type
= get_node_type(pos
->node
);
410 nsIDOMNode_Release(node
);
418 pos
->node
= prev_node(This
, node
);
420 nsIDOMNode_Release(node
);
423 if(pos
->type
== TEXT_NODE
)
427 static void set_range_pos(HTMLTxtRange
*This
, BOOL start
, dompos_t
*pos
)
432 if(pos
->type
== TEXT_NODE
)
433 nsres
= nsIDOMRange_SetStart(This
->nsrange
, pos
->node
, pos
->off
);
435 nsres
= nsIDOMRange_SetStartBefore(This
->nsrange
, pos
->node
);
437 if(pos
->type
== TEXT_NODE
&& pos
->p
[pos
->off
+1])
438 nsres
= nsIDOMRange_SetEnd(This
->nsrange
, pos
->node
, pos
->off
+1);
440 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, pos
->node
);
444 ERR("failed: %p %08x\n", pos
->node
, nsres
);
447 static inline void dompos_release(dompos_t
*pos
)
450 nsIDOMNode_Release(pos
->node
);
453 nsAString_Finish(&pos
->str
);
456 static inline void dompos_addref(dompos_t
*pos
)
459 nsIDOMNode_AddRef(pos
->node
);
461 if(pos
->type
== TEXT_NODE
)
465 static inline BOOL
dompos_cmp(const dompos_t
*pos1
, const dompos_t
*pos2
)
467 return pos1
->node
== pos2
->node
&& pos1
->off
== pos2
->off
;
470 static void range_to_string(HTMLTxtRange
*This
, wstrbuf_t
*buf
)
472 nsIDOMNode
*iter
, *tmp
;
473 dompos_t start_pos
, end_pos
;
476 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
484 get_cur_pos(This
, FALSE
, &end_pos
);
485 get_cur_pos(This
, TRUE
, &start_pos
);
487 if(start_pos
.type
== TEXT_NODE
) {
488 if(start_pos
.node
== end_pos
.node
) {
489 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, end_pos
.off
-start_pos
.off
+1);
490 iter
= start_pos
.node
;
491 nsIDOMNode_AddRef(iter
);
493 wstrbuf_append_nodetxt(buf
, start_pos
.p
+start_pos
.off
, strlenW(start_pos
.p
+start_pos
.off
));
494 iter
= next_node(start_pos
.node
);
497 iter
= start_pos
.node
;
498 nsIDOMNode_AddRef(iter
);
501 while(iter
!= end_pos
.node
) {
502 wstrbuf_append_node(buf
, iter
);
503 tmp
= next_node(iter
);
504 nsIDOMNode_Release(iter
);
508 nsIDOMNode_AddRef(end_pos
.node
);
510 if(start_pos
.node
!= end_pos
.node
) {
511 if(end_pos
.type
== TEXT_NODE
)
512 wstrbuf_append_nodetxt(buf
, end_pos
.p
, end_pos
.off
+1);
514 wstrbuf_append_node(buf
, end_pos
.node
);
517 nsIDOMNode_Release(iter
);
518 dompos_release(&start_pos
);
519 dompos_release(&end_pos
);
524 for(p
= buf
->buf
+buf
->len
-1; p
>= buf
->buf
&& isspaceW(*p
); p
--);
526 p
= strchrW(p
, '\r');
532 static WCHAR
get_pos_char(const dompos_t
*pos
)
536 return pos
->p
[pos
->off
];
538 if(is_space_elem(pos
->node
))
545 static void end_space(const dompos_t
*pos
, dompos_t
*new_pos
)
550 dompos_addref(new_pos
);
552 if(pos
->type
!= TEXT_NODE
)
555 p
= new_pos
->p
+new_pos
->off
;
557 if(!*p
|| !isspace(*p
))
560 while(p
[1] && isspace(p
[1]))
563 new_pos
->off
= p
- new_pos
->p
;
566 static WCHAR
next_char(const dompos_t
*pos
, dompos_t
*new_pos
)
568 nsIDOMNode
*iter
, *tmp
;
569 dompos_t last_space
, tmp_pos
;
573 if(pos
->type
== TEXT_NODE
&& pos
->off
!= -1 && pos
->p
[pos
->off
]) {
577 while(isspaceW(*++p
));
581 if(*p
&& isspaceW(*p
)) {
583 while(p
[1] && isspaceW(p
[1]))
589 new_pos
->off
= p
- pos
->p
;
590 dompos_addref(new_pos
);
592 return cspace
? cspace
: *p
;
595 last_space
.off
= p
- pos
->p
;
596 dompos_addref(&last_space
);
600 iter
= next_node(pos
->node
);
603 switch(get_node_type(iter
)) {
606 tmp_pos
.type
= TEXT_NODE
;
608 dompos_addref(&tmp_pos
);
613 dompos_release(&tmp_pos
);
615 }else if(isspaceW(*p
)) {
617 dompos_release(&last_space
);
621 while(p
[1] && isspaceW(p
[1]))
624 tmp_pos
.off
= p
-tmp_pos
.p
;
627 last_space
= tmp_pos
;
632 nsIDOMNode_Release(iter
);
635 *new_pos
= last_space
;
636 dompos_release(&tmp_pos
);
637 nsIDOMNode_Release(iter
);
645 nsIDOMNode_Release(iter
);
649 if(is_elem_tag(iter
, brW
)) {
651 dompos_release(&last_space
);
654 nsIDOMNode_AddRef(iter
);
655 last_space
.node
= iter
;
656 last_space
.type
= ELEMENT_NODE
;
659 }else if(is_elem_tag(iter
, hrW
)) {
661 *new_pos
= last_space
;
662 nsIDOMNode_Release(iter
);
666 new_pos
->node
= iter
;
667 new_pos
->type
= ELEMENT_NODE
;
675 iter
= next_node(iter
);
676 nsIDOMNode_Release(tmp
);
680 *new_pos
= last_space
;
683 dompos_addref(new_pos
);
689 static WCHAR
prev_char(HTMLTxtRange
*This
, const dompos_t
*pos
, dompos_t
*new_pos
)
691 nsIDOMNode
*iter
, *tmp
;
693 BOOL skip_space
= FALSE
;
695 if(pos
->type
== TEXT_NODE
&& isspaceW(pos
->p
[pos
->off
]))
698 if(pos
->type
== TEXT_NODE
&& pos
->off
) {
699 p
= pos
->p
+pos
->off
-1;
702 while(p
>= pos
->p
&& isspace(*p
))
708 new_pos
->off
= p
-pos
->p
;
709 dompos_addref(new_pos
);
710 return new_pos
->p
[new_pos
->off
];
714 iter
= prev_node(This
, pos
->node
);
717 switch(get_node_type(iter
)) {
722 tmp_pos
.type
= TEXT_NODE
;
724 dompos_addref(&tmp_pos
);
726 p
= tmp_pos
.p
+ strlenW(tmp_pos
.p
)-1;
729 while(p
>= tmp_pos
.p
&& isspaceW(*p
))
734 dompos_release(&tmp_pos
);
738 tmp_pos
.off
= p
-tmp_pos
.p
;
740 nsIDOMNode_Release(iter
);
745 if(is_elem_tag(iter
, brW
)) {
750 }else if(!is_elem_tag(iter
, hrW
)) {
754 new_pos
->node
= iter
;
755 new_pos
->type
= ELEMENT_NODE
;
762 iter
= prev_node(This
, iter
);
763 nsIDOMNode_Release(tmp
);
767 dompos_addref(new_pos
);
771 static long move_next_chars(long cnt
, const dompos_t
*pos
, BOOL col
, const dompos_t
*bound_pos
,
772 BOOL
*bounded
, dompos_t
*new_pos
)
785 end_space(pos
, new_pos
);
789 c
= next_char(pos
, &iter
);
794 c
= next_char(&tmp
, &iter
);
795 dompos_release(&tmp
);
800 if(bound_pos
&& dompos_cmp(&tmp
, bound_pos
)) {
810 static long move_prev_chars(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, BOOL end
,
811 const dompos_t
*bound_pos
, BOOL
*bounded
, dompos_t
*new_pos
)
815 BOOL prev_eq
= FALSE
;
821 c
= prev_char(This
, pos
, &iter
);
825 while(c
&& ret
< cnt
) {
827 c
= prev_char(This
, &tmp
, &iter
);
828 dompos_release(&tmp
);
842 prev_eq
= bound_pos
&& dompos_cmp(&iter
, bound_pos
);
849 static long find_prev_space(HTMLTxtRange
*This
, const dompos_t
*pos
, BOOL first_space
, dompos_t
*ret
)
854 c
= prev_char(This
, pos
, &iter
);
855 if(!c
|| (first_space
&& isspaceW(c
))) {
862 c
= prev_char(This
, &tmp
, &iter
);
863 if(!c
|| isspaceW(c
)) {
864 dompos_release(&iter
);
867 dompos_release(&tmp
);
874 static int find_word_end(const dompos_t
*pos
, dompos_t
*ret
)
879 c
= get_pos_char(pos
);
886 c
= next_char(pos
, &iter
);
897 while(c
&& !isspaceW(c
)) {
899 c
= next_char(&tmp
, &iter
);
901 dompos_release(&iter
);
905 dompos_release(&tmp
);
913 static long move_next_words(long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
919 c
= get_pos_char(pos
);
921 end_space(pos
, &iter
);
924 c
= next_char(pos
, &iter
);
929 while(c
&& ret
< cnt
) {
931 c
= next_char(&tmp
, &iter
);
932 dompos_release(&tmp
);
941 static long move_prev_words(HTMLTxtRange
*This
, long cnt
, const dompos_t
*pos
, dompos_t
*new_pos
)
947 dompos_addref(&iter
);
950 if(!find_prev_space(This
, &iter
, FALSE
, &tmp
))
953 dompos_release(&iter
);
962 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
964 static HRESULT WINAPI
HTMLTxtRange_QueryInterface(IHTMLTxtRange
*iface
, REFIID riid
, void **ppv
)
966 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
970 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
971 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
972 *ppv
= HTMLTXTRANGE(This
);
973 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
974 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
975 *ppv
= HTMLTXTRANGE(This
);
976 }else if(IsEqualGUID(&IID_IHTMLTxtRange
, riid
)) {
977 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This
, ppv
);
978 *ppv
= HTMLTXTRANGE(This
);
979 }else if(IsEqualGUID(&IID_IOleCommandTarget
, riid
)) {
980 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This
, ppv
);
981 *ppv
= CMDTARGET(This
);
985 IUnknown_AddRef((IUnknown
*)*ppv
);
989 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
990 return E_NOINTERFACE
;
993 static ULONG WINAPI
HTMLTxtRange_AddRef(IHTMLTxtRange
*iface
)
995 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
996 LONG ref
= InterlockedIncrement(&This
->ref
);
998 TRACE("(%p) ref=%d\n", This
, ref
);
1003 static ULONG WINAPI
HTMLTxtRange_Release(IHTMLTxtRange
*iface
)
1005 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1006 LONG ref
= InterlockedDecrement(&This
->ref
);
1008 TRACE("(%p) ref=%d\n", This
, ref
);
1012 nsISelection_Release(This
->nsrange
);
1014 list_remove(&This
->entry
);
1021 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange
*iface
, UINT
*pctinfo
)
1023 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1024 FIXME("(%p)->(%p)\n", This
, pctinfo
);
1028 static HRESULT WINAPI
HTMLTxtRange_GetTypeInfo(IHTMLTxtRange
*iface
, UINT iTInfo
,
1029 LCID lcid
, ITypeInfo
**ppTInfo
)
1031 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1032 FIXME("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1036 static HRESULT WINAPI
HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange
*iface
, REFIID riid
,
1037 LPOLESTR
*rgszNames
, UINT cNames
,
1038 LCID lcid
, DISPID
*rgDispId
)
1040 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1041 FIXME("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1046 static HRESULT WINAPI
HTMLTxtRange_Invoke(IHTMLTxtRange
*iface
, DISPID dispIdMember
,
1047 REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
,
1048 VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1050 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1051 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1052 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1056 static HRESULT WINAPI
HTMLTxtRange_get_htmlText(IHTMLTxtRange
*iface
, BSTR
*p
)
1058 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1060 TRACE("(%p)->(%p)\n", This
, p
);
1065 nsIDOMDocumentFragment
*fragment
;
1068 nsres
= nsIDOMRange_CloneContents(This
->nsrange
, &fragment
);
1069 if(NS_SUCCEEDED(nsres
)) {
1070 const PRUnichar
*nstext
;
1073 nsAString_Init(&nsstr
, NULL
);
1074 nsnode_to_nsstring((nsIDOMNode
*)fragment
, &nsstr
);
1075 nsIDOMDocumentFragment_Release(fragment
);
1077 nsAString_GetData(&nsstr
, &nstext
);
1078 *p
= SysAllocString(nstext
);
1080 nsAString_Finish(&nsstr
);
1085 const WCHAR emptyW
[] = {0};
1086 *p
= SysAllocString(emptyW
);
1089 TRACE("return %s\n", debugstr_w(*p
));
1093 static HRESULT WINAPI
HTMLTxtRange_put_text(IHTMLTxtRange
*iface
, BSTR v
)
1095 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1096 nsIDOMText
*text_node
;
1100 TRACE("(%p)->(%s)\n", This
, debugstr_w(v
));
1103 return MSHTML_E_NODOC
;
1105 nsAString_Init(&text_str
, v
);
1106 nsres
= nsIDOMHTMLDocument_CreateTextNode(This
->doc
->nsdoc
, &text_str
, &text_node
);
1107 nsAString_Finish(&text_str
);
1108 if(NS_FAILED(nsres
)) {
1109 ERR("CreateTextNode failed: %08x\n", nsres
);
1112 nsres
= nsIDOMRange_DeleteContents(This
->nsrange
);
1113 if(NS_FAILED(nsres
))
1114 ERR("DeleteContents failed: %08x\n", nsres
);
1116 nsres
= nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)text_node
);
1117 if(NS_FAILED(nsres
))
1118 ERR("InsertNode failed: %08x\n", nsres
);
1120 nsres
= nsIDOMRange_SetEndAfter(This
->nsrange
, (nsIDOMNode
*)text_node
);
1121 if(NS_FAILED(nsres
))
1122 ERR("SetEndAfter failed: %08x\n", nsres
);
1124 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), VARIANT_FALSE
);
1127 static HRESULT WINAPI
HTMLTxtRange_get_text(IHTMLTxtRange
*iface
, BSTR
*p
)
1129 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1132 TRACE("(%p)->(%p)\n", This
, p
);
1139 range_to_string(This
, &buf
);
1141 *p
= SysAllocString(buf
.buf
);
1142 wstrbuf_finish(&buf
);
1144 TRACE("ret %s\n", debugstr_w(*p
));
1148 static HRESULT WINAPI
HTMLTxtRange_parentElement(IHTMLTxtRange
*iface
, IHTMLElement
**parent
)
1150 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1151 nsIDOMNode
*nsnode
, *tmp
;
1154 TRACE("(%p)->(%p)\n", This
, parent
);
1156 nsIDOMRange_GetCommonAncestorContainer(This
->nsrange
, &nsnode
);
1157 while(nsnode
&& get_node_type(nsnode
) != ELEMENT_NODE
) {
1158 nsIDOMNode_GetParentNode(nsnode
, &tmp
);
1159 nsIDOMNode_Release(nsnode
);
1168 node
= get_node(This
->doc
, nsnode
, TRUE
);
1169 nsIDOMNode_Release(nsnode
);
1171 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node
), &IID_IHTMLElement
, (void**)parent
);
1174 static HRESULT WINAPI
HTMLTxtRange_duplicate(IHTMLTxtRange
*iface
, IHTMLTxtRange
**Duplicate
)
1176 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1177 nsIDOMRange
*nsrange
= NULL
;
1179 TRACE("(%p)->(%p)\n", This
, Duplicate
);
1181 nsIDOMRange_CloneRange(This
->nsrange
, &nsrange
);
1182 *Duplicate
= HTMLTxtRange_Create(This
->doc
, nsrange
);
1183 nsIDOMRange_Release(nsrange
);
1188 static HRESULT WINAPI
HTMLTxtRange_inRange(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1189 VARIANT_BOOL
*InRange
)
1191 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1192 HTMLTxtRange
*src_range
;
1196 TRACE("(%p)->(%p %p)\n", This
, Range
, InRange
);
1198 *InRange
= VARIANT_FALSE
;
1200 src_range
= get_range_object(This
->doc
, Range
);
1204 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1205 src_range
->nsrange
, &nsret
);
1206 if(NS_SUCCEEDED(nsres
) && nsret
<= 0) {
1207 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1208 src_range
->nsrange
, &nsret
);
1209 if(NS_SUCCEEDED(nsres
) && nsret
>= 0)
1210 *InRange
= VARIANT_TRUE
;
1213 if(NS_FAILED(nsres
))
1214 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1219 static HRESULT WINAPI
HTMLTxtRange_isEqual(IHTMLTxtRange
*iface
, IHTMLTxtRange
*Range
,
1220 VARIANT_BOOL
*IsEqual
)
1222 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1223 HTMLTxtRange
*src_range
;
1227 TRACE("(%p)->(%p %p)\n", This
, Range
, IsEqual
);
1229 *IsEqual
= VARIANT_FALSE
;
1231 src_range
= get_range_object(This
->doc
, Range
);
1235 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_START_TO_START
,
1236 src_range
->nsrange
, &nsret
);
1237 if(NS_SUCCEEDED(nsres
) && !nsret
) {
1238 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, NS_END_TO_END
,
1239 src_range
->nsrange
, &nsret
);
1240 if(NS_SUCCEEDED(nsres
) && !nsret
)
1241 *IsEqual
= VARIANT_TRUE
;
1244 if(NS_FAILED(nsres
))
1245 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1250 static HRESULT WINAPI
HTMLTxtRange_scrollIntoView(IHTMLTxtRange
*iface
, VARIANT_BOOL fStart
)
1252 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1253 FIXME("(%p)->(%x)\n", This
, fStart
);
1257 static HRESULT WINAPI
HTMLTxtRange_collapse(IHTMLTxtRange
*iface
, VARIANT_BOOL Start
)
1259 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1261 TRACE("(%p)->(%x)\n", This
, Start
);
1263 nsIDOMRange_Collapse(This
->nsrange
, Start
!= VARIANT_FALSE
);
1267 static HRESULT WINAPI
HTMLTxtRange_expand(IHTMLTxtRange
*iface
, BSTR Unit
, VARIANT_BOOL
*Success
)
1269 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1272 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(Unit
), Success
);
1274 unit
= string_to_unit(Unit
);
1275 if(unit
== RU_UNKNOWN
)
1276 return E_INVALIDARG
;
1278 *Success
= VARIANT_FALSE
;
1282 dompos_t end_pos
, start_pos
, new_start_pos
, new_end_pos
;
1285 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1287 get_cur_pos(This
, TRUE
, &start_pos
);
1288 get_cur_pos(This
, FALSE
, &end_pos
);
1290 if(find_word_end(&end_pos
, &new_end_pos
) || collapsed
) {
1291 set_range_pos(This
, FALSE
, &new_end_pos
);
1292 *Success
= VARIANT_TRUE
;
1295 if(start_pos
.type
&& (get_pos_char(&end_pos
) || !dompos_cmp(&new_end_pos
, &end_pos
))) {
1296 if(find_prev_space(This
, &start_pos
, TRUE
, &new_start_pos
)) {
1297 set_range_pos(This
, TRUE
, &new_start_pos
);
1298 *Success
= VARIANT_TRUE
;
1300 dompos_release(&new_start_pos
);
1303 dompos_release(&new_end_pos
);
1304 dompos_release(&end_pos
);
1305 dompos_release(&start_pos
);
1311 nsIDOMDocument
*nsdoc
;
1312 nsIDOMHTMLDocument
*nshtmldoc
;
1313 nsIDOMHTMLElement
*nsbody
= NULL
;
1316 nsres
= nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1317 if(NS_FAILED(nsres
) || !nsdoc
) {
1318 ERR("GetDocument failed: %08x\n", nsres
);
1322 nsIDOMDocument_QueryInterface(nsdoc
, &IID_nsIDOMHTMLDocument
, (void**)&nshtmldoc
);
1323 nsIDOMDocument_Release(nsdoc
);
1325 nsres
= nsIDOMHTMLDocument_GetBody(nshtmldoc
, &nsbody
);
1326 nsIDOMHTMLDocument_Release(nshtmldoc
);
1327 if(NS_FAILED(nsres
) || !nsbody
) {
1328 ERR("Could not get body: %08x\n", nsres
);
1332 nsres
= nsIDOMRange_SelectNodeContents(This
->nsrange
, (nsIDOMNode
*)nsbody
);
1333 nsIDOMHTMLElement_Release(nsbody
);
1334 if(NS_FAILED(nsres
)) {
1335 ERR("Collapse failed: %08x\n", nsres
);
1339 *Success
= VARIANT_TRUE
;
1344 FIXME("Unimplemented unit %s\n", debugstr_w(Unit
));
1350 static HRESULT WINAPI
HTMLTxtRange_move(IHTMLTxtRange
*iface
, BSTR Unit
,
1351 long Count
, long *ActualCount
)
1353 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1356 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1358 unit
= string_to_unit(Unit
);
1359 if(unit
== RU_UNKNOWN
)
1360 return E_INVALIDARG
;
1364 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1369 dompos_t cur_pos
, new_pos
;
1371 get_cur_pos(This
, TRUE
, &cur_pos
);
1374 *ActualCount
= move_next_chars(Count
, &cur_pos
, TRUE
, NULL
, NULL
, &new_pos
);
1375 set_range_pos(This
, FALSE
, &new_pos
);
1376 dompos_release(&new_pos
);
1378 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1380 *ActualCount
= -move_prev_chars(This
, -Count
, &cur_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1381 set_range_pos(This
, TRUE
, &new_pos
);
1382 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1383 dompos_release(&new_pos
);
1386 dompos_release(&cur_pos
);
1391 dompos_t cur_pos
, new_pos
;
1393 get_cur_pos(This
, TRUE
, &cur_pos
);
1396 *ActualCount
= move_next_words(Count
, &cur_pos
, &new_pos
);
1397 set_range_pos(This
, FALSE
, &new_pos
);
1398 dompos_release(&new_pos
);
1399 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1401 *ActualCount
= -move_prev_words(This
, -Count
, &cur_pos
, &new_pos
);
1402 set_range_pos(This
, TRUE
, &new_pos
);
1403 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1404 dompos_release(&new_pos
);
1407 dompos_release(&cur_pos
);
1412 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1415 TRACE("ret %ld\n", *ActualCount
);
1419 static HRESULT WINAPI
HTMLTxtRange_moveStart(IHTMLTxtRange
*iface
, BSTR Unit
,
1420 long Count
, long *ActualCount
)
1422 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1425 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1427 unit
= string_to_unit(Unit
);
1428 if(unit
== RU_UNKNOWN
)
1429 return E_INVALIDARG
;
1438 dompos_t start_pos
, end_pos
, new_pos
;
1441 get_cur_pos(This
, TRUE
, &start_pos
);
1442 get_cur_pos(This
, FALSE
, &end_pos
);
1443 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1448 *ActualCount
= move_next_chars(Count
, &start_pos
, collapsed
, &end_pos
, &bounded
, &new_pos
);
1449 set_range_pos(This
, !bounded
, &new_pos
);
1451 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), FALSE
);
1453 *ActualCount
= -move_prev_chars(This
, -Count
, &start_pos
, FALSE
, NULL
, NULL
, &new_pos
);
1454 set_range_pos(This
, TRUE
, &new_pos
);
1457 dompos_release(&start_pos
);
1458 dompos_release(&end_pos
);
1459 dompos_release(&new_pos
);
1464 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1470 static HRESULT WINAPI
HTMLTxtRange_moveEnd(IHTMLTxtRange
*iface
, BSTR Unit
,
1471 long Count
, long *ActualCount
)
1473 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1476 TRACE("(%p)->(%s %ld %p)\n", This
, debugstr_w(Unit
), Count
, ActualCount
);
1478 unit
= string_to_unit(Unit
);
1479 if(unit
== RU_UNKNOWN
)
1480 return E_INVALIDARG
;
1489 dompos_t start_pos
, end_pos
, new_pos
;
1492 get_cur_pos(This
, TRUE
, &start_pos
);
1493 get_cur_pos(This
, FALSE
, &end_pos
);
1494 nsIDOMRange_GetCollapsed(This
->nsrange
, &collapsed
);
1497 *ActualCount
= move_next_chars(Count
, &end_pos
, collapsed
, NULL
, NULL
, &new_pos
);
1498 set_range_pos(This
, FALSE
, &new_pos
);
1502 *ActualCount
= -move_prev_chars(This
, -Count
, &end_pos
, TRUE
, &start_pos
, &bounded
, &new_pos
);
1503 set_range_pos(This
, bounded
, &new_pos
);
1505 IHTMLTxtRange_collapse(HTMLTXTRANGE(This
), TRUE
);
1508 dompos_release(&start_pos
);
1509 dompos_release(&end_pos
);
1510 dompos_release(&new_pos
);
1515 FIXME("unimplemented unit %s\n", debugstr_w(Unit
));
1521 static HRESULT WINAPI
HTMLTxtRange_select(IHTMLTxtRange
*iface
)
1523 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1525 TRACE("(%p)\n", This
);
1527 if(This
->doc
->nscontainer
) {
1528 nsIDOMWindow
*dom_window
= NULL
;
1529 nsISelection
*nsselection
;
1531 nsIWebBrowser_GetContentDOMWindow(This
->doc
->nscontainer
->webbrowser
, &dom_window
);
1532 nsIDOMWindow_GetSelection(dom_window
, &nsselection
);
1533 nsIDOMWindow_Release(dom_window
);
1535 nsISelection_RemoveAllRanges(nsselection
);
1536 nsISelection_AddRange(nsselection
, This
->nsrange
);
1538 nsISelection_Release(nsselection
);
1544 static HRESULT WINAPI
HTMLTxtRange_pasteHTML(IHTMLTxtRange
*iface
, BSTR html
)
1546 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1547 FIXME("(%p)->(%s)\n", This
, debugstr_w(html
));
1551 static HRESULT WINAPI
HTMLTxtRange_moveToElementText(IHTMLTxtRange
*iface
, IHTMLElement
*element
)
1553 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1554 FIXME("(%p)->(%p)\n", This
, element
);
1558 static HRESULT WINAPI
HTMLTxtRange_setEndPoint(IHTMLTxtRange
*iface
, BSTR how
,
1559 IHTMLTxtRange
*SourceRange
)
1561 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1562 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(how
), SourceRange
);
1566 static HRESULT WINAPI
HTMLTxtRange_compareEndPoints(IHTMLTxtRange
*iface
, BSTR how
,
1567 IHTMLTxtRange
*SourceRange
, long *ret
)
1569 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1570 HTMLTxtRange
*src_range
;
1575 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_w(how
), SourceRange
, ret
);
1577 nscmpt
= string_to_nscmptype(how
);
1579 return E_INVALIDARG
;
1581 src_range
= get_range_object(This
->doc
, SourceRange
);
1585 nsres
= nsIDOMRange_CompareBoundaryPoints(This
->nsrange
, nscmpt
, src_range
->nsrange
, &nsret
);
1586 if(NS_FAILED(nsres
))
1587 ERR("CompareBoundaryPoints failed: %08x\n", nsres
);
1593 static HRESULT WINAPI
HTMLTxtRange_findText(IHTMLTxtRange
*iface
, BSTR String
,
1594 long count
, long Flags
, VARIANT_BOOL
*Success
)
1596 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1597 FIXME("(%p)->(%s %ld %08lx %p)\n", This
, debugstr_w(String
), count
, Flags
, Success
);
1601 static HRESULT WINAPI
HTMLTxtRange_moveToPoint(IHTMLTxtRange
*iface
, long x
, long y
)
1603 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1604 FIXME("(%p)->(%ld %ld)\n", This
, x
, y
);
1608 static HRESULT WINAPI
HTMLTxtRange_getBookmark(IHTMLTxtRange
*iface
, BSTR
*Bookmark
)
1610 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1611 FIXME("(%p)->(%p)\n", This
, Bookmark
);
1615 static HRESULT WINAPI
HTMLTxtRange_moveToBookmark(IHTMLTxtRange
*iface
, BSTR Bookmark
,
1616 VARIANT_BOOL
*Success
)
1618 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1619 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(Bookmark
), Success
);
1623 static HRESULT WINAPI
HTMLTxtRange_queryCommandSupported(IHTMLTxtRange
*iface
, BSTR cmdID
,
1624 VARIANT_BOOL
*pfRet
)
1626 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1627 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1631 static HRESULT WINAPI
HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange
*iface
, BSTR cmdID
,
1632 VARIANT_BOOL
*pfRet
)
1634 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1635 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1639 static HRESULT WINAPI
HTMLTxtRange_queryCommandState(IHTMLTxtRange
*iface
, BSTR cmdID
,
1640 VARIANT_BOOL
*pfRet
)
1642 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1643 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1647 static HRESULT WINAPI
HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange
*iface
, BSTR cmdID
,
1648 VARIANT_BOOL
*pfRet
)
1650 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1651 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1655 static HRESULT WINAPI
HTMLTxtRange_queryCommandText(IHTMLTxtRange
*iface
, BSTR cmdID
,
1658 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1659 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdText
);
1663 static HRESULT WINAPI
HTMLTxtRange_queryCommandValue(IHTMLTxtRange
*iface
, BSTR cmdID
,
1666 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1667 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pcmdValue
);
1671 static HRESULT WINAPI
HTMLTxtRange_execCommand(IHTMLTxtRange
*iface
, BSTR cmdID
,
1672 VARIANT_BOOL showUI
, VARIANT value
, VARIANT_BOOL
*pfRet
)
1674 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1675 FIXME("(%p)->(%s %x v %p)\n", This
, debugstr_w(cmdID
), showUI
, pfRet
);
1679 static HRESULT WINAPI
HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange
*iface
, BSTR cmdID
,
1680 VARIANT_BOOL
*pfRet
)
1682 HTMLTxtRange
*This
= HTMLTXTRANGE_THIS(iface
);
1683 FIXME("(%p)->(%s %p)\n", This
, debugstr_w(cmdID
), pfRet
);
1687 #undef HTMLTXTRANGE_THIS
1689 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl
= {
1690 HTMLTxtRange_QueryInterface
,
1691 HTMLTxtRange_AddRef
,
1692 HTMLTxtRange_Release
,
1693 HTMLTxtRange_GetTypeInfoCount
,
1694 HTMLTxtRange_GetTypeInfo
,
1695 HTMLTxtRange_GetIDsOfNames
,
1696 HTMLTxtRange_Invoke
,
1697 HTMLTxtRange_get_htmlText
,
1698 HTMLTxtRange_put_text
,
1699 HTMLTxtRange_get_text
,
1700 HTMLTxtRange_parentElement
,
1701 HTMLTxtRange_duplicate
,
1702 HTMLTxtRange_inRange
,
1703 HTMLTxtRange_isEqual
,
1704 HTMLTxtRange_scrollIntoView
,
1705 HTMLTxtRange_collapse
,
1706 HTMLTxtRange_expand
,
1708 HTMLTxtRange_moveStart
,
1709 HTMLTxtRange_moveEnd
,
1710 HTMLTxtRange_select
,
1711 HTMLTxtRange_pasteHTML
,
1712 HTMLTxtRange_moveToElementText
,
1713 HTMLTxtRange_setEndPoint
,
1714 HTMLTxtRange_compareEndPoints
,
1715 HTMLTxtRange_findText
,
1716 HTMLTxtRange_moveToPoint
,
1717 HTMLTxtRange_getBookmark
,
1718 HTMLTxtRange_moveToBookmark
,
1719 HTMLTxtRange_queryCommandSupported
,
1720 HTMLTxtRange_queryCommandEnabled
,
1721 HTMLTxtRange_queryCommandState
,
1722 HTMLTxtRange_queryCommandIndeterm
,
1723 HTMLTxtRange_queryCommandText
,
1724 HTMLTxtRange_queryCommandValue
,
1725 HTMLTxtRange_execCommand
,
1726 HTMLTxtRange_execCommandShowHelp
1729 #define OLECMDTRG_THIS(iface) DEFINE_THIS(HTMLTxtRange, OleCommandTarget, iface)
1731 static HRESULT WINAPI
RangeCommandTarget_QueryInterface(IOleCommandTarget
*iface
, REFIID riid
, void **ppv
)
1733 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1734 return IHTMLTxtRange_QueryInterface(HTMLTXTRANGE(This
), riid
, ppv
);
1737 static ULONG WINAPI
RangeCommandTarget_AddRef(IOleCommandTarget
*iface
)
1739 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1740 return IHTMLTxtRange_AddRef(HTMLTXTRANGE(This
));
1743 static ULONG WINAPI
RangeCommandTarget_Release(IOleCommandTarget
*iface
)
1745 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1746 return IHTMLTxtRange_Release(HTMLTXTRANGE(This
));
1749 static HRESULT WINAPI
RangeCommandTarget_QueryStatus(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1750 ULONG cCmds
, OLECMD prgCmds
[], OLECMDTEXT
*pCmdText
)
1752 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1753 FIXME("(%p)->(%s %d %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), cCmds
, prgCmds
, pCmdText
);
1757 static HRESULT
exec_indent(HTMLTxtRange
*This
, VARIANT
*in
, VARIANT
*out
)
1759 nsIDOMDocumentFragment
*fragment
;
1760 nsIDOMElement
*blockquote_elem
, *p_elem
;
1761 nsIDOMDocument
*nsdoc
;
1765 static const PRUnichar blockquoteW
[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1766 static const PRUnichar pW
[] = {'P',0};
1768 TRACE("(%p)->(%p %p)\n", This
, in
, out
);
1770 nsIWebNavigation_GetDocument(This
->doc
->nscontainer
->navigation
, &nsdoc
);
1772 nsAString_Init(&tag_str
, blockquoteW
);
1773 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &blockquote_elem
);
1774 nsAString_Finish(&tag_str
);
1776 nsAString_Init(&tag_str
, pW
);
1777 nsIDOMDocument_CreateElement(nsdoc
, &tag_str
, &p_elem
);
1778 nsAString_Finish(&tag_str
);
1780 nsIDOMDocument_Release(nsdoc
);
1782 nsIDOMRange_ExtractContents(This
->nsrange
, &fragment
);
1783 nsIDOMElement_AppendChild(p_elem
, (nsIDOMNode
*)fragment
, &tmp
);
1784 nsIDOMDocumentFragment_Release(fragment
);
1785 nsIDOMNode_Release(tmp
);
1787 nsIDOMElement_AppendChild(blockquote_elem
, (nsIDOMNode
*)p_elem
, &tmp
);
1788 nsIDOMElement_Release(p_elem
);
1789 nsIDOMNode_Release(tmp
);
1791 nsIDOMRange_InsertNode(This
->nsrange
, (nsIDOMNode
*)blockquote_elem
);
1792 nsIDOMElement_Release(blockquote_elem
);
1797 static HRESULT WINAPI
RangeCommandTarget_Exec(IOleCommandTarget
*iface
, const GUID
*pguidCmdGroup
,
1798 DWORD nCmdID
, DWORD nCmdexecopt
, VARIANT
*pvaIn
, VARIANT
*pvaOut
)
1800 HTMLTxtRange
*This
= OLECMDTRG_THIS(iface
);
1802 TRACE("(%p)->(%s %d %x %p %p)\n", This
, debugstr_guid(pguidCmdGroup
), nCmdID
,
1803 nCmdexecopt
, pvaIn
, pvaOut
);
1805 if(pguidCmdGroup
&& IsEqualGUID(&CGID_MSHTML
, pguidCmdGroup
)) {
1808 return exec_indent(This
, pvaIn
, pvaOut
);
1810 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID
);
1813 FIXME("Unsupported cmd %d of group %s\n", nCmdID
, debugstr_guid(pguidCmdGroup
));
1819 #undef OLECMDTRG_THIS
1821 static const IOleCommandTargetVtbl OleCommandTargetVtbl
= {
1822 RangeCommandTarget_QueryInterface
,
1823 RangeCommandTarget_AddRef
,
1824 RangeCommandTarget_Release
,
1825 RangeCommandTarget_QueryStatus
,
1826 RangeCommandTarget_Exec
1829 IHTMLTxtRange
*HTMLTxtRange_Create(HTMLDocument
*doc
, nsIDOMRange
*nsrange
)
1831 HTMLTxtRange
*ret
= heap_alloc(sizeof(HTMLTxtRange
));
1833 ret
->lpHTMLTxtRangeVtbl
= &HTMLTxtRangeVtbl
;
1834 ret
->lpOleCommandTargetVtbl
= &OleCommandTargetVtbl
;
1838 nsIDOMRange_AddRef(nsrange
);
1839 ret
->nsrange
= nsrange
;
1842 list_add_head(&doc
->range_list
, &ret
->entry
);
1844 return HTMLTXTRANGE(ret
);
1847 void detach_ranges(HTMLDocument
*This
)
1851 LIST_FOR_EACH_ENTRY(iter
, &This
->range_list
, HTMLTxtRange
, entry
) {