• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2008 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 "WMLAnchorElement.h"
25 
26 #include "EventNames.h"
27 #include "KeyboardEvent.h"
28 #include "WMLTaskElement.h"
29 #include "HTMLNames.h"
30 
31 namespace WebCore {
32 
WMLAnchorElement(const QualifiedName & tagName,Document * doc)33 WMLAnchorElement::WMLAnchorElement(const QualifiedName& tagName, Document* doc)
34     : WMLAElement(tagName, doc)
35     , m_task(0)
36 {
37     // Calling setIsLink(true), and returning a non-null value on CSSStyleSelectors' linkAttribute
38     // method, makes it possible to 'appear as link' (just like <a href="..">) without the need to
39     // actually set the href value to an empty value in the DOM tree.
40     setIsLink(true);
41 }
42 
~WMLAnchorElement()43 WMLAnchorElement::~WMLAnchorElement()
44 {
45 }
46 
defaultEventHandler(Event * event)47 void WMLAnchorElement::defaultEventHandler(Event* event)
48 {
49     bool shouldHandle = false;
50 
51     if (event->type() == eventNames().clickEvent)
52         shouldHandle = true;
53     else if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && focused())
54         shouldHandle = static_cast<KeyboardEvent*>(event)->keyIdentifier() == "Enter";
55 
56     if (shouldHandle && m_task) {
57         m_task->executeTask(event);
58         event->setDefaultHandled();
59         return;
60     }
61 
62     // Skip WMLAElement::defaultEventHandler, we don't own a href attribute, that needs to be handled.
63     WMLElement::defaultEventHandler(event);
64 }
65 
registerTask(WMLTaskElement * task)66 void WMLAnchorElement::registerTask(WMLTaskElement* task)
67 {
68     ASSERT(!m_task);
69     m_task = task;
70 }
71 
deregisterTask(WMLTaskElement * task)72 void WMLAnchorElement::deregisterTask(WMLTaskElement* task)
73 {
74     ASSERT(m_task == task);
75     m_task = 0;
76 }
77 
78 }
79 
80 #endif
81