Bug 1340483 - Part 2. Expose chrome-only previewValue attribute. r=baku,heycam

MozReview-Commit-ID: BCu0vXVm6wj
This commit is contained in:
Ray Lin
2017-03-21 00:08:01 +08:00
parent 78ff382026
commit f4d11417f9
9 changed files with 89 additions and 0 deletions

View File

@@ -2912,6 +2912,24 @@ HTMLInputElement::GetPreviewNode()
return nullptr; 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 void
HTMLInputElement::GetDisplayFileName(nsAString& aValue) const HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
{ {

View File

@@ -237,6 +237,8 @@ public:
NS_IMETHOD_(Element*) CreatePreviewNode() override; NS_IMETHOD_(Element*) CreatePreviewNode() override;
NS_IMETHOD_(Element*) GetPreviewNode() override; NS_IMETHOD_(Element*) GetPreviewNode() override;
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) 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_(bool) GetPlaceholderVisibility() override;
NS_IMETHOD_(void) InitializeKeyboardEventListeners() override; NS_IMETHOD_(void) InitializeKeyboardEventListeners() override;
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override; NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;

View File

@@ -333,6 +333,17 @@ HTMLTextAreaElement::GetPreviewNode()
return mState.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 nsresult
HTMLTextAreaElement::SetValueInternal(const nsAString& aValue, HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,

View File

@@ -107,6 +107,8 @@ public:
NS_IMETHOD_(Element*) GetPreviewNode() override; NS_IMETHOD_(Element*) GetPreviewNode() override;
NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override; NS_IMETHOD_(void) UpdatePlaceholderVisibility(bool aNotify) override;
NS_IMETHOD_(bool) GetPlaceholderVisibility() 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) InitializeKeyboardEventListeners() override;
NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override; NS_IMETHOD_(void) OnValueChanged(bool aNotify, bool aWasInteractiveUserChange) override;
virtual void GetValueFromSetRangeText(nsAString& aValue) override; virtual void GetValueFromSetRangeText(nsAString& aValue) override;

View File

@@ -164,6 +164,16 @@ public:
*/ */
NS_IMETHOD_(mozilla::dom::Element*) GetPreviewNode() = 0; 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. * Initialize the keyboard event listeners.
*/ */

View File

@@ -2722,6 +2722,37 @@ nsTextEditorState::UpdatePlaceholderText(bool aNotify)
mPlaceholderDiv->GetFirstChild()->SetText(placeholderValue, 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 void
nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify) nsTextEditorState::UpdatePlaceholderVisibility(bool aNotify)
{ {

View File

@@ -223,8 +223,13 @@ public:
bool GetPlaceholderVisibility() { bool GetPlaceholderVisibility() {
return mPlaceholderVisibility; return mPlaceholderVisibility;
} }
void UpdatePlaceholderText(bool aNotify); void UpdatePlaceholderText(bool aNotify);
// preview methods
void SetPreviewText(const nsAString& aValue, bool aNotify);
void GetPreviewText(nsAString& aValue);
/** /**
* Get the maxlength attribute * Get the maxlength attribute
* @param aMaxLength the value of the max length attr * @param aMaxLength the value of the max length attr

View File

@@ -265,3 +265,8 @@ partial interface HTMLInputElement {
[Pref="dom.forms.datetime", Func="IsChromeOrXBL"] [Pref="dom.forms.datetime", Func="IsChromeOrXBL"]
void setFocusState(boolean aIsFocused); void setFocusState(boolean aIsFocused);
}; };
partial interface HTMLInputElement {
[ChromeOnly]
attribute DOMString previewValue;
};

View File

@@ -98,3 +98,8 @@ partial interface HTMLTextAreaElement {
[ChromeOnly] [ChromeOnly]
void setUserInput(DOMString input); void setUserInput(DOMString input);
}; };
partial interface HTMLTextAreaElement {
[ChromeOnly]
attribute DOMString previewValue;
};