Bug 734530 - Spell check textareas if they're reframed when focused; r=roc a=akeybl
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 19 Mar 2012 12:21:56 -0400
changeset 91862 158500e8fa4edf2feba20f33f550bd4dd89ac4c0
parent 91861 772477595ea4ab74561baa5933e76fdb0b559b9b
child 91863 4b7327c0fd0050f629ee56c8b25cb2f9b309589e
push idunknown
push userunknown
push dateunknown
reviewersroc, akeybl
bugs734530
milestone13.0a2
Bug 734530 - Spell check textareas if they're reframed when focused; r=roc a=akeybl
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditorEventListener.cpp
editor/libeditor/base/nsEditorEventListener.h
layout/reftests/editor/reftest.list
layout/reftests/editor/spellcheck-textarea-focused-reframe.html
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -336,16 +336,23 @@ nsEditor::PostCreate()
 
     nsIMEStateManager::OnTextStateBlur(pc, nsnull);
     nsIMEStateManager::OnTextStateFocus(pc, focusedContent);
 
     nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(focusedContent);
     if (target) {
       InitializeSelection(target);
     }
+
+    // If the text control gets reframed during focus, Focus() would not be
+    // called, so take a chance here to see if we need to spell check the text
+    // control.
+    nsEditorEventListener* listener =
+      reinterpret_cast<nsEditorEventListener*> (mEventListener.get());
+    listener->SpellCheckIfNeeded();
   }
   return NS_OK;
 }
 
 /* virtual */
 void
 nsEditor::CreateEventListeners()
 {
--- a/editor/libeditor/base/nsEditorEventListener.cpp
+++ b/editor/libeditor/base/nsEditorEventListener.cpp
@@ -900,27 +900,19 @@ nsEditorEventListener::Focus(nsIDOMEvent
 {
   NS_ENSURE_TRUE(mEditor, NS_ERROR_NOT_AVAILABLE);
   NS_ENSURE_ARG(aEvent);
 
   // Don't turn on selection and caret when the editor is disabled.
   if (mEditor->IsDisabled()) {
     return NS_OK;
   }
-  
-  // If the spell check skip flag is still enabled from creation time,
-  // disable it because focused editors are allowed to spell check.
-  PRUint32 currentFlags = 0;
-  mEditor->GetFlags(&currentFlags);
-  if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck)
-  {
-    currentFlags ^= nsIPlaintextEditor::eEditorSkipSpellCheck;
-    mEditor->SetFlags(currentFlags);
-  }
-  
+
+  // Spell check a textarea the first time that it is focused.
+  SpellCheckIfNeeded();
 
   nsCOMPtr<nsIDOMEventTarget> target;
   aEvent->GetTarget(getter_AddRefs(target));
   nsCOMPtr<nsINode> node = do_QueryInterface(target);
   NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
 
   // If the traget is a document node but it's not editable, we should ignore
   // it because actual focused element's event is going to come.
@@ -1008,8 +1000,21 @@ nsEditorEventListener::Blur(nsIDOMEvent*
     }
 
     selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
   }
 
   return NS_OK;
 }
 
+void
+nsEditorEventListener::SpellCheckIfNeeded() {
+  // If the spell check skip flag is still enabled from creation time,
+  // disable it because focused editors are allowed to spell check.
+  PRUint32 currentFlags = 0;
+  mEditor->GetFlags(&currentFlags);
+  if(currentFlags & nsIPlaintextEditor::eEditorSkipSpellCheck)
+  {
+    currentFlags ^= nsIPlaintextEditor::eEditorSkipSpellCheck;
+    mEditor->SetFlags(currentFlags);
+  }
+}
+
--- a/editor/libeditor/base/nsEditorEventListener.h
+++ b/editor/libeditor/base/nsEditorEventListener.h
@@ -81,16 +81,18 @@ public:
   NS_IMETHOD HandleStartComposition(nsIDOMEvent* aCompositionEvent);
   NS_IMETHOD HandleEndComposition(nsIDOMEvent* aCompositionEvent);
   NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
   NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent) { return NS_OK; }
   NS_IMETHOD MouseClick(nsIDOMEvent* aMouseEvent);
   NS_IMETHOD Focus(nsIDOMEvent* aEvent);
   NS_IMETHOD Blur(nsIDOMEvent* aEvent);
 
+  void SpellCheckIfNeeded();
+
 protected:
   nsresult InstallToEditor();
   void UninstallFromEditor();
 
   bool CanDrop(nsIDOMDragEvent* aEvent);
   nsresult DragEnter(nsIDOMDragEvent* aDragEvent);
   nsresult DragOver(nsIDOMDragEvent* aDragEvent);
   nsresult DragExit(nsIDOMDragEvent* aDragEvent);
--- a/layout/reftests/editor/reftest.list
+++ b/layout/reftests/editor/reftest.list
@@ -37,17 +37,18 @@ fails-if(Android) != spellcheck-input-at
 == spellcheck-input-attr-dynamic-override-inherit.html spellcheck-input-nofocus-ref.html
 fails-if(Android) != spellcheck-input-attr-dynamic-override-inherit.html spellcheck-input-ref.html
 == spellcheck-input-property-dynamic-override.html spellcheck-input-nofocus-ref.html
 fails-if(Android) != spellcheck-input-property-dynamic-override.html spellcheck-input-ref.html
 == spellcheck-input-property-dynamic-override-inherit.html spellcheck-input-nofocus-ref.html
 fails-if(Android) != spellcheck-input-property-dynamic-override-inherit.html spellcheck-input-ref.html
 == spellcheck-textarea-attr.html spellcheck-textarea-nofocus-ref.html
 fails-if(Android) != spellcheck-textarea-attr.html spellcheck-textarea-ref.html
-== spellcheck-textarea-focused.html spellcheck-textarea-ref.html
+needs-focus == spellcheck-textarea-focused.html spellcheck-textarea-ref.html
+needs-focus == spellcheck-textarea-focused-reframe.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-nofocus.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-disabled.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-attr-inherit.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-attr-dynamic.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-attr-dynamic-inherit.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-property-dynamic.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-property-dynamic-inherit.html spellcheck-textarea-ref.html
 fails-if(Android) != spellcheck-textarea-attr-dynamic-override.html spellcheck-textarea-ref.html
copy from layout/reftests/editor/spellcheck-textarea-focused.html
copy to layout/reftests/editor/spellcheck-textarea-focused-reframe.html
--- a/layout/reftests/editor/spellcheck-textarea-focused.html
+++ b/layout/reftests/editor/spellcheck-textarea-focused-reframe.html
@@ -1,12 +1,17 @@
 <!DOCTYPE html>
 <html>
 <body>
 
-  <textarea id="testBox">blahblahblah</textarea>
+  <textarea id="testBox" onfocus="reframe(this);">blahblahblah</textarea>
   <script type="text/javascript">
+    function reframe(textbox) {
+      textbox.style.display = "none";
+      textbox.style.display = "";
+      textbox.clientWidth;
+    }
     //Adding focus to the textbox should trigger a spellcheck
     document.getElementById("testBox").focus();
   </script>
   
 </body>
-</html>
\ No newline at end of file
+</html>