Bug 1433345 - part 1: Expose nsComposerCommandsUpdater with renaming it to mozilla::ComposerCOmmandsUpdater r=m_kato

For making HTMLEditor stores it directly, we should expose
nsComposerCommandsUpdater first.  Then, it should be in mozilla namespace.

MozReview-Commit-ID: 8Vhum4Q3WY

--HG--
rename : editor/composer/nsComposerCommandsUpdater.cpp => editor/composer/ComposerCommandsUpdater.cpp
rename : editor/composer/nsComposerCommandsUpdater.h => editor/composer/ComposerCommandsUpdater.h
extra : rebase_source : 3056eeb4aa3dd3426246b74be1e1e18a93a7c33d
This commit is contained in:
Masayuki Nakano 2018-01-26 14:06:29 +09:00
Родитель 61536137bd
Коммит 5436129851
6 изменённых файлов: 173 добавлений и 188 удалений

Просмотреть файл

@ -4,11 +4,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ComposerCommandsUpdater.h"
#include "mozilla/mozalloc.h" // for operator new
#include "mozilla/dom/Selection.h"
#include "nsAString.h"
#include "nsComponentManagerUtils.h" // for do_CreateInstance
#include "nsComposerCommandsUpdater.h"
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
#include "nsError.h" // for NS_OK, NS_ERROR_FAILURE, etc
#include "nsICommandManager.h" // for nsICommandManager
@ -25,14 +26,16 @@
class nsIDOMDocument;
class nsITransaction;
nsComposerCommandsUpdater::nsComposerCommandsUpdater()
: mDirtyState(eStateUninitialized)
, mSelectionCollapsed(eStateUninitialized)
, mFirstDoOfFirstUndo(true)
namespace mozilla {
ComposerCommandsUpdater::ComposerCommandsUpdater()
: mDirtyState(eStateUninitialized)
, mSelectionCollapsed(eStateUninitialized)
, mFirstDoOfFirstUndo(true)
{
}
nsComposerCommandsUpdater::~nsComposerCommandsUpdater()
ComposerCommandsUpdater::~ComposerCommandsUpdater()
{
// cancel any outstanding update timer
if (mUpdateTimer) {
@ -40,16 +43,19 @@ nsComposerCommandsUpdater::~nsComposerCommandsUpdater()
}
}
NS_IMPL_ISUPPORTS(nsComposerCommandsUpdater, nsISelectionListener,
nsIDocumentStateListener, nsITransactionListener,
nsITimerCallback, nsINamed)
NS_IMPL_ISUPPORTS(ComposerCommandsUpdater,
nsISelectionListener,
nsIDocumentStateListener,
nsITransactionListener,
nsITimerCallback,
nsINamed)
#if 0
#pragma mark -
#endif
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifyDocumentCreated()
ComposerCommandsUpdater::NotifyDocumentCreated()
{
// Trigger an nsIObserve notification that the document has been created
UpdateOneCommand("obs_documentCreated");
@ -57,7 +63,7 @@ nsComposerCommandsUpdater::NotifyDocumentCreated()
}
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
ComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
{
// cancel any outstanding update timer
if (mUpdateTimer) {
@ -76,15 +82,16 @@ nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifyDocumentStateChanged(bool aNowDirty)
ComposerCommandsUpdater::NotifyDocumentStateChanged(bool aNowDirty)
{
// update document modified. We should have some other notifications for this too.
return UpdateDirtyState(aNowDirty);
}
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *,
nsISelection *, int16_t)
ComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
nsISelection* aSelection,
int16_t aReason)
{
return PrimeUpdateTimer();
}
@ -94,16 +101,18 @@ nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *,
#endif
NS_IMETHODIMP
nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, bool *aInterrupt)
ComposerCommandsUpdater::WillDo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aDoResult)
ComposerCommandsUpdater::DidDo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
nsresult aDoResult)
{
// only need to update if the status of the Undo menu item changes.
int32_t undoCount;
@ -119,18 +128,18 @@ nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
}
NS_IMETHODIMP
nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
bool *aInterrupt)
ComposerCommandsUpdater::WillUndo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
nsresult aUndoResult)
ComposerCommandsUpdater::DidUndo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
nsresult aUndoResult)
{
int32_t undoCount;
aManager->GetNumberOfUndoItems(&undoCount);
@ -142,68 +151,69 @@ nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager,
}
NS_IMETHODIMP
nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
bool *aInterrupt)
ComposerCommandsUpdater::WillRedo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
nsresult aRedoResult)
ComposerCommandsUpdater::DidRedo(nsITransactionManager* aManager,
nsITransaction* aTransaction,
nsresult aRedoResult)
{
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager,
bool *aInterrupt)
ComposerCommandsUpdater::WillBeginBatch(nsITransactionManager* aManager,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager,
bool *aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager,
ComposerCommandsUpdater::DidBeginBatch(nsITransactionManager* aManager,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge,
bool *aInterrupt)
ComposerCommandsUpdater::WillEndBatch(nsITransactionManager* aManager,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge,
bool aDidMerge, nsresult aMergeResult)
ComposerCommandsUpdater::DidEndBatch(nsITransactionManager* aManager,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP
ComposerCommandsUpdater::WillMerge(nsITransactionManager* aManager,
nsITransaction* aTopTransaction,
nsITransaction* aTransactionToMerge,
bool* aInterrupt)
{
*aInterrupt = false;
return NS_OK;
}
NS_IMETHODIMP
ComposerCommandsUpdater::DidMerge(nsITransactionManager* aManager,
nsITransaction* aTopTransaction,
nsITransaction* aTransactionToMerge,
bool aDidMerge,
nsresult aMergeResult)
{
return NS_OK;
}
@ -213,7 +223,7 @@ nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager,
#endif
nsresult
nsComposerCommandsUpdater::Init(nsPIDOMWindowOuter* aDOMWindow)
ComposerCommandsUpdater::Init(nsPIDOMWindowOuter* aDOMWindow)
{
NS_ENSURE_ARG(aDOMWindow);
mDOMWindow = do_GetWeakReference(aDOMWindow);
@ -222,7 +232,7 @@ nsComposerCommandsUpdater::Init(nsPIDOMWindowOuter* aDOMWindow)
}
nsresult
nsComposerCommandsUpdater::PrimeUpdateTimer()
ComposerCommandsUpdater::PrimeUpdateTimer()
{
if (!mUpdateTimer) {
mUpdateTimer = NS_NewTimer();;
@ -236,7 +246,8 @@ nsComposerCommandsUpdater::PrimeUpdateTimer()
}
void nsComposerCommandsUpdater::TimerCallback()
void
ComposerCommandsUpdater::TimerCallback()
{
// if the selection state has changed, update stuff
bool isCollapsed = SelectionIsCollapsed();
@ -251,7 +262,7 @@ void nsComposerCommandsUpdater::TimerCallback()
}
nsresult
nsComposerCommandsUpdater::UpdateDirtyState(bool aNowDirty)
ComposerCommandsUpdater::UpdateDirtyState(bool aNowDirty)
{
if (mDirtyState != static_cast<int8_t>(aNowDirty)) {
UpdateCommandGroup(NS_LITERAL_STRING("save"));
@ -263,7 +274,7 @@ nsComposerCommandsUpdater::UpdateDirtyState(bool aNowDirty)
}
nsresult
nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
ComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
{
nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
@ -320,7 +331,7 @@ nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
}
nsresult
nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand)
ComposerCommandsUpdater::UpdateOneCommand(const char* aCommand)
{
nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);
@ -331,7 +342,7 @@ nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand)
}
bool
nsComposerCommandsUpdater::SelectionIsCollapsed()
ComposerCommandsUpdater::SelectionIsCollapsed()
{
nsCOMPtr<nsPIDOMWindowOuter> domWindow = do_QueryReferent(mDOMWindow);
NS_ENSURE_TRUE(domWindow, true);
@ -345,7 +356,7 @@ nsComposerCommandsUpdater::SelectionIsCollapsed()
}
already_AddRefed<nsPICommandUpdater>
nsComposerCommandsUpdater::GetCommandUpdater()
ComposerCommandsUpdater::GetCommandUpdater()
{
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mDocShell);
NS_ENSURE_TRUE(docShell, nullptr);
@ -355,9 +366,9 @@ nsComposerCommandsUpdater::GetCommandUpdater()
}
NS_IMETHODIMP
nsComposerCommandsUpdater::GetName(nsACString& aName)
ComposerCommandsUpdater::GetName(nsACString& aName)
{
aName.AssignLiteral("nsComposerCommandsUpdater");
aName.AssignLiteral("ComposerCommandsUpdater");
return NS_OK;
}
@ -366,9 +377,9 @@ nsComposerCommandsUpdater::GetName(nsACString& aName)
#endif
nsresult
nsComposerCommandsUpdater::Notify(nsITimer *timer)
ComposerCommandsUpdater::Notify(nsITimer* aTimer)
{
NS_ASSERTION(timer == mUpdateTimer.get(), "Hey, this ain't my timer!");
NS_ASSERTION(aTimer == mUpdateTimer.get(), "Hey, this ain't my timer!");
TimerCallback();
return NS_OK;
}
@ -377,11 +388,4 @@ nsComposerCommandsUpdater::Notify(nsITimer *timer)
#pragma mark -
#endif
nsresult
NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult)
{
RefPtr<nsComposerCommandsUpdater> newThang = new nsComposerCommandsUpdater;
newThang.forget(aInstancePtrResult);
return NS_OK;
}
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_ComposerCommandsUpdater_h
#define mozilla_ComposerCommandsUpdater_h
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsIDocumentStateListener.h"
#include "nsINamed.h"
#include "nsISelectionListener.h"
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS
#include "nsITimer.h" // for NS_DECL_NSITIMERCALLBACK, etc
#include "nsITransactionListener.h" // for nsITransactionListener
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
#include "nscore.h" // for NS_IMETHOD, nsresult, etc
class nsPIDOMWindowOuter;
class nsITransaction;
class nsITransactionManager;
class nsPICommandUpdater;
namespace mozilla {
class ComposerCommandsUpdater final : public nsISelectionListener
, public nsIDocumentStateListener
, public nsITransactionListener
, public nsITimerCallback
, public nsINamed
{
public:
ComposerCommandsUpdater();
// nsISupports
NS_DECL_ISUPPORTS
// nsISelectionListener
NS_DECL_NSISELECTIONLISTENER
// nsIDocumentStateListener
NS_DECL_NSIDOCUMENTSTATELISTENER
// nsITimerCallback
NS_DECL_NSITIMERCALLBACK
// nsINamed
NS_DECL_NSINAMED
// nsITransactionListener
NS_DECL_NSITRANSACTIONLISTENER
nsresult Init(nsPIDOMWindowOuter* aDOMWindow);
protected:
virtual ~ComposerCommandsUpdater();
enum
{
eStateUninitialized = -1,
eStateOff = 0,
eStateOn = 1,
};
bool SelectionIsCollapsed();
nsresult UpdateDirtyState(bool aNowDirty);
nsresult UpdateOneCommand(const char* aCommand);
nsresult UpdateCommandGroup(const nsAString& aCommandGroup);
already_AddRefed<nsPICommandUpdater> GetCommandUpdater();
nsresult PrimeUpdateTimer();
void TimerCallback();
nsCOMPtr<nsITimer> mUpdateTimer;
nsWeakPtr mDOMWindow;
nsWeakPtr mDocShell;
int8_t mDirtyState;
int8_t mSelectionCollapsed;
bool mFirstDoOfFirstUndo;
};
} // namespace mozilla
#endif // #ifndef mozilla_ComposerCommandsUpdater_h

