mshtml: Store HTMLDOMNode struct instead of pointer in HTMLElement object.

This commit is contained in:
Jacek Caban 2007-09-12 23:39:17 +02:00 committed by Alexandre Julliard
parent bb90785a68
commit b733e95859
8 changed files with 73 additions and 53 deletions

View File

@ -82,7 +82,7 @@ static ULONG WINAPI HTMLAnchorElement_AddRef(IHTMLAnchorElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
}
static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
@ -91,7 +91,7 @@ static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
}
static HRESULT WINAPI HTMLAnchorElement_GetTypeInfoCount(IHTMLAnchorElement *iface, UINT *pctinfo)

View File

@ -95,7 +95,7 @@ static ULONG WINAPI HTMLBodyElement_AddRef(IHTMLBodyElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
}
static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
@ -104,7 +104,7 @@ static ULONG WINAPI HTMLBodyElement_Release(IHTMLBodyElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
}
static HRESULT WINAPI HTMLBodyElement_GetTypeInfoCount(IHTMLBodyElement *iface, UINT *pctinfo)
@ -406,18 +406,18 @@ static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, I
TRACE("(%p)->(%p)\n", This, range);
if(This->element->node->doc->nscontainer) {
if(This->element->node.doc->nscontainer) {
nsIDOMDocument *nsdoc;
nsIDOMDocumentRange *nsdocrange;
nsresult nsres;
nsIWebNavigation_GetDocument(This->element->node->doc->nscontainer->navigation, &nsdoc);
nsIWebNavigation_GetDocument(This->element->node.doc->nscontainer->navigation, &nsdoc);
nsIDOMDocument_QueryInterface(nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
nsIDOMDocument_Release(nsdoc);
nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &nsrange);
if(NS_SUCCEEDED(nsres)) {
nsres = nsIDOMRange_SelectNodeContents(nsrange, This->element->node->nsnode);
nsres = nsIDOMRange_SelectNodeContents(nsrange, This->element->node.nsnode);
if(NS_FAILED(nsres))
ERR("SelectNodeContents failed: %08x\n", nsres);
}else {
@ -427,7 +427,7 @@ static HRESULT WINAPI HTMLBodyElement_createTextRange(IHTMLBodyElement *iface, I
nsIDOMDocumentRange_Release(nsdocrange);
}
*range = HTMLTxtRange_Create(This->element->node->doc, nsrange);
*range = HTMLTxtRange_Create(This->element->node.doc, nsrange);
return S_OK;
}

View File

@ -58,6 +58,8 @@ static void elem_vector_add(elem_vector *buf, HTMLElement *elem)
#define HTMLELEM_THIS(iface) DEFINE_THIS(HTMLElement, HTMLElement, iface)
#define HTMLELEM_NODE_THIS(node) ((HTMLElement *) node)
static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
REFIID riid, void **ppv)
{
@ -82,7 +84,7 @@ static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
return IUnknown_AddRef(This->impl);
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->node.doc));
}
static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
@ -93,7 +95,7 @@ static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
return IUnknown_Release(This->impl);
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->node.doc));
}
static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
@ -199,7 +201,7 @@ static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttr
WCHAR buffer[256];
DWORD len;
BSTR bstrBaseUrl;
hres = IHTMLDocument2_get_URL(HTMLDOC(This->node->doc), &bstrBaseUrl);
hres = IHTMLDocument2_get_URL(HTMLDOC(This->node.doc), &bstrBaseUrl);
if(SUCCEEDED(hres)) {
hres = CoInternetCombineUrl(bstrBaseUrl, value,
URL_ESCAPE_SPACES_ONLY|URL_DONT_ESCAPE_EXTRA_INFO,
@ -763,7 +765,7 @@ static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR w
TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
nsres = nsIWebNavigation_GetDocument(This->node->doc->nscontainer->navigation, &nsdoc);
nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
if(NS_FAILED(nsres))
{
ERR("GetDocument failed: %08x\n", nsres);
@ -825,7 +827,7 @@ static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR w
TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
nsres = nsIWebNavigation_GetDocument(This->node->doc->nscontainer->navigation, &nsdoc);
nsres = nsIWebNavigation_GetDocument(This->node.doc->nscontainer->navigation, &nsdoc);
if(NS_FAILED(nsres) || !nsdoc)
{
ERR("GetDocument failed: %08x\n", nsres);
@ -1034,7 +1036,7 @@ static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector
HTMLDOMNode *node;
nsresult nsres;
nsres = nsIDOMNode_GetChildNodes(elem->node->nsnode, &nsnode_list);
nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
if(NS_FAILED(nsres)) {
ERR("GetChildNodes failed: %08x\n", nsres);
return;
@ -1058,7 +1060,7 @@ static void create_child_list(HTMLDocument *doc, HTMLElement *elem, elem_vector
if(node->node_type != NT_HTMLELEM)
continue;
elem_vector_add(buf, (HTMLElement*)node->impl.elem);
elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
}
}
@ -1069,7 +1071,7 @@ static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **
TRACE("(%p)->(%p)\n", This, p);
create_child_list(This->node->doc, This, &buf);
create_child_list(This->node.doc, This, &buf);
return HTMLElementCollection_Create((IUnknown*)HTMLELEM(This), buf.buf, buf.len, p);
}
@ -1082,7 +1084,7 @@ static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *b
HTMLDOMNode *node;
nsresult nsres;
nsres = nsIDOMNode_GetChildNodes(elem->node->nsnode, &nsnode_list);
nsres = nsIDOMNode_GetChildNodes(elem->node.nsnode, &nsnode_list);
if(NS_FAILED(nsres)) {
ERR("GetChildNodes failed: %08x\n", nsres);
return;
@ -1103,8 +1105,8 @@ static void create_all_list(HTMLDocument *doc, HTMLElement *elem, elem_vector *b
if(node->node_type != NT_HTMLELEM)
continue;
elem_vector_add(buf, (HTMLElement*)node->impl.elem);
create_all_list(doc, (HTMLElement*)node->impl.elem, buf);
elem_vector_add(buf, HTMLELEM_NODE_THIS(node));
create_all_list(doc, HTMLELEM_NODE_THIS(node), buf);
}
}
@ -1117,7 +1119,9 @@ 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, &buf);
TRACE("ret\n");
if(!buf.len) {
mshtml_free(buf.buf);
@ -1264,10 +1268,10 @@ HRESULT HTMLElement_QI(HTMLElement *This, REFIID riid, void **ppv)
return S_OK;
}
return HTMLDOMNode_QI(This->node, riid, ppv);
return HTMLDOMNode_QI(&This->node, riid, ppv);
}
void HTMLElement_Create(HTMLDOMNode *node)
HTMLElement *HTMLElement_Create(nsIDOMNode *nsnode)
{
HTMLElement *ret;
nsAString class_name_str;
@ -1282,19 +1286,18 @@ void HTMLElement_Create(HTMLDOMNode *node)
ret = mshtml_alloc(sizeof(HTMLElement));
ret->lpHTMLElementVtbl = &HTMLElementVtbl;
ret->node = node;
ret->impl = NULL;
ret->destructor = NULL;
node->node_type = NT_HTMLELEM;
node->impl.elem = HTMLELEM(ret);
node->destructor = HTMLElement_destructor;
ret->node.node_type = NT_HTMLELEM;
ret->node.impl.elem = HTMLELEM(ret);
ret->node.destructor = HTMLElement_destructor;
HTMLElement2_Init(ret);
nsres = nsIDOMNode_QueryInterface(node->nsnode, &IID_nsIDOMHTMLElement, (void**)&ret->nselem);
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&ret->nselem);
if(NS_FAILED(nsres))
return;
return NULL;
nsAString_Init(&class_name_str, NULL);
nsIDOMHTMLElement_GetTagName(ret->nselem, &class_name_str);
@ -1313,6 +1316,8 @@ void HTMLElement_Create(HTMLDOMNode *node)
HTMLTextAreaElement_Create(ret);
nsAString_Finish(&class_name_str);
return ret;
}
typedef struct {

View File

@ -83,7 +83,7 @@ static ULONG WINAPI HTMLInputElement_AddRef(IHTMLInputElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
}
static ULONG WINAPI HTMLInputElement_Release(IHTMLInputElement *iface)
@ -92,7 +92,7 @@ static ULONG WINAPI HTMLInputElement_Release(IHTMLInputElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
}
static HRESULT WINAPI HTMLInputElement_GetTypeInfoCount(IHTMLInputElement *iface, UINT *pctinfo)

View File

@ -335,6 +335,33 @@ HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
return E_NOINTERFACE;
}
static HTMLDOMNode *create_node(HTMLDocument *doc, nsIDOMNode *nsnode)
{
HTMLDOMNode *ret;
PRUint16 node_type;
nsIDOMNode_GetNodeType(nsnode, &node_type);
switch(node_type) {
case ELEMENT_NODE:
ret = &HTMLElement_Create(nsnode)->node;
break;
default:
ret = mshtml_alloc(sizeof(HTMLDOMNode));
ret->node_type = NT_UNKNOWN;
ret->impl.unk = NULL;
ret->destructor = NULL;
}
ret->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
ret->doc = doc;
nsIDOMNode_AddRef(nsnode);
ret->nsnode = nsnode;
return ret;
}
/*
* FIXME
* List looks really ugly here. We should use a better data structure or
@ -344,7 +371,6 @@ HRESULT HTMLDOMNode_QI(HTMLDOMNode *This, REFIID riid, void **ppv)
HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode)
{
HTMLDOMNode *iter = This->nodes, *ret;
PRUint16 node_type;
while(iter) {
if(iter->nsnode == nsnode)
@ -355,24 +381,11 @@ HTMLDOMNode *get_node(HTMLDocument *This, nsIDOMNode *nsnode)
if(iter)
return iter;
ret = mshtml_alloc(sizeof(HTMLDOMNode));
ret->lpHTMLDOMNodeVtbl = &HTMLDOMNodeVtbl;
ret->node_type = NT_UNKNOWN;
ret->impl.unk = NULL;
ret->destructor = NULL;
ret->doc = This;
nsIDOMNode_AddRef(nsnode);
ret->nsnode = nsnode;
ret = create_node(This, nsnode);
ret->next = This->nodes;
This->nodes = ret;
nsIDOMNode_GetNodeType(nsnode, &node_type);
if(node_type == ELEMENT_NODE)
HTMLElement_Create(ret);
return ret;
}
@ -385,9 +398,10 @@ void release_nodes(HTMLDocument *This)
for(iter = This->nodes; iter; iter = next) {
next = iter->next;
nsIDOMNode_Release(iter->nsnode);
if(iter->destructor)
iter->destructor(iter->impl.unk);
nsIDOMNode_Release(iter->nsnode);
mshtml_free(iter);
else
mshtml_free(iter);
}
}

View File

@ -83,7 +83,7 @@ static ULONG WINAPI HTMLSelectElement_AddRef(IHTMLSelectElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
}
static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
@ -92,7 +92,7 @@ static ULONG WINAPI HTMLSelectElement_Release(IHTMLSelectElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
}
static HRESULT WINAPI HTMLSelectElement_GetTypeInfoCount(IHTMLSelectElement *iface, UINT *pctinfo)

View File

@ -83,7 +83,7 @@ static ULONG WINAPI HTMLTextAreaElement_AddRef(IHTMLTextAreaElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_AddRef(HTMLDOC(This->element->node.doc));
}
static ULONG WINAPI HTMLTextAreaElement_Release(IHTMLTextAreaElement *iface)
@ -92,7 +92,7 @@ static ULONG WINAPI HTMLTextAreaElement_Release(IHTMLTextAreaElement *iface)
TRACE("(%p)\n", This);
return IHTMLDocument2_Release(HTMLDOC(This->element->node->doc));
return IHTMLDocument2_Release(HTMLDOC(This->element->node.doc));
}
static HRESULT WINAPI HTMLTextAreaElement_GetTypeInfoCount(IHTMLTextAreaElement *iface, UINT *pctinfo)

View File

@ -271,13 +271,14 @@ struct HTMLDOMNode {
};
typedef struct {
HTMLDOMNode node;
const IHTMLElementVtbl *lpHTMLElementVtbl;
const IHTMLElement2Vtbl *lpHTMLElement2Vtbl;
void (*destructor)(IUnknown*);
nsIDOMHTMLElement *nselem;
HTMLDOMNode *node;
IUnknown *impl;
} HTMLElement;
@ -414,7 +415,7 @@ IHTMLStyleSheet *HTMLStyleSheet_Create(void);
void detach_selection(HTMLDocument*);
void detach_ranges(HTMLDocument*);
void HTMLElement_Create(HTMLDOMNode*);
HTMLElement *HTMLElement_Create(nsIDOMNode*);
void HTMLAnchorElement_Create(HTMLElement*);
void HTMLBodyElement_Create(HTMLElement*);
void HTMLInputElement_Create(HTMLElement*);