Title: [120679] trunk/Source/WebCore
Revision
120679
Author
[email protected]
Date
2012-06-18 23:20:48 -0700 (Mon, 18 Jun 2012)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (120678 => 120679)


--- trunk/Source/WebCore/ChangeLog	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/ChangeLog	2012-06-19 06:20:48 UTC (rev 120679)
@@ -1,3 +1,75 @@
+2012-06-18  Kent Tamura  <[email protected]>
+
+        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.
+
 2012-06-18  Joone Hur  <[email protected]>
 
         [EFL] Fontconfig can't be linked properly

Modified: trunk/Source/WebCore/html/BaseCheckableInputType.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/BaseCheckableInputType.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/BaseCheckableInputType.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -32,6 +32,7 @@
 #include "config.h"
 #include "BaseCheckableInputType.h"
 
+#include "FormController.h"
 #include "FormDataList.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -42,15 +43,14 @@
 
 using namespace HTMLNames;
 
-bool BaseCheckableInputType::saveFormControlState(String& result) const
+FormControlState BaseCheckableInputType::saveFormControlState() const
 {
-    result = element()->checked() ? "on" : "off";
-    return true;
+    return FormControlState(element()->checked() ? "on" : "off");
 }
 
-void BaseCheckableInputType::restoreFormControlState(const String& state)
+void BaseCheckableInputType::restoreFormControlState(const FormControlState& state)
 {
-    element()->setChecked(state == "on");
+    element()->setChecked(state.value() == "on");
 }
 
 bool BaseCheckableInputType::appendFormData(FormDataList& encoding, bool) const

Modified: trunk/Source/WebCore/html/BaseCheckableInputType.h (120678 => 120679)


--- trunk/Source/WebCore/html/BaseCheckableInputType.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/BaseCheckableInputType.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -42,8 +42,8 @@
     virtual void handleKeydownEvent(KeyboardEvent*);
 
 private:
-    virtual bool saveFormControlState(String&) const OVERRIDE;
-    virtual void restoreFormControlState(const String&) OVERRIDE;
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
     virtual bool appendFormData(FormDataList&, bool) const OVERRIDE;
     virtual void handleKeypressEvent(KeyboardEvent*) OVERRIDE;
     virtual bool canSetStringValue() const OVERRIDE;

Modified: trunk/Source/WebCore/html/FileInputType.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/FileInputType.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -29,6 +29,7 @@
 #include "File.h"
 #include "FileList.h"
 #include "FileSystem.h"
+#include "FormController.h"
 #include "FormDataList.h"
 #include "Frame.h"
 #include "HTMLInputElement.h"
@@ -100,11 +101,13 @@
     return InputTypeNames::file();
 }
 
-bool FileInputType::saveFormControlState(String& result) const
+FormControlState FileInputType::saveFormControlState() const
 {
     if (m_fileList->isEmpty())
-        return false;
-    result = String();
+        return FormControlState();
+    // FIXME: FormControlState should be capable to have multiple strings and we
+    // should stop the following ugly string concatenation.
+    StringBuilder result;
     unsigned numFiles = m_fileList->length();
     for (unsigned i = 0; i < numFiles; ++i) {
         result.append(m_fileList->item(i)->path());
@@ -112,14 +115,14 @@
         result.append(m_fileList->item(i)->name());
         result.append('\0');
     }
-    return true;
+    return FormControlState(result.toString());
 }
 
-void FileInputType::restoreFormControlState(const String& state)
+void FileInputType::restoreFormControlState(const FormControlState& state)
 {
     Vector<FileChooserFileInfo> files;
     Vector<String> paths;
-    state.split('\0', paths);
+    state.value().split('\0', paths);
     for (unsigned i = 0; i < paths.size(); ++i) {
         Vector<String> pathAndName;
         paths[i].split('\1', pathAndName);

Modified: trunk/Source/WebCore/html/FileInputType.h (120678 => 120679)


--- trunk/Source/WebCore/html/FileInputType.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/FileInputType.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -49,8 +49,8 @@
 private:
     FileInputType(HTMLInputElement*);
     virtual const AtomicString& formControlType() const OVERRIDE;
-    virtual bool saveFormControlState(String&) const OVERRIDE;
-    virtual void restoreFormControlState(const String&) OVERRIDE;
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
     virtual bool appendFormData(FormDataList&, bool) const OVERRIDE;
     virtual bool valueMissing(const String&) const OVERRIDE;
     virtual String valueMissingText() const OVERRIDE;

Modified: trunk/Source/WebCore/html/FormController.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/FormController.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/FormController.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -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)

Modified: trunk/Source/WebCore/html/FormController.h (120678 => 120679)


--- trunk/Source/WebCore/html/FormController.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/FormController.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -26,6 +26,7 @@
 #include <wtf/Forward.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -72,6 +73,29 @@
     static bool isDeletedValue(const FormElementKey& value) { return value.isHashTableDeletedValue(); }
 };
 
+class FormControlState {
+public:
+    FormControlState() : m_type(TypeSkip) { }
+    explicit FormControlState(const String& value) : m_type(TypeRestore), m_value(value) { }
+    FormControlState(const FormControlState& another) : m_type(another.m_type), m_value(another.m_value) { }
+    FormControlState& operator=(const FormControlState&);
+
+    bool hasValue() const { return m_type == TypeRestore; }
+    String value() const { return m_value; }
+
+private:
+    enum Type { TypeSkip, TypeRestore };
+    Type m_type;
+    String m_value;
+};
+
+inline FormControlState& FormControlState::operator=(const FormControlState& another)
+{
+    m_type = another.m_type;
+    m_value = another.m_value;
+    return *this;
+}
+
 class FormController {
 public:
     static PassOwnPtr<FormController> create()
@@ -89,7 +113,7 @@
     // This should be callled only by Document::setStateForNewFormElements().
     void setStateForNewFormElements(const Vector<String>&);
     bool hasStateForNewFormElements() const;
-    bool takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type, String& state);
+    FormControlState takeStateForFormElement(AtomicStringImpl* name, AtomicStringImpl* type);
 
     void registerFormElementWithFormAttribute(FormAssociatedElement*);
     void unregisterFormElementWithFormAttribute(FormAssociatedElement*);

Modified: trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -62,6 +62,11 @@
     return attached() && shouldAutocomplete();
 }
 
+FormControlState HTMLFormControlElementWithState::saveFormControlState() const
+{
+    return FormControlState();
+}
+
 void HTMLFormControlElementWithState::finishParsingChildren()
 {
     HTMLFormControlElement::finishParsingChildren();
@@ -74,8 +79,8 @@
 
     Document* doc = document();
     if (doc->formController()->hasStateForNewFormElements()) {
-        String state;
-        if (doc->formController()->takeStateForFormElement(name().impl(), type().impl(), state))
+        FormControlState state = doc->formController()->takeStateForFormElement(name().impl(), type().impl());
+        if (state.hasValue())
             restoreFormControlState(state);
     }
 }

Modified: trunk/Source/WebCore/html/HTMLFormControlElementWithState.h (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLFormControlElementWithState.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLFormControlElementWithState.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -28,6 +28,8 @@
 
 namespace WebCore {
 
+class FormControlState;
+
 class HTMLFormControlElementWithState : public HTMLFormControlElement {
 public:
     virtual ~HTMLFormControlElementWithState();
@@ -35,8 +37,9 @@
     virtual bool canContainRangeEndPoint() const { return false; }
 
     bool shouldSaveAndRestoreFormControlState() const;
-    virtual bool saveFormControlState(String&) const { return false; }
-    virtual void restoreFormControlState(const String&) { }
+    virtual FormControlState saveFormControlState() const;
+    // The specified FormControlState must have one string value.
+    virtual void restoreFormControlState(const FormControlState&) { }
 
 protected:
     HTMLFormControlElementWithState(const QualifiedName& tagName, Document*, HTMLFormElement*);

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -493,12 +493,12 @@
     return m_inputType->formControlType();
 }
 
-bool HTMLInputElement::saveFormControlState(String& result) const
+FormControlState HTMLInputElement::saveFormControlState() const
 {
-    return m_inputType->saveFormControlState(result);
+    return m_inputType->saveFormControlState();
 }
 
-void HTMLInputElement::restoreFormControlState(const String& state)
+void HTMLInputElement::restoreFormControlState(const FormControlState& state)
 {
     m_inputType->restoreFormControlState(state);
     m_stateRestored = true;

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -292,8 +292,8 @@
 
     virtual const AtomicString& formControlType() const;
 
-    virtual bool saveFormControlState(String& value) const;
-    virtual void restoreFormControlState(const String&);
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
 
     virtual bool canStartSelection() const;
 

Modified: trunk/Source/WebCore/html/HTMLSelectElement.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLSelectElement.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -33,6 +33,7 @@
 #include "Chrome.h"
 #include "ChromeClient.h"
 #include "EventNames.h"
+#include "FormController.h"
 #include "FormDataList.h"
 #include "Frame.h"
 #include "HTMLFormElement.h"
@@ -914,7 +915,7 @@
     }
 }
 
-bool HTMLSelectElement::saveFormControlState(String& value) const
+FormControlState HTMLSelectElement::saveFormControlState() const
 {
     const Vector<HTMLElement*>& items = listItems();
     size_t length = items.size();
@@ -925,21 +926,21 @@
         bool selected = element->hasTagName(optionTag) && toHTMLOptionElement(element)->selected();
         builder.append(selected ? 'X' : '.');
     }
-    value = builder.toString();
-    return true;
+    return FormControlState(builder.toString());
 }
 
