mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1340483 - Part 2. Expose chrome-only previewValue attribute. r=baku,heycam
MozReview-Commit-ID: BCu0vXVm6wj --HG-- extra : rebase_source : 22d67ab3824c0df53daf3e3299a45c17746f62a3
This commit is contained in:
parent
c444b0fb87
commit
903f54b822
@ -2912,6 +2912,24 @@ HTMLInputElement::GetPreviewNode()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLInputElement::SetPreviewValue(const nsAString& aValue)
|
||||
{
|
||||
nsTextEditorState* state = GetEditorState();
|
||||
if (state) {
|
||||
state->SetPreviewText(aValue, true);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLInputElement::GetPreviewValue(nsAString& aValue)
|
||||
{
|
||||
nsTextEditorState* state = GetEditorState();
|
||||
if (state) {
|
||||
state->GetPreviewText(aValue);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
|
||||
{
|
||||
|
@ -237,6 +237,8 @@ public:
|
||||
NS_IMETHOD_(Element*) CreatePreviewNode() override;
|
||||
NS_IMETHOD_(Element*) GetPreviewNode() override;
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override;
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility() override;
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners() override;
|
||||
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;
|
||||
|
@ -333,6 +333,17 @@ HTMLTextAreaElement::GetPreviewNode()
|
||||
return mState.GetPreviewNode();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLTextAreaElement::SetPreviewValue(const nsAString& aValue)
|
||||
{
|
||||
mState.SetPreviewText(aValue, true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
HTMLTextAreaElement::GetPreviewValue(nsAString& aValue)
|
||||
{
|
||||
mState.GetPreviewText(aValue);
|
||||
}
|
||||
|
||||
nsresult
|
||||
HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
|
||||
|
@ -107,6 +107,8 @@ public:
|
||||
NS_IMETHOD_(Element*) GetPreviewNode() override;
|
||||
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
|
||||
NS_IMETHOD_(bool) GetPlaceholderVisibility() override;
|
||||
NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) override;
|
||||
NS_IMETHOD_(void) InitializeKeyboardEventListeners() override;
|
||||
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;
|
||||
virtual void GetValueFromSetRangeText(nsAString& aValue) override;
|
||||
|
@ -164,6 +164,16 @@ public:
|
||||
*/
|
||||
NS_IMETHOD_(mozilla::dom::Element*) GetPreviewNode() = 0;
|
||||
|
||||
/**
|
||||
* Update preview value for the text control.
|
||||
*/
|
||||
NS_IMETHOD_(void) SetPreviewValue(const nsAString& aValue) = 0;
|
||||
|
||||
/**
|
||||
* Get the current preview value for text control.
|
||||
*/
|
||||
NS_IMETHOD_(void) GetPreviewValue(nsAString& aValue) = 0;
|
||||
|
||||
/**
|
||||
* Initialize the keyboard event listeners.
|
||||
*/
|
||||
|
@ -2722,6 +2722,37 @@ nsTextEditorState::UpdatePlaceholderText(bool aNotify)
|
||||
mPlaceholderDiv->GetFirstChild()->SetText(placeholderValue, aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::SetPreviewText(const nsAString& aValue, bool aNotify)
|
||||
{
|
||||
MOZ_ASSERT(mPreviewDiv, "This function should not be called if "
|
||||
"mPreviewDiv isn't set");
|
||||
|
||||
// If we don't have a preview div, there's nothing to do.
|
||||
if (!mPreviewDiv)
|
||||
return;
|
||||
|
||||
nsAutoString previewValue(aValue);
|
||||
|
||||
nsContentUtils::RemoveNewlines(previewValue);
|
||||
MOZ_ASSERT(mPreviewDiv->GetFirstChild(), "preview div has no child");
|
||||
mPreviewDiv->GetFirstChild()->SetText(previewValue, aNotify);
|
||||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::GetPreviewText(nsAString& aValue)
|
||||
{
|
||||
// If we don't have a preview div, there's nothing to do.
|
||||
if (!mPreviewDiv)
|
||||
return;
|
||||
|
||||
MOZ_ASSERT(mPreviewDiv->GetFirstChild(), "preview div has no child");
|
||||
const nsTextFragment *text = mPreviewDiv->GetFirstChild()->GetText();
|
||||
|
||||
aValue.Truncate();
|
||||
text->AppendTo(aValue);
|
||||
}
|
||||
|
||||
void
|
||||
nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify)
|
||||
{
|
||||
|
@ -223,8 +223,13 @@ public:
|
||||
bool GetPlaceholderVisibility() {
|
||||
return mPlaceholderVisibility;
|
||||
}
|
||||
|
||||
void UpdatePlaceholderText(bool aNotify);
|
||||
|
||||
// preview methods
|
||||
void SetPreviewText(const nsAString& aValue, bool aNotify);
|
||||
void GetPreviewText(nsAString& aValue);
|
||||
|
||||
/**
|
||||
* Get the maxlength attribute
|
||||
* @param aMaxLength the value of the max length attr
|
||||
|
@ -265,3 +265,8 @@ partial interface HTMLInputElement {
|
||||
[Pref="dom.forms.datetime", Func="IsChromeOrXBL"]
|
||||
void setFocusState(boolean aIsFocused);
|
||||
};
|
||||
|
||||
partial interface HTMLInputElement {
|
||||
[ChromeOnly]
|
||||
attribute DOMString previewValue;
|
||||
};
|
||||
|
@ -98,3 +98,8 @@ partial interface HTMLTextAreaElement {
|
||||
[ChromeOnly]
|
||||
void setUserInput(DOMString input);
|
||||
};
|
||||
|
||||
partial interface HTMLTextAreaElement {
|
||||
[ChromeOnly]
|
||||
attribute DOMString previewValue;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user