2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5 * (C) 1999 Antti Koivisto (koivisto@kde.org)
6 * (C) 2000 Simon Hausmann <hausmann@kde.org>
7 * Copyright (C) 2003, 2006, 2007, 2008 Apple Inc. All rights reserved.
8 * (C) 2006 Graham Dennis (graham.dennis@gmail.com)
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
30 #include "WMLAElement.h"
32 #include "Attribute.h"
34 #include "EventHandler.h"
35 #include "EventNames.h"
37 #include "FrameLoader.h"
38 #include "HTMLNames.h"
39 #include "KeyboardEvent.h"
40 #include "MouseEvent.h"
41 #include "RenderBox.h"
42 #include "ResourceHandle.h"
47 using namespace WMLNames;
49 WMLAElement::WMLAElement(const QualifiedName& tagName, Document* doc)
50 : WMLElement(tagName, doc)
54 void WMLAElement::parseMappedAttribute(Attribute* attr)
56 if (attr->name() == HTMLNames::hrefAttr) {
57 bool wasLink = isLink();
58 setIsLink(!attr->isNull());
59 if (wasLink != isLink())
60 setNeedsStyleRecalc();
61 if (isLink() && document()->isDNSPrefetchEnabled()) {
62 String value = attr->value();
63 if (protocolIs(value, "http") || protocolIs(value, "https") || value.startsWith("//"))
64 ResourceHandle::prepareForURL(document()->completeURL(value));
66 } else if (attr->name() == HTMLNames::nameAttr
67 || attr->name() == HTMLNames::titleAttr
68 || attr->name() == HTMLNames::relAttr) {
71 WMLElement::parseMappedAttribute(attr);
74 bool WMLAElement::supportsFocus() const
76 return isLink() || WMLElement::supportsFocus();
79 bool WMLAElement::isMouseFocusable() const
84 bool WMLAElement::isKeyboardFocusable(KeyboardEvent* event) const
89 if (!document()->frame())
92 if (!document()->frame()->eventHandler()->tabsToLinks(event))
95 if (!renderer() || !renderer()->isBoxModelObject())
98 // Before calling absoluteRects, check for the common case where the renderer
99 // is non-empty, since this is a faster check and almost always returns true.
100 RenderBoxModelObject* box = toRenderBoxModelObject(renderer());
101 if (!box->borderBoundingBox().isEmpty())
104 Vector<IntRect> rects;
105 FloatPoint absPos = renderer()->localToAbsolute();
106 renderer()->absoluteRects(rects, absPos.x(), absPos.y());
107 size_t n = rects.size();
108 for (size_t i = 0; i < n; ++i)
109 if (!rects[i].isEmpty())
115 void WMLAElement::defaultEventHandler(Event* event)
117 if (isLink() && (event->type() == eventNames().clickEvent || (event->type() == eventNames().keydownEvent && focused()))) {
119 if (event->type() == eventNames().clickEvent && event->isMouseEvent())
120 e = static_cast<MouseEvent*>(event);
122 KeyboardEvent* k = 0;
123 if (event->type() == eventNames().keydownEvent && event->isKeyboardEvent())
124 k = static_cast<KeyboardEvent*>(event);
126 if (e && e->button() == RightButton) {
127 WMLElement::defaultEventHandler(event);
132 if (k->keyIdentifier() != "Enter") {
133 WMLElement::defaultEventHandler(event);
137 event->setDefaultHandled();
138 dispatchSimulatedClick(event);
142 if (!event->defaultPrevented() && document()->frame()) {
143 KURL url = document()->completeURL(deprecatedParseURL(getAttribute(HTMLNames::hrefAttr)));
144 document()->frame()->loader()->urlSelected(url, target(), event, false, false, true, SendReferrer);
147 event->setDefaultHandled();
150 WMLElement::defaultEventHandler(event);
153 void WMLAElement::accessKeyAction(bool sendToAnyElement)
155 // send the mouse button events if the caller specified sendToAnyElement
156 dispatchSimulatedClick(0, sendToAnyElement);
159 bool WMLAElement::isURLAttribute(Attribute *attr) const
161 return attr->name() == HTMLNames::hrefAttr;
164 String WMLAElement::target() const
166 return getAttribute(HTMLNames::targetAttr);