mshtml: Added IHTMLElement::put_outerHTML implementation.
This commit is contained in:
parent
495267e5f1
commit
b553019dc3
|
@ -908,8 +908,63 @@ static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
|
|||
static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
|
||||
{
|
||||
HTMLElement *This = HTMLELEM_THIS(iface);
|
||||
FIXME("(%p)->(%s)\n", This, debugstr_w(v));
|
||||
return E_NOTIMPL;
|
||||
nsIDOMDocumentFragment *nsfragment;
|
||||
nsIDOMDocumentRange *nsdocrange;
|
||||
nsIDOMNSRange *nsrange;
|
||||
nsIDOMNode *nsparent;
|
||||
nsIDOMRange *range;
|
||||
nsAString html_str;
|
||||
nsresult nsres;
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
|
||||
|
||||
nsres = nsIDOMHTMLDocument_QueryInterface(This->node.doc->nsdoc, &IID_nsIDOMDocumentRange, (void**)&nsdocrange);
|
||||
if(NS_FAILED(nsres))
|
||||
return E_FAIL;
|
||||
|
||||
nsres = nsIDOMDocumentRange_CreateRange(nsdocrange, &range);
|
||||
nsIDOMDocumentRange_Release(nsdocrange);
|
||||
if(NS_FAILED(nsres)) {
|
||||
ERR("CreateRange failed: %08x\n", nsres);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsres = nsIDOMRange_QueryInterface(range, &IID_nsIDOMNSRange, (void**)&nsrange);
|
||||
nsIDOMRange_Release(range);
|
||||
if(NS_FAILED(nsres)) {
|
||||
ERR("Could not get nsIDOMNSRange: %08x\n", nsres);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsAString_Init(&html_str, v);
|
||||
nsIDOMNSRange_CreateContextualFragment(nsrange, &html_str, &nsfragment);
|
||||
nsIDOMNSRange_Release(nsrange);
|
||||
nsAString_Finish(&html_str);
|
||||
if(NS_FAILED(nsres)) {
|
||||
ERR("CreateContextualFragment failed: %08x\n", nsres);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &nsparent);
|
||||
if(NS_SUCCEEDED(nsres) && nsparent) {
|
||||
nsIDOMNode *nstmp;
|
||||
|
||||
nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, This->node.nsnode, &nstmp);
|
||||
nsIDOMNode_Release(nsparent);
|
||||
if(NS_FAILED(nsres)) {
|
||||
ERR("ReplaceChild failed: %08x\n", nsres);
|
||||
hres = E_FAIL;
|
||||
}else if(nstmp) {
|
||||
nsIDOMNode_Release(nstmp);
|
||||
}
|
||||
}else {
|
||||
ERR("GetParentNode failed: %08x\n", nsres);
|
||||
hres = E_FAIL;
|
||||
}
|
||||
|
||||
nsIDOMDocumentFragment_Release(nsfragment);
|
||||
return hres;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
|
||||
|
|
|
@ -52,6 +52,11 @@ static const char elem_test_str[] =
|
|||
"<img id=\"imgid\"/>"
|
||||
"<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
|
||||
"</body></html>";
|
||||
static const char elem_test2_str[] =
|
||||
"<html><head><title>test</title><style>.body { margin-right: 0px; }</style>"
|
||||
"<body><div id=\"divid\"></div></body>"
|
||||
"</html>";
|
||||
|
||||
static const char indent_test_str[] =
|
||||
"<html><head><title>test</title></head><body>abc<br /><a href=\"about:blank\">123</a></body></html>";
|
||||
static const char cond_comment_str[] =
|
||||
|
@ -1572,6 +1577,21 @@ static void _test_elem_set_innerhtml(unsigned line, IUnknown *unk, const char *i
|
|||
SysFreeString(html);
|
||||
}
|
||||
|
||||
#define test_elem_set_outerhtml(e,t) _test_elem_set_outerhtml(__LINE__,e,t)
|
||||
static void _test_elem_set_outerhtml(unsigned line, IUnknown *unk, const char *outer_html)
|
||||
{
|
||||
IHTMLElement *elem = _get_elem_iface(line, unk);
|
||||
BSTR html;
|
||||
HRESULT hres;
|
||||
|
||||
html = a2bstr(outer_html);
|
||||
hres = IHTMLElement_put_outerHTML(elem, html);
|
||||
ok_(__FILE__,line)(hres == S_OK, "put_outerHTML failed: %08x\n", hres);
|
||||
|
||||
IHTMLElement_Release(elem);
|
||||
SysFreeString(html);
|
||||
}
|
||||
|
||||
#define get_first_child(n) _get_first_child(__LINE__,n)
|
||||
static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk)
|
||||
{
|
||||
|
@ -5390,6 +5410,33 @@ static void test_elems(IHTMLDocument2 *doc)
|
|||
IHTMLWindow2_Release(window);
|
||||
}
|
||||
|
||||
static void test_elems2(IHTMLDocument2 *doc)
|
||||
{
|
||||
IHTMLElement *elem, *elem2;
|
||||
|
||||
static const elem_type_t outer_types[] = {
|
||||
ET_BR,
|
||||
ET_A
|
||||
};
|
||||
|
||||
elem = get_doc_elem_by_id(doc, "divid");
|
||||
|
||||
test_elem_set_innerhtml((IUnknown*)elem, "<div id=\"innerid\"></div>");
|
||||
elem2 = get_doc_elem_by_id(doc, "innerid");
|
||||
ok(elem2 != NULL, "elem2 == NULL\n");
|
||||
test_elem_set_outerhtml((IUnknown*)elem2, "<br><a href=\"about:blank\" id=\"aid\">a</a>");
|
||||
test_elem_all((IUnknown*)elem, outer_types, sizeof(outer_types)/sizeof(*outer_types));
|
||||
IHTMLElement_Release(elem2);
|
||||
|
||||
elem2 = get_doc_elem_by_id(doc, "aid");
|
||||
ok(elem2 != NULL, "elem2 == NULL\n");
|
||||
test_elem_set_outerhtml((IUnknown*)elem2, "");
|
||||
test_elem_all((IUnknown*)elem, outer_types, 1);
|
||||
IHTMLElement_Release(elem2);
|
||||
|
||||
IHTMLElement_Release(elem);
|
||||
}
|
||||
|
||||
static void test_create_elems(IHTMLDocument2 *doc)
|
||||
{
|
||||
IHTMLElement *elem, *body, *elem2;
|
||||
|
@ -5924,6 +5971,7 @@ START_TEST(dom)
|
|||
}else {
|
||||
skip("IE running in Enhanced Security Configuration\n");
|
||||
}
|
||||
run_domtest(elem_test2_str, test_elems2);
|
||||
run_domtest(doc_blank, test_create_elems);
|
||||
run_domtest(doc_blank, test_defaults);
|
||||
run_domtest(indent_test_str, test_indent);
|
||||
|
|
Loading…
Reference in New Issue