Skip to content

Truly independent web browser

UI/Qt: Shrink a loading tab's ring to 20 px

Andreas Kling17652400e9ff
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.md
index 0dad3831a96..1dd9f30202d 100644
--- a/Documentation/UI/QuietDesign.md
+++ b/Documentation/UI/QuietDesign.md
@@ -430,7 +430,7 @@ Don't invent new shadows. Pick a level.
| Hover | The active tab's shape in `hover` fill, no feet; the × fades into its slot |
| Active | Joins the toolbar; title in full `text` color, weight 400 |
| Dragging | Stays in the strip with a Lift shadow, flat (no tilt), slides sideways only |
-| Loading | Accent ring (24 px) around the favicon. The favicon shrinks to 10 px inside the ring so square icons never touch it. |
+| Loading | Accent ring (20 px, 1.5 px line) around the favicon, reaching only 2 px past the favicon slot so the title keeps about 6 px of room and nothing moves. The favicon shrinks to 10 px inside the ring so square icons never touch it. |
| Playing audio / muted | 20 px speaker button left of the close slot; click to mute. Muted keeps the struck speaker. In sidebar rows (13 px titles) the speaker is a 16 px glyph in a 22 px button, in the `icon` color, so it matches the × in weight. In the collapsed sidebar rail, the speaker is an 18 px round badge with a 13 px glyph, overlapping the favicon's bottom-right corner by about 7 px, on an opaque toolbar-colored backing with a hairline ring; it is clickable. |
| Needs attention | A 7 px accent dot on the favicon's corner; clears on visit |
| Pinned | Favicon only, 44 px wide |
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index ee8fa4480ae..a58fd91d8b4 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -2079,24 +2079,33 @@ void paint_control_frame(QPainter& painter, QAbstractButton const& button, Contr
// A ring around a favicon, with an arc in the accent color going around it, to show that the page is loading. Every
// ring follows the same clock, so the rings on screen turn in step.
-static constexpr qreal LOADING_RING_RADIUS = 10.75;
+// NB: The radii are to the middle of the 1.5 px line, so the ring's outer edge is 0.75 px further out.
+static constexpr qreal LOADING_RING_LINE_WIDTH = 1.5;
+static constexpr qreal FAVICON_LOADING_RING_RADIUS = 9.25;
+static constexpr qreal TOOLBAR_BUTTON_LOADING_RING_RADIUS = 10.75;
+
+static QRectF loading_ring_rect(QPointF center, LoadingRingSize size)
+{
+ auto radius = size == LoadingRingSize::Favicon ? FAVICON_LOADING_RING_RADIUS : TOOLBAR_BUTTON_LOADING_RING_RADIUS;
+ return { center.x() - radius, center.y() - radius, 2 * radius, 2 * radius };
+}
void paint_progress_ring(QPainter& painter, QPalette const& palette, QPointF center, double progress)
{
- QRectF ring_rect { center.x() - LOADING_RING_RADIUS, center.y() - LOADING_RING_RADIUS, 2 * LOADING_RING_RADIUS, 2 * LOADING_RING_RADIUS };
+ auto ring_rect = loading_ring_rect(center, LoadingRingSize::ToolbarButton);
painter.save();
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setBrush(Qt::NoBrush);
- painter.setPen(QPen(Theme::chrome(palette).separator, 1.5));
+ painter.setPen(QPen(Theme::chrome(palette).separator, LOADING_RING_LINE_WIDTH));
painter.drawEllipse(ring_rect);
// NB: Qt's angles are in sixteenths of a degree, counterclockwise from three o'clock.
- painter.setPen(QPen(Theme::accent(), 1.5, Qt::SolidLine, Qt::RoundCap));
+ painter.setPen(QPen(Theme::accent(), LOADING_RING_LINE_WIDTH, Qt::SolidLine, Qt::RoundCap));
painter.drawArc(ring_rect, 90 * 16, -qRound(clamp(progress, 0.0, 1.0) * 360 * 16));
painter.restore();
}
-void paint_loading_ring(QPainter& painter, QPalette const& palette, QPointF center, LoadingPhase loading_phase)
+void paint_loading_ring(QPainter& painter, QPalette const& palette, QPointF center, LoadingRingSize size, LoadingPhase loading_phase)
{
static QElapsedTimer clock;
if (!clock.isValid())
@@ -2104,7 +2113,7 @@ void paint_loading_ring(QPainter& painter, QPalette const& palette, QPointF cent
auto period = loading_phase == LoadingPhase::WaitingForResponse ? LOADING_RING_WAITING_PERIOD_MS : LOADING_RING_PERIOD_MS;
auto phase = static_cast<qreal>(clock.elapsed() % period) / period;
- QRectF ring_rect { center.x() - LOADING_RING_RADIUS, center.y() - LOADING_RING_RADIUS, 2 * LOADING_RING_RADIUS, 2 * LOADING_RING_RADIUS };
+ auto ring_rect = loading_ring_rect(center, size);
painter.save();
painter.setRenderHint(QPainter::Antialiasing, true);
@@ -2112,7 +2121,7 @@ void paint_loading_ring(QPainter& painter, QPalette const& palette, QPointF cent
if (loading_phase == LoadingPhase::WaitingForResponse && !SystemAppearance::prefers_reduced_motion())
painter.setOpacity(painter.opacity() * 0.5);
painter.setBrush(Qt::NoBrush);
- painter.setPen(QPen(Theme::chrome(palette).separator, 1.5));
+ painter.setPen(QPen(Theme::chrome(palette).separator, LOADING_RING_LINE_WIDTH));
painter.drawEllipse(ring_rect);
// NB: Qt's angles are in sixteenths of a degree, counterclockwise from three o'clock. The arc is a quarter of the ring
@@ -2121,7 +2130,7 @@ void paint_loading_ring(QPainter& painter, QPalette const& palette, QPointF cent
auto start_angle = reduce_motion ? 90 * 16 : qRound((90.0 - (phase * 360.0)) * 16);
if (reduce_motion)
painter.setOpacity(painter.opacity() * (0.35 + (0.65 * (0.5 + (0.5 * qCos(phase * 2 * M_PI))))));
- painter.setPen(QPen(Theme::accent(), 1.5, Qt::SolidLine, Qt::RoundCap));
+ painter.setPen(QPen(Theme::accent(), LOADING_RING_LINE_WIDTH, Qt::SolidLine, Qt::RoundCap));
painter.drawArc(ring_rect, start_angle, -90 * 16);
painter.restore();
}
diff --git a/UI/Qt/ChromeStyle.h b/UI/Qt/ChromeStyle.h
index 6ec8bcacabb..1c5bed3d6a5 100644
--- a/UI/Qt/ChromeStyle.h
+++ b/UI/Qt/ChromeStyle.h
@@ -26,6 +26,12 @@ constexpr inline int LOCATION_EDIT_CORNER_RADIUS = 7;
constexpr inline int LOADING_RING_PERIOD_MS = 900;
// Before the site responds, the ring turns more slowly, at half opacity.
constexpr inline int LOADING_RING_WAITING_PERIOD_MS = 1600;
+enum class LoadingRingSize : u8 {
+ // 20 px, reaching 2 px past a tab's favicon slot.
+ Favicon,
+ // 23 px, filling a toolbar button.
+ ToolbarButton,
+};
enum class LoadingPhase : u8 {
WaitingForResponse,
Receiving,
@@ -111,7 +117,7 @@ Optional<ControlFrameColors> control_frame_colors(QAbstractButton const&, Contro
void paint_control_frame(QPainter&, QAbstractButton const&, ControlFrameStyle = ControlFrameStyle::InteractionOnly);
void paint_focus_ring(QPainter&, QRectF const&, qreal radius);
-void paint_loading_ring(QPainter&, QPalette const&, QPointF center, LoadingPhase = LoadingPhase::Receiving);
+void paint_loading_ring(QPainter&, QPalette const&, QPointF center, LoadingRingSize, LoadingPhase = LoadingPhase::Receiving);
// The loading ring's track, with an arc for the progress made, from 0 to 1, clockwise from twelve o'clock.
void paint_progress_ring(QPainter&, QPalette const&, QPointF center, double progress);
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index a4b8413b39b..28daaa94542 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -500,7 +500,7 @@ private:
if (progress.has_value())
ChromeStyle::paint_progress_ring(painter, palette, center, *progress);
else
- ChromeStyle::paint_loading_ring(painter, palette, center);
+ ChromeStyle::paint_loading_ring(painter, palette, center, ChromeStyle::LoadingRingSize::ToolbarButton);
painter.restore();
}
if (m_needs_attention) {
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index f8c01ccfcba..b000d4dd0f9 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -1310,7 +1310,7 @@ void TabBar::paintEvent(QPaintEvent*)
if (ring_opacity > 0) {
painter.save();
painter.setOpacity(ring_opacity);
- ChromeStyle::paint_loading_ring(painter, Theme::chrome_palette(*this), QRectF(icon_rect).center(), tab_for_index && tab_for_index->is_waiting_for_response() ? ChromeStyle::LoadingPhase::WaitingForResponse : ChromeStyle::LoadingPhase::Receiving);
+ ChromeStyle::paint_loading_ring(painter, Theme::chrome_palette(*this), QRectF(icon_rect).center(), ChromeStyle::LoadingRingSize::Favicon, tab_for_index && tab_for_index->is_waiting_for_response() ? ChromeStyle::LoadingPhase::WaitingForResponse : ChromeStyle::LoadingPhase::Receiving);
painter.restore();
}
// NB: The fallback globe is drawn on a chrome icon's larger canvas, with room around it, so it is painted at