Browse Source

Ladybird/AppKit: Update chrome color on theme color change

Junior Rantila 1 year ago
parent
commit
31ff752a10

+ 1 - 0
Ladybird/AppKit/UI/LadybirdWebView.h

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

+ 8 - 0
Ladybird/AppKit/UI/LadybirdWebView.mm

@@ -615,6 +615,14 @@ struct HideCursor {
                                   url:url
                                   url:url
                           activateTab:Web::HTML::ActivateTab::Yes];
                           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
 - (void)colorPickerClosed:(NSNotification*)notification

+ 26 - 0
Ladybird/AppKit/UI/Tab.mm

@@ -36,6 +36,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
 @property (nonatomic, strong) ConsoleController* console_controller;
 @property (nonatomic, strong) ConsoleController* console_controller;
 @property (nonatomic, strong) InspectorController* inspector_controller;
 @property (nonatomic, strong) InspectorController* inspector_controller;
 
 
+@property (nonatomic, assign) URL last_url;
+
 @end
 @end
 
 
 @implementation Tab
 @implementation Tab
@@ -100,6 +102,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
                  object:[scroll_view contentView]];
                  object:[scroll_view contentView]];
 
 
         [self setContentView:scroll_view];
         [self setContentView:scroll_view];
+        self.backgroundColor = [NSColor windowBackgroundColor];
+        self.titlebarAppearsTransparent = YES;
     }
     }
 
 
     return self;
     return self;
@@ -242,6 +246,11 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
 
 
 - (void)onLoadStart:(URL const&)url isRedirect:(BOOL)is_redirect
 - (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 tabController] onLoadStart:url isRedirect:is_redirect];
 
 
     self.title = Ladybird::string_to_ns_string(url.serialize());
     self.title = Ladybird::string_to_ns_string(url.serialize());
@@ -274,6 +283,23 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
     [self updateTabTitleAndFavicon];
     [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
 - (void)onFaviconChange:(Gfx::Bitmap const&)bitmap
 {
 {
     static constexpr size_t FAVICON_SIZE = 16;
     static constexpr size_t FAVICON_SIZE = 16;

+ 6 - 0
Ladybird/AppKit/UI/TabController.mm

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