Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLFormControlElementWithState.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2001 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6  *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #include "config.h"
26 #include "core/html/HTMLFormControlElementWithState.h"
27
28 #include "core/frame/FrameHost.h"
29 #include "core/frame/LocalFrame.h"
30 #include "core/html/HTMLFormElement.h"
31 #include "core/html/forms/FormController.h"
32 #include "core/loader/FrameLoaderClient.h"
33 #include "core/page/Chrome.h"
34 #include "core/page/ChromeClient.h"
35
36 namespace blink {
37
38 HTMLFormControlElementWithState::HTMLFormControlElementWithState(const QualifiedName& tagName, Document& doc, HTMLFormElement* f)
39     : HTMLFormControlElement(tagName, doc, f)
40 {
41 }
42
43 HTMLFormControlElementWithState::~HTMLFormControlElementWithState()
44 {
45 }
46
47 Node::InsertionNotificationRequest HTMLFormControlElementWithState::insertedInto(ContainerNode* insertionPoint)
48 {
49     if (insertionPoint->inDocument() && !containingShadowRoot())
50         document().formController().registerStatefulFormControl(*this);
51     return HTMLFormControlElement::insertedInto(insertionPoint);
52 }
53
54 void HTMLFormControlElementWithState::removedFrom(ContainerNode* insertionPoint)
55 {
56     if (insertionPoint->inDocument() && !containingShadowRoot() && !insertionPoint->containingShadowRoot())
57         document().formController().unregisterStatefulFormControl(*this);
58     HTMLFormControlElement::removedFrom(insertionPoint);
59 }
60
61 bool HTMLFormControlElementWithState::shouldAutocomplete() const
62 {
63     if (!form())
64         return true;
65     return form()->shouldAutocomplete();
66 }
67
68 void HTMLFormControlElementWithState::notifyFormStateChanged()
69 {
70     // This can be called during fragment parsing as a result of option
71     // selection before the document is active (or even in a frame).
72     if (!document().isActive())
73         return;
74     document().frame()->loader().client()->didUpdateCurrentHistoryItem();
75 }
76
77 bool HTMLFormControlElementWithState::shouldSaveAndRestoreFormControlState() const
78 {
79     // We don't save/restore control state in a form with autocomplete=off.
80     return inDocument() && shouldAutocomplete();
81 }
82
83 FormControlState HTMLFormControlElementWithState::saveFormControlState() const
84 {
85     return FormControlState();
86 }
87
88 void HTMLFormControlElementWithState::finishParsingChildren()
89 {
90     HTMLFormControlElement::finishParsingChildren();
91     document().formController().restoreControlStateFor(*this);
92 }
93
94 bool HTMLFormControlElementWithState::isFormControlElementWithState() const
95 {
96     return true;
97 }
98
99 } // namespace blink