mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
Ladybird/BrowserWindow: Add UI for switching preferred CSS color scheme
This commit is contained in:
parent
98bf0107ce
commit
97964bc710
4 changed files with 76 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include "WebView.h"
|
#include "WebView.h"
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QActionGroup>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
|
|
||||||
|
@ -59,6 +60,32 @@ BrowserWindow::BrowserWindow()
|
||||||
view_menu->addAction(open_previous_tab_action);
|
view_menu->addAction(open_previous_tab_action);
|
||||||
QObject::connect(open_previous_tab_action, &QAction::triggered, this, &BrowserWindow::open_previous_tab);
|
QObject::connect(open_previous_tab_action, &QAction::triggered, this, &BrowserWindow::open_previous_tab);
|
||||||
|
|
||||||
|
view_menu->addSeparator();
|
||||||
|
|
||||||
|
auto* color_scheme_menu = view_menu->addMenu("&Color Scheme");
|
||||||
|
|
||||||
|
auto* group = new QActionGroup(this);
|
||||||
|
|
||||||
|
auto* auto_color_scheme = new QAction("&Auto");
|
||||||
|
auto_color_scheme->setCheckable(true);
|
||||||
|
group->addAction(auto_color_scheme);
|
||||||
|
color_scheme_menu->addAction(auto_color_scheme);
|
||||||
|
QObject::connect(auto_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_auto_color_scheme);
|
||||||
|
|
||||||
|
auto* light_color_scheme = new QAction("&Light");
|
||||||
|
light_color_scheme->setCheckable(true);
|
||||||
|
group->addAction(light_color_scheme);
|
||||||
|
color_scheme_menu->addAction(light_color_scheme);
|
||||||
|
QObject::connect(light_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_light_color_scheme);
|
||||||
|
|
||||||
|
auto* dark_color_scheme = new QAction("&Dark");
|
||||||
|
dark_color_scheme->setCheckable(true);
|
||||||
|
group->addAction(dark_color_scheme);
|
||||||
|
color_scheme_menu->addAction(dark_color_scheme);
|
||||||
|
QObject::connect(dark_color_scheme, &QAction::triggered, this, &BrowserWindow::enable_dark_color_scheme);
|
||||||
|
|
||||||
|
auto_color_scheme->setChecked(true);
|
||||||
|
|
||||||
auto* inspect_menu = menuBar()->addMenu("&Inspect");
|
auto* inspect_menu = menuBar()->addMenu("&Inspect");
|
||||||
|
|
||||||
auto* view_source_action = new QAction("View &Source");
|
auto* view_source_action = new QAction("View &Source");
|
||||||
|
@ -294,3 +321,24 @@ void BrowserWindow::open_previous_tab()
|
||||||
next_index = m_tabs_container->count() - 1;
|
next_index = m_tabs_container->count() - 1;
|
||||||
m_tabs_container->setCurrentIndex(next_index);
|
m_tabs_container->setCurrentIndex(next_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::enable_auto_color_scheme()
|
||||||
|
{
|
||||||
|
for (auto& tab : m_tabs) {
|
||||||
|
tab.view().set_color_scheme(ColorScheme::Auto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::enable_light_color_scheme()
|
||||||
|
{
|
||||||
|
for (auto& tab : m_tabs) {
|
||||||
|
tab.view().set_color_scheme(ColorScheme::Light);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BrowserWindow::enable_dark_color_scheme()
|
||||||
|
{
|
||||||
|
for (auto& tab : m_tabs) {
|
||||||
|
tab.view().set_color_scheme(ColorScheme::Dark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ public slots:
|
||||||
void close_current_tab();
|
void close_current_tab();
|
||||||
void open_next_tab();
|
void open_next_tab();
|
||||||
void open_previous_tab();
|
void open_previous_tab();
|
||||||
|
void enable_auto_color_scheme();
|
||||||
|
void enable_light_color_scheme();
|
||||||
|
void enable_dark_color_scheme();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void debug_request(String const& request, String const& argument = "");
|
void debug_request(String const& request, String const& argument = "");
|
||||||
|
|
|
@ -970,3 +970,20 @@ void WebView::show_js_console()
|
||||||
m_js_console_widget->show();
|
m_js_console_widget->show();
|
||||||
m_js_console_input_edit->setFocus();
|
m_js_console_input_edit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebView::set_color_scheme(ColorScheme color_scheme)
|
||||||
|
{
|
||||||
|
switch (color_scheme) {
|
||||||
|
case ColorScheme::Auto:
|
||||||
|
m_page_client->m_preferred_color_scheme = Web::CSS::PreferredColorScheme::Auto;
|
||||||
|
break;
|
||||||
|
case ColorScheme::Light:
|
||||||
|
m_page_client->m_preferred_color_scheme = Web::CSS::PreferredColorScheme::Light;
|
||||||
|
break;
|
||||||
|
case ColorScheme::Dark:
|
||||||
|
m_page_client->m_preferred_color_scheme = Web::CSS::PreferredColorScheme::Dark;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (auto* document = m_page_client->page().top_level_browsing_context().active_document())
|
||||||
|
document->invalidate_style();
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,12 @@ class QLineEdit;
|
||||||
|
|
||||||
class HeadlessBrowserPageClient;
|
class HeadlessBrowserPageClient;
|
||||||
|
|
||||||
|
enum class ColorScheme {
|
||||||
|
Auto,
|
||||||
|
Light,
|
||||||
|
Dark,
|
||||||
|
};
|
||||||
|
|
||||||
class WebView final : public QAbstractScrollArea {
|
class WebView final : public QAbstractScrollArea {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -49,6 +55,8 @@ public:
|
||||||
Gfx::IntPoint to_content(Gfx::IntPoint) const;
|
Gfx::IntPoint to_content(Gfx::IntPoint) const;
|
||||||
Gfx::IntPoint to_widget(Gfx::IntPoint) const;
|
Gfx::IntPoint to_widget(Gfx::IntPoint) const;
|
||||||
|
|
||||||
|
void set_color_scheme(ColorScheme);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void link_hovered(QString, int timeout = 0);
|
void link_hovered(QString, int timeout = 0);
|
||||||
void link_unhovered();
|
void link_unhovered();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue