зеркало из https://github.com/mozilla/gecko-dev.git
Bug 809584 - Move the placeholder visibility logic to nsTextEditorState. r=ehsan
This commit is contained in:
Родитель
8644ce2020
Коммит
7e7986dbf9
|
@ -18,8 +18,8 @@ class nsTextControlFrame;
|
|||
|
||||
// IID for the nsITextControl interface
|
||||
#define NS_ITEXTCONTROLELEMENT_IID \
|
||||
{ 0x669bd7ca, 0x42af, 0x4f1e, \
|
||||
{ 0xa6, 0xe2, 0x86, 0xc4, 0x0a, 0x14, 0x73, 0x4e } }
|
||||
{ 0x3dd53b59, 0x9d8f, 0x40a3, \
|
||||
{ 0x81, 0xd7, 0xb3, 0x43, 0xa0, 0x51, 0xfc, 0xb5 } }
|
||||
|
||||
/**
|
||||
* This interface is used for the text control frame to get the editor and
|
||||
|
@ -151,9 +151,9 @@ public:
|
|||
NS_IMETHOD_(void) InitializeKeyboardEventListeners() = 0;
|
||||
|
||||
/**
|
||||
* Show/hide the placeholder for the control.
|
||||
* Update the placeholder visibility based on the element's state.
|
||||
*/
|
||||
NS_IMETHOD_(void) SetPlaceholderVisibility(bool aVisible, bool aNotify) = 0;
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) = 0;
|
||||
|
||||
/**
|
||||
* Returns the current expected placeholder visibility state.
|
||||
|
|
|
@ -1474,11 +1474,11 @@ nsHTMLInputElement::GetPlaceholderNode()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsHTMLInputElement::SetPlaceholderVisibility(bool aVisible, bool aNotify)
|
||||
nsHTMLInputElement::UpdatePlaceholderVisibility(bool aNotify)
|
||||
{
|
||||
nsTextEditorState *state = GetEditorState();
|
||||
if (state) {
|
||||
state->SetPlaceholderVisibility(aVisible, aNotify);
|
||||
state->UpdatePlaceholderVisibility(aNotify);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public:
|
|||
NS_IMETHOD_(nsIContent*) GetRootEditorNode();
|
||||
NS_IMETHOD_(nsIContent*) CreatePlaceholderNode();
|
||||
NS_IMETHOD_(nsIContent*) GetPlaceholderNode();
|
||||
NS_IMETHOD_(void) SetPlaceholderVisibility(bool aVisible, bool aNotify);
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify);
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility();
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners();
|
||||
NS_IMETHOD_(void) OnValueChanged(bool aNotify);
|
||||
|
|
|
@ -122,7 +122,7 @@ public:
|
|||
NS_IMETHOD_(nsIContent*) GetRootEditorNode();
|
||||
NS_IMETHOD_(nsIContent*) CreatePlaceholderNode();
|
||||
NS_IMETHOD_(nsIContent*) GetPlaceholderNode();
|
||||
NS_IMETHOD_(void) SetPlaceholderVisibility(bool aVisible, bool aNotify);
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify);
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility();
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners();
|
||||
NS_IMETHOD_(void) OnValueChanged(bool aNotify);
|
||||
|
@ -514,9 +514,9 @@ nsHTMLTextAreaElement::GetPlaceholderNode()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsHTMLTextAreaElement::SetPlaceholderVisibility(bool aVisible, bool aNotify)
|
||||
nsHTMLTextAreaElement::UpdatePlaceholderVisibility(bool aNotify)
|
||||
{
|
||||
mState.SetPlaceholderVisibility(aVisible, aNotify);
|
||||
mState.UpdatePlaceholderVisibility(aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
|
|
|
@ -1968,9 +1968,7 @@ nsTextEditorState::ValueWasChanged(bool aNotify)
|
|||
return;
|
||||
}
|
||||
|
||||
nsAutoString valueString;
|
||||
GetValue(valueString, true);
|
||||
SetPlaceholderVisibility(valueString.IsEmpty(), aNotify);
|
||||
UpdatePlaceholderVisibility(aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1994,13 +1992,15 @@ nsTextEditorState::UpdatePlaceholderText(bool aNotify)
|
|||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::SetPlaceholderVisibility(bool aVisible,
|
||||
bool aNotify)
|
||||
nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify)
|
||||
{
|
||||
NS_ASSERTION(mPlaceholderDiv, "This function should not be called if "
|
||||
"mPlaceholderDiv isn't set");
|
||||
|
||||
mPlaceholderVisibility = aVisible;
|
||||
nsAutoString value;
|
||||
GetValue(value, true);
|
||||
|
||||
mPlaceholderVisibility = value.IsEmpty();
|
||||
|
||||
if (mBoundFrame && aNotify) {
|
||||
mBoundFrame->InvalidateFrame();
|
||||
|
|
|
@ -174,7 +174,7 @@ public:
|
|||
}
|
||||
|
||||
// placeholder methods
|
||||
void SetPlaceholderVisibility(bool aVisible, bool aNotify);
|
||||
void UpdatePlaceholderVisibility(bool aNotify);
|
||||
bool GetPlaceholderVisibility() {
|
||||
return mPlaceholderVisibility;
|
||||
}
|
||||
|
|
|
@ -1313,11 +1313,8 @@ nsTextControlFrame::SetValueChanged(bool aValueChanged)
|
|||
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
||||
|
||||
if (mUsePlaceholder) {
|
||||
int32_t textLength;
|
||||
GetTextLength(&textLength);
|
||||
|
||||
nsWeakFrame weakFrame(this);
|
||||
txtCtrl->SetPlaceholderVisibility(!textLength, true);
|
||||
txtCtrl->UpdatePlaceholderVisibility(true);
|
||||
if (!weakFrame.IsAlive()) {
|
||||
return;
|
||||
}
|
||||
|
@ -1375,7 +1372,7 @@ nsTextControlFrame::UpdateValueDisplay(bool aNotify,
|
|||
if (mUsePlaceholder && !aBeforeEditorInit)
|
||||
{
|
||||
nsWeakFrame weakFrame(this);
|
||||
txtCtrl->SetPlaceholderVisibility(value.IsEmpty(), aNotify);
|
||||
txtCtrl->UpdatePlaceholderVisibility(aNotify);
|
||||
NS_ENSURE_STATE(weakFrame.IsAlive());
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче