Home | History | Annotate | Download | only in wml
      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 "WMLOnEventElement.h"
     25 
     26 #include "Attribute.h"
     27 #include "HTMLNames.h"
     28 #include "WMLErrorHandling.h"
     29 #include "WMLEventHandlingElement.h"
     30 #include "WMLIntrinsicEventHandler.h"
     31 #include "WMLNames.h"
     32 #include "WMLVariables.h"
     33 
     34 namespace WebCore {
     35 
     36 using namespace WMLNames;
     37 
     38 WMLOnEventElement::WMLOnEventElement(const QualifiedName& tagName, Document* doc)
     39     : WMLElement(tagName, doc)
     40     , m_type(WMLIntrinsicEventUnknown)
     41 {
     42 }
     43 
     44 PassRefPtr<WMLOnEventElement> WMLOnEventElement::create(const QualifiedName& tagName, Document* document)
     45 {
     46     return adoptRef(new WMLOnEventElement(tagName, document));
     47 }
     48 
     49 void WMLOnEventElement::parseMappedAttribute(Attribute* attr)
     50 {
     51     if (attr->name() == HTMLNames::typeAttr) {
     52         String parsedValue = parseValueForbiddingVariableReferences(attr->value());
     53         if (parsedValue.isEmpty())
     54             return;
     55 
     56         if (parsedValue == onenterforwardAttr)
     57             m_type = WMLIntrinsicEventOnEnterForward;
     58         else if (parsedValue == onenterbackwardAttr)
     59             m_type = WMLIntrinsicEventOnEnterBackward;
     60         else if (parsedValue == ontimerAttr)
     61             m_type = WMLIntrinsicEventOnTimer;
     62         else if (parsedValue == onpickAttr)
     63             m_type = WMLIntrinsicEventOnPick;
     64     } else
     65         WMLElement::parseMappedAttribute(attr);
     66 }
     67 
     68 static inline WMLEventHandlingElement* eventHandlingParent(Node* parent)
     69 {
     70     if (!parent || !parent->isWMLElement())
     71         return 0;
     72 
     73     return toWMLEventHandlingElement(static_cast<WMLElement*>(parent));
     74 }
     75 
     76 void WMLOnEventElement::registerTask(WMLTaskElement* task)
     77 {
     78     if (m_type == WMLIntrinsicEventUnknown)
     79         return;
     80 
     81     // Register intrinsic event to the event handler of the owner of onevent element
     82     WMLEventHandlingElement* eventHandlingElement = eventHandlingParent(parentNode());
     83     if (!eventHandlingElement)
     84         return;
     85 
     86     eventHandlingElement->createEventHandlerIfNeeded();
     87 
     88     RefPtr<WMLIntrinsicEvent> event = WMLIntrinsicEvent::createWithTask(task);
     89     if (!eventHandlingElement->eventHandler()->registerIntrinsicEvent(m_type, event))
     90         reportWMLError(document(), WMLErrorConflictingEventBinding);
     91 }
     92 
     93 void WMLOnEventElement::deregisterTask(WMLTaskElement*)
     94 {
     95     WMLEventHandlingElement* eventHandlingElement = eventHandlingParent(parentNode());
     96     if (!eventHandlingElement)
     97         return;
     98 
     99     eventHandlingElement->eventHandler()->deregisterIntrinsicEvent(m_type);
    100 }
    101 
    102 }
    103 
    104 #endif
    105