Command Controller refactoring and cleanup, mostly by mjudge with help by cmanske, b=170353, r=brade, sr=sfraser. EditingSession cleanup and new commands in \editor, b=174439, r=mjudge, sr=sfraser

git-svn-id: svn://10.0.0.236/trunk@133703 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cmanske%netscape.com
2002-11-12 23:03:27 +00:00
parent 12a72333d8
commit d6cc98279b
35 changed files with 1811 additions and 899 deletions

View File

@@ -254,10 +254,6 @@
{ 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {508f5601-e09b-11d3-9f7e-cf931f9f173c}
#define NS_CONTROLLERCOMMANDMANAGER_CID \
{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } }
// {BFD05264-834C-11d2-8EAC-00805F29F371}
#define NS_XULSORTSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } }

View File

@@ -254,10 +254,6 @@
{ 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {508f5601-e09b-11d3-9f7e-cf931f9f173c}
#define NS_CONTROLLERCOMMANDMANAGER_CID \
{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } }
// {BFD05264-834C-11d2-8EAC-00805F29F371}
#define NS_XULSORTSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } }

View File

@@ -43,7 +43,6 @@
#include "nsIRadioVisitor.h"
#include "nsIControllers.h"
#include "nsIEditorController.h"
#include "nsIFocusController.h"
#include "nsPIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
@@ -1990,17 +1989,6 @@ nsHTMLInputElement::GetControllers(nsIControllers** aResult)
controller(do_CreateInstance("@mozilla.org/editor/editorcontroller;1",
&rv));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIEditorController>
editorController = do_QueryInterface(controller, &rv);
if (NS_FAILED(rv))
return rv;
rv = editorController->Init(nsnull);
if (NS_FAILED(rv))
return rv;
mControllers->AppendController(controller);
}
}

View File

@@ -40,7 +40,6 @@
#include "nsIDOMNSHTMLTextAreaElement.h"
#include "nsITextControlElement.h"
#include "nsIControllers.h"
#include "nsIEditorController.h"
#include "nsContentCID.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
@@ -818,14 +817,6 @@ nsHTMLTextAreaElement::GetControllers(nsIControllers** aResult)
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIEditorController> editorController = do_QueryInterface(controller, &rv);
if (NS_FAILED(rv))
return rv;
rv = editorController->Init(nsnull);
if (NS_FAILED(rv))
return rv;
mControllers->AppendController(controller);
}

View File

@@ -203,7 +203,8 @@ nsXULControllers::GetControllerAt(PRUint32 aIndex, nsIController **_retval)
NS_IMETHODIMP
nsXULControllers::AppendController(nsIController *controller)
{
nsXULControllerData* controllerData = new nsXULControllerData(mCurControllerID++, controller);
// This assigns controller IDs starting at 1 so we can use 0 to test if an ID was obtained
nsXULControllerData* controllerData = new nsXULControllerData(++mCurControllerID, controller);
if (!controllerData) return NS_ERROR_OUT_OF_MEMORY;
PRBool appended = mControllers.AppendElement((void *)controllerData);
NS_ASSERTION(appended, "Appending controller failed");

View File

@@ -20,7 +20,9 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
* Simon Fraser <sfraser@netscape.com>
* Mike Judge <mjudge@netscape.com>
* Charles Manske <cmanske@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -47,32 +49,58 @@ interface nsIEditingShell;
interface nsIEditingSession : nsISupports
{
/**
* Error codes when we fail to create an editor
* is placed in attribute editorStatus
*/
const long eEditorOK = 0;
const long eEditorCreationInProgress = 1;
const long eEditorErrorCantEditMimeType = 2;
const long eEditorErrorFileNotFound = 3;
const long eEditorErrorCantEditFramesets = 8;
const long eEditorErrorUnknown = 9;
/**
* Status after editor creation and document loading
* Value is one of the above error codes
*/
readonly attribute unsigned long editorStatus;
/* Init the editing session, passing the window that will be the root of
the session (usually the content root frame.
*/
void init(in nsIDOMWindow aWindow);
* the session (usually the content root frame)
*/
void init(in nsIDOMWindow window);
/* Make this window editable
/**
* Make this window editable
* @param aWindow nsIDOMWindow, the window the embedder needs to make editable
* @param aEditorType string, "html" "htmlsimple" "text" "textsimple"
*/
void makeWindowEditable(in nsIDOMWindow aWindow, in string aEditorType, in boolean inDoAfterUriLoad);
void makeWindowEditable(in nsIDOMWindow window, in string aEditorType, in boolean doAfterUriLoad);
/* Test whether a specific window has had its editable flag set; it may have an editor
now, or will get one after the uri load.
Use this, passing the content root window, to test if we've set up editing
for this content.
*/
boolean windowIsEditable(in nsIDOMWindow aWindow);
/**
* Test whether a specific window has had its editable flag set; it may have an editor
* now, or will get one after the uri load.
*
* Use this, passing the content root window, to test if we've set up editing
* for this content.
*/
boolean windowIsEditable(in nsIDOMWindow window);
/* Get the editor for this window. May return null */
nsIEditor getEditorForWindow(in nsIDOMWindow aWindow);
/**
* Get the editor for this window. May return null
*/
nsIEditor getEditorForWindow(in nsIDOMWindow window);
/* lower level */
void setupEditorOnWindow(in nsIDOMWindow aWindow);
void tearDownEditorOnWindow(in nsIDOMWindow aWindow);
/**
* Setup editor and related support objects
*/
void setupEditorOnWindow(in nsIDOMWindow window);
/**
* Destroy editor and related support objects
*/
void tearDownEditorOnWindow(in nsIDOMWindow window);
};

View File

@@ -61,7 +61,6 @@ REQUIRES = xpcom \
$(NULL)
CPPSRCS = \
nsEditorShell.cpp \
nsEditorParserObserver.cpp \
nsInterfaceState.cpp \
nsComposerController.cpp \

File diff suppressed because it is too large Load Diff

View File

@@ -20,8 +20,9 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ryan Cassin <rcassin@supernova.org>
* Daniel Glazman <glazman@netscape.com>
* Ryan Cassin <rcassin@supernova.org>
* Daniel Glazman <glazman@netscape.com>
* Charles Manske <cmanske@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -44,6 +45,8 @@
#include "nsIControllerCommand.h"
#include "nsString.h"
class nsIEditor;
// This is a virtual base class for commands registered with the composer controller.
// Note that such commands are instantiated once per composer, so can store state.
// Also note that IsCommandEnabled can be called with an editor that may not
@@ -70,7 +73,6 @@ public:
};
#define NS_DECL_COMPOSER_COMMAND(_cmd) \
class _cmd : public nsBaseComposerCommand \
{ \
@@ -272,17 +274,16 @@ protected:
// composer commands
NS_DECL_COMPOSER_COMMAND(nsCloseCommand)
NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand)
NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand)
//NS_DECL_COMPOSER_COMMAND(nsPrintingCommands)
// Generic commands
// File menu
NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything
// Edit menu
NS_DECL_COMPOSER_COMMAND(nsPasteQuotationCommand)
NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand)
// Block transformations
@@ -294,5 +295,7 @@ NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)
// Insert content commands
NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand)
#endif // nsComposerCommands_h_

