From e567f309bf94b0218010b99f2598caf1cf26bafb Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 12 Nov 2014 16:25:31 +0100 Subject: [PATCH] mshtml: Added IHTMLTxtRange::pasteHTML implementation. --- dlls/mshtml/tests/dom.c | 27 +++++++++++++++++++++++++++ dlls/mshtml/txtrange.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 8c7adc9c267..39c3a7d2a28 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -2148,6 +2148,17 @@ static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRa } } +#define test_range_paste_html(a,b) _test_range_paste_html(__LINE__,a,b) +static void _test_range_paste_html(unsigned line, IHTMLTxtRange *range, const char *html) +{ + BSTR str = a2bstr(html); + HRESULT hres; + + hres = IHTMLTxtRange_pasteHTML(range, str); + ok_(__FILE__,line)(hres == S_OK, "pasteHTML failed: %08x\n", hres); + SysFreeString(str); +} + #define test_range_parent(r,t) _test_range_parent(__LINE__,r,t) static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t type) { @@ -5050,6 +5061,22 @@ static void test_txtrange(IHTMLDocument2 *doc) test_range_text(range, "abc xyz abc 123\r\nit's text"); test_range_parent(range, ET_BODY); + test_range_move(range, wordW, 1, 1); + test_range_moveend(range, characterW, 12, 12); + test_range_text(range, "xyz abc 123"); + + test_range_collapse(range, VARIANT_TRUE); + test_range_paste_html(range, "
paste
"); + test_range_text(range, NULL); + + test_range_moveend(range, characterW, 3, 3); + test_range_text(range, "xyz"); + + hres = IHTMLTxtRange_moveToElementText(range, body); + ok(hres == S_OK, "moveToElementText failed: %08x\n", hres); + + test_range_text(range, "abc \r\npaste\r\nxyz abc 123\r\nit's text"); + IHTMLElement_Release(body); IHTMLTxtRange_Release(range); diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c index 886f596a9de..43c9f1a5f60 100644 --- a/dlls/mshtml/txtrange.c +++ b/dlls/mshtml/txtrange.c @@ -17,6 +17,7 @@ */ #include +#include #define COBJMACROS @@ -1572,8 +1573,33 @@ static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface) static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html) { HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface); - FIXME("(%p)->(%s)\n", This, debugstr_w(html)); - return E_NOTIMPL; + nsIDOMDocumentFragment *doc_frag; + nsAString nsstr; + nsresult nsres; + + TRACE("(%p)->(%s)\n", This, debugstr_w(html)); + + nsres = nsIDOMRange_Collapse(This->nsrange, TRUE); + assert(nsres == NS_OK); + + nsAString_InitDepend(&nsstr, html); + nsres = nsIDOMRange_CreateContextualFragment(This->nsrange, &nsstr, &doc_frag); + nsAString_Finish(&nsstr); + if(NS_FAILED(nsres)) { + ERR("CreateContextualFragment failed: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)doc_frag); + nsIDOMDocumentFragment_Release(doc_frag); + if(NS_FAILED(nsres)) { + ERR("InsertNode failed: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsIDOMRange_Collapse(This->nsrange, FALSE); + assert(nsres == NS_OK); + return S_OK; } static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)