mshtml: Set selection to default on IHTMLSelectionObject::createRange if there is no range selected.

This commit is contained in:
Jacek Caban 2007-10-18 14:54:42 +02:00 committed by Alexandre Julliard
parent 7e92283678
commit 52b78f055e
2 changed files with 63 additions and 1 deletions

View File

@ -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))

View File

@ -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)