Jacek Caban : mshtml: Store HTMLDocument reference in HTMLTxtRange object.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Aug 17 06:30:44 CDT 2007


Module: wine
Branch: master
Commit: cfaf00fa51d4812ba25a221b78e76f514f58487b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cfaf00fa51d4812ba25a221b78e76f514f58487b

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Aug 17 02:37:01 2007 +0200

mshtml: Store HTMLDocument reference in HTMLTxtRange object.

---

 dlls/mshtml/htmlbody.c       |    2 +-
 dlls/mshtml/htmldoc.c        |    2 ++
 dlls/mshtml/mshtml_private.h |    4 +++-
 dlls/mshtml/selection.c      |    2 +-
 dlls/mshtml/txtrange.c       |   21 +++++++++++++++++++--
 5 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/dlls/mshtml/htmlbody.c b/dlls/mshtml/htmlbody.c
index 40d8983..b6b78f6 100644
--- a/dlls/mshtml/htmlbody.c
+++ b/dlls/mshtml/htmlbody.c
@@ -427,7 +427,7 @@ static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, I
         nsIDOMDocumentRange_Release(nsdocrange);
     }
 
-    *range = HTMLTxtRange_Create(nsrange);
+    *range = HTMLTxtRange_Create(This->element->node->doc, nsrange);
     return S_OK;
 }
 
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index f70b96e..19da49a 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -173,6 +173,7 @@ static ULONG WINAPI HTMLDocument_Release(IHTMLDocument2 *iface)
             IHTMLWindow2_Release(HTMLWINDOW2(This->window));
 
         detach_selection(This);
+        detach_ranges(This);
         release_nodes(This);
 
         ConnectionPointContainer_Destroy(&This->cp_container);
@@ -1130,6 +1131,7 @@ HRESULT HTMLDocument_Create(IUnknown *pUnkOuter, REFIID riid, void** ppvObject)
     ret->window = NULL;
 
     list_init(&ret->selection_list);
+    list_init(&ret->range_list);
 
     hres = IHTMLDocument_QueryInterface(HTMLDOC(ret), riid, ppvObject);
     if(FAILED(hres)) {
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 69472ff..63e2027 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -151,6 +151,7 @@ struct HTMLDocument {
     ConnectionPoint cp_propnotif;
 
     struct list selection_list;
+    struct list range_list;
 
     HTMLDOMNode *nodes;
 };
@@ -404,11 +405,12 @@ void set_document_bscallback(HTMLDocument*,BSCallback*);
 void set_current_mon(HTMLDocument*,IMoniker*);
 
 IHTMLSelectionObject *HTMLSelectionObject_Create(HTMLDocument*,nsISelection*);
-IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange*);
+IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument*,nsIDOMRange*);
 IHTMLStyle *HTMLStyle_Create(nsIDOMCSSStyleDeclaration*);
 IHTMLStyleSheet *HTMLStyleSheet_Create(void);
 
 void detach_selection(HTMLDocument*);
+void detach_ranges(HTMLDocument*);
 
 void HTMLElement_Create(HTMLDOMNode*);
 void HTMLBodyElement_Create(HTMLElement*);
diff --git a/dlls/mshtml/selection.c b/dlls/mshtml/selection.c
index 1ee3b97..4139d3b 100644
--- a/dlls/mshtml/selection.c
+++ b/dlls/mshtml/selection.c
@@ -161,7 +161,7 @@ static HRESULT WINAPI HTMLSelectionObject_createRange(IHTMLSelectionObject *ifac
             ERR("GetRangeAt failed: %08x\n", nsres);
     }
 
-    *range = (IDispatch*)HTMLTxtRange_Create(nsrange);
+    *range = (IDispatch*)HTMLTxtRange_Create(This->doc, nsrange);
     return S_OK;
 }
 
diff --git a/dlls/mshtml/txtrange.c b/dlls/mshtml/txtrange.c
index ae90e81..70791a3 100644
--- a/dlls/mshtml/txtrange.c
+++ b/dlls/mshtml/txtrange.c
@@ -42,6 +42,9 @@ typedef struct {
     LONG ref;
 
     nsIDOMRange *nsrange;
+    HTMLDocument *doc;
+
+    struct list entry;
 } HTMLTxtRange;
 
 #define HTMLTXTRANGE(x)  ((IHTMLTxtRange*)  &(x)->lpHTMLTxtRangeVtbl)
@@ -94,6 +97,8 @@ static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
     if(!ref) {
         if(This->nsrange)
             nsISelection_Release(This->nsrange);
+        if(This->doc)
+            list_remove(&This->entry);
         mshtml_free(This);
     }
 
@@ -229,7 +234,7 @@ static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange
     TRACE("(%p)->(%p)\n", This, Duplicate);
 
     nsIDOMRange_CloneRange(This->nsrange, &nsrange);
-    *Duplicate = HTMLTxtRange_Create(nsrange);
+    *Duplicate = HTMLTxtRange_Create(This->doc, nsrange);
     nsIDOMRange_Release(nsrange);
 
     return S_OK;
@@ -472,7 +477,7 @@ static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
     HTMLTxtRange_execCommandShowHelp
 };
 
-IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange *nsrange)
+IHTMLTxtRange *HTMLTxtRange_Create(HTMLDocument *doc, nsIDOMRange *nsrange)
 {
     HTMLTxtRange *ret = mshtml_alloc(sizeof(HTMLTxtRange));
 
@@ -483,5 +488,17 @@ IHTMLTxtRange *HTMLTxtRange_Create(nsIDOMRange *nsrange)
         nsIDOMRange_AddRef(nsrange);
     ret->nsrange = nsrange;
 
+    ret->doc = doc;
+    list_add_head(&doc->range_list, &ret->entry);
+
     return HTMLTXTRANGE(ret);
 }
+
+void detach_ranges(HTMLDocument *This)
+{
+    HTMLTxtRange *iter;
+
+    LIST_FOR_EACH_ENTRY(iter, &This->range_list, HTMLTxtRange, entry) {
+        iter->doc = NULL;
+    }
+}




More information about the wine-cvs mailing list