Bug 1660378 - part 2: Make `CSSEditUtils::RemoveCSSPoperty()` take `nsStyledElement&` instead of `Element&` r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 26 Aug 2020 04:48:16 +0000
changeset 546250 ee82ab27ad02e47fac66d0e558ef140f8236e226
parent 546249 7ee8df5f9eb9432e7a3db3b31d64995c30281108
child 546251 ac6b4ebdf31688981f48b201eb933a5dd3dfcfeb
push id124997
push usermasayuki@d-toybox.com
push dateWed, 26 Aug 2020 06:09:10 +0000
treeherderautoland@d1a42f86dd61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1660378
milestone82.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1660378 - part 2: Make `CSSEditUtils::RemoveCSSPoperty()` take `nsStyledElement&` instead of `Element&` r=m_kato Differential Revision: https://phabricator.services.mozilla.com/D87983
editor/libeditor/CSSEditUtils.cpp
editor/libeditor/CSSEditUtils.h
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/HTMLEditSubActionHandler.cpp
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
editor/libeditor/HTMLEditorObjectResizer.cpp
editor/libeditor/HTMLStyleEditor.cpp
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -412,36 +412,35 @@ nsresult CSSEditUtils::SetCSSPropertyPix
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "CSSEditUtils::SetCSSProperty() failed");
   return rv;
 }
 
 // The lowest level above the transaction; removes the value aValue from the
 // list of values specified for the CSS property aProperty, or totally remove
 // the declaration if this property accepts only one value
-nsresult CSSEditUtils::RemoveCSSProperty(Element& aElement, nsAtom& aProperty,
-                                         const nsAString& aValue,
-                                         bool aSuppressTxn) {
-  nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(&aElement);
-  if (NS_WARN_IF(!styledElement)) {
-    return NS_ERROR_INVALID_ARG;
-  }
+nsresult CSSEditUtils::RemoveCSSPropertyInternal(
+    nsStyledElement& aStyledElement, nsAtom& aProperty, const nsAString& aValue,
+    bool aSuppressTxn) {
   RefPtr<ChangeStyleTransaction> transaction =
-      ChangeStyleTransaction::CreateToRemove(*styledElement, aProperty, aValue);
+      ChangeStyleTransaction::CreateToRemove(aStyledElement, aProperty, aValue);
   if (aSuppressTxn) {
     nsresult rv = transaction->DoTransaction();
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                          "ChangeStyleTransaction::DoTransaction() failed");
     return rv;
   }
   if (NS_WARN_IF(!mHTMLEditor)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
   nsresult rv = htmlEditor->DoTransactionInternal(transaction);
+  if (NS_WARN_IF(htmlEditor->Destroyed())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "EditorBase::DoTransactionInternal() failed");
   return rv;
 }
 
 // static
 nsresult CSSEditUtils::GetSpecifiedProperty(nsIContent& aContent,
                                             nsAtom& aCSSProperty,
@@ -532,32 +531,36 @@ already_AddRefed<nsComputedDOMStyle> CSS
       NS_NewComputedDOMStyle(aElement, EmptyString(), document);
   return computedDOMStyle.forget();
 }
 
 // remove the CSS style "aProperty : aPropertyValue" and possibly remove the
 // whole node if it is a span and if its only attribute is _moz_dirty
 nsresult CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode, nsAtom* aProperty,
                                             const nsAString& aPropertyValue) {
-  OwningNonNull<Element> element(*aNode.AsElement());
+  nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(&aNode);
+  if (NS_WARN_IF(!styledElement)) {
+    return NS_ERROR_INVALID_ARG;
+  }
 
   // remove the property from the style attribute
-  nsresult rv = RemoveCSSProperty(element, *aProperty, aPropertyValue);
+  nsresult rv = RemoveCSSPropertyWithTransaction(*styledElement, *aProperty,
+                                                 aPropertyValue);
   if (NS_FAILED(rv)) {
-    NS_WARNING("CSSEditUtils::RemoveCSSProperty() failed");
+    NS_WARNING("CSSEditUtils::RemoveCSSPropertyWithTransaction() failed");
     return rv;
   }
 
-  if (!element->IsHTMLElement(nsGkAtoms::span) ||
-      HTMLEditor::HasAttributes(element)) {
+  if (!styledElement->IsHTMLElement(nsGkAtoms::span) ||
+      HTMLEditor::HasAttributes(styledElement)) {
     return NS_OK;
   }
 
   OwningNonNull<HTMLEditor> htmlEditor(*mHTMLEditor);
-  rv = htmlEditor->RemoveContainerWithTransaction(element);
+  rv = htmlEditor->RemoveContainerWithTransaction(*styledElement);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "HTMLEditor::RemoveContainerWithTransaction() failed");
   return rv;
 }
 
 // Answers true if the property can be removed by setting a "none" CSS value
 // on a node
 
@@ -869,23 +872,30 @@ nsresult CSSEditUtils::RemoveCSSEquivale
   // Find the CSS equivalence to the HTML style
   nsTArray<nsStaticAtom*> cssPropertyArray;
   nsTArray<nsString> cssValueArray;
   GenerateCSSDeclarationsFromHTMLStyle(*aElement, aHTMLProperty, aAttribute,
                                        aValue, cssPropertyArray, cssValueArray,
                                        true);
 
   // remove the individual CSS inline styles
-  int32_t count = cssPropertyArray.Length();
-  for (int32_t index = 0; index < count; index++) {
-    nsresult rv =
-        RemoveCSSProperty(*aElement, MOZ_KnownLive(*cssPropertyArray[index]),
-                          cssValueArray[index], aSuppressTransaction);
+  const size_t count = cssPropertyArray.Length();
+  if (!count) {
+    return NS_OK;
+  }
+  nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(aElement);
+  if (NS_WARN_IF(!styledElement)) {
+    return NS_ERROR_FAILURE;
+  }
+  for (size_t index = 0; index < count; index++) {
+    nsresult rv = RemoveCSSPropertyInternal(
+        *styledElement, MOZ_KnownLive(*cssPropertyArray[index]),
+        cssValueArray[index], aSuppressTransaction);
     if (NS_FAILED(rv)) {
-      NS_WARNING("CSSEditUtils::RemoveCSSProperty() failed");
+      NS_WARNING("CSSEditUtils::RemoveCSSPropertyWithoutTransaction() failed");
       return rv;
     }
   }
   return NS_OK;
 }
 
 // returns in aValue the list of values for the CSS equivalences to
 // the HTML style aHTMLProperty/aAttribute/aValue for the node aNode;
--- a/editor/libeditor/CSSEditUtils.h
+++ b/editor/libeditor/CSSEditUtils.h
@@ -97,20 +97,22 @@ class CSSEditUtils final {
    */
   MOZ_CAN_RUN_SCRIPT nsresult SetCSSProperty(dom::Element& aElement,
                                              nsAtom& aProperty,
                                              const nsAString& aValue,
                                              bool aSuppressTxn = false);
   MOZ_CAN_RUN_SCRIPT nsresult SetCSSPropertyPixels(dom::Element& aElement,
                                                    nsAtom& aProperty,
                                                    int32_t aIntValue);
-  MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSProperty(dom::Element& aElement,
-                                                nsAtom& aProperty,
-                                                const nsAString& aPropertyValue,
-                                                bool aSuppressTxn = false);
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSPropertyWithTransaction(
+      nsStyledElement& aStyledElement, nsAtom& aProperty,
+      const nsAString& aPropertyValue) {
+    return RemoveCSSPropertyInternal(aStyledElement, aProperty, aPropertyValue,
+                                     false);
+  }
 
   /**
    * Gets the specified/computed style value of a CSS property for a given
    * node (or its element ancestor if it is not an element).
    *
    * @param aContent       [IN] A DOM node.
    * @param aProperty      [IN] An atom containing the CSS property to get.
    * @param aPropertyValue [OUT] The retrieved value of the property.
@@ -264,17 +266,17 @@ class CSSEditUtils final {
    * @param aElement       [IN] A DOM Element (must not be null).
    * @param aHTMLProperty  [IN] An atom containing an HTML property.
    * @param aAttribute     [IN] An atom to an attribute name or nullptr if
    *                            irrelevant.
    * @param aValue         [IN] The attribute value.
    * @param aSuppressTransaction [IN] A boolean indicating, when true,
    *                                  that no transaction should be recorded.
    */
-  MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSEquivalentToHTMLStyle(
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSEquivalentToHTMLStyle(
       dom::Element* aElement, nsAtom* aHTMLProperty, nsAtom* aAttribute,
       const nsAString* aValue, bool aSuppressTransaction);
 
   /**
    * Parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char.
    *
    * @param aString        [IN] Input string to parse.
    * @param aValue         [OUT] Numeric part.
@@ -399,16 +401,20 @@ class CSSEditUtils final {
                                                StyleType aStyleType);
   MOZ_CAN_RUN_SCRIPT static bool IsCSSEquivalentToHTMLInlineStyleSetInternal(
       nsIContent& aContent, nsAtom* aHTMLProperty, nsAtom* aAttribute,
       nsAString& aValue, StyleType aStyleType);
   MOZ_CAN_RUN_SCRIPT static bool HaveCSSEquivalentStylesInternal(
       nsIContent& aContent, nsAtom* aHTMLProperty, nsAtom* aAttribute,
       StyleType aStyleType);
 
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult RemoveCSSPropertyInternal(
+      nsStyledElement& aStyledElement, nsAtom& aProperty,
+      const nsAString& aPropertyValue, bool aSuppressTxn = false);
+
  private:
   HTMLEditor* mHTMLEditor;
   bool mIsCSSPrefChecked;
 };
 
 #define NS_EDITOR_INDENT_INCREMENT_IN 0.4134f
 #define NS_EDITOR_INDENT_INCREMENT_CM 1.05f
 #define NS_EDITOR_INDENT_INCREMENT_MM 10.5f
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -28,16 +28,17 @@
 #include "nsINode.h"
 #include "nsIPrincipal.h"
 #include "nsISupportsImpl.h"
 #include "nsISupportsUtils.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
+#include "nsStyledElement.h"
 #include "nscore.h"
 #include <algorithm>
 
 namespace mozilla {
 
 using namespace dom;
 
 nsresult HTMLEditor::SetSelectionToAbsoluteOrStaticAsAction(
@@ -616,72 +617,122 @@ nsresult HTMLEditor::SetPositionToAbsolu
   RefPtr<Element> newBRElement =
       InsertBRElementWithTransaction(EditorDOMPoint(parentNode, 0));
   NS_WARNING_ASSERTION(newBRElement,
                        "HTMLEditor::InsertBRElementWithTransaction() failed");
   return newBRElement ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult HTMLEditor::SetPositionToStatic(Element& aElement) {
+  nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(&aElement);
+  if (NS_WARN_IF(!styledElement)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
   AutoPlaceholderBatch treatAsOneTransaction(*this,
                                              ScrollSelectionIntoView::Yes);
 
-  DebugOnly<nsresult> rvIgnored = NS_OK;
-  rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::position,
-                                               EmptyString());
-  NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                       "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::position) "
-                       "failed, but ignored");
-  rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::top,
-                                               EmptyString());
-  NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                       "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::top) "
-                       "failed, but ignored");
-  rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::left,
-                                               EmptyString());
-  NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                       "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::left) "
-                       "failed, but ignored");
-  rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::z_index,
-                                               EmptyString());
-  NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                       "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::z_index) "
-                       "failed, but ignored");
+  nsresult rv;
+  rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+      *styledElement, *nsGkAtoms::position, EmptyString());
+  if (rv == NS_ERROR_EDITOR_DESTROYED) {
+    NS_WARNING(
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::position) "
+        "destroyed the editor");
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::position) "
+      "failed, but ignored");
+  rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+      *styledElement, *nsGkAtoms::top, EmptyString());
+  if (rv == NS_ERROR_EDITOR_DESTROYED) {
+    NS_WARNING(
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::top) "
+        "destroyed the editor");
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::top) "
+      "failed, but ignored");
+  rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+      *styledElement, *nsGkAtoms::left, EmptyString());
+  if (rv == NS_ERROR_EDITOR_DESTROYED) {
+    NS_WARNING(
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::left) "
+        "destroyed the editor");
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::left) "
+      "failed, but ignored");
+  rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+      *styledElement, *nsGkAtoms::z_index, EmptyString());
+  if (rv == NS_ERROR_EDITOR_DESTROYED) {
+    NS_WARNING(
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::z_index) "
+        "destroyed the editor");
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
+  NS_WARNING_ASSERTION(
+      NS_SUCCEEDED(rv),
+      "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::z_index) "
+      "failed, but ignored");
 
-  if (!HTMLEditUtils::IsImage(&aElement)) {
-    rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::width,
-                                                 EmptyString());
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                         "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::width) "
-                         "failed, but ignored");
-    rvIgnored = mCSSEditUtils->RemoveCSSProperty(aElement, *nsGkAtoms::height,
-                                                 EmptyString());
-    NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                         "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::height) "
-                         "failed, but ignored");
+  if (!HTMLEditUtils::IsImage(styledElement)) {
+    rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+        *styledElement, *nsGkAtoms::width, EmptyString());
+    if (rv == NS_ERROR_EDITOR_DESTROYED) {
+      NS_WARNING(
+          "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::width) "
+          "destroyed the editor");
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
+    NS_WARNING_ASSERTION(
+        NS_SUCCEEDED(rv),
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::width) "
+        "failed, but ignored");
+    rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+        *styledElement, *nsGkAtoms::height, EmptyString());
+    if (rv == NS_ERROR_EDITOR_DESTROYED) {
+      NS_WARNING(
+          "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::height) "
+          "destroyed the editor");
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
+    NS_WARNING_ASSERTION(
+        NS_SUCCEEDED(rv),
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::height) "
+        "failed, but ignored");
   }
 
-  if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
-      HTMLEditor::HasStyleOrIdOrClassAttribute(aElement)) {
+  if (!styledElement->IsHTMLElement(nsGkAtoms::div) ||
+      HTMLEditor::HasStyleOrIdOrClassAttribute(*styledElement)) {
     return NS_OK;
   }
 
   // Make sure the first fild and last child of aElement starts/ends hard
   // line(s) even after removing `aElement`.
-  nsresult rv = EnsureHardLineBeginsWithFirstChildOf(aElement);
+  rv = EnsureHardLineBeginsWithFirstChildOf(*styledElement);
   if (NS_FAILED(rv)) {
     NS_WARNING("HTMLEditor::EnsureHardLineBeginsWithFirstChildOf() failed");
     return rv;
   }
-  rv = EnsureHardLineEndsWithLastChildOf(aElement);
+  rv = EnsureHardLineEndsWithLastChildOf(*styledElement);
   if (NS_FAILED(rv)) {
     NS_WARNING("HTMLEditor::EnsureHardLineEndsWithLastChildOf() failed");
     return rv;
   }
-  rv = RemoveContainerWithTransaction(aElement);
+  rv = RemoveContainerWithTransaction(*styledElement);
+  if (NS_WARN_IF(Destroyed())) {
+    return NS_ERROR_EDITOR_DESTROYED;
+  }
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "HTMLEditor::RemoveContainerWithTransaction() failed");
   return rv;
 }
 
 NS_IMETHODIMP HTMLEditor::SetSnapToGridEnabled(bool aEnabled) {
   mSnapToGridEnabled = aEnabled;
   return NS_OK;
--- a/editor/libeditor/HTMLEditSubActionHandler.cpp
+++ b/editor/libeditor/HTMLEditSubActionHandler.cpp
@@ -50,16 +50,17 @@
 #include "nsID.h"
 #include "nsIFrame.h"
 #include "nsINode.h"
 #include "nsLiteralString.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
+#include "nsStyledElement.h"
 #include "nsTArray.h"
 #include "nsTextNode.h"
 #include "nsThreadUtils.h"
 #include "nsUnicharUtils.h"
 
 // Workaround for windows headers
 #ifdef SetProp
 #  undef SetProp
@@ -12917,20 +12918,28 @@ nsresult HTMLEditor::ChangeMarginStart(E
     if (NS_WARN_IF(Destroyed())) {
       return NS_ERROR_EDITOR_DESTROYED;
     }
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
                          "CSSEditUtils::SetCSSProperty() failed, but ignored");
     return NS_OK;
   }
 
-  mCSSEditUtils->RemoveCSSProperty(aElement, MOZ_KnownLive(marginProperty),
-                                   value);
-  if (NS_WARN_IF(Destroyed())) {
-    return NS_ERROR_EDITOR_DESTROYED;
+  if (nsCOMPtr<nsStyledElement> styledElement = do_QueryInterface(&aElement)) {
+    nsresult rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+        *styledElement, MOZ_KnownLive(marginProperty), value);
+    if (rv == NS_ERROR_EDITOR_DESTROYED) {
+      NS_WARNING(
+          "CSSEditUtils::RemoveCSSPropertyWithTransaction() destroyed the "
+          "editor");
+      return NS_ERROR_EDITOR_DESTROYED;
+    }
+    NS_WARNING_ASSERTION(
+        NS_SUCCEEDED(rv),
+        "CSSEditUtils::RemoveCSSPropertyWithTransaction() failed, but ignored");
   }
 
   // Remove unnecessary divs
   if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
       HTMLEditor::HasAttributes(&aElement)) {
     return NS_OK;
   }
   // Don't touch editiong host nor node which is outside of it.
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -5174,18 +5174,27 @@ nsresult HTMLEditor::SetAttributeOrEquiv
   MOZ_ASSERT(aElement);
   MOZ_ASSERT(aAttribute);
 
   nsAutoScriptBlocker scriptBlocker;
 
   if (!IsCSSEnabled() || !mCSSEditUtils) {
     // we are not in an HTML+CSS editor; let's set the attribute the HTML way
     if (mCSSEditUtils) {
-      mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
+      nsresult rv = mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
           aElement, nullptr, aAttribute, nullptr, aSuppressTransaction);
+      if (rv == NS_ERROR_EDITOR_DESTROYED) {
+        NS_WARNING(
+            "CSSEditUtils::RemoveCSSEquivalentToHTMLStyle() destroyed the "
+            "editor");
+        return NS_ERROR_EDITOR_DESTROYED;
+      }
+      NS_WARNING_ASSERTION(
+          NS_SUCCEEDED(rv),
+          "CSSEditUtils::RemoveCSSEquivalentToHTMLStyle() failed, but ignored");
     }
     if (aSuppressTransaction) {
       nsresult rv =
           aElement->SetAttr(kNameSpaceID_None, aAttribute, aValue, true);
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Element::SetAttr() failed");
       return rv;
     }
     nsresult rv = SetAttributeWithTransaction(*aElement, *aAttribute, aValue);
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1148,17 +1148,18 @@ class HTMLEditor final : public TextEdit
    *                    Set nullptr if you want to clear all styles.
    * @param aAttribute  Attribute name if aProperty has some styles like
    *                    nsGkAtoms::font.
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT EditResult ClearStyleAt(
       const EditorDOMPoint& aPoint, nsAtom* aProperty, nsAtom* aAttribute);
 
   MOZ_CAN_RUN_SCRIPT nsresult SetPositionToAbsolute(Element& aElement);
-  MOZ_CAN_RUN_SCRIPT nsresult SetPositionToStatic(Element& aElement);
+  [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult
+  SetPositionToStatic(Element& aElement);
 
   /**
    * OnModifyDocument() is called when the editor is changed.  This should
    * be called only by runnable in HTMLEditor::OnDocumentModified() to call
    * HTMLEditor::OnModifyDocument() with AutoEditActionDataSetter instance.
    */
   [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult OnModifyDocument();
 
--- a/editor/libeditor/HTMLEditorObjectResizer.cpp
+++ b/editor/libeditor/HTMLEditorObjectResizer.cpp
@@ -26,16 +26,17 @@
 #include "nsIContent.h"
 #include "nsID.h"
 #include "mozilla/dom/Document.h"
 #include "nsISupportsUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
+#include "nsStyledElement.h"
 #include "nsTextNode.h"
 #include "nscore.h"
 #include <algorithm>
 
 #define kTopLeft u"nw"_ns
 #define kTop u"n"_ns
 #define kTopRight u"ne"_ns
 #define kLeft u"w"_ns
@@ -1262,29 +1263,46 @@ void HTMLEditor::SetFinalSize(int32_t aX
       DebugOnly<nsresult> rvIgnored =
           SetAttributeWithTransaction(*resizedObject, *nsGkAtoms::height, h);
       NS_WARNING_ASSERTION(
           NS_SUCCEEDED(rvIgnored),
           "EditorBase::SetAttributeWithTransaction(nsGkAtoms::height) "
           "failed, but ignored");
     }
 
-    if (setWidth) {
-      DebugOnly<nsresult> rvIgnored = mCSSEditUtils->RemoveCSSProperty(
-          *resizedObject, *nsGkAtoms::width, EmptyString());
-      NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                           "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::width) "
-                           "failed, but ignored");
-    }
-    if (setHeight) {
-      DebugOnly<nsresult> rvIgnored = mCSSEditUtils->RemoveCSSProperty(
-          *resizedObject, *nsGkAtoms::height, EmptyString());
-      NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
-                           "CSSEditUtils::RemoveCSSProperty(nsGkAtoms::height) "
-                           "failed, but ignored");
+    if (setWidth || setHeight) {
+      if (nsCOMPtr<nsStyledElement> resizedStyledElement =
+              do_QueryInterface(resizedObject)) {
+        if (setWidth) {
+          nsresult rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+              *resizedStyledElement, *nsGkAtoms::width, EmptyString());
+          if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
+            NS_WARNING(
+                "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::"
+                "width) destroyed the editor");
+            return;
+          }
+          NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
+                               "CSSEditUtils::RemoveCSSPropertyWithTransaction("
+                               "nsGkAtoms::width) failed, but ignored");
+        }
+        if (setHeight) {
+          nsresult rv = mCSSEditUtils->RemoveCSSPropertyWithTransaction(
+              *resizedStyledElement, *nsGkAtoms::height, EmptyString());
+          if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
+            NS_WARNING(
+                "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::"
+                "height) destroyed the editor");
+            return;
+          }
+          NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
+                               "CSSEditUtils::RemoveCSSPropertyWithTransaction("
+                               "nsGkAtoms::height) failed, but ignored");
+        }
+      }
     }
   }
 
   // keep track of that size
   mResizedObjectWidth = width;
   mResizedObjectHeight = height;
 
   DebugOnly<nsresult> rvIgnored = RefreshResizersInternal();
