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/. */
8 * This is the base class for all link classes.
11 #ifndef mozilla_dom_Link_h__
12 #define mozilla_dom_Link_h__
14 #include "nsWrapperCache.h" // For nsWrapperCache::FlagsType
16 #include "mozilla/dom/RustTypes.h"
30 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
32 0xb25edee6, 0xdd35, 0x4f8b, { \
33 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 \
37 class Link
: public nsISupports
{
39 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID
)
41 enum class State
: uint8_t {
48 * aElement is the element pointer corresponding to this link.
50 explicit Link(Element
* aElement
);
53 * This constructor is only used for testing.
57 virtual void VisitedQueryFinished(bool aVisited
);
60 * @return the URI this link is for, if available.
62 nsIURI
* GetURI() const;
65 * Helper methods for modifying and obtaining parts of the URI of the Link.
67 void SetProtocol(const nsAString
& aProtocol
);
68 void SetUsername(const nsAString
& aUsername
);
69 void SetPassword(const nsAString
& aPassword
);
70 void SetHost(const nsAString
& aHost
);
71 void SetHostname(const nsAString
& aHostname
);
72 void SetPathname(const nsAString
& aPathname
);
73 void SetSearch(const nsAString
& aSearch
);
74 void SetPort(const nsAString
& aPort
);
75 void SetHash(const nsAString
& aHash
);
76 void GetOrigin(nsAString
& aOrigin
);
77 void GetProtocol(nsAString
& _protocol
);
78 void GetUsername(nsAString
& aUsername
);
79 void GetPassword(nsAString
& aPassword
);
80 void GetHost(nsAString
& _host
);
81 void GetHostname(nsAString
& _hostname
);
82 void GetPathname(nsAString
& _pathname
);
83 void GetSearch(nsAString
& _search
);
84 void GetPort(nsAString
& _port
);
85 void GetHash(nsAString
& _hash
);
88 * Invalidates any link caching, and resets the state to the default.
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;
122 nsIURI
* GetCachedURI() const { return mCachedURI
; }
123 bool HasCachedURI() const { return !!mCachedURI
; }
127 * Unregisters from History and the document so this node no longer gets
128 * notifications about changes to visitedness.
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
)
147 } // namespace mozilla
149 #endif // mozilla_dom_Link_h__