View File

@@ -18,14 +18,16 @@
* Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
* Simon Fraser <sfraser@netscape.com>
* Michael Judge <mjudge@netscape.com>
* Charles Manske <cmanske@netscape.com>
*/
#include "nsIDOMWindow.h"
#include "nsComposerCommandsUpdater.h"
#include "nsIServiceManager.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
//#include "nsIDocument.h"
#include "nsISelection.h"
#include "nsIScriptGlobalObject.h"
@@ -39,8 +41,8 @@
#include "nsITransactionManager.h"
nsComposerCommandsUpdater::nsComposerCommandsUpdater()
: mEditor(nsnull)
, mDocShell(nsnull)
: mDOMWindow(nsnull)
, mDocShell(nsnull)
, mDirtyState(eStateUninitialized)
, mSelectionCollapsed(eStateUninitialized)
, mFirstDoOfFirstUndo(PR_TRUE)
@@ -52,7 +54,8 @@ nsComposerCommandsUpdater::~nsComposerCommandsUpdater()
{
}
NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, nsIDocumentStateListener, nsITransactionListener, nsITimerCallback);
NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener,
nsIDocumentStateListener, nsITransactionListener, nsITimerCallback);
#if 0
#pragma mark -
@@ -61,6 +64,8 @@ NS_IMPL_ISUPPORTS4(nsComposerCommandsUpdater, nsISelectionListener, nsIDocumentS
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifyDocumentCreated()
{
// Trigger an nsIObserve notification that the document has been created
UpdateOneCommand("obs_documentCreated");
return NS_OK;
}
@@ -71,6 +76,8 @@ nsComposerCommandsUpdater::NotifyDocumentWillBeDestroyed()
if (mUpdateTimer)
mUpdateTimer->Cancel();
// Trigger an nsIObserve notification that the document will be destroyed
UpdateOneCommand("obs_documentWillBeDestroyed");
return NS_OK;
}
@@ -83,7 +90,8 @@ nsComposerCommandsUpdater::NotifyDocumentStateChanged(PRBool aNowDirty)
}
NS_IMETHODIMP
nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short)
nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *,
nsISelection *, short)
{
return PrimeUpdateTimer();
}
@@ -92,14 +100,16 @@ nsComposerCommandsUpdater::NotifySelectionChanged(nsIDOMDocument *, nsISelection
#pragma mark -
#endif
NS_IMETHODIMP nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
NS_IMETHODIMP
nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aDoResult)
{
// only need to update if the status of the Undo menu item changes.
@@ -108,78 +118,99 @@ NS_IMETHODIMP nsComposerCommandsUpdater::DidDo(nsITransactionManager *aManager,
if (undoCount == 1)
{
if (mFirstDoOfFirstUndo)
CallUpdateCommands(NS_LITERAL_STRING("undo"));
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
mFirstDoOfFirstUndo = PR_FALSE;
}
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aUndoResult)
NS_IMETHODIMP
nsComposerCommandsUpdater::DidUndo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
nsresult aUndoResult)
{
PRInt32 undoCount;
aManager->GetNumberOfUndoItems(&undoCount);
if (undoCount == 0)
mFirstDoOfFirstUndo = PR_TRUE; // reset the state for the next do
CallUpdateCommands(NS_LITERAL_STRING("undo"));
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction, nsresult aRedoResult)
NS_IMETHODIMP
nsComposerCommandsUpdater::DidRedo(nsITransactionManager *aManager,
nsITransaction *aTransaction,
nsresult aRedoResult)
{
CallUpdateCommands(NS_LITERAL_STRING("undo"));
UpdateCommandGroup(NS_LITERAL_STRING("undo"));
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillBeginBatch(nsITransactionManager *aManager,
PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager, nsresult aResult)
NS_IMETHODIMP
nsComposerCommandsUpdater::DidBeginBatch(nsITransactionManager *aManager,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillEndBatch(nsITransactionManager *aManager,
PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager, nsresult aResult)
NS_IMETHODIMP
nsComposerCommandsUpdater::DidEndBatch(nsITransactionManager *aManager,
nsresult aResult)
{
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool *aInterrupt)
NS_IMETHODIMP
nsComposerCommandsUpdater::WillMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge,
PRBool *aInterrupt)
{
*aInterrupt = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge,
PRBool aDidMerge, nsresult aMergeResult)
NS_IMETHODIMP
nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManager,
nsITransaction *aTopTransaction,
nsITransaction *aTransactionToMerge,
PRBool aDidMerge, nsresult aMergeResult)
{
return NS_OK;
}
@@ -189,9 +220,18 @@ NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge(nsITransactionManager *aManage
#endif
nsresult
nsComposerCommandsUpdater::SetEditor(nsIEditor* aEditor)
nsComposerCommandsUpdater::Init(nsIDOMWindow* aDOMWindow)
{
mEditor = aEditor; // no addreffing here
NS_ENSURE_ARG(aDOMWindow);
mDOMWindow = aDOMWindow;
nsCOMPtr<nsIScriptGlobalObject> scriptObject(do_QueryInterface(aDOMWindow));
if (scriptObject)
{
nsCOMPtr<nsIDocShell> docShell;
scriptObject->GetDocShell(getter_AddRefs(docShell));
mDocShell = docShell.get();
}
return NS_OK;
}
@@ -212,7 +252,7 @@ nsComposerCommandsUpdater::PrimeUpdateTimer()
if (NS_FAILED(rv)) return rv;
const PRUint32 kUpdateTimerDelay = 150;
return mUpdateTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this),
return mUpdateTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this),
kUpdateTimerDelay,
nsITimer::TYPE_ONE_SHOT);
}
@@ -224,11 +264,11 @@ void nsComposerCommandsUpdater::TimerCallback()
PRBool isCollapsed = SelectionIsCollapsed();
if (isCollapsed != mSelectionCollapsed)
{
CallUpdateCommands(NS_LITERAL_STRING("select"));
UpdateCommandGroup(NS_LITERAL_STRING("select"));
mSelectionCollapsed = isCollapsed;
}
CallUpdateCommands(NS_LITERAL_STRING("style"));
UpdateCommandGroup(NS_LITERAL_STRING("style"));
}
nsresult
@@ -236,8 +276,7 @@ nsComposerCommandsUpdater::UpdateDirtyState(PRBool aNowDirty)
{
if (mDirtyState != aNowDirty)
{
CallUpdateCommands(NS_LITERAL_STRING("save"));
UpdateCommandGroup(NS_LITERAL_STRING("save"));
mDirtyState = aNowDirty;
}
@@ -245,51 +284,87 @@ nsComposerCommandsUpdater::UpdateDirtyState(PRBool aNowDirty)
}
nsresult
nsComposerCommandsUpdater::CallUpdateCommands(const nsAString& aCommand)
nsComposerCommandsUpdater::UpdateCommandGroup(const nsAString& aCommandGroup)
{
if (!mDocShell)
if (!mDocShell) return NS_ERROR_FAILURE;
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell);
nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager);
if (!commandUpdater) return NS_ERROR_FAILURE;
// This hardcoded list of commands is temporary.
// This code should use nsIControllerCommandGroup.
if (aCommandGroup.Equals(NS_LITERAL_STRING("undo")))
{
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
if (!editor) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> domDoc;
editor->GetDocument(getter_AddRefs(domDoc));
if (!domDoc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> theDoc = do_QueryInterface(domDoc);
if (!theDoc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
nsCOMPtr<nsIDocShell> docShell;
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
mDocShell = docShell.get();
commandUpdater->CommandStatusChanged("cmd_undo");
commandUpdater->CommandStatusChanged("cmd_redo");
}
else if (aCommandGroup.Equals(NS_LITERAL_STRING("select")) ||
aCommandGroup.Equals(NS_LITERAL_STRING("style")))
{
commandUpdater->CommandStatusChanged("cmd_bold");
commandUpdater->CommandStatusChanged("cmd_italic");
commandUpdater->CommandStatusChanged("cmd_underline");
commandUpdater->CommandStatusChanged("cmd_tt");
commandUpdater->CommandStatusChanged("cmd_strikethrough");
commandUpdater->CommandStatusChanged("cmd_superscript");
commandUpdater->CommandStatusChanged("cmd_subscript");
commandUpdater->CommandStatusChanged("cmd_nobreak");
commandUpdater->CommandStatusChanged("cmd_em");
commandUpdater->CommandStatusChanged("cmd_strong");
commandUpdater->CommandStatusChanged("cmd_cite");
commandUpdater->CommandStatusChanged("cmd_abbr");
commandUpdater->CommandStatusChanged("cmd_acronym");
commandUpdater->CommandStatusChanged("cmd_code");
commandUpdater->CommandStatusChanged("cmd_samp");
commandUpdater->CommandStatusChanged("cmd_var");
commandUpdater->CommandStatusChanged("cmd_increaseFont");
commandUpdater->CommandStatusChanged("cmd_decreaseFont");
commandUpdater->CommandStatusChanged("cmd_paragraphState");
commandUpdater->CommandStatusChanged("cmd_fontFace");
commandUpdater->CommandStatusChanged("cmd_fontColor");
commandUpdater->CommandStatusChanged("cmd_backgroundColor");
commandUpdater->CommandStatusChanged("cmd_highlight");
}
else if (aCommandGroup.Equals(NS_LITERAL_STRING("save")))
{
// save commands (most are not in C++)
commandUpdater->CommandStatusChanged("cmd_setDocumentModified");
commandUpdater->CommandStatusChanged("cmd_save");
}
return NS_OK;
}
nsresult
nsComposerCommandsUpdater::UpdateOneCommand(const char *aCommand)
{
if (!mDocShell) return NS_ERROR_FAILURE;
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(mDocShell);
nsCOMPtr<nsPICommandUpdater> commandUpdater = do_QueryInterface(commandManager);
if (!commandUpdater) return NS_ERROR_FAILURE;
commandUpdater->CommandStatusChanged("cmd_bold");
commandUpdater->CommandStatusChanged("cmd_italic");
commandUpdater->CommandStatusChanged("cmd_underline");
commandUpdater->CommandStatusChanged(aCommand);
return NS_OK;
}
PRBool
nsComposerCommandsUpdater::SelectionIsCollapsed()
{
if (!mDOMWindow) return PR_TRUE;
nsresult rv;
// we don't care too much about failures here.
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsISelection> domSelection;
rv = editor->GetSelection(getter_AddRefs(domSelection));
rv = mDOMWindow->GetSelection(getter_AddRefs(domSelection));
if (NS_SUCCEEDED(rv))
{
PRBool selectionCollapsed = PR_FALSE;
@@ -318,19 +393,13 @@ nsComposerCommandsUpdater::Notify(nsITimer *timer)
#endif
nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult)
nsresult
NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult)
{
nsComposerCommandsUpdater* newThang = new nsComposerCommandsUpdater;
if (!newThang)
return NS_ERROR_OUT_OF_MEMORY;
*aInstancePtrResult = nsnull;
nsresult rv = newThang->SetEditor(aEditor);
if (NS_FAILED(rv))
{
delete newThang;
return rv;
}
return newThang->QueryInterface(NS_GET_IID(nsISelectionListener), (void **)aInstancePtrResult);
return newThang->QueryInterface(NS_GET_IID(nsISelectionListener),
(void **)aInstancePtrResult);
}

View File

@@ -18,7 +18,9 @@
* Rights Reserved.
*
* Contributor(s):
* Simon Fraser <sfraser@netscape.com>
* Simon Fraser <sfraser@netscape.com>
* Michael Judge <mjudge@netscape.com>
* Charles Manske <cmanske@netscape.com>
*/
@@ -35,7 +37,6 @@
#include "nsIDocumentStateListener.h"
#include "nsITransactionListener.h"
class nsIEditor;
class nsIDocShell;
class nsITransactionManager;
@@ -80,7 +81,7 @@ public:
PRBool aDidMerge, nsresult aMergeResult);
nsresult SetEditor(nsIEditor* aEditor);
nsresult Init(nsIDOMWindow* aDOMWindow);
protected:
@@ -92,21 +93,15 @@ protected:
PRBool SelectionIsCollapsed();
nsresult UpdateDirtyState(PRBool aNowDirty);
nsresult CallUpdateCommands(const nsAString& aCommand);
nsresult UpdateOneCommand(const char* aCommand);
nsresult UpdateCommandGroup(const nsAString& aCommandGroup);
nsresult PrimeUpdateTimer();
void TimerCallback();
// this class should not hold references to the editor or editorShell. Doing
// so would result in cirular reference chains.
nsIEditor* mEditor; // the HTML editor
nsIDocShell* mDocShell;
nsCOMPtr<nsITimer> mUpdateTimer;
nsIDOMWindow* mDOMWindow; // Weak reference
nsIDocShell* mDocShell; // Weak reference
PRInt8 mDirtyState;
PRInt8 mSelectionCollapsed;
PRPackedBool mFirstDoOfFirstUndo;
@@ -114,7 +109,7 @@ protected:
};
extern "C" nsresult NS_NewComposerCommandsUpdater(nsIEditor* aEditor, nsISelectionListener** aInstancePtrResult);
extern "C" nsresult NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult);
#endif // nsComposerCommandsUpdater_h__

View File

@@ -40,89 +40,10 @@
* ***** END LICENSE BLOCK ***** */
#include "nsIComponentManager.h"
#include "nsIControllerCommandManager.h"
#include "nsComposerController.h"
#if 0
#include "nsIEditor.h"
#include "nsIEditorMailSupport.h"
#include "nsIFormControlFrame.h"
#include "nsISelection.h"
#include "nsIHTMLEditor.h"
#include "nsXPIDLString.h"
#include "nsISelectionController.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsEditorCommands.h"
#endif
#include "nsComposerCommands.h"
NS_IMPL_ADDREF(nsComposerController)
NS_IMPL_RELEASE(nsComposerController)
NS_INTERFACE_MAP_BEGIN(nsComposerController)
NS_INTERFACE_MAP_ENTRY(nsIController)
NS_INTERFACE_MAP_ENTRY(nsICommandController)
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
NS_INTERFACE_MAP_END
nsComposerController::nsComposerController()
{
NS_INIT_ISUPPORTS();
}
nsComposerController::~nsComposerController()
{
}
NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon)
{
nsresult rv;
// get our ref to the singleton command manager
// This will create mCommandManager and register commands if not already done.
rv = GetComposerCommandManager(getter_AddRefs(mCommandManager));
if (NS_FAILED(rv)) return rv;
mCommandRefCon = aCommandRefCon; // no addref
// the following (7?) lines can be removed when the JS commands are stateless and in C++
mCommandManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
// register the commands.
rv = nsComposerController::RegisterComposerCommands(mCommandManager);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
NS_IMETHODIMP
nsComposerController::SetCommandRefCon(nsISupports *aCommandRefCon)
{
mCommandRefCon = aCommandRefCon; // no addref
return NS_OK;
}
NS_IMETHODIMP
nsComposerController::GetInterface(const nsIID & aIID, void * *result)
{
NS_ENSURE_ARG_POINTER(result);
if (NS_SUCCEEDED(QueryInterface(aIID, result)))
return NS_OK;
if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
return mCommandManager->QueryInterface(aIID, result);
return NS_NOINTERFACE;
}
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
{ \
_cmdClass* theCmd; \
@@ -159,12 +80,29 @@ nsComposerController::GetInterface(const nsIID & aIID, void * *result)
// static
nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager)
nsresult
nsComposerController::RegisterEditorDocStateCommands(
nsIControllerCommandManager *inCommandManager)
{
nsresult rv;
// observer commands for document state
NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentCreated")
NS_REGISTER_ONE_COMMAND(nsDocumentStateCommand, "obs_documentWillBeDestroyed")
// commands that may get or change state
NS_REGISTER_ONE_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentModified")
return NS_OK;
}
// static
nsresult
nsComposerController::RegisterHTMLEditorCommands(
nsIControllerCommandManager *inCommandManager)
{
nsresult rv;
// Edit menu
NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
NS_REGISTER_ONE_COMMAND(nsPasteNoFormattingCommand, "cmd_pasteNoFormatting");
// indent/outdent
@@ -211,90 +149,8 @@ nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandMana
NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
// Insert content
NS_REGISTER_ONE_COMMAND(nsInsertHTMLCommand, "cmd_insertHTML");
return NS_OK;
}
/* =======================================================================
* nsIController
* ======================================================================= */
NS_IMETHODIMP
nsComposerController::IsCommandEnabled(const char * aCommand,
PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP
nsComposerController::SupportsCommand(const char * aCommand,
PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP
nsComposerController::DoCommand(const char *aCommand)
{
return mCommandManager->DoCommand(aCommand, mCommandRefCon);
}
NS_IMETHODIMP
nsComposerController::OnEvent(const char * aEventName)
{
return NS_OK;
}
nsWeakPtr nsComposerController::sComposerCommandManager = NULL;
// static
nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager)
{
NS_ENSURE_ARG_POINTER(outCommandManager);
nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sComposerCommandManager);
if (!cmdManager)
{
nsresult rv;
cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
// register the commands. This just happens once per instance
rv = nsComposerController::RegisterComposerCommands(cmdManager);
if (NS_FAILED(rv)) return rv;
// save the singleton in our static weak reference
sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
if (NS_FAILED(rv)) return rv;
}
NS_ADDREF(*outCommandManager = cmdManager);
return NS_OK;
}
// GetCommandStateWithParams
/*
cmd_bold,cmd_italic,cmd_underline ->state commands
state_start : true,false
state_end : true,false
state_all : true,false
state_mixed : true,false
*/
/* void getCommandStateWithParams (in DOMString aCommandName, inout nsICommandParams aCommandParams); */
NS_IMETHODIMP nsComposerController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aCommandParams)
{
if (!mCommandRefCon || !mCommandManager)
return NS_ERROR_NOT_INITIALIZED;
return mCommandManager->GetCommandState(aCommand,aCommandParams,mCommandRefCon);
}
/* void doCommandWithParams (in DOMString aCommandName, in nsICommandParams aCommandParams); */
NS_IMETHODIMP nsComposerController::DoCommandWithParams(const char *aCommand, nsICommandParams *aCommandParams)
{
if (!mCommandRefCon || !mCommandManager)
return NS_ERROR_NOT_INITIALIZED;
return mCommandManager->DoCommandParams(aCommand, aCommandParams,mCommandRefCon);
}

View File

@@ -39,66 +39,27 @@
#ifndef nsComposerController_h__
#define nsComposerController_h__
#define NS_COMPOSERCONTROLLER_CID \
{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
#include "nsString.h"
#include "nsIEditorController.h"
#include "nsIController.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIControllerCommand.h"
#include "nsIControllerCommandManager.h"
#include "nsWeakPtr.h"
class nsIControllerCommandManager;
// the editor controller is used for composer only (and other HTML compose
// areas). The refCon that gets passed to its commands is an nsIEditor.
class nsComposerController : public nsIController,
public nsICommandController,
public nsIEditorController,
public nsIInterfaceRequestor
// The plaintext editor controller is used for basic text editing and html editing
// commands in composer
// The refCon that gets passed to its commands is initially nsIEditingSession,
// and after successfule editor creation it is changed to nsIEditor.
#define NS_EDITORDOCSTATECONTROLLER_CID \
{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
// The HTMLEditor controller is used only for HTML editors and takes nsIEditor as refCon
#define NS_HTMLEDITORCONTROLLER_CID \
{ 0x62db0002, 0xdbb6, 0x43f4, { 0x8f, 0xb7, 0x9d, 0x25, 0x38, 0xbc, 0x57, 0x47 } }
class nsComposerController
{
public:
nsComposerController();
virtual ~nsComposerController();
// nsISupports
NS_DECL_ISUPPORTS
// nsIController
NS_DECL_NSICONTROLLER
/** init the controller */
NS_IMETHOD Init(nsISupports *aCommandRefCon);
/** Set the cookie that is passed to commands
*/
NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
// nsIInterfaceRequestor
NS_DECL_NSIINTERFACEREQUESTOR
//nsICommandController
NS_DECL_NSICOMMANDCONTROLLER
protected:
//if editor is null then look to mContent. this is for dual use of window and content
//attached controller.
nsISupports *mCommandRefCon;
nsCOMPtr<nsIControllerCommandManager> mCommandManager; // our reference to the command manager
private:
static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager);
static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager);
// the singleton command manager
static nsWeakPtr sComposerCommandManager; // common composer commands
static nsresult RegisterEditorDocStateCommands(nsIControllerCommandManager* inCommandManager);
static nsresult RegisterHTMLEditorCommands(nsIControllerCommandManager* inCommandManager);
};
#endif /* nsComposerController_h__ */

