Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / ipc / CoalescedInputData.cpp
blob6336f869286389919e804a402b4dbcecd1880ca2
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 "nsRefreshDriver.h"
8 #include "BrowserChild.h"
9 #include "CoalescedInputData.h"
10 #include "mozilla/PresShell.h"
12 using namespace mozilla;
13 using namespace mozilla::dom;
15 void CoalescedInputFlusher::StartObserver() {
16 nsRefreshDriver* refreshDriver = GetRefreshDriver();
17 if (mRefreshDriver && mRefreshDriver == refreshDriver) {
18 // Nothing to do if we already added an observer and it's same refresh
19 // driver.
20 return;
22 RemoveObserver();
23 if (refreshDriver) {
24 mRefreshDriver = refreshDriver;
25 mRefreshDriver->AddRefreshObserver(this, FlushType::Event,
26 "Coalesced input move flusher");
30 CoalescedInputFlusher::CoalescedInputFlusher(BrowserChild* aBrowserChild)
31 : mBrowserChild(aBrowserChild) {}
33 void CoalescedInputFlusher::RemoveObserver() {
34 if (mRefreshDriver) {
35 mRefreshDriver->RemoveRefreshObserver(this, FlushType::Event);
36 mRefreshDriver = nullptr;
40 CoalescedInputFlusher::~CoalescedInputFlusher() = default;
42 nsRefreshDriver* CoalescedInputFlusher::GetRefreshDriver() {
43 if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
44 return presShell->GetRefreshDriver();
46 return nullptr;