Bug 1468708 - Part 4. Use EditorBase::GetPresContext to get nsPresContext in nsComposerDocumentCommands. r?masayuki
MozReview-Commit-ID: 5ubcYtk5Ylj
--- 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());