script/dom/execcommand/commands/
stylewithcss.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::dom::bindings::str::DOMString;
6use crate::dom::document::Document;
7use crate::dom::execcommand::basecommand::BaseCommand;
8use crate::dom::selection::Selection;
9
10pub(crate) struct StyleWithCssCommand {}
11
12impl BaseCommand for StyleWithCssCommand {
13    /// <https://w3c.github.io/editing/docs/execCommand/#the-stylewithcss-command>
14    fn execute(
15        &self,
16        _cx: &mut js::context::JSContext,
17        document: &Document,
18        _selection: &Selection,
19        value: DOMString,
20    ) -> bool {
21        // > If value is an ASCII case-insensitive match for the string "false", set the CSS styling flag to false.
22        // > Otherwise, set the CSS styling flag to true. Either way, return true.
23        let value = value.to_ascii_lowercase().as_str() != "false";
24
25        document.set_css_styling_flag(value);
26
27        true
28    }
29
30    /// <https://w3c.github.io/editing/docs/execCommand/#the-stylewithcss-command>
31    fn current_state(&self, document: &Document) -> Option<bool> {
32        Some(document.css_styling_flag())
33    }
34}