Bug 675579 - Part 2: Dispatch an input event when changing the direction of a plain text element; r=roc
☠☠ backed out by f5efef8989a5 ☠ ☠
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Fri, 17 Jan 2014 08:51:43 -0500
changeset 163946 54ddff6ebfa5da5bdea7d14520d49e187f696833
parent 163945 e9d82d8ad687eb5854d8dd51e8c12b377c7f3b6b
child 163947 b9757c55e79b9c917b760fe76b5156179872926e
push id38587
push usereakhgari@mozilla.com
push dateFri, 17 Jan 2014 13:51:49 +0000
treeherdermozilla-inbound@54ddff6ebfa5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs675579
milestone29.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 675579 - Part 2: Dispatch an input event when changing the direction of a plain text element; r=roc
editor/libeditor/base/nsEditor.cpp
editor/libeditor/base/nsEditor.h
editor/libeditor/text/tests/test_bug629172.html
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -1846,16 +1846,22 @@ void nsEditor::NotifyEditorObservers(voi
   for (int32_t i = 0; i < mEditorObservers.Count(); i++) {
     mEditorObservers[i]->EditAction();
   }
 
   if (!mDispatchInputEvent) {
     return;
   }
 
+  FireInputEvent();
+}
+
+void
+nsEditor::FireInputEvent()
+{
   // We don't need to dispatch multiple input events if there is a pending
   // input event.  However, it may have different event target.  If we resolved
   // this issue, we need to manage the pending events in an array.  But it's
   // overwork.  We don't need to do it for the very rare case.
 
   nsCOMPtr<nsIContent> target = GetInputEventTargetContent();
   NS_ENSURE_TRUE_VOID(target);
 
@@ -5059,16 +5065,20 @@ nsEditor::SwitchTextDirection()
   } else if (mFlags & nsIPlaintextEditor::eEditorLeftToRight) {
     NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorRightToLeft),
                  "Unexpected mutually exclusive flag");
     mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
     mFlags &= ~nsIPlaintextEditor::eEditorLeftToRight;
     rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
   }
 
+  if (NS_SUCCEEDED(rv)) {
+    FireInputEvent();
+  }
+
   return rv;
 }
 
 void
 nsEditor::SwitchTextDirectionTo(uint32_t aDirection)
 {
   // Get the current root direction from its frame
   nsIContent* rootElement = GetExposedRoot();
@@ -5078,24 +5088,28 @@ nsEditor::SwitchTextDirectionTo(uint32_t
 
   // Apply the requested direction
   if (aDirection == nsIPlaintextEditor::eEditorLeftToRight &&
       (mFlags & nsIPlaintextEditor::eEditorRightToLeft)) {
     NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorLeftToRight),
                  "Unexpected mutually exclusive flag");
     mFlags &= ~nsIPlaintextEditor::eEditorRightToLeft;
     mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
-    rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("ltr"), true);
+    rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("ltr"), true);
   } else if (aDirection == nsIPlaintextEditor::eEditorRightToLeft &&
              (mFlags & nsIPlaintextEditor::eEditorLeftToRight)) {
     NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorRightToLeft),
                  "Unexpected mutually exclusive flag");
     mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
     mFlags &= ~nsIPlaintextEditor::eEditorLeftToRight;
-    rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
+    rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
+  }
+
+  if (NS_SUCCEEDED(rv)) {
+    FireInputEvent();
   }
 }
 
 #if DEBUG_JOE
 void
 nsEditor::DumpNode(nsIDOMNode *aNode, int32_t indent)
 {
   int32_t i;
--- a/editor/libeditor/base/nsEditor.h
+++ b/editor/libeditor/base/nsEditor.h
@@ -246,16 +246,17 @@ public:
   virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,
                                         nsIPrivateTextRangeList *aTextRange)=0;
   void EndIMEComposition();
 
   void SwitchTextDirectionTo(uint32_t aDirection);
 
 protected:
   nsresult DetermineCurrentDirection();
+  void FireInputEvent();
 
   /** create a transaction for setting aAttribute to aValue on aElement
     */
   NS_IMETHOD CreateTxnForSetAttribute(mozilla::dom::Element *aElement,
                                       const nsAString &  aAttribute,
                                       const nsAString &  aValue,
                                       ChangeAttributeTxn ** aTxn);
 
--- a/editor/libeditor/text/tests/test_bug629172.html
+++ b/editor/libeditor/text/tests/test_bug629172.html
@@ -43,30 +43,36 @@ SimpleTest.waitForFocus(function() {
       return this[dir];
     }
   };
 
   function testDirection(initialDir) {
     var t = document.createElement("textarea");
     t.setAttribute("dir", initialDir);
     t.value = "test.";
+    var inputEventCount = 0;
+    t.oninput = function() { inputEventCount++; };
     document.getElementById("content").appendChild(t);
     document.body.clientWidth;
     var s1 = snapshotWindow(window);
     ok(compareSnapshots(s1, Screenshots.get(initialDir, false), true)[0],
        "Textarea should appear correctly before switching the direction (" + initialDir + ")");
     t.focus();
+    is(inputEventCount, 0, "input event count must be 0 before");
     synthesizeKey("x", {accelKey: true, shiftKey: true});
     is(t.getAttribute("dir"), initialDir == "ltr" ? "rtl" : "ltr", "The dir attribute must be correctly updated");
+    is(inputEventCount, 1, "input event count must be 1 after");
     t.blur();
     var s2 = snapshotWindow(window);
     ok(compareSnapshots(s2, Screenshots.get(initialDir, true), true)[0],
        "Textarea should appear correctly after switching the direction (" + initialDir + ")");
     t.focus();
+    is(inputEventCount, 1, "input event count must be 1 before");
     synthesizeKey("x", {accelKey: true, shiftKey: true});
+    is(inputEventCount, 2, "input event count must be 2 after");
     is(t.getAttribute("dir"), initialDir == "ltr" ? "ltr" : "rtl", "The dir attribute must be correctly updated");
     t.blur();
     var s3 = snapshotWindow(window);
     ok(compareSnapshots(s3, Screenshots.get(initialDir, false), true)[0],
        "Textarea should appear correctly after switching back the direction (" + initialDir + ")");
     t.parentNode.removeChild(t);
   }