1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsICanvasRenderingContextInternal.h"
8 #include "mozilla/dom/Document.h"
9 #include "mozilla/PresShell.h"
10 #include "nsRefreshDriver.h"
12 nsICanvasRenderingContextInternal::nsICanvasRenderingContextInternal()
14 std::make_shared
<nsICanvasRenderingContextInternal
*>(this)) {}
16 nsICanvasRenderingContextInternal::~nsICanvasRenderingContextInternal() =
19 mozilla::PresShell
* nsICanvasRenderingContextInternal::GetPresShell() {
21 return mCanvasElement
->OwnerDoc()->GetPresShell();
26 void nsICanvasRenderingContextInternal::RemovePostRefreshObserver() {
28 mRefreshDriver
->RemovePostRefreshObserver(this);
29 mRefreshDriver
= nullptr;
33 void nsICanvasRenderingContextInternal::AddPostRefreshObserverIfNecessary() {
34 if (!GetPresShell() || !GetPresShell()->GetPresContext() ||
35 !GetPresShell()->GetPresContext()->RefreshDriver()) {
38 mRefreshDriver
= GetPresShell()->GetPresContext()->RefreshDriver();
39 mRefreshDriver
->AddPostRefreshObserver(this);