Bug 221820 - Part 5: Make lazy editor initialization compatible with placeholder values; r=bzbarsky

This commit is contained in:
Ehsan Akhgari 2010-04-06 16:43:39 -04:00
parent 82c0a0f238
commit d42f42731a
2 changed files with 35 additions and 12 deletions

View File

@ -1651,6 +1651,10 @@ nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
if (!aElements.AppendElement(mValueDiv))
return NS_ERROR_OUT_OF_MEMORY;
// Now create the placeholder anonymous content
rv = CreatePlaceholderDiv(aElements, doc->NodeInfoManager());
NS_ENSURE_SUCCESS(rv, rv);
rv = UpdateValueDisplay(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
@ -1704,10 +1708,6 @@ nsTextControlFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
}
}
// Now create the placeholder anonymous content
rv = CreatePlaceholderDiv(aElements, doc->NodeInfoManager());
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -2436,6 +2436,15 @@ nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aModType)
{
// First, check for the placeholder attribute, because it doesn't
// depend on the editor being present.
if (nsGkAtoms::placeholder == aAttribute)
{
nsWeakFrame weakFrame(this);
UpdatePlaceholderText(PR_TRUE);
NS_ENSURE_STATE(weakFrame.IsAlive());
}
if (!mEditor || !mSelCon)
return nsBoxFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);;
@ -2497,12 +2506,6 @@ nsTextControlFrame::AttributeChanged(PRInt32 aNameSpaceID,
}
mEditor->SetFlags(flags);
}
else if (nsGkAtoms::placeholder == aAttribute)
{
nsWeakFrame weakFrame(this);
UpdatePlaceholderText(PR_TRUE);
NS_ENSURE_STATE(weakFrame.IsAlive());
}
else if (!mUseEditor && nsGkAtoms::value == aAttribute) {
UpdateValueDisplay(PR_TRUE);
}
@ -2926,6 +2929,7 @@ nsTextControlFrame::UpdateValueDisplay(PRBool aNotify,
"Do not call this after editor has been initialized");
NS_ASSERTION(mValueDiv->GetChildCount() <= 1,
"Cannot have more than one child node");
NS_ASSERTION(mPlaceholderDiv, "A placeholder div must exist");
enum {
NO_NODE,
@ -2957,6 +2961,17 @@ nsTextControlFrame::UpdateValueDisplay(PRBool aNotify,
GetValue(value, PR_TRUE);
}
// Update the display of the placeholder value if needed.
{
nsWeakFrame weakFrame(this);
if (value.IsEmpty()) {
ShowPlaceholder();
} else {
HidePlaceholder();
}
NS_ENSURE_STATE(weakFrame.IsAlive());
}
if (aBeforeEditorInit && value.IsEmpty()) {
mValueDiv->RemoveChildAt(0, PR_TRUE, PR_FALSE);
return NS_OK;

View File

@ -72,7 +72,7 @@
function doTest() {
var t1 = $("t1");
var t2 = $("t2");
t1.value = "1";
setTextboxValue(t1, "1");
var t1Enabled = {};
var t1CanUndo = {};
t1.editor.canUndo(t1Enabled, t1CanUndo);
@ -80,7 +80,7 @@
"undo correctly enabled when placeholder was not changed through property");
t2.placeholder = "reallyempty";
t2.value = "2";
setTextboxValue(t2, "2");
var t2Enabled = {};
var t2CanUndo = {};
t2.editor.canUndo(t2Enabled, t2CanUndo);
@ -90,6 +90,14 @@
SimpleTest.finish();
}
function setTextboxValue(textbox, value) {
textbox.focus();
for (var i = 0; i < value.length; ++i) {
synthesizeKey(value.charAt(i), {});
}
textbox.blur();
}
SimpleTest.waitForFocus(doTest);
]]></script>