Bug 1730429 - part 2: Delete empty inline elements which become newly empty but preserve the styles for next editing r=m_kato

This change makes deletion of all contents in inline elements compatible with
the other browsers.

Differential Revision: https://phabricator.services.mozilla.com/D125369
This commit is contained in:
Masayuki Nakano 2021-09-15 04:13:44 +00:00
Родитель 7317c9449e
Коммит c0d8a32379
8 изменённых файлов: 66 добавлений и 99 удалений

Просмотреть файл

@ -625,16 +625,49 @@ nsresult HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal() {
IsStyleCachePreservingSubAction(GetTopLevelEditSubAction());
break;
}
// If the selection is in empty inline HTML elements, we should delete
// them.
if (mPlaceholderBatch && SelectionRef().IsCollapsed() &&
SelectionRef().GetFocusNode()) {
RefPtr<Element> mostDistantEmptyInlineAncestor = nullptr;
for (Element* ancestor :
SelectionRef().GetFocusNode()->InclusiveAncestorsOfType<Element>()) {
if (!ancestor->IsHTMLElement() ||
!HTMLEditUtils::IsRemovableFromParentNode(*ancestor) ||
!HTMLEditUtils::IsEmptyInlineContent(*ancestor)) {
break;
}
mostDistantEmptyInlineAncestor = ancestor;
}
if (mostDistantEmptyInlineAncestor) {
nsresult rv =
DeleteNodeWithTransaction(*mostDistantEmptyInlineAncestor);
if (Destroyed()) {
NS_WARNING(
"HTMLEditor::DeleteNodeWithTransaction() caused destroying the "
"editor at deleting empty inline ancestors");
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_FAILED(rv)) {
NS_WARNING(
"HTMLEditor::DeleteNodeWithTransaction() failed at deleting "
"empty inline ancestors");
return rv;
}
}
}
// But the cached inline styles should be restored from type-in-state later.
if (reapplyCachedStyle) {
DebugOnly<nsresult> rvIgnored =
mTypeInState->UpdateSelState(SelectionRef());
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"TypeInState::UpdateSelState() failed, but ignored");
rv = ReapplyCachedStyles();
if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::ReapplyCachedStyles() failed");
return rv;
}
rvIgnored = ReapplyCachedStyles();
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored),
"HTMLEditor::ReapplyCachedStyles() failed, but ignored");
TopLevelEditSubActionDataRef().mCachedInlineStyles->Clear();
}
}
@ -8198,12 +8231,27 @@ nsresult HTMLEditor::GetInlineStyles(nsIContent& aContent,
bool useCSS = IsCSSEnabled();
for (nsStaticAtom* property :
{nsGkAtoms::b, nsGkAtoms::i, nsGkAtoms::u, nsGkAtoms::face,
nsGkAtoms::size, nsGkAtoms::color, nsGkAtoms::tt, nsGkAtoms::em,
nsGkAtoms::strong, nsGkAtoms::dfn, nsGkAtoms::code, nsGkAtoms::samp,
nsGkAtoms::var, nsGkAtoms::cite, nsGkAtoms::abbr, nsGkAtoms::acronym,
nsGkAtoms::backgroundColor, nsGkAtoms::sub, nsGkAtoms::sup}) {
for (nsStaticAtom* property : {nsGkAtoms::b,
nsGkAtoms::i,
nsGkAtoms::u,
nsGkAtoms::s,
nsGkAtoms::strike,
nsGkAtoms::face,
nsGkAtoms::size,
nsGkAtoms::color,
nsGkAtoms::tt,
nsGkAtoms::em,
nsGkAtoms::strong,
nsGkAtoms::dfn,
nsGkAtoms::code,
nsGkAtoms::samp,
nsGkAtoms::var,
nsGkAtoms::cite,
nsGkAtoms::abbr,
nsGkAtoms::acronym,
nsGkAtoms::backgroundColor,
nsGkAtoms::sub,
nsGkAtoms::sup}) {
nsStaticAtom *tag, *attribute;
if (property == nsGkAtoms::face || property == nsGkAtoms::size ||
property == nsGkAtoms::color) {

Просмотреть файл

@ -75,7 +75,7 @@ class StyleCache final {
};
class MOZ_STACK_CLASS AutoStyleCacheArray final
: public AutoTArray<StyleCache, 19> {
: public AutoTArray<StyleCache, 21> {
public:
index_type IndexOf(const nsStaticAtom* aTag,
const nsStaticAtom* aAttribute) const {

Просмотреть файл

@ -100,7 +100,7 @@ load 1441619.html
load 1443664.html
skip-if(Android) needs-focus load 1444630.html
load 1446451.html
pref(dom.document.exec_command.nested_calls_allowed,true) asserts(1) load 1464251.html # assertion is that mutation event listener caused by execCommand calls another execCommand
pref(dom.document.exec_command.nested_calls_allowed,true) load 1464251.html
pref(layout.accessiblecaret.enabled,true) load 1470926.html
pref(dom.document.exec_command.nested_calls_allowed,true) asserts(2) load 1474978.html # assertion is that mutation event listener caused by execCommand calls another execCommand
load 1517028.html

Просмотреть файл

@ -93,12 +93,8 @@ SimpleTest.waitForFocus(function() {
document.execCommand("strikethrough");
sendString("test");
// XXX <strike> is not handled correctly in this case.
todo_is(editor.innerHTML, "before<strike><i><b>test</b></i></strike>after",
"#02-01 At replacing \"selection\" after setting some styles, should keep the styles at inserting text");
// XXX For testing current (buggy) behavior for now.
is(editor.innerHTML, "before<i><b>test</b></i><strike><i><b></b></i></strike>after",
"#02-01 At replacing \"selection\" after setting some styles, should keep the styles");
is(editor.innerHTML, "before<strike><i><b>test</b></i></strike>after",
"#02-01 At replacing \"selection\" after setting some styles, should keep the styles at inserting text");
// #02-02 Inserting text after removing selected text after setting some styles should not keep the styles.
// XXX Chromium keeps the style.
@ -124,11 +120,7 @@ SimpleTest.waitForFocus(function() {
synthesizeKey("KEY_Enter");
sendString("test");
// XXX <strike> is not handled correctly in this case.
todo_is(editor.innerHTML, "<div>before</div><div><strike><i><b>test</b></i></strike>after</div>",
"#02-03-1 Typing Enter after setting style to selected text should keep the styles");
// XXX For testing current (buggy) behavior for now.
is(editor.innerHTML, "<div>before</div><div><i><b>test</b></i>after</div>",
is(editor.innerHTML, "<div>before</div><div><strike><i><b>test</b></i></strike>after</div>",
"#02-03-1 Typing Enter after setting style to selected text should keep the styles");
editor.innerHTML = "<p>beforeselectionafter</p>";

Просмотреть файл

@ -54,9 +54,6 @@
[[["delete",""\]\] "foo &nbsp;[\]" compare innerHTML]
expected: FAIL
[[["delete",""\]\] "foo <span>&nbsp;</span>[\] bar" compare innerHTML]
expected: FAIL
[[["delete",""\]\] "foo <span>&nbsp;</span> [\]bar" compare innerHTML]
expected: FAIL
@ -458,24 +455,6 @@
[[["stylewithcss","false"\],["defaultparagraphseparator","p"\],["delete",""\]\] "<p style=color:blue>foo<div style=color:brown><p style=color:green>[\]bar" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["delete",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["delete",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["delete",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["delete",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["delete",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["delete",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["delete",""\]\] "<p>foo</p><p>{bar</p>}<p>baz</p>" compare innerHTML]
expected: FAIL

Просмотреть файл

@ -211,42 +211,6 @@
[[["stylewithcss","true"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo<span style=color:#aBcDeF>{bar}</span>baz" queryCommandValue("defaultparagraphseparator") before]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>[foo<span style=color:#aBcDeF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>{foo<span style=color:#aBcDeF>bar}</span>baz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["stylewithcss","true"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["stylewithcss","false"\],["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<p>foo<span style=color:#aBcDeF>[bar</span><span style=color:#fEdCbA>baz\]</span>quz" compare innerHTML]
expected: FAIL
[[["insertparagraph",""\]\] "<ul contenteditable><li>{}<br></ul>" compare innerHTML]
expected: FAIL
@ -300,8 +264,8 @@
[insertparagraph.html?5001-6000]
min-asserts: 10 # Retrieving meaningless raw DOM point from WSScannerResult
max-asserts: 16 # Only on W-fis on Linux1804-64-qr and on Android, there are 2 additional assertions.
max-asserts: 16 # Retrieving meaningless raw DOM point from WSScannerResult
min-asserts: 10 # Only on W-fis on Linux1804-64-qr and on Android, there are 2 additional assertions.
[[["defaultparagraphseparator","p"\],["insertparagraph",""\]\] "<ul><li><div>foo[\]</ul>" compare innerHTML]
expected: FAIL
@ -397,4 +361,3 @@
[[["defaultparagraphseparator","div"\],["insertparagraph",""\]\] "<div>abc[\] </div>" compare innerHTML]
expected: FAIL

Просмотреть файл

@ -1023,9 +1023,6 @@
[[["backcolor","tan"\],["hilitecolor","aqua"\],["inserttext","a"\]\] "foo[\]bar" queryCommandValue("hilitecolor") after]
expected: FAIL
[[["delete",""\],["inserttext","a"\]\] "foo<s>[bar\]</s>baz" compare innerHTML]
expected: FAIL
[[["delete",""\],["inserttext","a"\]\] "foo<a href=http://www.google.com>[bar\]</a>baz" compare innerHTML]
expected: FAIL
@ -1065,12 +1062,6 @@
[[["delete",""\],["inserttext","a"\]\] "foo<font size=3><sub>[bar\]</sub></font>baz" compare innerHTML]
expected: FAIL
[[["delete",""\],["inserttext","a"\]\] "[foo<span style=background-color:#00FFFF>bar\]</span>baz" compare innerHTML]
expected: FAIL
[[["delete",""\],["inserttext","a"\]\] "foo<s>[bar</s>baz\]" compare innerHTML]
expected: FAIL
[[["delete",""\],["inserttext","a"\]\] "foo<a href=http://www.google.com>[bar</a>baz\]" compare innerHTML]
expected: FAIL

Просмотреть файл

@ -27,15 +27,9 @@
[Backspace at "<p> a[\]bc</p>"]
expected: FAIL
[Backspace at "<p>a<span>b[\]</span>c</p>" - comparing innerHTML]
expected: FAIL
[Backspace at "<p>a<span>b[\]</span>c</p>"]
expected: FAIL
[Backspace at "<p>a<span>b</span>[\]c</p>" - comparing innerHTML]
expected: FAIL
[Backspace at "<p>a<span>b</span>[\]c</p>"]
expected: FAIL