1 /** 2 * Copyright (C) 2008, 2009 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 "WMLEventHandlingElement.h" 25 26 #include "WMLCardElement.h" 27 #include "WMLDoElement.h" 28 #include "WMLIntrinsicEventHandler.h" 29 #include "WMLOptionElement.h" 30 #include "WMLTaskElement.h" 31 #include "WMLTemplateElement.h" 32 #include "WMLNames.h" 33 34 namespace WebCore { 35 36 using namespace WMLNames; 37 38 WMLEventHandlingElement::WMLEventHandlingElement() 39 { 40 } 41 42 WMLEventHandlingElement::~WMLEventHandlingElement() 43 { 44 } 45 46 void WMLEventHandlingElement::createEventHandlerIfNeeded() 47 { 48 if (!m_eventHandler) 49 m_eventHandler.set(new WMLIntrinsicEventHandler); 50 } 51 52 void WMLEventHandlingElement::registerDoElement(WMLDoElement* doElement, Document* document) 53 { 54 Vector<WMLDoElement*>::iterator it = m_doElements.begin(); 55 Vector<WMLDoElement*>::iterator end = m_doElements.end(); 56 57 for (; it != end; ++it) { 58 if ((*it)->name() == doElement->name()) { 59 reportWMLError(document, WMLErrorDuplicatedDoElement); 60 return; 61 } 62 } 63 64 ASSERT(m_doElements.find(doElement) == WTF::notFound); 65 m_doElements.append(doElement); 66 doElement->setActive(true); 67 } 68 69 void WMLEventHandlingElement::deregisterDoElement(WMLDoElement* doElement) 70 { 71 doElement->setActive(false); 72 73 size_t position = m_doElements.find(doElement); 74 if (position == WTF::notFound) 75 return; 76 77 m_doElements.remove(position); 78 } 79 80 WMLEventHandlingElement* toWMLEventHandlingElement(WMLElement* element) 81 { 82 if (!element->isWMLElement()) 83 return 0; 84 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); 91 92 return 0; 93 } 94 95 } 96 97 #endif 98