Skip to content

Truly independent web browser

UI/Qt: Tint selected text in chrome fields with the theme accent

Andreas Klingfeb9dbc5273c
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index 04fdc975888..ace93bb07a2 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -171,11 +171,6 @@ QColor chrome_accent()
return Theme::accent();
}
-static QColor chrome_text_highlight()
-{
- return over(Theme::selection(), Theme::panel().page);
-}
-
QColor chrome_text(QPalette const& palette)
{
return Theme::chrome(palette).text;
@@ -221,6 +216,33 @@ QString style_sheet_color(QColor const& color)
return qformatted("rgb({}, {}, {})", color.red(), color.green(), color.blue());
}
+// NB: Style sheets give a window in the background the colors of the rules without :active.
+static QString text_selection_style_sheet(QStringList const& selectors, Theme::TextSelectionColors const& active, Theme::TextSelectionColors const& inactive)
+{
+ QStringList active_selectors;
+ for (auto const& selector : selectors)
+ active_selectors.append(selector + ":active");
+ return qformatted(R"(
+{} {{
+ selection-background-color: {};
+ selection-color: {};
+}}
+
+{} {{
+ selection-background-color: {};
+ selection-color: {};
+}}
+)",
+ selectors.join(", "), style_sheet_color(inactive.background), style_sheet_color(inactive.text),
+ active_selectors.join(", "), style_sheet_color(active.background), style_sheet_color(active.text));
+}
+
+QString panel_text_selection_style_sheet(QStringList const& selectors, QColor const& text)
+{
+ return text_selection_style_sheet(selectors, Theme::panel_text_selection(QPalette::Active, text),
+ Theme::panel_text_selection(QPalette::Inactive, text));
+}
+
QString menu_zoom_row_style_sheet()
{
auto const& panel = Theme::panel();
@@ -505,8 +527,6 @@ QString location_edit_style_sheet(QPalette const& palette)
auto focus_border = style_sheet_color(chrome.field_edge.alpha() ? chrome.field_edge : focus_color);
auto text = style_sheet_color(chrome.text);
auto placeholder = style_sheet_color(chrome.muted);
- auto selection = style_sheet_color(chrome_text_highlight());
- auto selection_text = style_sheet_color(chrome.text);
auto not_secure_text = style_sheet_color(chrome.warning_ink);
auto not_secure_background = style_sheet_color(chrome.warning_fill);
auto not_secure_hover = style_sheet_color(warning_hover);
@@ -521,27 +541,25 @@ QLineEdit#LadybirdLocationEdit {{
color: {4};
background: {0};
border: 1px solid {2};
- border-radius: {18}px;
+ border-radius: {16}px;
min-height: 26px;
max-height: 26px;
padding: 0 8px;
- selection-background-color: {6};
- selection-color: {7};
placeholder-text-color: {5};
}}
QLineEdit#LadybirdLocationEdit[fieldHovered="true"] {{
background: {1};
- border-color: {8};
+ border-color: {6};
}}
QLineEdit#LadybirdLocationEdit:focus {{
- background: {17};
+ background: {15};
border-color: {3};
}}
QLineEdit#LadybirdLocationEdit[autocompleteOpen="true"] {{
- border-color: {17};
+ border-color: {15};
}}
QLineEdit#LadybirdLocationEdit:disabled {{
@@ -557,16 +575,16 @@ QToolButton#LadybirdLocationIcon {{
}}
QToolButton#LadybirdLocationIcon:hover {{
- background: {19};
+ background: {17};
}}
QToolButton#LadybirdLocationIcon:pressed {{
- background: {20};
+ background: {18};
}}
QToolButton#LadybirdLocationIcon[notSecure="true"] {{
- color: {9};
- background: {10};
+ color: {7};
+ background: {8};
border: 0;
border-radius: 5px;
padding: 0 8px;
@@ -575,16 +593,16 @@ QToolButton#LadybirdLocationIcon[notSecure="true"] {{
}}
QToolButton#LadybirdLocationIcon[notSecure="true"]:hover {{
- background: {11};
+ background: {9};
}}
QToolButton#LadybirdLocationIcon[notSecure="true"]:pressed {{
- background: {12};
+ background: {10};
}}
QToolButton#LadybirdLocationZoomIndicator {{
- color: {13};
- background: {14};
+ color: {11};
+ background: {12};
border: 0;
border-radius: 5px;
padding: 0 8px;
@@ -592,16 +610,16 @@ QToolButton#LadybirdLocationZoomIndicator {{
}}
QToolButton#LadybirdLocationZoomIndicator:hover {{
- background: {15};
+ background: {13};
}}
QToolButton#LadybirdLocationZoomIndicator:pressed {{
- background: {16};
+ background: {14};
}}
QToolButton#LadybirdInUseChip {{
- color: {13};
- background: {14};
+ color: {11};
+ background: {12};
border: 0;
border-radius: 5px;
padding: 0 8px;
@@ -609,11 +627,11 @@ QToolButton#LadybirdInUseChip {{
}}
QToolButton#LadybirdInUseChip:hover {{
- background: {15};
+ background: {13};
}}
QToolButton#LadybirdInUseChip:pressed {{
- background: {16};
+ background: {14};
}}
QToolButton#LadybirdLocationAction {{
@@ -629,9 +647,11 @@ QLineEdit#LadybirdLocationEdit QToolButton {{
min-height: 0;
}}
)",
- surface, hover, border, focus_border, text, placeholder, selection, selection_text, hover_border,
- not_secure_text, not_secure_background, not_secure_hover, not_secure_pressed, zoom_text, zoom_background, zoom_hover, zoom_pressed, focus, LOCATION_EDIT_CORNER_RADIUS,
- style_sheet_color(chrome.hover), style_sheet_color(panel.pressed));
+ surface, hover, border, focus_border, text, placeholder, hover_border,
+ not_secure_text, not_secure_background, not_secure_hover, not_secure_pressed, zoom_text, zoom_background, zoom_hover, zoom_pressed, focus, LOCATION_EDIT_CORNER_RADIUS,
+ style_sheet_color(chrome.hover), style_sheet_color(panel.pressed))
+ + text_selection_style_sheet({ "QLineEdit#LadybirdLocationEdit" }, Theme::address_field_text_selection(palette, QPalette::Active),
+ Theme::address_field_text_selection(palette, QPalette::Inactive));
}
QString bookmarks_bar_style_sheet(QPalette const& palette, int corner_radius)
@@ -697,8 +717,6 @@ QWidget#LadybirdFindInPageField QLineEdit {{
background: transparent;
border: 0;
padding: 0;
- selection-background-color: {6};
- selection-color: {1};
}}
QWidget#LadybirdFindInPageField[noResults="true"] {{
@@ -711,7 +729,7 @@ QLabel#LadybirdFindInPageResult {{
}}
QLabel#LadybirdFindInPageResult[noResults="true"] {{
- color: {9};
+ color: {8};
}}
QPushButton#LadybirdFindInPageButton {{
@@ -729,17 +747,18 @@ QPushButton#LadybirdFindInPageButton:hover {{
QPushButton#LadybirdFindInPageButton:checked {{
color: #ffffff;
- background: {7};
+ background: {6};
}}
QFrame#LadybirdFindInPageSeparator {{
- background: {8};
+ background: {7};
border: 0;
}}
)",
- style_sheet_color(panel.page), style_sheet_color(panel.text), style_sheet_color(panel.muted), style_sheet_color(panel.body),
- style_sheet_color(panel.control), style_sheet_color(no_match_fill), style_sheet_color(Theme::selection()), style_sheet_color(Theme::accent()),
- style_sheet_color(panel.separator), style_sheet_color(no_match_text));
+ style_sheet_color(panel.page), style_sheet_color(panel.text), style_sheet_color(panel.muted), style_sheet_color(panel.body),
+ style_sheet_color(panel.control), style_sheet_color(no_match_fill), style_sheet_color(Theme::accent()),
+ style_sheet_color(panel.separator), style_sheet_color(no_match_text))
+ + panel_text_selection_style_sheet({ "QWidget#LadybirdFindInPageField QLineEdit" }, panel.text);
}
QString javascript_dialog_style_sheet(QPalette const&)
@@ -785,12 +804,10 @@ QFrame#LadybirdJavaScriptDialogPanel QLineEdit {{
border-radius: 7px;
min-height: 28px;
padding: 0 9px;
- selection-background-color: {8};
- selection-color: {0};
}}
QCheckBox#LadybirdJavaScriptDialogBlockFurtherDialogs {{
- color: {9};
+ color: {8};
background: transparent;
font-size: 12px;
spacing: 8px;
@@ -841,9 +858,10 @@ QFrame#LadybirdJavaScriptDialogPanel QScrollBar::sub-page:vertical {{
background: transparent;
}}
)",
- style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.muted),
- style_sheet_color(panel.control), style_sheet_color(panel.pressed), style_sheet_color(primary), style_sheet_color(primary.darker(115)), style_sheet_color(Theme::selection()),
- style_sheet_color(panel.body));
+ style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.muted),
+ style_sheet_color(panel.control), style_sheet_color(panel.pressed), style_sheet_color(primary), style_sheet_color(primary.darker(115)),
+ style_sheet_color(panel.body))
+ + panel_text_selection_style_sheet({ "QFrame#LadybirdJavaScriptDialogPanel QLineEdit" }, panel.text);
}
QString bookmark_dialog_style_sheet(QPalette const& palette)
@@ -854,8 +872,6 @@ QString bookmark_dialog_style_sheet(QPalette const& palette)
auto pressed = style_sheet_color(chrome_control_surface_pressed(palette));
auto control_border = style_sheet_color(chrome_control_border(palette));
auto accent = style_sheet_color(chrome_accent());
- auto selection = style_sheet_color(chrome_text_highlight());
- auto selection_text = style_sheet_color(chrome_text(palette));
auto text = style_sheet_color(chrome_text(palette));
return qformatted(R"(
@@ -878,8 +894,6 @@ QDialog#LadybirdBookmarkDialog QComboBox {{
border-radius: 7px;
min-height: 26px;
padding: 2px 9px;
- selection-background-color: {7};
- selection-color: {8};
}}
QDialog#LadybirdBookmarkDialog QLineEdit:focus,
@@ -949,7 +963,9 @@ QDialog#LadybirdBookmarkDialog QPushButton:focus {{
border-color: {5};
}}
)",
- surface, recessed, hover, pressed, control_border, accent, text, selection, selection_text);
+ surface, recessed, hover, pressed, control_border, accent, text)
+ + panel_text_selection_style_sheet({ "QDialog#LadybirdBookmarkDialog QLineEdit", "QDialog#LadybirdBookmarkDialog QComboBox" },
+ chrome_text(palette));
}
QString report_review_style_sheet(QPalette const& palette)
@@ -957,8 +973,6 @@ QString report_review_style_sheet(QPalette const& palette)
auto recessed = style_sheet_color(chrome_surface_recessed(palette));
auto control_border = style_sheet_color(chrome_control_border(palette));
auto accent = style_sheet_color(chrome_accent());
- auto selection = style_sheet_color(chrome_text_highlight());
- auto selection_text = style_sheet_color(chrome_text(palette));
auto text = style_sheet_color(chrome_text(palette));
auto muted = style_sheet_color(chrome_muted_text(palette));
@@ -969,8 +983,6 @@ QWidget#LadybirdReportReview QPlainTextEdit {{
background: {0};
border: 1px solid transparent;
border-radius: 7px;
- selection-background-color: {5};
- selection-color: {6};
}}
QWidget#LadybirdReportReview QLineEdit {{
@@ -998,20 +1010,22 @@ QWidget#LadybirdReportReview QFrame#ReportDetails {{
}}
QWidget#LadybirdReportReview QPushButton#WebCompatReportShowReportButton {{
- color: {7};
+ color: {5};
background: transparent;
border: 0;
padding: 0;
}}
QWidget#LadybirdReportReview QFrame#WebCompatReportFooterLine {{
- background: {8};
+ background: {6};
border: 0;
min-height: 1px;
max-height: 1px;
}}
)",
- recessed, control_border, accent, text, muted, selection, selection_text, style_sheet_color(Theme::panel().link), style_sheet_color(Theme::panel().separator_soft));
+ recessed, control_border, accent, text, muted, style_sheet_color(Theme::panel().link), style_sheet_color(Theme::panel().separator_soft))
+ + panel_text_selection_style_sheet({ "QWidget#LadybirdReportReview QLineEdit", "QWidget#LadybirdReportReview QPlainTextEdit" },
+ chrome_text(palette));
}
// Placeholders hint at what to write, so they stay readable rather than taking the platform's faintest text color.
@@ -1438,11 +1452,10 @@ QLineEdit#LadybirdBookmarkPopoverName {{
max-height: 28px;
padding: 0 8px;
font-size: 13px;
- selection-background-color: {8};
}}
QLineEdit#LadybirdBookmarkPopoverName:focus {{
- border-color: {9};
+ border-color: {8};
}}
QComboBox#LadybirdBookmarkPopoverFolder {{
@@ -1476,7 +1489,7 @@ QPushButton#LadybirdBookmarkPopoverRemove {{
}}
QPushButton#LadybirdBookmarkPopoverRemove:pressed {{
- background: {10};
+ background: {9};
}}
QPushButton#LadybirdBookmarkPopoverDone {{
@@ -1494,9 +1507,10 @@ QPushButton#LadybirdBookmarkPopoverDone:pressed {{
background: {7};
}}
)",
- style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.muted),
- style_sheet_color(panel.page), style_sheet_color(panel.control), style_sheet_color(primary), style_sheet_color(primary.darker(122)),
- style_sheet_color(Theme::selection()), style_sheet_color(Theme::focus_edge()), style_sheet_color(panel.pressed));
+ style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.muted),
+ style_sheet_color(panel.page), style_sheet_color(panel.control), style_sheet_color(primary), style_sheet_color(primary.darker(122)),
+ style_sheet_color(Theme::focus_edge()), style_sheet_color(panel.pressed))
+ + panel_text_selection_style_sheet({ "QLineEdit#LadybirdBookmarkPopoverName" }, panel.text);
}
// A permission prompt looks like a message popover, its three answers stacked as equal secondary buttons, since the
@@ -1811,7 +1825,6 @@ QLineEdit#LadybirdAllTabsSearch {{
max-height: 28px;
padding: 0 6px 0 2px;
font-size: 13px;
- selection-background-color: {4};
}}
QScrollArea#LadybirdAllTabsList, QScrollArea#LadybirdAllTabsList > QWidget {{
@@ -1819,18 +1832,19 @@ QScrollArea#LadybirdAllTabsList, QScrollArea#LadybirdAllTabsList > QWidget {{
}}
QLabel#LadybirdAllTabsHeading {{
- color: {5};
+ color: {4};
background: transparent;
font-size: 12px;
}}
QFrame#LadybirdPopoverSeparator {{
- background: {6};
+ background: {5};
border: 0;
}}
)",
- style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.control),
- style_sheet_color(Theme::selection()), style_sheet_color(panel.muted), style_sheet_color(panel.separator));
+ style_sheet_color(panel.text), style_sheet_color(panel.surface), style_sheet_color(over(panel.edge, panel.surface)), style_sheet_color(panel.control),
+ style_sheet_color(panel.muted), style_sheet_color(panel.separator))
+ + panel_text_selection_style_sheet({ "QLineEdit#LadybirdAllTabsSearch" }, panel.text);
}
QString zoom_popover_style_sheet(QPalette const&)
diff --git a/UI/Qt/ChromeStyle.h b/UI/Qt/ChromeStyle.h
index 457ece83135..b6a89496d2a 100644
--- a/UI/Qt/ChromeStyle.h
+++ b/UI/Qt/ChromeStyle.h
@@ -10,6 +10,7 @@
#include <AK/Types.h>
#include <QColor>
#include <QString>
+#include <QStringList>
class QAbstractButton;
class QFont;
@@ -75,6 +76,9 @@ QFont chrome_title_font(QFont);
QString style_sheet_color(QColor const&);
+// The colors of selected text in the fields the selectors match, for a field on a panel.
+QString panel_text_selection_style_sheet(QStringList const& selectors, QColor const& text);
+
// The panel outline painted over the panel, for a panel that cannot be partly clear.
QColor opaque_panel_edge();
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index ae7343ccfe1..f8de2f24bf5 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -534,14 +534,13 @@ QLineEdit#LadybirdTaskManagerFilter {{
border: none;
border-radius: 7px;
padding: 0 8px;
- selection-background-color: {5};
}}
QWidget#LadybirdTaskManagerFooter {{
background: {0};
border-top: 1px solid {2};
}}
QLabel#LadybirdTaskManagerSummary {{
- color: {6};
+ color: {5};
}}
QPushButton#LadybirdTaskManagerEndButton {{
color: {3};
@@ -551,10 +550,10 @@ QPushButton#LadybirdTaskManagerEndButton {{
padding: 0 14px;
}}
QPushButton#LadybirdTaskManagerEndButton:pressed {{
- background: {7};
+ background: {6};
}}
QPushButton#LadybirdTaskManagerEndButton:disabled {{
- color: {6};
+ color: {5};
}}
QTreeWidget {{
background: {0};
@@ -566,8 +565,9 @@ QTreeWidget::item {{
padding: 0px 4px;
}}
)",
- color(panel.page), color(Theme::chrome().toolbar), color(panel.separator), color(panel.text), color(panel.control),
- color(Theme::selection()), color(panel.muted), color(panel.pressed)));
+ color(panel.page), color(Theme::chrome().toolbar), color(panel.separator), color(panel.text), color(panel.control),
+ color(panel.muted), color(panel.pressed))
+ + ChromeStyle::panel_text_selection_style_sheet({ "QLineEdit#LadybirdTaskManagerFilter" }, panel.text));
// NB: The tree draws the selected row's fill itself, so the style's highlight under the branch area is left clear.
auto tree_palette = m_processes->palette();
diff --git a/UI/Qt/Theme.cpp b/UI/Qt/Theme.cpp
index 339a7f40175..3f8909236da 100644
--- a/UI/Qt/Theme.cpp
+++ b/UI/Qt/Theme.cpp
@@ -444,14 +444,17 @@ static AccentColor const& system_accent_color()
}
// The theme's accent clears 3:1 on the toolbar, darker on the light appearance and lighter on the dark one.
-QColor accent()
+static QColor accent(bool dark, QColor const& toolbar)
{
- if (s_color_theme.accent.has_value()) {
- auto dark = is_dark();
- return with_contrast(*s_color_theme.accent, chrome().toolbar, 3, dark ? Adjustment::Lighten : Adjustment::Darken);
- }
+ if (s_color_theme.accent.has_value())
+ return with_contrast(*s_color_theme.accent, toolbar, 3, dark ? Adjustment::Lighten : Adjustment::Darken);
auto const& accent = system_accent_color();
- return is_dark() ? accent.dark : accent.light;
+ return dark ? accent.dark : accent.light;
+}
+
+QColor accent()
+{
+ return accent(is_dark(), chrome().toolbar);
}
// On the dark appearance, the focus ring is a lighter tint of the accent, as the accent itself is too deep there.
@@ -479,11 +482,33 @@ QColor focus_ring()
return color;
}
-QColor selection()
+static TextSelectionColors text_selection(QPalette::ColorGroup group, bool dark, QColor const& toolbar, QColor const& text)
{
- auto color = accent();
- color.setAlphaF(is_dark() ? 0.40f : 0.22f);
- return color;
+ // NB: The system's colors suit only chrome of the system's own appearance, which a private window may not have.
+ if (!s_color_theme.accent.has_value()) {
+ auto system_palette = QGuiApplication::palette();
+ auto system_is_dark = system_palette.color(QPalette::Window).lightness() < 128;
+ if (system_is_dark == dark)
+ return { system_palette.color(group, QPalette::Highlight), system_palette.color(group, QPalette::HighlightedText) };
+ }
+
+ if (group != QPalette::Active)
+ return { dark ? rgba(255, 255, 255, 0.14) : rgba(0, 0, 0, 0.10), text };
+
+ auto background = accent(dark, toolbar);
+ background.setAlphaF(dark ? 0.40f : 0.28f);
+ return { background, text };
+}
+
+TextSelectionColors address_field_text_selection(QPalette const& palette, QPalette::ColorGroup group)
+{
+ auto const& colors = chrome(palette);
+ return text_selection(group, is_dark(palette), colors.toolbar, colors.text);
+}
+
+TextSelectionColors panel_text_selection(QPalette::ColorGroup group, QColor const& text)
+{
+ return text_selection(group, is_dark(), chrome().toolbar, text);
}
// The theme's accent fills primary buttons and selected rows deep enough that white text on them clears 4.5:1.
diff --git a/UI/Qt/Theme.h b/UI/Qt/Theme.h
index 54e887a13dc..226c8cdebbd 100644
--- a/UI/Qt/Theme.h
+++ b/UI/Qt/Theme.h
@@ -98,7 +98,16 @@ QColor accent();
// A focus ring is a fine line of the focus edge color right outside the focused control, in a wider, fainter halo.
QColor focus_edge();
QColor focus_ring();
-QColor selection();
+
+// Selected text in a field. A color theme tints it with its accent and keeps the text in its normal color, so it stays
+// readable on every theme and looks unlike a selected row. A window in the background shows a gray tint instead.
+// Without a color theme, it is the system's own text selection color.
+struct TextSelectionColors {
+ QColor background;
+ QColor text;
+};
+TextSelectionColors address_field_text_selection(QPalette const&, QPalette::ColorGroup);
+TextSelectionColors panel_text_selection(QPalette::ColorGroup, QColor const& text);
// The fill of a primary button, a blue that white text stays clear on.
QColor primary();