-void HTMLSelectElement::restoreFormControlState(const String& state)
+void HTMLSelectElement::restoreFormControlState(const FormControlState& state)
 {
     recalcListItems();
 
     const Vector<HTMLElement*>& items = listItems();
     size_t length = items.size();
 
+    String mask = state.value();
     for (size_t i = 0; i < length; ++i) {
         HTMLElement* element = items[i];
         if (element->hasTagName(optionTag))
-            toHTMLOptionElement(element)->setSelectedState(state[i] == 'X');
+            toHTMLOptionElement(element)->setSelectedState(mask[i] == 'X');
     }
 
     setOptionsChangedOnRenderer();

Modified: trunk/Source/WebCore/html/HTMLSelectElement.h (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLSelectElement.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLSelectElement.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -120,8 +120,8 @@
     virtual bool isEnumeratable() const { return true; }
     virtual bool supportLabels() const OVERRIDE { return true; }
 
-    virtual bool saveFormControlState(String& value) const;
-    virtual void restoreFormControlState(const String&);
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
 
     virtual void parseAttribute(const Attribute&) OVERRIDE;
     virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -34,6 +34,7 @@
 #include "Event.h"
 #include "EventNames.h"
 #include "ExceptionCode.h"
+#include "FormController.h"
 #include "FormDataList.h"
 #include "Frame.h"
 #include "HTMLNames.h"
@@ -98,18 +99,17 @@
     return textarea;
 }
 
-bool HTMLTextAreaElement::saveFormControlState(String& result) const
+FormControlState HTMLTextAreaElement::saveFormControlState() const
 {
     String currentValue = value();
     if (currentValue == defaultValue())
-        return false;
-    result = currentValue;
-    return true;
+        return FormControlState();
+    return FormControlState(currentValue);
 }
 
-void HTMLTextAreaElement::restoreFormControlState(const String& state)
+void HTMLTextAreaElement::restoreFormControlState(const FormControlState& state)
 {
-    setValue(state);
+    setValue(state.value());
 }
 
 void HTMLTextAreaElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.h (120678 => 120679)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -90,8 +90,8 @@
 
     virtual const AtomicString& formControlType() const;
 
-    virtual bool saveFormControlState(String& value) const;
-    virtual void restoreFormControlState(const String&);
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
 
     virtual bool isTextFormControl() const { return true; }
 

Modified: trunk/Source/WebCore/html/HiddenInputType.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/HiddenInputType.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HiddenInputType.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -32,6 +32,7 @@
 #include "config.h"
 #include "HiddenInputType.h"
 
+#include "FormController.h"
 #include "FormDataList.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -51,15 +52,15 @@
     return InputTypeNames::hidden();
 }
 
-bool HiddenInputType::saveFormControlState(String& result) const
+FormControlState HiddenInputType::saveFormControlState() const
 {
-    result = element()->value();
-    return true;
+    // FIXME: We should not always save the value. http://webkit.org/b/88685
+    return FormControlState(element()->value());
 }
 
-void HiddenInputType::restoreFormControlState(const String& string)
+void HiddenInputType::restoreFormControlState(const FormControlState& state)
 {
-    element()->setAttribute(valueAttr, string);
+    element()->setAttribute(valueAttr, state.value());
 }
 
 bool HiddenInputType::supportsValidation() const

