Bug 549208 - Dragging a text in an input/textarea element doesn't make the placeholder disappear; r=bzbarsky

This commit is contained in:
Mounir Lamouri
2010-03-01 10:35:40 -08:00
parent c149a6c400
commit d33d564829

View File

@@ -268,14 +268,9 @@ NS_INTERFACE_MAP_END
static PRBool
IsFocusedContent(nsIContent* aContent)
{
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm)
return PR_FALSE;
nsFocusManager* fm = nsFocusManager::GetFocusManager();
nsCOMPtr<nsIDOMElement> focusedElement;
fm->GetFocusedElement(getter_AddRefs(focusedElement));
nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
return (focusedContent == aContent);
return fm && fm->GetFocusedContent() == aContent;
}
NS_IMETHODIMP
@@ -1541,6 +1536,12 @@ nsTextControlFrame::InitEditor()
// Now restore the original editor flags.
rv = mEditor->SetFlags(editorFlags);
// By default the placeholder is shown,
// we should hide it if the default value is not empty.
nsWeakFrame weakFrame(this);
HidePlaceholder();
NS_ENSURE_STATE(weakFrame.IsAlive());
if (NS_FAILED(rv))
return rv;
}
@@ -2751,15 +2752,6 @@ nsTextControlFrame::SetValue(const nsAString& aValue)
editor->SetFlags(savedFlags);
if (selPriv)
selPriv->EndBatchChanges();
if (newValue.IsEmpty())
{
if (!IsFocusedContent(mContent))
ShowPlaceholder();
// else it's already hidden
}
else
HidePlaceholder();
}
NS_ENSURE_STATE(weakFrame.IsAlive());
@@ -2837,6 +2829,18 @@ nsTextControlFrame::IsScrollable() const
void
nsTextControlFrame::SetValueChanged(PRBool aValueChanged)
{
// placeholder management
if (!IsFocusedContent(mContent)) {
// If the content is focused, we don't care about the changes because
// the placeholder is going to be hide/show on blur.
nsAutoString valueString;
GetValue(valueString, PR_TRUE);
if (valueString.IsEmpty())
ShowPlaceholder();
else
HidePlaceholder();
}
nsCOMPtr<nsITextControlElement> elem = do_QueryInterface(mContent);
if (elem) {
elem->SetValueChanged(aValueChanged);