2 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
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.
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.
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.
24 #include "WMLDoElement.h"
26 #include "Attribute.h"
28 #include "EventNames.h"
29 #include "HTMLNames.h"
30 #include "KeyboardEvent.h"
32 #include "RenderButton.h"
33 #include "WMLCardElement.h"
34 #include "WMLDocument.h"
36 #include "WMLPageState.h"
37 #include "WMLTaskElement.h"
38 #include "WMLTimerElement.h"
39 #include "WMLVariables.h"
43 using namespace WMLNames;
45 WMLDoElement::WMLDoElement(const QualifiedName& tagName, Document* doc)
46 : WMLElement(tagName, doc)
54 PassRefPtr<WMLDoElement> WMLDoElement::create(const QualifiedName& tagName, Document* document)
56 return adoptRef(new WMLDoElement(tagName, document));
59 void WMLDoElement::defaultEventHandler(Event* event)
64 if (event->type() == eventNames().keypressEvent) {
65 WMLElement::defaultEventHandler(event);
69 if (event->type() != eventNames().clickEvent && event->type() != eventNames().keydownEvent)
72 if (event->isKeyboardEvent()
73 && static_cast<KeyboardEvent*>(event)->keyIdentifier() != "Enter")
76 if (m_type == "accept" || m_type == "options") {
78 m_task->executeTask();
79 } else if (m_type == "prev") {
80 ASSERT(document()->isWMLDocument());
81 WMLDocument* document = static_cast<WMLDocument*>(this->document());
83 WMLPageState* pageState = wmlPageStateForDocument(document);
87 // Stop the timer of the current card if it is active
88 if (WMLCardElement* card = document->activeCard()) {
89 if (WMLTimerElement* eventTimer = card->eventTimer())
93 pageState->page()->backForward()->goBack();
94 } else if (m_type == "reset") {
95 WMLPageState* pageState = wmlPageStateForDocument(document());
103 void WMLDoElement::parseMappedAttribute(Attribute* attr)
105 if (attr->name() == HTMLNames::typeAttr)
106 m_type = parseValueForbiddingVariableReferences(attr->value());
107 else if (attr->name() == HTMLNames::nameAttr)
108 m_name = parseValueForbiddingVariableReferences(attr->value());
109 else if (attr->name() == optionalAttr)
110 m_isOptional = (attr->value() == "true");
112 WMLElement::parseMappedAttribute(attr);
115 void WMLDoElement::insertedIntoDocument()
117 WMLElement::insertedIntoDocument();
119 // Spec: An unspecified 'name' defaults to the value of the 'type' attribute.
120 if (!hasAttribute(HTMLNames::nameAttr))
123 ContainerNode* parent = parentNode();
124 if (!parent || !parent->isWMLElement())
127 if (WMLEventHandlingElement* eventHandlingElement = toWMLEventHandlingElement(static_cast<WMLElement*>(parent)))
128 eventHandlingElement->registerDoElement(this, document());
131 void WMLDoElement::removedFromDocument()
133 ContainerNode* parent = parentNode();
135 if (parent && parent->isWMLElement()) {
136 if (WMLEventHandlingElement* eventHandlingElement = toWMLEventHandlingElement(static_cast<WMLElement*>(parent)))
137 eventHandlingElement->deregisterDoElement(this);
140 WMLElement::removedFromDocument();
143 void WMLDoElement::attach()
145 WMLElement::attach();
147 // The call to updateFromElement() needs to go after the call through
148 // to the base class's attach() because that can sometimes do a close
151 renderer()->updateFromElement();
154 RenderObject* WMLDoElement::createRenderer(RenderArena* arena, RenderStyle* style)
156 if (!m_isActive || m_isOptional || m_isNoop)
161 style->setBackgroundColor(Color::lightGray);
164 return new (arena) RenderButton(this);
167 void WMLDoElement::recalcStyle(StyleChange change)
169 WMLElement::recalcStyle(change);
172 renderer()->updateFromElement();
175 void WMLDoElement::registerTask(WMLTaskElement* task)
181 void WMLDoElement::deregisterTask(WMLTaskElement* task)
183 ASSERT_UNUSED(task, m_task == task);
187 String WMLDoElement::label() const
189 return parseValueSubstitutingVariableReferences(getAttribute(HTMLNames::labelAttr));