Bug 1451672 - part 12: Create HTMLEditor::RemoveStyleSheetWithTransaction() as implementation of nsIEditorStyleSheets::RemoveStyleSheet() r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 12 Apr 2018 17:20:21 +0900
changeset 468365 4b372e4cc463abb94c3fbc5ccaf2870ffceec894
parent 468364 4076543894020d6614e523e805b13b35e511cb45
child 468366 979bfcb751572486dce5e69b709f916c008425ee
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1451672
milestone61.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 1451672 - part 12: Create HTMLEditor::RemoveStyleSheetWithTransaction() as implementation of nsIEditorStyleSheets::RemoveStyleSheet() r=m_kato MozReview-Commit-ID: BIXU3jzD1rU
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2911,18 +2911,26 @@ HTMLEditor::ReplaceStyleSheet(const nsAS
 
   return ps->GetDocument()->CSSLoader()->LoadSheet(
     uaURI, false, nullptr, nullptr, this);
 }
 
 NS_IMETHODIMP
 HTMLEditor::RemoveStyleSheet(const nsAString& aURL)
 {
+  return RemoveStyleSheetWithTransaction(aURL);
+}
+
+nsresult
+HTMLEditor::RemoveStyleSheetWithTransaction(const nsAString& aURL)
+{
   RefPtr<StyleSheet> sheet = GetStyleSheetForURL(aURL);
-  NS_ENSURE_TRUE(sheet, NS_ERROR_UNEXPECTED);
+  if (NS_WARN_IF(!sheet)) {
+    return NS_ERROR_UNEXPECTED;
+  }
 
   RefPtr<RemoveStyleSheetTransaction> transaction =
     RemoveStyleSheetTransaction::Create(*this, *sheet);
   nsresult rv = DoTransaction(transaction);
   if (NS_SUCCEEDED(rv)) {
     mLastStyleSheetURL.Truncate();        // forget it
   }
   // Remove it from our internal list
@@ -3414,18 +3422,19 @@ HTMLEditor::DebugUnitTests(int32_t* outN
 
 NS_IMETHODIMP
 HTMLEditor::StyleSheetLoaded(StyleSheet* aSheet,
                              bool aWasAlternate,
                              nsresult aStatus)
 {
   AutoPlaceholderBatch batchIt(this);
 
-  if (!mLastStyleSheetURL.IsEmpty())
-    RemoveStyleSheet(mLastStyleSheetURL);
+  if (!mLastStyleSheetURL.IsEmpty()) {
+    RemoveStyleSheetWithTransaction(mLastStyleSheetURL);
+  }
 
   RefPtr<AddStyleSheetTransaction> transaction =
     AddStyleSheetTransaction::Create(*this, *aSheet);
   nsresult rv = DoTransaction(transaction);
   if (NS_SUCCEEDED(rv)) {
     // Get the URI, then url spec from the sheet
     nsAutoCString spec;
     rv = aSheet->GetSheetURI()->GetSpec(spec);
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1188,16 +1188,22 @@ protected:
                                   int32_t aDirection, bool aSelected);
 
   /**
    * A more C++-friendly version of nsIHTMLEditor::GetSelectedElement
    * that just returns null on errors.
    */
   already_AddRefed<dom::Element> GetSelectedElement(const nsAString& aTagName);
 
+  /**
+   * RemoveStyleSheetWithTransaction() removes the given URL stylesheet
+   * from mStyleSheets and mStyleSheetURLs.
+   */
+  nsresult RemoveStyleSheetWithTransaction(const nsAString& aURL);
+
 protected:
   RefPtr<TypeInState> mTypeInState;
   RefPtr<ComposerCommandsUpdater> mComposerCommandsUpdater;
 
   bool mCRInParagraphCreatesParagraph;
 
   bool mCSSAware;
   UniquePtr<CSSEditUtils> mCSSEditUtils;