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 "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 blink {
     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     DEFINE_WRAPPERTYPEINFO();
     60 public:
     61     static PassRefPtrWillBeRawPtr<HTMLAnchorElement> create(Document&);
     62 
     63     virtual ~HTMLAnchorElement();
     64 
     65     KURL href() const;
     66     void setHref(const AtomicString&);
     67 
     68     const AtomicString& name() const;
     69 
     70     virtual KURL url() const OVERRIDE FINAL;
     71     virtual void setURL(const KURL&) OVERRIDE FINAL;
     72 
     73     virtual String input() const OVERRIDE FINAL;
     74     virtual void setInput(const String&) OVERRIDE FINAL;
     75 
     76     virtual bool isLiveLink() const OVERRIDE FINAL;
     77 
     78     virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL;
     79 
     80     bool hasRel(uint32_t relation) const;
     81     void setRel(const AtomicString&);
     82 
     83     LinkHash visitedLinkHash() const;
     84     void invalidateCachedVisitedLinkHash() { m_cachedVisitedLinkHash = 0; }
     85 
     86     void sendPings(const KURL& destinationURL) const;
     87 
     88 protected:
     89     HTMLAnchorElement(const QualifiedName&, Document&);
     90 
     91     virtual void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) OVERRIDE;
     92     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
     93     virtual bool supportsFocus() const OVERRIDE;
     94 
     95 private:
     96     virtual bool shouldHaveFocusAppearance() const OVERRIDE FINAL;
     97     virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE;
     98     virtual bool isMouseFocusable() const OVERRIDE;
     99     virtual bool isKeyboardFocusable() const OVERRIDE;
    100     virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
    101     virtual void setActive(bool = true) OVERRIDE FINAL;
    102     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE FINAL;
    103     virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL;
    104     virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL;
    105     virtual bool canStartSelection() const OVERRIDE FINAL;
    106     virtual short tabIndex() const OVERRIDE FINAL;
    107     virtual bool draggable() const OVERRIDE FINAL;
    108     virtual bool isInteractiveContent() const OVERRIDE FINAL;
    109     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
    110     void handleClick(Event*);
    111 
    112     uint32_t m_linkRelations;
    113     mutable LinkHash m_cachedVisitedLinkHash;
    114     bool m_wasFocusedByMouse;
    115 };
    116 
    117 inline LinkHash HTMLAnchorElement::visitedLinkHash() const
    118 {
    119     if (!m_cachedVisitedLinkHash)
    120         m_cachedVisitedLinkHash = blink::visitedLinkHash(document().baseURL(), fastGetAttribute(HTMLNames::hrefAttr));
    121     return m_cachedVisitedLinkHash;
    122 }
    123 
    124 // Functions shared with the other anchor elements (i.e., SVG).
    125 
    126 bool isEnterKeyKeydownEvent(Event*);
    127 bool isLinkClick(Event*);
    128 
    129 } // namespace blink
    130 
    131 #endif // HTMLAnchorElement_h
    132