Changeset 122559 in webkit


Ignore:
Timestamp:
Jul 13, 2012 3:59:59 AM (12 years ago)
Author:
tkent@chromium.org
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().

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122558 r122559  
     12012-07-13  Kent Tamura  <tkent@chromium.org>
     2
     3        Change the timing of form state restore
     4        https://bugs.webkit.org/show_bug.cgi?id=89962
     5
     6        Reviewed by Hajime Morita.
     7
     8        For a preparation to fix a form identification problem (Bug 91209),
     9        restore controls states when the parsing of their owner forms is
     10        completed. For controls without owners, their states are restored when
     11        their parsing is completed as ever.
     12
     13        No new tests. This doesn't change observable behavior.
     14
     15        * html/FormController.cpp:
     16        (WebCore::ownerFormForState):
     17        Added. This code was used in formKey(), and restoreControlState*() use it.
     18        (WebCore::FormKeyGenerator::formKey): Use ownerFormForState(). No behavior change.
     19        (WebCore::FormController::restoreControlStateFor):
     20        Moved some code from HTMLFormControlElementWithState::finishParsingChildren().
     21        The difference is we don't resotre state if this control is owned by a form.
     22        (WebCore::FormController::restoreControlStateIn):
     23        Restore states of associated controls. This is called from
     24        finishParsingChildren() for <form>.
     25        * html/FormController.h:
     26        (FormController):
     27        - Declare restoreControlStateFor() and restoreControlStateIn().
     28        - Make takeStateForFormElement() private.
     29
     30        * html/FormAssociatedElement.cpp:
     31        (WebCore::FormAssociatedElement::isFormControlElementWithState):
     32        Added. The default implementation returns false.
     33        * html/FormAssociatedElement.h:
     34        (FormAssociatedElement):
     35        Added isFormControlElementWithState() for FormController::restoreControlStateIn().
     36        * html/HTMLFormControlElementWithState.cpp:
     37        (WebCore::HTMLFormControlElementWithState::finishParsingChildren):
     38        Some code was moved to FormController:restoreControlStateFor().
     39        (WebCore::HTMLFormControlElementWithState::isFormControlElementWithState):
     40        Added. Returns true.
     41        * html/HTMLFormControlElementWithState.h:
     42        (HTMLFormControlElementWithState): Declare isFormControlElementWithState().
     43        * html/HTMLFormElement.cpp:
     44        (WebCore::HTMLFormElement::finishParsingChildren):
     45        Added. Calls FormController::restoreControlStateIn().
     46        * html/HTMLFormElement.h:
     47        (HTMLFormElement): Declare finishParsingChildren().
     48
    1492012-07-13  Kent Tamura  <tkent@chromium.org>
    250
  • trunk/Source/WebCore/html/FormAssociatedElement.cpp

    r120049 r122559  
    228228}
    229229
     230bool FormAssociatedElement::isFormControlElementWithState() const
     231{
     232    return false;
     233}
     234
    230235const HTMLElement* toHTMLElement(const FormAssociatedElement* associatedElement)
    231236{
  • trunk/Source/WebCore/html/FormAssociatedElement.h

    r120049 r122559  
    4747
    4848    virtual bool isFormControlElement() const = 0;
     49    virtual bool isFormControlElementWithState() const;
    4950    virtual bool isEnumeratable() const = 0;
    5051
  • trunk/Source/WebCore/html/FormController.cpp

    r122422 r122559  
    3030using namespace HTMLNames;
    3131
     32static inline HTMLFormElement* ownerFormForState(const HTMLFormControlElementWithState& control)
     33{
     34    // Assume controls with form attribute have no owners because we restore
     35    // state during parsing and form owners of such controls might be
     36    // indeterminate.
     37    return control.fastHasAttribute(formAttr) ? 0 : control.form();
     38}
     39
    3240// ----------------------------------------------------------------------------
    3341
     
    104112AtomicString FormKeyGenerator::formKey(const HTMLFormControlElementWithState& control)
    105113{
    106     // Assume contorl with form attribute have no owners because we restores
    107     // state during parsing and form owners of such controls might be
    108     // indeterminate.
    109     HTMLFormElement* form = control.fastHasAttribute(formAttr) ? 0 : control.form();
     114    HTMLFormElement* form = ownerFormForState(control);
    110115    if (!form) {
    111116        DEFINE_STATIC_LOCAL(AtomicString, formKeyForNoOwner, ("No owner"));
     
    241246}
    242247
     248void FormController::restoreControlStateFor(HTMLFormControlElementWithState& control)
     249{
     250    // We don't save state of a control with shouldSaveAndRestoreFormControlState()
     251    // == false. But we need to skip restoring process too because a control in
     252    // another form might have the same pair of name and type and saved its state.
     253    if (!control.shouldSaveAndRestoreFormControlState())
     254        return;
     255    if (ownerFormForState(control))
     256        return;
     257    FormControlState state = takeStateForFormElement(control);
     258    if (state.valueSize() > 0)
     259        control.restoreFormControlState(state);
     260}
     261
     262void FormController::restoreControlStateIn(HTMLFormElement& form)
     263{
     264    const Vector<FormAssociatedElement*>& elements = form.associatedElements();
     265    for (size_t i = 0; i < elements.size(); ++i) {
     266        if (!elements[i]->isFormControlElementWithState())
     267            continue;
     268        HTMLFormControlElementWithState* control = static_cast<HTMLFormControlElementWithState*>(elements[i]);
     269        if (!control->shouldSaveAndRestoreFormControlState())
     270            continue;
     271        if (ownerFormForState(*control) != &form)
     272            continue;
     273        FormControlState state = takeStateForFormElement(*control);
     274        if (state.valueSize() > 0)
     275            control->restoreFormControlState(state);
     276    }
     277}
     278
    243279void FormController::registerFormElementWithFormAttribute(FormAssociatedElement* element)
    244280{
  • trunk/Source/WebCore/html/FormController.h

    r121420 r122559  
    130130    // This should be callled only by Document::setStateForNewFormElements().
    131131    void setStateForNewFormElements(const Vector<String>&);
    132     FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
    133132    void willDeleteForm(HTMLFormElement*);
     133    void restoreControlStateFor(HTMLFormControlElementWithState&);
     134    void restoreControlStateIn(HTMLFormElement&);
    134135
    135136    void registerFormElementWithFormAttribute(FormAssociatedElement*);
     
    139140private:
    140141    FormController();
     142    FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
    141143
    142144    CheckedRadioButtons m_checkedRadioButtons;
  • trunk/Source/WebCore/html/HTMLFormControlElementWithState.cpp

    r121235 r122559  
    7171{
    7272    HTMLFormControlElement::finishParsingChildren();
     73    document()->formController()->restoreControlStateFor(*this);
     74}
    7375
    74     // We don't save state of a control with shouldSaveAndRestoreFormControlState()=false.
    75     // But we need to skip restoring process too because a control in another
    76     // form might have the same pair of name and type and saved its state.
    77     if (!shouldSaveAndRestoreFormControlState())
    78         return;
    79 
    80     FormControlState state = document()->formController()->takeStateForFormElement(*this);
    81     if (state.valueSize() > 0)
    82         restoreFormControlState(state);
     76bool HTMLFormControlElementWithState::isFormControlElementWithState() const
     77{
     78    return true;
    8379}
    8480
  • trunk/Source/WebCore/html/HTMLFormControlElementWithState.h

    r122414 r122559  
    4848    virtual void finishParsingChildren();
    4949    virtual void didMoveToNewDocument(Document* oldDocument) OVERRIDE;
     50    virtual bool isFormControlElementWithState() const OVERRIDE;
    5051};
    5152
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r122115 r122559  
    686686}
    687687
     688void HTMLFormElement::finishParsingChildren()
     689{
     690    HTMLElement::finishParsingChildren();
     691    document()->formController()->restoreControlStateIn(*this);
     692}
     693
    688694} // namespace
  • trunk/Source/WebCore/html/HTMLFormElement.h

    r122115 r122559  
    122122    virtual void didNotifyDescendantInsertions(ContainerNode*) OVERRIDE;
    123123    virtual void removedFrom(ContainerNode*) OVERRIDE;
     124    virtual void finishParsingChildren() OVERRIDE;
    124125
    125126    virtual void handleLocalEvents(Event*);
Note: See TracChangeset for help on using the changeset viewer.