Jacek Caban : mshtml: Include document element in collection returned by IHTMLDocument2::get_all .

Alexandre Julliard julliard at winehq.org
Thu Oct 4 06:21:10 CDT 2007


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Oct  4 02:13:01 2007 +0200

mshtml: Include document element in collection returned by IHTMLDocument2::get_all.

---

 dlls/mshtml/htmldoc.c        |   37 ++++++++++++++++++++++++-------------
 dlls/mshtml/htmlelem.c       |   21 +++++++++++++++++----
 dlls/mshtml/mshtml_private.h |    2 ++
 3 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index 32307e4..4faeb6e 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -234,25 +234,36 @@ static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch *
 static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p)
 {
     HTMLDocument *This = HTMLDOC_THIS(iface);
-    IHTMLElement *doc;
-    IDispatch *disp;
-    HRESULT hres;
+    nsIDOMDocument *nsdoc = NULL;
+    nsIDOMElement *nselem = NULL;
+    nsresult nsres;
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    hres = IHTMLDocument3_get_documentElement(HTMLDOC3(This), &doc);
-    if(FAILED(hres))
-        return hres;
+    if(!This->nscontainer) {
+        *p = NULL;
+        return S_OK;
+    }
 
-    hres = IHTMLElement_get_all(doc, &disp);
-    IHTMLElement_Release(doc);
-    if(FAILED(hres))
-        return hres;
+    nsres = nsIWebNavigation_GetDocument(This->nscontainer->navigation, &nsdoc);
+    if(NS_FAILED(nsres))
+        ERR("GetDocument failed: %08x\n", nsres);
 
-    hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)p);
-    IDispatch_Release(disp);
+    if(nsdoc) {
+        nsres = nsIDOMHTMLDocument_GetDocumentElement(nsdoc, &nselem);
+        if(NS_FAILED(nsres))
+            ERR("GetDocumentElement failed: %08x\n", nsres);
+    }
 
-    return hres;
+    if(!nselem) {
+        *p = NULL;
+        return S_OK;
+    }
+
+    *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem));
+
+    nsIDOMElement_Release(nselem);
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p)
diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index dd152f2..4d921c2 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -1087,7 +1087,7 @@ static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **
     return S_OK;
 }
 
-static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *buf)
+static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
 {
     nsIDOMNodeList *nsnode_list;
     nsIDOMNode *iter;
@@ -1095,7 +1095,7 @@ static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *b
     PRUint16 node_type;
     nsresult nsres;
 
-    nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
+    nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
     if(NS_FAILED(nsres)) {
         ERR("GetChildNodes failed: %08x\n", nsres);
         return;
@@ -1117,7 +1117,7 @@ static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *b
             HTMLDOMNode *node = get_node(doc, iter);
 
             elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
-            create_all_list(doc, HTMLELEM_NODE_THIS(node), buf);
+            create_all_list(doc, node, buf);
         }
     }
 }
@@ -1131,7 +1131,7 @@ static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
 
     buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**));
 
-    create_all_list(This->node.doc, This, &buf);
+    create_all_list(This->node.doc, &This->node, &buf);
     elem_vector_normalize(&buf);
 
     *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
@@ -1595,6 +1595,19 @@ static const IHTMLElementCollectionVtbl HTMLElementCollectionVtbl = {
     HTMLElementCollection_tags
 };
 
+IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
+{
+    elem_vector buf = {NULL, 0, 8};
+
+    buf.buf = mshtml_alloc(buf.size*sizeof(HTMLElement**));
+
+    elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
+    create_all_list(node->doc, node, &buf);
+    elem_vector_normalize(&buf);
+
+    return HTMLElementCollection_Create((IUnknown*)HTMLDOMNODE(node), buf.buf, buf.len);
+}
+
 static IHTMLElementCollection *HTMLElementCollection_Create(IUnknown *ref_unk,
             HTMLElement **elems, DWORD len)
 {
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index b0ac454..f73d1a0 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -430,6 +430,8 @@ void HTMLElement_destructor(HTMLDOMNode*);
 HTMLDOMNode *get_node(HTMLDocument*,nsIDOMNode*);
 void release_nodes(HTMLDocument*);
 
+IHTMLElementCollection *create_all_collection(HTMLDOMNode*);
+
 BOOL install_wine_gecko(void);
 
 /* commands */




More information about the wine-cvs mailing list