mshtml: Use our IDispatchEx-based attributes implementation instead of nsIDOMAttr.

This commit is contained in:
Jacek Caban 2011-03-02 13:34:24 +01:00 committed by Alexandre Julliard
parent 110155099b
commit 903279eff9
3 changed files with 76 additions and 42 deletions

View File

@ -80,7 +80,6 @@ static ULONG WINAPI HTMLDOMAttribute_Release(IHTMLDOMAttribute *iface)
if(!ref) { if(!ref) {
assert(!This->elem); assert(!This->elem);
nsIDOMAttr_Release(This->nsattr);
release_dispex(&This->dispex); release_dispex(&This->dispex);
heap_free(This); heap_free(This);
} }
@ -136,27 +135,19 @@ static HRESULT WINAPI HTMLDOMAttribute_put_nodeName(IHTMLDOMAttribute *iface, VA
static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p) static HRESULT WINAPI HTMLDOMAttribute_get_nodeValue(IHTMLDOMAttribute *iface, VARIANT *p)
{ {
HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface); HTMLDOMAttribute *This = impl_from_IHTMLDOMAttribute(iface);
const PRUnichar *val; DISPPARAMS dp = {NULL, NULL, 0, 0};
nsAString val_str; EXCEPINFO ei;
HRESULT hres = S_OK;
TRACE("(%p)->(%p)\n", This, p); TRACE("(%p)->(%p)\n", This, p);
nsAString_Init(&val_str, NULL); if(!This->elem) {
nsIDOMAttr_GetNodeValue(This->nsattr, &val_str); FIXME("NULL This->elem\n");
nsAString_GetData(&val_str, &val); return E_UNEXPECTED;
V_VT(p) = VT_BSTR;
if(*val) {
V_BSTR(p) = SysAllocString(val);
if(!V_BSTR(p))
hres = E_OUTOFMEMORY;
}else {
V_BSTR(p) = NULL;
} }
nsAString_Finish(&val_str); memset(&ei, 0, sizeof(ei));
return hres; return IDispatchEx_InvokeEx(&This->elem->node.dispex.IDispatchEx_iface, This->dispid, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dp, p, &ei, NULL);
} }
static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p) static HRESULT WINAPI HTMLDOMAttribute_get_specified(IHTMLDOMAttribute *iface, VARIANT_BOOL *p)
@ -191,7 +182,7 @@ static dispex_static_data_t HTMLDOMAttribute_dispex = {
HTMLDOMAttribute_iface_tids HTMLDOMAttribute_iface_tids
}; };
HRESULT HTMLDOMAttribute_Create(HTMLElement *elem, nsIDOMAttr *nsattr, HTMLDOMAttribute **attr) HRESULT HTMLDOMAttribute_Create(HTMLElement *elem, DISPID dispid, HTMLDOMAttribute **attr)
{ {
HTMLDOMAttribute *ret; HTMLDOMAttribute *ret;
@ -202,9 +193,7 @@ HRESULT HTMLDOMAttribute_Create(HTMLElement *elem, nsIDOMAttr *nsattr, HTMLDOMAt
ret->IHTMLDOMAttribute_iface.lpVtbl = &HTMLDOMAttributeVtbl; ret->IHTMLDOMAttribute_iface.lpVtbl = &HTMLDOMAttributeVtbl;
ret->ref = 1; ret->ref = 1;
nsIDOMAttr_AddRef(nsattr); ret->dispid = dispid;
ret->nsattr = nsattr;
ret->elem = elem; ret->elem = elem;
list_add_tail(&elem->attrs, &ret->entry); list_add_tail(&elem->attrs, &ret->entry);

View File

@ -557,44 +557,89 @@ static HRESULT WINAPI HTMLElement4_normalize(IHTMLElement4 *iface)
return E_NOTIMPL; return E_NOTIMPL;
} }
/* FIXME: This should be done in IDispatchEx implementation layer */
static BOOL get_attr_from_nselem(HTMLElement *This, BSTR name, DISPID *dispid)
{
const PRUnichar *v;
nsIDOMAttr *nsattr;
nsAString nsstr;
BSTR val = NULL;
nsresult nsres;
HRESULT hres;
nsAString_InitDepend(&nsstr, name);
nsres = nsIDOMHTMLElement_GetAttributeNode(This->nselem, &nsstr, &nsattr);
nsAString_Finish(&nsstr);
if(NS_FAILED(nsres) || !nsattr)
return FALSE;
FIXME("HACK\n");
nsAString_Init(&nsstr, NULL);
nsres = nsIDOMAttr_GetNodeValue(nsattr, &nsstr);
if(NS_FAILED(nsres)) {
nsAString_Finish(&nsstr);
return FALSE;
}
nsAString_GetData(&nsstr, &v);
if(*v) {
val = SysAllocString(v);
if(!val) {
nsAString_Finish(&nsstr);
return FALSE;
}
}
nsAString_Finish(&nsstr);
hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, name, fdexNameEnsure, dispid);
if(SUCCEEDED(hres)) {
VARIANT arg;
DISPPARAMS dp = {&arg, NULL, 1, 0};
EXCEPINFO ei;
V_VT(&arg) = VT_BSTR;
V_BSTR(&arg) = val;
memset(&ei, 0, sizeof(ei));
hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, *dispid,
LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dp, NULL, &ei, NULL);
}
SysFreeString(val);
return SUCCEEDED(hres);
}
static HRESULT WINAPI HTMLElement4_getAttributeNode(IHTMLElement4 *iface, BSTR bstrname, IHTMLDOMAttribute **ppAttribute) static HRESULT WINAPI HTMLElement4_getAttributeNode(IHTMLElement4 *iface, BSTR bstrname, IHTMLDOMAttribute **ppAttribute)
{ {
HTMLElement *This = impl_from_IHTMLElement4(iface); HTMLElement *This = impl_from_IHTMLElement4(iface);
HTMLDOMAttribute *attr = NULL, *iter; HTMLDOMAttribute *attr = NULL, *iter;
nsAString name_str; DISPID dispid;
nsIDOMAttr *nsattr;
nsresult nsres;
HRESULT hres; HRESULT hres;
TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrname), ppAttribute); TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrname), ppAttribute);
nsAString_InitDepend(&name_str, bstrname); hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, bstrname, fdexNameCaseInsensitive, &dispid);
nsres = nsIDOMHTMLElement_GetAttributeNode(This->nselem, &name_str, &nsattr); if(hres == DISP_E_UNKNOWNNAME) {
nsAString_Finish(&name_str); if(!get_attr_from_nselem(This, bstrname, &dispid)) {
if(NS_FAILED(nsres)) {
ERR("GetAttributeNode failed: %08x\n", nsres);
return E_FAIL;
}
if(!nsattr) {
*ppAttribute = NULL; *ppAttribute = NULL;
return S_OK; return S_OK;
} }
}else if(FAILED(hres)) {
return hres;
}
LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) { LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
if(iter->nsattr == nsattr) { if(iter->dispid == dispid) {
attr = iter; attr = iter;
break; break;
} }
} }
if(!attr) { if(!attr) {
hres = HTMLDOMAttribute_Create(This, nsattr, &attr); hres = HTMLDOMAttribute_Create(This, dispid, &attr);
if(FAILED(hres)) { if(FAILED(hres))
nsIDOMAttr_Release(nsattr);
return hres; return hres;
} }
}
IHTMLDOMAttribute_AddRef(&attr->IHTMLDOMAttribute_iface); IHTMLDOMAttribute_AddRef(&attr->IHTMLDOMAttribute_iface);
*ppAttribute = &attr->IHTMLDOMAttribute_iface; *ppAttribute = &attr->IHTMLDOMAttribute_iface;

View File

@ -749,13 +749,13 @@ typedef struct {
IHTMLDOMAttribute IHTMLDOMAttribute_iface; IHTMLDOMAttribute IHTMLDOMAttribute_iface;
LONG ref; LONG ref;
nsIDOMAttr *nsattr;
DISPID dispid;
HTMLElement *elem; HTMLElement *elem;
struct list entry; struct list entry;
} HTMLDOMAttribute; } HTMLDOMAttribute;
HRESULT HTMLDOMAttribute_Create(HTMLElement*,nsIDOMAttr*,HTMLDOMAttribute**); HRESULT HTMLDOMAttribute_Create(HTMLElement*,DISPID,HTMLDOMAttribute**);
HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**); HRESULT HTMLElement_Create(HTMLDocumentNode*,nsIDOMNode*,BOOL,HTMLElement**);
HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**); HRESULT HTMLCommentElement_Create(HTMLDocumentNode*,nsIDOMNode*,HTMLElement**);