forked from mirrors/gecko-dev
Bug 1890576 - Make root element color-scheme affect widget appearance. r=mstange,mac-reviewers
Instead of relying on the embedder color-scheme directly, use the color-scheme property to determine the nsCocoaWindow's appearance. This is more in line with what content does, would've prevented this bug from existing altogether, and avoids the need for MOZGlobalAppearance. Differential Revision: https://phabricator.services.mozilla.com/D207050
This commit is contained in:
parent
77e7febf08
commit
e78109826b
7 changed files with 8 additions and 106 deletions
|
|
@ -11847,10 +11847,9 @@ void PresShell::SyncWindowProperties(bool aSync) {
|
|||
canvas ? canvas : rootFrame, rootFrame);
|
||||
windowWidget->SetTransparencyMode(mode);
|
||||
|
||||
// For macOS, apply color scheme overrides to the top level window widget.
|
||||
if (auto scheme = pc->GetOverriddenOrEmbedderColorScheme()) {
|
||||
windowWidget->SetColorScheme(scheme);
|
||||
}
|
||||
// For macOS, apply color scheme to the top level window widget.
|
||||
windowWidget->SetColorScheme(
|
||||
Some(LookAndFeel::ColorSchemeForFrame(rootFrame)));
|
||||
}
|
||||
|
||||
if (!weak.IsAlive()) {
|
||||
|
|
|
|||
|
|
@ -22,10 +22,6 @@
|
|||
|
||||
#define AVG2(a, b) (((a) + (b) + 1) >> 1)
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
void OverrideGlobalAppearance(mozilla::ColorScheme);
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
using dom::Document;
|
||||
|
|
@ -274,10 +270,6 @@ void PreferenceSheet::Initialize() {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef XP_MACOSX
|
||||
OverrideGlobalAppearance(sChromePrefs.mColorScheme);
|
||||
#endif
|
||||
|
||||
nsAutoString useDocumentColorPref;
|
||||
switch (StaticPrefs::browser_display_document_color_use()) {
|
||||
case 1:
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef AppearanceOverride_h
|
||||
#define AppearanceOverride_h
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
namespace mozilla {
|
||||
enum class ColorScheme: uint8_t;
|
||||
}
|
||||
|
||||
void OverrideGlobalAppearance(mozilla::ColorScheme);
|
||||
|
||||
// Implements support for the browser.theme.toolbar-theme pref.
|
||||
// Use MOZGlobalAppearance.sharedInstance.effectiveAppearance
|
||||
// in all places where you would like the global override to be respected. The
|
||||
// effectiveAppearance property can be key-value observed.
|
||||
@interface MOZGlobalAppearance : NSObject <NSAppearanceCustomization>
|
||||
@property(class, readonly) MOZGlobalAppearance* sharedInstance;
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||
/* 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/. */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "AppearanceOverride.h"
|
||||
#include "nsNativeThemeColors.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
@implementation MOZGlobalAppearance
|
||||
NSAppearance* mAppearance;
|
||||
|
||||
+ (MOZGlobalAppearance*)sharedInstance {
|
||||
static MOZGlobalAppearance* sInstance = nil;
|
||||
if (!sInstance) {
|
||||
sInstance = [[MOZGlobalAppearance alloc] init];
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
- (NSAppearance*)appearance {
|
||||
return mAppearance;
|
||||
}
|
||||
|
||||
- (void)setAppearance:(NSAppearance*)aAppearance {
|
||||
mAppearance = aAppearance;
|
||||
}
|
||||
|
||||
- (NSApplication*)_app {
|
||||
return NSApp;
|
||||
}
|
||||
|
||||
+ (NSSet*)keyPathsForValuesAffectingEffectiveAppearance {
|
||||
// Automatically notify any key-value observers of our effectiveAppearance
|
||||
// property whenever appearance or the NSApp's effectiveAppearance change.
|
||||
return [NSSet setWithObjects:@"appearance", @"_app.effectiveAppearance", nil];
|
||||
}
|
||||
|
||||
- (NSAppearance*)effectiveAppearance {
|
||||
return mAppearance ? mAppearance : NSApp.effectiveAppearance;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void OverrideGlobalAppearance(mozilla::ColorScheme aScheme) {
|
||||
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
||||
if (!XRE_IsParentProcess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto* inst = MOZGlobalAppearance.sharedInstance;
|
||||
auto* appearance = NSAppearanceForColorScheme(aScheme);
|
||||
if (inst.appearance != appearance) {
|
||||
inst.appearance = appearance;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@ EXPORTS += [
|
|||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"AppearanceOverride.mm",
|
||||
"GfxInfo.mm",
|
||||
"MOZIconHelper.mm",
|
||||
"MOZMenuOpeningCoordinator.mm",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "nsCocoaWindow.h"
|
||||
|
||||
#include "AppearanceOverride.h"
|
||||
#include "NativeKeyBindings.h"
|
||||
#include "ScreenHelperCocoa.h"
|
||||
#include "TextInputHandler.h"
|
||||
|
|
@ -525,10 +524,6 @@ nsresult nsCocoaWindow::CreateNativeWindow(const NSRect& aRect,
|
|||
[WindowDataMap.sharedWindowDataMap ensureDataForWindow:mWindow];
|
||||
mWindowMadeHere = true;
|
||||
|
||||
// Make the window respect the global appearance, which follows the
|
||||
// browser.theme.toolbar-theme pref.
|
||||
mWindow.appearanceSource = MOZGlobalAppearance.sharedInstance;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
|
||||
|
|
@ -2327,9 +2322,11 @@ void nsCocoaWindow::SetColorScheme(const Maybe<ColorScheme>& aScheme) {
|
|||
if (!mWindow) {
|
||||
return;
|
||||
}
|
||||
|
||||
mWindow.appearance = aScheme ? NSAppearanceForColorScheme(*aScheme) : nil;
|
||||
|
||||
NSAppearance* appearance =
|
||||
aScheme ? NSAppearanceForColorScheme(*aScheme) : nil;
|
||||
if (mWindow.appearance != appearance) {
|
||||
mWindow.appearance = appearance;
|
||||
}
|
||||
NS_OBJC_END_TRY_IGNORE_BLOCK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
* 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 "AppearanceOverride.h"
|
||||
#include "mozilla/widget/ThemeChangeKind.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsCocoaFeatures.h"
|
||||
|
|
|
|||
Loading…
Reference in a new issue