View File

@@ -20,6 +20,8 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Judge <mjudge@netscape.com>
* Charles Manske <cmanske@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -38,11 +40,11 @@
#include "nsIGenericFactory.h"
#include "nsEditorShell.h" // for the CID
#include "nsEditingSession.h" // for the CID
#include "nsComposerController.h" // for the CID
#include "nsEditorSpellCheck.h" // for the CID
#include "nsEditorService.h"
#include "nsIControllerContext.h"
////////////////////////////////////////////////////////////////////////
// Define the contructor function for the objects
@@ -50,25 +52,90 @@
// NOTE: This creates an instance of objects by using the default constructor
//
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck)
NS_IMETHODIMP nsEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static PRBool sDocStateCommandsRegistered = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIControllerCommandManager> composerCommandManager(
do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
if (!composerCommandManager)
return NS_ERROR_OUT_OF_MEMORY;
if (!sDocStateCommandsRegistered)
{
rv = nsComposerController::RegisterEditorDocStateCommands(composerCommandManager);
if (NS_FAILED(rv))
{
return rv;
}
sDocStateCommandsRegistered = PR_TRUE;
}
context->SetControllerCommandManager(composerCommandManager);
return context->QueryInterface(aIID, aResult);
}
NS_IMETHODIMP nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static PRBool sHTMLCommandsRegistered = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIControllerCommandManager> composerCommandManager(
do_GetService(NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
if (!composerCommandManager)
return NS_ERROR_OUT_OF_MEMORY;
if (!sHTMLCommandsRegistered)
{
rv = nsComposerController::RegisterHTMLEditorCommands(composerCommandManager);
if (NS_FAILED(rv))
{
return rv;
}
sHTMLCommandsRegistered = PR_TRUE;
}
context->SetControllerCommandManager(composerCommandManager);
return context->QueryInterface(aIID, aResult);
}
////////////////////////////////////////////////////////////////////////
// Define a table of CIDs implemented by this module along with other
// information like the function to create an instance, contractid, and
// class name.
//
static const nsModuleComponentInfo components[] = {
{ "Composer Controller", NS_COMPOSERCONTROLLER_CID,
"@mozilla.org/editor/composercontroller;1",
nsComposerControllerConstructor, },
{ "Editor Shell Component", NS_EDITORSHELL_CID,
"@mozilla.org/editor/editorshell;1", nsEditorShellConstructor, },
{ "Editor Shell Spell Checker", NS_EDITORSHELL_CID,
"@mozilla.org/editor/editorspellcheck;1", nsEditorShellConstructor, },
{ "Editor DocState Controller", NS_EDITORDOCSTATECONTROLLER_CID,
"@mozilla.org/editor/editordocstatecontroller;1",
nsEditorDocStateControllerConstructor, },
{ "HTML Editor Controller", NS_HTMLEDITORCONTROLLER_CID,
"@mozilla.org/editor/htmleditorcontroller;1",
nsHTMLEditorControllerConstructor, },
{ "Editing Session", NS_EDITINGSESSION_CID,
"@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, },
{ "Editor Service", NS_EDITORSERVICE_CID,

File diff suppressed because it is too large Load Diff

View File

@@ -46,6 +46,11 @@
#endif
#include "nsIEditor.h"
#include "nsITimer.h"
#ifndef __gen_nsIControllers_h__
#include "nsIControllers.h"
#endif
#ifndef __gen_nsIDocShell_h__
#include "nsIDocShell.h"
@@ -59,7 +64,7 @@
#include "nsIEditingSession.h"
#endif
#include "nsString.h"
#define NS_EDITINGSESSION_CID \
{ 0xbc26ff01, 0xf2bd, 0x11d4, { 0xa7, 0x3c, 0xe5, 0xa4, 0xb5, 0xa8, 0xbd, 0xfc } }
@@ -67,6 +72,12 @@
class nsIWebProgress;
class nsIEditorDocShell;
class nsIChannel;
#ifndef FULL_EDITOR_HTML_SUPPORT
class nsEditorParserObserver;
#endif
class nsComposerCommandsUpdater;
@@ -88,33 +99,60 @@ public:
// nsIEditingSession
NS_DECL_NSIEDITINGSESSION
protected:
nsresult GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell);
nsresult GetEditorDocShellFromWindow(nsIDOMWindow *inWindow, nsIEditorDocShell** outDocShell);
nsresult SetupFrameControllers(nsIDOMWindow *inWindow, PRBool aSetupComposerController);
nsresult GetDocShellFromWindow(nsIDOMWindow *aWindow,
nsIDocShell** outDocShell);
nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow,
nsIEditorDocShell** outDocShell);
nsresult SetEditorOnControllers(nsIDOMWindow *inWindow, nsIEditor* inEditor);
nsresult SetupEditorCommandController(const char *aControllerClassName,
nsIDOMWindow *aWindow,
nsISupports *aRefCon,
PRUint32 *aControllerId);
nsresult SetEditorOnControllers(nsIDOMWindow *aWindow,
nsIEditor* aEditor);
nsresult SetRefConOnControllerById(nsIControllers* aControllers,
nsISupports* aRefCon,
PRUint32 aID);
nsresult PrepareForEditing();
static void TimerCallback(nsITimer *aTimer, void *aClosure);
nsCOMPtr<nsITimer> mLoadBlankDocTimer;
// progress load stuff
nsresult StartDocumentLoad(nsIWebProgress *aWebProgress);
nsresult EndDocumentLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus);
nsresult StartPageLoad(nsIWebProgress *aWebProgress);
nsresult EndPageLoad(nsIWebProgress *aWebProgress, nsIChannel* aChannel, nsresult aStatus);
nsresult EndDocumentLoad(nsIWebProgress *aWebProgress,
nsIChannel* aChannel, nsresult aStatus);
nsresult StartPageLoad(nsIChannel *aChannel);
nsresult EndPageLoad(nsIWebProgress *aWebProgress,
nsIChannel* aChannel, nsresult aStatus);
PRBool NotifyingCurrentDocument(nsIWebProgress *aWebProgress);
protected:
nsWeakPtr mEditingShell; // weak ptr back to our editing (web) shell. It owns us.
PRBool mDoneSetup; // have we prepared for editing yet?
nsWeakPtr mEditingShell;// weak ptr to the editing (web) shell that owns us
PRBool mDoneSetup; // have we prepared for editing yet?
nsComposerCommandsUpdater *mStateMaintainer; // we hold the owning ref to this.
const char * mEditorClassString; //we need this to hold onto the type for invoking editor after loading uri
// Used to prevent double creation of editor because nsIWebProgressListener
// receives a STATE_STOP notification before the STATE_START
// for our document, so we wait for the STATE_START, then STATE_STOP
// before creating an editor
PRBool mCanCreateEditor;
// THE REMAINING MEMBER VARIABLES WILL BECOME A SET WHEN WE EDIT
// MORE THAN ONE EDITOR PER EDITING SESSION
nsCOMPtr<nsISupports> mStateMaintainer; // we hold the owning ref to this
// Save the editor type so we can create the editor after loading uri
nsCString mEditorType;
PRUint32 mEditorFlags;
PRUint32 mEditorStatus;
PRUint32 mBaseCommandControllerId;
PRUint32 mDocStateControllerId;
PRUint32 mHTMLCommandControllerId;
};

