Bug 1468708 - Part 4. Use EditorBase::GetPresContext to get nsPresContext in nsComposerDocumentCommands. r?masayuki draft
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Tue, 12 Jun 2018 16:55:34 -0700
changeset 807751 7d97ad2bee09911aa66fa697fb1e1fb0e6f5df76
parent 807750 42140bd2efb46b98d082e4e0989b0c0c02a27fe7
child 807752 844b330d1941f2f975404a5348f942bdbe62c914
push id113196
push userbmo:m_kato@ga2.so-net.ne.jp
push dateFri, 15 Jun 2018 17:12:54 +0000
reviewersmasayuki
bugs1468708
milestone62.0a1
Bug 1468708 - Part 4. Use EditorBase::GetPresContext to get nsPresContext in nsComposerDocumentCommands. r?masayuki MozReview-Commit-ID: 5ubcYtk5Ylj
editor/composer/nsComposerDocumentCommands.cpp
--- a/editor/composer/nsComposerDocumentCommands.cpp
+++ b/editor/composer/nsComposerDocumentCommands.cpp
@@ -30,32 +30,16 @@ using namespace mozilla;
 class nsISupports;
 
 //defines
 #define STATE_ENABLED  "state_enabled"
 #define STATE_ALL "state_all"
 #define STATE_ATTRIBUTE "state_attribute"
 #define STATE_DATA "state_data"
 
-static
-nsresult
-GetPresContextFromEditor(TextEditor* aTextEditor, nsPresContext** aResult)
-{
-  if (NS_WARN_IF(!aResult) || NS_WARN_IF(!aTextEditor)) {
-    return NS_ERROR_INVALID_ARG;
-  }
-  *aResult = nullptr;
-  nsCOMPtr<nsIPresShell> presShell = aTextEditor->GetPresShell();
-  if (NS_WARN_IF(!presShell)) {
-    return NS_ERROR_FAILURE;
-  }
-  RefPtr<nsPresContext> presContext = presShell->GetPresContext();
-  presContext.forget(aResult);
-  return NS_OK;
-}
 
 NS_IMETHODIMP
 nsSetDocumentOptionsCommand::IsCommandEnabled(const char * aCommandName,
                                               nsISupports *refCon,
                                               bool *outCmdEnabled)
 {
   NS_ENSURE_ARG_POINTER(outCmdEnabled);
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
@@ -85,21 +69,20 @@ nsSetDocumentOptionsCommand::DoCommandPa
 
   nsCOMPtr<nsIEditor> editor = do_QueryInterface(refCon);
   if (NS_WARN_IF(!editor)) {
     return NS_ERROR_INVALID_ARG;
   }
   TextEditor* textEditor = editor->AsTextEditor();
   MOZ_ASSERT(textEditor);
 
-  RefPtr<nsPresContext> presContext;
-  nsresult rv =
-    GetPresContextFromEditor(textEditor, getter_AddRefs(presContext));
-  NS_ENSURE_SUCCESS(rv, rv);
-  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
+  RefPtr<nsPresContext> presContext = textEditor->GetPresContext();
+  if (NS_WARN_IF(!presContext)) {
+    return NS_ERROR_FAILURE;
+  }
 
   int32_t animationMode;
   rv = aParams->GetLongValue("imageAnimation", &animationMode);
   if (NS_SUCCEEDED(rv)) {
     // for possible values of animation mode, see:
     // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl
     presContext->SetImageAnimationMode(animationMode);
   }
@@ -135,20 +118,20 @@ nsSetDocumentOptionsCommand::GetCommandS
 
   // Always get the enabled state
   bool outCmdEnabled = false;
   IsCommandEnabled(aCommandName, refCon, &outCmdEnabled);
   nsresult rv = aParams->SetBooleanValue(STATE_ENABLED, outCmdEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // get pres context
-  RefPtr<nsPresContext> presContext;
-  rv = GetPresContextFromEditor(textEditor, getter_AddRefs(presContext));
-  NS_ENSURE_SUCCESS(rv, rv);
-  NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
+  RefPtr<nsPresContext> presContext = textEditor->GetPresContext();
+  if (NS_WARN_IF(!presContext)) {
+    return NS_ERROR_FAILURE;
+  }
 
   int32_t animationMode;
   rv = aParams->GetLongValue("imageAnimation", &animationMode);
   if (NS_SUCCEEDED(rv)) {
     // for possible values of animation mode, see
     // http://lxr.mozilla.org/seamonkey/source/image/public/imgIContainer.idl
     rv = aParams->SetLongValue("imageAnimation",
                                presContext->ImageAnimationMode());