Commit 573d612d authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Reimplement IHTMTxtRange on top of nsIDOMRange.

parent a543e60d
...@@ -351,7 +351,7 @@ void set_document_bscallback(HTMLDocument*,BSCallback*); ...@@ -351,7 +351,7 @@ void set_document_bscallback(HTMLDocument*,BSCallback*);
IHlink *Hlink_Create(void); IHlink *Hlink_Create(void);
IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*); IHTMLSelectionObject *HTMLSelectionObject_Create(nsISelection*);
IHTMLTxtRange *HTMLTxtRange_Create(nsISelection*); IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*); IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
IHTMLStyleSheet *HTMLStyleSheet_Create(void); IHTMLStyleSheet *HTMLStyleSheet_Create(void);
......
...@@ -139,10 +139,24 @@ static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DI ...@@ -139,10 +139,24 @@ static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DI
static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range) static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range)
{ {
HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface); HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface);
nsIDOMRange *nsrange = NULL;
TRACE("(%p)->(%p)\n", This, range); 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; return S_OK;
} }
......
...@@ -41,7 +41,7 @@ typedef struct { ...@@ -41,7 +41,7 @@ typedef struct {
LONG ref; LONG ref;
nsISelection *nsselection; nsIDOMRange *nsrange;
} HTMLTxtRange; } HTMLTxtRange;
#define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl) #define HTMLTXTRANGE(x) ((IHTMLTxtRange*) &(x)->lpHTMLTxtRangeVtbl)
...@@ -92,8 +92,8 @@ static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface) ...@@ -92,8 +92,8 @@ static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
TRACE("(%p) ref=%d\n", This, ref); TRACE("(%p) ref=%d\n", This, ref);
if(!ref) { if(!ref) {
if(This->nsselection) if(This->nsrange)
nsISelection_Release(This->nsselection); nsISelection_Release(This->nsrange);
mshtml_free(This); mshtml_free(This);
} }
...@@ -152,25 +152,35 @@ static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v) ...@@ -152,25 +152,35 @@ static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p) static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
{ {
HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface); HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface);
PRUnichar *nstext = NULL;
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
if(!This->nsselection) { *p = NULL;
static const WCHAR empty[] = {0};
*p = SysAllocString(empty); if(This->nsrange) {
return S_OK; 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);
} }
nsres = nsISelection_ToString(This->nsselection, &nstext); if(!*p) {
if(NS_FAILED(nsres) || !nstext) { static const WCHAR empty[] = {0};
ERR("toString failed: %08x\n", nsres); *p = SysAllocString(empty);
return E_FAIL;
} }
*p = SysAllocString(nstext);
nsfree(nstext);
return S_OK; return S_OK;
} }
...@@ -422,16 +432,16 @@ static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = { ...@@ -422,16 +432,16 @@ static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
HTMLTxtRange_execCommandShowHelp HTMLTxtRange_execCommandShowHelp
}; };
IHTMLTxtRange *HTMLTxtRange_Create(nsISelection *nsselection) IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange *nsrange)
{ {
HTMLTxtRange *ret = mshtml_alloc(sizeof(HTMLTxtRange)); HTMLTxtRange *ret = mshtml_alloc(sizeof(HTMLTxtRange));
ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl; ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl;
ret->ref = 1; ret->ref = 1;
if(nsselection) if(nsrange)
nsISelection_AddRef(nsselection); nsIDOMRange_AddRef(nsrange);
ret->nsselection = nsselection; ret->nsrange = nsrange;
return HTMLTXTRANGE(ret); return HTMLTXTRANGE(ret);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment