Ladybird/AppKit: Update chrome color on theme color change

This commit is contained in:
Junior Rantila 2023-09-19 01:57:10 +02:00 committed by Andrew Kaster
parent a5b01689f1
commit 31ff752a10
4 changed files with 41 additions and 0 deletions

View file

@ -26,6 +26,7 @@
- (void)loadURL:(URL const&)url;
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)is_redirect;
- (void)onLoadFinish:(URL const&)url;
- (void)onThemeColorChange:(Color)color;
- (void)onTitleChange:(DeprecatedString const&)title;
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;

View file

@ -615,6 +615,14 @@ struct HideCursor {
url:url
activateTab:Web::HTML::ActivateTab::Yes];
};
m_web_view_bridge->on_theme_color_change = [self](auto color) {
self.backgroundColor = [NSColor colorWithRed:(color.red() / 255.0)
green:(color.green() / 255.0)
blue:(color.blue() / 255.0)
alpha:1.0];
[self.observer onThemeColorChange:color];
};
}
- (void)colorPickerClosed:(NSNotification*)notification

View file

@ -36,6 +36,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
@property (nonatomic, strong) ConsoleController* console_controller;
@property (nonatomic, strong) InspectorController* inspector_controller;
@property (nonatomic, assign) URL last_url;
@end
@implementation Tab
@ -100,6 +102,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
object:[scroll_view contentView]];
[self setContentView:scroll_view];
self.backgroundColor = [NSColor windowBackgroundColor];
self.titlebarAppearsTransparent = YES;
}
return self;
@ -242,6 +246,11 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
- (void)onLoadStart:(URL const&)url isRedirect:(BOOL)is_redirect
{
if (url != self.last_url) {
self.backgroundColor = [NSColor windowBackgroundColor];
self.last_url = url;
}
[[self tabController] onLoadStart:url isRedirect:is_redirect];
self.title = Ladybird::string_to_ns_string(url.serialize());
@ -274,6 +283,23 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
[self updateTabTitleAndFavicon];
}
- (void)onThemeColorChange:(Color)color
{
auto* nscolor = [NSColor colorWithRed:((CGFloat)color.red()) / 255.0
green:((CGFloat)color.green()) / 255.0
blue:((CGFloat)color.blue()) / 255.0
alpha:1.0];
CGFloat hue = 0.0;
CGFloat saturation = 0.0;
CGFloat brightness = 0.0;
[nscolor getHue:&hue saturation:&saturation brightness:&brightness alpha:nil];
if (brightness > 0.75)
brightness = 0.75;
nscolor = [NSColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1.0];
self.backgroundColor = nscolor;
self.titlebarAppearsTransparent = YES;
}
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap
{
static constexpr size_t FAVICON_SIZE = 16;

View file

@ -193,9 +193,13 @@ enum class IsHistoryNavigation {
{
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
self.tab.titlebarAppearsTransparent = NO;
[delegate createNewTab:OptionalNone {}
fromTab:[self tab]
activateTab:Web::HTML::ActivateTab::Yes];
self.tab.titlebarAppearsTransparent = YES;
}
- (void)updateNavigationButtonStates
@ -212,7 +216,9 @@ enum class IsHistoryNavigation {
- (void)showTabOverview:(id)sender
{
self.tab.titlebarAppearsTransparent = NO;
[self.window toggleTabOverview:sender];
self.tab.titlebarAppearsTransparent = YES;
}
- (void)dumpDOMTree:(id)sender