d7215b9e729dca0973a0b6cca057996475cf4f44
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / HTMLAnchorElement.h
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Simon Hausmann <hausmann@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 PassRefPtrWillBeRawPtr<HTMLAnchorElement> create(Document&);
60
61     virtual ~HTMLAnchorElement();
62
63     KURL href() const;
64     void setHref(const AtomicString&);
65
66     const AtomicString& name() const;
67
68     virtual KURL url() const OVERRIDE FINAL;
69     virtual void setURL(const KURL&) OVERRIDE FINAL;
70
71     virtual String input() const OVERRIDE FINAL;
72     virtual void setInput(const String&) OVERRIDE FINAL;
73
74     bool isLiveLink() const;
75
76     virtual bool willRespondToMouseClickEvents() OVERRIDE FINAL;
77
78     bool hasRel(uint32_t relation) const;
79     void setRel(const AtomicString&);
80
81     LinkHash visitedLinkHash() const;
82     void invalidateCachedVisitedLinkHash() { m_cachedVisitedLinkHash = 0; }
83
84 protected:
85     HTMLAnchorElement(const QualifiedName&, Document&);
86
87     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
88     virtual bool supportsFocus() const OVERRIDE;
89
90 private:
91     virtual bool isMouseFocusable() const OVERRIDE;
92     virtual bool isKeyboardFocusable() const OVERRIDE;
93     virtual void defaultEventHandler(Event*) OVERRIDE FINAL;
94     virtual void setActive(bool = true) OVERRIDE FINAL;
95     virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE FINAL;
96     virtual bool isURLAttribute(const Attribute&) const OVERRIDE FINAL;
97     virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE FINAL;
98     virtual bool canStartSelection() const OVERRIDE FINAL;
99     virtual short tabIndex() const OVERRIDE FINAL;
100     virtual bool draggable() const OVERRIDE FINAL;
101     virtual bool isInteractiveContent() const OVERRIDE FINAL;
102
103     void sendPings(const KURL& destinationURL);
104     AtomicString target() const;
105     void handleClick(Event*);
106
107     class PrefetchEventHandler;
108     PrefetchEventHandler* prefetchEventHandler();
109
110     uint32_t m_linkRelations;
111     OwnPtr<PrefetchEventHandler> m_prefetchEventHandler;
112     mutable LinkHash m_cachedVisitedLinkHash;
113 };
114
115 inline LinkHash HTMLAnchorElement::visitedLinkHash() const
116 {
117     if (!m_cachedVisitedLinkHash)
118         m_cachedVisitedLinkHash = WebCore::visitedLinkHash(document().baseURL(), fastGetAttribute(HTMLNames::hrefAttr));
119     return m_cachedVisitedLinkHash;
120 }
121
122 // Functions shared with the other anchor elements (i.e., SVG).
123
124 bool isEnterKeyKeydownEvent(Event*);
125 bool isLinkClick(Event*);
126
127 } // namespace WebCore
128
129 #endif // HTMLAnchorElement_h