Skip to content

Truly independent web browser

LibWeb: Draw color inputs and file buttons as native buttons

Andreas Klinga5a674054e13
diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.css
index 52bd2cff634..a46b21ba8a6 100644
--- a/Libraries/LibWeb/CSS/Default.css
+++ b/Libraries/LibWeb/CSS/Default.css
@@ -59,16 +59,12 @@ textarea {
overflow-wrap: break-word;
}
-input[type=color] {
- border-color: ButtonBorder;
-}
-
input::placeholder, textarea::placeholder {
color: GrayText;
line-height: initial;
}
-button, input[type=submit], input[type=button], input[type=reset], select, ::file-selector-button {
+button, input[type=submit], input[type=button], input[type=reset], input[type=color], select, ::file-selector-button {
padding: 2px 8px;
background-color: ButtonFace;
border: 1px solid ButtonBorder;
@@ -89,6 +85,12 @@ button, input[type=submit], input[type=button], input[type=reset], select, ::fil
}
}
+input[type=color] {
+ width: 50px;
+ height: 27px;
+ padding: 1px 2px;
+}
+
input[type=image] {
cursor: pointer;
}
@@ -666,6 +668,10 @@ input, select, button, textarea {
appearance: auto;
}
+::file-selector-button {
+ appearance: auto;
+}
+
input:not([type=range i], [type=checkbox i], [type=radio i]) {
overflow: clip !important;
overflow-clip-margin: 0 !important;
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index 1105190e8a9..0b298fbb90b 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -1360,26 +1360,25 @@ void HTMLInputElement::create_color_input_shadow_tree()
auto color = value_sanitization_algorithm(m_value);
- auto border = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
- border->set_attribute_value(HTML::AttributeNames::style, R"~~~(
- width: fit-content;
- height: fit-content;
- padding: 4px;
- border: 1px solid ButtonBorder;
- background-color: ButtonFace;
+ auto swatch_wrapper = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
+ swatch_wrapper->set_attribute_value(HTML::AttributeNames::style, R"~~~(
+ display: flex;
+ width: 100%;
+ height: 100%;
+ padding: 4px 2px;
+ box-sizing: border-box;
)~~~"_utf16);
m_color_well_element = DOM::create_element(document(), HTML::TagNames::div, Namespace::HTML).release_value_but_fixme_should_propagate_errors();
m_color_well_element->set_attribute_value(HTML::AttributeNames::style, R"~~~(
- width: 32px;
- height: 16px;
- border: 1px solid ButtonBorder;
- box-sizing: border-box;
+ flex: 1;
+ min-width: 0;
+ border: 1px solid #777777;
)~~~"_utf16);
MUST(m_color_well_element->style()->set_property(CSS::PropertyID::BackgroundColor, color.utf16_view()));
- MUST(border->append_child(*m_color_well_element));
- MUST(shadow_root->append_child(border));
+ MUST(swatch_wrapper->append_child(*m_color_well_element));
+ MUST(shadow_root->append_child(swatch_wrapper));
}
void HTMLInputElement::update_color_well_element()
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/inherited-input-cascade-reuse.txt b/Tests/LibWeb/Text/expected/css/style-engine/inherited-input-cascade-reuse.txt
index 350de0e7fe6..e53937417dd 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/inherited-input-cascade-reuse.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/inherited-input-cascade-reuse.txt
@@ -1,3 +1,3 @@
color: rgb(0, 0, 255)
pseudo color: rgb(0, 0, 255)
-cascade matches: 6
+cascade matches: 7
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt
index 7237902ccaa..7a645bc42b1 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt
@@ -4,5 +4,5 @@ section.shadow-guard: .shadow-guard:has(~ .shadow-target)
section.shadow-target: .shadow-guard ~ .shadow-target .shadow-target:nth-of-type(2) .shadow-guard:has(.shadow-deep) ~ .shadow-target
cold node evaluations: 25
-candidate checks: 78
-rule matches emitted: 118
+candidate checks: 91
+rule matches emitted: 138
diff --git a/Tests/LibWeb/Text/expected/css/style-engine/pseudo-only-flip-keeps-element-winners.txt b/Tests/LibWeb/Text/expected/css/style-engine/pseudo-only-flip-keeps-element-winners.txt
index 73771fd856a..bb053aa19e8 100644
--- a/Tests/LibWeb/Text/expected/css/style-engine/pseudo-only-flip-keeps-element-winners.txt
+++ b/Tests/LibWeb/Text/expected/css/style-engine/pseudo-only-flip-keeps-element-winners.txt
@@ -1,3 +1,3 @@
-cascade matches: 180
+cascade matches: 210
::before color: rgb(0, 128, 0)
padding: 29px
diff --git a/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt b/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt
new file mode 100644
index 00000000000..84a23c2702a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/display_list/color-and-file-input-appearance.txt
@@ -0,0 +1,21 @@
+AccumulatedVisualContext Tree:
+ spatial:
+ [s0] transform=[1,0,0,1,0,0] origin=(0,0) (Viewport<#document>)
+ [s1] scroll (Viewport<#document>)
+ clips:
+ [c0 in s1] clip=[9,9 48x25] radii=(3,3,3,3) (BlockContainer<INPUT>)
+ [c1 in s1] clip=[66,15 208x20] (BlockContainer<INPUT>)
+ effects:
+ [e0 in s0] effects=[]
+
+DisplayList:
+FillRectWithRoundedCorners@s1/e0 rect=[8,8 50x27] color=rgb(239, 239, 239)
+FillRoundedRectRing@s1/e0 rect=[8,8 50x27] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)
+FillRect@s1/c0/e0 rect=[13,14 40x15] color=rgb(68, 136, 255)
+FillRoundedRectRing@s1/c0/e0 rect=[13,14 40x15] widths=[1,1,1,1] color=rgb(119, 119, 119)
+DrawGlyphRun@s1/e0 rect=[58,16 8x16] translation=[58,28.796875] color=rgb(0, 0, 0)
+FillRectWithRoundedCorners@s1/c1/e0 rect=[66,15 97x20] color=rgb(239, 239, 239)
+FillRoundedRectRing@s1/c1/e0 rect=[66,15 97x20] corner_radii=[4x4,4x4,4x4,4x4] widths=[1,1,1,1] color=rgb(118, 118, 118)
+DrawGlyphRun@s1/c1/e0 rect=[75,18 79x14] translation=[75,28.984375] color=rgb(0, 0, 0)
+DrawGlyphRun@s1/c1/e0 rect=[166,18 107x14] translation=[166.65625,28.984375] color=rgb(0, 0, 0)
+
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-color/system-color-consistency.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-color/system-color-consistency.txt
index be8ed55afa0..3840da57919 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-color/system-color-consistency.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-color/system-color-consistency.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 62 tests
-60 Pass
-2 Fail
+62 Pass
Pass Property color value 'ButtonBorder' resolves to the same color as the border-color of a button (light)
Pass Property color value 'ButtonFace' resolves to the same color as the background-color of a button (light)
Pass Property color value 'ButtonText' resolves to the same color as text on a button (light)
@@ -14,7 +13,7 @@ Pass Property color value 'ButtonBorder' resolves to the same color as the borde
Pass Property color value 'ButtonFace' resolves to the same color as the background-color of a reset button (light)
Pass Property color value 'ButtonText' resolves to the same color as text on a reset button (light)
Pass Property color value 'ButtonBorder' resolves to the same color as the border-color of a color picker (light)
-Fail Property color value 'ButtonFace' resolves to the same color as the background-color of a color picker (light)
+Pass Property color value 'ButtonFace' resolves to the same color as the background-color of a color picker (light)
Pass Property color value 'ButtonText' resolves to the same color as text on a color picker (light)
Pass Property color value 'CanvasText' has the same color as the color of the html element (light)
Pass Property color value 'Field' resolves to the same color as the background-color of a text field (light)
@@ -45,7 +44,7 @@ Pass Property color value 'ButtonBorder' resolves to the same color as the borde
Pass Property color value 'ButtonFace' resolves to the same color as the background-color of a reset button (dark)
Pass Property color value 'ButtonText' resolves to the same color as text on a reset button (dark)
Pass Property color value 'ButtonBorder' resolves to the same color as the border-color of a color picker (dark)
-Fail Property color value 'ButtonFace' resolves to the same color as the background-color of a color picker (dark)
+Pass Property color value 'ButtonFace' resolves to the same color as the background-color of a color picker (dark)
Pass Property color value 'ButtonText' resolves to the same color as text on a color picker (dark)
Pass Property color value 'CanvasText' has the same color as the color of the html element (dark)
Pass Property color value 'Field' resolves to the same color as the background-color of a text field (dark)
diff --git a/Tests/LibWeb/Text/input/display_list/color-and-file-input-appearance.html b/Tests/LibWeb/Text/input/display_list/color-and-file-input-appearance.html
new file mode 100644
index 00000000000..2f4d28c36ec
--- /dev/null
+++ b/Tests/LibWeb/Text/input/display_list/color-and-file-input-appearance.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<input type="color" value="#4488ff">
+<input type="file">
+<script>
+ test(() => {
+ println(internals.dumpDisplayList());
+ });
+</script>