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 "WMLTemplateElement.h"
26 #include "Attribute.h"
28 #include "WMLCardElement.h"
29 #include "WMLDocument.h"
30 #include "WMLIntrinsicEventHandler.h"
35 using namespace WMLNames;
37 WMLTemplateElement::WMLTemplateElement(const QualifiedName& tagName, Document* doc)
38 : WMLElement(tagName, doc)
42 WMLTemplateElement::~WMLTemplateElement()
46 PassRefPtr<WMLTemplateElement> WMLTemplateElement::create(const QualifiedName& tagName, Document* document)
48 return adoptRef(new WMLTemplateElement(tagName, document));
51 void WMLTemplateElement::parseMappedAttribute(Attribute* attr)
53 WMLIntrinsicEventType eventType = WMLIntrinsicEventUnknown;
55 if (attr->name() == onenterforwardAttr)
56 eventType = WMLIntrinsicEventOnEnterForward;
57 else if (attr->name() == onenterbackwardAttr)
58 eventType = WMLIntrinsicEventOnEnterBackward;
59 else if (attr->name() == ontimerAttr)
60 eventType = WMLIntrinsicEventOnTimer;
62 WMLElement::parseMappedAttribute(attr);
66 if (eventType == WMLIntrinsicEventUnknown)
69 // Register intrinsic event in card
70 RefPtr<WMLIntrinsicEvent> event = WMLIntrinsicEvent::create(document(), attr->value());
72 createEventHandlerIfNeeded();
73 eventHandler()->registerIntrinsicEvent(eventType, event);
76 void WMLTemplateElement::registerTemplatesInDocument(Document* doc)
80 // Build list of cards in document
81 RefPtr<NodeList> nodeList = doc->getElementsByTagName("card");
85 unsigned length = nodeList->length();
89 HashSet<WMLCardElement*> cards;
90 for (unsigned i = 0; i < length; ++i)
91 cards.add(static_cast<WMLCardElement*>(nodeList->item(i)));
96 // Register template element to all cards
97 nodeList = doc->getElementsByTagName("template");
101 length = nodeList->length();
105 // Only one template element should be allowed in a document
106 // Calling setTemplateElement() twice on a WMLCardElement, will result in a parser error.
107 for (unsigned i = 0; i < length; ++i) {
108 WMLTemplateElement* temp = static_cast<WMLTemplateElement*>(nodeList->item(i));
110 HashSet<WMLCardElement*>::iterator it = cards.begin();
111 HashSet<WMLCardElement*>::iterator end = cards.end();
113 for (; it != end; ++it)
114 (*it)->setTemplateElement(temp);