View File

@@ -42,62 +42,10 @@
#include "nsIComponentManager.h"
#include "nsEditorController.h"
#include "nsIEditor.h"
#include "nsEditorCommands.h"
#include "nsIControllerCommandManager.h"
NS_IMPL_ADDREF(nsEditorController)
NS_IMPL_RELEASE(nsEditorController)
NS_INTERFACE_MAP_BEGIN(nsEditorController)
NS_INTERFACE_MAP_ENTRY(nsIController)
NS_INTERFACE_MAP_ENTRY(nsICommandController)
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
NS_INTERFACE_MAP_END
nsEditorController::nsEditorController()
: mCommandRefCon(nsnull)
{
NS_INIT_ISUPPORTS();
}
nsEditorController::~nsEditorController()
{
}
NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon)
{
nsresult rv;
// get our ref to the singleton command manager
rv = GetEditorCommandManager(getter_AddRefs(mCommandManager));
if (NS_FAILED(rv)) return rv;
mCommandRefCon = aCommandRefCon; // no addref
return NS_OK;
}
NS_IMETHODIMP nsEditorController::SetCommandRefCon(nsISupports *aCommandRefCon)
{
mCommandRefCon = aCommandRefCon; // no addref
return NS_OK;
}
NS_IMETHODIMP nsEditorController::GetInterface(const nsIID & aIID, void * *result)
{
NS_ENSURE_ARG_POINTER(result);
if (NS_SUCCEEDED(QueryInterface(aIID, result)))
return NS_OK;
if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
return mCommandManager->QueryInterface(aIID, result);
return NS_NOINTERFACE;
}
#define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
{ \
@@ -184,70 +132,12 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageUp");
NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown");
return NS_OK;
}
// Insert content
NS_REGISTER_ONE_COMMAND(nsInsertPlaintextCommand, "cmd_insertText");
NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
/* =======================================================================
* nsIController
* ======================================================================= */
NS_IMETHODIMP nsEditorController::IsCommandEnabled(const char *aCommand, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::SupportsCommand(const char *aCommand, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::DoCommand(const char *aCommand)
{
return mCommandManager->DoCommand(aCommand, mCommandRefCon);
}
NS_IMETHODIMP nsEditorController::DoCommandWithParams(const char *aCommand, nsICommandParams *aParams)
{
return mCommandManager->DoCommandParams(aCommand, aParams, mCommandRefCon);
}
NS_IMETHODIMP nsEditorController::GetCommandStateWithParams(const char *aCommand, nsICommandParams *aParams)
{
return mCommandManager->GetCommandState(aCommand, aParams, mCommandRefCon);
}
NS_IMETHODIMP nsEditorController::OnEvent(const char * aEventName)
{
return NS_OK;
}
nsWeakPtr nsEditorController::sEditorCommandManager = NULL;
// static
nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager)
{
NS_ENSURE_ARG_POINTER(outCommandManager);
nsCOMPtr<nsIControllerCommandManager> cmdManager = do_QueryReferent(sEditorCommandManager);
if (!cmdManager)
{
nsresult rv;
cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
// register the commands. This just happens once per instance
rv = nsEditorController::RegisterEditorCommands(cmdManager);
if (NS_FAILED(rv)) return rv;
// save the singleton in our static weak reference
sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
if (NS_FAILED(rv)) return rv;
}
NS_ADDREF(*outCommandManager = cmdManager);
return NS_OK;
}

View File

@@ -42,69 +42,16 @@
#define NS_EDITORCONTROLLER_CID \
{ 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } }
#include "nsIController.h"
#include "nsIEditorController.h"
#include "nsIControllerCommand.h"
#include "nsIControllerCommandManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsWeakPtr.h"
class nsIEditor;
class nsIControllerCommandManager;
// the editor controller is used for both text widgets, and basic text editing
// commands in composer. The refCon that gets passed to its commands is an nsIEditor.
class nsEditorController : public nsIController,
public nsIEditorController,
public nsIInterfaceRequestor,
public nsICommandController
class nsEditorController
{
public:
nsEditorController();
virtual ~nsEditorController();
// nsISupports
NS_DECL_ISUPPORTS
// nsIController
NS_DECL_NSICONTROLLER
// nsICommandController
NS_DECL_NSICOMMANDCONTROLLER
/** init the controller */
NS_IMETHOD Init(nsISupports *aCommandRefCon);
/** Set the cookie that is passed to commands
*/
NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
// nsIInterfaceRequestor
NS_DECL_NSIINTERFACEREQUESTOR
protected:
//if editor is null then look to mContent. this is for dual use of window and content
//attached controller.
nsISupports *mCommandRefCon;
nsCOMPtr<nsIControllerCommandManager> mCommandManager; // our reference to the command manager
private:
static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager);
static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager);
// the singleton command manager
static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands
};
#endif /* nsEditorController_h__ */

View File

