diff --git a/editor/libeditor/HTMLEditor.cpp b/editor/libeditor/HTMLEditor.cpp index a9aea467e8e9..bcccdbf95168 100644 --- a/editor/libeditor/HTMLEditor.cpp +++ b/editor/libeditor/HTMLEditor.cpp @@ -3097,7 +3097,7 @@ HTMLEditor::ReplaceOverrideStyleSheet(const nsAString& aURL) // Disable last sheet if not the same as new one if (!mLastOverrideStyleSheetURL.IsEmpty() && !mLastOverrideStyleSheetURL.Equals(aURL)) { - return EnableStyleSheet(mLastOverrideStyleSheetURL, false); + EnableStyleSheetInternal(mLastOverrideStyleSheetURL, false); } return NS_OK; } @@ -3152,10 +3152,21 @@ HTMLEditor::RemoveOverrideStyleSheetInternal(const nsAString& aURL) } NS_IMETHODIMP -HTMLEditor::EnableStyleSheet(const nsAString& aURL, bool aEnable) +HTMLEditor::EnableStyleSheet(const nsAString& aURL, + bool aEnable) +{ + EnableStyleSheetInternal(aURL, aEnable); + return NS_OK; +} + +void +HTMLEditor::EnableStyleSheetInternal(const nsAString& aURL, + bool aEnable) { RefPtr sheet = GetStyleSheetForURL(aURL); - NS_ENSURE_TRUE(sheet, NS_OK); // Don't fail if sheet not found + if (!sheet) { + return; + } // Ensure the style sheet is owned by our document. nsCOMPtr document = GetDocument(); @@ -3163,7 +3174,6 @@ HTMLEditor::EnableStyleSheet(const nsAString& aURL, bool aEnable) document, StyleSheet::NotOwnedByDocumentOrShadowRoot); sheet->SetDisabled(!aEnable); - return NS_OK; } bool diff --git a/editor/libeditor/HTMLEditor.h b/editor/libeditor/HTMLEditor.h index 5f6d9e606e93..b5a0be51a8a6 100644 --- a/editor/libeditor/HTMLEditor.h +++ b/editor/libeditor/HTMLEditor.h @@ -1008,6 +1008,17 @@ protected: // Shouldn't be used by friend classes */ nsresult RemoveOverrideStyleSheetInternal(const nsAString& aURL); + /** + * Enable or disable the style sheet synchronously. + * aURL is just a key to specify a style sheet in the internal array. + * I.e., the style sheet has already been registered with + * AddOverrideStyleSheetInternal(). + * + * @param aURL URL to the style sheet. + * @param aEnable true if enable the style sheet. false if disable it. + */ + void EnableStyleSheetInternal(const nsAString& aURL, bool aEnable); + /** * MaybeCollapseSelectionAtFirstEditableNode() may collapse selection at * proper position to staring to edit. If there is a non-editable node