Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / ResizeObserverController.h
blob26f8a766229809b2d39c837a6bf0d6bff7e011d6
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ResizeObserverController_h
8 #define mozilla_dom_ResizeObserverController_h
10 #include "mozilla/dom/ResizeObserver.h"
11 #include "mozilla/TimeStamp.h"
12 #include "nsRefreshDriver.h"
13 #include "nsTObserverArray.h"
15 namespace mozilla {
17 class PresShell;
19 namespace dom {
21 class Document;
22 class ResizeObserverController;
24 /**
25 * ResizeObserverNotificationHelper will trigger ResizeObserver notifications
26 * by registering with the Refresh Driver.
28 class ResizeObserverNotificationHelper final : public nsARefreshObserver {
29 public:
30 NS_INLINE_DECL_REFCOUNTING(ResizeObserverNotificationHelper, override)
32 explicit ResizeObserverNotificationHelper(ResizeObserverController* aOwner)
33 : mOwner(aOwner), mRegistered(false) {
34 MOZ_ASSERT(mOwner, "Need a non-null owner");
37 MOZ_CAN_RUN_SCRIPT void WillRefresh(TimeStamp aTime) override;
39 nsRefreshDriver* GetRefreshDriver() const;
41 void Register();
43 void Unregister();
45 bool IsRegistered() const { return mRegistered; }
47 void DetachFromOwner() { mOwner = nullptr; }
49 private:
50 virtual ~ResizeObserverNotificationHelper();
52 ResizeObserverController* mOwner;
53 bool mRegistered;
56 /**
57 * ResizeObserverController contains the list of ResizeObservers and controls
58 * the flow of notification.
60 class ResizeObserverController final {
61 public:
62 explicit ResizeObserverController(Document* aDocument)
63 : mDocument(aDocument),
64 mResizeObserverNotificationHelper(
65 new ResizeObserverNotificationHelper(this)) {
66 MOZ_ASSERT(mDocument, "Need a non-null document");
69 // Methods for supporting cycle-collection
70 void Traverse(nsCycleCollectionTraversalCallback& aCb);
71 void Unlink();
73 void ShellDetachedFromDocument();
74 void AddResizeObserver(ResizeObserver* aObserver);
76 /**
77 * Schedule the notification via ResizeObserverNotificationHelper refresh
78 * observer.
80 void ScheduleNotification();
82 /**
83 * Notify all ResizeObservers by gathering and broadcasting all active
84 * observations.
86 MOZ_CAN_RUN_SCRIPT void Notify();
88 PresShell* GetPresShell() const { return mDocument->GetPresShell(); }
90 ~ResizeObserverController();
92 private:
93 /**
94 * Calls GatherActiveObservations(aDepth) for all ResizeObservers in this
95 * controller. All observations in each ResizeObserver with element's depth
96 * more than aDepth will be gathered.
98 void GatherAllActiveObservations(uint32_t aDepth);
101 * Calls BroadcastActiveObservations() for all ResizeObservers in this
102 * controller. It also returns the shallowest depth of observed target
103 * elements with active observations from all ResizeObservers or
104 * numeric_limits<uint32_t>::max() if there aren't any active observations
105 * at all.
107 MOZ_CAN_RUN_SCRIPT uint32_t BroadcastAllActiveObservations();
110 * Returns whether there is any ResizeObserver that has active observations.
112 bool HasAnyActiveObservations() const;
115 * Returns whether there is any ResizeObserver that has skipped observations.
117 bool HasAnySkippedObservations() const;
119 // Raw pointer is OK because mDocument strongly owns us & hence must outlive
120 // us.
121 Document* const mDocument;
123 RefPtr<ResizeObserverNotificationHelper> mResizeObserverNotificationHelper;
124 nsTObserverArray<RefPtr<ResizeObserver>> mResizeObservers;
127 } // namespace dom
128 } // namespace mozilla
130 #endif // mozilla_dom_ResizeObserverController_h