mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibWeb: Implement the "backColor" and "hiliteColor" editing commands
This commit is contained in:
parent
7736d63290
commit
05386fe99c
Notes:
github-actions[bot]
2025-01-10 22:37:15 +00:00
Author: https://github.com/gmta
Commit: 05386fe99c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3216
4 changed files with 59 additions and 0 deletions
|
@ -25,6 +25,28 @@
|
|||
|
||||
namespace Web::Editing {
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-backcolor-command
|
||||
bool command_back_color_action(DOM::Document& document, String const& value)
|
||||
{
|
||||
// 1. If value is not a valid CSS color, prepend "#" to it.
|
||||
auto resulting_value = value;
|
||||
if (!Color::from_string(resulting_value).has_value()) {
|
||||
resulting_value = MUST(String::formatted("#{}", resulting_value));
|
||||
|
||||
// 2. If value is still not a valid CSS color, or if it is currentColor, return false.
|
||||
if (!Color::from_string(resulting_value).has_value()) {
|
||||
// FIXME: Also return false in case of currentColor.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Set the selection's value to value.
|
||||
set_the_selections_value(document, CommandNames::backColor, resulting_value);
|
||||
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-bold-command
|
||||
bool command_bold_action(DOM::Document& document, String const&)
|
||||
{
|
||||
|
@ -1030,6 +1052,12 @@ bool command_style_with_css_state(DOM::Document const& document)
|
|||
}
|
||||
|
||||
static Array const commands {
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-backcolor-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::backColor,
|
||||
.action = command_back_color_action,
|
||||
.relevant_css_property = CSS::PropertyID::BackgroundColor,
|
||||
},
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-bold-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::bold,
|
||||
|
@ -1055,6 +1083,12 @@ static Array const commands {
|
|||
.action = command_forward_delete_action,
|
||||
.preserves_overrides = true,
|
||||
},
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-hilitecolor-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::hiliteColor,
|
||||
.action = command_back_color_action, // For historical reasons, backColor and hiliteColor behave identically.
|
||||
.relevant_css_property = CSS::PropertyID::BackgroundColor,
|
||||
},
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-insertlinebreak-command
|
||||
CommandDefinition {
|
||||
.command = CommandNames::insertLineBreak,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue