Jacek Caban : mshtml: Use Gecko attributes for getAttribute, setAttribute and removeAttribute implementation in IE8+ mode.

Alexandre Julliard julliard at winehq.org
Fri Apr 23 15:20:18 CDT 2021


Module: wine
Branch: master
Commit: 10e7ead350d9bb896450fb6f6940190ca21d5b6d
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=10e7ead350d9bb896450fb6f6940190ca21d5b6d

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Apr 23 19:40:14 2021 +0200

mshtml: Use Gecko attributes for getAttribute, setAttribute and removeAttribute implementation in IE8+ mode.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmlelem.c            | 31 +++++++++++++++++++++++++++++++
 dlls/mshtml/tests/documentmode.js | 30 ++++++++++++++++++++++++++++++
 dlls/mshtml/tests/dom.js          |  8 --------
 3 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index 011a06298c2..8187cbf867e 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -871,6 +871,23 @@ static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttr
 
     TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
 
+    if(This->dom_element && dispex_compat_mode(&This->node.event_target.dispex) >= COMPAT_MODE_IE8) {
+        nsAString name_str, value_str;
+        nsresult nsres;
+
+        hres = variant_to_nsstr(&AttributeValue, FALSE, &value_str);
+        if(FAILED(hres))
+            return hres;
+
+        nsAString_InitDepend(&name_str, strAttributeName);
+        nsres = nsIDOMElement_SetAttribute(This->dom_element, &name_str, &value_str);
+        nsAString_Finish(&name_str);
+        nsAString_Finish(&value_str);
+        if(NS_FAILED(nsres))
+            WARN("SetAttribute failed: %08x\n", nsres);
+        return map_nsresult(nsres);
+    }
+
     hres = IDispatchEx_GetDispID(&This->node.event_target.dispex.IDispatchEx_iface, strAttributeName,
             (lFlags&ATTRFLAG_CASESENSITIVE ? fdexNameCaseSensitive : fdexNameCaseInsensitive) | fdexNameEnsure, &dispid);
     if(FAILED(hres))
@@ -927,6 +944,17 @@ static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttr
     if(lFlags & ~(ATTRFLAG_CASESENSITIVE|ATTRFLAG_ASSTRING))
         FIXME("Unsupported flags %x\n", lFlags);
 
