1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:17:36 +00:00

LibWeb: Allow input color to give continuous updates

This commit is contained in:
Bastiaan van der Plaat 2023-12-11 06:53:10 +01:00 committed by Andrew Kaster
parent cf69fd0a09
commit 0dd5aa40a8
13 changed files with 53 additions and 19 deletions

View file

@ -599,6 +599,8 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
auto* panel = [NSColorPanel sharedColorPanel];
[panel setColor:Ladybird::gfx_color_to_ns_color(current_color)];
[panel setShowsAlpha:NO];
[panel setTarget:self];
[panel setAction:@selector(colorPickerUpdate:)];
NSNotificationCenter* notification_center = [NSNotificationCenter defaultCenter];
[notification_center addObserver:self
@ -761,9 +763,14 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
m_web_view_bridge->select_dropdown_closed({});
}
- (void)colorPickerUpdate:(NSColorPanel*)colorPanel
{
m_web_view_bridge->color_picker_update(Ladybird::ns_color_to_gfx_color(colorPanel.color), Web::HTML::ColorPickerUpdateState::Update);
}
- (void)colorPickerClosed:(NSNotification*)notification
{
m_web_view_bridge->color_picker_closed(Ladybird::ns_color_to_gfx_color([[NSColorPanel sharedColorPanel] color]));
m_web_view_bridge->color_picker_update(Ladybird::ns_color_to_gfx_color([NSColorPanel sharedColorPanel].color), Web::HTML::ColorPickerUpdateState::Closed);
}
- (NSScrollView*)scrollView

View file

@ -217,11 +217,14 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
dialog.setWindowTitle("Ladybird");
dialog.setOption(QColorDialog::ShowAlphaChannel, false);
QObject::connect(&dialog, &QColorDialog::currentColorChanged, this, [this](const QColor& color) {
view().color_picker_update(Color(color.red(), color.green(), color.blue()), Web::HTML::ColorPickerUpdateState::Update);
});
if (dialog.exec() == QDialog::Accepted)
view().color_picker_closed(Color(dialog.selectedColor().red(), dialog.selectedColor().green(), dialog.selectedColor().blue()));
view().color_picker_update(Color(dialog.selectedColor().red(), dialog.selectedColor().green(), dialog.selectedColor().blue()), Web::HTML::ColorPickerUpdateState::Closed);
else
view().color_picker_closed({});
view().color_picker_update({}, Web::HTML::ColorPickerUpdateState::Closed);
m_dialog = nullptr;
};