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