Refactoring: Introduce a class to represent restoring state of a form control
https://bugs.webkit.org/show_bug.cgi?id=89412
Reviewed by Hajime Morita.
HTMLFormControlElementWithState::saveFormControlState had two return
values; One is a boolean to represent whether we should save the state
or not, and another is form control value. This patch introduces
FormControlState class representing these values.
We're going to extend FormControlState class so that it can contain
multiple strings to fix a FileInputType issue and it have another type
to fix Bug 89409.
No new tests. Just a refactoring.
* html/FormController.cpp:
(WebCore::FormController::formElementsState):
Gets a state string from a FormControlState instance.
(WebCore::FormController::takeStateForFormElement):
Creates a FormControlState instance with a state string.
* html/FormController.h:
(WebCore::FormControlState): Added.
* html/BaseCheckableInputType.cpp:
(WebCore::BaseCheckableInputType::saveFormControlState):
Use FormControlState class.
(WebCore::BaseCheckableInputType::restoreFormControlState): ditto.
* html/BaseCheckableInputType.h:
(BaseCheckableInputType): ditto.
* html/FileInputType.cpp:
(WebCore::FileInputType::saveFormControlState): ditto.
(WebCore::FileInputType::restoreFormControlState): ditto.
* html/FileInputType.h:
(FileInputType): ditto.
* html/HTMLFormControlElementWithState.cpp:
(WebCore::HTMLFormControlElementWithState::saveFormControlState): ditto.
(WebCore::HTMLFormControlElementWithState::finishParsingChildren): ditto.
* html/HTMLFormControlElementWithState.h:
(HTMLFormControlElementWithState): ditto.
(WebCore::HTMLFormControlElementWithState::restoreFormControlState): ditto.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::saveFormControlState): ditto.
(WebCore::HTMLInputElement::restoreFormControlState): ditto.
* html/HTMLInputElement.h:
(HTMLInputElement): ditto.
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::saveFormControlState): ditto.
(WebCore::HTMLSelectElement::restoreFormControlState): ditto.
* html/HTMLSelectElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::saveFormControlState): ditto.
(WebCore::HTMLTextAreaElement::restoreFormControlState): ditto.
* html/HTMLTextAreaElement.h:
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::saveFormControlState): ditto.
(WebCore::HiddenInputType::restoreFormControlState): ditto.
* html/HiddenInputType.h:
(HiddenInputType): ditto.
* html/InputType.cpp:
(WebCore::InputType::saveFormControlState): ditto.
(WebCore::InputType::restoreFormControlState): ditto.
* html/InputType.h:
(InputType): ditto.
* html/PasswordInputType.cpp:
(WebCore::PasswordInputType::saveFormControlState): ditto.
(WebCore::PasswordInputType::restoreFormControlState): ditto.
* html/PasswordInputType.h:
(PasswordInputType): ditto.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@120679 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/html/FormController.cpp b/Source/WebCore/html/FormController.cpp
index c882805..80d01f2 100644
--- a/Source/WebCore/html/FormController.cpp
+++ b/Source/WebCore/html/FormController.cpp
@@ -45,12 +45,12 @@
HTMLFormControlElementWithState* elementWithState = *it;
if (!elementWithState->shouldSaveAndRestoreFormControlState())
continue;
- String value;
- if (!elementWithState->saveFormControlState(value))
+ FormControlState state = elementWithState->saveFormControlState();
+ if (!state.hasValue())
continue;
stateVector.append(elementWithState->name().string());
stateVector.append(elementWithState->formControlType().string());
- stateVector.append(value);
+ stateVector.append(state.value());
}
return stateVector;
}
@@ -96,19 +96,19 @@
return !m_stateForNewFormElements.isEmpty();
}
-bool FormController::takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state)
+FormControlState FormController::takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type)
{
typedef FormElementStateMap::iterator Iterator;
Iterator it = m_stateForNewFormElements.find(FormElementKey(name, type));
if (it == m_stateForNewFormElements.end())
- return false;
+ return FormControlState();
ASSERT(it->second.size());
- state = it->second.last();
+ FormControlState state(it->second.last());
if (it->second.size() > 1)
it->second.removeLast();
else
m_stateForNewFormElements.remove(it);
- return true;
+ return state;
}
void FormController::registerFormElementWithFormAttribute(FormAssociatedElement* element)