Backed out changeset 97a8f04641de (bug 1618906) on request by masayuki

This commit is contained in:
Coroiu Cristina 2020-03-05 06:36:44 +02:00
Родитель 7eb1434fa4
Коммит e3e3fb9577
7 изменённых файлов: 1 добавлений и 171 удалений

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

@ -5455,21 +5455,6 @@ NS_IMETHODIMP EditorBase::SetNewlineHandling(int32_t aNewlineHandling) {
}
}
bool EditorBase::IsSelectionRangeContainerNotContent() const {
MOZ_ASSERT(IsEditActionDataAvailable());
for (uint32_t i = 0; i < SelectionRefPtr()->RangeCount(); i++) {
nsRange* range = SelectionRefPtr()->GetRangeAt(i);
MOZ_ASSERT(range);
if (!range || !range->GetStartContainer() ||
!range->GetStartContainer()->IsContent() || !range->GetEndContainer() ||
!range->GetEndContainer()->IsContent()) {
return true;
}
}
return false;
}
NS_IMETHODIMP EditorBase::InsertText(const nsAString& aStringToInsert) {
nsresult rv = InsertTextAsAction(aStringToInsert);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert text");

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

@ -1341,12 +1341,6 @@ class EditorBase : public nsIEditor,
EditorRawDOMPoint GetCompositionStartPoint() const;
EditorRawDOMPoint GetCompositionEndPoint() const;
/**
* IsSelectionRangeContainerNotContent() returns true if one of container
* of selection ranges is not a content node, i.e., a Document node.
*/
bool IsSelectionRangeContainerNotContent() const;
/**
* InsertTextAsSubAction() inserts aStringToInsert at selection. This
* should be used for handling it as an edit sub-action.

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

@ -810,10 +810,6 @@ AlignStateAtSelection::AlignStateAtSelection(HTMLEditor& aHTMLEditor,
return;
}
if (aHTMLEditor.IsSelectionRangeContainerNotContent()) {
return;
}
// For now, just return first alignment. We don't check if it's mixed.
// This is for efficiency given that our current UI doesn't care if it's
// mixed.
@ -832,7 +828,6 @@ AlignStateAtSelection::AlignStateAtSelection(HTMLEditor& aHTMLEditor,
EditorRawDOMPoint atBodyOrDocumentElement(bodyOrDocumentElement);
nsRange* firstRange = aHTMLEditor.SelectionRefPtr()->GetRangeAt(0);
MOZ_ASSERT(firstRange);
if (NS_WARN_IF(!firstRange)) {
aRv.Throw(NS_ERROR_FAILURE);
return;
@ -1013,10 +1008,6 @@ ParagraphStateAtSelection::ParagraphStateAtSelection(HTMLEditor& aHTMLEditor,
return;
}
if (aHTMLEditor.IsSelectionRangeContainerNotContent()) {
return;
}
AutoTArray<OwningNonNull<nsIContent>, 64> arrayOfContents;
nsresult rv =
CollectEditableFormatNodesInSelection(aHTMLEditor, arrayOfContents);
@ -4073,10 +4064,6 @@ EditActionResult HTMLEditor::MakeOrChangeListAndListItemAsSubAction(
return result;
}
if (IsSelectionRangeContainerNotContent()) {
return EditActionIgnored();
}
AutoPlaceholderBatch treatAsOneTransaction(*this);
// XXX EditSubAction::eCreateOrChangeDefinitionListItem and
@ -4174,7 +4161,6 @@ EditActionResult HTMLEditor::ChangeSelectedHardLinesToList(
const nsAString& aBulletType,
SelectAllOfCurrentList aSelectAllOfCurrentList) {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
AutoSelectionRestorer restoreSelectionLater(*this);
@ -4865,7 +4851,6 @@ nsresult HTMLEditor::FormatBlockContainerWithTransaction(nsAtom& blockType) {
nsresult HTMLEditor::MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
if (!SelectionRefPtr()->IsCollapsed()) {
return NS_OK;
@ -4911,19 +4896,11 @@ EditActionResult HTMLEditor::IndentAsSubAction() {
return result;
}
if (IsSelectionRangeContainerNotContent()) {
return EditActionIgnored();
}
result |= HandleIndentAtSelection();
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
return result;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
@ -5022,7 +4999,6 @@ nsresult HTMLEditor::IndentListChild(RefPtr<Element>* aCurList,
EditActionResult HTMLEditor::HandleIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
@ -5050,10 +5026,6 @@ EditActionResult HTMLEditor::HandleIndentAtSelection() {
}
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if (IsCSSEnabled()) {
nsresult rv = HandleCSSIndentAtSelection();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
@ -5067,7 +5039,6 @@ EditActionResult HTMLEditor::HandleIndentAtSelection() {
nsresult HTMLEditor::HandleCSSIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
if (!SelectionRefPtr()->IsCollapsed()) {
nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
@ -5090,7 +5061,6 @@ nsresult HTMLEditor::HandleCSSIndentAtSelection() {
nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
AutoSelectionRestorer restoreSelectionLater(*this);
AutoTArray<OwningNonNull<nsIContent>, 64> arrayOfContents;
@ -5269,7 +5239,6 @@ nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() {
nsresult HTMLEditor::HandleHTMLIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
if (!SelectionRefPtr()->IsCollapsed()) {
nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
@ -5521,19 +5490,11 @@ EditActionResult HTMLEditor::OutdentAsSubAction() {
return result;
}
if (IsSelectionRangeContainerNotContent()) {
return EditActionIgnored();
}
result |= HandleOutdentAtSelection();
if (NS_WARN_IF(result.Failed()) || result.Canceled()) {
return result;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
nsresult rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
@ -5543,7 +5504,6 @@ EditActionResult HTMLEditor::OutdentAsSubAction() {
EditActionResult HTMLEditor::HandleOutdentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
if (!SelectionRefPtr()->IsCollapsed()) {
nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
@ -6228,10 +6188,6 @@ EditActionResult HTMLEditor::AlignAsSubAction(const nsAString& aAlignType) {
return result;
}
if (IsSelectionRangeContainerNotContent()) {
return EditActionIgnored();
}
nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
@ -6240,10 +6196,6 @@ EditActionResult HTMLEditor::AlignAsSubAction(const nsAString& aAlignType) {
NS_SUCCEEDED(rv),
"EnsureNoPaddingBRElementForEmptyEditor() failed, but ignored");
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
if (NS_SUCCEEDED(rv) && SelectionRefPtr()->IsCollapsed()) {
nsresult rv = EnsureCaretNotAfterPaddingBRElement();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
@ -6280,10 +6232,6 @@ EditActionResult HTMLEditor::AlignAsSubAction(const nsAString& aAlignType) {
return EditActionHandled(rv);
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv),
@ -6292,9 +6240,6 @@ EditActionResult HTMLEditor::AlignAsSubAction(const nsAString& aAlignType) {
}
nsresult HTMLEditor::AlignContentsAtSelection(const nsAString& aAlignType) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
AutoSelectionRestorer restoreSelectionLater(*this);
// Convert the selection ranges into "promoted" selection ranges: This
@ -6358,9 +6303,6 @@ nsresult HTMLEditor::AlignContentsAtSelection(const nsAString& aAlignType) {
}
if (createEmptyDivElement) {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE;
}
EditActionResult result =
AlignContentsAtSelectionWithEmptyDivElement(aAlignType);
NS_WARNING_ASSERTION(
@ -6380,7 +6322,6 @@ nsresult HTMLEditor::AlignContentsAtSelection(const nsAString& aAlignType) {
EditActionResult HTMLEditor::AlignContentsAtSelectionWithEmptyDivElement(
const nsAString& aAlignType) {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
nsRange* firstRange = SelectionRefPtr()->GetRangeAt(0);
if (NS_WARN_IF(!firstRange)) {
@ -7843,7 +7784,6 @@ nsresult HTMLEditor::MaybeSplitElementsAtEveryBRElement(
Element* HTMLEditor::GetParentListElementAtSelection() const {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
for (uint32_t i = 0; i < SelectionRefPtr()->RangeCount(); ++i) {
nsRange* range = SelectionRefPtr()->GetRangeAt(i);
@ -10678,10 +10618,6 @@ EditActionResult HTMLEditor::SetSelectionToAbsoluteAsSubAction() {
return EditActionHandled(rv);
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return EditActionHandled(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
rv = MaybeInsertPaddingBRElementForEmptyLastLineAtSelection();
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditActionHandled(rv);

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

@ -985,19 +985,13 @@ nsresult HTMLEditor::InsertLineBreakAsAction(nsIPrincipal* aPrincipal) {
return EditorBase::ToGenericNSResult(rv);
}
if (IsSelectionRangeContainerNotContent()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
// XXX This method may be called by "insertLineBreak" command. So, using
// TypingTxnName here is odd in such case.
AutoPlaceholderBatch treatAsOneTransaction(*this, *nsGkAtoms::TypingTxnName);
rv = InsertBrElementAtSelectionWithTransaction();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"InsertBrElementAtSelectionWithTransaction() failed");
// Don't return NS_SUCCESS_DOM_NO_OPERATION for compatibility of `execCommand`
// result of Chrome.
return NS_FAILED(rv) ? rv : NS_OK;
return rv;
}
nsresult HTMLEditor::InsertParagraphSeparatorAsAction(
@ -1116,7 +1110,6 @@ EditActionResult HTMLEditor::HandleTabKeyPressInTable(
nsresult HTMLEditor::InsertBrElementAtSelectionWithTransaction() {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
// calling it text insertion to trigger moz br treatment by rules
// XXX Why do we use EditSubAction::eInsertText here? Looks like
@ -1854,10 +1847,6 @@ HTMLEditor::GetParagraphState(bool* aMixed, nsAString& aFirstParagraphState) {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_FAILURE;
}
ErrorResult error;
ParagraphStateAtSelection state(*this, error);
if (NS_WARN_IF(error.Failed())) {
@ -2226,10 +2215,6 @@ nsresult HTMLEditor::FormatBlockContainerAsSubAction(nsAtom& aTagName) {
return result.Rv();
}
if (IsSelectionRangeContainerNotContent()) {
return NS_SUCCESS_DOM_NO_OPERATION;
}
nsresult rv = EnsureNoPaddingBRElementForEmptyEditor();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
@ -2336,18 +2321,12 @@ Element* HTMLEditor::GetElementOrParentByTagName(const nsAtom& aTagName,
if (aNode) {
return GetElementOrParentByTagNameInternal(aTagName, *aNode);
}
if (IsSelectionRangeContainerNotContent()) {
return nullptr;
}
return GetElementOrParentByTagNameAtSelection(aTagName);
}
Element* HTMLEditor::GetElementOrParentByTagNameAtSelection(
const nsAtom& aTagName) const {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(!IsSelectionRangeContainerNotContent());
MOZ_ASSERT(&aTagName != nsGkAtoms::_empty);

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

@ -1748,10 +1748,6 @@ HTMLEditor::SelectTable() {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_OK; // Don't fail if we didn't find a table.
}
RefPtr<Element> table =
GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (NS_WARN_IF(!table)) {
@ -1776,14 +1772,8 @@ HTMLEditor::SelectTableCell() {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
// Don't fail if we didn't find a cell.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
RefPtr<Element> cell = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::td);
if (NS_WARN_IF(!cell)) {
// Don't fail if we didn't find a cell.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
@ -1805,11 +1795,6 @@ HTMLEditor::SelectAllTableCells() {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
// Don't fail if we didn't find a cell.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
RefPtr<Element> cell = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::td);
if (NS_WARN_IF(!cell)) {
// Don't fail if we didn't find a cell.
@ -1887,11 +1872,6 @@ HTMLEditor::SelectTableRow() {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
// Don't fail if we didn't find a cell.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
RefPtr<Element> cell = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::td);
if (NS_WARN_IF(!cell)) {
// Don't fail if we didn't find a cell.
@ -1973,11 +1953,6 @@ HTMLEditor::SelectTableColumn() {
return NS_ERROR_NOT_INITIALIZED;
}
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
// Don't fail if we didn't find a cell.
return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND;
}
RefPtr<Element> cell = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::td);
if (NS_WARN_IF(!cell)) {
// Don't fail if we didn't find a cell.
@ -2985,10 +2960,6 @@ HTMLEditor::NormalizeTable(Element* aTableOrElementInTable) {
}
if (!aTableOrElementInTable) {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_OK; // Don't throw error even if the element is not in <table>.
}
aTableOrElementInTable =
GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (!aTableOrElementInTable) {
@ -3139,11 +3110,6 @@ void HTMLEditor::CellIndexes::Update(HTMLEditor& aHTMLEditor,
Selection& aSelection, ErrorResult& aRv) {
MOZ_ASSERT(!aRv.Failed());
if (NS_WARN_IF(aHTMLEditor.IsSelectionRangeContainerNotContent())) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Guarantee the life time of the cell element since Init() will access
// layout methods.
RefPtr<Element> cellElement =
@ -3233,9 +3199,6 @@ HTMLEditor::GetTableSize(Element* aTableOrElementInTable, int32_t* aRowCount,
Element* tableOrElementInTable = aTableOrElementInTable;
if (!tableOrElementInTable) {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_FAILURE;
}
tableOrElementInTable =
GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (NS_WARN_IF(!tableOrElementInTable)) {
@ -3312,9 +3275,6 @@ HTMLEditor::GetCellDataAt(Element* aTableElement, int32_t aRowIndex,
// them.
RefPtr<Element> table = aTableElement;
if (!table) {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_FAILURE;
}
// Get the selected table or the table enclosing the selection anchor.
table = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (NS_WARN_IF(!table)) {
@ -3398,9 +3358,6 @@ HTMLEditor::GetCellAt(Element* aTableElement, int32_t aRowIndex,
Element* tableElement = aTableElement;
if (!tableElement) {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_FAILURE;
}
// Get the selected table or the table enclosing the selection anchor.
tableElement = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (NS_WARN_IF(!tableElement)) {
@ -4021,9 +3978,6 @@ HTMLEditor::GetSelectedCellsType(Element* aElement, uint32_t* aSelectionType) {
return NS_ERROR_FAILURE;
}
} else {
if (NS_WARN_IF(IsSelectionRangeContainerNotContent())) {
return NS_ERROR_FAILURE;
}
table = GetElementOrParentByTagNameAtSelection(*nsGkAtoms::table);
if (NS_WARN_IF(!table)) {
return NS_ERROR_FAILURE;

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

@ -1,17 +0,0 @@
<html>
<head>
<script>
window.addEventListener('load', () => {
const range = new Range()
const fragment = range.cloneContents()
range.selectNodeContents(document)
document.designMode = 'on'
document.replaceChild(fragment, document.documentElement)
const selection = window.getSelection()
selection.addRange(range)
document.execCommand('indent', false, null)
})
</script>
</head>
</html>
<!-- COMMENT -->

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

@ -117,4 +117,3 @@ load 1547898.html
load 1556799.html
load 1574544.html
load 1596516.html
load 1618906.html