Modified: trunk/Source/WebCore/html/HiddenInputType.h (120678 => 120679)


--- trunk/Source/WebCore/html/HiddenInputType.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/HiddenInputType.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -42,8 +42,8 @@
 private:
     HiddenInputType(HTMLInputElement* element) : InputType(element) { }
     virtual const AtomicString& formControlType() const OVERRIDE;
-    virtual bool saveFormControlState(String&) const OVERRIDE;
-    virtual void restoreFormControlState(const String&) OVERRIDE;
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
     virtual bool supportsValidation() const OVERRIDE;
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const OVERRIDE;
     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;

Modified: trunk/Source/WebCore/html/InputType.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/InputType.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/InputType.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -42,6 +42,7 @@
 #include "ExceptionCode.h"
 #include "FileInputType.h"
 #include "FileList.h"
+#include "FormController.h"
 #include "FormDataList.h"
 #include "HTMLFormElement.h"
 #include "HTMLInputElement.h"
@@ -168,18 +169,17 @@
     return false;
 }
 
-bool InputType::saveFormControlState(String& result) const
+FormControlState InputType::saveFormControlState() const
 {
     String currentValue = element()->value();
     if (currentValue == element()->defaultValue())
-        return false;
-    result = currentValue;
-    return true;
+        return FormControlState();
+    return FormControlState(currentValue);
 }
 
-void InputType::restoreFormControlState(const String& state)
+void InputType::restoreFormControlState(const FormControlState& state)
 {
-    element()->setValue(state);
+    element()->setValue(state.value());
 }
 
 bool InputType::isFormDataAppendable() const

Modified: trunk/Source/WebCore/html/InputType.h (120678 => 120679)


--- trunk/Source/WebCore/html/InputType.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/InputType.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -126,8 +126,8 @@
 
     // Form value functions
 
-    virtual bool saveFormControlState(String&) const;
-    virtual void restoreFormControlState(const String&);
+    virtual FormControlState saveFormControlState() const;
+    virtual void restoreFormControlState(const FormControlState&);
     virtual bool isFormDataAppendable() const;
     virtual bool appendFormData(FormDataList&, bool multipart) const;
 

Modified: trunk/Source/WebCore/html/PasswordInputType.cpp (120678 => 120679)


--- trunk/Source/WebCore/html/PasswordInputType.cpp	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/PasswordInputType.cpp	2012-06-19 06:20:48 UTC (rev 120679)
@@ -32,6 +32,7 @@
 #include "config.h"
 #include "PasswordInputType.h"
 
+#include "FormController.h"
 #include "HTMLInputElement.h"
 #include <wtf/Assertions.h>
 #include <wtf/PassOwnPtr.h>
@@ -48,13 +49,13 @@
     return InputTypeNames::password();
 }
 
-bool PasswordInputType::saveFormControlState(String&) const
+FormControlState PasswordInputType::saveFormControlState() const
 {
     // Should never save/restore password fields.
-    return false;
+    return FormControlState();
 }
 
-void PasswordInputType::restoreFormControlState(const String&)
+void PasswordInputType::restoreFormControlState(const FormControlState&)
 {
     // Should never save/restore password fields.
     ASSERT_NOT_REACHED();

Modified: trunk/Source/WebCore/html/PasswordInputType.h (120678 => 120679)


--- trunk/Source/WebCore/html/PasswordInputType.h	2012-06-19 06:16:16 UTC (rev 120678)
+++ trunk/Source/WebCore/html/PasswordInputType.h	2012-06-19 06:20:48 UTC (rev 120679)
@@ -42,8 +42,8 @@
 private:
     PasswordInputType(HTMLInputElement* element) : BaseTextInputType(element) { }
     virtual const AtomicString& formControlType() const OVERRIDE;
-    virtual bool saveFormControlState(String&) const OVERRIDE;
-    virtual void restoreFormControlState(const String&) OVERRIDE;
+    virtual FormControlState saveFormControlState() const OVERRIDE;
+    virtual void restoreFormControlState(const FormControlState&) OVERRIDE;
     virtual bool shouldUseInputMethod() const OVERRIDE;
     virtual bool shouldResetOnDocumentActivation() OVERRIDE;
     virtual bool shouldRespectListAttribute() OVERRIDE;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to