OSDN Git Service

Merge commit 'remotes/korg/cupcake' into merge
[android-x86/external-webkit.git] / WebCore / wml / WMLTaskElement.cpp
1 /**
2  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "config.h"
22
23 #if ENABLE(WML)
24 #include "WMLTaskElement.h"
25
26 #include "WMLAnchorElement.h"
27 #include "WMLDoElement.h"
28 #include "WMLNames.h"
29 #include "WMLOnEventElement.h"
30 #include "WMLPageState.h"
31 #include "WMLSetvarElement.h"
32
33 namespace WebCore {
34
35 using namespace WMLNames;
36
37 WMLTaskElement::WMLTaskElement(const QualifiedName& tagName, Document* doc)
38     : WMLElement(tagName, doc)
39 {
40 }
41
42 WMLTaskElement::~WMLTaskElement()
43 {
44 }
45
46 void WMLTaskElement::insertedIntoDocument()
47 {
48     WMLElement::insertedIntoDocument();
49
50     Node* parent = parentNode();
51     ASSERT(parent);
52
53     if (!parent || !parent->isWMLElement())
54         return;
55
56     if (parent->hasTagName(anchorTag))
57         static_cast<WMLAnchorElement*>(parent)->registerTask(this);
58     else if (parent->hasTagName(doTag))
59         static_cast<WMLDoElement*>(parent)->registerTask(this);
60     else if (parent->hasTagName(oneventTag))
61         static_cast<WMLOnEventElement*>(parent)->registerTask(this);
62 }
63
64 void WMLTaskElement::registerVariableSetter(WMLSetvarElement* element)
65 {
66     ASSERT(element);
67     m_variableSetterElements.add(element);
68 }
69
70 void WMLTaskElement::storeVariableState(WMLPageState* pageState)
71 {
72     if (!pageState || m_variableSetterElements.isEmpty())
73         return;
74
75     WMLVariableMap variables;
76     HashSet<WMLSetvarElement*>::iterator it = m_variableSetterElements.begin();
77     HashSet<WMLSetvarElement*>::iterator end = m_variableSetterElements.end();
78
79     for (; it != end; ++it) {
80         WMLSetvarElement* setterElement = (*it);
81         if (setterElement->name().isEmpty())
82             continue;
83
84         variables.set(setterElement->name(), setterElement->value());
85     }
86
87     if (variables.isEmpty())
88         return;
89
90     pageState->storeVariables(variables);
91 }
92
93 }
94
95 #endif