Bug 1681240 - Make TextControlState::SetValueFlags an enum class r=saschanaz

Using integer as a bit field may cause simple mistake and may not be easy
to read, and we have `EnumSet` class which can treat an `enum class` as
a bit flags so that we should make it an `enum class` and use it with the
`EnumSet` class.

Differential Revision: https://phabricator.services.mozilla.com/D99172
This commit is contained in:
Masayuki Nakano
2020-12-09 23:34:28 +00:00
parent 29715b8fd2
commit fbba4fb0ed
9 changed files with 198 additions and 148 deletions

View File

@@ -120,8 +120,12 @@ nsresult HTMLTextAreaElement::Clone(dom::NodeInfo* aNodeInfo,
GetValueInternal(value, true);
// SetValueInternal handles setting mValueChanged for us
rv = it->SetValueInternal(value, TextControlState::eSetValue_Notify);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_WARN_IF(NS_FAILED(
rv = it->SetValueInternal(
value, ValueSetterOption::
UpdateOverlayTextVisibilityAndInvalidateFrame)))) {
return rv;
}
}
it->mLastValueChangeWasInteractive = mLastValueChangeWasInteractive;
@@ -270,19 +274,20 @@ bool HTMLTextAreaElement::GetPreviewVisibility() {
return mState->GetPreviewVisibility();
}
nsresult HTMLTextAreaElement::SetValueInternal(const nsAString& aValue,
uint32_t aFlags) {
nsresult HTMLTextAreaElement::SetValueInternal(
const nsAString& aValue, const ValueSetterOptions& aOptions) {
MOZ_ASSERT(mState);
// Need to set the value changed flag here if our value has in fact changed
// (i.e. if eSetValue_Notify is in aFlags), so that
// nsTextControlFrame::UpdateValueDisplay retrieves the correct value if
// needed.
if (aFlags & TextControlState::eSetValue_Notify) {
// (i.e. if ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame
// is in aOptions), so that nsTextControlFrame::UpdateValueDisplay retrieves
// the correct value if needed.
if (aOptions.contains(
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame)) {
SetValueChanged(true);
}
if (!mState->SetValue(aValue, aFlags)) {
if (!mState->SetValue(aValue, aOptions)) {
return NS_ERROR_OUT_OF_MEMORY;
}
@@ -302,9 +307,9 @@ void HTMLTextAreaElement::SetValue(const nsAString& aValue,
GetValueInternal(currentValue, true);
nsresult rv = SetValueInternal(
aValue, TextControlState::eSetValue_ByContent |
TextControlState::eSetValue_Notify |
TextControlState::eSetValue_MoveCursorToEndIfValueChanged);
aValue, {ValueSetterOption::ByContentAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame,
ValueSetterOption::MoveCursorToEndIfValueChanged});
if (NS_WARN_IF(NS_FAILED(rv))) {
aError.Throw(rv);
return;
@@ -318,9 +323,9 @@ void HTMLTextAreaElement::SetValue(const nsAString& aValue,
void HTMLTextAreaElement::SetUserInput(const nsAString& aValue,
nsIPrincipal& aSubjectPrincipal) {
SetValueInternal(
aValue, TextControlState::eSetValue_BySetUserInput |
TextControlState::eSetValue_Notify |
TextControlState::eSetValue_MoveCursorToEndIfValueChanged);
aValue, {ValueSetterOption::BySetUserInputAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame,
ValueSetterOption::MoveCursorToEndIfValueChanged});
}
nsresult HTMLTextAreaElement::SetValueChanged(bool aValueChanged) {
@@ -655,8 +660,10 @@ void HTMLTextAreaElement::GetValueFromSetRangeText(nsAString& aValue) {
nsresult HTMLTextAreaElement::SetValueFromSetRangeText(
const nsAString& aValue) {
return SetValueInternal(aValue, TextControlState::eSetValue_ByContent |
TextControlState::eSetValue_Notify);
return SetValueInternal(
aValue,
{ValueSetterOption::ByContentAPI,
ValueSetterOption::UpdateOverlayTextVisibilityAndInvalidateFrame});
}
nsresult HTMLTextAreaElement::Reset() {
@@ -664,8 +671,7 @@ nsresult HTMLTextAreaElement::Reset() {
GetDefaultValue(resetVal, IgnoreErrors());
SetValueChanged(false);
nsresult rv =
SetValueInternal(resetVal, TextControlState::eSetValue_Internal);
nsresult rv = SetValueInternal(resetVal, ValueSetterOption::ByInternalAPI);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;