Change the serialization format of form control state to make the code simple
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2012 09:43:07 +0000 (09:43 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 25 Jun 2012 09:43:07 +0000 (09:43 +0000)
commit7f6a819a30efe92067e3a23caf617be0ac896d4d
treeb67ebdc4893673241f3a91ed2ebcde24437e40a9
parent65af26a70e1252e2b7890f932a08a681b1d16e12
Change the serialization format of form control state to make the code simple
https://bugs.webkit.org/show_bug.cgi?id=89847

Reviewed by Hajime Morita.

Source/WebCore:

We used multiple strings to represent state of single form control. It
made the code complex. We change the serialization format so that one
CSV string represents state.

Examples in the old format:
    "0"
    "1", "value"
    "3", "value1", "value2,value2", "value3"

Examples in the new format:
    ""
    ",value"
    ",value1,value2\,value2,value3"

Test: fast/forms/state-restore-various-values.html

* html/FormController.cpp:
(WebCore::FormControlState::serialize):
Generate comma-separated string.
',' in a value is serialized as "\,".
We changed the signature because we don't need the out-argument.
(WebCore::FormControlState::deserialize):
Parses the input comma-separated string.
We changed the signature because we don't need multiple input strings.
(formStateSignature):
Bump up the version because of the representation change.
(WebCore::FormController::formElementsState):
The new serialized format occupies just one string for one control.
- Expected size is now 3n+1.
- Use FormControlState::serialize().
(WebCore::FormController::setStateForNewFormElements):
The new serialized format occupies just one string for one control.
So we can check the vector size before the iteration.
* html/FormController.h:
(FormControlState): Change the function signatures.

* html/shadow/CalendarPickerElement.cpp:
(WebCore::addJavaScriptString): Use StringBuilder::appendEscaped().

Source/WTF:

* wtf/text/StringBuilder.h:
(WTF::StringBuilder::appendEscaped): Added. This function adds the
escaped form of the input string. e.g. if stiring="foo,bar" escape='\'
special=',', the appended string is foo\,bar.

LayoutTests:

* fast/forms/state-restore-broken-state-expected.txt:
Apply the serialization format change.
* fast/forms/state-restore-various-values-expected.txt: Added.
* fast/forms/state-restore-various-values.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@121145 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/forms/state-restore-broken-state-expected.txt
LayoutTests/fast/forms/state-restore-various-values-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/state-restore-various-values.html [new file with mode: 0644]
Source/WTF/ChangeLog
Source/WTF/wtf/text/StringBuilder.h
Source/WebCore/ChangeLog
Source/WebCore/html/FormController.cpp
Source/WebCore/html/FormController.h
Source/WebCore/html/shadow/CalendarPickerElement.cpp