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 nsIDOMHTMLDocument *nshtmldoc;
329 nsIDOMHTMLElement *nselem;
330 nsIDOMDocument *nsdoc;
332 nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
333 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
334 nsIDOMDocument_Release(nsdoc);
335 nsIDOMHTMLDocument_GetBody(nshtmldoc, &nselem);
336 nsIDOMHTMLDocument_Release(nshtmldoc);
338 nsIDOMElement_GetLastChild(nselem, &tmp);
340 return (nsIDOMNode*)nselem;
344 nsIDOMNode_GetLastChild(ret, &tmp);
347 nsIDOMElement_Release(nselem);
352 nsres = nsIDOMNode_GetLastChild(iter, &ret);
353 if(NS_SUCCEEDED(nsres) && ret)
356 nsIDOMNode_AddRef(iter);
359 nsres = nsIDOMNode_GetPreviousSibling(iter, &ret);
360 if(NS_SUCCEEDED(nsres) && ret) {
361 nsIDOMNode_Release(iter);
365 nsres = nsIDOMNode_GetParentNode(iter, &tmp);
366 nsIDOMNode_Release(iter);
368 }while(NS_SUCCEEDED(nsres) && iter);
373 static nsIDOMNode *get_child_node(nsIDOMNode *node, PRUint32 off)
375 nsIDOMNodeList *node_list;
376 nsIDOMNode *ret = NULL;
378 nsIDOMNode_GetChildNodes(node, &node_list);
379 nsIDOMNodeList_Item(node_list, off, &ret);
380 nsIDOMNodeList_Release(node_list);
385 static void get_cur_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
394 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
399 nsIDOMRange_GetStartContainer(This->nsrange, &node);
400 nsIDOMRange_GetStartOffset(This->nsrange, &off);
402 nsIDOMRange_GetEndContainer(This->nsrange, &node);
403 nsIDOMRange_GetEndOffset(This->nsrange, &off);
406 pos->type = get_node_type(node);
407 if(pos->type == ELEMENT_NODE) {
409 pos->node = get_child_node(node, off);
412 pos->node = off ? get_child_node(node, off-1) : prev_node(This, node);
416 pos->type = get_node_type(pos->node);
417 nsIDOMNode_Release(node);
425 pos->node = prev_node(This, node);
427 nsIDOMNode_Release(node);
430 if(pos->type == TEXT_NODE)
434 static void set_range_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
439 if(pos->type == TEXT_NODE)
440 nsres = nsIDOMRange_SetStart(This->nsrange, pos->node, pos->off);
442 nsres = nsIDOMRange_SetStartBefore(This->nsrange, pos->node);
444 if(pos->type == TEXT_NODE && pos->p[pos->off+1])
445 nsres = nsIDOMRange_SetEnd(This->nsrange, pos->node, pos->off+1);
447 nsres = nsIDOMRange_SetEndAfter(This->nsrange, pos->node);
451 ERR("failed: %p %08x\n", pos->node, nsres);
454 static inline void dompos_release(dompos_t *pos)
457 nsIDOMNode_Release(pos->node);
460 nsAString_Finish(&pos->str);
463 static inline void dompos_addref(dompos_t *pos)
466 nsIDOMNode_AddRef(pos->node);
468 if(pos->type == TEXT_NODE)
472 static inline BOOL dompos_cmp(const dompos_t *pos1, const dompos_t *pos2)
474 return pos1->node == pos2->node && pos1->off == pos2->off;
477 static void range_to_string(HTMLTxtRange *This, wstrbuf_t *buf)
479 nsIDOMNode *iter, *tmp;
480 dompos_t start_pos, end_pos;
483 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
491 get_cur_pos(This, FALSE, &end_pos);
492 get_cur_pos(This, TRUE, &start_pos);
494 if(start_pos.type == TEXT_NODE) {
495 if(start_pos.node == end_pos.node) {
496 wstrbuf_append_nodetxt(buf, start_pos.p+start_pos.off, end_pos.off-start_pos.off+1);
497 iter = start_pos.node;
498 nsIDOMNode_AddRef(iter);
500 wstrbuf_append_nodetxt(buf, start_pos.p+start_pos.off, strlenW(start_pos.p+start_pos.off));
501 iter = next_node(start_pos.node);
504 iter = start_pos.node;
505 nsIDOMNode_AddRef(iter);
508 while(iter != end_pos.node) {
509 wstrbuf_append_node(buf, iter);
510 tmp = next_node(iter);
511 nsIDOMNode_Release(iter);
515 nsIDOMNode_AddRef(end_pos.node);
517 if(start_pos.node != end_pos.node) {
518 if(end_pos.type == TEXT_NODE)
519 wstrbuf_append_nodetxt(buf, end_pos.p, end_pos.off+1);
521 wstrbuf_append_node(buf, end_pos.node);
524 nsIDOMNode_Release(iter);
525 dompos_release(&start_pos);
526 dompos_release(&end_pos);
531 for(p = buf->buf+buf->len-1; p >= buf->buf && isspaceW(*p); p--);
533 p = strchrW(p, '\r');
539 static WCHAR get_pos_char(const dompos_t *pos)
543 return pos->p[pos->off];
545 if(is_space_elem(pos->node))
552 static void end_space(const dompos_t *pos, dompos_t *new_pos)
557 dompos_addref(new_pos);
559 if(pos->type != TEXT_NODE)
562 p = new_pos->p+new_pos->off;
564 if(!*p || !isspace(*p))
567 while(p[1] && isspace(p[1]))
570 new_pos->off = p - new_pos->p;
573 static WCHAR next_char(const dompos_t *pos, dompos_t *new_pos)
575 nsIDOMNode *iter, *tmp;
576 dompos_t last_space, tmp_pos;
580 if(pos->type == TEXT_NODE && pos->off != -1 && pos->p[pos->off]) {
584 while(isspaceW(*++p));
588 if(*p && isspaceW(*p)) {
590 while(p[1] && isspaceW(p[1]))
596 new_pos->off = p - pos->p;
597 dompos_addref(new_pos);
599 return cspace ? cspace : *p;
602 last_space.off = p - pos->p;
603 dompos_addref(&last_space);
607 iter = next_node(pos->node);
610 switch(get_node_type(iter)) {
613 tmp_pos.type = TEXT_NODE;
615 dompos_addref(&tmp_pos);
620 dompos_release(&tmp_pos);
622 }else if(isspaceW(*p)) {
624 dompos_release(&last_space);
628 while(p[1] && isspaceW(p[1]))
631 tmp_pos.off = p-tmp_pos.p;
634 last_space = tmp_pos;
639 nsIDOMNode_Release(iter);
642 *new_pos = last_space;
643 dompos_release(&tmp_pos);
644 nsIDOMNode_Release(iter);
652 nsIDOMNode_Release(iter);
656 if(is_elem_tag(iter, brW)) {
658 dompos_release(&last_space);
661 nsIDOMNode_AddRef(iter);
662 last_space.node = iter;
663 last_space.type = ELEMENT_NODE;
666 }else if(is_elem_tag(iter, hrW)) {
668 *new_pos = last_space;
669 nsIDOMNode_Release(iter);
673 new_pos->node = iter;
674 new_pos->type = ELEMENT_NODE;
682 iter = next_node(iter);
683 nsIDOMNode_Release(tmp);
687 *new_pos = last_space;
690 dompos_addref(new_pos);
696 static WCHAR prev_char(HTMLTxtRange *This, const dompos_t *pos, dompos_t *new_pos)
698 nsIDOMNode *iter, *tmp;
700 BOOL skip_space = FALSE;
702 if(pos->type == TEXT_NODE && isspaceW(pos->p[pos->off]))
705 if(pos->type == TEXT_NODE && pos->off) {
706 p = pos->p+pos->off-1;
709 while(p >= pos->p && isspace(*p))
715 new_pos->off = p-pos->p;
716 dompos_addref(new_pos);
717 return new_pos->p[new_pos->off];
721 iter = prev_node(This, pos->node);
724 switch(get_node_type(iter)) {
729 tmp_pos.type = TEXT_NODE;
731 dompos_addref(&tmp_pos);
733 p = tmp_pos.p + strlenW(tmp_pos.p)-1;
736 while(p >= tmp_pos.p && isspaceW(*p))
741 dompos_release(&tmp_pos);
745 tmp_pos.off = p-tmp_pos.p;
747 nsIDOMNode_Release(iter);
752 if(is_elem_tag(iter, brW)) {
757 }else if(!is_elem_tag(iter, hrW)) {
761 new_pos->node = iter;
762 new_pos->type = ELEMENT_NODE;
769 iter = prev_node(This, iter);
770 nsIDOMNode_Release(tmp);
774 dompos_addref(new_pos);
778 static long move_next_chars(long cnt, const dompos_t *pos, BOOL col, const dompos_t *bound_pos,
779 BOOL *bounded, dompos_t *new_pos)
792 end_space(pos, new_pos);
796 c = next_char(pos, &iter);
801 c = next_char(&tmp, &iter);
802 dompos_release(&tmp);
807 if(bound_pos && dompos_cmp(&tmp, bound_pos)) {
817 static long move_prev_chars(HTMLTxtRange *This, long cnt, const dompos_t *pos, BOOL end,
818 const dompos_t *bound_pos, BOOL *bounded, dompos_t *new_pos)
822 BOOL prev_eq = FALSE;
828 c = prev_char(This, pos, &iter);
832 while(c && ret < cnt) {
834 c = prev_char(This, &tmp, &iter);
835 dompos_release(&tmp);
849 prev_eq = bound_pos && dompos_cmp(&iter, bound_pos);
856 static long find_prev_space(HTMLTxtRange *This, const dompos_t *pos, BOOL first_space, dompos_t *ret)
861 c = prev_char(This, pos, &iter);
862 if(!c || (first_space && isspaceW(c))) {
869 c = prev_char(This, &tmp, &iter);
870 if(!c || isspaceW(c)) {
871 dompos_release(&iter);
874 dompos_release(&tmp);
881 static int find_word_end(const dompos_t *pos, dompos_t *ret)
886 c = get_pos_char(pos);
893 c = next_char(pos, &iter);
904 while(c && !isspaceW(c)) {
906 c = next_char(&tmp, &iter);
908 dompos_release(&iter);
912 dompos_release(&tmp);
920 static long move_next_words(long cnt, const dompos_t *pos, dompos_t *new_pos)
926 c = get_pos_char(pos);
928 end_space(pos, &iter);
931 c = next_char(pos, &iter);
936 while(c && ret < cnt) {
938 c = next_char(&tmp, &iter);
939 dompos_release(&tmp);
948 static long move_prev_words(HTMLTxtRange *This, long cnt, const dompos_t *pos, dompos_t *new_pos)
954 dompos_addref(&iter);
957 if(!find_prev_space(This, &iter, FALSE, &tmp))
960 dompos_release(&iter);
969 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
971 static HRESULT WINAPI HTMLTxtRange_QueryInterface(IHTMLTxtRange *iface, REFIID riid, void **ppv)
973 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
977 if(IsEqualGUID(&IID_IUnknown, riid)) {
978 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
979 *ppv = HTMLTXTRANGE(This);
980 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
981 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
982 *ppv = HTMLTXTRANGE(This);
983 }else if(IsEqualGUID(&IID_IHTMLTxtRange, riid)) {
984 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This, ppv);
985 *ppv = HTMLTXTRANGE(This);
986 }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
987 TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
988 *ppv = CMDTARGET(This);
992 IUnknown_AddRef((IUnknown*)*ppv);
996 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
997 return E_NOINTERFACE;
1000 static ULONG WINAPI HTMLTxtRange_AddRef(IHTMLTxtRange *iface)
1002 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1003 LONG ref = InterlockedIncrement(&This->ref);
1005 TRACE("(%p) ref=%d\n", This, ref);
1010 static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
1012 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1013 LONG ref = InterlockedDecrement(&This->ref);
1015 TRACE("(%p) ref=%d\n", This, ref);
1019 nsISelection_Release(This->nsrange);
1021 list_remove(&This->entry);
1028 static HRESULT WINAPI HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange *iface, UINT *pctinfo)
1030 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1031 FIXME("(%p)->(%p)\n", This, pctinfo);
1035 static HRESULT WINAPI HTMLTxtRange_GetTypeInfo(IHTMLTxtRange *iface, UINT iTInfo,
1036 LCID lcid, ITypeInfo **ppTInfo)
1038 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1039 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1043 static HRESULT WINAPI HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange *iface, REFIID riid,
1044 LPOLESTR *rgszNames, UINT cNames,
1045 LCID lcid, DISPID *rgDispId)
1047 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1048 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1053 static HRESULT WINAPI HTMLTxtRange_Invoke(IHTMLTxtRange *iface, DISPID dispIdMember,
1054 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
1055 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
1057 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1058 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1059 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1063 static HRESULT WINAPI HTMLTxtRange_get_htmlText(IHTMLTxtRange *iface, BSTR *p)
1065 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1067 TRACE("(%p)->(%p)\n", This, p);
1072 nsIDOMDocumentFragment *fragment;
1075 nsres = nsIDOMRange_CloneContents(This->nsrange, &fragment);
1076 if(NS_SUCCEEDED(nsres)) {
1077 const PRUnichar *nstext;
1080 nsAString_Init(&nsstr, NULL);
1081 nsnode_to_nsstring((nsIDOMNode*)fragment, &nsstr);
1082 nsIDOMDocumentFragment_Release(fragment);
1084 nsAString_GetData(&nsstr, &nstext);
1085 *p = SysAllocString(nstext);
1087 nsAString_Finish(&nsstr);
1092 const WCHAR emptyW[] = {0};
1093 *p = SysAllocString(emptyW);
1096 TRACE("return %s\n", debugstr_w(*p));
1100 static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
1102 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1103 nsIDOMDocument *nsdoc;
1104 nsIDOMText *text_node;
1108 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1111 return MSHTML_E_NODOC;
1113 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
1114 if(NS_FAILED(nsres)) {
1115 ERR("GetDocument failed: %08x\n", nsres);
1119 nsAString_Init(&text_str, v);
1120 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &text_str, &text_node);
1121 nsIDOMDocument_Release(nsdoc);
1122 nsAString_Finish(&text_str);
1123 if(NS_FAILED(nsres)) {
1124 ERR("CreateTextNode failed: %08x\n", nsres);
1127 nsres = nsIDOMRange_DeleteContents(This->nsrange);
1128 if(NS_FAILED(nsres))
1129 ERR("DeleteContents failed: %08x\n", nsres);
1131 nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)text_node);
1132 if(NS_FAILED(nsres))
1133 ERR("InsertNode failed: %08x\n", nsres);
1135 nsres = nsIDOMRange_SetEndAfter(This->nsrange, (nsIDOMNode*)text_node);
1136 if(NS_FAILED(nsres))
1137 ERR("SetEndAfter failed: %08x\n", nsres);
1139 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This), VARIANT_FALSE);
1142 static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
1144 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1147 TRACE("(%p)->(%p)\n", This, p);
1154 range_to_string(This, &buf);
1156 *p = SysAllocString(buf.buf);
1157 wstrbuf_finish(&buf);
1159 TRACE("ret %s\n", debugstr_w(*p));
1163 static HRESULT WINAPI HTMLTxtRange_parentElement(IHTMLTxtRange *iface, IHTMLElement **parent)
1165 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1166 nsIDOMNode *nsnode, *tmp;
1169 TRACE("(%p)->(%p)\n", This, parent);
1171 nsIDOMRange_GetCommonAncestorContainer(This->nsrange, &nsnode);
1172 while(nsnode && get_node_type(nsnode) != ELEMENT_NODE) {
1173 nsIDOMNode_GetParentNode(nsnode, &tmp);
1174 nsIDOMNode_Release(nsnode);
1183 node = get_node(This->doc, nsnode, TRUE);
1184 nsIDOMNode_Release(nsnode);
1186 return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)parent);
1189 static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange **Duplicate)
1191 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1192 nsIDOMRange *nsrange = NULL;
1194 TRACE("(%p)->(%p)\n", This, Duplicate);
1196 nsIDOMRange_CloneRange(This->nsrange, &nsrange);
1197 *Duplicate = HTMLTxtRange_Create(This->doc, nsrange);
1198 nsIDOMRange_Release(nsrange);
1203 static HRESULT WINAPI HTMLTxtRange_inRange(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
1204 VARIANT_BOOL *InRange)
1206 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1207 HTMLTxtRange *src_range;
1211 TRACE("(%p)->(%p %p)\n", This, Range, InRange);
1213 *InRange = VARIANT_FALSE;
1215 src_range = get_range_object(This->doc, Range);
1219 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
1220 src_range->nsrange, &nsret);
1221 if(NS_SUCCEEDED(nsres) && nsret <= 0) {
1222 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
1223 src_range->nsrange, &nsret);
1224 if(NS_SUCCEEDED(nsres) && nsret >= 0)
1225 *InRange = VARIANT_TRUE;
1228 if(NS_FAILED(nsres))
1229 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1234 static HRESULT WINAPI HTMLTxtRange_isEqual(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
1235 VARIANT_BOOL *IsEqual)
1237 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1238 HTMLTxtRange *src_range;
1242 TRACE("(%p)->(%p %p)\n", This, Range, IsEqual);
1244 *IsEqual = VARIANT_FALSE;
1246 src_range = get_range_object(This->doc, Range);
1250 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
1251 src_range->nsrange, &nsret);
1252 if(NS_SUCCEEDED(nsres) && !nsret) {
1253 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
1254 src_range->nsrange, &nsret);
1255 if(NS_SUCCEEDED(nsres) && !nsret)
1256 *IsEqual = VARIANT_TRUE;
1259 if(NS_FAILED(nsres))
1260 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1265 static HRESULT WINAPI HTMLTxtRange_scrollIntoView(IHTMLTxtRange *iface, VARIANT_BOOL fStart)
1267 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1268 FIXME("(%p)->(%x)\n", This, fStart);
1272 static HRESULT WINAPI HTMLTxtRange_collapse(IHTMLTxtRange *iface, VARIANT_BOOL Start)
1274 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1276 TRACE("(%p)->(%x)\n", This, Start);
1278 nsIDOMRange_Collapse(This->nsrange, Start != VARIANT_FALSE);
1282 static HRESULT WINAPI HTMLTxtRange_expand(IHTMLTxtRange *iface, BSTR Unit, VARIANT_BOOL *Success)
1284 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1287 TRACE("(%p)->(%s %p)\n", This, debugstr_w(Unit), Success);
1289 unit = string_to_unit(Unit);
1290 if(unit == RU_UNKNOWN)
1291 return E_INVALIDARG;
1293 *Success = VARIANT_FALSE;
1297 dompos_t end_pos, start_pos, new_start_pos, new_end_pos;
1300 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1302 get_cur_pos(This, TRUE, &start_pos);
1303 get_cur_pos(This, FALSE, &end_pos);
1305 if(find_word_end(&end_pos, &new_end_pos) || collapsed) {
1306 set_range_pos(This, FALSE, &new_end_pos);
1307 *Success = VARIANT_TRUE;
1310 if(start_pos.type && (get_pos_char(&end_pos) || !dompos_cmp(&new_end_pos, &end_pos))) {
1311 if(find_prev_space(This, &start_pos, TRUE, &new_start_pos)) {
1312 set_range_pos(This, TRUE, &new_start_pos);
1313 *Success = VARIANT_TRUE;
1315 dompos_release(&new_start_pos);
1318 dompos_release(&new_end_pos);
1319 dompos_release(&end_pos);
1320 dompos_release(&start_pos);
1326 nsIDOMDocument *nsdoc;
1327 nsIDOMHTMLDocument *nshtmldoc;
1328 nsIDOMHTMLElement *nsbody = NULL;
1331 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
1332 if(NS_FAILED(nsres) || !nsdoc) {
1333 ERR("GetDocument failed: %08x\n", nsres);
1337 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
1338 nsIDOMDocument_Release(nsdoc);
1340 nsres = nsIDOMHTMLDocument_GetBody(nshtmldoc, &nsbody);
1341 nsIDOMHTMLDocument_Release(nshtmldoc);
1342 if(NS_FAILED(nsres) || !nsbody) {
1343 ERR("Could not get body: %08x\n", nsres);
1347 nsres = nsIDOMRange_SelectNodeContents(This->nsrange, (nsIDOMNode*)nsbody);
1348 nsIDOMHTMLElement_Release(nsbody);
1349 if(NS_FAILED(nsres)) {
1350 ERR("Collapse failed: %08x\n", nsres);
1354 *Success = VARIANT_TRUE;
1359 FIXME("Unimplemented unit %s\n", debugstr_w(Unit));
1365 static HRESULT WINAPI HTMLTxtRange_move(IHTMLTxtRange *iface, BSTR Unit,
1366 long Count, long *ActualCount)
1368 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1371 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1373 unit = string_to_unit(Unit);
1374 if(unit == RU_UNKNOWN)
1375 return E_INVALIDARG;
1379 return IHTMLTxtRange_collapse(HTMLTXTRANGE(This), TRUE);
1384 dompos_t cur_pos, new_pos;
1386 get_cur_pos(This, TRUE, &cur_pos);
1389 *ActualCount = move_next_chars(Count, &cur_pos, TRUE, NULL, NULL, &new_pos);
1390 set_range_pos(This, FALSE, &new_pos);
1391 dompos_release(&new_pos);
1393 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), FALSE);
1395 *ActualCount = -move_prev_chars(This, -Count, &cur_pos, FALSE, NULL, NULL, &new_pos);
1396 set_range_pos(This, TRUE, &new_pos);
1397 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), TRUE);
1398 dompos_release(&new_pos);
1401 dompos_release(&cur_pos);
1406 dompos_t cur_pos, new_pos;
1408 get_cur_pos(This, TRUE, &cur_pos);
1411 *ActualCount = move_next_words(Count, &cur_pos, &new_pos);
1412 set_range_pos(This, FALSE, &new_pos);
1413 dompos_release(&new_pos);
1414 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), FALSE);
1416 *ActualCount = -move_prev_words(This, -Count, &cur_pos, &new_pos);
1417 set_range_pos(This, TRUE, &new_pos);
1418 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), TRUE);
1419 dompos_release(&new_pos);
1422 dompos_release(&cur_pos);
1427 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1430 TRACE("ret %ld\n", *ActualCount);
1434 static HRESULT WINAPI HTMLTxtRange_moveStart(IHTMLTxtRange *iface, BSTR Unit,
1435 long Count, long *ActualCount)
1437 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1440 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1442 unit = string_to_unit(Unit);
1443 if(unit == RU_UNKNOWN)
1444 return E_INVALIDARG;
1453 dompos_t start_pos, end_pos, new_pos;
1456 get_cur_pos(This, TRUE, &start_pos);
1457 get_cur_pos(This, FALSE, &end_pos);
1458 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1463 *ActualCount = move_next_chars(Count, &start_pos, collapsed, &end_pos, &bounded, &new_pos);
1464 set_range_pos(This, !bounded, &new_pos);
1466 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), FALSE);
1468 *ActualCount = -move_prev_chars(This, -Count, &start_pos, FALSE, NULL, NULL, &new_pos);
1469 set_range_pos(This, TRUE, &new_pos);
1472 dompos_release(&start_pos);
1473 dompos_release(&end_pos);
1474 dompos_release(&new_pos);
1479 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1485 static HRESULT WINAPI HTMLTxtRange_moveEnd(IHTMLTxtRange *iface, BSTR Unit,
1486 long Count, long *ActualCount)
1488 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1491 TRACE("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1493 unit = string_to_unit(Unit);
1494 if(unit == RU_UNKNOWN)
1495 return E_INVALIDARG;
1504 dompos_t start_pos, end_pos, new_pos;
1507 get_cur_pos(This, TRUE, &start_pos);
1508 get_cur_pos(This, FALSE, &end_pos);
1509 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
1512 *ActualCount = move_next_chars(Count, &end_pos, collapsed, NULL, NULL, &new_pos);
1513 set_range_pos(This, FALSE, &new_pos);
1517 *ActualCount = -move_prev_chars(This, -Count, &end_pos, TRUE, &start_pos, &bounded, &new_pos);
1518 set_range_pos(This, bounded, &new_pos);
1520 IHTMLTxtRange_collapse(HTMLTXTRANGE(This), TRUE);
1523 dompos_release(&start_pos);
1524 dompos_release(&end_pos);
1525 dompos_release(&new_pos);
1530 FIXME("unimplemented unit %s\n", debugstr_w(Unit));
1536 static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface)
1538 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1540 TRACE("(%p)\n", This);
1542 if(This->doc->nscontainer) {
1543 nsIDOMWindow *dom_window = NULL;
1544 nsISelection *nsselection;
1546 nsIWebBrowser_GetContentDOMWindow(This->doc->nscontainer->webbrowser, &dom_window);
1547 nsIDOMWindow_GetSelection(dom_window, &nsselection);
1548 nsIDOMWindow_Release(dom_window);
1550 nsISelection_RemoveAllRanges(nsselection);
1551 nsISelection_AddRange(nsselection, This->nsrange);
1553 nsISelection_Release(nsselection);
1559 static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html)
1561 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1562 FIXME("(%p)->(%s)\n", This, debugstr_w(html));
1566 static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)
1568 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1569 FIXME("(%p)->(%p)\n", This, element);
1573 static HRESULT WINAPI HTMLTxtRange_setEndPoint(IHTMLTxtRange *iface, BSTR how,
1574 IHTMLTxtRange *SourceRange)
1576 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1577 FIXME("(%p)->(%s %p)\n", This, debugstr_w(how), SourceRange);
1581 static HRESULT WINAPI HTMLTxtRange_compareEndPoints(IHTMLTxtRange *iface, BSTR how,
1582 IHTMLTxtRange *SourceRange, long *ret)
1584 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1585 HTMLTxtRange *src_range;
1590 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(how), SourceRange, ret);
1592 nscmpt = string_to_nscmptype(how);
1594 return E_INVALIDARG;
1596 src_range = get_range_object(This->doc, SourceRange);
1600 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, nscmpt, src_range->nsrange, &nsret);
1601 if(NS_FAILED(nsres))
1602 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1608 static HRESULT WINAPI HTMLTxtRange_findText(IHTMLTxtRange *iface, BSTR String,
1609 long count, long Flags, VARIANT_BOOL *Success)
1611 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1612 FIXME("(%p)->(%s %ld %08lx %p)\n", This, debugstr_w(String), count, Flags, Success);
1616 static HRESULT WINAPI HTMLTxtRange_moveToPoint(IHTMLTxtRange *iface, long x, long y)
1618 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1619 FIXME("(%p)->(%ld %ld)\n", This, x, y);
1623 static HRESULT WINAPI HTMLTxtRange_getBookmark(IHTMLTxtRange *iface, BSTR *Bookmark)
1625 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1626 FIXME("(%p)->(%p)\n", This, Bookmark);
1630 static HRESULT WINAPI HTMLTxtRange_moveToBookmark(IHTMLTxtRange *iface, BSTR Bookmark,
1631 VARIANT_BOOL *Success)
1633 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1634 FIXME("(%p)->(%s %p)\n", This, debugstr_w(Bookmark), Success);
1638 static HRESULT WINAPI HTMLTxtRange_queryCommandSupported(IHTMLTxtRange *iface, BSTR cmdID,
1639 VARIANT_BOOL *pfRet)
1641 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1642 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1646 static HRESULT WINAPI HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange *iface, BSTR cmdID,
1647 VARIANT_BOOL *pfRet)
1649 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1650 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1654 static HRESULT WINAPI HTMLTxtRange_queryCommandState(IHTMLTxtRange *iface, BSTR cmdID,
1655 VARIANT_BOOL *pfRet)
1657 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1658 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1662 static HRESULT WINAPI HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange *iface, BSTR cmdID,
1663 VARIANT_BOOL *pfRet)
1665 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1666 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1670 static HRESULT WINAPI HTMLTxtRange_queryCommandText(IHTMLTxtRange *iface, BSTR cmdID,
1673 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1674 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdText);
1678 static HRESULT WINAPI HTMLTxtRange_queryCommandValue(IHTMLTxtRange *iface, BSTR cmdID,
1681 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1682 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdValue);
1686 static HRESULT WINAPI HTMLTxtRange_execCommand(IHTMLTxtRange *iface, BSTR cmdID,
1687 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1689 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1690 FIXME("(%p)->(%s %x v %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1694 static HRESULT WINAPI HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange *iface, BSTR cmdID,
1695 VARIANT_BOOL *pfRet)
1697 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1698 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1702 #undef HTMLTXTRANGE_THIS
1704 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
1705 HTMLTxtRange_QueryInterface,
1706 HTMLTxtRange_AddRef,
1707 HTMLTxtRange_Release,
1708 HTMLTxtRange_GetTypeInfoCount,
1709 HTMLTxtRange_GetTypeInfo,
1710 HTMLTxtRange_GetIDsOfNames,
1711 HTMLTxtRange_Invoke,
1712 HTMLTxtRange_get_htmlText,
1713 HTMLTxtRange_put_text,
1714 HTMLTxtRange_get_text,
1715 HTMLTxtRange_parentElement,
1716 HTMLTxtRange_duplicate,
1717 HTMLTxtRange_inRange,
1718 HTMLTxtRange_isEqual,
1719 HTMLTxtRange_scrollIntoView,
1720 HTMLTxtRange_collapse,
1721 HTMLTxtRange_expand,
1723 HTMLTxtRange_moveStart,
1724 HTMLTxtRange_moveEnd,
1725 HTMLTxtRange_select,
1726 HTMLTxtRange_pasteHTML,
1727 HTMLTxtRange_moveToElementText,
1728 HTMLTxtRange_setEndPoint,
1729 HTMLTxtRange_compareEndPoints,
1730 HTMLTxtRange_findText,
1731 HTMLTxtRange_moveToPoint,
1732 HTMLTxtRange_getBookmark,
1733 HTMLTxtRange_moveToBookmark,
1734 HTMLTxtRange_queryCommandSupported,
1735 HTMLTxtRange_queryCommandEnabled,
1736 HTMLTxtRange_queryCommandState,
1737 HTMLTxtRange_queryCommandIndeterm,
1738 HTMLTxtRange_queryCommandText,
1739 HTMLTxtRange_queryCommandValue,
1740 HTMLTxtRange_execCommand,
1741 HTMLTxtRange_execCommandShowHelp
1744 #define OLECMDTRG_THIS(iface) DEFINE_THIS(HTMLTxtRange, OleCommandTarget, iface)
1746 static HRESULT WINAPI RangeCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
1748 HTMLTxtRange *This = OLECMDTRG_THIS(iface);
1749 return IHTMLTxtRange_QueryInterface(HTMLTXTRANGE(This), riid, ppv);
1752 static ULONG WINAPI RangeCommandTarget_AddRef(IOleCommandTarget *iface)
1754 HTMLTxtRange *This = OLECMDTRG_THIS(iface);
1755 return IHTMLTxtRange_AddRef(HTMLTXTRANGE(This));
1758 static ULONG WINAPI RangeCommandTarget_Release(IOleCommandTarget *iface)
1760 HTMLTxtRange *This = OLECMDTRG_THIS(iface);
1761 return IHTMLTxtRange_Release(HTMLTXTRANGE(This));
1764 static HRESULT WINAPI RangeCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
1765 ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
1767 HTMLTxtRange *This = OLECMDTRG_THIS(iface);
1768 FIXME("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
1772 static HRESULT exec_indent(HTMLTxtRange *This, VARIANT *in, VARIANT *out)
1774 nsIDOMDocumentFragment *fragment;
1775 nsIDOMElement *blockquote_elem, *p_elem;
1776 nsIDOMDocument *nsdoc;
1780 static const PRUnichar blockquoteW[] = {'B','L','O','C','K','Q','U','O','T','E',0};
1781 static const PRUnichar pW[] = {'P',0};
1783 TRACE("(%p)->(%p %p)\n", This, in, out);
1785 nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
1787 nsAString_Init(&tag_str, blockquoteW);
1788 nsIDOMDocument_CreateElement(nsdoc, &tag_str, &blockquote_elem);
1789 nsAString_Finish(&tag_str);
1791 nsAString_Init(&tag_str, pW);
1792 nsIDOMDocument_CreateElement(nsdoc, &tag_str, &p_elem);
1793 nsAString_Finish(&tag_str);
1795 nsIDOMDocument_Release(nsdoc);
1797 nsIDOMRange_ExtractContents(This->nsrange, &fragment);
1798 nsIDOMElement_AppendChild(p_elem, (nsIDOMNode*)fragment, &tmp);
1799 nsIDOMDocumentFragment_Release(fragment);
1800 nsIDOMNode_Release(tmp);
1802 nsIDOMElement_AppendChild(blockquote_elem, (nsIDOMNode*)p_elem, &tmp);
1803 nsIDOMElement_Release(p_elem);
1804 nsIDOMNode_Release(tmp);
1806 nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)blockquote_elem);
1807 nsIDOMElement_Release(blockquote_elem);
1812 static HRESULT WINAPI RangeCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
1813 DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
1815 HTMLTxtRange *This = OLECMDTRG_THIS(iface);
1817 TRACE("(%p)->(%s %d %x %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
1818 nCmdexecopt, pvaIn, pvaOut);
1820 if(pguidCmdGroup && IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
1823 return exec_indent(This, pvaIn, pvaOut);
1825 FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID);
1828 FIXME("Unsupported cmd %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
1834 #undef OLECMDTRG_THIS
1836 static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
1837 RangeCommandTarget_QueryInterface,
1838 RangeCommandTarget_AddRef,
1839 RangeCommandTarget_Release,
1840 RangeCommandTarget_QueryStatus,
1841 RangeCommandTarget_Exec
1844 IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument *doc, nsIDOMRange *nsrange)
1846 HTMLTxtRange *ret = heap_alloc(sizeof(HTMLTxtRange));
1848 ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl;
1849 ret->lpOleCommandTargetVtbl = &OleCommandTargetVtbl;
1853 nsIDOMRange_AddRef(nsrange);
1854 ret->nsrange = nsrange;
1857 list_add_head(&doc->range_list, &ret->entry);
1859 return HTMLTXTRANGE(ret);
1862 void detach_ranges(HTMLDocument *This)
1866 LIST_FOR_EACH_ENTRY(iter, &This->range_list, HTMLTxtRange, entry) {