Ladybird/AppKit: Update chrome color on theme color change
This commit is contained in:
parent
a5b01689f1
commit
31ff752a10
Notes:
sideshowbarker
2024-07-17 21:16:31 +09:00
Author: https://github.com/juniorrantila Commit: https://github.com/SerenityOS/serenity/commit/31ff752a10 Pull-request: https://github.com/SerenityOS/serenity/pull/21150 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/bplaat Reviewed-by: https://github.com/shannonbooth
4 changed files with 41 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue