• 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(), 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();
41 }
42 
create(const QualifiedName & tagName,Document * document)43 PassRefPtr<WMLAnchorElement> WMLAnchorElement::create(const QualifiedName& tagName, Document* document)
44 {
45     return adoptRef(new WMLAnchorElement(tagName, document));
46 }
47 
~WMLAnchorElement()48 WMLAnchorElement::~WMLAnchorElement()
49 {
50 }
51 
defaultEventHandler(Event * event)52 void WMLAnchorElement::defaultEventHandler(Event* event)
53 {
54     bool shouldHandle = false;
55 
56     if (event->type() == eventNames().clickEvent)
57         shouldHandle = true;
58     else if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent() && focused())
59         shouldHandle = static_cast<KeyboardEvent*>(event)->keyIdentifier() == "Enter";
60 
61     if (shouldHandle && m_task) {
62         m_task->executeTask();
63         event->setDefaultHandled();
64         return;
65     }
66 
67     // Skip WMLAElement::defaultEventHandler, we don't own a href attribute, that needs to be handled.
68     WMLElement::defaultEventHandler(event);
69 }
70 
registerTask(WMLTaskElement * task)71 void WMLAnchorElement::registerTask(WMLTaskElement* task)
72 {
73     ASSERT(!m_task);
74     m_task = task;
75 }
76 
deregisterTask(WMLTaskElement * task)77 void WMLAnchorElement::deregisterTask(WMLTaskElement* task)
78 {
79     ASSERT_UNUSED(task, m_task == task);
80     m_task = 0;
81 }
82 
83 }
84 
85 #endif
86