Truly independent web browser
UI/Qt: Dim the close buttons of inactive tabs
Andreas Kling578c274bea54
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 5596136d799..526c78d9087 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -97,7 +97,7 @@ All sizes are in logical pixels.| Active tab | 30 px tall | 8 px top radius plus an 8 px inverted "foot" on each side where it joins the toolbar. 5 px of strip shows above it. Its contents are vertically centered in it, which puts them on the shared center line. || End insets | Favicon 7 px from the left edge; × glyph 11 px from the right edge | Rule: each end item is as far from the tab's side as it is from the tab's top (the 16 px favicon sits 7 px down, the 8 px × glyph 11 px down). Padding: active 0 6 px 0 7 px; inactive 3 px inset + 0 3 px 0 4 px, so favicons and × never move when a tab becomes active. || Favicon to title | 8 px | |-| Close button | 18 px hover square, 7 px × (14 px glyph box); click area extends to the full tab height | The × is always visible on every tab except pinned tabs, in `muted`; its hover square appears on hover. Indicators like the speaker and the microphone sit to its left. |+| Close button | 18 px hover square, 7 px × (14 px glyph box); click area extends to the full tab height | The × is always visible on every tab except pinned tabs, in `muted`. On tabs that are neither active nor hovered it is dimmed as a whole, to 75% opacity in light and 55% in dark and private, and it is at full opacity on the active tab, on a hovered tab and with increased contrast. Its hover square appears on hover. Indicators like the speaker and the microphone sit to its left. || Tab width | 20 to 232 px | Tabs shrink until only the favicon is left, giving up their padding below 32 px, then the strip scrolls. A tab too narrow for its favicon beside its × shows only the favicon; the active one shows its × in the favicon's place. || Pinned tab | 44 px wide | Favicon only, always first. While the tab plays audio or uses the microphone, those indicators take the favicon's place. || New tab (+) | 26 px button, 14 px glyph | Follows the last tab directly, 8 px after it (just clear of the active tab's foot), centered on the tab row; with few tabs it does not move to the end of the strip. Click area at least 32 px. |@@ -130,7 +130,7 @@ All sizes are in logical pixels.| Element | Size ||---|---|| Sidebar width | 236 px |-| Tab rows | 30 px, 6 px radius. Selected: toolbar color with a soft shadow in light; white 15% fill only in dark and private, with no ring: on the dark sidebar the fill is enough, and stacked outlines (Ladybird button, focused field, row) make the column busy. The × on each row is lighter at rest (`#9C9CA3` light, `#7A7A81` dark) and takes the `muted` color on the hovered and selected rows, so a full list does not draw a dark stripe down the sidebar. It is always there; only its tone changes. |+| Tab rows | 30 px, 6 px radius. Selected: toolbar color with a soft shadow in light; white 15% fill only in dark and private, with no ring: on the dark sidebar the fill is enough, and stacked outlines (Ladybird button, focused field, row) make the column busy. The × on each row is dimmed at rest, as on a horizontal tab (75% opacity in light, 55% in dark and private), and is at full opacity on the hovered and selected rows, so a full list does not draw a dark stripe down the sidebar. It is always there; only its tone changes. || Collapsed rail | 52 px. Tiles are 36 × 32 with the favicon centered. Badges sit on the favicon's corners, 18 px round on a toolbar-colored backing with a hairline ring: × top left (on hover only), speaker bottom right (while playing or muted), microphone bottom left (while in use). The × and the speaker are buttons, and opposite corners keep them apart. The microphone is not a button; it sits 2 px from the speaker and touches the × while that shows on hover. || Header | Traffic lights, Ladybird button, all tabs, then empty space, then the hide-sidebar toggle at the sidebar's right edge. With the sidebar collapsed, the toolbar starts the same way: traffic lights, Ladybird button, all tabs, show-sidebar toggle. || Background | `sidebar` token: the strip color in light, the toolbar color in dark and private. The page must never sit directly against near-black chrome. |@@ -769,7 +769,7 @@ zoom chip, drag and drop) is on the canvas's motion spec board.| Situation | Behavior ||---|---|| Tooltips | After 500 ms of hover. Once one has shown, neighbouring tooltips appear at once for the next 1.5 s. |-| Tab close | Every tab except pinned tabs always shows its ×. A tab too narrow for both its favicon and its × shows only its favicon, and once selected, its × in the favicon's place. Nothing appears or moves on hover. Middle-click anywhere on a tab closes it. In the collapsed sidebar rail the × stays a hover badge, so favicons aren't covered. |+| Tab close | Every tab except pinned tabs always shows its ×. A tab too narrow for both its favicon and its × shows only its favicon, and once selected, its × in the favicon's place. Nothing appears or moves on hover; the × of an inactive tab only goes from dimmed to full opacity. Middle-click anywhere on a tab closes it. In the collapsed sidebar rail the × stays a hover badge, so favicons aren't covered. || Width lock | After closing a tab by clicking, tab widths stay fixed until the pointer leaves the strip, plus 300 ms, so the next × lands under the cursor. || Dragging tabs | Starts after 4 px. The tab stays in the strip and slides along it until pulled 40 px away (up or down; sideways out of the sidebar in vertical mode), then comes loose as a window preview. Esc cancels. || Dropping | A link, URL or file dropped on the strip opens a new tab at the marker; on the bookmarks bar it becomes a bookmark; on the page, the page decides. |diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex d2f42fc34e6..c4363b7c037 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -232,9 +232,9 @@ static constexpr int TAB_TITLE_FADE_WIDTH = 24;static constexpr int SIDEBAR_ROW_AUDIO_BUTTON_SIZE = 22;static constexpr int SIDEBAR_ROW_AUDIO_ICON_SIZE = 16;static constexpr int SIDEBAR_ROW_BUTTON_GAP = 4;-// A sidebar row's close button is lighter than the muted color at rest.-static constexpr QRgb SIDEBAR_ROW_QUIET_CLOSE_ICON_LIGHT = 0x9C9CA3;-static constexpr QRgb SIDEBAR_ROW_QUIET_CLOSE_ICON_DARK = 0x7A7A81;+// The close button of a tab that is neither selected nor hovered is dimmed, so that a row of them steps back.+static constexpr qreal QUIET_TAB_CLOSE_BUTTON_OPACITY_LIGHT = 0.75;+static constexpr qreal QUIET_TAB_CLOSE_BUTTON_OPACITY_DARK = 0.55;// In the collapsed sidebar, the close button and the speaker are round badges on opposite corners of the favicon,// reaching a little past them.static constexpr int RAIL_BADGE_SIZE = 18;@@ -3107,10 +3107,12 @@ void TabBar::update_tab_button_geometry()// than fading out over the favicon.if (!show_close_button && !has_room && close_button->isVisible())close_button->hide();- if (auto* tab_bar_button = qobject_cast<TabBarButton*>(close_button))+ if (auto* tab_bar_button = qobject_cast<TabBarButton*>(close_button)) {+ tab_bar_button->set_tab_emphasized(is_selected || index == m_hovered_tab_index);tab_bar_button->set_revealed(show_close_button);- else if (close_button->isVisible() != show_close_button)+ } else if (close_button->isVisible() != show_close_button) {close_button->setVisible(show_close_button);+ }if (has_room)trailing_edge = close_button_position.x() - 2;}@@ -3148,7 +3150,7 @@ void TabBar::update_tab_button_geometry()return;prepare_button(button, TabBarButton::Placement::SidebarRow);if (auto* tab_bar_button = qobject_cast<TabBarButton*>(button))- tab_bar_button->set_row_emphasized(index == m_hovered_tab_index || index == currentIndex());+ tab_bar_button->set_tab_emphasized(index == m_hovered_tab_index || index == currentIndex());auto button_size = button->size();if (button_size.isEmpty())@@ -5624,11 +5626,11 @@ void TabBarButton::set_revealed(bool revealed)m_reveal_animation->start();}-void TabBarButton::set_row_emphasized(bool emphasized)+void TabBarButton::set_tab_emphasized(bool emphasized){- if (m_row_emphasized == emphasized)+ if (m_tab_emphasized == emphasized)return;- m_row_emphasized = emphasized;+ m_tab_emphasized = emphasized;update();}@@ -5659,20 +5661,16 @@ void TabBarButton::paintEvent(QPaintEvent*)auto icon_pixmap = icon().pixmap(iconSize(), devicePixelRatioF(), icon_mode);option.icon = {};- // A full sidebar would draw a dark stripe of close buttons down its side, so they are lighter but on the hovered and- // the selected rows, and on the button under the pointer.+ // Every tab shows its close button, so the ones on the other tabs are dimmed, but on the hovered and the selected+ // tabs, and on the button under the pointer. With increased contrast, none are.+ // NB: The icon is dimmed as a whole, rather than drawn in a lighter color, so that it steps back as far on every+ // surface it sits on.auto is_hovered = isDown() || (underMouse() && rect().contains(mapFromGlobal(QCursor::pos())));- if (m_placement == Placement::SidebarRow && m_role == Role::Close && !m_row_emphasized && !is_hovered && isEnabled() && !Theme::has_increased_contrast()) {- auto dark = Theme::is_dark(*this);- if (m_quiet_close_icon.isNull() || m_quiet_close_icon_is_dark != dark) {- m_quiet_close_icon = create_chrome_icon(ChromeIcon::TabClose, QColor::fromRgb(dark ? SIDEBAR_ROW_QUIET_CLOSE_ICON_DARK : SIDEBAR_ROW_QUIET_CLOSE_ICON_LIGHT));- m_quiet_close_icon_is_dark = dark;- }- icon_pixmap = m_quiet_close_icon.pixmap(iconSize(), devicePixelRatioF());- }+ auto is_quiet = m_placement != Placement::RailBadge && m_role == Role::Close && !m_tab_emphasized && !is_hovered && isEnabled() && !Theme::has_increased_contrast();+ auto quiet_opacity = Theme::is_dark(*this) ? QUIET_TAB_CLOSE_BUTTON_OPACITY_DARK : QUIET_TAB_CLOSE_BUTTON_OPACITY_LIGHT;QStylePainter painter(this);- painter.setOpacity(m_opacity);+ painter.setOpacity(is_quiet ? m_opacity * quiet_opacity : m_opacity);if (m_placement == Placement::RailBadge) {ChromeStyle::paint_control_frame(painter, *this, ChromeStyle::ControlFrameStyle::ActiveTabOverlay);diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.hindex 27e5ec4755c..3314c2ddb19 100644--- a/UI/Qt/TabBar.h+++ b/UI/Qt/TabBar.h@@ -533,8 +533,8 @@ public:void set_placement(Placement);// Shows the button by fading it in, or fades it out and hides it.void set_revealed(bool);- // A sidebar row's close button is quieter, but on the hovered and the selected rows.- void set_row_emphasized(bool);+ // A close button is dimmed, but on the hovered and the selected tabs.+ void set_tab_emphasized(bool);protected:virtual bool event(QEvent* event) override;@@ -546,9 +546,7 @@ private:Role m_role { Role::Close };Placement m_placement { Placement::Tab };bool m_revealed { false };- bool m_row_emphasized { false };- QIcon m_quiet_close_icon;- bool m_quiet_close_icon_is_dark { false };+ bool m_tab_emphasized { false };qreal m_opacity { 1 };QVariantAnimation* m_reveal_animation { nullptr };};