Title: [122559] trunk/Source/WebCore
Revision
122559
Author
[email protected]
Date
2012-07-13 03:59:59 -0700 (Fri, 13 Jul 2012)

Log Message

Change the timing of form state restore
https://bugs.webkit.org/show_bug.cgi?id=89962

Reviewed by Hajime Morita.

For a preparation to fix a form identification problem (Bug 91209),
restore controls states when the parsing of their owner forms is
completed. For controls without owners, their states are restored when
their parsing is completed as ever.

No new tests. This doesn't change observable behavior.

* html/FormController.cpp:
(WebCore::ownerFormForState):
Added. This code was used in formKey(), and restoreControlState*() use it.
(WebCore::FormKeyGenerator::formKey): Use ownerFormForState(). No behavior change.
(WebCore::FormController::restoreControlStateFor):
Moved some code from HTMLFormControlElementWithState::finishParsingChildren().
The difference is we don't resotre state if this control is owned by a form.
(WebCore::FormController::restoreControlStateIn):
Restore states of associated controls. This is called from
finishParsingChildren() for <form>.
* html/FormController.h:
(FormController):
- Declare restoreControlStateFor() and restoreControlStateIn().
- Make takeStateForFormElement() private.

* html/FormAssociatedElement.cpp:
(WebCore::FormAssociatedElement::isFormControlElementWithState):
Added. The default implementation returns false.
* html/FormAssociatedElement.h:
(FormAssociatedElement):
Added isFormControlElementWithState() for FormController::restoreControlStateIn().
* html/HTMLFormControlElementWithState.cpp:
(WebCore::HTMLFormControlElementWithState::finishParsingChildren):
Some code was moved to FormController:restoreControlStateFor().
(WebCore::HTMLFormControlElementWithState::isFormControlElementWithState):
Added. Returns true.
* html/HTMLFormControlElementWithState.h:
(HTMLFormControlElementWithState): Declare isFormControlElementWithState().
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::finishParsingChildren):
Added. Calls FormController::restoreControlStateIn().
* html/HTMLFormElement.h:
(HTMLFormElement): Declare finishParsingChildren().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (122558 => 122559)


--- trunk/Source/WebCore/ChangeLog	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/ChangeLog	2012-07-13 10:59:59 UTC (rev 122559)
@@ -1,5 +1,53 @@
 2012-07-13  Kent Tamura  <[email protected]>
 
+        Change the timing of form state restore
+        https://bugs.webkit.org/show_bug.cgi?id=89962
+
+        Reviewed by Hajime Morita.
+
+        For a preparation to fix a form identification problem (Bug 91209),
+        restore controls states when the parsing of their owner forms is
+        completed. For controls without owners, their states are restored when
+        their parsing is completed as ever.
+
+        No new tests. This doesn't change observable behavior.
+
+        * html/FormController.cpp:
+        (WebCore::ownerFormForState):
+        Added. This code was used in formKey(), and restoreControlState*() use it.
+        (WebCore::FormKeyGenerator::formKey): Use ownerFormForState(). No behavior change.
+        (WebCore::FormController::restoreControlStateFor):
+        Moved some code from HTMLFormControlElementWithState::finishParsingChildren().
+        The difference is we don't resotre state if this control is owned by a form.
+        (WebCore::FormController::restoreControlStateIn):
+        Restore states of associated controls. This is called from
+        finishParsingChildren() for <form>.
+        * html/FormController.h:
+        (FormController):
+        - Declare restoreControlStateFor() and restoreControlStateIn().
+        - Make takeStateForFormElement() private.
+
+        * html/FormAssociatedElement.cpp:
+        (WebCore::FormAssociatedElement::isFormControlElementWithState):
+        Added. The default implementation returns false.
+        * html/FormAssociatedElement.h:
+        (FormAssociatedElement):
+        Added isFormControlElementWithState() for FormController::restoreControlStateIn().
+        * html/HTMLFormControlElementWithState.cpp:
+        (WebCore::HTMLFormControlElementWithState::finishParsingChildren):
+        Some code was moved to FormController:restoreControlStateFor().
+        (WebCore::HTMLFormControlElementWithState::isFormControlElementWithState):
+        Added. Returns true.
+        * html/HTMLFormControlElementWithState.h:
+        (HTMLFormControlElementWithState): Declare isFormControlElementWithState().
+        * html/HTMLFormElement.cpp:
+        (WebCore::HTMLFormElement::finishParsingChildren):
+        Added. Calls FormController::restoreControlStateIn().
+        * html/HTMLFormElement.h:
+        (HTMLFormElement): Declare finishParsingChildren().
+
+2012-07-13  Kent Tamura  <[email protected]>
+
         Make calendar pickers testable
         https://bugs.webkit.org/show_bug.cgi?id=84827
 

