Page MenuHomePhabricator

Bug 1965029 - Accept CSS color syntax in `input type=color` r=emilio
ClosedPublic

Authored by saschanaz on Jul 25 2025, 1:57 AM.
Referenced Files
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Unknown Object (File)
Nov 13 2025, 9:08 PM
Subscribers

Details

Summary

The alpha and colorspace part of the https://html.spec.whatwg.org/#serialize-a-color-well-control-color is largely skipped in this patch, as we don't support them yet in <input type=color>, and thus the value is always in the "HTML compatible" form.

Changing the existing WPT color.tentative.html to color.html to specifically cover implementations without alpha and colorspace support, because otherwise reading the test result of color.window.js is overly confusing. (Ideally the two tests should share the same test data, but for now I'm skipping that as I'm not confident yet to fill the display-p3 fields. That can be done when we actually implement colorspace support.)

Introducing Servo_ComputeColorWellControlColor so that the colorspace conversion can happen before losing number precision, following the spec.

Event Timeline

saschanaz created this revision.
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".Jul 25 2025, 1:57 AM
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
saschanaz updated this revision to Diff 1096057.
saschanaz updated this revision to Diff 1097579.
saschanaz retitled this revision from WIP: Bug 1965029 - Accept CSS color syntax in `input type=color` to Bug 1965029 - Accept CSS color syntax in `input type=color` r=emilio.
saschanaz edited the summary of this revision. (Show Details)
saschanaz added a reviewer: emilio.
dom/html/HTMLInputElement.cpp
795

(Keeping the serialization as a separate function as ultimately I want to pass the structured object to the color picker popup)

emilio requested changes to this revision.Jul 30 2025, 10:25 AM
emilio added inline comments.
dom/html/HTMLInputElement.cpp
741

Pass the styleset instead for consistency with ComputeColor?

792

Use OwnerDoc(). Also that can't return null so...

layout/style/ServoCSSParser.h
92

This should document that invalid colors return black in the specifiied color space.

Also, document the aToColorSpace parameter?

94

Maybe just ComputeAbsoluteColor? Or link to the spec, because otherwise the name is quite bizarre.

servo/ports/geckolib/glue.rs
8451

Is it worth signaling the error somehow rather than returning black?

This revision now requires changes to proceed.Jul 30 2025, 10:25 AM

r? for questions around OwnerDoc and RawData.

dom/html/HTMLInputElement.cpp
741

It only needs RawData anyway? I'd rather change ComputeColor for consistency. Does that make sense?

792

But OwnerDoc() behaves differently with disconnected nodes, and we probably don't want that?

servo/ports/geckolib/glue.rs
8451

For now I don't see the reason why we would want the error signal. (It's not that there's an error event...)

dom/html/HTMLInputElement.cpp
792

Oh wait, it's not ComposedDoc. I'll do that.

dom/html/HTMLInputElement.cpp
741

It only needs RawData anyway? I'd rather change ComputeColor for consistency. Does that make sense?

Sure

emilio requested changes to this revision.Jul 30 2025, 11:56 AM

(Seems like a lot of comments aren't addressed)

This revision now requires changes to proceed.Jul 30 2025, 11:56 AM
saschanaz updated this revision to Diff 1098071.
dom/canvas/CanvasRenderingContext2D.cpp
1312

Should this also just do document->EnsureStyleSet()->RawData() instead of getting it from PresShell? 🤔

emilio added a project: testing-approved.

Some nits, but looks good with those.

dom/canvas/CanvasRenderingContext2D.cpp
1312

Should this also just do document->EnsureStyleSet()->RawData() instead of getting it from PresShell? 🤔

I'd prefer not to. The styleset without the presshell is not very useful fwiw.

layout/inspector/InspectorUtils.cpp
770

StyleSet is non-null, just return ps->StyleSet()->RawData();

servo/ports/geckolib/glue.rs
8411–8412

let computed = specified::Color::parse_and_compute(...)?;, now that we propagate the Option<>

8439
let Some(result) = compute_color(..) else { return false };
This revision is now accepted and ready to land.Jul 30 2025, 12:40 PM
saschanaz marked 7 inline comments as done.
This revision is now accepted and ready to land.Jul 30 2025, 6:24 PM