Skip to content

Truly independent web browser

LibWeb: Restyle progress and meter, and animate indeterminate progress

Andreas Kling479c8b31ff84
diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.css
index 387785b6590..81c27db1ba1 100644
--- a/Libraries/LibWeb/CSS/Default.css
+++ b/Libraries/LibWeb/CSS/Default.css
@@ -141,14 +141,17 @@ input[type=range] {
/* Custom <meter> styles */
meter {
display: inline-block;
- width: 300px;
- height: 12px;
+ width: 5em;
+ height: 1em;
+ vertical-align: -0.2em;
&::slider-track {
display: block;
- height: 100%;
- background-color: hsl(0, 0%, 96%);
- border: 1px solid rgba(0, 0, 0, 0.5);
+ height: 0.5em;
+ margin-top: 0.25em;
+ border-radius: 0.25em;
+ overflow: hidden;
+ background-color: color-mix(in srgb, CanvasText 15%, transparent);
}
&::slider-fill {
@@ -157,29 +160,32 @@ meter {
}
&:optimal-value::slider-fill {
- background-color: hsl(141, 53%, 53%);
+ background-color: #107c10;
}
&:suboptimal-value::slider-fill {
- background-color: hsl(48, 100%, 67%);
+ background-color: #ffb900;
}
&:even-less-good-value::slider-fill {
- background-color: hsl(348, 100%, 61%);
+ background-color: #d83b01;
}
}
/* Custom <progress> styles */
progress {
display: inline-block;
- width: 300px;
- height: 12px;
+ width: 10em;
+ height: 1em;
+ vertical-align: -0.2em;
&::slider-track {
display: block;
- height: 100%;
- background-color: AccentColorText;
- border: 1px solid rgba(0, 0, 0, 0.5);
+ height: 0.5em;
+ margin-top: 0.25em;
+ border-radius: 0.25em;
+ overflow: hidden;
+ background-color: color-mix(in srgb, CanvasText 15%, transparent);
}
&::slider-fill {
@@ -187,6 +193,22 @@ progress {
height: 100%;
background-color: AccentColor;
}
+
+ /* NB: An indeterminate progress bar slides a fifth of the track to the far end and back. */
+ &:indeterminate::slider-fill {
+ width: 20%;
+ border-radius: inherit;
+ animation: -ua-progress-indeterminate 1.25s linear infinite alternate;
+ }
+}
+
+@keyframes -ua-progress-indeterminate {
+ from {
+ transform: translateX(0);
+ }
+ to {
+ transform: translateX(400%);
+ }
}
/* 15.3.1 Hidden elements
diff --git a/Libraries/LibWeb/HTML/HTMLProgressElement.cpp b/Libraries/LibWeb/HTML/HTMLProgressElement.cpp
index d15dcd3edab..a0a08c316fc 100644
--- a/Libraries/LibWeb/HTML/HTMLProgressElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLProgressElement.cpp
@@ -109,10 +109,17 @@ void HTMLProgressElement::create_shadow_tree_if_needed()
void HTMLProgressElement::update_progress_value_element()
{
- if (m_progress_value_element) {
- auto width = Utf16String::formatted("{}%", position() * 100);
- MUST(m_progress_value_element->style()->set_property(CSS::PropertyID::Width, width.utf16_view()));
+ if (!m_progress_value_element)
+ return;
+
+ // NB: An indeterminate progress bar takes the width of its animated fill from the UA style sheet.
+ if (!is_determinate()) {
+ (void)MUST(m_progress_value_element->style()->remove_property(CSS::PropertyID::Width));
+ return;
}
+
+ auto width = Utf16String::formatted("{}%", position() * 100);
+ MUST(m_progress_value_element->style()->set_property(CSS::PropertyID::Width, width.utf16_view()));
}
}
diff --git a/Tests/LibWeb/Layout/expected/element-use-pseudo-element.txt b/Tests/LibWeb/Layout/expected/element-use-pseudo-element.txt
index 8cbbc9cbc95..b143bb184a9 100644
--- a/Tests/LibWeb/Layout/expected/element-use-pseudo-element.txt
+++ b/Tests/LibWeb/Layout/expected/element-use-pseudo-element.txt
@@ -1,12 +1,13 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 36 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 20 0+0+8] children: inline
- frag 0 from BlockContainer start: 0, length: 0, rect: [8,12 300x12] baseline: 12
- BlockContainer <progress#a> at [8,12] inline-block [0+0+0 300 0+0+0] [0+0+0 12 0+0+0] [BFC] children: not-inline
- BlockContainer <div> at [9,13] [0+1+0 298 0+1+0] [0+1+0 12 0+1+0] children: not-inline
- BlockContainer <div> at [9,13] [0+0+0 298 0+0+0] [0+0+0 12 0+0+0] children: not-inline
+ frag 0 from BlockContainer start: 0, length: 0, rect: [8,8 200x20] baseline: 20
+ BlockContainer <progress#a> at [8,8] inline-block [0+0+0 200 0+0+0] [0+0+0 20 0+0+0] [BFC] children: not-inline
+ BlockContainer <div> at [8,13] [0+0+0 200 0+0+0] [5+0+0 10 0+0+0] [BFC] children: not-inline
+ BlockContainer <div> at [8,13] [0+0+0 40 0+0+160] [0+0+0 10 0+0+0] children: not-inline
TextNode <#text> (not painted)
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
SC for BlockContainer<HTML> [0,0 800x36] (z-index: auto)
+ SC for BlockContainer<DIV> [8,13 40x10] (z-index: auto), has_transform
diff --git a/Tests/LibWeb/Screenshot/expected-macos/color-scheme.png b/Tests/LibWeb/Screenshot/expected-macos/color-scheme.png
index 844d61344c3..727bf8ac982 100644
Binary files a/Tests/LibWeb/Screenshot/expected-macos/color-scheme.png and b/Tests/LibWeb/Screenshot/expected-macos/color-scheme.png differ
diff --git a/Tests/LibWeb/Screenshot/expected/meter.png b/Tests/LibWeb/Screenshot/expected/meter.png
index 43cb5eadb5a..e9e445f5d78 100644
Binary files a/Tests/LibWeb/Screenshot/expected/meter.png and b/Tests/LibWeb/Screenshot/expected/meter.png differ
diff --git a/Tests/LibWeb/Screenshot/input/meter.html b/Tests/LibWeb/Screenshot/input/meter.html
index 7922c5508bd..52b69ae7783 100644
--- a/Tests/LibWeb/Screenshot/input/meter.html
+++ b/Tests/LibWeb/Screenshot/input/meter.html
@@ -1,4 +1,5 @@
<!DOCTYPE html>
+<meta name="fuzzy" content="maxDifference=0-1;totalPixels=0-116" />
<style>
* {
margin: 0;
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/live-state-facts.txt b/Tests/LibWeb/Text/expected/css/style-engine/live-state-facts.txt
index 414d160fe59..85b3fcfabbc 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/live-state-facts.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/live-state-facts.txt
@@ -1,7 +1,7 @@
make checkbox indeterminate: [indeterminate-subject]
make checkbox determinate: []
-make progress determinate: [div, progress-subject]
-make progress indeterminate: []
+make progress determinate: [progress, div, progress-subject]
+make progress indeterminate: [progress]
make text input read-only: [read-only-subject, read-write-subject]
make text input read-write: []
disable text input: [text, read-only-subject, read-write-subject]