Keep auxilliary media objects on the heap always.
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / FormAssociatedElement.h
blob34f1c103b314582cb61cf775910b7c742a641161
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #ifndef FormAssociatedElement_h
25 #define FormAssociatedElement_h
27 #include "core/CoreExport.h"
28 #include "platform/heap/Handle.h"
29 #include "wtf/WeakPtr.h"
30 #include "wtf/text/WTFString.h"
32 namespace blink {
34 class ContainerNode;
35 class Document;
36 class FormAttributeTargetObserver;
37 class FormDataList;
38 class HTMLElement;
39 class HTMLFormElement;
40 class Node;
41 class ValidityState;
43 class CORE_EXPORT FormAssociatedElement : public WillBeGarbageCollectedMixin {
44 public:
45 virtual ~FormAssociatedElement();
47 #if !ENABLE(OILPAN)
48 void ref() { refFormAssociatedElement(); }
49 void deref() { derefFormAssociatedElement(); }
50 #endif
52 static HTMLFormElement* findAssociatedForm(const HTMLElement*);
53 HTMLFormElement* form() const { return m_form.get(); }
54 ValidityState* validity();
56 virtual bool isFormControlElement() const = 0;
57 virtual bool isFormControlElementWithState() const;
58 virtual bool isEnumeratable() const = 0;
59 virtual bool isLabelElement() const { return false; }
61 // Returns the 'name' attribute value. If this element has no name
62 // attribute, it returns an empty string instead of null string.
63 // Note that the 'name' IDL attribute doesn't use this function.
64 virtual const AtomicString& name() const;
66 // Override in derived classes to get the encoded name=value pair for submitting.
67 // Return true for a successful control (see HTML4-17.13.2).
68 virtual bool appendFormData(FormDataList&, bool) { return false; }
70 void resetFormOwner();
72 void formRemovedFromTree(const Node& formRoot);
74 // ValidityState attribute implementations
75 bool customError() const;
77 // Override functions for patterMismatch, rangeOverflow, rangerUnderflow,
78 // stepMismatch, tooLong, tooShort and valueMissing must call willValidate method.
79 virtual bool hasBadInput() const;
80 virtual bool patternMismatch() const;
81 virtual bool rangeOverflow() const;
82 virtual bool rangeUnderflow() const;
83 virtual bool stepMismatch() const;
84 virtual bool tooLong() const;
85 virtual bool tooShort() const;
86 virtual bool typeMismatch() const;
87 virtual bool valueMissing() const;
88 virtual String validationMessage() const;
89 bool valid() const;
90 virtual void setCustomValidity(const String&);
92 void formAttributeTargetChanged();
94 typedef WillBeHeapVector<RawPtrWillBeMember<FormAssociatedElement>> List;
96 DECLARE_VIRTUAL_TRACE();
98 protected:
99 FormAssociatedElement();
101 void insertedInto(ContainerNode*);
102 void removedFrom(ContainerNode*);
103 void didMoveToNewDocument(Document& oldDocument);
105 // FIXME: Remove usage of setForm. resetFormOwner should be enough, and
106 // setForm is confusing.
107 void setForm(HTMLFormElement*);
108 void associateByParser(HTMLFormElement*);
109 void formAttributeChanged();
111 // If you add an override of willChangeForm() or didChangeForm() to a class
112 // derived from this one, you will need to add a call to setForm(0) to the
113 // destructor of that class.
114 virtual void willChangeForm();
115 virtual void didChangeForm();
117 String customValidationMessage() const;
119 private:
120 #if !ENABLE(OILPAN)
121 virtual void refFormAssociatedElement() = 0;
122 virtual void derefFormAssociatedElement() = 0;
123 #endif
125 void setFormAttributeTargetObserver(PassOwnPtrWillBeRawPtr<FormAttributeTargetObserver>);
126 void resetFormAttributeTargetObserver();
128 OwnPtrWillBeMember<FormAttributeTargetObserver> m_formAttributeTargetObserver;
129 #if ENABLE(OILPAN)
130 Member<HTMLFormElement> m_form;
131 #else
132 WeakPtr<HTMLFormElement> m_form;
133 #endif
134 OwnPtrWillBeMember<ValidityState> m_validityState;
135 String m_customValidationMessage;
136 // Non-Oilpan: Even if m_formWasSetByParser is true, m_form can be null
137 // because parentNode is not a strong reference and |this| and m_form don't
138 // die together.
139 // Oilpan: If m_formWasSetByParser is true, m_form is always non-null.
140 bool m_formWasSetByParser;
143 HTMLElement* toHTMLElement(FormAssociatedElement*);
144 HTMLElement& toHTMLElement(FormAssociatedElement&);
145 const HTMLElement* toHTMLElement(const FormAssociatedElement*);
146 const HTMLElement& toHTMLElement(const FormAssociatedElement&);
148 } // namespace
150 #endif // FormAssociatedElement_h