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

Code before:
        // Step 1.
        let element_not_rendered = !node.is_connected() || !element.has_css_layout_box();
        if element_not_rendered {
            return node.GetTextContent().unwrap();
        }

        window.layout_reflow(QueryMsg::ElementInnerOuterTextQuery);
        let text = window
            .layout()
            .query_element_inner_outer_text(node.to_trusted_node_address());

        DOMString::from(text)
    }

    /// <https://html.spec.whatwg.org/multipage/#set-the-inner-text-steps>
    pub(crate) fn set_inner_text(&self, input: DOMString, can_gc: CanGc) {
        // Step 1: Let fragment be the rendered text fragment for value given element's node
        // document.
        let fragment = self.rendered_text_fragment(input, can_gc);

        // Step 2: Replace all with fragment within element.
        Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>(), can_gc);
    }

    /// <https://html.spec.whatwg.org/multipage/#matches-the-environment>
    pub(crate) fn matches_media_environment(&self) -> bool {
        // A string matches the environment of the user if it is the empty string,
        // a string consisting of only ASCII whitespace, or is a media query list that
        // matches the user's environment according to the definitions given in Media Queries. [MQ]
        self.upcast::<Element>()
            .get_attribute(&ns!(), &local_name!("media"))
            .is_none_or(|media| {
                MediaList::matches_environment(&self.owner_document(), &media.value())
            })
    }
}

impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
    /// <https://html.spec.whatwg.org/multipage/#the-style-attribute>
    fn Style(&self, can_gc: CanGc) -> DomRoot<CSSStyleDeclaration> {
        self.style_decl.or_init(|| {
            let global = self.owner_window();
            CSSStyleDeclaration::new(
                &global,
                CSSStyleOwner::Element(Dom::from_ref(self.upcast())),
                None,
                CSSModificationAccess::ReadWrite,
                can_gc,
            )
        })
    }

Review comment (suggestion):
Maybe call this `media_attribute_matches_media_environment` as it isn't clear from the name what matches.

Code after:
        // Step 1.
        let element_not_rendered = !node.is_connected() || !element.has_css_layout_box();
        if element_not_rendered {
            return node.GetTextContent().unwrap();
        }

        window.layout_reflow(QueryMsg::ElementInnerOuterTextQuery);
        let text = window
            .layout()
            .query_element_inner_outer_text(node.to_trusted_node_address());

        DOMString::from(text)
    }

    /// <https://html.spec.whatwg.org/multipage/#set-the-inner-text-steps>
    pub(crate) fn set_inner_text(&self, input: DOMString, can_gc: CanGc) {
        // Step 1: Let fragment be the rendered text fragment for value given element's node
        // document.
        let fragment = self.rendered_text_fragment(input, can_gc);

        // Step 2: Replace all with fragment within element.
        Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>(), can_gc);
    }

    /// <https://html.spec.whatwg.org/multipage/#matches-the-environment>
    pub(crate) fn media_attribute_matches_media_environment(&self) -> bool {
        // A string matches the environment of the user if it is the empty string,
        // a string consisting of only ASCII whitespace, or is a media query list that
        // matches the user's environment according to the definitions given in Media Queries. [MQ]
        self.upcast::<Element>()
            .get_attribute(&ns!(), &local_name!("media"))
            .is_none_or(|media| {
                MediaList::matches_environment(&self.owner_document(), &media.value())
            })
    }
}

impl HTMLElementMethods<crate::DomTypeHolder> for HTMLElement {
    /// <https://html.spec.whatwg.org/multipage/#the-style-attribute>
    fn Style(&self, can_gc: CanGc) -> DomRoot<CSSStyleDeclaration> {
        self.style_decl.or_init(|| {
            let global = self.owner_window();
            CSSStyleDeclaration::new(
                &global,
                CSSStyleOwner::Element(Dom::from_ref(self.upcast())),
                None,
                CSSModificationAccess::ReadWrite,
                can_gc,
            )
        })
    }