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 "WMLEventHandlingElement.h"
26 #include "WMLCardElement.h"
27 #include "WMLDoElement.h"
28 #include "WMLIntrinsicEventHandler.h"
29 #include "WMLOptionElement.h"
30 #include "WMLTaskElement.h"
31 #include "WMLTemplateElement.h"
36 using namespace WMLNames;
38 WMLEventHandlingElement::WMLEventHandlingElement()
42 WMLEventHandlingElement::~WMLEventHandlingElement()
46 void WMLEventHandlingElement::createEventHandlerIfNeeded()
49 m_eventHandler.set(new WMLIntrinsicEventHandler);
52 void WMLEventHandlingElement::registerDoElement(WMLDoElement* doElement, Document* document)
54 Vector<WMLDoElement*>::iterator it = m_doElements.begin();
55 Vector<WMLDoElement*>::iterator end = m_doElements.end();
57 for (; it != end; ++it) {
58 if ((*it)->name() == doElement->name()) {
59 reportWMLError(document, WMLErrorDuplicatedDoElement);
64 ASSERT(m_doElements.find(doElement) == WTF::notFound);
65 m_doElements.append(doElement);
66 doElement->setActive(true);
69 void WMLEventHandlingElement::deregisterDoElement(WMLDoElement* doElement)
71 doElement->setActive(false);
73 size_t position = m_doElements.find(doElement);
74 if (position == WTF::notFound)
77 m_doElements.remove(position);
80 WMLEventHandlingElement* toWMLEventHandlingElement(WMLElement* element)
82 if (!element->isWMLElement())
85 if (element->hasTagName(cardTag))
86 return static_cast<WMLCardElement*>(element);
87 else if (element->hasTagName(optionTag))
88 return static_cast<WMLOptionElement*>(element);
89 else if (element->hasTagName(templateTag))
90 return static_cast<WMLTemplateElement*>(element);