Bug 1451672 - part 12: Create HTMLEditor::RemoveStyleSheetWithTransaction() as implementation of nsIEditorStyleSheets::RemoveStyleSheet() r?m_kato
MozReview-Commit-ID: BIXU3jzD1rU
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -2917,18 +2917,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
@@ -3420,18 +3428,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;