Bug 629172 - Fix the regression in switching the text input direction using Cmd/Ctrl+Shift+X; r=roc a=blocking-final+

--HG--
extra : rebase_source : 57471865db00c1efa07bb746df42de8278027b36
This commit is contained in:
Ehsan Akhgari 2011-01-27 00:26:33 -05:00
parent 25abf1251e
commit b1d2463ed9
5 changed files with 129 additions and 6 deletions

View File

@ -1124,6 +1124,18 @@ nsTextEditorState::BindToFrame(nsTextControlFrame* aFrame)
nsCOMPtr<nsIContent> content = do_QueryInterface(mTextCtrlElement);
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
// Set the correct direction on the newly created root node
PRUint32 flags;
rv = mEditor->GetFlags(&flags);
NS_ENSURE_SUCCESS(rv, rv);
if (flags & nsIPlaintextEditor::eEditorRightToLeft) {
rootNode->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("rtl"), PR_FALSE);
} else if (flags & nsIPlaintextEditor::eEditorLeftToRight) {
rootNode->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, NS_LITERAL_STRING("ltr"), PR_FALSE);
} else {
// otherwise, inherit the content node's direction
}
if (!nsContentUtils::AddScriptRunner(
new PrepareEditorEvent(*this, content, currentValue)))
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -71,6 +71,12 @@ interface nsIPlaintextEditor : nsISupports
// when this is set, the characters in password editor are always masked.
// see bug 530367 for the detail.
const long eEditorDontEchoPassword = 0x1000;
// when this flag is set, the internal direction of the editor is RTL.
// if neither of the direction flags are set, the direction is determined
// from the text control's content node.
const long eEditorRightToLeft = 0x2000;
// when this flag is set, the internal direction of the editor is LTR.
const long eEditorLeftToRight = 0x4000;
/*
* The valid values for newlines handling.

View File

@ -5175,17 +5175,40 @@ nsEditor::SwitchTextDirection()
nsIDOMElement *rootElement = GetRoot();
nsresult rv;
nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsIFrame *frame = content->GetPrimaryFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
// If we don't have an explicit direction, determine our direction
// from the content's direction
if (!(mFlags & (nsIPlaintextEditor::eEditorLeftToRight |
nsIPlaintextEditor::eEditorRightToLeft))) {
nsCOMPtr<nsIContent> content = do_QueryInterface(rootElement, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsIFrame* frame = content->GetPrimaryFrame();
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
// Set the flag here, to enable us to use the same code path below.
// It will be flipped before returning from the function.
if (frame->GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
} else {
mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
}
}
// Apply the opposite direction
if (frame->GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL)
if (mFlags & nsIPlaintextEditor::eEditorRightToLeft) {
NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorLeftToRight),
"Unexpected mutually exclusive flag");
mFlags &= ~nsIPlaintextEditor::eEditorRightToLeft;
mFlags |= nsIPlaintextEditor::eEditorLeftToRight;
rv = rootElement->SetAttribute(NS_LITERAL_STRING("dir"), NS_LITERAL_STRING("ltr"));
else
} else if (mFlags & nsIPlaintextEditor::eEditorLeftToRight) {
NS_ASSERTION(!(mFlags & nsIPlaintextEditor::eEditorRightToLeft),
"Unexpected mutually exclusive flag");
mFlags |= nsIPlaintextEditor::eEditorRightToLeft;
mFlags &= ~nsIPlaintextEditor::eEditorLeftToRight;
rv = rootElement->SetAttribute(NS_LITERAL_STRING("dir"), NS_LITERAL_STRING("rtl"));
}
return rv;
}

View File

@ -58,6 +58,7 @@ _TEST_FILES = \
test_bug603556.html \
test_bug604532.html \
test_bug625452.html \
test_bug629172.html \
$(NULL)
# disables the key handling test on gtk2 because gtk2 overrides some key events

View File

@ -0,0 +1,81 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=629172
-->
<head>
<title>Test for Bug 629172</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629172">Mozilla Bug 629172</a>
<p id="display"></p>
<div id="content">
<textarea id="ltr-ref" style="display: none">test.</textarea>
<textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 629172 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var LTRRef = document.getElementById("ltr-ref");
var RTLRef = document.getElementById("rtl-ref");
var Screenshots = {};
// generate the reference screenshots
LTRRef.style.display = "";
document.body.clientWidth;
Screenshots.ltr = snapshotWindow(window);
LTRRef.parentNode.removeChild(LTRRef);
RTLRef.style.display = "";
document.body.clientWidth;
Screenshots.rtl = snapshotWindow(window);
RTLRef.parentNode.removeChild(RTLRef);
Screenshots.get = function(dir, flip) {
if (flip) {
return this[dir == "rtl" ? "ltr" : "rtl"];
} else {
return this[dir];
}
};
function testDirection(initialDir) {
var t = document.createElement("textarea");
t.setAttribute("dir", initialDir);
t.value = "test.";
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();
synthesizeKey("x", {accelKey: true, shiftKey: true});
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();
synthesizeKey("x", {accelKey: true, shiftKey: true});
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);
}
testDirection("ltr");
testDirection("rtl");
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>