1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * (C) 2000 Simon Hausmann <hausmann (at) kde.org> 5 * Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 * 22 */ 23 24 #ifndef HTMLAnchorElement_h 25 #define HTMLAnchorElement_h 26 27 #include "core/HTMLNames.h" 28 #include "core/dom/DOMURLUtils.h" 29 #include "core/dom/Document.h" 30 #include "core/html/HTMLElement.h" 31 #include "platform/LinkHash.h" 32 33 namespace WebCore { 34 35 // Link relation bitmask values. 36 // FIXME: Uncomment as the various link relations are implemented. 37 enum { 38 // RelationAlternate = 0x00000001, 39 // RelationArchives = 0x00000002, 40 // RelationAuthor = 0x00000004, 41 // RelationBoomark = 0x00000008, 42 // RelationExternal = 0x00000010, 43 // RelationFirst = 0x00000020, 44 // RelationHelp = 0x00000040, 45 // RelationIndex = 0x00000080, 46 // RelationLast = 0x00000100, 47 // RelationLicense = 0x00000200, 48 // RelationNext = 0x00000400, 49 // RelationNoFolow = 0x00000800, 50 RelationNoReferrer = 0x00001000, 51 // RelationPrev = 0x00002000, 52 // RelationSearch = 0x00004000, 53 // RelationSidebar = 0x00008000, 54 // RelationTag = 0x00010000, 55 // RelationUp = 0x00020000, 56 }; 57 58 class HTMLAnchorElement : public HTMLElement, public DOMURLUtils { 59 public: 60 static PassRefPtrWillBeRawPtr<HTMLAnchorElement> create(Document&); 61 62 virtual ~HTMLAnchorElement(); 63 64 KURL href() const; 65 void setHref(const AtomicString&); 66 67 const AtomicString& name() const; 68 69 virtual KURL url() const OVERRIDE FINAL; 70 virtual void setURL(const KURL&) OVERRIDE FINAL; 71 72 virtual String input() const OVERRIDE FINAL; 73 virtual void setInput(const String&) OVERRIDE FINAL; 74 75 bool isLiveLink() const; 76 77 virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL; 78 79 bool hasRel(uint32_t relation) const; 80 void setRel(const AtomicString&); 81 82 LinkHash visitedLinkHash() const; 83 void invalidateCachedVisitedLinkHash() { m_cachedVisitedLinkHash = 0; } 84 85 virtual void trace(Visitor*) OVERRIDE; 86 87 protected: 88 HTMLAnchorElement(const QualifiedName&, Document&); 89 90 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 91 virtual bool supportsFocus() const OVERRIDE; 92 93 private: 94 virtual bool isMouseFocusable() const OVERRIDE; 95 virtual bool isKeyboardFocusable() const OVERRIDE; 96 virtual void defaultEventHandler(Event*) OVERRIDE FINAL; 97 virtual void setActive(bool = true) OVERRIDE FINAL; 98 virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE FINAL; 99 virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL; 100 virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL; 101 virtual bool canStartSelection() const OVERRIDE FINAL; 102 virtual short tabIndex() const OVERRIDE FINAL; 103 virtual bool draggable() const OVERRIDE FINAL; 104 virtual bool isInteractiveContent() const OVERRIDE FINAL; 105 106 void sendPings(const KURL& destinationURL); 107 AtomicString target() const; 108 void handleClick(Event*); 109 110 class PrefetchEventHandler; 111 PrefetchEventHandler* prefetchEventHandler(); 112 113 uint32_t m_linkRelations; 114 OwnPtrWillBeMember<PrefetchEventHandler> m_prefetchEventHandler; 115 mutable LinkHash m_cachedVisitedLinkHash; 116 }; 117 118 inline LinkHash HTMLAnchorElement::visitedLinkHash() const 119 { 120 if (!m_cachedVisitedLinkHash) 121 m_cachedVisitedLinkHash = WebCore::visitedLinkHash(document().baseURL(), fastGetAttribute(HTMLNames::hrefAttr)); 122 return m_cachedVisitedLinkHash; 123 } 124 125 // Functions shared with the other anchor elements (i.e., SVG). 126 127 bool isEnterKeyKeydownEvent(Event*); 128 bool isLinkClick(Event*); 129 130 } // namespace WebCore 131 132 #endif // HTMLAnchorElement_h 133