Bug 675579 - Part 2: Dispatch an input event when changing the direction of a plain text element; r=roc

--HG--
extra : rebase_source : 06eb0f2fa67ca81e214df8800ceec8dc305ee7c6
This commit is contained in:
Ehsan Akhgari 2014-01-17 10:31:18 -05:00
parent bdb1d7b375
commit 381fac62ca
3 changed files with 23 additions and 2 deletions

View File

@ -1851,6 +1851,12 @@ void nsEditor::NotifyEditorObservers(void)
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
@ -5064,6 +5070,10 @@ nsEditor::SwitchTextDirection()
rv = rootElement->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), true);
}
if (NS_SUCCEEDED(rv)) {
FireInputEvent();
}
return rv;
}
@ -5083,14 +5093,18 @@ nsEditor::SwitchTextDirectionTo(uint32_t aDirection)
"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();
}
}

View File

@ -251,6 +251,7 @@ public:
protected:
nsresult DetermineCurrentDirection();
void FireInputEvent();
/** create a transaction for setting aAttribute to aValue on aElement
*/

View File

@ -48,20 +48,26 @@ SimpleTest.waitForFocus(function() {
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);