--- a/editor/libeditor/HTMLStyleEditor.cpp
+++ b/editor/libeditor/HTMLStyleEditor.cpp
@@ -31,16 +31,17 @@
 #include "nsINode.h"
 #include "nsIPrincipal.h"
 #include "nsISupportsImpl.h"
 #include "nsLiteralString.h"
 #include "nsRange.h"
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsStringFwd.h"
+#include "nsStyledElement.h"
 #include "nsTArray.h"
 #include "nsUnicharUtils.h"
 #include "nscore.h"
 
 class nsISupports;
 
 namespace mozilla {
 
@@ -1133,24 +1134,26 @@ nsresult HTMLEditor::RemoveStyleInside(E
 
   // Then, remove CSS style if specified.
   // XXX aElement may have already been removed from the DOM tree.  Why
   //     do we keep handling aElement here??
   if (CSSEditUtils::IsCSSEditableProperty(&aElement, aProperty, aAttribute) &&
       CSSEditUtils::HaveSpecifiedCSSEquivalentStyles(aElement, aProperty,
                                                      aAttribute)) {
     // If aElement has CSS declaration of the given style, remove it.
-    DebugOnly<nsresult> rvIgnored =
-        mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
-            &aElement, aProperty, aAttribute, nullptr, false);
-    if (NS_WARN_IF(Destroyed())) {
+    nsresult rv = mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
+        &aElement, aProperty, aAttribute, nullptr, false);
+    if (rv == NS_ERROR_EDITOR_DESTROYED) {
+      NS_WARNING(
+          "CSSEditUtils::RemoveCSSEquivalentToHTMLStyle() destroyed the "
+          "editor");
       return NS_ERROR_EDITOR_DESTROYED;
     }
     NS_WARNING_ASSERTION(
-        NS_SUCCEEDED(rvIgnored),
+        NS_SUCCEEDED(rv),
         "CSSEditUtils::RemoveCSSEquivalentToHTMLStyle() failed, but ignored");
     // Additionally, remove aElement itself if it's a `<span>` or `<font>`
     // and it does not have non-empty `style`, `id` nor `class` attribute.
     if (aElement.IsAnyOfHTMLElements(nsGkAtoms::span, nsGkAtoms::font) &&
         !HTMLEditor::HasStyleOrIdOrClassAttribute(aElement)) {
       DebugOnly<nsresult> rvIgnored = RemoveContainerWithTransaction(aElement);
       if (NS_WARN_IF(Destroyed())) {
         return NS_ERROR_EDITOR_DESTROYED;