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 #include "nsRefreshObservers.h"
8 #include "nsPresContext.h"
12 ManagedPostRefreshObserver::ManagedPostRefreshObserver(nsPresContext
* aPc
,
14 : mPresContext(aPc
), mAction(std::move(aAction
)) {}
16 ManagedPostRefreshObserver::ManagedPostRefreshObserver(nsPresContext
* aPc
)
17 : mPresContext(aPc
) {}
19 ManagedPostRefreshObserver::~ManagedPostRefreshObserver() = default;
21 void ManagedPostRefreshObserver::Cancel() {
22 // Caller holds a strong reference, so no need to reference stuff from here.
25 mPresContext
= nullptr;
28 void ManagedPostRefreshObserver::DidRefresh() {
29 RefPtr
<ManagedPostRefreshObserver
> thisObject
= this;
31 Unregister unregister
= mAction(false);
32 if (unregister
== Unregister::Yes
) {
33 if (RefPtr
<nsPresContext
> pc
= std::move(mPresContext
)) {
34 // In theory mAction could've ended up in `Cancel` being called. In which
35 // case we're already unregistered so no need to do anything.
37 pc
->UnregisterManagedPostRefreshObserver(this);
39 MOZ_DIAGNOSTIC_ASSERT(!mAction
);
44 } // namespace mozilla