script/dom/execcommand/commands/
italic.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 js::context::JSContext;
6
7use crate::dom::document::Document;
8use crate::dom::execcommand::basecommand::CommandName;
9use crate::dom::execcommand::execcommands::DocumentExecCommandSupport;
10use crate::dom::selection::Selection;
11
12/// <https://w3c.github.io/editing/docs/execCommand/#the-italic-command>
13pub(crate) fn execute_italic_command(
14    cx: &mut JSContext,
15    document: &Document,
16    selection: &Selection,
17) -> bool {
18    // > If queryCommandState("italic") returns true, set the selection's value to "normal".
19    // > Otherwise set the selection's value to "italic". Either way, return true.
20    let value = if document.command_state_for_command(cx, "italic".into()) {
21        Some("normal".into())
22    } else {
23        Some("italic".into())
24    };
25    selection.set_the_selection_value(cx, value, CommandName::Italic, document);
26
27    true
28}