Jacek Caban : mshtml: Reimplement IHTMTxtRange on top of nsIDOMRange.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu May 10 07:49:52 CDT 2007
Module: wine
Branch: master
Commit: 573d612de46b665081f7ea01ccf21b1d6243bc69
URL: http://source.winehq.org/git/wine.git/?a=commit;h=573d612de46b665081f7ea01ccf21b1d6243bc69
Author: Jacek Caban <jacek at codeweavers.com>
Date: Thu May 10 00:32:48 2007 +0200
mshtml: Reimplement IHTMTxtRange on top of nsIDOMRange.
---
dlls/mshtml/mshtml_private.h | 2 +-
dlls/mshtml/selection.c | 16 +++++++++++++-
dlls/mshtml/txtrange.c | 48 +++++++++++++++++++++++++----------------
3 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 6d8e154..432df7e 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -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);
diff --git a/dlls/mshtml/selection.c b/dlls/mshtml/selection.c
index f5cc5aa..79683f0 100644
--- a/dlls/mshtml/selection.c
+++ b/dlls/mshtml/selection.c
@@ -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;
}
diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c
index eb83fd0..70fb1f9 100644
--- a/dlls/mshtml/txtrange.c
+++ b/dlls/mshtml/txtrange.c
@@ -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) {
- static const WCHAR empty[] = {0};
- *p = SysAllocString(empty);
- return S_OK;
+ *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);
}
- nsres = nsISelection_ToString(This->nsselection, &nstext);
- if(NS_FAILED(nsres) || !nstext) {
- ERR("toString failed: %08x\n", nsres);
- return E_FAIL;
+ if(!*p) {
+ static const WCHAR empty[] = {0};
+ *p = SysAllocString(empty);
}
- *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);
}
More information about the wine-cvs
mailing list