mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-16 05:47:02 +00:00
mshtml: Implement HTMLStyleSheet's addRule.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
2412a04d84
commit
e670d0a81a
|
@ -795,9 +795,41 @@ static HRESULT WINAPI HTMLStyleSheet_addRule(IHTMLStyleSheet *iface, BSTR bstrSe
|
|||
BSTR bstrStyle, LONG lIndex, LONG *plIndex)
|
||||
{
|
||||
HTMLStyleSheet *This = impl_from_IHTMLStyleSheet(iface);
|
||||
FIXME("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
|
||||
const WCHAR format[] = L"%s {%s}";
|
||||
nsIDOMCSSRuleList *nslist = NULL;
|
||||
UINT32 length, new_index;
|
||||
nsAString nsstr;
|
||||
nsresult nsres;
|
||||
WCHAR *rule;
|
||||
size_t len;
|
||||
|
||||
TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(bstrSelector), debugstr_w(bstrStyle),
|
||||
lIndex, plIndex);
|
||||
return E_NOTIMPL;
|
||||
|
||||
if(!bstrSelector || !bstrStyle || !bstrSelector[0] || !bstrStyle[0])
|
||||
return E_INVALIDARG;
|
||||
|
||||
nsres = nsIDOMCSSStyleSheet_GetCssRules(This->nsstylesheet, &nslist);
|
||||
if(NS_FAILED(nsres))
|
||||
return E_FAIL;
|
||||
nsIDOMCSSRuleList_GetLength(nslist, &length);
|
||||
|
||||
if(lIndex > length)
|
||||
lIndex = length;
|
||||
|
||||
len = ARRAY_SIZE(format) - 4 /* %s twice */ + wcslen(bstrSelector) + wcslen(bstrStyle);
|
||||
if(!(rule = heap_alloc(len * sizeof(WCHAR))))
|
||||
return E_OUTOFMEMORY;
|
||||
swprintf(rule, len, format, bstrSelector, bstrStyle);
|
||||
|
||||
nsAString_InitDepend(&nsstr, rule);
|
||||
nsres = nsIDOMCSSStyleSheet_InsertRule(This->nsstylesheet, &nsstr, lIndex, &new_index);
|
||||
if(NS_FAILED(nsres)) WARN("failed: %08x\n", nsres);
|
||||
nsAString_Finish(&nsstr);
|
||||
heap_free(rule);
|
||||
|
||||
*plIndex = new_index;
|
||||
return map_nsresult(nsres);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI HTMLStyleSheet_removeImport(IHTMLStyleSheet *iface, LONG lIndex)
|
||||
|
|
|
@ -405,6 +405,32 @@ sync_test("stylesheets", function() {
|
|||
stylesheet.insertRule(".input { margin-left: 1px; }", 3);
|
||||
ok(false, "expected exception");
|
||||
}catch(e) {}
|
||||
|
||||
id = stylesheet.addRule(".p", "margin-top: 2px");
|
||||
ok(id === 2, "id = " + id);
|
||||
ok(document.styleSheets.length === 1, "document.styleSheets.length = " + document.styleSheets.length);
|
||||
ok(stylesheet.rules.length === 3, "stylesheet.rules.length = " + stylesheet.rules.length);
|
||||
|
||||
id = stylesheet.addRule(".pre", "border: none", -1);
|
||||
ok(id === 3, "id = " + id);
|
||||
ok(stylesheet.rules.length === 4, "stylesheet.rules.length = " + stylesheet.rules.length);
|
||||
|
||||
id = stylesheet.addRule(".h1", " ", 0);
|
||||
ok(id === 0, "id = " + id);
|
||||
ok(stylesheet.rules.length === 5, "stylesheet.rules.length = " + stylesheet.rules.length);
|
||||
|
||||
id = stylesheet.addRule(".h2", "color: black", 8);
|
||||
ok(id === 5, "id = " + id);
|
||||
ok(stylesheet.rules.length === 6, "stylesheet.rules.length = " + stylesheet.rules.length);
|
||||
|
||||
try {
|
||||
stylesheet.addRule("", "border: none", 0);
|
||||
ok(false, "expected exception");
|
||||
}catch(e) {}
|
||||
try {
|
||||
stylesheet.addRule(".img", "", 0);
|
||||
ok(false, "expected exception");
|
||||
}catch(e) {}
|
||||
});
|
||||
|
||||
sync_test("storage", function() {
|
||||
|
|
Loading…
Reference in a new issue