Bug 688438 - Fix the IME code to handle text controls correctly when checking for IME status; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 16 Oct 2011 16:15:40 -0400
changeset 79027 269ee0275709eb007bc3cc8f82fe649efe07791a
parent 79026 be42bc18185a53721ac7070b144455b61745fb3f
child 79028 7324c75b47caba4cd479db1b25e1fe3310e187ca
push id21355
push usermak77@bonardo.net
push dateFri, 21 Oct 2011 08:01:08 +0000
treeherdermozilla-central@edcd50167446 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs688438
milestone10.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 688438 - Fix the IME code to handle text controls correctly when checking for IME status; r=bzbarsky
content/base/src/nsGenericElement.cpp
content/events/src/nsIMEStateManager.cpp
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -1343,17 +1343,22 @@ nsIContent::GetFlattenedTreeParent() con
   }
   return parent;
 }
 
 PRUint32
 nsIContent::GetDesiredIMEState()
 {
   if (!IsEditableInternal()) {
-    return IME_STATUS_DISABLE;
+    // Check for the special case where we're dealing with elements which don't
+    // have the editable flag set, but are readwrite (such as text controls).
+    if (!IsElement() ||
+        !AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
+      return IME_STATUS_DISABLE;
+    }
   }
   // NOTE: The content for independent editors (e.g., input[type=text],
   // textarea) must override this method, so, we don't need to worry about
   // that here.
   nsIContent *editableAncestor = GetEditingHost();
 
   // This is in another editable content, use the result of it.
   if (editableAncestor && editableAncestor != this) {
--- a/content/events/src/nsIMEStateManager.cpp
+++ b/content/events/src/nsIMEStateManager.cpp
@@ -641,23 +641,34 @@ nsTextStateManager::ContentRemoved(nsIDo
     return;
 
   // fire notification
   if (childOffset)
     nsContentUtils::AddScriptRunner(
         new TextChangeEvent(mWidget, offset, offset + childOffset, offset));
 }
 
+static bool IsEditable(nsINode* node) {
+  if (node->IsEditable()) {
+    return true;
+  }
+  // |node| might be readwrite (for example, a text control)
+  if (node->IsElement() && node->AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
+    return true;
+  }
+  return false;
+}
+
 static nsINode* GetRootEditableNode(nsPresContext* aPresContext,
                                     nsIContent* aContent)
 {
   if (aContent) {
     nsINode* root = nsnull;
     nsINode* node = aContent;
-    while (node && node->IsEditable()) {
+    while (node && IsEditable(node)) {
       root = node;
       node = node->GetNodeParent();
     }
     return root;
   }
   if (aPresContext) {
     nsIDocument* document = aPresContext->Document();
     if (document && document->IsEditable())