Просмотреть файл

@ -15,9 +15,9 @@ XPIDL_SOURCES += [
XPIDL_MODULE = 'composer'
UNIFIED_SOURCES += [
'ComposerCommandsUpdater.cpp',
'EditorSpellCheck.cpp',
'nsComposerCommands.cpp',
'nsComposerCommandsUpdater.cpp',
'nsComposerController.cpp',
'nsComposerDocumentCommands.cpp',
'nsComposerRegistration.cpp',
@ -26,6 +26,7 @@ UNIFIED_SOURCES += [
]
EXPORTS.mozilla += [
'ComposerCommandsUpdater.h',
'EditorSpellCheck.h',
]

Просмотреть файл

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsComposerCommandsUpdater_h__
#define nsComposerCommandsUpdater_h__
#include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
#include "nsIDocumentStateListener.h"
#include "nsINamed.h"
#include "nsISelectionListener.h"
#include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS
#include "nsITimer.h" // for NS_DECL_NSITIMERCALLBACK, etc
#include "nsITransactionListener.h" // for nsITransactionListener
#include "nsIWeakReferenceUtils.h" // for nsWeakPtr
#include "nscore.h" // for NS_IMETHOD, nsresult, etc
class nsPIDOMWindowOuter;
class nsITransaction;
class nsITransactionManager;
class nsPICommandUpdater;
class nsComposerCommandsUpdater : public nsISelectionListener,
public nsIDocumentStateListener,
public nsITransactionListener,
public nsITimerCallback,
public nsINamed
{
public:
nsComposerCommandsUpdater();
// nsISupports
NS_DECL_ISUPPORTS
// nsISelectionListener
NS_DECL_NSISELECTIONLISTENER
// nsIDocumentStateListener
NS_DECL_NSIDOCUMENTSTATELISTENER
// nsITimerCallback interfaces
NS_DECL_NSITIMERCALLBACK
// nsINamed
NS_DECL_NSINAMED
/** nsITransactionListener interfaces
*/
NS_IMETHOD WillDo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override;
NS_IMETHOD DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult) override;
NS_IMETHOD WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override;
NS_IMETHOD DidUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult) override;
NS_IMETHOD WillRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, bool *aInterrupt) override;
NS_IMETHOD DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult) override;
NS_IMETHOD WillBeginBatch(nsITransactionManager *aManager, bool *aInterrupt) override;
NS_IMETHOD DidBeginBatch(nsITransactionManager *aManager, nsresult aResult) override;
NS_IMETHOD WillEndBatch(nsITransactionManager *aManager, bool *aInterrupt) override;
NS_IMETHOD DidEndBatch(nsITransactionManager *aManager, nsresult aResult) override;
NS_IMETHOD WillMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge, bool *aInterrupt) override;
NS_IMETHOD DidMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge,
bool aDidMerge, nsresult aMergeResult) override;
nsresult Init(nsPIDOMWindowOuter* aDOMWindow);
protected:
virtual ~nsComposerCommandsUpdater();
enum {
eStateUninitialized = -1,
eStateOff = false,
eStateOn = true
};
bool SelectionIsCollapsed();
nsresult UpdateDirtyState(bool aNowDirty);
nsresult UpdateOneCommand(const char* aCommand);
nsresult UpdateCommandGroup(const nsAString& aCommandGroup);
already_AddRefed<nsPICommandUpdater> GetCommandUpdater();
nsresult PrimeUpdateTimer();
void TimerCallback();
nsCOMPtr<nsITimer> mUpdateTimer;
nsWeakPtr mDOMWindow;
nsWeakPtr mDocShell;
int8_t mDirtyState;
int8_t mSelectionCollapsed;
bool mFirstDoOfFirstUndo;
};
extern "C" nsresult NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult);
#endif // nsComposerCommandsUpdater_h__

