Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 809584 - Move the placeholder visibility logic to nsTextEditorSta…
Browse files Browse the repository at this point in the history
…te. r=ehsan
  • Loading branch information
mounirlamouri committed Nov 9, 2012
1 parent 4370a1c commit 7afe5c8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
8 changes: 4 additions & 4 deletions content/html/content/public/nsITextControlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -151,9 +151,9 @@ class nsITextControlElement : public nsISupports {
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.
Expand Down
4 changes: 2 additions & 2 deletions content/html/content/src/nsHTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/html/content/src/nsHTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class nsHTMLInputElement : public nsGenericHTMLFormElement,
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);
Expand Down
6 changes: 3 additions & 3 deletions content/html/content/src/nsHTMLTextAreaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class nsHTMLTextAreaElement : public nsGenericHTMLFormElement,
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);
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions content/html/content/src/nsTextEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1968,9 +1968,7 @@ nsTextEditorState::ValueWasChanged(bool aNotify)
return;
}

nsAutoString valueString;
GetValue(valueString, true);
SetPlaceholderVisibility(valueString.IsEmpty(), aNotify);
UpdatePlaceholderVisibility(aNotify);
}

void
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion content/html/content/src/nsTextEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class nsTextEditorState : public mozilla::SupportsWeakPtr<nsTextEditorState> {
}

// placeholder methods
void SetPlaceholderVisibility(bool aVisible, bool aNotify);
void UpdatePlaceholderVisibility(bool aNotify);
bool GetPlaceholderVisibility() {
return mPlaceholderVisibility;
}
Expand Down
7 changes: 2 additions & 5 deletions layout/forms/nsTextControlFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit 7afe5c8

Please sign in to comment.