Просмотр исходного кода

LibWeb: Implement document.execCommand("styleWithCSS")

Jelle Raaijmakers 7 месяцев назад
Родитель
Сommit
4b0d8cbfad

+ 7 - 0
Libraries/LibWeb/DOM/Document.h

@@ -753,6 +753,10 @@ public:
     FlyString const& default_single_line_container_name() const { return m_default_single_line_container_name; }
     FlyString const& default_single_line_container_name() const { return m_default_single_line_container_name; }
     void set_default_single_line_container_name(FlyString const& name) { m_default_single_line_container_name = name; }
     void set_default_single_line_container_name(FlyString const& name) { m_default_single_line_container_name = name; }
 
 
+    // https://w3c.github.io/editing/docs/execCommand/#css-styling-flag
+    bool css_styling_flag() const { return m_css_styling_flag; }
+    void set_css_styling_flag(bool flag) { m_css_styling_flag = flag; }
+
 protected:
 protected:
     virtual void initialize(JS::Realm&) override;
     virtual void initialize(JS::Realm&) override;
     virtual void visit_edges(Cell::Visitor&) override;
     virtual void visit_edges(Cell::Visitor&) override;
@@ -1046,6 +1050,9 @@ private:
 
 
     // https://w3c.github.io/editing/docs/execCommand/#default-single-line-container-name
     // https://w3c.github.io/editing/docs/execCommand/#default-single-line-container-name
     FlyString m_default_single_line_container_name { HTML::TagNames::div };
     FlyString m_default_single_line_container_name { HTML::TagNames::div };
+
+    // https://w3c.github.io/editing/docs/execCommand/#css-styling-flag
+    bool m_css_styling_flag { false };
 };
 };
 
 
 template<>
 template<>

+ 19 - 0
Libraries/LibWeb/Editing/Commands.cpp

@@ -19,6 +19,24 @@
 
 
 namespace Web::Editing {
 namespace Web::Editing {
 
 
+// https://w3c.github.io/editing/docs/execCommand/#the-stylewithcss-command
+bool command_style_with_css_action(DOM::Document& document, String const& value)
+{
+    // If value is an ASCII case-insensitive match for the string "false", set the CSS styling flag to false.
+    // Otherwise, set the CSS styling flag to true.
+    document.set_css_styling_flag(!value.equals_ignoring_ascii_case("false"sv));
+
+    // Either way, return true.
+    return true;
+}
+
+// https://w3c.github.io/editing/docs/execCommand/#the-stylewithcss-command
+bool command_style_with_css_state(DOM::Document const& document)
+{
+    // True if the CSS styling flag is true, otherwise false.
+    return document.css_styling_flag();
+}
+
 // https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command
 // https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command
 bool command_default_paragraph_separator_action(DOM::Document& document, String const& input_value)
 bool command_default_paragraph_separator_action(DOM::Document& document, String const& input_value)
 {
 {
@@ -369,6 +387,7 @@ bool command_delete_action(DOM::Document& document, String const&)
 static Array const commands {
 static Array const commands {
     CommandDefinition { CommandNames::delete_, command_delete_action, {}, {}, {} },
     CommandDefinition { CommandNames::delete_, command_delete_action, {}, {}, {} },
     CommandDefinition { CommandNames::defaultParagraphSeparator, command_default_paragraph_separator_action, {}, {}, command_default_paragraph_separator_value },
     CommandDefinition { CommandNames::defaultParagraphSeparator, command_default_paragraph_separator_action, {}, {}, command_default_paragraph_separator_value },
+    CommandDefinition { CommandNames::styleWithCSS, command_style_with_css_action, {}, command_style_with_css_state, {} },
 };
 };
 
 
 Optional<CommandDefinition const&> find_command_definition(FlyString const& command)
 Optional<CommandDefinition const&> find_command_definition(FlyString const& command)

+ 2 - 0
Libraries/LibWeb/Editing/Commands.h

@@ -21,6 +21,8 @@ struct CommandDefinition {
 Optional<CommandDefinition const&> find_command_definition(FlyString const&);
 Optional<CommandDefinition const&> find_command_definition(FlyString const&);
 
 
 // Command implementations
 // Command implementations
+bool command_style_with_css_action(DOM::Document&, String const&);
+bool command_style_with_css_state(DOM::Document const&);
 bool command_default_paragraph_separator_action(DOM::Document&, String const&);
 bool command_default_paragraph_separator_action(DOM::Document&, String const&);
 String command_default_paragraph_separator_value(DOM::Document const&);
 String command_default_paragraph_separator_value(DOM::Document const&);
 bool command_delete_action(DOM::Document&, String const&);
 bool command_delete_action(DOM::Document&, String const&);