Просмотреть файл

@ -7,12 +7,12 @@
#include <string.h> // for nullptr, strcmp
#include "imgIContainer.h" // for imgIContainer, etc
#include "mozilla/ComposerCommandsUpdater.h" // for ComposerCommandsUpdater
#include "mozilla/FlushType.h" // for FlushType::Frames
#include "mozilla/HTMLEditor.h" // for HTMLEditor
#include "mozilla/mozalloc.h" // for operator new
#include "nsAString.h"
#include "nsComponentManagerUtils.h" // for do_CreateInstance
#include "nsComposerCommandsUpdater.h" // for nsComposerCommandsUpdater
#include "nsContentUtils.h"
#include "nsDebug.h" // for NS_ENSURE_SUCCESS, etc
#include "nsEditingSession.h"
@ -378,7 +378,7 @@ nsEditingSession::SetupEditorOnWindow(mozIDOMWindowProxy* aWindow)
}
// make the UI state maintainer
mStateMaintainer = new nsComposerCommandsUpdater();
mStateMaintainer = new ComposerCommandsUpdater();
// now init the state maintainer
// This allows notification of error state

Просмотреть файл

@ -36,7 +36,6 @@ class nsITimer;
{ 0xbc26ff01, 0xf2bd, 0x11d4, { 0xa7, 0x3c, 0xe5, 0xa4, 0xb5, 0xa8, 0xbd, 0xfc } }
class nsComposerCommandsUpdater;
class nsIChannel;
class nsIControllers;
class nsIDocShell;
@ -44,6 +43,7 @@ class nsIEditor;
class nsIWebProgress;
namespace mozilla {
class ComposerCommandsUpdater;
class HTMLEditor;
} // namespace mozilla
@ -130,7 +130,7 @@ protected:
// THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT
// MORE THAN ONE EDITOR PER EDITING SESSION
RefPtr<nsComposerCommandsUpdater> mStateMaintainer;
RefPtr<mozilla::ComposerCommandsUpdater> mStateMaintainer;
// Save the editor type so we can create the editor after loading uri
nsCString mEditorType;