Gabriel Ivăncescu : mshtml: Implement HTMLStyleSheet's addRule.
Alexandre Julliard
julliard at winehq.org
Fri Oct 1 18:02:23 CDT 2021
Module: wine
Branch: master
Commit: e670d0a81a57f2a344ff6445af335a85e8132c63
URL: https://source.winehq.org/git/wine.git/?a=commit;h=e670d0a81a57f2a344ff6445af335a85e8132c63
Author: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Date: Fri Oct 1 16:12:46 2021 +0300
mshtml: Implement HTMLStyleSheet's addRule.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/mshtml/htmlstylesheet.c | 36 ++++++++++++++++++++++++++++++++++--
dlls/mshtml/tests/dom.js | 26 ++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlstylesheet.c b/dlls/mshtml/htmlstylesheet.c
index 4519b06155e..b6f1c980760 100644
--- a/dlls/mshtml/htmlstylesheet.c
+++ b/dlls/mshtml/htmlstylesheet.c
@@ -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)
diff --git a/dlls/mshtml/tests/dom.js b/dlls/mshtml/tests/dom.js
index 73c2b3b0866..3a2b96a7958 100644
--- a/dlls/mshtml/tests/dom.js
+++ b/dlls/mshtml/tests/dom.js
@@ -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() {
More information about the wine-cvs
mailing list