Bug 1869796 - Make xul alert windows have the appropriate type hint. r=stransky

Before bug 1869796 they had an utility type hint, now they have a
toplevel type hint, after the patch they have a notification type hint,
which seems more appropriate.

Differential Revision: https://phabricator.services.mozilla.com/D197872
This commit is contained in:
Emilio Cobos Álvarez 2024-01-09 12:38:33 +00:00
parent b2168e5b30
commit d55d0f229d
6 changed files with 25 additions and 18 deletions

View File

@ -12,15 +12,12 @@
#include "mozilla/EventForwards.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/dom/Notification.h"
#include "mozilla/Unused.h"
#include "nsISupportsPrimitives.h"
#include "nsPIDOMWindow.h"
#include "nsIWindowWatcher.h"
using namespace mozilla;
#define ALERT_CHROME_URL "chrome://global/content/alerts/alert.xhtml"_ns
namespace {
StaticRefPtr<nsXULAlerts> gXULAlerts;
} // anonymous namespace
@ -163,9 +160,8 @@ nsXULAlerts::ShowAlert(nsIAlertNotification* aAlert,
PendingAlert* pa = mPendingPersistentAlerts.AppendElement();
pa->Init(aAlert, aAlertListener);
return NS_OK;
} else {
return ShowAlertWithIconURI(aAlert, aAlertListener, nullptr);
}
return ShowAlertWithIconURI(aAlert, aAlertListener, nullptr);
}
NS_IMETHODIMP
@ -181,8 +177,9 @@ nsXULAlerts::ShowAlertWithIconURI(nsIAlertNotification* aAlert,
NS_ENSURE_SUCCESS(rv, rv);
if (mDoNotDisturb) {
if (aAlertListener)
if (aAlertListener) {
aAlertListener->Observe(nullptr, "alertfinished", cookie.get());
}
return NS_OK;
}
@ -354,12 +351,13 @@ nsXULAlerts::ShowAlertWithIconURI(nsIAlertNotification* aAlert,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<mozIDOMWindowProxy> newWindow;
nsAutoCString features("chrome,dialog=yes,titlebar=no");
nsAutoCString features("chrome,dialog=yes,alert=yes,titlebar=no");
if (inPrivateBrowsing) {
features.AppendLiteral(",private");
}
rv = wwatch->OpenWindow(nullptr, ALERT_CHROME_URL, "_blank"_ns, features,
argsArray, getter_AddRefs(newWindow));
rv = wwatch->OpenWindow(
nullptr, "chrome://global/content/alerts/alert.xhtml"_ns, "_blank"_ns,
features, argsArray, getter_AddRefs(newWindow));
NS_ENSURE_SUCCESS(rv, rv);
mNamedWindows.InsertOrUpdate(name, newWindow);

View File

@ -50,6 +50,8 @@ interface nsIWebBrowserChrome : nsISupports
const unsigned long CHROME_WINDOW_MINIMIZE = 1 << 14;
const unsigned long CHROME_ALERT = 1 << 15;
// whether to open a new private window. CHROME_NON_PRIVATE_WINDOW
// forces the opened window to be non-private, and overrides
// CHROME_PRIVATE_WINDOW if it's set. CHROME_PRIVATE_WINDOW

View File

@ -2005,6 +2005,9 @@ uint32_t nsWindowWatcher::CalculateChromeFlagsForSystem(
if (aFeatures.GetBoolWithDefault("dialog", false)) {
chromeFlags |= nsIWebBrowserChrome::CHROME_OPENAS_DIALOG;
}
if (aFeatures.GetBoolWithDefault("alert", false)) {
chromeFlags |= nsIWebBrowserChrome::CHROME_ALERT;
}
/* dialogs need to have the last word. assume dialogs are dialogs,
and opened as chrome, unless explicitly told otherwise. */

View File

@ -100,11 +100,13 @@ struct InitData {
// true if the window should support an alpha channel, if available.
bool mHasRemoteContent = false;
bool mAlwaysOnTop = false;
// Is PictureInPicture window
// Whether we're a PictureInPicture window
bool mPIPWindow = false;
// True if the window is user-resizable.
bool mResizable = false;
bool mIsPrivate = false;
// True if the window is an alert / notification.
bool mIsAlert = false;
};
} // namespace mozilla::widget

View File

@ -6075,8 +6075,12 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
gtk_window_resize(GTK_WINDOW(mShell), size.width, size.height);
}
if (mIsPIPWindow) {
LOG(" Is PIP Window\n");
LOG(" Is PIP window\n");
gtk_window_set_type_hint(GTK_WINDOW(mShell), GDK_WINDOW_TYPE_HINT_UTILITY);
} else if (aInitData && aInitData->mIsAlert) {
LOG(" Is alert window\n");
gtk_window_set_type_hint(GTK_WINDOW(mShell),
GDK_WINDOW_TYPE_HINT_NOTIFICATION);
} else if (mWindowType == WindowType::Dialog) {
mGtkWindowRoleName = "Dialog";
@ -7550,13 +7554,9 @@ nsresult nsWindow::MakeFullScreen(bool aFullScreen) {
gtk_window_unfullscreen(GTK_WINDOW(mShell));
if (mIsPIPWindow) {
gtk_window_set_type_hint(GTK_WINDOW(mShell),
GDK_WINDOW_TYPE_HINT_UTILITY);
if (gUseAspectRatio) {
mAspectRatio = mAspectRatioSaved;
// ApplySizeConstraints();
}
if (mIsPIPWindow && gUseAspectRatio) {
mAspectRatio = mAspectRatioSaved;
// ApplySizeConstraints();
}
}

View File

@ -596,6 +596,8 @@ nsresult nsAppShellService::JustCreateTopWindow(
}
#endif
widgetInitData.mIsAlert = !!(aChromeMask & nsIWebBrowserChrome::CHROME_ALERT);
#ifdef XP_MACOSX
// Mac OS X sheet support
// Adding CHROME_OPENAS_CHROME to sheetMask makes modal windows opened from