Bug 1360154 - Part 2. Add fast path to check whether valus is emtpy. r=masayuki

Actually, we use GetValue to check whether value is empty or not for placeholder.  But since GetValue uses TextEditor::OutputToString when on editor, it is expensive.  Since editor has DocumentIsEmpty method, we should use it for this case.

MozReview-Commit-ID: rQX8yjnWQz

--HG--
extra : rebase_source : 25ec89385d704f5c4d2d0a15021c2a59b0201983
This commit is contained in:
Makoto Kato 2017-05-11 14:04:18 +09:00
Родитель 353b47086e
Коммит 66f56b4e7d
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -2682,6 +2682,23 @@ nsTextEditorState::SetValue(const nsAString& aValue, uint32_t aFlags)
return true;
}
bool
nsTextEditorState::HasNonEmptyValue()
{
if (mEditor && mBoundFrame && mEditorInitialized &&
!mIsCommittingComposition) {
bool empty;
nsresult rv = mEditor->GetDocumentIsEmpty(&empty);
if (NS_SUCCEEDED(rv)) {
return !empty;
}
}
nsAutoString value;
GetValue(value, true);
return !value.IsEmpty();
}
void
nsTextEditorState::InitializeKeyboardEventListeners()
{
@ -2765,11 +2782,11 @@ void
nsTextEditorState::UpdateOverlayTextVisibility(bool aNotify)
{
nsAutoString value, previewValue;
GetValue(value, true);
bool valueIsEmpty = !HasNonEmptyValue();
GetPreviewText(previewValue);
mPreviewVisibility = value.IsEmpty() && !previewValue.IsEmpty();
mPlaceholderVisibility = value.IsEmpty() && previewValue.IsEmpty();
mPreviewVisibility = valueIsEmpty && !previewValue.IsEmpty();
mPlaceholderVisibility = valueIsEmpty && previewValue.IsEmpty();
if (mPlaceholderVisibility &&
!Preferences::GetBool("dom.placeholder.show_on_focus", true)) {

Просмотреть файл

@ -181,6 +181,11 @@ public:
};
MOZ_MUST_USE bool SetValue(const nsAString& aValue, uint32_t aFlags);
void GetValue(nsAString& aValue, bool aIgnoreWrap) const;
bool HasNonEmptyValue();
// The following methods are for textarea element to use whether default
// value or not.
// XXX We might have to add assertion when it is into editable,
// or reconsider fixing bug 597525 to remove these.
void EmptyValue() { if (mValue) mValue->Truncate(); }
bool IsEmpty() const { return mValue ? mValue->IsEmpty() : true; }