Bug 1545410 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Office Online Server r=smaug a=jcristau
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 23 May 2019 22:00:58 +0000
changeset 536570 b9d57ba2bf45a07a5348473a354931c49b580e3f
parent 536569 4738da99fbc88df4ba50b494b58342d44fa3575b
child 536571 083d8b196e64e7d0b4b67272abc4788630ef0f47
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1545410, 1514940
milestone68.0
Bug 1545410 - part 1: Forcibly disable new keyCode/charCode value of keypress events if the document is Office Online Server r=smaug a=jcristau Similar to bug 1514940, we need to use "split model" keypres events on Office Online Server since they can be installed into user own servers. Microsoft said it's safe to check whether there is an element whose id is "WACViewPanel_EditingElement": https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c17 Additionally, they'll add new class to the element after fixing the bug in their side: https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c17 https://bugzilla.mozilla.org/show_bug.cgi?id=1545410#c20 Differential Revision: https://phabricator.services.mozilla.com/D32287
dom/events/test/mochitest.ini
dom/events/test/test_use_conflated_keypress_event_model_on_newer_Office_Online_Server.html
dom/events/test/test_use_split_keypress_event_model_on_old_Office_Online_Server.html
toolkit/actors/KeyPressEventModelCheckerChild.jsm
--- a/dom/events/test/mochitest.ini
+++ b/dom/events/test/mochitest.ini
@@ -186,16 +186,18 @@ skip-if = toolkit == 'android' #CRASH_DU
 [test_messageEvent_init.html]
 [test_moz_mouse_pixel_scroll_event.html]
 [test_offsetxy.html]
 [test_onerror_handler_args.html]
 [test_passive_listeners.html]
 [test_paste_image.html]
 skip-if = headless # Bug 1405869
 [test_text_event_in_content.html]
+[test_use_conflated_keypress_event_model_on_newer_Office_Online_Server.html]
+[test_use_split_keypress_event_model_on_old_Office_Online_Server.html]
 [test_wheel_default_action.html]
 skip-if = (verify && debug && (os == 'linux'))
 [test_bug687787.html]
 [test_bug1305458.html]
 [test_bug1298970.html]
 [test_bug1304044.html]
 [test_bug1332699.html]
 [test_bug1339758.html]
