Bug 1718755 - Use an early refresh driver runner rather than Dispatch() to coalesce theme changes. r=stransky

That way we guarantee they are processed before display.

Differential Revision: https://phabricator.services.mozilla.com/D119023
This commit is contained in:
Emilio Cobos Álvarez 2021-07-20 14:10:58 +00:00
Родитель 253bc4185f
Коммит 7d5f5e0d0c
2 изменённых файлов: 29 добавлений и 13 удалений

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

@ -586,18 +586,34 @@ void nsPresContext::PreferenceChanged(const char* aPrefName) {
}
}
struct WeakRunnableMethod : Runnable {
using Method = void (nsPresContext::*)();
WeakRunnableMethod(const char* aName, nsPresContext* aPc, Method aMethod)
: Runnable(aName), mPresContext(aPc), mMethod(aMethod) {}
NS_IMETHOD Run() override {
if (nsPresContext* pc = mPresContext.get()) {
(pc->*mMethod)();
}
return NS_OK;
}
private:
WeakPtr<nsPresContext> mPresContext;
Method mMethod;
};
void nsPresContext::DispatchPrefChangedRunnableIfNeeded() {
if (mPostedPrefChangedRunnable) {
return;
}
nsCOMPtr<nsIRunnable> runnable =
NewRunnableMethod("nsPresContext::UpdateAfterPreferencesChanged", this,
nsCOMPtr<nsIRunnable> runnable = new WeakRunnableMethod(
"nsPresContext::UpdateAfterPreferencesChanged", this,
&nsPresContext::UpdateAfterPreferencesChanged);
nsresult rv = Document()->Dispatch(TaskCategory::Other, runnable.forget());
if (NS_SUCCEEDED(rv)) {
RefreshDriver()->AddEarlyRunner(runnable);
mPostedPrefChangedRunnable = true;
}
}
void nsPresContext::UpdateAfterPreferencesChanged() {
@ -1361,13 +1377,11 @@ void nsPresContext::ThemeChanged(widget::ThemeChangeKind aKind) {
sThemeChanged = true;
nsCOMPtr<nsIRunnable> ev =
NewRunnableMethod("nsPresContext::ThemeChangedInternal", this,
new WeakRunnableMethod("nsPresContext::ThemeChangedInternal", this,
&nsPresContext::ThemeChangedInternal);
nsresult rv = Document()->Dispatch(TaskCategory::Other, ev.forget());
if (NS_SUCCEEDED(rv)) {
RefreshDriver()->AddEarlyRunner(ev);
mPendingThemeChanged = true;
}
}
}
void nsPresContext::ThemeChangedInternal() {

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

@ -2885,6 +2885,8 @@ void nsRefreshDriver::Disconnect() {
StopTimer();
mEarlyRunners.Clear();
if (mPresContext) {
mPresContext = nullptr;
if (--sRefreshDriverCount == 0) {