Jacek Caban : mshtml: Use create_all_collection in IHTMLElement:: get_all implementation.

Alexandre Julliard julliard at winehq.org
Wed Oct 1 14:09:26 CDT 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Sep 30 17:45:08 2008 +0200

mshtml: Use create_all_collection in IHTMLElement::get_all implementation.

---

 dlls/mshtml/htmldoc.c        |    2 +-
 dlls/mshtml/htmlelem.c       |   78 +-----------------------------------------
 dlls/mshtml/htmlelemcol.c    |    5 ++-
 dlls/mshtml/mshtml_private.h |    2 +-
 4 files changed, 6 insertions(+), 81 deletions(-)

diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index dd989ff..ebb6538 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -289,7 +289,7 @@ static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCo
         return S_OK;
     }
 
-    *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE));
+    *p = create_all_collection(get_node(This, (nsIDOMNode*)nselem, TRUE), TRUE);
 
     nsIDOMElement_Release(nselem);
     return S_OK;
diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index fb3cccd..d3c0633 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -35,43 +35,6 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
-typedef struct {
-    HTMLElement **buf;
-    DWORD len;
-    DWORD size;
-} elem_vector;
-
-static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
-{
-    if(buf->len == buf->size) {
-        buf->size <<= 1;
-        buf->buf = heap_realloc(buf->buf, buf->size*sizeof(HTMLElement**));
-    }
-
-    buf->buf[buf->len++] = elem;
-}
-
-static void elem_vector_normalize(elem_vector *buf)
-{
-    if(!buf->len) {
-        heap_free(buf->buf);
-        buf->buf = NULL;
-    }else if(buf->size > buf->len) {
-        buf->buf = heap_realloc(buf->buf, buf->len*sizeof(HTMLElement**));
-    }
-
-    buf->size = buf->len;
-}
-
-static BOOL is_elem_node(nsIDOMNode *node)
-{
-    PRUint16 type=0;
-
-    nsIDOMNode_GetNodeType(node, &type);
-
-    return type == ELEMENT_NODE || type == COMMENT_NODE;
-}
-
 #define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
 
 #define HTMLELEM_NODE_THIS(iface) DEFINE_THIS2(HTMLElement, node, iface)
@@ -1230,52 +1193,13 @@ static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **
     return S_OK;
 }
 
-static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector *buf)
-{
-    nsIDOMNodeList *nsnode_list;
-    nsIDOMNode *iter;
-    PRUint32 list_len = 0, i;
-    nsresult nsres;
-
-    nsres = nsIDOMNode_GetChildNodes(elem->nsnode, &nsnode_list);
-    if(NS_FAILED(nsres)) {
-        ERR("GetChildNodes failed: %08x\n", nsres);
-        return;
-    }
-
-    nsIDOMNodeList_GetLength(nsnode_list, &list_len);
-    if(!list_len)
-        return;
-
-    for(i=0; i<list_len; i++) {
-        nsres = nsIDOMNodeList_Item(nsnode_list, i, &iter);
-        if(NS_FAILED(nsres)) {
-            ERR("Item failed: %08x\n", nsres);
-            continue;
-        }
-
-        if(is_elem_node(iter)) {
-            HTMLDOMNode *node = get_node(doc, iter, TRUE);
-
-            elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
-            create_all_list(doc, node, buf);
-        }
-    }
-}
-
 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
 {
     HTMLElement *This = HTMLELEM_THIS(iface);
-    elem_vector buf = {NULL, 0, 8};
 
     TRACE("(%p)->(%p)\n", This, p);
 
-    buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
-
-    create_all_list(This->node.doc, &This->node, &buf);
-    elem_vector_normalize(&buf);
-
-    *p = (IDispatch*)HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len);
+    *p = (IDispatch*)create_all_collection(&This->node, FALSE);
     return S_OK;
 }
 
diff --git a/dlls/mshtml/htmlelemcol.c b/dlls/mshtml/htmlelemcol.c
index 9a2c710..768dbee 100644
--- a/dlls/mshtml/htmlelemcol.c
+++ b/dlls/mshtml/htmlelemcol.c
@@ -463,13 +463,14 @@ static void create_all_list(HTMLDocument *doc, HTMLDOMNode *elem, elem_vector_t
     }
 }
 
-IHTMLElementCollection *create_all_collection(HTMLDOMNode *node)
+IHTMLElementCollection *create_all_collection(HTMLDOMNode *node, BOOL include_root)
 {
     elem_vector_t buf = {NULL, 0, 8};
 
     buf.buf = heap_alloc(buf.size*sizeof(HTMLElement**));
 
-    elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
+    if(include_root)
+        elem_vector_add(&buf, HTMLELEM_NODE_THIS(node));
     create_all_list(node->doc, node, &buf);
     elem_vector_normalize(&buf);
 
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 80dc5ff..b14ad02 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -585,7 +585,7 @@ IDispatch *script_parse_event(HTMLDocument*,LPCWSTR);
 void set_script_mode(HTMLDocument*,SCRIPTMODE);
 
 IHTMLElementCollection *HTMLElementCollection_Create(IUnknown*,HTMLElement**,DWORD);
-IHTMLElementCollection *create_all_collection(HTMLDOMNode*);
+IHTMLElementCollection *create_all_collection(HTMLDOMNode*,BOOL);
 IHTMLElementCollection *create_collection_from_nodelist(HTMLDocument*,IUnknown*,nsIDOMNodeList*);
 
 /* commands */




More information about the wine-cvs mailing list