Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / base / src / Link.h
blob163bf746f7cbb4bb40de657c6d9fb7e2bcf43107
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 et :
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 * This is the base class for all link classes.
9 */
11 #ifndef mozilla_dom_Link_h__
12 #define mozilla_dom_Link_h__
14 #include "mozilla/IHistory.h"
15 #include "mozilla/MemoryReporting.h"
16 #include "nsEventStates.h"
17 #include "nsIContent.h"
19 namespace mozilla {
20 namespace dom {
22 class Element;
24 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
25 { 0xb25edee6, 0xdd35, 0x4f8b, \
26 { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
28 class Link : public nsISupports
30 public:
31 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
33 /**
34 * aElement is the element pointer corresponding to this link.
36 Link(Element* aElement);
37 virtual void SetLinkState(nsLinkState aState);
39 /**
40 * @return NS_EVENT_STATE_VISITED if this link is visited,
41 * NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
42 * link is not actually a link.
44 nsEventStates LinkState() const;
46 /**
47 * @return the URI this link is for, if available.
49 nsIURI* GetURI() const;
50 virtual nsIURI* GetURIExternal() const {
51 return GetURI();
54 /**
55 * Helper methods for modifying and obtaining parts of the URI of the Link.
57 void SetProtocol(const nsAString &aProtocol);
58 void SetUsername(const nsAString &aUsername);
59 void SetPassword(const nsAString &aPassword);
60 void SetHost(const nsAString &aHost);
61 void SetHostname(const nsAString &aHostname);
62 void SetPathname(const nsAString &aPathname);
63 void SetSearch(const nsAString &aSearch);
64 void SetPort(const nsAString &aPort);
65 void SetHash(const nsAString &aHash);
66 void GetOrigin(nsAString &aOrigin);
67 void GetProtocol(nsAString &_protocol);
68 void GetUsername(nsAString &aUsername);
69 void GetPassword(nsAString &aPassword);
70 void GetHost(nsAString &_host);
71 void GetHostname(nsAString &_hostname);
72 void GetPathname(nsAString &_pathname);
73 void GetSearch(nsAString &_search);
74 void GetPort(nsAString &_port);
75 void GetHash(nsAString &_hash);
77 /**
78 * Invalidates any link caching, and resets the state to the default.
80 * @param aNotify
81 * true if ResetLinkState should notify the owning document about style
82 * changes or false if it should not.
84 void ResetLinkState(bool aNotify, bool aHasHref);
86 // This method nevers returns a null element.
87 Element* GetElement() const { return mElement; }
89 /**
90 * DNS prefetch has been deferred until later, e.g. page load complete.
92 virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
94 /**
95 * DNS prefetch has been submitted to Host Resolver.
97 virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
99 /**
100 * Checks if DNS Prefetching is ok
102 * @returns boolean
103 * Defaults to true; should be overridden for specialised cases
105 virtual bool HasDeferredDNSPrefetchRequest() { return true; }
107 virtual size_t
108 SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
110 bool ElementHasHref() const;
112 protected:
113 virtual ~Link();
116 * Return true if the link has associated URI.
118 bool HasURI() const
120 if (HasCachedURI()) {
121 return true;
124 return !!GetURI();
127 nsIURI* GetCachedURI() const { return mCachedURI; }
128 bool HasCachedURI() const { return !!mCachedURI; }
130 private:
132 * Unregisters from History so this node no longer gets notifications about
133 * changes to visitedness.
135 void UnregisterFromHistory();
137 already_AddRefed<nsIURI> GetURIToMutate();
138 void SetHrefAttribute(nsIURI *aURI);
140 mutable nsCOMPtr<nsIURI> mCachedURI;
142 Element * const mElement;
144 // Strong reference to History. The link has to unregister before History
145 // can disappear.
146 nsCOMPtr<IHistory> mHistory;
148 uint16_t mLinkState;
150 bool mNeedsRegistration;
152 bool mRegistered;
155 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
157 } // namespace dom
158 } // namespace mozilla
160 #endif // mozilla_dom_Link_h__