Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / Link.h
blobcee1e1c5ca2339c46a3e85af5613ee75917b67e9
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;
28 struct BindContext;
30 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
31 { \
32 0xb25edee6, 0xdd35, 0x4f8b, { \
33 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
34 } \
37 class Link : public nsISupports {
38 public:
39 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
41 enum class State : uint8_t {
42 Unvisited = 0,
43 Visited,
44 NotLink,
47 /**
48 * aElement is the element pointer corresponding to this link.
50 explicit Link(Element* aElement);
52 /**
53 * This constructor is only used for testing.
55 explicit Link();
57 virtual void VisitedQueryFinished(bool aVisited);
59 /**
60 * @return the URI this link is for, if available.
62 nsIURI* GetURI() const;
64 /**
65 * Helper methods for modifying and obtaining parts of the URI of the Link.
67 void SetProtocol(const nsACString& aProtocol);
68 void SetUsername(const nsACString& aUsername);
69 void SetPassword(const nsACString& aPassword);
70 void SetHost(const nsACString& aHost);
71 void SetHostname(const nsACString& aHostname);
72 void SetPathname(const nsACString& aPathname);
73 void SetSearch(const nsACString& aSearch);
74 void SetPort(const nsACString& aPort);
75 void SetHash(const nsACString& aHash);
76 void GetOrigin(nsACString& aOrigin);
77 void GetProtocol(nsACString& aProtocol);
78 void GetUsername(nsACString& aUsername);
79 void GetPassword(nsACString& aPassword);
80 void GetHost(nsACString& aHost);
81 void GetHostname(nsACString& aHostname);
82 void GetPathname(nsACString& aPathname);
83 void GetSearch(nsACString& aSearch);
84 void GetPort(nsACString& aPort);
85 void GetHash(nsACString& aHash);
87 /**
88 * Invalidates any link caching, and resets the state to the default.
90 * @param aNotify
91 * true if ResetLinkState should notify the owning document about style
92 * changes or false if it should not.
94 void ResetLinkState(bool aNotify, bool aHasHref);
95 void ResetLinkState(bool aNotify) {
96 ResetLinkState(aNotify, ElementHasHref());
98 void BindToTree(const BindContext&);
99 void UnbindFromTree() { ResetLinkState(false); }
101 // This method nevers returns a null element.
102 Element* GetElement() const { return mElement; }
104 virtual size_t SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
106 virtual bool ElementHasHref() const;
108 bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
109 void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
110 void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
111 void TriggerLinkUpdate(bool aNotify);
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 and the document so this node no longer gets
128 * notifications about changes to visitedness.
130 void Unregister();
131 void SetLinkState(State, bool aNotify);
132 void SetHrefAttribute(nsIURI* aURI);
134 mutable nsCOMPtr<nsIURI> mCachedURI;
136 Element* const mElement;
138 bool mNeedsRegistration : 1;
139 bool mRegistered : 1;
140 bool mHasPendingLinkUpdate : 1;
141 const bool mHistory : 1;
144 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
146 } // namespace dom
147 } // namespace mozilla
149 #endif // mozilla_dom_Link_h__