@@ -20,6 +20,8 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Judge <mjudge@netscape.com>
* Charles Manske <cmanske@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -47,6 +49,9 @@
#include "nsTextServicesDocument.h"
#include "nsTextServicesCID.h"
#include "nsIControllerContext.h"
#include "nsIServiceManager.h"
////////////////////////////////////////////////////////////////////////
// Define the contructor function for the objects
@@ -55,9 +60,42 @@
//
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPlaintextEditor)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTextServicesDocument)
NS_IMETHODIMP nsEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static PRBool commandsRegistered = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIControllerContext> context =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1",&rv);
if (NS_FAILED(rv))
return rv;
if (!context)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIControllerCommandManager> editorCommandManager(
do_GetService(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
if (!editorCommandManager)
return NS_ERROR_OUT_OF_MEMORY;
if (!commandsRegistered)
{
rv = nsEditorController::RegisterEditorCommands(editorCommandManager);
if (NS_FAILED(rv))
{
return rv;
}
commandsRegistered = PR_TRUE;
}
context->SetControllerCommandManager(editorCommandManager);
return context->QueryInterface(aIID, aResult);
}
#ifdef ENABLE_EDITOR_API_LOG
#include "nsHTMLEditorLog.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLEditorLog)

View File

@@ -1115,6 +1115,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBaseCommandController.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPrintDialogExtension.r</PATH>
@@ -1244,6 +1251,11 @@
<PATH>nsControllerCommandManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBaseCommandController.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPrintDialogExtension.r</PATH>
@@ -2313,6 +2325,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBaseCommandController.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS>Debug</FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPrintDialogExtension.r</PATH>
@@ -2442,6 +2461,11 @@
<PATH>nsControllerCommandManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBaseCommandController.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsPrintDialogExtension.r</PATH>
@@ -2498,6 +2522,12 @@
<PATH>nsControllerCommandManager.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>EmbedComponentsDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsBaseCommandController.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>WindowWatcher</NAME>
<FILEREF>

View File

@@ -828,6 +828,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerContext.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerCommand.idl</PATH>
@@ -928,6 +935,11 @@
<PATH>nsPICommandUpdater.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerContext.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerCommand.idl</PATH>
@@ -1725,6 +1737,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerContext.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerCommand.idl</PATH>
@@ -1825,6 +1844,11 @@
<PATH>nsPICommandUpdater.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerContext.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerCommand.idl</PATH>
@@ -1945,6 +1969,12 @@
<PATH>nsPICommandUpdater.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIControllerContext.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>headers</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@@ -50,6 +50,7 @@
#include "nsCommandParams.h"
#include "nsCommandGroup.h"
#include "nsPrintingPromptService.h"
#include "nsBaseCommandController.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPromptService, Init)
@@ -64,6 +65,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandManager)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCommandParams, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseCommandController)
static const nsModuleComponentInfo gComponents[] = {
@@ -76,9 +78,11 @@ static const nsModuleComponentInfo gComponents[] = {
{ NS_APPSTARTUPNOTIFIER_CLASSNAME, NS_APPSTARTUPNOTIFIER_CID, NS_APPSTARTUPNOTIFIER_CONTRACTID, nsAppStartupNotifierConstructor },
{ "WebBrowserPersist Component", NS_WEBBROWSERPERSIST_CID, NS_WEBBROWSERPERSIST_CONTRACTID, nsWebBrowserPersistConstructor },
{ "Controller Command Manager", NS_CONTROLLERCOMMANDMANAGER_CID, NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, nsControllerCommandManagerConstructor },
{ "Composers Controller Command Manager", NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CID, NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID, nsControllerCommandManagerConstructor },
{ "Command Manager", NS_COMMAND_MANAGER_CID, NS_COMMAND_MANAGER_CONTRACTID, nsCommandManagerConstructor },
{ "Command Params", NS_COMMAND_PARAMS_CID, NS_COMMAND_PARAMS_CONTRACTID, nsCommandParamsConstructor },
{ "Command Group", NS_CONTROLLER_COMMAND_GROUP_CID, NS_CONTROLLER_COMMAND_GROUP_CONTRACTID, nsControllerCommandGroupConstructor },
{ "Base Command Controller", NS_BASECOMMANDCONTROLLER_CID, NS_BASECOMMANDCONTROLLER_CONTRACTID, nsBaseCommandControllerConstructor },
{ "Printing Prompt Service", NS_PRINTINGPROMPTSERVICE_CID, NS_PRINTINGPROMPTSERVICE_CONTRACTID, nsPrintingPromptServiceConstructor }
};

View File

@@ -2,4 +2,5 @@ nsICommandManager.idl
nsPICommandUpdater.idl
nsICommandParams.idl
nsIControllerCommand.idl
nsIControllerCommandManager.idl
nsIControllerContext.idl
nsIControllerCommandManager.idl

View File

@@ -33,6 +33,7 @@ XPIDLSRCS = \
nsICommandManager.idl \
nsICommandParams.idl \
nsIControllerCommand.idl \
nsIControllerContext.idl \
nsIControllerCommandManager.idl \
nsPICommandUpdater.idl \
$(NULL)

View File

@@ -135,8 +135,8 @@ interface nsICommandManager : nsISupports
Arguments to observers "Observe" method are as follows:
void Observe( in nsISupports aSubject, // The nsICommandManager calling this Observer
in string aTopic, // Unused
in wstring aDummy ); // Name of the command
in string aTopic, // Name of the command
in wstring aDummy ); // unused
*/

View File

@@ -102,4 +102,8 @@ interface nsIControllerCommandManager : nsISupports
#define NS_CONTROLLERCOMMANDMANAGER_CONTRACTID \
"@mozilla.org/embedcomp/controller-command-manager;1"
#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CONTRACTID \
"@mozilla.org/embedcomp/composers-controller-command-manager;1"
#define NS_COMPOSERSCONTROLLERCOMMANDMANAGER_CID \
{ 0xb0e54f80, 0xc274, 0x4765, { 0x9e, 0x36, 0xd0, 0x0a, 0xcd, 0x38, 0x92, 0x9c } }
%}

View File

@@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Judge <mjudge@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIControllerCommandManager.idl"
[scriptable, uuid(47B82B60-A36F-4167-8072-6F421151ED50)]
interface nsIControllerContext : nsISupports
{
/**
* Set the cookie that is passed to commands
* Note that the commandRefCon is *not* addreffed
* and thus it needs to outlive the controller
*/
void setCommandRefCon(in nsISupports commandRefCon);
/**
* Set the command manager. This will have the effect of making the manager immutable
*/
void setControllerCommandManager(in nsIControllerCommandManager commandManager);
};

View File

@@ -40,6 +40,7 @@ REQUIRES = string \
LIBRARY_NAME = commandhandler_s
CPPSRCS = \
nsBaseCommandController.cpp \
nsCommandGroup.cpp \
nsCommandManager.cpp \
nsCommandParams.cpp \

View File

