Bug 688438 - Fix the IME code to handle text controls correctly when checking for IME status; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 24 May 2012 17:49:44 -0400
changeset 94882 4651104e0d0e405f5263b21c41e78a0620dfc051
parent 94881 eca8e2875ef5ce3f2c54b859c68dcdb578c4fc81
child 94883 8a089d72876e15b50cb5d7387cc0cf92ad23bd60
push id9850
push usereakhgari@mozilla.com
push dateThu, 24 May 2012 21:49:52 +0000
treeherdermozilla-inbound@4651104e0d0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs688438
milestone15.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
@@ -1473,17 +1473,22 @@ nsIContent::GetFlattenedTreeParent() con
   }
   return parent;
 }
 
 nsIContent::IMEState
 nsIContent::GetDesiredIMEState()
 {
   if (!IsEditableInternal()) {
-    return IMEState(IMEState::DISABLED);
+    // 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 IMEState(IMEState::DISABLED);
+    }
   }
   // 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
@@ -655,23 +655,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())