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