new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_use_conflated_keypress_event_model_on_newer_Office_Online_Server.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1545410
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Testing whether "keypress" event model is forcibly conflated model if the document is newer Office Online Server instance</title>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1545410">Bug 1545410</a>
+<p id="display"></p>
+<pre id="test"></pre>
+<input id="input">
+<iframe id="iframe" srcdoc='<html><body><div id="WACViewPanel_EditingElement" spellcheck="false" class="FireFox usehover WACEditing EditMode EditingSurfaceBody WACViewPanel_DisableLegacyKeyCodeAndCharCode" style="overflow: visible; visibility: visible;" contenteditable="true"></div></body></html>'></iframe>
+<script>
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async function doTests() {
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      ["dom.keyboardevent.keypress.set_keycode_and_charcode_to_same_value", true],
+    ],
+  });
+
+  let iframe = document.getElementById("iframe");
+  iframe.contentDocument.body.firstChild.focus();
+  let keypressEvent;
+  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("a", {}, iframe.contentWindow);
+  is(keypressEvent.keyCode, "a".charCodeAt(0),
+     "keyCode value of 'a' should be 'a'");
+  is(keypressEvent.charCode, "a".charCodeAt(0),
+     "charCode value of 'a' should be 'a'");
+
+  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("KEY_Enter", {}, iframe.contentWindow);
+  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
+     "keyCode value of 'Enter' should be DOM_VK_RETURN");
+  is(keypressEvent.charCode, KeyboardEvent.DOM_VK_RETURN,
+     "charCode value of 'Enter' should be DOM_VK_RETURN");
+
+  let input = document.getElementById("input");
+  input.focus();
+  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("a", {});
+  is(keypressEvent.keyCode, "a".charCodeAt(0),
+     "keyCode value of 'a' in the parent document should be 'a'");
+  is(keypressEvent.charCode, "a".charCodeAt(0),
+     "charCode value of 'a' in the parent document should be 'a'");
+
+  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("KEY_Enter");
+  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
+     "keyCode value of 'Enter' in the parent document should be DOM_VK_RETURN");
+  is(keypressEvent.charCode, KeyboardEvent.DOM_VK_RETURN,
+     "charCode value of 'Enter' in the parent document should be DOM_VK_RETURN");
+
+  SimpleTest.finish();
+});
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_use_split_keypress_event_model_on_old_Office_Online_Server.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1545410
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Testing whether "keypress" event model is forcibly split model if the document is old Office Online Server instance</title>
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1545410">Bug 1545410</a>
+<p id="display"></p>
+<pre id="test"></pre>
+<input id="input">
+<iframe id="iframe" srcdoc='<html><body><div id="WACViewPanel_EditingElement" spellcheck="false" class="FireFox usehover WACEditing EditMode EditingSurfaceBody" style="overflow: visible; visibility: visible;" contenteditable="true"></div></body></html>'></iframe>
+<script>
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(async function doTests() {
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      ["dom.keyboardevent.keypress.set_keycode_and_charcode_to_same_value", true],
+    ],
+  });
+
+  let iframe = document.getElementById("iframe");
+  iframe.contentDocument.body.firstChild.focus();
+  let keypressEvent;
+  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("a", {}, iframe.contentWindow);
+  is(keypressEvent.keyCode, 0,
+     "keyCode value of 'a' should be 0");
+  is(keypressEvent.charCode, "a".charCodeAt(0),
+     "charCode value of 'a' should be 'a'");
+
+  iframe.contentDocument.body.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("KEY_Enter", {}, iframe.contentWindow);
+  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
+     "keyCode value of 'Enter' should be DOM_VK_RETURN");
+  is(keypressEvent.charCode, 0,
+     "charCode value of 'Enter' should be 0");
+
+  let input = document.getElementById("input");
+  input.focus();
+  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("a", {});
+  is(keypressEvent.keyCode, "a".charCodeAt(0),
+     "keyCode value of 'a' in the parent document should be 'a'");
+  is(keypressEvent.charCode, "a".charCodeAt(0),
+     "charCode value of 'a' in the parent document should be 'a'");
+
+  input.addEventListener("keypress", aEvent => keypressEvent = aEvent, {once: true});
+  synthesizeKey("KEY_Enter");
+  is(keypressEvent.keyCode, KeyboardEvent.DOM_VK_RETURN,
+     "keyCode value of 'Enter' in the parent document should be DOM_VK_RETURN");
+  is(keypressEvent.charCode, KeyboardEvent.DOM_VK_RETURN,
+     "charCode value of 'Enter' in the parent document should be DOM_VK_RETURN");
+
+  SimpleTest.finish();
+});
+</script>
+</body>
+</html>
--- a/toolkit/actors/KeyPressEventModelCheckerChild.jsm
+++ b/toolkit/actors/KeyPressEventModelCheckerChild.jsm
@@ -24,22 +24,35 @@ class KeyPressEventModelCheckerChild ext
       // Therefore, we need to keep propagating it at least on debug build.
       aEvent.stopImmediatePropagation();
     }
 
     // Currently, even if we set HTMLDocument.KEYPRESS_EVENT_MODEL_CONFLATED
     // here, conflated model isn't used forcibly.  If you need it, you need
     // to change WidgetKeyboardEvent, dom::KeyboardEvent and PresShell.
     let model = HTMLDocument.KEYPRESS_EVENT_MODEL_DEFAULT;
-    if (this._isOldConfluence(aEvent.target.ownerGlobal)) {
+    if (this._isOldOfficeOnlineServer(aEvent.target) ||
+        this._isOldConfluence(aEvent.target.ownerGlobal)) {
       model = HTMLDocument.KEYPRESS_EVENT_MODEL_SPLIT;
     }
     aEvent.target.setKeyPressEventModel(model);
   }
 
+  _isOldOfficeOnlineServer(aDocument) {
+    let editingElement =
+        aDocument.getElementById("WACViewPanel_EditingElement");
+    if (!editingElement) {
+      return false;
+    }
+    let isOldVersion =
+        !editingElement.classList.contains(
+            "WACViewPanel_DisableLegacyKeyCodeAndCharCode");
+    return isOldVersion;
+  }
+
   _isOldConfluence(aWindow) {
     if (!aWindow) {
       return false;
     }
     // aWindow should be an editor window in <iframe>.  However, we don't know
     // whether it can be without <iframe>.  Anyway, there should be tinyMCE
     // object in the parent window or in the window.
     let tinyMCEObject;