Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / Link.h
blob7d547d75ba061cfa1d5a6788d30b2667568feb80
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 "nsWrapperCache.h" // For nsWrapperCache::FlagsType
15 #include "nsCOMPtr.h"
16 #include "mozilla/dom/RustTypes.h"
18 class nsIURI;
20 namespace mozilla {
22 class SizeOfState;
24 namespace dom {
26 class Document;
27 class Element;
29 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
30 { \
31 0xb25edee6, 0xdd35, 0x4f8b, { \
32 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
33 } \
36 class Link : public nsISupports {
37 public:
38 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
40 enum class State : uint8_t {
41 Unvisited = 0,
42 Visited,
43 NotLink,
46 /**
47 * aElement is the element pointer corresponding to this link.
49 explicit Link(Element* aElement);
51 /**
52 * This constructor is only used for testing.
54 explicit Link();
56 virtual void VisitedQueryFinished(bool aVisited);
58 /**
59 * @return ElementState::VISITED if this link is visited,
60 * ElementState::UNVISTED if this link is not visited, or 0 if this
61 * link is not actually a link.
63 ElementState LinkState() const;
65 /**
66 * @return the URI this link is for, if available.
68 nsIURI* GetURI() const;
70 /**
71 * Helper methods for modifying and obtaining parts of the URI of the Link.
73 void SetProtocol(const nsAString& aProtocol);
74 void SetUsername(const nsAString& aUsername);
75 void SetPassword(const nsAString& aPassword);
76 void SetHost(const nsAString& aHost);
77 void SetHostname(const nsAString& aHostname);
78 void SetPathname(const nsAString& aPathname);
79 void SetSearch(const nsAString& aSearch);
80 void SetPort(const nsAString& aPort);
81 void SetHash(const nsAString& aHash);
82 void GetOrigin(nsAString& aOrigin);
83 void GetProtocol(nsAString& _protocol);
84 void GetUsername(nsAString& aUsername);
85 void GetPassword(nsAString& aPassword);
86 void GetHost(nsAString& _host);
87 void GetHostname(nsAString& _hostname);
88 void GetPathname(nsAString& _pathname);
89 void GetSearch(nsAString& _search);
90 void GetPort(nsAString& _port);
91 void GetHash(nsAString& _hash);
93 /**
94 * Invalidates any link caching, and resets the state to the default.
96 * @param aNotify
97 * true if ResetLinkState should notify the owning document about style
98 * changes or false if it should not.
100 void ResetLinkState(bool aNotify, bool aHasHref);
102 // This method nevers returns a null element.
103 Element* GetElement() const { return mElement; }
105 virtual size_t SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
107 virtual bool ElementHasHref() const;
109 bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
110 void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
111 void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
113 // To ensure correct mHasPendingLinkUpdate handling, we have this method
114 // similar to the one in Element. Overriders must call
115 // ClearHasPendingLinkUpdate().
116 // If you change this, change also the method in nsINode.
117 virtual void NodeInfoChanged(Document* aOldDoc) = 0;
119 protected:
120 virtual ~Link();
122 nsIURI* GetCachedURI() const { return mCachedURI; }
123 bool HasCachedURI() const { return !!mCachedURI; }
125 private:
127 * Unregisters from History so this node no longer gets notifications about
128 * changes to visitedness.
130 void UnregisterFromHistory();
132 void SetHrefAttribute(nsIURI* aURI);
134 mutable nsCOMPtr<nsIURI> mCachedURI;
136 Element* const mElement;
138 // TODO(emilio): This ideally could be `State mState : 2`, but the version of
139 // gcc we build on automation with (7 as of this writing) has a useless
140 // warning about all values in the range of the enum not fitting, see
141 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.
142 State mState;
143 bool mNeedsRegistration : 1;
144 bool mRegistered : 1;
145 bool mHasPendingLinkUpdate : 1;
146 bool mHistory : 1;
149 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
151 } // namespace dom
152 } // namespace mozilla
154 #endif // mozilla_dom_Link_h__