forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use NSAppearance in color pipeline for Mac
This updates the color pipeline and NativeThemeMac ways of getting colors to stop relying on the NSApp level NSAppearance. Instead they use the passed in color_scheme to set a (thread) local NSAppearance value when they load system colors so they get the correct light/dark color. This value is removed at the end of the function to clean up the state. Bug: 1071671 Change-Id: Ie8bc333bd955b64594fa2b0b538895d6749853e0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2161318 Commit-Queue: Joan Barnett <johnsm@microsoft.com> Reviewed-by: Peter Kasting <pkasting@chromium.org> Cr-Commit-Position: refs/heads/master@{#762617}
- Loading branch information
John Smith
authored and
Commit Bot
committed
Apr 25, 2020
1 parent
586bec6
commit cb6ef92
Showing
6 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_COLOR_MAC_SCOPED_CURRENT_NSAPPEARANCE_H_ | ||
#define UI_COLOR_MAC_SCOPED_CURRENT_NSAPPEARANCE_H_ | ||
|
||
#include "base/component_export.h" | ||
|
||
namespace ui { | ||
|
||
// Class for handling changing the NSAppearance to get colors in a scoped way | ||
// based on the desired light/dark colors scheme. | ||
class COMPONENT_EXPORT(COLOR) ScopedCurrentNSAppearance { | ||
public: | ||
explicit ScopedCurrentNSAppearance(bool dark); | ||
|
||
// There should be no reason to copy or move a ScopedCurrentNSAppearance. | ||
ScopedCurrentNSAppearance(const ScopedCurrentNSAppearance&) = delete; | ||
ScopedCurrentNSAppearance& operator=(const ScopedCurrentNSAppearance&) = | ||
delete; | ||
|
||
~ScopedCurrentNSAppearance(); | ||
}; | ||
|
||
} // namespace ui | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/color/mac/scoped_current_nsappearance.h" | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
namespace ui { | ||
ScopedCurrentNSAppearance::ScopedCurrentNSAppearance(bool dark) { | ||
if (@available(macOS 10.14, *)) { | ||
NSAppearanceName appearance = | ||
dark ? NSAppearanceNameDarkAqua : NSAppearanceNameAqua; | ||
[NSAppearance | ||
setCurrentAppearance:[NSAppearance appearanceNamed:appearance]]; | ||
} | ||
} | ||
|
||
ScopedCurrentNSAppearance::~ScopedCurrentNSAppearance() { | ||
if (@available(macOS 10.14, *)) | ||
[NSAppearance setCurrentAppearance:nil]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters