Module: wine Branch: master Commit: 52b78f055ed2c335de83d8ee8f19a160163db189 URL: http://source.winehq.org/git/wine.git/?a=commit;h=52b78f055ed2c335de83d8ee8f...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Oct 18 14:54:42 2007 +0200
mshtml: Set selection to default on IHTMLSelectionObject::createRange if there is no range selected.
---
dlls/mshtml/selection.c | 30 +++++++++++++++++++++++++++++- dlls/mshtml/tests/dom.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/dlls/mshtml/selection.c b/dlls/mshtml/selection.c index 4139d3b..df2d635 100644 --- a/dlls/mshtml/selection.c +++ b/dlls/mshtml/selection.c @@ -153,8 +153,36 @@ static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *ifac nsresult nsres;
nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt); - if(nsrange_cnt != 1) + if(!nsrange_cnt) { + nsIDOMDocument *nsdoc; + nsIDOMHTMLDocument *nshtmldoc; + nsIDOMHTMLElement *nsbody = NULL; + + TRACE("nsrange_cnt = 0\n"); + + nsres = nsIWebNavigation_GetDocument(This->doc->nscontainer->navigation, &nsdoc); + if(NS_FAILED(nsres) || !nsdoc) { + ERR("GetDocument failed: %08x\n", nsres); + return E_FAIL; + } + + nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMHTMLDocument, (void**)&nshtmldoc); + nsIDOMDocument_Release(nsdoc); + + nsres = nsIDOMHTMLDocument_GetBody(nshtmldoc, &nsbody); + nsIDOMHTMLDocument_Release(nshtmldoc); + if(NS_FAILED(nsres) || !nsbody) { + ERR("Could not get body: %08x\n", nsres); + return E_FAIL; + } + + nsres = nsISelection_Collapse(This->nsselection, (nsIDOMNode*)nsbody, 0); + nsIDOMHTMLElement_Release(nsbody); + if(NS_FAILED(nsres)) + ERR("Collapse failed: %08x\n", nsres); + }else if(nsrange_cnt > 1) { FIXME("range_cnt = %d\n", nsrange_cnt); + }
nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange); if(NS_FAILED(nsres)) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index bf9f499..3933ac8 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -539,6 +539,20 @@ static void _test_range_isequal(unsigned line, IHTMLTxtRange *range1, IHTMLTxtRa } }
+#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) +{ + IHTMLElement *elem; + HRESULT hres; + + hres = IHTMLTxtRange_parentElement(range, &elem); + ok_(__FILE__,line) (hres == S_OK, "parentElement failed: %08x\n", hres); + + _test_elem_type(line, (IUnknown*)elem, type); + + IHTMLElement_Release(elem); +} + static void test_elem_collection(IHTMLElementCollection *col, const elem_type_t *elem_types, long exlen) { long len; @@ -695,6 +709,8 @@ static void test_txtrange(IHTMLDocument2 *doc) IHTMLElement *elem; IHTMLBodyElement *body; IHTMLTxtRange *body_range, *range, *range2; + IHTMLSelectionObject *selection; + IDispatch *disp_range; HRESULT hres;
hres = IHTMLDocument2_get_body(doc, &elem); @@ -841,6 +857,24 @@ static void test_txtrange(IHTMLDocument2 *doc)
IHTMLTxtRange_Release(range); IHTMLTxtRange_Release(body_range); + + hres = IHTMLDocument2_get_selection(doc, &selection); + ok(hres == S_OK, "IHTMLDocument2_get_selection failed: %08x\n", hres); + + hres = IHTMLSelectionObject_createRange(selection, &disp_range); + ok(hres == S_OK, "IHTMLSelectionObject_createRange failed: %08x\n", hres); + IHTMLSelectionObject_Release(selection); + + hres = IDispatch_QueryInterface(disp_range, &IID_IHTMLTxtRange, (void **)&range); + ok(hres == S_OK, "Could not get IID_IHTMLTxtRange interface: 0x%08x\n", hres); + IDispatch_Release(disp_range); + + test_range_text(range, NULL); + test_range_moveend(range, characterW, 3, 3); + test_range_text(range, "wor"); + test_range_parent(range, ET_BODY); + + IHTMLTxtRange_Release(range); }
static void test_compatmode(IHTMLDocument2 *doc)