+    if(This->dom_element && dispex_compat_mode(&This->node.event_target.dispex) >= COMPAT_MODE_IE8) {
+        nsAString name_str, value_str;
+        nsresult nsres;
+
+        nsAString_InitDepend(&name_str, strAttributeName);
+        nsAString_InitDepend(&value_str, NULL);
+        nsres = nsIDOMElement_GetAttribute(This->dom_element, &name_str, &value_str);
+        nsAString_Finish(&name_str);
+        return return_nsstr_variant(nsres, &value_str, 0, AttributeValue);
+    }
+
     hres = IDispatchEx_GetDispID(&This->node.event_target.dispex.IDispatchEx_iface, strAttributeName,
             lFlags&ATTRFLAG_CASESENSITIVE ? fdexNameCaseSensitive : fdexNameCaseInsensitive, &dispid);
     if(hres == DISP_E_UNKNOWNNAME) {
@@ -954,6 +982,9 @@ static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strA
 
     TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
 
+    if(dispex_compat_mode(&This->node.event_target.dispex) >= COMPAT_MODE_IE8)
+        return element_remove_attribute(This, strAttributeName);
+
     hres = IDispatchEx_GetDispID(&This->node.event_target.dispex.IDispatchEx_iface, strAttributeName,
             lFlags&ATTRFLAG_CASESENSITIVE ? fdexNameCaseSensitive : fdexNameCaseInsensitive, &id);
     if(hres == DISP_E_UNKNOWNNAME) {
diff --git a/dlls/mshtml/tests/documentmode.js b/dlls/mshtml/tests/documentmode.js
index 9cb9c6058a0..d46da5d44a0 100644
--- a/dlls/mshtml/tests/documentmode.js
+++ b/dlls/mshtml/tests/documentmode.js
@@ -622,3 +622,33 @@ sync_test("set_obj", function() {
     r = Object.prototype.toString.call(s);
     ok(r === "[object Object]", "toString returned " + r);
 });
+
+sync_test("elem_attr", function() {
+    var v = document.documentMode;
+    var elem = document.createElement("div"), r;
+
+    r = elem.getAttribute("class");
+    ok(r === null, "class attr = " + r);
+    r = elem.getAttribute("className");
+    ok(r === (v < 8 ? "" : null), "className attr = " + r);
+
+    elem.className = "cls";
+    r = elem.getAttribute("class");
+    ok(r === (v < 8 ? null : "cls"), "class attr = " + r);
+    r = elem.getAttribute("className");
+    ok(r === (v < 8 ? "cls" : null), "className attr = " + r);
+
+    elem.setAttribute("class", "cls2");
+    ok(elem.className === (v < 8 ? "cls" : "cls2"), "elem.className = " + elem.className);
+    r = elem.getAttribute("class");
+    ok(r === "cls2", "class attr = " + r);
+    r = elem.getAttribute("className");
+    ok(r === (v < 8 ? "cls" : null), "className attr = " + r);
+
+    elem.setAttribute("className", "cls3");
+    ok(elem.className === (v < 8 ? "cls3" : "cls2"), "elem.className = " + elem.className);
+    r = elem.getAttribute("class");
+    ok(r === "cls2", "class attr = " + r);
+    r = elem.getAttribute("className");
+    ok(r === "cls3", "className attr = " + r);
+});
diff --git a/dlls/mshtml/tests/dom.js b/dlls/mshtml/tests/dom.js
index 6a84dd3a032..d171b516cfd 100644
--- a/dlls/mshtml/tests/dom.js
+++ b/dlls/mshtml/tests/dom.js
@@ -462,7 +462,6 @@ async_test("animation_frame", function() {
 sync_test("title", function() {
     var elem = document.createElement("div");
     ok(elem.title === "", "div.title = " + elem.title);
-    todo_wine.
     ok(elem.getAttribute("title") === null, "title attribute = " + elem.getAttribute("title"));
     elem.title = "test";
     ok(elem.title === "test", "div.title = " + elem.title);
@@ -473,27 +472,22 @@ sync_test("disabled", function() {
     var elem = document.createElement("div");
     document.body.appendChild(elem);
     ok(elem.disabled === false, "div.disabled = " + elem.disabled);
-    todo_wine.
     ok(elem.getAttribute("disabled") === null, "disabled attribute = " + elem.getAttribute("disabled") + " expected null");
 
     elem.disabled = true;
     ok(elem.disabled === true, "div.disabled = " + elem.disabled);
-    todo_wine.
     ok(elem.getAttribute("disabled") === "", "disabled attribute = " + elem.getAttribute("disabled") + " expected \"\"");
 
     elem.disabled = false;
     ok(elem.disabled === false, "div.disabled = " + elem.disabled);
-    todo_wine.
     ok(elem.getAttribute("disabled") === null, "disabled attribute = " + elem.getAttribute("disabled") + " expected null");
 
     elem.setAttribute("disabled", "false");
     ok(elem.disabled === true, "div.disabled = " + elem.disabled);
-    todo_wine.
     ok(elem.getAttribute("disabled") === "false", "disabled attribute = " + elem.getAttribute("disabled"));
 
     elem.removeAttribute("disabled");
     ok(elem.disabled === false, "div.disabled = " + elem.disabled);
-    todo_wine.
     ok(elem.getAttribute("disabled") === null, "disabled attribute = " + elem.getAttribute("disabled") + " expected null");
 });
 
@@ -508,11 +502,9 @@ sync_test("hasAttribute", function() {
 
     elem.setAttribute("attr2", "abc");
     r = elem.hasAttribute("attr2");
-    todo_wine.
     ok(r === true, "hasAttribute(attr2) returned " + r);
 
     elem.removeAttribute("attr");
     r = elem.hasAttribute("attr");
-    todo_wine.
     ok(r === false, "hasAttribute(attr) returned " + r);
 });




More information about the wine-cvs mailing list