Home | History | Annotate | Download | only in html
      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 "HTMLNames.h"
     28 #include "core/dom/DOMURLUtils.h"
     29 #include "core/html/HTMLElement.h"
     30 #include "platform/LinkHash.h"
     31 
     32 namespace WebCore {
     33 
     34 // Link relation bitmask values.
     35 // FIXME: Uncomment as the various link relations are implemented.
     36 enum {
     37 //     RelationAlternate   = 0x00000001,
     38 //     RelationArchives    = 0x00000002,
     39 //     RelationAuthor      = 0x00000004,
     40 //     RelationBoomark     = 0x00000008,
     41 //     RelationExternal    = 0x00000010,
     42 //     RelationFirst       = 0x00000020,
     43 //     RelationHelp        = 0x00000040,
     44 //     RelationIndex       = 0x00000080,
     45 //     RelationLast        = 0x00000100,
     46 //     RelationLicense     = 0x00000200,
     47 //     RelationNext        = 0x00000400,
     48 //     RelationNoFolow    = 0x00000800,
     49     RelationNoReferrer     = 0x00001000,
     50 //     RelationPrev        = 0x00002000,
     51 //     RelationSearch      = 0x00004000,
     52 //     RelationSidebar     = 0x00008000,
     53 //     RelationTag         = 0x00010000,
     54 //     RelationUp          = 0x00020000,
     55 };
     56 
     57 class HTMLAnchorElement : public HTMLElement, public DOMURLUtils {
     58 public:
     59     static PassRefPtr<HTMLAnchorElement> create(Document&);
     60     static PassRefPtr<HTMLAnchorElement> create(const QualifiedName&, 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;
     70     virtual void setURL(const KURL&) OVERRIDE;
     71 
     72     virtual String input() const OVERRIDE;
     73     virtual void setInput(const String&) OVERRIDE;
     74 
     75     String text();
     76 
     77     bool isLiveLink() const;
     78 
     79     virtual bool willRespondToMouseClickEvents() OVERRIDE;
     80 
     81     bool hasRel(uint32_t relation) const;
     82     void setRel(const String&);
     83 
     84     LinkHash visitedLinkHash() const;
     85     void invalidateCachedVisitedLinkHash() { m_cachedVisitedLinkHash = 0; }
     86 
     87 protected:
     88     HTMLAnchorElement(const QualifiedName&, Document&);
     89 
     90     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
     91 
     92 private:
     93     virtual bool supportsFocus() const;
     94     virtual bool isMouseFocusable() const;
     95     virtual bool isKeyboardFocusable() const OVERRIDE;
     96     virtual void defaultEventHandler(Event*);
     97     virtual void setActive(bool = true) OVERRIDE FINAL;
     98     virtual void accessKeyAction(bool sendMouseEvents);
     99     virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    100     virtual bool canStartSelection() const;
    101     virtual String target() const;
    102     virtual short tabIndex() const;
    103     virtual bool draggable() const;
    104     virtual bool isInteractiveContent() const OVERRIDE;
    105 
    106     void sendPings(const KURL& destinationURL);
    107 
    108     void handleClick(Event*);
    109 
    110     enum EventType {
    111         MouseEventWithoutShiftKey,
    112         MouseEventWithShiftKey,
    113         NonMouseEvent,
    114     };
    115     static EventType eventType(Event*);
    116     bool treatLinkAsLiveForEventType(EventType) const;
    117 
    118     Element* rootEditableElementForSelectionOnMouseDown() const;
    119     void setRootEditableElementForSelectionOnMouseDown(Element*);
    120     void clearRootEditableElementForSelectionOnMouseDown();
    121 
    122     class PrefetchEventHandler;
    123     PrefetchEventHandler* prefetchEventHandler();
    124 
    125     bool m_hasRootEditableElementForSelectionOnMouseDown : 1;
    126     bool m_wasShiftKeyDownOnMouseDown : 1;
    127     uint32_t m_linkRelations : 30;
    128     OwnPtr<PrefetchEventHandler> m_prefetchEventHandler;
    129     mutable LinkHash m_cachedVisitedLinkHash;
    130 };
    131 
    132 inline LinkHash HTMLAnchorElement::visitedLinkHash() const
    133 {
    134     if (!m_cachedVisitedLinkHash)
    135         m_cachedVisitedLinkHash = WebCore::visitedLinkHash(document().baseURL(), fastGetAttribute(HTMLNames::hrefAttr));
    136     return m_cachedVisitedLinkHash;
    137 }
    138 
    139 // Functions shared with the other anchor elements (i.e., SVG).
    140 
    141 bool isEnterKeyKeydownEvent(Event*);
    142 bool isLinkClick(Event*);
    143 
    144 inline bool isHTMLAnchorElement(const Node* node)
    145 {
    146     return node->hasTagName(HTMLNames::aTag);
    147 }
    148 
    149 inline bool isHTMLAnchorElement(const Element* element)
    150 {
    151     return element->hasTagName(HTMLNames::aTag);
    152 }
    153 
    154 inline bool isHTMLAnchorElement(const Element& element)
    155 {
    156     return element.hasTagName(HTMLNames::aTag);
    157 }
    158 
    159 DEFINE_NODE_TYPE_CASTS(HTMLAnchorElement, hasTagName(HTMLNames::aTag));
    160 
    161 } // namespace WebCore
    162 
    163 #endif // HTMLAnchorElement_h
    164