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

Code before:
            InputType::Button |
            InputType::Checkbox |
            InputType::File |
            InputType::Hidden |
            InputType::Image |
            InputType::Radio |
            InputType::Reset |
            InputType::Submit => (),
        }
    }

    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    fn selection(&self) -> TextControlSelection<'_, Self> {
        TextControlSelection::new(self, &self.textinput)
    }

    /// <https://html.spec.whatwg.org/multipage/#update-a-color-well-control-color>
    fn update_a_color_well_control_color(&self, element_value: &mut DOMString) {
        // Step 1. Assert: element is an input element whose type attribute is in the Color state.
        debug_assert_eq!(self.input_type(), InputType::Color);

        // Step 2. Let value be the result of running these steps:
        // Step 2.1 If element's dirty value flag is true, then return the result of getting an attribute
        // by namespace and local name given null, "value", and element.
        // FIXME: If we do this then things break
        // Step 3. Return element's value.
        let value = element_value.to_owned();

        // Step 3. Let color be the result of parsing value.
        // Step 4. If color is failure, then set color to opaque black.
        // TODO: Use a dummy url here, like gecko
        // https://searchfox.org/firefox-main/rev/3eaf7e2acf8186eb7aa579561eaa1312cb89132b/servo/ports/geckolib/glue.rs#8931
        let urlextradata = self.owner_document().url().as_url().to_owned().into();
        let context = ParserContext::new(
            Origin::Author,
            &urlextradata,
            Some(CssRuleType::Style),
            ParsingMode::DEFAULT,
            QuirksMode::NoQuirks,
            Default::default(),
            None,
            None,
        );
        let input = value.str();
        let mut input = ParserInput::new(&input);
        let mut input = Parser::new(&mut input);
        let color = Color::parse_and_compute(&context, &mut input, None)
            .map(|computed_color| computed_color.resolve_to_absolute(&AbsoluteColor::BLACK))
            .unwrap_or(AbsoluteColor::BLACK);

        // Step 5. Set element's value to the result of serializing a color well control color

Review comment (suggestion):
Nit:
```suggestion
        // Step 2.2. Return element's value.
```

Code after:
            InputType::Button |
            InputType::Checkbox |
            InputType::File |
            InputType::Hidden |
            InputType::Image |
            InputType::Radio |
            InputType::Reset |
            InputType::Submit => (),
        }
    }

    #[cfg_attr(crown, expect(crown::unrooted_must_root))]
    fn selection(&self) -> TextControlSelection<'_, Self> {
        TextControlSelection::new(self, &self.textinput)
    }

    /// <https://html.spec.whatwg.org/multipage/#update-a-color-well-control-color>
    fn update_a_color_well_control_color(&self, element_value: &mut DOMString) {
        // Step 1. Assert: element is an input element whose type attribute is in the Color state.
        debug_assert_eq!(self.input_type(), InputType::Color);

        // Step 2. Let value be the result of running these steps:
        // Step 2.1 If element's dirty value flag is true, then return the result of getting an attribute
        // by namespace and local name given null, "value", and element.
        // FIXME: If we do this then things break
        // Step 2.2. Return element's value.
        let value = element_value.to_owned();

        // Step 3. Let color be the result of parsing value.
        // Step 4. If color is failure, then set color to opaque black.
        // TODO: Use a dummy url here, like gecko
        // https://searchfox.org/firefox-main/rev/3eaf7e2acf8186eb7aa579561eaa1312cb89132b/servo/ports/geckolib/glue.rs#8931
        let urlextradata = self.owner_document().url().as_url().to_owned().into();
        let context = ParserContext::new(
            Origin::Author,
            &urlextradata,
            Some(CssRuleType::Style),
            ParsingMode::DEFAULT,
            QuirksMode::NoQuirks,
            Default::default(),
            None,
            None,
        );
        let input = value.str();
        let mut input = ParserInput::new(&input);
        let mut input = Parser::new(&mut input);
        let color = Color::parse_and_compute(&context, &mut input, None)
            .map(|computed_color| computed_color.resolve_to_absolute(&AbsoluteColor::BLACK))
            .unwrap_or(AbsoluteColor::BLACK);

        // Step 5. Set element's value to the result of serializing a color well control color