mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
Ladybird/AppKit: Add color picker support
This commit is contained in:
parent
ebee480bcc
commit
0ce9dc4c8e
3 changed files with 44 additions and 0 deletions
|
@ -527,6 +527,20 @@ struct HideCursor {
|
||||||
returnCode:NSModalResponseCancel];
|
returnCode:NSModalResponseCancel];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
m_web_view_bridge->on_request_color_picker = [self](Color current_color) {
|
||||||
|
auto* panel = [NSColorPanel sharedColorPanel];
|
||||||
|
[panel setColor:Ladybird::gfx_color_to_ns_color(current_color)];
|
||||||
|
[panel setShowsAlpha:NO];
|
||||||
|
|
||||||
|
NSNotificationCenter* notification_center = [NSNotificationCenter defaultCenter];
|
||||||
|
[notification_center addObserver:self
|
||||||
|
selector:@selector(colorPickerClosed:)
|
||||||
|
name:NSWindowWillCloseNotification
|
||||||
|
object:panel];
|
||||||
|
|
||||||
|
[panel makeKeyAndOrderFront:nil];
|
||||||
|
};
|
||||||
|
|
||||||
m_web_view_bridge->on_get_all_cookies = [](auto const& url) {
|
m_web_view_bridge->on_get_all_cookies = [](auto const& url) {
|
||||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||||
return [delegate cookieJar].get_all_cookies(url);
|
return [delegate cookieJar].get_all_cookies(url);
|
||||||
|
@ -603,6 +617,11 @@ struct HideCursor {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)colorPickerClosed:(NSNotification*)notification
|
||||||
|
{
|
||||||
|
m_web_view_bridge->color_picker_closed(Ladybird::ns_color_to_gfx_color([[NSColorPanel sharedColorPanel] color]));
|
||||||
|
}
|
||||||
|
|
||||||
- (NSScrollView*)scrollView
|
- (NSScrollView*)scrollView
|
||||||
{
|
{
|
||||||
return (NSScrollView*)[self superview];
|
return (NSScrollView*)[self superview];
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <LibGfx/Color.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
#include <LibGfx/Size.h>
|
#include <LibGfx/Size.h>
|
||||||
|
@ -30,4 +31,7 @@ NSSize gfx_size_to_ns_size(Gfx::IntSize);
|
||||||
Gfx::IntPoint ns_point_to_gfx_point(NSPoint);
|
Gfx::IntPoint ns_point_to_gfx_point(NSPoint);
|
||||||
NSPoint gfx_point_to_ns_point(Gfx::IntPoint);
|
NSPoint gfx_point_to_ns_point(Gfx::IntPoint);
|
||||||
|
|
||||||
|
Gfx::Color ns_color_to_gfx_color(NSColor*);
|
||||||
|
NSColor* gfx_color_to_ns_color(Gfx::Color);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,4 +86,25 @@ NSPoint gfx_point_to_ns_point(Gfx::IntPoint point)
|
||||||
static_cast<CGFloat>(point.y()));
|
static_cast<CGFloat>(point.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::Color ns_color_to_gfx_color(NSColor* color)
|
||||||
|
{
|
||||||
|
auto rgb_color = [color colorUsingColorSpace:NSColorSpace.genericRGBColorSpace];
|
||||||
|
if (rgb_color != nil)
|
||||||
|
return {
|
||||||
|
static_cast<u8>([rgb_color redComponent] * 255),
|
||||||
|
static_cast<u8>([rgb_color greenComponent] * 255),
|
||||||
|
static_cast<u8>([rgb_color blueComponent] * 255),
|
||||||
|
static_cast<u8>([rgb_color alphaComponent] * 255)
|
||||||
|
};
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
NSColor* gfx_color_to_ns_color(Gfx::Color color)
|
||||||
|
{
|
||||||
|
return [NSColor colorWithRed:(color.red() / 255.f)
|
||||||
|
green:(color.green() / 255.f)
|
||||||
|
blue:(color.blue() / 255.f)
|
||||||
|
alpha:(color.alpha() / 255.f)];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue