2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2010, 2011, 2012 Google Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef FormController_h
23 #define FormController_h
25 #include "core/html/forms/RadioButtonGroupScope.h"
26 #include "wtf/Forward.h"
27 #include "wtf/ListHashSet.h"
28 #include "wtf/Vector.h"
29 #include "wtf/text/AtomicStringHash.h"
33 class FormAssociatedElement;
34 class FormKeyGenerator;
35 class HTMLFormControlElementWithState;
36 class HTMLFormElement;
39 class FormControlState {
41 FormControlState() : m_type(TypeSkip) { }
42 explicit FormControlState(const String& value) : m_type(TypeRestore) { m_values.append(value); }
43 static FormControlState deserialize(const Vector<String>& stateVector, size_t& index);
44 FormControlState(const FormControlState& another) : m_type(another.m_type), m_values(another.m_values) { }
45 FormControlState& operator=(const FormControlState&);
47 bool isFailure() const { return m_type == TypeFailure; }
48 size_t valueSize() const { return m_values.size(); }
49 const String& operator[](size_t i) const { return m_values[i]; }
50 void append(const String&);
51 void serializeTo(Vector<String>& stateVector) const;
54 enum Type { TypeSkip, TypeRestore, TypeFailure };
55 explicit FormControlState(Type type) : m_type(type) { }
58 Vector<String> m_values;
61 inline FormControlState& FormControlState::operator=(const FormControlState& another)
63 m_type = another.m_type;
64 m_values = another.m_values;
68 inline void FormControlState::append(const String& value)
71 m_values.append(value);
74 class FormController {
75 WTF_MAKE_FAST_ALLOCATED;
77 static PassOwnPtr<FormController> create()
79 return adoptPtr(new FormController);
83 RadioButtonGroupScope& radioButtonGroupScope() { return m_radioButtonGroupScope; }
85 void registerStatefulFormControl(HTMLFormControlElementWithState&);
86 void unregisterStatefulFormControl(HTMLFormControlElementWithState&);
87 // This should be callled only by Document::formElementsState().
88 Vector<String> formElementsState() const;
89 // This should be callled only by Document::setStateForNewFormElements().
90 void setStateForNewFormElements(const Vector<String>&);
91 void willDeleteForm(HTMLFormElement*);
92 void restoreControlStateFor(HTMLFormControlElementWithState&);
93 void restoreControlStateIn(HTMLFormElement&);
95 static Vector<String> getReferencedFilePaths(const Vector<String>& stateVector);
98 typedef ListHashSet<RefPtr<HTMLFormControlElementWithState>, 64> FormElementListHashSet;
99 typedef HashMap<AtomicString, OwnPtr<SavedFormState> > SavedFormStateMap;
102 static PassOwnPtr<SavedFormStateMap> createSavedFormStateMap(const FormElementListHashSet&);
103 FormControlState takeStateForFormElement(const HTMLFormControlElementWithState&);
104 static void formStatesFromStateVector(const Vector<String>&, SavedFormStateMap&);
106 RadioButtonGroupScope m_radioButtonGroupScope;
107 FormElementListHashSet m_formControls;
108 SavedFormStateMap m_savedFormStateMap;
109 OwnPtr<FormKeyGenerator> m_formKeyGenerator;
112 } // namespace WebCore