Bug 1386582, create element state objects only if needed, r=ehsan

This commit is contained in:
Olli Pettay
2017-08-02 22:28:48 +03:00
parent 1fc9ce2714
commit 626438c592
2 changed files with 35 additions and 20 deletions

View File

@@ -6410,18 +6410,30 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
NS_IMETHODIMP
HTMLInputElement::SaveState()
{
RefPtr<HTMLInputElementState> inputState;
nsPresState* state = nullptr;
switch (GetValueMode()) {
case VALUE_MODE_DEFAULT_ON:
if (mCheckedChanged) {
inputState = new HTMLInputElementState();
state = GetPrimaryPresState();
if (!state) {
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
inputState->SetChecked(mChecked);
state->SetStateProperty(inputState);
}
break;
case VALUE_MODE_FILENAME:
if (!mFileData->mFilesOrDirectories.IsEmpty()) {
inputState = new HTMLInputElementState();
state = GetPrimaryPresState();
if (!state) {
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
inputState->SetFilesOrDirectories(mFileData->mFilesOrDirectories);
state->SetStateProperty(inputState);
}
break;
case VALUE_MODE_VALUE:
@@ -6434,7 +6446,12 @@ HTMLInputElement::SaveState()
break;
}
inputState = new HTMLInputElementState();
state = GetPrimaryPresState();
if (!state) {
return NS_OK;
}
RefPtr<HTMLInputElementState> inputState = new HTMLInputElementState();
nsAutoString value;
GetValue(value, CallerType::System);
@@ -6451,18 +6468,14 @@ HTMLInputElement::SaveState()
}
inputState->SetValue(value);
state->SetStateProperty(inputState);
break;
}
if (inputState) {
nsPresState* state = GetPrimaryPresState();
if (state) {
state->SetStateProperty(inputState);
}
}
if (mDisabledChanged) {
nsPresState* state = GetPrimaryPresState();
if (!state) {
state = GetPrimaryPresState();
}
if (state) {
// We do not want to save the real disabled state but the disabled
// attribute.