Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / base / PopoverData.h
blob2fa8a61036240b56fd9b9eb647d80b94f75c793d
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 #ifndef mozilla_dom_PopoverData_h
8 #define mozilla_dom_PopoverData_h
10 #include "Element.h"
11 #include "nsINode.h"
12 #include "nsIRunnable.h"
13 #include "nsIWeakReferenceUtils.h"
14 #include "nsStringFwd.h"
15 #include "nsThreadUtils.h"
17 namespace mozilla::dom {
19 // https://html.spec.whatwg.org/#attr-popover
20 enum class PopoverAttributeState : uint8_t {
21 None,
22 Auto, ///< https://html.spec.whatwg.org/#attr-popover-auto-state
23 Manual, ///< https://html.spec.whatwg.org/#attr-popover-manual-state
26 enum class PopoverVisibilityState : uint8_t {
27 Hidden,
28 Showing,
31 class PopoverToggleEventTask : public Runnable {
32 public:
33 explicit PopoverToggleEventTask(nsWeakPtr aElement,
34 PopoverVisibilityState aOldState);
36 // MOZ_CAN_RUN_SCRIPT_BOUNDARY until Runnable::Run is MOZ_CAN_RUN_SCRIPT. See
37 // bug 1535398.
38 MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD Run() override;
40 PopoverVisibilityState GetOldState() const { return mOldState; }
42 private:
43 nsWeakPtr mElement;
44 PopoverVisibilityState mOldState;
47 class PopoverData {
48 public:
49 PopoverData() = default;
50 ~PopoverData() = default;
52 PopoverAttributeState GetPopoverAttributeState() const { return mState; }
53 void SetPopoverAttributeState(PopoverAttributeState aState) {
54 mState = aState;
57 PopoverVisibilityState GetPopoverVisibilityState() const {
58 return mVisibilityState;
60 void SetPopoverVisibilityState(PopoverVisibilityState aVisibilityState) {
61 mVisibilityState = aVisibilityState;
64 nsWeakPtr GetPreviouslyFocusedElement() const {
65 return mPreviouslyFocusedElement;
67 void SetPreviouslyFocusedElement(nsWeakPtr aPreviouslyFocusedElement) {
68 mPreviouslyFocusedElement = aPreviouslyFocusedElement;
71 RefPtr<Element> GetInvoker() const {
72 return do_QueryReferent(mInvokerElement);
74 void SetInvoker(Element* aInvokerElement) {
75 mInvokerElement =
76 do_GetWeakReference(static_cast<nsINode*>(aInvokerElement));
79 PopoverToggleEventTask* GetToggleEventTask() const { return mTask; }
80 void SetToggleEventTask(PopoverToggleEventTask* aTask) { mTask = aTask; }
81 void ClearToggleEventTask() { mTask = nullptr; }
83 bool IsShowingOrHiding() const { return mIsShowingOrHiding; }
84 void SetIsShowingOrHiding(bool aIsShowingOrHiding) {
85 mIsShowingOrHiding = aIsShowingOrHiding;
88 private:
89 PopoverVisibilityState mVisibilityState = PopoverVisibilityState::Hidden;
90 PopoverAttributeState mState = PopoverAttributeState::None;
91 // Popover and dialog don't share mPreviouslyFocusedElement for there are
92 // chances to lose the previously focused element.
93 // See, https://github.com/whatwg/html/issues/9063
94 nsWeakPtr mPreviouslyFocusedElement = nullptr;
96 // https://html.spec.whatwg.org/#popover-invoker
97 // Since having a popover invoker only makes a difference if the invoker
98 // is in the document (in another open popover to be precise) we can make
99 // this a weak reference, as if the element goes away it's necessarily not
100 // connected to our document.
101 nsWeakPtr mInvokerElement;
102 bool mIsShowingOrHiding = false;
103 RefPtr<PopoverToggleEventTask> mTask;
105 } // namespace mozilla::dom
107 #endif