Repository: servo/servo
File: components/script/dom/html/htmlinputelement.rs (Rust)

Code before:
        if !has_alpha {
            color.alpha = 1.0;
        }

        // Step 4. If element's colorspace attribute is in the Limited sRGB state:
        // NOTE: Servo doesn't support the colorspace attribute yet, so this is always true
        // Step 4.1 Set color to color converted to the 'srgb' color space.

        // NOTE: Even though we don't support other values for the colorspace attribute, the color might
        // not be in the "srgb" color space because CSS colors can specify their own colorspaces.
        // For example: "color(display-p3 1 0 0)"
        color = color.to_color_space(ColorSpace::Srgb);

        // Step 4.2 Round each of color's components so they are in the range 0 to 255,
        // inclusive. Components are to be rounded towards +∞.
        color.components.0 = color.components.0.clamp(0.0, 1.0);
        color.components.1 = color.components.1.clamp(0.0, 1.0);
        color.components.2 = color.components.2.clamp(0.0, 1.0);

        // Step 4.3 If element's alpha attribute is not specified, then set htmlCompatible to true.
        if !has_alpha {
            html_compatible = true;
        }

        // Step 5. Otherwise:
        // NOTE: This is unreachable

        // Step 6. Return the result of serializing color. If htmlCompatible is true,
        // then do so with HTML-compatible serialization requested.
        *destination = if html_compatible {
            format!(
                "#{:0>2x}{:0>2x}{:0>2x}",
                (color.components.0 * 255.0).round() as usize,
                (color.components.1 * 255.0).round() as usize,
                (color.components.2 * 255.0).round() as usize
            )
        } else {
            color.to_css_string()
        }
        .into();
    }

    // https://html.spec.whatwg.org/multipage/#implicit-submission
    fn implicit_submission(&self, can_gc: CanGc) {
        let doc = self.owner_document();
        let node = doc.upcast::<Node>();
        let owner = self.form_owner();
        let form = match owner {
            None => return,
            Some(ref f) => f,
        };

Review comment (bug):
Is this a spec bug? I do see `display-p3` in the failing WPT tests, so I think we are missing something here?

>   [Testing '#ffffff;' with color space 'display-p3' and with alpha (setAttribute("value"))]

Edit: Okay, I missed your other notes. Instead of these, please mark them as TODO and state that it should be implemented once colorspace is suppored

Code after:
        if !has_alpha {
            color.alpha = 1.0;
        }

        // Step 4. If element's colorspace attribute is in the Limited sRGB state:
        // TODO: Servo doesn't support the colorspace attribute yet, so this is always true
        // Step 4.1 Set color to color converted to the 'srgb' color space.

        // NOTE: Even though we don't support other values for the colorspace attribute, the color might
        // not be in the "srgb" color space because CSS colors can specify their own colorspaces.
        // For example: "color(display-p3 1 0 0)"
        color = color.to_color_space(ColorSpace::Srgb);

        // Step 4.2 Round each of color's components so they are in the range 0 to 255,
        // inclusive. Components are to be rounded towards +∞.
        color.components.0 = color.components.0.clamp(0.0, 1.0);
        color.components.1 = color.components.1.clamp(0.0, 1.0);
        color.components.2 = color.components.2.clamp(0.0, 1.0);

        // Step 4.3 If element's alpha attribute is not specified, then set htmlCompatible to true.
        if !has_alpha {
            html_compatible = true;
        }

        // Step 5. Otherwise:
        // TODO: This is unreachable, see the note on Step 4.

        // Step 6. Return the result of serializing color. If htmlCompatible is true,
        // then do so with HTML-compatible serialization requested.
        *destination = if html_compatible {
            format!(
                "#{:0>2x}{:0>2x}{:0>2x}",
                (color.components.0 * 255.0).round() as usize,
                (color.components.1 * 255.0).round() as usize,
                (color.components.2 * 255.0).round() as usize
            )
        } else {
            color.to_css_string()
        }
        .into();
    }

    // https://html.spec.whatwg.org/multipage/#implicit-submission
    fn implicit_submission(&self, can_gc: CanGc) {
        let doc = self.owner_document();
        let node = doc.upcast::<Node>();
        let owner = self.form_owner();
        let form = match owner {
            None => return,
            Some(ref f) => f,
        };