Modified: trunk/Source/WebCore/html/FormAssociatedElement.cpp (122558 => 122559)


--- trunk/Source/WebCore/html/FormAssociatedElement.cpp	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/FormAssociatedElement.cpp	2012-07-13 10:59:59 UTC (rev 122559)
@@ -227,6 +227,11 @@
     return name.isNull() ? emptyAtom : name;
 }
 
+bool FormAssociatedElement::isFormControlElementWithState() const
+{
+    return false;
+}
+
 const HTMLElement* toHTMLElement(const FormAssociatedElement* associatedElement)
 {
     if (associatedElement->isFormControlElement())

Modified: trunk/Source/WebCore/html/FormAssociatedElement.h (122558 => 122559)


--- trunk/Source/WebCore/html/FormAssociatedElement.h	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/FormAssociatedElement.h	2012-07-13 10:59:59 UTC (rev 122559)
@@ -46,6 +46,7 @@
     ValidityState* validity();
 
     virtual bool isFormControlElement() const = 0;
+    virtual bool isFormControlElementWithState() const;
     virtual bool isEnumeratable() const = 0;
 
     // Returns the 'name' attribute value. If this element has no name

Modified: trunk/Source/WebCore/html/FormController.cpp (122558 => 122559)


--- trunk/Source/WebCore/html/FormController.cpp	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/FormController.cpp	2012-07-13 10:59:59 UTC (rev 122559)
@@ -29,6 +29,14 @@
 
 using namespace HTMLNames;
 
+static inline HTMLFormElement* ownerFormForState(const HTMLFormControlElementWithState& control)
+{
+    // Assume controls with form attribute have no owners because we restore
+    // state during parsing and form owners of such controls might be
+    // indeterminate.
+    return control.fastHasAttribute(formAttr) ? 0 : control.form();
+}
+
 // ----------------------------------------------------------------------------
 
 // Serilized form of FormControlState:
@@ -103,10 +111,7 @@
 
 AtomicString FormKeyGenerator::formKey(const HTMLFormControlElementWithState& control)
 {
-    // Assume contorl with form attribute have no owners because we restores
-    // state during parsing and form owners of such controls might be
-    // indeterminate.
-    HTMLFormElement* form = control.fastHasAttribute(formAttr) ? 0 : control.form();
+    HTMLFormElement* form = ownerFormForState(control);
     if (!form) {
         DEFINE_STATIC_LOCAL(AtomicString, formKeyForNoOwner, ("No owner"));
         return formKeyForNoOwner;
@@ -240,6 +245,37 @@
         m_formKeyGenerator->willDeleteForm(form);
 }
 
+void FormController::restoreControlStateFor(HTMLFormControlElementWithState& control)
+{
+    // We don't save state of a control with shouldSaveAndRestoreFormControlState()
+    // == false. But we need to skip restoring process too because a control in
+    // another form might have the same pair of name and type and saved its state.
+    if (!control.shouldSaveAndRestoreFormControlState())
+        return;
+    if (ownerFormForState(control))
+        return;
+    FormControlState state = takeStateForFormElement(control);
+    if (state.valueSize() > 0)
+        control.restoreFormControlState(state);
+}
+
+void FormController::restoreControlStateIn(HTMLFormElement& form)
+{
+    const Vector<FormAssociatedElement*>& elements = form.associatedElements();
+    for (size_t i = 0; i < elements.size(); ++i) {
+        if (!elements[i]->isFormControlElementWithState())
+            continue;
+        HTMLFormControlElementWithState* control = static_cast<HTMLFormControlElementWithState*>(elements[i]);
+        if (!control->shouldSaveAndRestoreFormControlState())
+            continue;
+        if (ownerFormForState(*control) != &form)
+            continue;
+        FormControlState state = takeStateForFormElement(*control);
+        if (state.valueSize() > 0)
+            control->restoreFormControlState(state);
+    }
+}
+
 void FormController::registerFormElementWithFormAttribute(FormAssociatedElement* element)
 {
     ASSERT(toHTMLElement(element)->fastHasAttribute(formAttr));

Modified: trunk/Source/WebCore/html/FormController.h (122558 => 122559)


--- trunk/Source/WebCore/html/FormController.h	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/FormController.h	2012-07-13 10:59:59 UTC (rev 122559)
@@ -129,8 +129,9 @@
     Vector<String> formElementsState() const;
     // This should be callled only by Document::setStateForNewFormElements().
     void setStateForNewFormElements(const Vector<String>&);
-    FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
     void willDeleteForm(HTMLFormElement*);
+    void restoreControlStateFor(HTMLFormControlElementWithState&);
+    void restoreControlStateIn(HTMLFormElement&);
 
     void registerFormElementWithFormAttribute(FormAssociatedElement*);
     void unregisterFormElementWithFormAttribute(FormAssociatedElement*);
@@ -138,6 +139,7 @@
 
 private:
     FormController();
+    FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
 
     CheckedRadioButtons m_checkedRadioButtons;
 

Modified: trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp (122558 => 122559)


--- trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp	2012-07-13 10:59:59 UTC (rev 122559)
@@ -70,16 +70,12 @@
 void HTMLFormControlElementWithState::finishParsingChildren()
 {
     HTMLFormControlElement::finishParsingChildren();
+    document()->formController()->restoreControlStateFor(*this);
+}
 
-    // We don't save state of a control with shouldSaveAndRestoreFormControlState()=false.
-    // But we need to skip restoring process too because a control in another
-    // form might have the same pair of name and type and saved its state.
-    if (!shouldSaveAndRestoreFormControlState())
-        return;
-
-    FormControlState state = document()->formController()->takeStateForFormElement(*this);
-    if (state.valueSize() > 0)
-        restoreFormControlState(state);
+bool HTMLFormControlElementWithState::isFormControlElementWithState() const
+{
+    return true;
 }
 
 } // namespace Webcore

Modified: trunk/Source/WebCore/html/HTMLFormControlElementWithState.h (122558 => 122559)


--- trunk/Source/WebCore/html/HTMLFormControlElementWithState.h	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/HTMLFormControlElementWithState.h	2012-07-13 10:59:59 UTC (rev 122559)
@@ -47,6 +47,7 @@
     virtual bool shouldAutocomplete() const;
     virtual void finishParsingChildren();
     virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
+    virtual bool isFormControlElementWithState() const OVERRIDE;
 };
 
 } // namespace

Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (122558 => 122559)


--- trunk/Source/WebCore/html/HTMLFormElement.cpp	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp	2012-07-13 10:59:59 UTC (rev 122559)
@@ -685,4 +685,10 @@
     return !equalIgnoringCase(fastGetAttribute(autocompleteAttr), "off");
 }
 
+void HTMLFormElement::finishParsingChildren()
+{
+    HTMLElement::finishParsingChildren();
+    document()->formController()->restoreControlStateIn(*this);
+}
+
 } // namespace

Modified: trunk/Source/WebCore/html/HTMLFormElement.h (122558 => 122559)


--- trunk/Source/WebCore/html/HTMLFormElement.h	2012-07-13 10:35:57 UTC (rev 122558)
+++ trunk/Source/WebCore/html/HTMLFormElement.h	2012-07-13 10:59:59 UTC (rev 122559)
@@ -121,6 +121,7 @@
     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
     virtual void didNotifyDescendantInsertions(ContainerNode*) OVERRIDE;
     virtual void removedFrom(ContainerNode*) OVERRIDE;
+    virtual void finishParsingChildren() OVERRIDE;
 
     virtual void handleLocalEvents(Event*);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to