2 * Copyright 2006 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
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "mshtml_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 static const WCHAR brW[] = {'b','r',0};
42 const IHTMLTxtRangeVtbl *lpHTMLTxtRangeVtbl;
52 #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
76 static HTMLTxtRange *get_range_object(HTMLDocument *doc, IHTMLTxtRange *iface)
80 LIST_FOR_EACH_ENTRY(iter, &doc->range_list, HTMLTxtRange, entry) {
81 if(HTMLTXTRANGE(iter) == iface)
85 ERR("Could not find range in document\n");
89 static range_unit_t string_to_unit(LPCWSTR str)
91 static const WCHAR characterW[] =
92 {'c','h','a','r','a','c','t','e','r',0};
93 static const WCHAR wordW[] =
95 static const WCHAR sentenceW[] =
96 {'s','e','n','t','e','n','c','e',0};
97 static const WCHAR texteditW[] =
98 {'t','e','x','t','e','d','i','t',0};
100 if(!strcmpiW(str, characterW)) return RU_CHAR;
101 if(!strcmpiW(str, wordW)) return RU_WORD;
102 if(!strcmpiW(str, sentenceW)) return RU_SENTENCE;
103 if(!strcmpiW(str, texteditW)) return RU_TEXTEDIT;
108 static int string_to_nscmptype(LPCWSTR str)
110 static const WCHAR seW[] = {'S','t','a','r','t','T','o','E','n','d',0};
111 static const WCHAR ssW[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
112 static const WCHAR esW[] = {'E','n','d','T','o','S','t','a','r','t',0};
113 static const WCHAR eeW[] = {'E','n','d','T','o','E','n','d',0};
115 if(!strcmpiW(str, seW)) return NS_START_TO_END;
116 if(!strcmpiW(str, ssW)) return NS_START_TO_START;
117 if(!strcmpiW(str, esW)) return NS_END_TO_START;
118 if(!strcmpiW(str, eeW)) return NS_END_TO_END;
123 static PRUint16 get_node_type(nsIDOMNode *node)
125 PRUint16 type = 0xfff;
128 nsIDOMNode_GetNodeType(node, &type);
133 static BOOL is_br_node(nsIDOMNode *node)
137 const PRUnichar *tag;
141 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
145 nsAString_Init(&tag_str, NULL);
146 nsIDOMElement_GetTagName(elem, &tag_str);
147 nsIDOMElement_Release(elem);
148 nsAString_GetData(&tag_str, &tag, 0);
150 if(!strcmpiW(tag, brW))
153 nsAString_Finish(&tag_str);
158 static void inline wstrbuf_init(wstrbuf_t *buf)
162 buf->buf = mshtml_alloc(buf->size * sizeof(WCHAR));
166 static void inline wstrbuf_finish(wstrbuf_t *buf)
168 mshtml_free(buf->buf);
171 static void wstrbuf_append_len(wstrbuf_t *buf, LPCWSTR str, int len)
173 if(buf->len+len >= buf->size) {
174 buf->size = 2*buf->len+len;
175 buf->buf = mshtml_realloc(buf->buf, buf->size * sizeof(WCHAR));
178 memcpy(buf->buf+buf->len, str, len*sizeof(WCHAR));
180 buf->buf[buf->len] = 0;
183 static void inline wstrbuf_append(wstrbuf_t *buf, LPCWSTR str)
185 wstrbuf_append_len(buf, str, strlenW(str));
188 static void wstrbuf_append_node(wstrbuf_t *buf, nsIDOMNode *node)
191 switch(get_node_type(node)) {
195 const PRUnichar *data;
197 nsIDOMNode_QueryInterface(node, &IID_nsIDOMText, (void**)&nstext);
199 nsAString_Init(&data_str, NULL);
200 nsIDOMText_GetData(nstext, &data_str);
201 nsAString_GetData(&data_str, &data, NULL);
202 wstrbuf_append(buf, data);
203 nsAString_Finish(&data_str);
205 nsIDOMText_Release(nstext);
210 if(is_br_node(node)) {
211 static const WCHAR endlW[] = {'\r','\n'};
212 wstrbuf_append_len(buf, endlW, 2);
217 static BOOL fill_nodestr(dompos_t *pos)
222 if(pos->type != TEXT_NODE)
225 nsres = nsIDOMNode_QueryInterface(pos->node, &IID_nsIDOMText, (void**)&text);
229 nsAString_Init(&pos->str, NULL);
230 nsIDOMText_GetData(text, &pos->str);
231 nsIDOMText_Release(text);
232 nsAString_GetData(&pos->str, &pos->p, NULL);
237 static nsIDOMNode *next_node(nsIDOMNode *iter)
239 nsIDOMNode *ret, *tmp;
245 nsres = nsIDOMNode_GetFirstChild(iter, &ret);
246 if(NS_SUCCEEDED(nsres) && ret)
249 nsIDOMNode_AddRef(iter);
252 nsres = nsIDOMNode_GetNextSibling(iter, &ret);
253 if(NS_SUCCEEDED(nsres) && ret) {
254 nsIDOMNode_Release(iter);
258 nsres = nsIDOMNode_GetParentNode(iter, &tmp);
259 nsIDOMNode_Release(iter);
261 }while(NS_SUCCEEDED(nsres) && iter);
266 static nsIDOMNode *prev_node(HTMLTxtRange *This, nsIDOMNode *iter)
268 nsIDOMNode *ret, *tmp;
272 nsIDOMHTMLDocument *nshtmldoc;
273 nsIDOMHTMLElement *nselem;
274 nsIDOMDocument *nsdoc;
276 nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
277 nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc);
278 nsIDOMDocument_Release(nsdoc);
279 nsIDOMHTMLDocument_GetBody(nshtmldoc, &nselem);
280 nsIDOMHTMLDocument_Release(nshtmldoc);
282 nsIDOMElement_GetLastChild(nselem, &tmp);
284 return (nsIDOMNode*)nselem;
288 nsIDOMNode_GetLastChild(ret, &tmp);
291 nsIDOMElement_Release(nselem);
296 nsres = nsIDOMNode_GetLastChild(iter, &ret);
297 if(NS_SUCCEEDED(nsres) && ret)
300 nsIDOMNode_AddRef(iter);
303 nsres = nsIDOMNode_GetPreviousSibling(iter, &ret);
304 if(NS_SUCCEEDED(nsres) && ret) {
305 nsIDOMNode_Release(iter);
309 nsres = nsIDOMNode_GetParentNode(iter, &tmp);
310 nsIDOMNode_Release(iter);
312 }while(NS_SUCCEEDED(nsres) && iter);
317 static nsIDOMNode *get_child_node(nsIDOMNode *node, PRUint32 off)
319 nsIDOMNodeList *node_list;
320 nsIDOMNode *ret = NULL;
322 nsIDOMNode_GetChildNodes(node, &node_list);
323 nsIDOMNodeList_Item(node_list, off, &ret);
324 nsIDOMNodeList_Release(node_list);
329 static void get_cur_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
338 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
343 nsIDOMRange_GetStartContainer(This->nsrange, &node);
344 nsIDOMRange_GetStartOffset(This->nsrange, &off);
346 nsIDOMRange_GetEndContainer(This->nsrange, &node);
347 nsIDOMRange_GetEndOffset(This->nsrange, &off);
350 pos->type = get_node_type(node);
351 if(pos->type == ELEMENT_NODE) {
353 pos->node = get_child_node(node, off);
356 pos->node = off ? get_child_node(node, off-1) : prev_node(This, node);
360 pos->type = get_node_type(pos->node);
361 nsIDOMNode_Release(node);
369 pos->node = prev_node(This, node);
371 nsIDOMNode_Release(node);
374 if(pos->type == TEXT_NODE)
378 static void set_range_pos(HTMLTxtRange *This, BOOL start, dompos_t *pos)
383 if(pos->type == TEXT_NODE)
384 nsres = nsIDOMRange_SetStart(This->nsrange, pos->node, pos->off);
386 nsres = nsIDOMRange_SetStartBefore(This->nsrange, pos->node);
388 if(pos->type == TEXT_NODE)
389 nsres = nsIDOMRange_SetEnd(This->nsrange, pos->node, pos->off+1);
391 nsres = nsIDOMRange_SetEndAfter(This->nsrange, pos->node);
395 ERR("failed: %p %08x\n", pos->node, nsres);
398 static void inline dompos_release(dompos_t *pos)
401 nsIDOMNode_Release(pos->node);
404 nsAString_Finish(&pos->str);
407 static void inline dompos_addref(dompos_t *pos)
410 nsIDOMNode_AddRef(pos->node);
412 if(pos->type == TEXT_NODE)
416 static void range_to_string(HTMLTxtRange *This, wstrbuf_t *buf)
418 nsIDOMNode *iter, *tmp;
419 dompos_t start_pos, end_pos;
422 nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
430 get_cur_pos(This, FALSE, &end_pos);
431 get_cur_pos(This, TRUE, &start_pos);
433 if(start_pos.type == TEXT_NODE) {
434 if(start_pos.node == end_pos.node) {
435 wstrbuf_append_len(buf, start_pos.p+start_pos.off, end_pos.off-start_pos.off+1);
436 iter = start_pos.node;
437 nsIDOMNode_AddRef(iter);
439 wstrbuf_append(buf, start_pos.p+start_pos.off);
440 iter = next_node(start_pos.node);
443 iter = start_pos.node;
444 nsIDOMNode_AddRef(iter);
447 while(iter != end_pos.node) {
448 wstrbuf_append_node(buf, iter);
449 tmp = next_node(iter);
450 nsIDOMNode_Release(iter);
454 nsIDOMNode_AddRef(end_pos.node);
456 if(start_pos.node != end_pos.node && !is_br_node(end_pos.node))
457 wstrbuf_append_len(buf, end_pos.p, end_pos.off+1);
459 nsIDOMNode_Release(iter);
460 dompos_release(&start_pos);
461 dompos_release(&end_pos);
464 static WCHAR get_pos_char(const dompos_t *pos)
468 return pos->p[pos->off];
470 if(is_br_node(pos->node))
477 static WCHAR next_char(const dompos_t *pos, dompos_t *new_pos)
479 nsIDOMNode *iter, *tmp;
481 if(pos->type == TEXT_NODE && pos->off != -1 && pos->p[pos->off+1]) {
484 dompos_addref(new_pos);
485 return new_pos->p[new_pos->off];
488 iter = next_node(pos->node);
493 switch(get_node_type(iter)) {
495 new_pos->node = iter;
496 new_pos->type = TEXT_NODE;
498 fill_nodestr(new_pos);
502 if(!is_br_node(iter))
505 new_pos->node = iter;
506 new_pos->type = ELEMENT_NODE;
513 iter = next_node(iter);
514 nsIDOMNode_Release(tmp);
523 static WCHAR prev_char(HTMLTxtRange *This, const dompos_t *pos, dompos_t *new_pos)
525 nsIDOMNode *iter, *tmp;
527 if(pos->type == TEXT_NODE && pos->off > 0) {
530 dompos_addref(new_pos);
531 return new_pos->p[new_pos->off];
534 iter = prev_node(This, pos->node);
539 switch(get_node_type(iter)) {
541 new_pos->node = iter;
542 new_pos->type = TEXT_NODE;
543 fill_nodestr(new_pos);
544 new_pos->off = strlenW(new_pos->p)-1;
545 return new_pos->p[new_pos->off];
548 if(!is_br_node(iter))
551 new_pos->node = iter;
552 new_pos->type = ELEMENT_NODE;
559 iter = prev_node(This, iter);
560 nsIDOMNode_Release(tmp);
567 dompos_addref(new_pos);
571 static BOOL find_next_space(const dompos_t *pos, BOOL first_space, dompos_t *ret)
577 c = get_pos_char(pos);
578 if(c && isspaceW(c)) {
585 c = next_char(pos, &iter);
592 while(!isspaceW(c)) {
594 c = next_char(&tmp, &iter);
599 dompos_release(&tmp);
606 static long find_prev_space(HTMLTxtRange *This, const dompos_t *pos, BOOL first_space, dompos_t *ret)
611 c = prev_char(This, pos, &iter);
612 if(!c || (first_space && isspaceW(c))) {
620 c = prev_char(This, &tmp, &iter);
621 if(!c || isspaceW(c)) {
622 dompos_release(&iter);
625 dompos_release(&tmp);
632 #define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
634 static HRESULT WINAPI HTMLTxtRange_QueryInterface(IHTMLTxtRange *iface, REFIID riid, void **ppv)
636 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
640 if(IsEqualGUID(&IID_IUnknown, riid)) {
641 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
642 *ppv = HTMLTXTRANGE(This);
643 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
644 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
645 *ppv = HTMLTXTRANGE(This);
646 }else if(IsEqualGUID(&IID_IHTMLTxtRange, riid)) {
647 TRACE("(%p)->(IID_IHTMLTxtRange %p)\n", This, ppv);
648 *ppv = HTMLTXTRANGE(This);
652 IUnknown_AddRef((IUnknown*)*ppv);
656 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
657 return E_NOINTERFACE;
660 static ULONG WINAPI HTMLTxtRange_AddRef(IHTMLTxtRange *iface)
662 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
663 LONG ref = InterlockedIncrement(&This->ref);
665 TRACE("(%p) ref=%d\n", This, ref);
670 static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
672 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
673 LONG ref = InterlockedDecrement(&This->ref);
675 TRACE("(%p) ref=%d\n", This, ref);
679 nsISelection_Release(This->nsrange);
681 list_remove(&This->entry);
688 static HRESULT WINAPI HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange *iface, UINT *pctinfo)
690 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
691 FIXME("(%p)->(%p)\n", This, pctinfo);
695 static HRESULT WINAPI HTMLTxtRange_GetTypeInfo(IHTMLTxtRange *iface, UINT iTInfo,
696 LCID lcid, ITypeInfo **ppTInfo)
698 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
699 FIXME("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
703 static HRESULT WINAPI HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange *iface, REFIID riid,
704 LPOLESTR *rgszNames, UINT cNames,
705 LCID lcid, DISPID *rgDispId)
707 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
708 FIXME("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
713 static HRESULT WINAPI HTMLTxtRange_Invoke(IHTMLTxtRange *iface, DISPID dispIdMember,
714 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
715 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
717 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
718 FIXME("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
719 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
723 static HRESULT WINAPI HTMLTxtRange_get_htmlText(IHTMLTxtRange *iface, BSTR *p)
725 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
727 TRACE("(%p)->(%p)\n", This, p);
732 nsIDOMDocumentFragment *fragment;
735 nsres = nsIDOMRange_CloneContents(This->nsrange, &fragment);
736 if(NS_SUCCEEDED(nsres)) {
737 const PRUnichar *nstext;
740 nsAString_Init(&nsstr, NULL);
741 nsnode_to_nsstring((nsIDOMNode*)fragment, &nsstr);
742 nsIDOMDocumentFragment_Release(fragment);
744 nsAString_GetData(&nsstr, &nstext, NULL);
745 *p = SysAllocString(nstext);
747 nsAString_Finish(&nsstr);
752 const WCHAR emptyW[] = {0};
753 *p = SysAllocString(emptyW);
756 TRACE("return %s\n", debugstr_w(*p));
760 static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
762 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
763 nsIDOMDocument *nsdoc;
764 nsIDOMText *text_node;
768 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
771 return MSHTML_E_NODOC;
773 nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc);
774 if(NS_FAILED(nsres)) {
775 ERR("GetDocument failed: %08x\n", nsres);
779 nsAString_Init(&text_str, v);
780 nsres = nsIDOMDocument_CreateTextNode(nsdoc, &text_str, &text_node);
781 nsAString_Finish(&text_str);
782 if(NS_FAILED(nsres)) {
783 ERR("CreateTextNode failed: %08x\n", nsres);
786 nsres = nsIDOMRange_DeleteContents(This->nsrange);
788 ERR("DeleteContents failed: %08x\n", nsres);
790 nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)text_node);
792 ERR("InsertNode failed: %08x\n", nsres);
797 static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
799 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
802 TRACE("(%p)->(%p)\n", This, p);
805 range_to_string(This, &buf);
807 *p = SysAllocString(buf.buf);
810 wstrbuf_finish(&buf);
812 TRACE("ret %s\n", debugstr_w(*p));
816 static HRESULT WINAPI HTMLTxtRange_parentElement(IHTMLTxtRange *iface, IHTMLElement **parent)
818 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
819 nsIDOMNode *nsnode, *tmp;
823 TRACE("(%p)->(%p)\n", This, parent);
825 nsIDOMRange_GetCommonAncestorContainer(This->nsrange, &nsnode);
826 while(nsnode && get_node_type(nsnode) != ELEMENT_NODE) {
827 nsIDOMNode_GetParentNode(nsnode, &tmp);
828 nsIDOMNode_Release(nsnode);
837 node = get_node(This->doc, nsnode);
838 nsIDOMNode_Release(nsnode);
840 hres = IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)parent);
842 IHTMLDOMNode_Release(HTMLDOMNODE(node));
846 static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange **Duplicate)
848 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
849 nsIDOMRange *nsrange = NULL;
851 TRACE("(%p)->(%p)\n", This, Duplicate);
853 nsIDOMRange_CloneRange(This->nsrange, &nsrange);
854 *Duplicate = HTMLTxtRange_Create(This->doc, nsrange);
855 nsIDOMRange_Release(nsrange);
860 static HRESULT WINAPI HTMLTxtRange_inRange(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
861 VARIANT_BOOL *InRange)
863 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
864 HTMLTxtRange *src_range;
868 TRACE("(%p)->(%p %p)\n", This, Range, InRange);
870 *InRange = VARIANT_FALSE;
872 src_range = get_range_object(This->doc, Range);
876 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
877 src_range->nsrange, &nsret);
878 if(NS_SUCCEEDED(nsres) && nsret <= 0) {
879 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
880 src_range->nsrange, &nsret);
881 if(NS_SUCCEEDED(nsres) && nsret >= 0)
882 *InRange = VARIANT_TRUE;
886 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
891 static HRESULT WINAPI HTMLTxtRange_isEqual(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
892 VARIANT_BOOL *IsEqual)
894 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
895 HTMLTxtRange *src_range;
899 TRACE("(%p)->(%p %p)\n", This, Range, IsEqual);
901 *IsEqual = VARIANT_FALSE;
903 src_range = get_range_object(This->doc, Range);
907 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
908 src_range->nsrange, &nsret);
909 if(NS_SUCCEEDED(nsres) && !nsret) {
910 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
911 src_range->nsrange, &nsret);
912 if(NS_SUCCEEDED(nsres) && !nsret)
913 *IsEqual = VARIANT_TRUE;
917 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
922 static HRESULT WINAPI HTMLTxtRange_scrollIntoView(IHTMLTxtRange *iface, VARIANT_BOOL fStart)
924 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
925 FIXME("(%p)->(%x)\n", This, fStart);
929 static HRESULT WINAPI HTMLTxtRange_collapse(IHTMLTxtRange *iface, VARIANT_BOOL Start)
931 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
933 TRACE("(%p)->(%x)\n", This, Start);
935 nsIDOMRange_Collapse(This->nsrange, Start != VARIANT_FALSE);
939 static HRESULT WINAPI HTMLTxtRange_expand(IHTMLTxtRange *iface, BSTR Unit, VARIANT_BOOL *Success)
941 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
944 TRACE("(%p)->(%s %p)\n", This, debugstr_w(Unit), Success);
946 unit = string_to_unit(Unit);
947 if(unit == RU_UNKNOWN)
952 dompos_t end_pos, start_pos, new_pos;
954 *Success = VARIANT_FALSE;
956 get_cur_pos(This, TRUE, &start_pos);
957 get_cur_pos(This, FALSE, &end_pos);
958 if(find_next_space(&end_pos, TRUE, &new_pos)) {
959 set_range_pos(This, FALSE, &new_pos);
960 *Success = VARIANT_TRUE;
962 dompos_release(&new_pos);
964 if(find_prev_space(This, &start_pos, TRUE, &new_pos)) {
965 set_range_pos(This, TRUE, &new_pos);
966 *Success = VARIANT_TRUE;
969 dompos_release(&new_pos);
970 dompos_release(&end_pos);
975 FIXME("Unimplemented unit %s\n", debugstr_w(Unit));
981 static HRESULT WINAPI HTMLTxtRange_move(IHTMLTxtRange *iface, BSTR Unit,
982 long Count, long *ActualCount)
984 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
985 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
989 static HRESULT WINAPI HTMLTxtRange_moveStart(IHTMLTxtRange *iface, BSTR Unit,
990 long Count, long *ActualCount)
992 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
993 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
997 static HRESULT WINAPI HTMLTxtRange_moveEnd(IHTMLTxtRange *iface, BSTR Unit,
998 long Count, long *ActualCount)
1000 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1001 FIXME("(%p)->(%s %ld %p)\n", This, debugstr_w(Unit), Count, ActualCount);
1005 static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface)
1007 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1009 TRACE("(%p)\n", This);
1011 if(This->doc->nscontainer) {
1012 nsIDOMWindow *dom_window = NULL;
1013 nsISelection *nsselection;
1015 nsIWebBrowser_GetContentDOMWindow(This->doc->nscontainer->webbrowser, &dom_window);
1016 nsIDOMWindow_GetSelection(dom_window, &nsselection);
1017 nsIDOMWindow_Release(dom_window);
1019 nsISelection_RemoveAllRanges(nsselection);
1020 nsISelection_AddRange(nsselection, This->nsrange);
1022 nsISelection_Release(nsselection);
1028 static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html)
1030 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1031 FIXME("(%p)->(%s)\n", This, debugstr_w(html));
1035 static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)
1037 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1038 FIXME("(%p)->(%p)\n", This, element);
1042 static HRESULT WINAPI HTMLTxtRange_setEndPoint(IHTMLTxtRange *iface, BSTR how,
1043 IHTMLTxtRange *SourceRange)
1045 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1046 FIXME("(%p)->(%s %p)\n", This, debugstr_w(how), SourceRange);
1050 static HRESULT WINAPI HTMLTxtRange_compareEndPoints(IHTMLTxtRange *iface, BSTR how,
1051 IHTMLTxtRange *SourceRange, long *ret)
1053 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1054 HTMLTxtRange *src_range;
1059 TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(how), SourceRange, ret);
1061 nscmpt = string_to_nscmptype(how);
1063 return E_INVALIDARG;
1065 src_range = get_range_object(This->doc, SourceRange);
1069 nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, nscmpt, src_range->nsrange, &nsret);
1070 if(NS_FAILED(nsres))
1071 ERR("CompareBoundaryPoints failed: %08x\n", nsres);
1077 static HRESULT WINAPI HTMLTxtRange_findText(IHTMLTxtRange *iface, BSTR String,
1078 long count, long Flags, VARIANT_BOOL *Success)
1080 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1081 FIXME("(%p)->(%s %ld %08lx %p)\n", This, debugstr_w(String), count, Flags, Success);
1085 static HRESULT WINAPI HTMLTxtRange_moveToPoint(IHTMLTxtRange *iface, long x, long y)
1087 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1088 FIXME("(%p)->(%ld %ld)\n", This, x, y);
1092 static HRESULT WINAPI HTMLTxtRange_getBookmark(IHTMLTxtRange *iface, BSTR *Bookmark)
1094 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1095 FIXME("(%p)->(%p)\n", This, Bookmark);
1099 static HRESULT WINAPI HTMLTxtRange_moveToBookmark(IHTMLTxtRange *iface, BSTR Bookmark,
1100 VARIANT_BOOL *Success)
1102 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1103 FIXME("(%p)->(%s %p)\n", This, debugstr_w(Bookmark), Success);
1107 static HRESULT WINAPI HTMLTxtRange_queryCommandSupported(IHTMLTxtRange *iface, BSTR cmdID,
1108 VARIANT_BOOL *pfRet)
1110 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1111 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1115 static HRESULT WINAPI HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange *iface, BSTR cmdID,
1116 VARIANT_BOOL *pfRet)
1118 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1119 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1123 static HRESULT WINAPI HTMLTxtRange_queryCommandState(IHTMLTxtRange *iface, BSTR cmdID,
1124 VARIANT_BOOL *pfRet)
1126 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1127 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1131 static HRESULT WINAPI HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange *iface, BSTR cmdID,
1132 VARIANT_BOOL *pfRet)
1134 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1135 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1139 static HRESULT WINAPI HTMLTxtRange_queryCommandText(IHTMLTxtRange *iface, BSTR cmdID,
1142 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1143 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdText);
1147 static HRESULT WINAPI HTMLTxtRange_queryCommandValue(IHTMLTxtRange *iface, BSTR cmdID,
1150 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1151 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdValue);
1155 static HRESULT WINAPI HTMLTxtRange_execCommand(IHTMLTxtRange *iface, BSTR cmdID,
1156 VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
1158 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1159 FIXME("(%p)->(%s %x v %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
1163 static HRESULT WINAPI HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange *iface, BSTR cmdID,
1164 VARIANT_BOOL *pfRet)
1166 HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
1167 FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
1171 #undef HTMLTXTRANGE_THIS
1173 static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
1174 HTMLTxtRange_QueryInterface,
1175 HTMLTxtRange_AddRef,
1176 HTMLTxtRange_Release,
1177 HTMLTxtRange_GetTypeInfoCount,
1178 HTMLTxtRange_GetTypeInfo,
1179 HTMLTxtRange_GetIDsOfNames,
1180 HTMLTxtRange_Invoke,
1181 HTMLTxtRange_get_htmlText,
1182 HTMLTxtRange_put_text,
1183 HTMLTxtRange_get_text,
1184 HTMLTxtRange_parentElement,
1185 HTMLTxtRange_duplicate,
1186 HTMLTxtRange_inRange,
1187 HTMLTxtRange_isEqual,
1188 HTMLTxtRange_scrollIntoView,
1189 HTMLTxtRange_collapse,
1190 HTMLTxtRange_expand,
1192 HTMLTxtRange_moveStart,
1193 HTMLTxtRange_moveEnd,
1194 HTMLTxtRange_select,
1195 HTMLTxtRange_pasteHTML,
1196 HTMLTxtRange_moveToElementText,
1197 HTMLTxtRange_setEndPoint,
1198 HTMLTxtRange_compareEndPoints,
1199 HTMLTxtRange_findText,
1200 HTMLTxtRange_moveToPoint,
1201 HTMLTxtRange_getBookmark,
1202 HTMLTxtRange_moveToBookmark,
1203 HTMLTxtRange_queryCommandSupported,
1204 HTMLTxtRange_queryCommandEnabled,
1205 HTMLTxtRange_queryCommandState,
1206 HTMLTxtRange_queryCommandIndeterm,
1207 HTMLTxtRange_queryCommandText,
1208 HTMLTxtRange_queryCommandValue,
1209 HTMLTxtRange_execCommand,
1210 HTMLTxtRange_execCommandShowHelp
1213 IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument *doc, nsIDOMRange *nsrange)
1215 HTMLTxtRange *ret = mshtml_alloc(sizeof(HTMLTxtRange));
1217 ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl;
1221 nsIDOMRange_AddRef(nsrange);
1222 ret->nsrange = nsrange;
1225 list_add_head(&doc->range_list, &ret->entry);
1227 return HTMLTXTRANGE(ret);
1230 void detach_ranges(HTMLDocument *This)
1234 LIST_FOR_EACH_ENTRY(iter, &This->range_list, HTMLTxtRange, entry) {