mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1340483 - Part 4. Update input visibility accordingly. r=heycam
MozReview-Commit-ID: 7eBhj7w4qhP --HG-- extra : rebase_source : 3610353fbb4e8d4c1abed57536a0bab3a537b134
This commit is contained in:
parent
f50d5b5b45
commit
acabd05355
@ -2873,11 +2873,11 @@ HTMLInputElement::GetPlaceholderNode()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLInputElement::UpdatePlaceholderVisibility(bool aNotify)
|
||||
HTMLInputElement::UpdateOverlayTextVisibility(bool aNotify)
|
||||
{
|
||||
nsTextEditorState* state = GetEditorState();
|
||||
if (state) {
|
||||
state->UpdatePlaceholderVisibility(aNotify);
|
||||
state->UpdateOverlayTextVisibility(aNotify);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2949,6 +2949,17 @@ HTMLInputElement::IsPreviewEnabled()
|
||||
return mIsPreviewEnabled;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
HTMLInputElement::GetPreviewVisibility()
|
||||
{
|
||||
nsTextEditorState* state = GetEditorState();
|
||||
if (!state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return state->GetPreviewVisibility();
|
||||
}
|
||||
|
||||
void
|
||||
HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
|
||||
{
|
||||
|
@ -236,12 +236,13 @@ public:
|
||||
NS_IMETHOD_(Element*) GetPlaceholderNode() override;
|
||||
NS_IMETHOD_(Element*) CreatePreviewNode() override;
|
||||
NS_IMETHOD_(Element*) GetPreviewNode() override;
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) EnablePreview() override;
|
||||
NS_IMETHOD_(bool) IsPreviewEnabled() override;
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility() override;
|
||||
NS_IMETHOD_(bool) GetPreviewVisibility() override;
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners() override;
|
||||
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;
|
||||
virtual void GetValueFromSetRangeText(nsAString& aValue) override;
|
||||
|
@ -310,9 +310,9 @@ HTMLTextAreaElement::GetPlaceholderNode()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLTextAreaElement::UpdatePlaceholderVisibility(bool aNotify)
|
||||
HTMLTextAreaElement::UpdateOverlayTextVisibility(bool aNotify)
|
||||
{
|
||||
mState.UpdatePlaceholderVisibility(aNotify);
|
||||
mState.UpdateOverlayTextVisibility(aNotify);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
@ -364,6 +364,12 @@ HTMLTextAreaElement::IsPreviewEnabled()
|
||||
return mIsPreviewEnabled;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
HTMLTextAreaElement::GetPreviewVisibility()
|
||||
{
|
||||
return mState.GetPreviewVisibility();
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
|
||||
uint32_t aFlags)
|
||||
|
@ -105,8 +105,9 @@ public:
|
||||
NS_IMETHOD_(Element*) GetPlaceholderNode() override;
|
||||
NS_IMETHOD_(Element*) CreatePreviewNode() override;
|
||||
NS_IMETHOD_(Element*) GetPreviewNode() override;
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility() override;
|
||||
NS_IMETHOD_(bool) GetPreviewVisibility() override;
|
||||
NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) EnablePreview() override;
|
||||
|
@ -190,15 +190,20 @@ public:
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners() = 0;
|
||||
|
||||
/**
|
||||
* Update the placeholder visibility based on the element's state.
|
||||
* Update the visibility of both the placholder and preview text based on the element's state.
|
||||
*/
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) = 0;
|
||||
NS_IMETHOD_(void) UpdateOverlayTextVisibility(bool aNotify) = 0;
|
||||
|
||||
/**
|
||||
* Returns the current expected placeholder visibility state.
|
||||
*/
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility() = 0;
|
||||
|
||||
/**
|
||||
* Returns the current expected preview visibility state.
|
||||
*/
|
||||
NS_IMETHOD_(bool) GetPreviewVisibility() = 0;
|
||||
|
||||
/**
|
||||
* Callback called whenever the value is changed.
|
||||
*/
|
||||
|
@ -1067,6 +1067,7 @@ nsTextEditorState::nsTextEditorState(nsITextControlElement* aOwningElement)
|
||||
, mSelectionCached(true)
|
||||
, mSelectionRestoreEagerInit(false)
|
||||
, mPlaceholderVisibility(false)
|
||||
, mPreviewVisibility(false)
|
||||
, mIsCommittingComposition(false)
|
||||
// When adding more member variable initializations here, add the same
|
||||
// also to ::Construct.
|
||||
@ -1091,6 +1092,7 @@ nsTextEditorState::Construct(nsITextControlElement* aOwningElement,
|
||||
state->mSelectionCached = true;
|
||||
state->mSelectionRestoreEagerInit = false;
|
||||
state->mPlaceholderVisibility = false;
|
||||
state->mPreviewVisibility = false;
|
||||
state->mIsCommittingComposition = false;
|
||||
// When adding more member variable initializations here, add the same
|
||||
// also to the constructor.
|
||||
@ -2700,7 +2702,7 @@ nsTextEditorState::InitializeKeyboardEventListeners()
|
||||
void
|
||||
nsTextEditorState::ValueWasChanged(bool aNotify)
|
||||
{
|
||||
UpdatePlaceholderVisibility(aNotify);
|
||||
UpdateOverlayTextVisibility(aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2737,6 +2739,8 @@ nsTextEditorState::SetPreviewText(const nsAString& aValue, bool aNotify)
|
||||
nsContentUtils::RemoveNewlines(previewValue);
|
||||
MOZ_ASSERT(mPreviewDiv->GetFirstChild(), "preview div has no child");
|
||||
mPreviewDiv->GetFirstChild()->SetText(previewValue, aNotify);
|
||||
|
||||
UpdateOverlayTextVisibility(aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2754,12 +2758,14 @@ nsTextEditorState::GetPreviewText(nsAString& aValue)
|
||||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify)
|
||||
nsTextEditorState::UpdateOverlayTextVisibility(bool aNotify)
|
||||
{
|
||||
nsAutoString value;
|
||||
nsAutoString value, previewValue;
|
||||
GetValue(value, true);
|
||||
GetPreviewText(previewValue);
|
||||
|
||||
mPlaceholderVisibility = value.IsEmpty();
|
||||
mPreviewVisibility = value.IsEmpty() && !previewValue.IsEmpty();
|
||||
mPlaceholderVisibility = value.IsEmpty() && previewValue.IsEmpty();
|
||||
|
||||
if (mPlaceholderVisibility &&
|
||||
!Preferences::GetBool("dom.placeholder.show_on_focus", true)) {
|
||||
|
@ -218,17 +218,20 @@ public:
|
||||
return mTextCtrlElement->GetRows();
|
||||
}
|
||||
|
||||
void UpdateOverlayTextVisibility(bool aNotify);
|
||||
|
||||
// placeholder methods
|
||||
void UpdatePlaceholderVisibility(bool aNotify);
|
||||
bool GetPlaceholderVisibility() {
|
||||
return mPlaceholderVisibility;
|
||||
}
|
||||
|
||||
void UpdatePlaceholderText(bool aNotify);
|
||||
|
||||
// preview methods
|
||||
void SetPreviewText(const nsAString& aValue, bool aNotify);
|
||||
void GetPreviewText(nsAString& aValue);
|
||||
bool GetPreviewVisibility() {
|
||||
return mPreviewVisibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maxlength attribute
|
||||
@ -450,6 +453,7 @@ private:
|
||||
bool mSelectionCached; // Whether mSelectionProperties is valid
|
||||
mutable bool mSelectionRestoreEagerInit; // Whether we're eager initing because of selection restore
|
||||
bool mPlaceholderVisibility;
|
||||
bool mPreviewVisibility;
|
||||
bool mIsCommittingComposition;
|
||||
};
|
||||
|
||||
|
@ -364,7 +364,7 @@ nsTextControlFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
|
||||
// For textareas, UpdateValueDisplay doesn't initialize the visibility
|
||||
// status of the placeholder because it returns early, so we have to
|
||||
// do that manually here.
|
||||
txtCtrl->UpdatePlaceholderVisibility(true);
|
||||
txtCtrl->UpdateOverlayTextVisibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -656,7 +656,7 @@ void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint)
|
||||
// If 'dom.placeholeder.show_on_focus' preference is 'false', focusing or
|
||||
// blurring the frame can have an impact on the placeholder visibility.
|
||||
if (mUsePlaceholder) {
|
||||
txtCtrl->UpdatePlaceholderVisibility(true);
|
||||
txtCtrl->UpdateOverlayTextVisibility(true);
|
||||
}
|
||||
|
||||
if (!aOn) {
|
||||
@ -1183,7 +1183,7 @@ nsTextControlFrame::SetValueChanged(bool aValueChanged)
|
||||
|
||||
if (mUsePlaceholder) {
|
||||
AutoWeakFrame weakFrame(this);
|
||||
txtCtrl->UpdatePlaceholderVisibility(true);
|
||||
txtCtrl->UpdateOverlayTextVisibility(true);
|
||||
if (!weakFrame.IsAlive()) {
|
||||
return;
|
||||
}
|
||||
@ -1233,13 +1233,13 @@ nsTextControlFrame::UpdateValueDisplay(bool aNotify,
|
||||
txtCtrl->GetTextEditorValue(value, true);
|
||||
}
|
||||
|
||||
// Update the display of the placeholder value if needed.
|
||||
// We don't need to do this if we're about to initialize the
|
||||
// editor, since EnsureEditorInitialized takes care of this.
|
||||
if (mUsePlaceholder && !aBeforeEditorInit)
|
||||
// Update the display of the placeholder value and preview text if needed.
|
||||
// We don't need to do this if we're about to initialize the editor, since
|
||||
// EnsureEditorInitialized takes care of this.
|
||||
if ((mUsePlaceholder || mUsePreview) && !aBeforeEditorInit)
|
||||
{
|
||||
AutoWeakFrame weakFrame(this);
|
||||
txtCtrl->UpdatePlaceholderVisibility(aNotify);
|
||||
txtCtrl->UpdateOverlayTextVisibility(aNotify);
|
||||
NS_ENSURE_STATE(weakFrame.IsAlive());
|
||||
}
|
||||
|
||||
@ -1355,10 +1355,12 @@ nsTextControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
||||
nsDisplayListSet set(content, content, content, content, content, content);
|
||||
|
||||
while (kid) {
|
||||
// If the frame is the placeholder frame, we should only show it if the
|
||||
// placeholder has to be visible.
|
||||
if (kid->GetContent() != txtCtrl->GetPlaceholderNode() ||
|
||||
txtCtrl->GetPlaceholderVisibility()) {
|
||||
// If the frame is the placeholder or preview frame, we should only show
|
||||
// it if it has to be visible.
|
||||
if (!((kid->GetContent() == txtCtrl->GetPlaceholderNode() &&
|
||||
!txtCtrl->GetPlaceholderVisibility()) ||
|
||||
(kid->GetContent() == txtCtrl->GetPreviewNode() &&
|
||||
!txtCtrl->GetPreviewVisibility()))) {
|
||||
BuildDisplayListForChild(aBuilder, kid, aDirtyRect, set, 0);
|
||||
}
|
||||
kid = kid->GetNextSibling();
|
||||
|
Loading…
Reference in New Issue
Block a user