Bug 1175399 - Move readonly detection into isFocusableElement. r=janjongboom
authorTim Chien <timdream@gmail.com>
Fri, 03 Jul 2015 01:42:00 +0200
changeset 275852 0371fcd2e3e439f85c70860fd2ca450d55ac62f5
parent 275851 cd94f7a2b847521e3b9578b336871398597a9eb6
child 275853 bd5a76b318f790830b34088d665dd352514dec03
push id3246
push usergijskruitbosch@gmail.com
push dateTue, 07 Jul 2015 09:06:38 +0000
reviewersjanjongboom
bugs1175399
milestone42.0a1
Bug 1175399 - Move readonly detection into isFocusableElement. r=janjongboom
dom/inputmethod/forms.js
dom/inputmethod/mochitest/mochitest.ini
dom/inputmethod/mochitest/test_bug1175399.html
--- a/dom/inputmethod/forms.js
+++ b/dom/inputmethod/forms.js
@@ -666,17 +666,18 @@ let FormAssistant = {
   handleFocus: function fa_handleFocus(target) {
     if (this.focusedElement === target)
       return;
 
     if (target instanceof HTMLOptionElement)
       target = target.parentNode;
 
     this.setFocusedElement(target);
-    this.isHandlingFocus = this.sendInputState(target);
+    this.sendInputState(target);
+    this.isHandlingFocus = true;
   },
 
   unhandleFocus: function fa_unhandleFocus() {
     this.setFocusedElement(null);
     this.isHandlingFocus = false;
     sendAsyncMessage("Forms:Input", { "type": "blur" });
   },
 
@@ -685,40 +686,33 @@ let FormAssistant = {
         element instanceof HTMLTextAreaElement)
       return true;
 
     if (element instanceof HTMLOptionElement &&
         element.parentNode instanceof HTMLSelectElement)
       return true;
 
     return (element instanceof HTMLInputElement &&
-            !this.ignoredInputTypes.has(element.type));
+            !this.ignoredInputTypes.has(element.type) &&
+            !element.readOnly);
   },
 
   getTopLevelEditable: function fa_getTopLevelEditable(element) {
     function retrieveTopLevelEditable(element) {
       while (element && !isContentEditable(element))
         element = element.parentNode;
 
       return element;
     }
 
     return retrieveTopLevelEditable(element) || element;
   },
 
   sendInputState: function(element) {
-    // FIXME/bug 729623: work around apparent bug in the IME manager
-    // in gecko.
-    let readonly = element.getAttribute("readonly");
-    if (readonly) {
-      return false;
-    }
-
     sendAsyncMessage("Forms:Input", getJSON(element, this._focusCounter));
-    return true;
   },
 
   getSelectionInfo: function fa_getSelectionInfo() {
     let element = this.focusedElement;
     let range =  getSelectionRange(element);
 
     let text = isContentEditable(element) ? getContentEditableText(element)
                                           : element.value;
--- a/dom/inputmethod/mochitest/mochitest.ini
+++ b/dom/inputmethod/mochitest/mochitest.ini
@@ -15,13 +15,14 @@ support-files =
 [test_bug949059.html]
 [test_bug953044.html]
 [test_bug960946.html]
 [test_bug978918.html]
 [test_bug1026997.html]
 [test_bug1043828.html]
 [test_bug1059163.html]
 [test_bug1066515.html]
+[test_bug1175399.html]
 [test_sendkey_cancel.html]
 [test_sync_edit.html]
 [test_two_inputs.html]
 [test_two_selects.html]
 [test_unload.html]
new file mode 100644
--- /dev/null
+++ b/dom/inputmethod/mochitest/test_bug1175399.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1175399
+-->
+<head>
+  <title>Test focus when page unloads</title>
+  <script type="application/javascript;version=1.7" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript;version=1.7" src="inputmethod_common.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=1175399">Mozilla Bug 1175399</a>
+<p id="display"></p>
+<pre id="test">
+<script class="testbody" type="application/javascript;version=1.7">
+
+inputmethod_setup(function() {
+  runTest();
+});
+
+let appFrameScript = function appFrameScript() {
+  let input = content.document.body.firstElementChild;
+  input.focus();
+
+  content.setTimeout(function() {
+    sendAsyncMessage('test:step');
+  });
+};
+
+function runTest() {
+  let im = navigator.mozInputMethod;
+
+  // Set current page as an input method.
+  SpecialPowers.wrap(im).setActive(true);
+
+  let iframe = document.createElement('iframe');
+  iframe.src = 'data:text/html,<html><body><input value="First" readonly></body></html>';
+  iframe.setAttribute('mozbrowser', true);
+  document.body.appendChild(iframe);
+
+  let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
+  im.oninputcontextchange = function() {
+    is(false, 'should not receive inputcontextchange event');
+  };
+
+  iframe.addEventListener('mozbrowserloadend', function() {
+    mm.addMessageListener('test:step', function() {
+      let inputcontext = navigator.mozInputMethod.inputcontext;
+      is(inputcontext, null, 'inputcontext is null');
+
+      inputmethod_cleanup();
+    });
+    mm.loadFrameScript('data:,(' + encodeURIComponent(appFrameScript.toString()) + ')();', false);
+  });
+}
+
+</script>
+</pre>
+</body>
+</html>
+