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, 2010 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 "HTMLAnchorElement.h"
39 #include "HTMLNames.h"
40 #include "HTMLParserIdioms.h"
41 #include "KeyboardEvent.h"
42 #include "MouseEvent.h"
43 #include "RenderBox.h"
44 #include "ResourceHandle.h"
49 using namespace WMLNames;
51 WMLAElement::WMLAElement(const QualifiedName& tagName, Document* doc)
52 : WMLElement(tagName, doc)
56 PassRefPtr<WMLAElement> WMLAElement::create(const QualifiedName& tagName, Document* document)
58 return adoptRef(new WMLAElement(tagName, document));
61 void WMLAElement::parseMappedAttribute(Attribute* attr)
63 if (attr->name() == HTMLNames::hrefAttr) {
64 bool wasLink = isLink();
65 setIsLink(!attr->isNull());
66 if (wasLink != isLink())
67 setNeedsStyleRecalc();
68 if (isLink() && document()->isDNSPrefetchEnabled()) {
69 String value = attr->value();
70 if (protocolIs(value, "http") || protocolIs(value, "https") || value.startsWith("//"))
71 ResourceHandle::prepareForURL(document()->completeURL(value));
73 } else if (attr->name() == HTMLNames::nameAttr
74 || attr->name() == HTMLNames::titleAttr
75 || attr->name() == HTMLNames::relAttr) {
78 WMLElement::parseMappedAttribute(attr);
81 bool WMLAElement::supportsFocus() const
83 return isLink() || WMLElement::supportsFocus();
86 bool WMLAElement::isMouseFocusable() const
91 bool WMLAElement::isKeyboardFocusable(KeyboardEvent* event) const
96 if (!document()->frame())
99 if (!document()->frame()->eventHandler()->tabsToLinks(event))
102 if (!renderer() || !renderer()->isBoxModelObject())
105 // Before calling absoluteRects, check for the common case where the renderer
106 // is non-empty, since this is a faster check and almost always returns true.
107 RenderBoxModelObject* box = toRenderBoxModelObject(renderer());
108 if (!box->borderBoundingBox().isEmpty())
111 Vector<IntRect> rects;
112 FloatPoint absPos = renderer()->localToAbsolute();
113 renderer()->absoluteRects(rects, absPos.x(), absPos.y());
114 size_t n = rects.size();
115 for (size_t i = 0; i < n; ++i)
116 if (!rects[i].isEmpty())
122 void WMLAElement::defaultEventHandler(Event* event)
125 if (focused() && isEnterKeyKeydownEvent(event)) {
126 event->setDefaultHandled();
127 dispatchSimulatedClick(event);
131 if (isLinkClick(event)) {
132 handleLinkClick(event, document(), stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames::hrefAttr)), target(), event);
137 WMLElement::defaultEventHandler(event);
140 void WMLAElement::accessKeyAction(bool sendToAnyElement)
142 // send the mouse button events if the caller specified sendToAnyElement
143 dispatchSimulatedClick(0, sendToAnyElement);
146 bool WMLAElement::isURLAttribute(Attribute *attr) const
148 return attr->name() == HTMLNames::hrefAttr;
151 String WMLAElement::target() const
153 return getAttribute(HTMLNames::targetAttr);