File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,20 @@ - (void)setWebViewCallbacks
527
527
returnCode: NSModalResponseCancel ];
528
528
};
529
529
530
+ m_web_view_bridge->on_request_color_picker = [self ](Color current_color) {
531
+ auto * panel = [NSColorPanel sharedColorPanel ];
532
+ [panel setColor: Ladybird: :gfx_color_to_ns_color (current_color)];
533
+ [panel setShowsAlpha: NO ];
534
+
535
+ NSNotificationCenter * notification_center = [NSNotificationCenter defaultCenter ];
536
+ [notification_center addObserver: self
537
+ selector: @selector (colorPickerClosed: )
538
+ name: NSWindowWillCloseNotification
539
+ object: panel];
540
+
541
+ [panel makeKeyAndOrderFront: nil ];
542
+ };
543
+
530
544
m_web_view_bridge->on_get_all_cookies = [](auto const & url) {
531
545
auto * delegate = (ApplicationDelegate*)[NSApp delegate ];
532
546
return [delegate cookieJar ].get_all_cookies (url);
@@ -603,6 +617,11 @@ - (void)setWebViewCallbacks
603
617
};
604
618
}
605
619
620
+ - (void )colorPickerClosed : (NSNotification *)notification
621
+ {
622
+ m_web_view_bridge->color_picker_closed (Ladybird::ns_color_to_gfx_color ([[NSColorPanel sharedColorPanel ] color ]));
623
+ }
624
+
606
625
- (NSScrollView *)scrollView
607
626
{
608
627
return (NSScrollView *)[self superview ];
Original file line number Diff line number Diff line change 8
8
9
9
#include < AK/String.h>
10
10
#include < AK/StringView.h>
11
+ #include < LibGfx/Color.h>
11
12
#include < LibGfx/Point.h>
12
13
#include < LibGfx/Rect.h>
13
14
#include < LibGfx/Size.h>
@@ -30,4 +31,7 @@ NSSize gfx_size_to_ns_size(Gfx::IntSize);
30
31
Gfx::IntPoint ns_point_to_gfx_point (NSPoint );
31
32
NSPoint gfx_point_to_ns_point (Gfx::IntPoint);
32
33
34
+ Gfx::Color ns_color_to_gfx_color (NSColor *);
35
+ NSColor * gfx_color_to_ns_color (Gfx::Color);
36
+
33
37
}
Original file line number Diff line number Diff line change @@ -86,4 +86,25 @@ NSPoint gfx_point_to_ns_point(Gfx::IntPoint point)
86
86
static_cast <CGFloat>(point.y ()));
87
87
}
88
88
89
+ Gfx::Color ns_color_to_gfx_color (NSColor * color)
90
+ {
91
+ auto rgb_color = [color colorUsingColorSpace: NSColorSpace .genericRGBColorSpace];
92
+ if (rgb_color != nil )
93
+ return {
94
+ static_cast <u8 >([rgb_color redComponent ] * 255 ),
95
+ static_cast <u8 >([rgb_color greenComponent ] * 255 ),
96
+ static_cast <u8 >([rgb_color blueComponent ] * 255 ),
97
+ static_cast <u8 >([rgb_color alphaComponent ] * 255 )
98
+ };
99
+ return {};
100
+ }
101
+
102
+ NSColor * gfx_color_to_ns_color (Gfx::Color color)
103
+ {
104
+ return [NSColor colorWithRed: (color.red () / 255 .f)
105
+ green: (color.green () / 255 .f)
106
+ blue: (color.blue () / 255 .f)
107
+ alpha: (color.alpha () / 255 .f)];
108
+ }
109
+
89
110
}
You can’t perform that action at this time.
0 commit comments