1 /** 2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 3 * 4 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 5 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 6 * (C) 2000 Simon Hausmann <hausmann (at) kde.org> 7 * Copyright (C) 2003, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 8 * (C) 2006 Graham Dennis (graham.dennis (at) gmail.com) 9 * 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. 14 * 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. 19 * 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. 24 * 25 */ 26 27 #include "config.h" 28 29 #if ENABLE(WML) 30 #include "WMLAElement.h" 31 32 #include "Attribute.h" 33 #include "Event.h" 34 #include "EventHandler.h" 35 #include "EventNames.h" 36 #include "Frame.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" 45 #include "WMLNames.h" 46 47 namespace WebCore { 48 49 using namespace WMLNames; 50 51 WMLAElement::WMLAElement(const QualifiedName& tagName, Document* doc) 52 : WMLElement(tagName, doc) 53 { 54 } 55 56 PassRefPtr<WMLAElement> WMLAElement::create(const QualifiedName& tagName, Document* document) 57 { 58 return adoptRef(new WMLAElement(tagName, document)); 59 } 60 61 void WMLAElement::parseMappedAttribute(Attribute* attr) 62 { 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)); 72 } 73 } else if (attr->name() == HTMLNames::nameAttr 74 || attr->name() == HTMLNames::titleAttr 75 || attr->name() == HTMLNames::relAttr) { 76 // Do nothing. 77 } else 78 WMLElement::parseMappedAttribute(attr); 79 } 80 81 bool WMLAElement::supportsFocus() const 82 { 83 return isLink() || WMLElement::supportsFocus(); 84 } 85 86 bool WMLAElement::isMouseFocusable() const 87 { 88 return false; 89 } 90 91 bool WMLAElement::isKeyboardFocusable(KeyboardEvent* event) const 92 { 93 if (!isFocusable()) 94 return false; 95 96 if (!document()->frame()) 97 return false; 98 99 if (!document()->frame()->eventHandler()->tabsToLinks(event)) 100 return false; 101 102 if (!renderer() || !renderer()->isBoxModelObject()) 103 return false; 104 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()) 109 return true; 110 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()) 117 return true; 118 119 return false; 120 } 121 122 void WMLAElement::defaultEventHandler(Event* event) 123 { 124 if (isLink()) { 125 if (focused() && isEnterKeyKeydownEvent(event)) { 126 event->setDefaultHandled(); 127 dispatchSimulatedClick(event); 128 return; 129 } 130 131 if (isLinkClick(event)) { 132 handleLinkClick(event, document(), stripLeadingAndTrailingHTMLSpaces(getAttribute(HTMLNames::hrefAttr)), target(), event); 133 return; 134 } 135 } 136 137 WMLElement::defaultEventHandler(event); 138 } 139 140 void WMLAElement::accessKeyAction(bool sendToAnyElement) 141 { 142 // send the mouse button events if the caller specified sendToAnyElement 143 dispatchSimulatedClick(0, sendToAnyElement); 144 } 145 146 bool WMLAElement::isURLAttribute(Attribute *attr) const 147 { 148 return attr->name() == HTMLNames::hrefAttr; 149 } 150 151 String WMLAElement::target() const 152 { 153 return getAttribute(HTMLNames::targetAttr); 154 } 155 156 } 157 158 #endif 159