Loading editor/libeditor/HTMLEditor.cpp +14 −17 Original line number Diff line number Diff line Loading @@ -2352,17 +2352,15 @@ nsresult HTMLEditor::GetHTMLBackgroundColorState(bool* aMixed, *aMixed = false; aOutColor.Truncate(); ErrorResult error; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error); if (error.Failed()) { NS_WARNING( "HTMLEditor::GetSelectedOrParentTableElement() returned nullptr"); return error.StealNSResult(); Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() returned error"); return cellOrRowOrTableElementOrError.unwrapErr(); } for (RefPtr<Element> element = std::move(cellOrRowOrTableElement); element; element = element->GetParentElement()) { for (RefPtr<Element> element = cellOrRowOrTableElementOrError.unwrap(); element; element = element->GetParentElement()) { // We are in a cell or selected table element->GetAttr(kNameSpaceID_None, nsGkAtoms::bgcolor, aOutColor); Loading Loading @@ -3297,19 +3295,18 @@ nsresult HTMLEditor::SetHTMLBackgroundColorWithTransaction( MOZ_ASSERT(IsEditActionDataAvailable()); // Find a selected or enclosing table element to set background on ErrorResult error; bool isCellSelected = false; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error, &isCellSelected); if (error.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(&isCellSelected); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return error.StealNSResult(); return cellOrRowOrTableElementOrError.unwrapErr(); } bool setColor = !aColor.IsEmpty(); RefPtr<Element> rootElementOfBackgroundColor; if (cellOrRowOrTableElement) { rootElementOfBackgroundColor = std::move(cellOrRowOrTableElement); RefPtr<Element> rootElementOfBackgroundColor = cellOrRowOrTableElementOrError.unwrap(); if (rootElementOfBackgroundColor) { // Needs to set or remove background color of each selected cell elements. // Therefore, just the cell contains selection range, we don't need to // do this. Note that users can select each cell, but with Selection API, Loading editor/libeditor/HTMLEditor.h +2 −2 Original line number Diff line number Diff line Loading @@ -3243,8 +3243,8 @@ class HTMLEditor final : public EditorBase, * In #1 and #4, *aIsCellSelected will be set to true (i.e,, when * a selection range selects a cell element). */ already_AddRefed<Element> GetSelectedOrParentTableElement( ErrorResult& aRv, bool* aIsCellSelected = nullptr) const; Result<RefPtr<Element>, nsresult> GetSelectedOrParentTableElement( bool* aIsCellSelected = nullptr) const; /** * PasteInternal() pasts text with replacing selected content. Loading editor/libeditor/HTMLTableEditor.cpp +30 −35 Original line number Diff line number Diff line Loading @@ -3867,30 +3867,28 @@ nsresult HTMLEditor::GetCellContext(Element** aTable, Element** aCell, // or get the enclosing by a cell if (!cell) { // Find a selected or enclosing table element ErrorResult error; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error); if (error.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return error.StealNSResult(); return cellOrRowOrTableElementOrError.unwrapErr(); } if (!cellOrRowOrTableElement) { if (!cellOrRowOrTableElementOrError.inspect()) { return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::table)) { if (HTMLEditUtils::IsTable(cellOrRowOrTableElementOrError.inspect())) { // We have a selected table, not a cell if (aTable) { cellOrRowOrTableElement.forget(aTable); cellOrRowOrTableElementOrError.unwrap().forget(aTable); } return NS_OK; } if (!cellOrRowOrTableElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th)) { if (!HTMLEditUtils::IsTableCell(cellOrRowOrTableElementOrError.inspect())) { return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND; } // We found a cell cell = std::move(cellOrRowOrTableElement); cell = cellOrRowOrTableElementOrError.unwrap(); } if (aCell) { // we don't want to cell.forget() here, because we use it below. Loading Loading @@ -4113,16 +4111,18 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( } bool isCellSelected = false; ErrorResult aRv; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(aRv, &isCellSelected); if (aRv.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(&isCellSelected); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return EditorBase::ToGenericNSResult(aRv.StealNSResult()); return EditorBase::ToGenericNSResult( cellOrRowOrTableElementOrError.unwrapErr()); } if (!cellOrRowOrTableElement) { if (!cellOrRowOrTableElementOrError.inspect()) { return NS_OK; } RefPtr<Element> cellOrRowOrTableElement = cellOrRowOrTableElementOrError.unwrap(); if (isCellSelected) { aTagName.AssignLiteral("td"); Loading @@ -4131,22 +4131,21 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( return NS_OK; } if (cellOrRowOrTableElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th)) { if (HTMLEditUtils::IsTableCell(cellOrRowOrTableElement)) { aTagName.AssignLiteral("td"); // Keep *aSelectedCount as 0. cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); return NS_OK; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::table)) { if (HTMLEditUtils::IsTable(cellOrRowOrTableElement)) { aTagName.AssignLiteral("table"); *aSelectedCount = 1; cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); return NS_OK; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::tr)) { if (HTMLEditUtils::IsTableRow(cellOrRowOrTableElement)) { aTagName.AssignLiteral("tr"); *aSelectedCount = 1; cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); Loading @@ -4157,19 +4156,16 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( return NS_ERROR_UNEXPECTED; } already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( ErrorResult& aRv, bool* aIsCellSelected /* = nullptr */) const { Result<RefPtr<Element>, nsresult> HTMLEditor::GetSelectedOrParentTableElement( bool* aIsCellSelected /* = nullptr */) const { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!aRv.Failed()); if (aIsCellSelected) { *aIsCellSelected = false; } if (NS_WARN_IF(!SelectionRef().RangeCount())) { aRv.Throw(NS_ERROR_FAILURE); // XXX Shouldn't throw an exception? return nullptr; return Err(NS_ERROR_FAILURE); // XXX Shouldn't throw an exception? } // Try to get the first selected cell, first. Loading @@ -4179,13 +4175,12 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( if (aIsCellSelected) { *aIsCellSelected = true; } return cellElement.forget(); return cellElement; } const RangeBoundary& anchorRef = SelectionRef().AnchorRef(); if (NS_WARN_IF(!anchorRef.IsSet())) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; return Err(NS_ERROR_FAILURE); } // If anchor selects a <td>, <table> or <tr>, return it. Loading @@ -4201,17 +4196,17 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( if (aIsCellSelected) { *aIsCellSelected = true; } return do_AddRef(selectedContent->AsElement()); return RefPtr<Element>(selectedContent->AsElement()); } if (selectedContent->IsAnyOfHTMLElements(nsGkAtoms::table, nsGkAtoms::tr)) { return do_AddRef(selectedContent->AsElement()); return RefPtr<Element>(selectedContent->AsElement()); } } } if (NS_WARN_IF(!anchorRef.Container()->IsContent())) { return nullptr; return RefPtr<Element>(); } // Then, look for a cell element (either <td> or <th>) which contains Loading @@ -4219,11 +4214,11 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( cellElement = GetInclusiveAncestorByTagNameInternal( *nsGkAtoms::td, *anchorRef.Container()->AsContent()); if (!cellElement) { return nullptr; // Not in table. return RefPtr<Element>(); // Not in table. } // Don't set *aIsCellSelected to true in this case because it does NOT // select a cell, just in a cell. return cellElement.forget(); return cellElement; } NS_IMETHODIMP HTMLEditor::GetSelectedCellsType(Element* aElement, Loading Loading
editor/libeditor/HTMLEditor.cpp +14 −17 Original line number Diff line number Diff line Loading @@ -2352,17 +2352,15 @@ nsresult HTMLEditor::GetHTMLBackgroundColorState(bool* aMixed, *aMixed = false; aOutColor.Truncate(); ErrorResult error; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error); if (error.Failed()) { NS_WARNING( "HTMLEditor::GetSelectedOrParentTableElement() returned nullptr"); return error.StealNSResult(); Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() returned error"); return cellOrRowOrTableElementOrError.unwrapErr(); } for (RefPtr<Element> element = std::move(cellOrRowOrTableElement); element; element = element->GetParentElement()) { for (RefPtr<Element> element = cellOrRowOrTableElementOrError.unwrap(); element; element = element->GetParentElement()) { // We are in a cell or selected table element->GetAttr(kNameSpaceID_None, nsGkAtoms::bgcolor, aOutColor); Loading Loading @@ -3297,19 +3295,18 @@ nsresult HTMLEditor::SetHTMLBackgroundColorWithTransaction( MOZ_ASSERT(IsEditActionDataAvailable()); // Find a selected or enclosing table element to set background on ErrorResult error; bool isCellSelected = false; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error, &isCellSelected); if (error.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(&isCellSelected); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return error.StealNSResult(); return cellOrRowOrTableElementOrError.unwrapErr(); } bool setColor = !aColor.IsEmpty(); RefPtr<Element> rootElementOfBackgroundColor; if (cellOrRowOrTableElement) { rootElementOfBackgroundColor = std::move(cellOrRowOrTableElement); RefPtr<Element> rootElementOfBackgroundColor = cellOrRowOrTableElementOrError.unwrap(); if (rootElementOfBackgroundColor) { // Needs to set or remove background color of each selected cell elements. // Therefore, just the cell contains selection range, we don't need to // do this. Note that users can select each cell, but with Selection API, Loading
editor/libeditor/HTMLEditor.h +2 −2 Original line number Diff line number Diff line Loading @@ -3243,8 +3243,8 @@ class HTMLEditor final : public EditorBase, * In #1 and #4, *aIsCellSelected will be set to true (i.e,, when * a selection range selects a cell element). */ already_AddRefed<Element> GetSelectedOrParentTableElement( ErrorResult& aRv, bool* aIsCellSelected = nullptr) const; Result<RefPtr<Element>, nsresult> GetSelectedOrParentTableElement( bool* aIsCellSelected = nullptr) const; /** * PasteInternal() pasts text with replacing selected content. Loading
editor/libeditor/HTMLTableEditor.cpp +30 −35 Original line number Diff line number Diff line Loading @@ -3867,30 +3867,28 @@ nsresult HTMLEditor::GetCellContext(Element** aTable, Element** aCell, // or get the enclosing by a cell if (!cell) { // Find a selected or enclosing table element ErrorResult error; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(error); if (error.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return error.StealNSResult(); return cellOrRowOrTableElementOrError.unwrapErr(); } if (!cellOrRowOrTableElement) { if (!cellOrRowOrTableElementOrError.inspect()) { return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::table)) { if (HTMLEditUtils::IsTable(cellOrRowOrTableElementOrError.inspect())) { // We have a selected table, not a cell if (aTable) { cellOrRowOrTableElement.forget(aTable); cellOrRowOrTableElementOrError.unwrap().forget(aTable); } return NS_OK; } if (!cellOrRowOrTableElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th)) { if (!HTMLEditUtils::IsTableCell(cellOrRowOrTableElementOrError.inspect())) { return NS_SUCCESS_EDITOR_ELEMENT_NOT_FOUND; } // We found a cell cell = std::move(cellOrRowOrTableElement); cell = cellOrRowOrTableElementOrError.unwrap(); } if (aCell) { // we don't want to cell.forget() here, because we use it below. Loading Loading @@ -4113,16 +4111,18 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( } bool isCellSelected = false; ErrorResult aRv; RefPtr<Element> cellOrRowOrTableElement = GetSelectedOrParentTableElement(aRv, &isCellSelected); if (aRv.Failed()) { Result<RefPtr<Element>, nsresult> cellOrRowOrTableElementOrError = GetSelectedOrParentTableElement(&isCellSelected); if (cellOrRowOrTableElementOrError.isErr()) { NS_WARNING("HTMLEditor::GetSelectedOrParentTableElement() failed"); return EditorBase::ToGenericNSResult(aRv.StealNSResult()); return EditorBase::ToGenericNSResult( cellOrRowOrTableElementOrError.unwrapErr()); } if (!cellOrRowOrTableElement) { if (!cellOrRowOrTableElementOrError.inspect()) { return NS_OK; } RefPtr<Element> cellOrRowOrTableElement = cellOrRowOrTableElementOrError.unwrap(); if (isCellSelected) { aTagName.AssignLiteral("td"); Loading @@ -4131,22 +4131,21 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( return NS_OK; } if (cellOrRowOrTableElement->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th)) { if (HTMLEditUtils::IsTableCell(cellOrRowOrTableElement)) { aTagName.AssignLiteral("td"); // Keep *aSelectedCount as 0. cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); return NS_OK; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::table)) { if (HTMLEditUtils::IsTable(cellOrRowOrTableElement)) { aTagName.AssignLiteral("table"); *aSelectedCount = 1; cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); return NS_OK; } if (cellOrRowOrTableElement->IsHTMLElement(nsGkAtoms::tr)) { if (HTMLEditUtils::IsTableRow(cellOrRowOrTableElement)) { aTagName.AssignLiteral("tr"); *aSelectedCount = 1; cellOrRowOrTableElement.forget(aCellOrRowOrTableElement); Loading @@ -4157,19 +4156,16 @@ NS_IMETHODIMP HTMLEditor::GetSelectedOrParentTableElement( return NS_ERROR_UNEXPECTED; } already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( ErrorResult& aRv, bool* aIsCellSelected /* = nullptr */) const { Result<RefPtr<Element>, nsresult> HTMLEditor::GetSelectedOrParentTableElement( bool* aIsCellSelected /* = nullptr */) const { MOZ_ASSERT(IsEditActionDataAvailable()); MOZ_ASSERT(!aRv.Failed()); if (aIsCellSelected) { *aIsCellSelected = false; } if (NS_WARN_IF(!SelectionRef().RangeCount())) { aRv.Throw(NS_ERROR_FAILURE); // XXX Shouldn't throw an exception? return nullptr; return Err(NS_ERROR_FAILURE); // XXX Shouldn't throw an exception? } // Try to get the first selected cell, first. Loading @@ -4179,13 +4175,12 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( if (aIsCellSelected) { *aIsCellSelected = true; } return cellElement.forget(); return cellElement; } const RangeBoundary& anchorRef = SelectionRef().AnchorRef(); if (NS_WARN_IF(!anchorRef.IsSet())) { aRv.Throw(NS_ERROR_FAILURE); return nullptr; return Err(NS_ERROR_FAILURE); } // If anchor selects a <td>, <table> or <tr>, return it. Loading @@ -4201,17 +4196,17 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( if (aIsCellSelected) { *aIsCellSelected = true; } return do_AddRef(selectedContent->AsElement()); return RefPtr<Element>(selectedContent->AsElement()); } if (selectedContent->IsAnyOfHTMLElements(nsGkAtoms::table, nsGkAtoms::tr)) { return do_AddRef(selectedContent->AsElement()); return RefPtr<Element>(selectedContent->AsElement()); } } } if (NS_WARN_IF(!anchorRef.Container()->IsContent())) { return nullptr; return RefPtr<Element>(); } // Then, look for a cell element (either <td> or <th>) which contains Loading @@ -4219,11 +4214,11 @@ already_AddRefed<Element> HTMLEditor::GetSelectedOrParentTableElement( cellElement = GetInclusiveAncestorByTagNameInternal( *nsGkAtoms::td, *anchorRef.Container()->AsContent()); if (!cellElement) { return nullptr; // Not in table. return RefPtr<Element>(); // Not in table. } // Don't set *aIsCellSelected to true in this case because it does NOT // select a cell, just in a cell. return cellElement.forget(); return cellElement; } NS_IMETHODIMP HTMLEditor::GetSelectedCellsType(Element* aElement, Loading