From 1be2b749351e3090201272d34cf4bfd003cc0c4c Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Wed, 6 Nov 2019 20:49:07 +0000 Subject: [PATCH] Bug 969322 - make :-moz-window-inactive state follow GDK_WINDOW_STATE_FOCUSED when drawing in titlebar r=karlt,stransky This patch fixes activation of the :-moz-window-inactive pseudoclass in client side decoration during drag operations. It depends on and complements the fixes provided in support of Bug 1491808. Obsoletes D50445 Differential Revision: https://phabricator.services.mozilla.com/D51307 --HG-- extra : moz-landing-system : lando --- widget/gtk/nsWindow.cpp | 31 +++++++++++++++++++++++++++++-- widget/gtk/nsWindow.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 6c5eff4c1c21..870841388b5e 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -3064,6 +3064,14 @@ void nsWindow::OnContainerFocusOutEvent(GdkEventFocus* aEvent) { DispatchDeactivateEvent(); + if (mDrawInTitlebar) { + // DispatchDeactivateEvent() ultimately results in a call to + // nsGlobalWindowOuter::ActivateOrDeactivate(), which resets + // the mIsActive flag. We call UpdateMozWindowActive() to keep + // the flag in sync with GDK_WINDOW_STATE_FOCUSED. + UpdateMozWindowActive(); + } + LOGFOCUS(("Done with container focus out [%p]\n", (void*)this)); } @@ -3330,6 +3338,9 @@ void nsWindow::OnWindowStateEvent(GtkWidget* aWidget, mTitlebarBackdropState = !(aEvent->new_window_state & GDK_WINDOW_STATE_FOCUSED); + // keep mIsActive in sync with GDK_WINDOW_STATE_FOCUSED + UpdateMozWindowActive(); + ForceTitlebarRedraw(); } @@ -7396,6 +7407,19 @@ nsIFrame* nsWindow::GetFrame(void) { return view->GetFrame(); } +void nsWindow::UpdateMozWindowActive() { + // Update activation state for the :-moz-window-inactive pseudoclass. + // Normally, this follows focus; we override it here to follow + // GDK_WINDOW_STATE_FOCUSED. + mozilla::dom::Document* document = GetDocument(); + if (document) { + nsPIDOMWindowOuter* window = document->GetWindow(); + if (window) { + window->SetActive(!mTitlebarBackdropState); + } + } +} + void nsWindow::ForceTitlebarRedraw(void) { MOZ_ASSERT(mDrawInTitlebar, "We should not redraw invisible titlebar."); @@ -7410,8 +7434,11 @@ void nsWindow::ForceTitlebarRedraw(void) { frame = FindTitlebarFrame(frame); if (frame) { - nsLayoutUtils::PostRestyleEvent(frame->GetContent()->AsElement(), - RestyleHint{0}, nsChangeHint_RepaintFrame); + nsIContent* content = frame->GetContent(); + if (content) { + nsLayoutUtils::PostRestyleEvent(content->AsElement(), RestyleHint{0}, + nsChangeHint_RepaintFrame); + } } } diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index cd8502012a38..f4fe269506e4 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -625,6 +625,8 @@ class nsWindow final : public nsBaseWidget { virtual int32_t RoundsWidgetCoordinatesTo() override; + void UpdateMozWindowActive(); + void ForceTitlebarRedraw(); void SetPopupWindowDecoration(bool aShowOnTaskbar);