part 1: Make `HTMLEditor::SetInlinePropertiesAsSubAction` extend and/or shrink range smarter

Blink's behavior is better than Gecko.  That is, when selected range crosses
an inline element boundary, Blink shrinks selected range to select only
children, but Gecko extends selected range to cover all inline parents around
the range.  E.g., when setting `abc[<i>def]</i>ghi` to `<b>`, Chrome changes it
to `abc<i><b>def</b></i>ghi`, but Gecko changes it to `abc<b><i>def</i></b>ghi`.
The Gecko's behavior is odd especially when `abc<i>[def]</i>ghi` since user
does not select the `<i>`, but Gecko wraps it in new `<b>`.

However, if the range contains an inline element entirely, e.g.,
`abc[<i>def</i>]ghi`, Chrome changes it to `abc<b><i>def</i></b>ghi` without
shrinking the range.  This is reasonable too.

On the other hand, there is a case that browsers need to extend the range.
That is an parent inline element has the style of what we're setting a range to.
E.g., `abc<span style="background-color: red"><b>[def]</b></span>ghi`, user
wants to update the style attribute of the `<span>` element rather than wrapping
the selected text node with new `<span>` element in the `<b>`.  Therefore,
if shrunken range starts from very beginning of a node or ends at very end of
a node and the inline parents have same style, we need extend the range to wrap
it.  (Note that Gecko deletes same styles in range with
`HTMLEditor::RemoveStyleInside`.  Therefore, wrapping most distant inline
element makes Gecko works as expected.)

Finally, if the containers of range boundaries are not same one, we should
extend the range to save the number of creating element.  E.g.,
`<span>[abc</span> <span>def]</span>` should become
`<b><span>abc</span> <span>def</span>` rather than
`<span><b>abc</b></span><b> </b><span><b>def</b></span>`.

Note that the new expected failures are caused by the difference of selection
range after applying the style.  That should be fixed by the following patch.

Depends on D164521

Differential Revision: https://phabricator.services.mozilla.com/D164522

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1792386
gecko-commit: bde5b32f67622bbe8c6e2e1425a0af432ac77d28
gecko-reviewers: m_kato
diff --git a/editing/data/bold.js b/editing/data/bold.js
index 0d7587d..4e2882c 100644
--- a/editing/data/bold.js
+++ b/editing/data/bold.js
@@ -1038,4 +1038,38 @@
     "abcd<span contenteditable=\"false\"><span contenteditable=\"\">e</span></span>fghi",
     [true,true],
     {}],
+
+// Check where the new style (<b>) will be applied.  Basically, it should be
+// applied to minimized range as far as possible, but should not shrink the
+// range into the nodes entirely selected.
+["abc<i>[def]</i>ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<i><b>def</b></i>ghi",
+    [true,true],
+    {}],
+["abc[<i>def</i>]ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<b><i>def</i></b>ghi",
+    [true,true],
+    {}],
+["abc<i>{def}</i>ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<i><b>def</b></i>ghi",
+    [true,true],
+    {}],
+["abc{<i>def</i>}ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<b><i>def</i></b>ghi",
+    [true,true],
+    {}],
+["abc<i>[def</i>]ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<i><b>def</b></i>ghi",
+    [true,true],
+    {}],
+["abc[<i>def]</i>ghi",
+    [["stylewithcss","false"],["bold",""]],
+    "abc<i><b>def</b></i>ghi",
+    [true,true],
+    {}],
 ]
diff --git a/editing/data/strikethrough.js b/editing/data/strikethrough.js
index 86d2668..db26555 100644
--- a/editing/data/strikethrough.js
+++ b/editing/data/strikethrough.js
@@ -181,7 +181,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"strikethrough":[false,false,"",false,true,""]}],
 ["foo<u>[bar]</u>baz",
     [["stylewithcss","false"],["strikethrough",""]],
-    "foo<strike><u>[bar]</u></strike>baz",
+    "foo<u><strike>[bar]</strike></u>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"strikethrough":[false,false,"",false,true,""]}],
 // The <span> which is a  container of the range has text-decoration style.
@@ -388,7 +388,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"strikethrough":[false,false,"",false,true,""]}],
 ["foo<ins>[bar]</ins>baz",
     [["stylewithcss","false"],["strikethrough",""]],
-    "foo<strike><ins>[bar]</ins></strike>baz",
+    "foo<ins><strike>[bar]</strike></ins>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"strikethrough":[false,false,"",false,true,""]}],
 ["<ins>foo[bar]baz</ins>",
@@ -598,7 +598,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"strikethrough":[false,false,"",false,true,""]}],
 ["foo<span class=\"underline\">[bar]</span>baz",
     [["stylewithcss","false"],["strikethrough",""]],
-    "foo<strike><span class=\"underline\">[bar]</span></strike>baz",
+    "foo<span class=\"underline\"><strike>[bar]</strike></span>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"strikethrough":[false,false,"",false,true,""]}],
 ["foo<span class=\"underline\">b[a]r</span>baz",
diff --git a/editing/data/underline.js b/editing/data/underline.js
index 812798a..64fe0ac 100644
--- a/editing/data/underline.js
+++ b/editing/data/underline.js
@@ -245,7 +245,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"underline":[false,false,"",false,true,""]}],
 ["foo<s>[bar]</s>baz",
     [["stylewithcss","false"],["underline",""]],
-    "foo<u><s>[bar]</s></u>baz",
+    "foo<s><u>[bar]</u></s>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"underline":[false,false,"",false,true,""]}],
 // Should update text-decoration declaration in the <span> which is a container
@@ -330,7 +330,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"underline":[false,false,"",false,true,""]}],
 ["foo<strike>[bar]</strike>baz",
     [["stylewithcss","false"],["underline",""]],
-    "foo<u><strike>[bar]</strike></u>baz",
+    "foo<strike><u>[bar]</u></strike>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"underline":[false,false,"",false,true,""]}],
 ["<strike>foo[bar]baz</strike>",
@@ -423,7 +423,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"underline":[false,false,"",false,true,""]}],
 ["foo<del>[bar]</del>baz",
     [["stylewithcss","false"],["underline",""]],
-    "foo<u><del>[bar]</del></u>baz",
+    "foo<del><u>[bar]</u></del>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"underline":[false,false,"",false,true,""]}],
 ["<del>foo[bar]baz</del>",
@@ -602,7 +602,7 @@
     {"stylewithcss":[false,false,"",false,true,""],"underline":[false,false,"",false,true,""]}],
 ["foo<span class=\"line-through\">[bar]</span>baz",
     [["stylewithcss","false"],["underline",""]],
-    "foo<u><span class=\"line-through\">[bar]</span></u>baz",
+    "foo<span class=\"line-through\"><u>[bar]</u></span>baz",
     [true,true],
     {"stylewithcss":[false,true,"",false,false,""],"underline":[false,false,"",false,true,""]}],
 ["foo<span class=\"line-through\">b[a]r</span>baz",