From d460c67305d912d40148e11375d3dc3fa03412e5 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 16 Sep 2009 22:11:43 +0200 Subject: [PATCH] mshtml: Moved range_list to HTMLDocumentNode object. --- dlls/mshtml/htmlbody.c | 7 +++++-- dlls/mshtml/htmldoc.c | 4 ++-- dlls/mshtml/mshtml_private.h | 7 +++---- dlls/mshtml/selection.c | 9 +++++++-- dlls/mshtml/txtrange.c | 38 +++++++++++++++++++++--------------- 5 files changed, 39 insertions(+), 26 deletions(-) diff --git a/dlls/mshtml/htmlbody.c b/dlls/mshtml/htmlbody.c index da5d70a2209..280464acb34 100644 --- a/dlls/mshtml/htmlbody.c +++ b/dlls/mshtml/htmlbody.c @@ -602,6 +602,7 @@ static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, I nsIDOMDocumentRange *nsdocrange; nsIDOMRange *nsrange = NULL; nsresult nsres; + HRESULT hres; TRACE("(%p)->(%p)\n", This, range); @@ -628,8 +629,10 @@ static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, I nsIDOMDocumentRange_Release(nsdocrange); - *range = HTMLTxtRange_Create(This->textcont.element.node.doc, nsrange); - return S_OK; + hres = HTMLTxtRange_Create(This->textcont.element.node.doc->doc_node, nsrange, range); + + nsIDOMRange_Release(nsrange); + return hres; } #undef HTMLBODY_THIS diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index b835c99a7b9..5261c978069 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1740,7 +1740,6 @@ static void init_doc(HTMLDocument *doc, const htmldoc_vtbl_t *vtbl) doc->readystate = READYSTATE_UNINITIALIZED; list_init(&doc->bindings); - list_init(&doc->range_list); HTMLDocument_HTMLDocument3_Init(doc); HTMLDocument_HTMLDocument5_Init(doc); @@ -1771,7 +1770,6 @@ static void destroy_htmldoc(HTMLDocument *This) release_event_target(This->event_target); heap_free(This->mime); - detach_ranges(This); release_nodes(This); release_dispex(&This->dispex); @@ -1809,6 +1807,7 @@ static ULONG HTMLDocumentNode_Release(HTMLDocument *base) if(!ref) { detach_selection(This); + detach_ranges(This); destroy_htmldoc(&This->basedoc); heap_free(This); } @@ -1844,6 +1843,7 @@ HRESULT create_doc_from_nsdoc(nsIDOMHTMLDocument *nsdoc, HTMLDocumentObj *doc_ob doc->basedoc.window = window; list_init(&doc->selection_list); + list_init(&doc->range_list); *ret = doc; return S_OK; diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 05fb91f685e..1c744edd303 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -301,8 +301,6 @@ struct HTMLDocument { ConnectionPoint cp_htmldocevents2; ConnectionPoint cp_propnotif; - struct list range_list; - HTMLDOMNode *nodes; }; @@ -327,6 +325,7 @@ struct HTMLDocumentNode { LONG ref; struct list selection_list; + struct list range_list; }; struct HTMLDocumentObj { @@ -638,13 +637,13 @@ void channelbsc_set_channel(nsChannelBSC*,nsChannel*,nsIStreamListener*,nsISuppo IMoniker *get_channelbsc_mon(nsChannelBSC*); HRESULT HTMLSelectionObject_Create(HTMLDocumentNode*,nsISelection*,IHTMLSelectionObject**); -IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument*,nsIDOMRange*); +HRESULT HTMLTxtRange_Create(HTMLDocumentNode*,nsIDOMRange*,IHTMLTxtRange**); IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*); IHTMLStyleSheet *HTMLStyleSheet_Create(nsIDOMStyleSheet*); IHTMLStyleSheetsCollection *HTMLStyleSheetsCollection_Create(nsIDOMStyleSheetList*); void detach_selection(HTMLDocumentNode*); -void detach_ranges(HTMLDocument*); +void detach_ranges(HTMLDocumentNode*); HRESULT get_node_text(HTMLDOMNode*,BSTR*); HTMLDOMNode *HTMLDOMTextNode_Create(HTMLDocument*,nsIDOMNode*); diff --git a/dlls/mshtml/selection.c b/dlls/mshtml/selection.c index 0d1729d02e0..65e3ecb16b0 100644 --- a/dlls/mshtml/selection.c +++ b/dlls/mshtml/selection.c @@ -140,7 +140,9 @@ static HRESULT WINAPI HTMLSelectionObject_Invoke(IHTMLSelectionObject *iface, DI static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *iface, IDispatch **range) { HTMLSelectionObject *This = HTMLSELOBJ_THIS(iface); + IHTMLTxtRange *range_obj = NULL; nsIDOMRange *nsrange = NULL; + HRESULT hres; TRACE("(%p)->(%p)\n", This, range); @@ -178,8 +180,11 @@ static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *ifac ERR("GetRangeAt failed: %08x\n", nsres); } - *range = (IDispatch*)HTMLTxtRange_Create(&This->doc->basedoc, nsrange); - return S_OK; + hres = HTMLTxtRange_Create(This->doc, nsrange, &range_obj); + + nsIDOMRange_Release(nsrange); + *range = (IDispatch*)range_obj; + return hres; } static HRESULT WINAPI HTMLSelectionObject_empty(IHTMLSelectionObject *iface) diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c index e6a6ff2cd2a..9ed6f6380fa 100644 --- a/dlls/mshtml/txtrange.c +++ b/dlls/mshtml/txtrange.c @@ -43,7 +43,7 @@ typedef struct { LONG ref; nsIDOMRange *nsrange; - HTMLDocument *doc; + HTMLDocumentNode *doc; struct list entry; } HTMLTxtRange; @@ -72,7 +72,7 @@ typedef enum { RU_TEXTEDIT } range_unit_t; -static HTMLTxtRange *get_range_object(HTMLDocument *doc, IHTMLTxtRange *iface) +static HTMLTxtRange *get_range_object(HTMLDocumentNode *doc, IHTMLTxtRange *iface) { HTMLTxtRange *iter; @@ -342,7 +342,7 @@ static nsIDOMNode *prev_node(HTMLTxtRange *This, nsIDOMNode *iter) if(!iter) { nsIDOMHTMLElement *nselem; - nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nselem); + nsIDOMHTMLDocument_GetBody(This->doc->basedoc.nsdoc, &nselem); nsIDOMElement_GetLastChild(nselem, &tmp); if(!tmp) return (nsIDOMNode*)nselem; @@ -1139,7 +1139,7 @@ static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v) return MSHTML_E_NODOC; nsAString_Init(&text_str, v); - nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc->nsdoc, &text_str, &text_node); + nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc->basedoc.nsdoc, &text_str, &text_node); nsAString_Finish(&text_str); if(NS_FAILED(nsres)) { ERR("CreateTextNode failed: %08x\n", nsres); @@ -1201,7 +1201,7 @@ static HRESULT WINAPI HTMLTxtRange_parentElement(IHTMLTxtRange *iface, IHTMLElem return S_OK; } - node = get_node(This->doc, nsnode, TRUE); + node = get_node(&This->doc->basedoc, nsnode, TRUE); nsIDOMNode_Release(nsnode); return IHTMLDOMNode_QueryInterface(HTMLDOMNODE(node), &IID_IHTMLElement, (void**)parent); @@ -1211,14 +1211,15 @@ static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange { HTMLTxtRange *This = HTMLTXTRANGE_THIS(iface); nsIDOMRange *nsrange = NULL; + HRESULT hres; TRACE("(%p)->(%p)\n", This, Duplicate); nsIDOMRange_CloneRange(This->nsrange, &nsrange); - *Duplicate = HTMLTxtRange_Create(This->doc, nsrange); + hres = HTMLTxtRange_Create(This->doc, nsrange, Duplicate); nsIDOMRange_Release(nsrange); - return S_OK; + return hres; } static HRESULT WINAPI HTMLTxtRange_inRange(IHTMLTxtRange *iface, IHTMLTxtRange *Range, @@ -1347,7 +1348,7 @@ static HRESULT WINAPI HTMLTxtRange_expand(IHTMLTxtRange *iface, BSTR Unit, VARIA nsIDOMHTMLElement *nsbody = NULL; nsresult nsres; - nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody); + nsres = nsIDOMHTMLDocument_GetBody(This->doc->basedoc.nsdoc, &nsbody); if(NS_FAILED(nsres) || !nsbody) { ERR("Could not get body: %08x\n", nsres); break; @@ -1550,7 +1551,7 @@ static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface) TRACE("(%p)\n", This); - nsres = nsIDOMWindow_GetSelection(This->doc->window->nswindow, &nsselection); + nsres = nsIDOMWindow_GetSelection(This->doc->basedoc.window->nswindow, &nsselection); if(NS_FAILED(nsres)) { ERR("GetSelection failed: %08x\n", nsres); return E_FAIL; @@ -1787,17 +1788,17 @@ static HRESULT exec_indent(HTMLTxtRange *This, VARIANT *in, VARIANT *out) TRACE("(%p)->(%p %p)\n", This, in, out); - if(!This->doc->nsdoc) { + if(!This->doc->basedoc.nsdoc) { WARN("NULL nsdoc\n"); return E_NOTIMPL; } nsAString_Init(&tag_str, blockquoteW); - nsIDOMHTMLDocument_CreateElement(This->doc->nsdoc, &tag_str, &blockquote_elem); + nsIDOMHTMLDocument_CreateElement(This->doc->basedoc.nsdoc, &tag_str, &blockquote_elem); nsAString_Finish(&tag_str); nsAString_Init(&tag_str, pW); - nsIDOMDocument_CreateElement(This->doc->nsdoc, &tag_str, &p_elem); + nsIDOMDocument_CreateElement(This->doc->basedoc.nsdoc, &tag_str, &p_elem); nsAString_Finish(&tag_str); nsIDOMRange_ExtractContents(This->nsrange, &fragment); @@ -1847,9 +1848,13 @@ static const IOleCommandTargetVtbl OleCommandTargetVtbl = { RangeCommandTarget_Exec }; -IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument *doc, nsIDOMRange *nsrange) +HRESULT HTMLTxtRange_Create(HTMLDocumentNode *doc, nsIDOMRange *nsrange, IHTMLTxtRange **p) { - HTMLTxtRange *ret = heap_alloc(sizeof(HTMLTxtRange)); + HTMLTxtRange *ret; + + ret = heap_alloc(sizeof(HTMLTxtRange)); + if(!ret) + return E_OUTOFMEMORY; ret->lpHTMLTxtRangeVtbl = &HTMLTxtRangeVtbl; ret->lpOleCommandTargetVtbl = &OleCommandTargetVtbl; @@ -1862,10 +1867,11 @@ IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument *doc, nsIDOMRange *nsrange) ret->doc = doc; list_add_head(&doc->range_list, &ret->entry); - return HTMLTXTRANGE(ret); + *p = HTMLTXTRANGE(ret); + return S_OK; } -void detach_ranges(HTMLDocument *This) +void detach_ranges(HTMLDocumentNode *This) { HTMLTxtRange *iter;