Bug 1482023 - Create HTMLEditor::EnableStyleSheetInternal() for internal use r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 16 Aug 2018 10:03:46 +0000
changeset 487139 f3e7a7dd30a59ebe893fe37caaeb63e63485127d
parent 487138 4c023e0cd20fde4784d6d974718f659b115ab7de
child 487140 c7cba947e5046220f9a3678b465df6db769c58f7
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1482023
milestone63.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 1482023 - Create HTMLEditor::EnableStyleSheetInternal() for internal use r=m_kato HTMLEditor::EnableStyleSheet() is an XPCOM method but it's used internally. Therefore, we should create non-virtual method for internal use. Differential Revision: https://phabricator.services.mozilla.com/D3456
editor/libeditor/HTMLEditor.cpp
editor/libeditor/HTMLEditor.h
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -3092,17 +3092,17 @@ HTMLEditor::AddOverrideStyleSheetInterna
 NS_IMETHODIMP
 HTMLEditor::ReplaceOverrideStyleSheet(const nsAString& aURL)
 {
   // Enable existing sheet if already loaded.
   if (EnableExistingStyleSheet(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;
   }
   // Remove the previous sheet
   if (!mLastOverrideStyleSheetURL.IsEmpty()) {
     DebugOnly<nsresult> rv =
       RemoveOverrideStyleSheetInternal(mLastOverrideStyleSheetURL);
     NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
@@ -3147,28 +3147,38 @@ HTMLEditor::RemoveOverrideStyleSheetInte
 
   presShell->RemoveOverrideStyleSheet(sheet);
   presShell->ApplicableStylesChanged();
 
   return NS_OK;
 }
 
 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<StyleSheet> 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<nsIDocument> document = GetDocument();
   sheet->SetAssociatedDocumentOrShadowRoot(
     document, StyleSheet::NotOwnedByDocumentOrShadowRoot);
 
   sheet->SetDisabled(!aEnable);
-  return NS_OK;
 }
 
 bool
 HTMLEditor::EnableExistingStyleSheet(const nsAString& aURL)
 {
   RefPtr<StyleSheet> sheet = GetStyleSheetForURL(aURL);
 
   // Enable sheet if already loaded.
--- a/editor/libeditor/HTMLEditor.h
+++ b/editor/libeditor/HTMLEditor.h
@@ -1004,16 +1004,27 @@ protected: // Shouldn't be used by frien
    *
    * @param aURL        URL to the style sheet.
    * @return            Even if there is no specified style sheet in the
    *                    internal lists, this returns NS_OK.
    */
   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
    * before any editable text nodes or inline elements which can have text
    * nodes as their children, collapse selection at start of the editing
    * host.  If there is an editable text node which is not collapsed, collapses
    * selection at the start of the text node.  If there is an editable inline
    * element which cannot have text nodes as its child, collapses selection at
    * before the element node.  Otherwise, collapses selection at start of the