@@ -0,0 +1,160 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsString.h"
#include "nsIComponentManager.h"
#include "nsBaseCommandController.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsWeakPtr.h"
NS_IMPL_ADDREF(nsBaseCommandController)
NS_IMPL_RELEASE(nsBaseCommandController)
NS_INTERFACE_MAP_BEGIN(nsBaseCommandController)
NS_INTERFACE_MAP_ENTRY(nsIController)
NS_INTERFACE_MAP_ENTRY(nsICommandController)
NS_INTERFACE_MAP_ENTRY(nsIControllerContext)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllerContext)
NS_INTERFACE_MAP_END
nsBaseCommandController::nsBaseCommandController()
: mCommandRefCon(nsnull), mImmutableManager(PR_FALSE)
{
NS_INIT_ISUPPORTS();
nsresult rv;
mCommandManager =
do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to create CommandManager in nsBaseCommandController");
}
nsBaseCommandController::~nsBaseCommandController()
{
}
NS_IMETHODIMP
nsBaseCommandController::SetCommandRefCon(nsISupports *aCommandRefCon)
{
mCommandRefCon = aCommandRefCon; // no addref
return NS_OK;
}
NS_IMETHODIMP
nsBaseCommandController::SetControllerCommandManager(
nsIControllerCommandManager *aCommandManager)
{
if (!aCommandManager)
return NS_ERROR_NULL_POINTER;
mCommandManager = aCommandManager;
mImmutableManager = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsBaseCommandController::GetInterface(const nsIID & aIID, void * *result)
{
NS_ENSURE_ARG_POINTER(result);
if (NS_SUCCEEDED(QueryInterface(aIID, result)))
return NS_OK;
// Don't let users get the command manager if it's
// immutable. They may harm it in some way.
if (!mImmutableManager && mCommandManager &&
aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
return mCommandManager->QueryInterface(aIID, result);
return NS_NOINTERFACE;
}
/* =======================================================================
* nsIController
* ======================================================================= */
NS_IMETHODIMP
nsBaseCommandController::IsCommandEnabled(const char *aCommand,
PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aCommand);
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP
nsBaseCommandController::SupportsCommand(const char *aCommand, PRBool *aResult)
{
NS_ENSURE_ARG_POINTER(aCommand);
NS_ENSURE_ARG_POINTER(aResult);
return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP
nsBaseCommandController::DoCommand(const char *aCommand)
{
NS_ENSURE_ARG_POINTER(aCommand);
return mCommandManager->DoCommand(aCommand, mCommandRefCon);
}
NS_IMETHODIMP
nsBaseCommandController::DoCommandWithParams(const char *aCommand,
nsICommandParams *aParams)
{
NS_ENSURE_ARG_POINTER(aCommand);
return mCommandManager->DoCommandParams(aCommand, aParams, mCommandRefCon);
}
NS_IMETHODIMP
nsBaseCommandController::GetCommandStateWithParams(const char *aCommand,
nsICommandParams *aParams)
{
NS_ENSURE_ARG_POINTER(aCommand);
return mCommandManager->GetCommandState(aCommand, aParams, mCommandRefCon);
}
NS_IMETHODIMP
nsBaseCommandController::OnEvent(const char * aEventName)
{
NS_ENSURE_ARG_POINTER(aEventName);
return NS_OK;
}

View File

@@ -0,0 +1,99 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Michael Judge <mjudge@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsBaseCommandController_h__
#define nsBaseCommandController_h__
#define NS_BASECOMMANDCONTROLLER_CID \
{ 0xbf88b48c, 0xfd8e, 0x40b4, { 0xba, 0x36, 0xc7, 0xc3, 0xad, 0x6d, 0x8a, 0xc9 } }
#define NS_BASECOMMANDCONTROLLER_CONTRACTID \
"@mozilla.org/embedcomp/base-command-controller;1"
#include "nsIController.h"
#include "nsIControllerContext.h"
#include "nsIControllerCommand.h"
#include "nsIControllerCommandManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
//#include "nsHashtable.h"
//#include "nsString.h"
//#include "nsWeakPtr.h"
// The base editor controller is used for both text widgets,
// and all other text and html editing
class nsBaseCommandController : public nsIController,
public nsIControllerContext,
public nsIInterfaceRequestor,
public nsICommandController
{
public:
nsBaseCommandController();
virtual ~nsBaseCommandController();
// nsISupports
NS_DECL_ISUPPORTS
// nsIController
NS_DECL_NSICONTROLLER
// nsICommandController
NS_DECL_NSICOMMANDCONTROLLER
//nsIControllerContext
NS_DECL_NSICONTROLLERCONTEXT
// nsIInterfaceRequestor
NS_DECL_NSIINTERFACEREQUESTOR
private:
nsISupports *mCommandRefCon;
// Our reference to the command manager
nsCOMPtr<nsIControllerCommandManager> mCommandManager;
PRBool mImmutableManager;
};
#endif /* nsBaseCommandController_h_ */

View File

@@ -62,8 +62,6 @@ public:
protected:
nsSupportsHashtable mCommandsTable; // hash table of nsIControllerCommands, keyed by command name
};

View File

@@ -55,7 +55,7 @@
#include "nsISelectionPrivate.h"
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIEditorController.h"
#include "nsIControllerContext.h"
#include "nsIElementFactory.h"
#include "nsIHTMLContent.h"
#include "nsIEditorIMESupport.h"
@@ -1412,7 +1412,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
if (NS_SUCCEEDED(rv) && controller)
{
nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller);
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(nsnull);
@@ -1978,7 +1978,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
if (NS_SUCCEEDED(rv) && controller)
{
nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller);
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(mEditor);

View File

@@ -50,6 +50,7 @@ REQUIRES = xpcom \
accessibility \
xpconnect \
unicharutil \
commandhandler \
$(NULL)
CPPSRCS = \

View File

@@ -55,7 +55,7 @@
#include "nsISelectionPrivate.h"
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIEditorController.h"
#include "nsIControllerContext.h"
#include "nsIElementFactory.h"
#include "nsIHTMLContent.h"
#include "nsIEditorIMESupport.h"
@@ -1412,7 +1412,7 @@ nsTextControlFrame::PreDestroy(nsIPresContext* aPresContext)
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
if (NS_SUCCEEDED(rv) && controller)
{
nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller);
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(nsnull);
@@ -1978,7 +1978,7 @@ nsTextControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext,
rv = controllers->GetControllerAt(i, getter_AddRefs(controller));
if (NS_SUCCEEDED(rv) && controller)
{
nsCOMPtr<nsIEditorController> editController = do_QueryInterface(controller);
nsCOMPtr<nsIControllerContext> editController = do_QueryInterface(controller);
if (editController)
{
editController->SetCommandRefCon(mEditor);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 125 B