Bug 1712825 - Refactor CoalescedMouseMoveFlusher into a generic class for input events r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D116624
This commit is contained in:
Sean Feng 2021-06-07 15:29:15 +00:00
Родитель 0a9e50b29c
Коммит bef5b44628
5 изменённых файлов: 79 добавлений и 48 удалений

Просмотреть файл

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsRefreshDriver.h"
#include "BrowserChild.h"
#include "CoalescedInputData.h"
#include "mozilla/PresShell.h"
using namespace mozilla;
using namespace mozilla::dom;
void CoalescedInputFlusher::StartObserver() {
nsRefreshDriver* refreshDriver = GetRefreshDriver();
if (mRefreshDriver && mRefreshDriver == refreshDriver) {
// Nothing to do if we already added an observer and it's same refresh
// driver.
return;
}
RemoveObserver();
if (refreshDriver) {
mRefreshDriver = refreshDriver;
mRefreshDriver->AddRefreshObserver(this, FlushType::Event,
"Coalesced input move flusher");
}
}
CoalescedInputFlusher::CoalescedInputFlusher(BrowserChild* aBrowserChild)
: mBrowserChild(aBrowserChild) {}
void CoalescedInputFlusher::RemoveObserver() {
if (mRefreshDriver) {
mRefreshDriver->RemoveRefreshObserver(this, FlushType::Event);
mRefreshDriver = nullptr;
}
}
CoalescedInputFlusher::~CoalescedInputFlusher() = default;
nsRefreshDriver* CoalescedInputFlusher::GetRefreshDriver() {
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
return presShell->GetRefreshDriver();
}
return nullptr;
}

Просмотреть файл

@ -9,10 +9,15 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/layers/ScrollableLayerGuid.h"
#include "nsRefreshObservers.h"
class nsRefreshDriver;
namespace mozilla {
namespace dom {
class BrowserChild;
template <class InputEventType>
class CoalescedInputData {
protected:
@ -46,6 +51,25 @@ class CoalescedInputData {
uint64_t GetInputBlockId() { return mInputBlockId; }
};
class CoalescedInputFlusher : public nsARefreshObserver {
public:
explicit CoalescedInputFlusher(BrowserChild* aBrowserChild);
virtual void WillRefresh(mozilla::TimeStamp aTime) override = 0;
NS_INLINE_DECL_REFCOUNTING(CoalescedInputFlusher, override)
void StartObserver();
void RemoveObserver();
protected:
virtual ~CoalescedInputFlusher();
nsRefreshDriver* GetRefreshDriver();
BrowserChild* mBrowserChild;
RefPtr<nsRefreshDriver> mRefreshDriver;
};
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -69,45 +69,14 @@ bool CoalescedMouseData::CanCoalesce(const WidgetMouseEvent& aEvent,
mInputBlockId == aInputBlockId);
}
CoalescedMouseMoveFlusher::CoalescedMouseMoveFlusher(
BrowserChild* aBrowserChild)
: CoalescedInputFlusher(aBrowserChild) {}
void CoalescedMouseMoveFlusher::WillRefresh(mozilla::TimeStamp aTime) {
MOZ_ASSERT(mRefreshDriver);
mBrowserChild->FlushAllCoalescedMouseData();
mBrowserChild->ProcessPendingCoalescedMouseDataAndDispatchEvents();
}
void CoalescedMouseMoveFlusher::StartObserver() {
nsRefreshDriver* refreshDriver = GetRefreshDriver();
if (mRefreshDriver && mRefreshDriver == refreshDriver) {
// Nothing to do if we already added an observer and it's same refresh
// driver.
return;
}
RemoveObserver();
if (refreshDriver) {
mRefreshDriver = refreshDriver;
mRefreshDriver->AddRefreshObserver(this, FlushType::Event,
"Coalesced mouse move flusher");
}
}
void CoalescedMouseMoveFlusher::RemoveObserver() {
if (mRefreshDriver) {
mRefreshDriver->RemoveRefreshObserver(this, FlushType::Event);
mRefreshDriver = nullptr;
}
}
CoalescedMouseMoveFlusher::CoalescedMouseMoveFlusher(
BrowserChild* aBrowserChild)
: mBrowserChild(aBrowserChild) {
MOZ_ASSERT(mBrowserChild);
}
CoalescedMouseMoveFlusher::~CoalescedMouseMoveFlusher() { RemoveObserver(); }
nsRefreshDriver* CoalescedMouseMoveFlusher::GetRefreshDriver() {
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
return presShell->GetRefreshDriver();
}
return nullptr;
}

Просмотреть файл

@ -31,24 +31,14 @@ class CoalescedMouseData final : public CoalescedInputData<WidgetMouseEvent> {
const uint64_t& aInputBlockId);
};
class CoalescedMouseMoveFlusher final : public nsARefreshObserver {
class CoalescedMouseMoveFlusher final : public CoalescedInputFlusher {
public:
explicit CoalescedMouseMoveFlusher(BrowserChild* aBrowserChild);
virtual void WillRefresh(mozilla::TimeStamp aTime) override;
NS_INLINE_DECL_REFCOUNTING(CoalescedMouseMoveFlusher, override)
void StartObserver();
void RemoveObserver();
void WillRefresh(mozilla::TimeStamp aTime) override;
private:
~CoalescedMouseMoveFlusher();
nsRefreshDriver* GetRefreshDriver();
BrowserChild* mBrowserChild;
RefPtr<nsRefreshDriver> mRefreshDriver;
~CoalescedMouseMoveFlusher() override;
};
} // namespace dom

Просмотреть файл

@ -92,6 +92,7 @@ UNIFIED_SOURCES += [
"BrowserHost.cpp",
"BrowserParent.cpp",
"ClonedErrorHolder.cpp",
"CoalescedInputData.cpp",
"CoalescedMouseData.cpp",
"CoalescedWheelData.cpp",
"ColorPickerParent.cpp",