mshtml: Reimplement IHTMTxtRange on top of nsIDOMRange.

This commit is contained in:
Jacek Caban 2007-05-10 00:32:48 +02:00 committed by Alexandre Julliard
parent a543e60dc9
commit 573d612de4
3 changed files with 45 additions and 21 deletions

View File

@ -351,7 +351,7 @@ void set_document_bscallback(HTMLDocument*,BSCallback*);
IHlink *Hlink_Create(void);
IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
IHTMLTxtRange *HTMLTxtRange_Create(nsISelection*);
IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
IHTMLStyleSheet *HTMLStyleSheet_Create(void);

View File

@ -139,10 +139,24 @@ static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DI
static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
{
HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
nsIDOMRange *nsrange = NULL;
TRACE("(%p)->(%p)\n", This, range);
*range = (IDispatch*)HTMLTxtRange_Create(This->nsselection);
if(This->nsselection) {
PRInt32 nsrange_cnt = 0;
nsresult nsres;
nsISelection_GetRangeCount(This->nsselection, &nsrange_cnt);
if(nsrange_cnt != 1)
FIXME("range_cnt = %d\n", nsrange_cnt);
nsres = nsISelection_GetRangeAt(This->nsselection, 0, &nsrange);
if(NS_FAILED(nsres))
ERR("GetRangeAt failed: %08x\n", nsres);
}
*range = (IDispatch*)HTMLTxtRange_Create(nsrange);
return S_OK;
}

View File

@ -41,7 +41,7 @@ typedef struct {
LONG ref;
nsISelection *nsselection;
nsIDOMRange *nsrange;
} HTMLTxtRange;
#define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
@ -92,8 +92,8 @@ static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
TRACE("(%p) ref=%d\n", This, ref);
if(!ref) {
if(This->nsselection)
nsISelection_Release(This->nsselection);
if(This->nsrange)
nsISelection_Release(This->nsrange);
mshtml_free(This);
}
@ -152,25 +152,35 @@ static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
{
HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
PRUnichar *nstext = NULL;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
if(!This->nsselection) {
*p = NULL;
if(This->nsrange) {
nsAString text_str;
nsresult nsres;
nsAString_Init(&text_str, NULL);
nsres = nsIDOMRange_ToString(This->nsrange, &text_str);
if(NS_SUCCEEDED(nsres)) {
const PRUnichar *nstext;
nsAString_GetData(&text_str, &nstext, NULL);
*p = SysAllocString(nstext);
}else {
ERR("ToString failed: %08x\n", nsres);
}
nsAString_Finish(&text_str);
}
if(!*p) {
static const WCHAR empty[] = {0};
*p = SysAllocString(empty);
return S_OK;
}
nsres = nsISelection_ToString(This->nsselection, &nstext);
if(NS_FAILED(nsres) || !nstext) {
ERR("toString failed: %08x\n", nsres);
return E_FAIL;
}
*p = SysAllocString(nstext);
nsfree(nstext);
return S_OK;
}
@ -422,16 +432,16 @@ static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
HTMLTxtRange_execCommandShowHelp
};
IHTMLTxtRange *HTMLTxtRange_Create(nsISelection *nsselection)
IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange *nsrange)
{
HTMLTxtRange *ret = mshtml_alloc(sizeof(HTMLTxtRange));
ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl;
ret->ref = 1;
if(nsselection)
nsISelection_AddRef(nsselection);
ret->nsselection = nsselection;
if(nsrange)
nsIDOMRange_AddRef(nsrange);
ret->nsrange = nsrange;
return HTMLTXTRANGE(ret);
}