From 40f7d1b02ed0123a5f9abbec366266ff49f1398c Mon Sep 17 00:00:00 2001 From: "mjudge%netscape.com" Date: Sat, 2 Feb 2002 05:13:56 +0000 Subject: [PATCH] 115922 embedding work. no changes should be observed in current product this will only affect the embedded effort. This moves the command handler stuff from content xul to embedding/components/commandhandler. a=judd r=saari built on mac/windows/gmake with this we will be able to finish removing editorshell from the app and have a true embedded editor.akkana will pick this up after me and finish the embedding work. git-svn-id: svn://10.0.0.236/trunk@113507 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/build/nsContentModule.cpp | 7 - mozilla/content/macbuild/content.xml | 4 +- mozilla/content/macbuild/contentIDL.xml | 34 +- .../content/xul/document/public/MANIFEST_IDL | 1 - .../content/xul/document/public/Makefile.in | 1 - .../content/xul/document/public/makefile.win | 1 - .../xul/document/public/nsIController.idl | 46 + mozilla/content/xul/document/src/Makefile.in | 2 +- mozilla/content/xul/document/src/makefile.win | 2 +- .../document/src/nsControllerCommandManager.h | 2 +- mozilla/docshell/base/MANIFEST_IDL | 1 + mozilla/docshell/base/Makefile.in | 5 + mozilla/docshell/base/makefile.win | 5 + mozilla/docshell/base/nsDocShell.cpp | 88 ++ mozilla/docshell/base/nsDocShell.h | 8 + mozilla/docshell/base/nsWebShell.cpp | 29 + mozilla/docshell/base/nsWebShell.h | 4 + mozilla/docshell/build/Makefile.in | 3 + mozilla/docshell/build/makefile.win | 3 + mozilla/docshell/macbuild/docshell.xml | 34 +- mozilla/docshell/macbuild/docshellIDL.xml | 34 +- mozilla/editor/composer/Makefile.in | 2 +- mozilla/editor/composer/makefile.win | 2 +- mozilla/editor/composer/src/Makefile.in | 3 + mozilla/editor/composer/src/makefile.win | 3 + .../composer/src/nsComposerCommands.cpp | 887 +++++++++++++++++- .../editor/composer/src/nsComposerCommands.h | 41 +- .../composer/src/nsComposerController.cpp | 29 +- .../composer/src/nsComposerController.h | 7 +- .../composer/src/nsComposerRegistration.cpp | 4 + mozilla/editor/libeditor/base/Makefile.in | 1 + mozilla/editor/libeditor/base/makefile.win | 1 + .../libeditor/base/nsEditorCommands.cpp | 181 ++++ .../editor/libeditor/base/nsEditorCommands.h | 2 + .../libeditor/base/nsEditorController.cpp | 2 +- .../libeditor/base/nsEditorController.h | 1 + mozilla/editor/libeditor/build/Makefile.in | 1 + mozilla/editor/libeditor/build/makefile.win | 1 + mozilla/editor/macbuild/EditorIDL.xml | 54 +- mozilla/editor/macbuild/composer.xml | 64 +- mozilla/editor/macbuild/editor.xml | 20 +- mozilla/embedding/components/Makefile.in | 2 +- .../embedding/components/build/Makefile.in | 4 + .../build/macbuild/EmbedComponents.xml | 126 ++- .../build/macbuild/EmbedComponentsIDL.xml | 124 ++- .../embedding/components/build/makefile.win | 4 + .../embedding/components/build/nsModule.cpp | 16 +- .../commandhandler/public/MANIFEST_IDL | 2 + mozilla/embedding/components/makefile.win | 1 + .../embedding/tests/mfcembed/BrowserFrm.cpp | 127 ++- mozilla/embedding/tests/mfcembed/BrowserFrm.h | 13 + .../embedding/tests/mfcembed/BrowserImpl.cpp | 124 +++ .../embedding/tests/mfcembed/BrowserImpl.h | 13 + mozilla/embedding/tests/mfcembed/Makefile.in | 3 + mozilla/embedding/tests/mfcembed/MfcEmbed.cpp | 7 +- mozilla/embedding/tests/mfcembed/MfcEmbed.h | 2 +- mozilla/embedding/tests/mfcembed/MfcEmbed.rc | 48 +- mozilla/embedding/tests/mfcembed/makefile.win | 3 + mozilla/embedding/tests/mfcembed/mfcembed.dsp | 48 + mozilla/embedding/tests/mfcembed/resource.h | 11 +- 60 files changed, 2185 insertions(+), 113 deletions(-) diff --git a/mozilla/content/build/nsContentModule.cpp b/mozilla/content/build/nsContentModule.cpp index 2ad3946254d..21032d634fd 100644 --- a/mozilla/content/build/nsContentModule.cpp +++ b/mozilla/content/build/nsContentModule.cpp @@ -65,7 +65,6 @@ #include "nsIContentIterator.h" #include "nsIContentSerializer.h" #include "nsIController.h" -#include "nsIControllerCommand.h" #include "nsIControllers.h" #include "nsIDOMDOMImplementation.h" #include "nsIDOMRange.h" @@ -354,7 +353,6 @@ MAKE_CTOR(CreateXULElementFactory, nsIElementFactory, NS_NewXUL #ifdef MOZ_SVG MAKE_CTOR(CreateSVGElementFactory, nsIElementFactory, NS_NewSVGElementFactory) #endif -MAKE_CTOR(CreateControllerCommandManager, nsIControllerCommandManager, NS_NewControllerCommandManager) NS_GENERIC_FACTORY_CONSTRUCTOR(nsContentHTTPStartup) MAKE_CTOR(CreateContentDLF, nsIDocumentLoaderFactory, NS_NewContentDocumentLoaderFactory) NS_GENERIC_FACTORY_CONSTRUCTOR(nsCSSOMFactory) @@ -792,11 +790,6 @@ static const nsModuleComponentInfo gComponents[] = { CreateSVGElementFactory }, #endif - { "Controller Command Manager", - NS_CONTROLLERCOMMANDMANAGER_CID, - "@mozilla.org/content/controller-command-manager;1", - CreateControllerCommandManager }, - { "Content HTTP Startup Listener", NS_CONTENTHTTPSTARTUP_CID, NS_CONTENTHTTPSTARTUP_CONTRACTID, diff --git a/mozilla/content/macbuild/content.xml b/mozilla/content/macbuild/content.xml index 5d07adab84e..547f3b873c8 100644 --- a/mozilla/content/macbuild/content.xml +++ b/mozilla/content/macbuild/content.xml @@ -507,7 +507,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2635rsan635rae2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -3948,7 +3948,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2635rsan635rae2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 diff --git a/mozilla/content/macbuild/contentIDL.xml b/mozilla/content/macbuild/contentIDL.xml index 2a416115218..7f48404229a 100644 --- a/mozilla/content/macbuild/contentIDL.xml +++ b/mozilla/content/macbuild/contentIDL.xml @@ -347,7 +347,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jysun5jyay2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -834,13 +834,6 @@ Text - - Name - nsIControllerCommand.idl - MacOS - Text - - Name nsIControllers.idl @@ -952,11 +945,6 @@ nsIController.idl MacOS - - Name - nsIControllerCommand.idl - MacOS - Name nsIControllers.idl @@ -1288,7 +1276,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jysun5jyay2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -1775,13 +1763,6 @@ Text - - Name - nsIControllerCommand.idl - MacOS - Text - - Name nsIControllers.idl @@ -1893,11 +1874,6 @@ nsIController.idl MacOS - - Name - nsIControllerCommand.idl - MacOS - Name nsIControllers.idl @@ -2015,12 +1991,6 @@ nsIController.idl MacOS - - headers - Name - nsIControllerCommand.idl - MacOS - headers Name diff --git a/mozilla/content/xul/document/public/MANIFEST_IDL b/mozilla/content/xul/document/public/MANIFEST_IDL index 009388fa38f..a16b53f6b70 100644 --- a/mozilla/content/xul/document/public/MANIFEST_IDL +++ b/mozilla/content/xul/document/public/MANIFEST_IDL @@ -1,3 +1,2 @@ nsIController.idl -nsIControllerCommand.idl nsIControllers.idl diff --git a/mozilla/content/xul/document/public/Makefile.in b/mozilla/content/xul/document/public/Makefile.in index 1768d304574..3766c32dd72 100644 --- a/mozilla/content/xul/document/public/Makefile.in +++ b/mozilla/content/xul/document/public/Makefile.in @@ -31,7 +31,6 @@ MODULE = xuldoc XPIDLSRCS = \ nsIController.idl \ nsIControllers.idl \ - nsIControllerCommand.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/content/xul/document/public/makefile.win b/mozilla/content/xul/document/public/makefile.win index ac18534617c..2b21692045b 100644 --- a/mozilla/content/xul/document/public/makefile.win +++ b/mozilla/content/xul/document/public/makefile.win @@ -28,7 +28,6 @@ DEPTH=..\..\..\.. XPIDLSRCS = \ .\nsIController.idl \ .\nsIControllers.idl \ - .\nsIControllerCommand.idl \ $(NULL) EXPORTS = \ diff --git a/mozilla/content/xul/document/public/nsIController.idl b/mozilla/content/xul/document/public/nsIController.idl index 899180c4c07..3debd730f25 100644 --- a/mozilla/content/xul/document/public/nsIController.idl +++ b/mozilla/content/xul/document/public/nsIController.idl @@ -47,3 +47,49 @@ interface nsIController : nsISupports { void onEvent(in DOMString eventName); }; + + +/* + + Enhanced controller interface that allows for passing of parameters + to commands. + +*/ + +interface nsICommandParams; + +[scriptable, uuid(EBE55080-C8A9-11D5-A73C-DD620D6E04BC)] +interface nsICommandController : nsISupports +{ + + void getCommandState( in nsICommandParams aCommandParams); + + void doCommand(in nsICommandParams aCommandParams); + +}; + + +/* + An API for registering commands in groups, to allow for + updating via nsIDOMWindowInternal::UpdateCommands. +*/ +interface nsISimpleEnumerator; + +[scriptable, uuid(9F82C404-1C7B-11D5-A73C-ECA43CA836FC)] +interface nsIControllerCommandGroup : nsISupports +{ + + void addCommandToGroup(in DOMString aCommand, in DOMString aGroup); + void removeCommandFromGroup(in DOMString aCommand, in DOMString aGroup); + + boolean isCommandInGroup(in DOMString aCommand, in DOMString aGroup); + + /* + We should expose some methods that allow for enumeration. + */ + nsISimpleEnumerator getGroupsEnumerator(); + + nsISimpleEnumerator getEnumeratorForGroup(in DOMString aGroup); + +}; + diff --git a/mozilla/content/xul/document/src/Makefile.in b/mozilla/content/xul/document/src/Makefile.in index 938772b808b..e9e3bfe582f 100644 --- a/mozilla/content/xul/document/src/Makefile.in +++ b/mozilla/content/xul/document/src/Makefile.in @@ -55,10 +55,10 @@ REQUIRES = xpcom \ webshell \ webbrwsr \ unicharutil \ + commandhandler \ $(NULL) CPPSRCS = \ - nsControllerCommandManager.cpp \ nsElementMap.cpp \ nsXULCommandDispatcher.cpp \ nsXULContentSink.cpp \ diff --git a/mozilla/content/xul/document/src/makefile.win b/mozilla/content/xul/document/src/makefile.win index 8cb12f0cd87..a86c767c4ca 100644 --- a/mozilla/content/xul/document/src/makefile.win +++ b/mozilla/content/xul/document/src/makefile.win @@ -49,12 +49,12 @@ REQUIRES = xpcom \ webshell \ webBrowser_core \ unicharutil \ + commandhandler \ $(NULL) DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN CPP_OBJS= \ - .\$(OBJDIR)\nsControllerCommandManager.obj \ .\$(OBJDIR)\nsElementMap.obj \ .\$(OBJDIR)\nsXULCommandDispatcher.obj \ .\$(OBJDIR)\nsXULContentSink.obj \ diff --git a/mozilla/content/xul/document/src/nsControllerCommandManager.h b/mozilla/content/xul/document/src/nsControllerCommandManager.h index b2330d3babc..58873c0e51c 100644 --- a/mozilla/content/xul/document/src/nsControllerCommandManager.h +++ b/mozilla/content/xul/document/src/nsControllerCommandManager.h @@ -39,7 +39,7 @@ #ifndef nsControllerCommandManager_h_ #define nsControllerCommandManager_h_ - +#include "nsIControllerCommandManager.h" #include "nsIControllerCommand.h" #include "nsWeakReference.h" #include "nsHashtable.h" diff --git a/mozilla/docshell/base/MANIFEST_IDL b/mozilla/docshell/base/MANIFEST_IDL index 457b627a079..13a5a0c9c55 100644 --- a/mozilla/docshell/base/MANIFEST_IDL +++ b/mozilla/docshell/base/MANIFEST_IDL @@ -34,3 +34,4 @@ nsIContentViewer.idl nsIContentViewerEdit.idl nsIContentViewerFile.idl nsIURIFixup.idl +nsIEditorDocShell.idl \ No newline at end of file diff --git a/mozilla/docshell/base/Makefile.in b/mozilla/docshell/base/Makefile.in index ad30e498ffb..abe28293f04 100644 --- a/mozilla/docshell/base/Makefile.in +++ b/mozilla/docshell/base/Makefile.in @@ -58,6 +58,9 @@ REQUIRES = xpcom \ xuldoc \ find \ nkcache \ + composer \ + commandhandler \ + editor \ $(NULL) XPIDLSRCS = \ @@ -77,12 +80,14 @@ XPIDLSRCS = \ nsIContentViewerEdit.idl \ nsIContentViewerFile.idl \ nsIURIFixup.idl \ + nsIEditorDocShell.idl \ $(NULL) CPPSRCS = \ nsDocShell.cpp \ nsWebShell.cpp \ nsDocShellLoadInfo.cpp \ + nsDocShellEditorData.cpp \ nsDocShellEnumerator.cpp \ nsDSURIContentListener.cpp \ nsDefaultURIFixup.cpp \ diff --git a/mozilla/docshell/base/makefile.win b/mozilla/docshell/base/makefile.win index 426f03a5fd7..3aac8caae4b 100644 --- a/mozilla/docshell/base/makefile.win +++ b/mozilla/docshell/base/makefile.win @@ -50,6 +50,9 @@ REQUIRES = xpcom \ content \ gfx \ history \ + composer \ + commandhandler \ + editor \ $(NULL) LIBRARY_NAME=basedocshell_s @@ -71,10 +74,12 @@ XPIDLSRCS= \ .\nsITextScroll.idl \ .\nsIWebNavigation.idl \ .\nsIURIFixup.idl \ + .\nsIEditorDocShell.idl \ $(NULL) CPP_OBJS= \ .\$(OBJDIR)\nsDocShell.obj \ + .\$(OBJDIR)\nsDocShellEditorData.obj \ .\$(OBJDIR)\nsWebShell.obj \ .\$(OBJDIR)\nsDocShellEnumerator.obj \ .\$(OBJDIR)\nsDocShellLoadInfo.obj \ diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index dc3fd88ada4..36de816c809 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -78,6 +78,9 @@ #include "nsIPrincipal.h" #include "nsIHistoryEntry.h" +// Editor-related +#include "nsIEditingSession.h" + #include "nsPIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsICachingChannel.h" @@ -265,6 +268,7 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell) NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer) + NS_INTERFACE_MAP_ENTRY(nsIEditorDocShell) NS_INTERFACE_MAP_END_THREADSAFE ///***************************************************************************** @@ -363,6 +367,18 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID & aIID, void **aSink) NS_ADDREF((nsISupports*)*aSink); return NS_OK; } + else if (aIID.Equals(NS_GET_IID(nsIEditingSession)) && NS_SUCCEEDED(EnsureEditorData())) { + nsCOMPtr editingSession; + mEditorData->GetEditingSession(getter_AddRefs(editingSession)); + if (editingSession) + { + *aSink = editingSession; + NS_ADDREF((nsISupports *)*aSink); + return NS_OK; + } + + return NS_NOINTERFACE; + } else { return QueryInterface(aIID, aSink); } @@ -5567,6 +5583,64 @@ nsDocShell::ShouldAddToGlobalHistory(nsIURI * aURI, PRBool * aShouldAdd) return NS_OK; } + + +//***************************************************************************** +// nsDocShell: nsIEditorDocShell +//***************************************************************************** + +NS_IMETHODIMP nsDocShell::GetEditor(nsIEditor * *aEditor) +{ + NS_ENSURE_ARG_POINTER(aEditor); + nsresult rv = EnsureEditorData(); + if (NS_FAILED(rv)) return rv; + + return mEditorData->GetEditor(aEditor); +} + +NS_IMETHODIMP nsDocShell::SetEditor(nsIEditor * aEditor) +{ + nsresult rv = EnsureEditorData(); + if (NS_FAILED(rv)) return rv; + + return mEditorData->SetEditor(aEditor); +} + + +NS_IMETHODIMP nsDocShell::GetEditable(PRBool *aEditable) +{ + NS_ENSURE_ARG_POINTER(aEditable); + *aEditable = mEditorData && mEditorData->GetEditable(); + return NS_OK; +} + + +NS_IMETHODIMP nsDocShell::GetHasEditingSession(PRBool *aHasEditingSession) +{ + NS_ENSURE_ARG_POINTER(aHasEditingSession); + + if (mEditorData) + { + nsCOMPtr editingSession; + mEditorData->GetEditingSession(getter_AddRefs(editingSession)); + *aHasEditingSession = (editingSession.get() != nsnull); + } + else + { + *aHasEditingSession = PR_FALSE; + } + + return NS_OK; +} + +NS_IMETHODIMP nsDocShell::MakeEditable(PRBool inWaitForUriLoad) +{ + nsresult rv = EnsureEditorData(); + if (NS_FAILED(rv)) return rv; + + return mEditorData->MakeEditable(inWaitForUriLoad); +} + NS_IMETHODIMP nsDocShell::AddToGlobalHistory(nsIURI * aURI) { @@ -5759,6 +5833,20 @@ nsDocShell::EnsureScriptEnvironment() return NS_OK; } + +NS_IMETHODIMP +nsDocShell::EnsureEditorData() +{ + if (!mEditorData) + { + mEditorData = new nsDocShellEditorData(this); + if (!mEditorData) return NS_ERROR_OUT_OF_MEMORY; + } + + return mEditorData ? NS_OK : NS_ERROR_FAILURE; +} + + NS_IMETHODIMP nsDocShell::EnsureFind() { nsresult rv; diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index 6bf11e48035..500c665889d 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -40,11 +40,13 @@ #include "nsIDocumentLoader.h" #include "nsIURILoader.h" +#include "nsIEditorDocShell.h" #include "nsWeakReference.h" // Local Includes #include "nsDSURIContentListener.h" +#include "nsDocShellEditorData.h" // Helper Classes #include "nsCOMPtr.h" @@ -149,6 +151,7 @@ class nsDocShell : public nsIDocShell, public nsIScriptGlobalObjectOwner, public nsIRefreshURI, public nsIWebProgressListener, + public nsIEditorDocShell, public nsSupportsWeakReference { friend class nsDSURIContentListener; @@ -173,6 +176,7 @@ public: NS_DECL_NSIWEBPROGRESSLISTENER NS_DECL_NSIREFRESHURI NS_DECL_NSICONTENTVIEWERCONTAINER + NS_DECL_NSIEDITORDOCSHELL nsresult SetLoadCookie(nsISupports * aCookie); nsresult GetLoadCookie(nsISupports ** aResult); @@ -239,6 +243,7 @@ protected: NS_IMETHOD GetRootScrollableView(nsIScrollableView ** aOutScrollView); NS_IMETHOD EnsureContentListener(); NS_IMETHOD EnsureScriptEnvironment(); + NS_IMETHOD EnsureEditorData(); NS_IMETHOD EnsureFind(); static inline PRUint32 @@ -339,6 +344,9 @@ protected: PRBool mIsBeingDestroyed; + // Editor stuff + nsDocShellEditorData* mEditorData; // editor data, if any + // WEAK REFERENCES BELOW HERE. // Note these are intentionally not addrefd. Doing so will create a cycle. // For that reasons don't use nsCOMPtr. diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 0bc87d7650b..49b8fe361b5 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -110,6 +110,7 @@ typedef unsigned long HMTX; #include "nsILayoutHistoryState.h" #include "nsTextFormatter.h" #include "nsPIDOMWindow.h" +#include "nsPICommandUpdater.h" #include "nsIController.h" #include "nsIFocusController.h" #include "nsGUIEvent.h" @@ -228,6 +229,27 @@ void nsWebShell::InitFrameData() SetMarginHeight(-1); } +nsresult +nsWebShell::EnsureCommandHandler() +{ + if (!mCommandManager) + { + mCommandManager = do_CreateInstance("@mozilla.org/embedcomp/command-manager;1"); + if (!mCommandManager) return NS_ERROR_OUT_OF_MEMORY; + + nsCOMPtr commandUpdater = do_QueryInterface(mCommandManager); + if (!commandUpdater) return NS_ERROR_FAILURE; + + nsCOMPtr domWindow = do_GetInterface(NS_STATIC_CAST(nsIInterfaceRequestor *, this)); + nsresult rv = commandUpdater->Init(domWindow); + NS_ASSERTION(NS_SUCCEEDED(rv), "Initting command manager failed"); + } + + return mCommandManager ? NS_OK : NS_ERROR_FAILURE; +} + + + NS_IMPL_ADDREF_INHERITED(nsWebShell, nsDocShell) NS_IMPL_RELEASE_INHERITED(nsWebShell, nsDocShell) @@ -274,6 +296,13 @@ nsWebShell::GetInterface(const nsIID &aIID, void** aInstancePtr) NS_ERROR_FAILURE); return NS_OK; } + else if(aIID.Equals(NS_GET_IID(nsICommandManager))) + { + NS_ENSURE_SUCCESS(EnsureCommandHandler(), NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mCommandManager->QueryInterface(NS_GET_IID(nsICommandManager), + aInstancePtr), NS_ERROR_FAILURE); + return NS_OK; + } if (!*aInstancePtr || NS_FAILED(rv)) return nsDocShell::GetInterface(aIID,aInstancePtr); diff --git a/mozilla/docshell/base/nsWebShell.h b/mozilla/docshell/base/nsWebShell.h index c4ae9b3398d..75c90d8cbc8 100644 --- a/mozilla/docshell/base/nsWebShell.h +++ b/mozilla/docshell/base/nsWebShell.h @@ -28,6 +28,7 @@ #include "nsILinkHandler.h" #include "nsIClipboardCommands.h" #include "nsDocShell.h" +#include "nsICommandManager.h" class nsIController; struct PRThread; @@ -99,6 +100,7 @@ protected: virtual nsresult GetControllerForCommand ( const nsAReadableString & inCommand, nsIController** outController ); virtual nsresult IsCommandEnabled ( const nsAReadableString & inCommand, PRBool* outEnabled ); virtual nsresult DoCommand ( const nsAReadableString & inCommand ); + nsresult EnsureCommandHandler(); // // Helper method that is called when a new document (including any @@ -122,6 +124,8 @@ protected: const char* aCommand, nsIStreamListener** aResult); + nsCOMPtr mCommandManager; + #ifdef DEBUG private: // We're counting the number of |nsWebShells| to help find leaks diff --git a/mozilla/docshell/build/Makefile.in b/mozilla/docshell/build/Makefile.in index ce6e9a514dd..448b64e8c04 100644 --- a/mozilla/docshell/build/Makefile.in +++ b/mozilla/docshell/build/Makefile.in @@ -48,6 +48,9 @@ REQUIRES = xpcom \ chardet \ appcomps \ find \ + composer \ + editor \ + commandhandler \ $(NULL) ifeq ($(OS_ARCH),WINNT) diff --git a/mozilla/docshell/build/makefile.win b/mozilla/docshell/build/makefile.win index f5045f83be5..6e00f53729a 100644 --- a/mozilla/docshell/build/makefile.win +++ b/mozilla/docshell/build/makefile.win @@ -38,6 +38,9 @@ REQUIRES = xpcom \ find \ gfx \ history \ + composer \ + editor \ + commandhandler \ $(NULL) include <$(DEPTH)\config\config.mak> diff --git a/mozilla/docshell/macbuild/docshell.xml b/mozilla/docshell/macbuild/docshell.xml index 975903ffac2..6bd0b71a37c 100644 --- a/mozilla/docshell/macbuild/docshell.xml +++ b/mozilla/docshell/macbuild/docshell.xml @@ -547,7 +547,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password263jzwcn63nthc2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -1041,6 +1041,13 @@ Library Debug + + Name + nsDocShellEditorData.cpp + MacOS + Text + Debug + @@ -1108,6 +1115,11 @@ nsDocShellEnumerator.cpp MacOS + + Name + nsDocShellEditorData.cpp + MacOS + @@ -1604,7 +1616,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password263jzwcn63nthc2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -2098,6 +2110,13 @@ Library Debug + + Name + nsDocShellEditorData.cpp + MacOS + Text + Debug + @@ -2165,6 +2184,11 @@ nsDocShellEnumerator.cpp MacOS + + Name + nsDocShellEditorData.cpp + MacOS + @@ -2218,6 +2242,12 @@ nsDocShellModule.cpp MacOS + + docshell.shlb + Name + nsDocShellEditorData.cpp + MacOS + NS Libraries Optimized diff --git a/mozilla/docshell/macbuild/docshellIDL.xml b/mozilla/docshell/macbuild/docshellIDL.xml index 1a9ce00966d..1879e7f5943 100644 --- a/mozilla/docshell/macbuild/docshellIDL.xml +++ b/mozilla/docshell/macbuild/docshellIDL.xml @@ -307,7 +307,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password265jqwan65niha2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -815,6 +815,13 @@ Text + + Name + nsIEditorDocShell.idl + MacOS + Text + + @@ -892,6 +899,11 @@ nsIContentViewerFile.idl MacOS + + Name + nsIEditorDocShell.idl + MacOS + @@ -1148,7 +1160,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password265jqwan65niha2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -1656,6 +1668,13 @@ Text + + Name + nsIEditorDocShell.idl + MacOS + Text + + @@ -1733,6 +1752,11 @@ nsIContentViewerFile.idl MacOS + + Name + nsIEditorDocShell.idl + MacOS + @@ -1829,6 +1853,12 @@ nsIContentViewer.idl MacOS + + headers + Name + nsIEditorDocShell.idl + MacOS + headers Name diff --git a/mozilla/editor/composer/Makefile.in b/mozilla/editor/composer/Makefile.in index 80cc4208bb8..38a5bf9da1b 100644 --- a/mozilla/editor/composer/Makefile.in +++ b/mozilla/editor/composer/Makefile.in @@ -26,7 +26,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = src +DIRS = src public # Enable Editor API Logging! ENABLE_EDITOR_API_LOG=1 diff --git a/mozilla/editor/composer/makefile.win b/mozilla/editor/composer/makefile.win index 92367ab59f0..7402d285cd8 100644 --- a/mozilla/editor/composer/makefile.win +++ b/mozilla/editor/composer/makefile.win @@ -21,7 +21,7 @@ DEPTH=..\.. -DIRS= src +DIRS= src public include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/editor/composer/src/Makefile.in b/mozilla/editor/composer/src/Makefile.in index 25d2b34f679..76984dda8d3 100644 --- a/mozilla/editor/composer/src/Makefile.in +++ b/mozilla/editor/composer/src/Makefile.in @@ -58,6 +58,7 @@ REQUIRES = xpcom \ gfx2 \ webbrwsr \ unicharutil \ + commandhandler \ $(NULL) CPPSRCS = \ @@ -68,6 +69,8 @@ CPPSRCS = \ nsComposerController.cpp \ nsComposerCommands.cpp \ nsComposerRegistration.cpp \ + nsEditingSession.cpp \ + nsComposerCommandsUpdater.cpp \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/editor/composer/src/makefile.win b/mozilla/editor/composer/src/makefile.win index 235ca44bc81..8b040bf3885 100644 --- a/mozilla/editor/composer/src/makefile.win +++ b/mozilla/editor/composer/src/makefile.win @@ -27,10 +27,12 @@ MODULE_NAME=nsComposerModule CPP_OBJS = \ .\$(OBJDIR)\nsEditorShell.obj \ + .\$(OBJDIR)\nsEditingSession.obj \ .\$(OBJDIR)\nsEditorShellMouseListener.obj \ .\$(OBJDIR)\nsInterfaceState.obj \ .\$(OBJDIR)\nsComposerController.obj \ .\$(OBJDIR)\nsComposerCommands.obj \ + .\$(OBJDIR)\nsComposerCommandsUpdater.obj \ .\$(OBJDIR)\nsComposerRegistration.obj \ .\$(OBJDIR)\nsEditorParserObserver.obj \ $(NULL) @@ -64,6 +66,7 @@ REQUIRES = xpcom \ gfx2 \ webBrowser_core \ unicharutil \ + commandhandler \ $(NULL) include <$(DEPTH)/config/config.mak> diff --git a/mozilla/editor/composer/src/nsComposerCommands.cpp b/mozilla/editor/composer/src/nsComposerCommands.cpp index 6a81b26b433..120fbccb8df 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.cpp +++ b/mozilla/editor/composer/src/nsComposerCommands.cpp @@ -53,6 +53,27 @@ #include "nsCOMPtr.h" #include "nsComposerCommands.h" +#include "nsIEditorMailSupport.h" +#include "nsReadableUtils.h" +#include "nsICommandParams.h" +#include "nsComponentManagerUtils.h" +//prototype +nsresult GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **tagStr); +nsresult PasteAsQuotation(nsIEditor *aEditor, PRInt32 aSelectionType); +nsresult RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, const nsString &aAttr); +nsresult RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr); +nsresult SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value); +nsresult GetListItemState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval); + + +//defines +#define COMMAND_NAME NS_ConvertASCIItoUCS2("cmd_name") +#define STATE_ENABLED NS_ConvertASCIItoUCS2("state_enabled") +#define STATE_ALL NS_ConvertASCIItoUCS2("state_all") +#define STATE_BEGIN NS_ConvertASCIItoUCS2("state_begin") +#define STATE_END NS_ConvertASCIItoUCS2("state_end") +#define STATE_MIXED NS_ConvertASCIItoUCS2("state_mixed") +#define STATE_STRING NS_ConvertASCIItoUCS2("state_string") nsBaseComposerCommand::nsBaseComposerCommand() @@ -126,6 +147,14 @@ nsBaseComposerCommand::EditingHTML(nsIEditorShell* inEditorShell) return PR_TRUE; } +PRBool +nsBaseComposerCommand::EditingHTML(nsIEditor* inEditor) +//-------------------------------------------------------------------------------------------------------------------- +{ + //look at mime type + return PR_TRUE; +} + #ifdef XP_MAC #pragma mark - @@ -175,6 +204,31 @@ nsBaseStateUpdatingCommand::DoCommand(const nsAReadableString & aCommandName, ns return UpdateCommandState(aCommandName, refCon); } +NS_IMETHODIMP +nsBaseStateUpdatingCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + if (!editor) + return NS_ERROR_NOT_INITIALIZED; + + nsresult rv = ToggleState(editor, mTagName); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +NS_IMETHODIMP +nsBaseStateUpdatingCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + nsresult rv = NS_OK; + if (editor) + { + rv = GetCurrentState(editor, mTagName, aParams); + } + return rv; +} + NS_IMETHODIMP nsBaseStateUpdatingCommand::UpdateCommandState(const nsAReadableString & aCommandName, nsISupports *refCon) { @@ -270,6 +324,33 @@ nsPasteQuotationCommand::DoCommand(const nsAReadableString & aCommandName, nsISu return rv; } +NS_IMETHODIMP +nsPasteQuotationCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + rv = PasteAsQuotation(editor,nsIClipboard::kGlobalClipboard); + } + + return rv; +} + +NS_IMETHODIMP +nsPasteQuotationCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + PRBool enabled = PR_FALSE; + if (editor) + { + editor->CanPaste(nsIClipboard::kGlobalClipboard, &enabled); + aParams->SetBooleanValue(STATE_ENABLED,enabled); + } + + return NS_OK; +} #ifdef XP_MAC #pragma mark - @@ -303,6 +384,28 @@ nsStyleUpdatingCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char return rv; } +nsresult +nsStyleUpdatingCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need editor shell here"); + nsresult rv = NS_OK; + + PRBool firstOfSelectionHasProp = PR_FALSE; + PRBool anyOfSelectionHasProp = PR_FALSE; + PRBool allOfSelectionHasProp = PR_FALSE; + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aTagName)); + rv = htmlEditor->GetInlineProperty(styleAtom, NS_LITERAL_STRING(""), NS_LITERAL_STRING(""), &firstOfSelectionHasProp, &anyOfSelectionHasProp, &allOfSelectionHasProp);\ + aParams->SetBooleanValue(STATE_ALL,allOfSelectionHasProp); + aParams->SetBooleanValue(STATE_BEGIN,firstOfSelectionHasProp); + aParams->SetBooleanValue(STATE_END,allOfSelectionHasProp);//not completely accurate + aParams->SetBooleanValue(STATE_MIXED,anyOfSelectionHasProp && !allOfSelectionHasProp); + return NS_OK; +} + nsresult nsStyleUpdatingCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName) { @@ -338,6 +441,52 @@ nsStyleUpdatingCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aT return rv; } +nsresult +nsStyleUpdatingCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) +{ + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) + return NS_ERROR_NO_INTERFACE; + PRBool styleSet; + //create some params now... + nsresult rv; + nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) + return rv; + + rv = GetCurrentState(aEditor, aTagName, params); + if (NS_FAILED(rv)) + return rv; + rv = params->GetBooleanValue(STATE_ALL,&styleSet); + if (NS_FAILED(rv)) + return rv; + nsAutoString tagName; tagName.AssignWithConversion(aTagName); + if (styleSet) + rv = RemoveTextProperty(aEditor, tagName.get(), nsnull); + else + { + // Superscript and Subscript styles are mutually exclusive + nsAutoString removeName; + aEditor->BeginTransaction(); + + if (tagName.Equals(NS_LITERAL_STRING("sub"))) + { + removeName.AssignWithConversion("sup"); + rv = RemoveTextProperty(aEditor,tagName.get(), nsnull); + } + else if (tagName.Equals(NS_LITERAL_STRING("sup"))) + { + removeName.AssignWithConversion("sub"); + rv = RemoveTextProperty(aEditor, tagName.get(), nsnull); + } + if (NS_SUCCEEDED(rv)) + rv = SetTextProperty(aEditor,tagName.get(), nsnull, nsnull); + + aEditor->EndTransaction(); + } + + return rv; +} #ifdef XP_MAC #pragma mark - #endif @@ -365,6 +514,23 @@ nsListCommand::GetCurrentState(nsIEditorShell *aEditorShell, const char* aTagNam return NS_OK; } +nsresult +nsListCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need editor here"); + + PRBool bMixed; + PRUnichar *tagStr; + nsresult rv = GetListState(aEditor,&bMixed, &tagStr); + if (NS_FAILED(rv)) return rv; + + // Need to use mTagName???? + PRBool inList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); + aParams->SetBooleanValue(STATE_ALL, !bMixed && inList); + aParams->SetBooleanValue(STATE_MIXED, bMixed); + if (tagStr) nsCRT::free(tagStr); + return NS_OK; +} nsresult nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName) @@ -383,6 +549,32 @@ nsListCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagName) return rv; } +nsresult +nsListCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) +{ + nsCOMPtr editor = do_QueryInterface(aEditor); + if (!editor) + return NS_NOINTERFACE; + PRBool inList; + // Need to use mTagName???? + nsresult rv; + nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) + return rv; + rv = GetCurrentState(aEditor, mTagName, params); + rv = params->GetBooleanValue(STATE_ALL,&inList); + if (NS_FAILED(rv)) + return rv; + + nsAutoString listType; listType.AssignWithConversion(mTagName); + nsString empty; + if (inList) + rv = editor->RemoveList(listType); + else + rv = editor->MakeOrChangeList(listType, PR_FALSE, empty); + + return rv; +} #ifdef XP_MAC #pragma mark - @@ -454,6 +646,72 @@ nsListItemCommand::ToggleState(nsIEditorShell *aEditorShell, const char* aTagNam return rv; } +nsresult +nsListItemCommand::GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need editor here"); + + PRBool bMixed; + PRUnichar *tagStr; + nsresult rv = GetListItemState(aEditor,&bMixed, &tagStr); + if (NS_FAILED(rv)) return rv; + + PRBool inList = (0 == nsCRT::strcmp(tagStr, NS_ConvertASCIItoUCS2(mTagName).get())); + aParams->SetBooleanValue(STATE_ALL, !bMixed && inList); + aParams->SetBooleanValue(STATE_MIXED, bMixed); + + if (tagStr) nsCRT::free(tagStr); + + return NS_OK; +} + +nsresult +nsListItemCommand::ToggleState(nsIEditor *aEditor, const char* aTagName) +{ + NS_ASSERTION(aEditor, "Need editor here"); + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_NOT_INITIALIZED; + + PRBool inList; + // Need to use mTagName???? + nsresult rv; + nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) + return rv; + rv = GetCurrentState(aEditor, mTagName, params); + rv = params->GetBooleanValue(STATE_ALL,&inList); + if (NS_FAILED(rv)) + return rv; + if (NS_FAILED(rv)) return rv; + + if (inList) + { + // To remove a list, first get what kind of list we're in + PRBool bMixed; + PRUnichar *tagStr; + rv = GetListState(aEditor,&bMixed, &tagStr); + if (NS_FAILED(rv)) return rv; + if (tagStr) + { + if (!bMixed) + { + rv = htmlEditor->RemoveList(nsDependentString(tagStr)); + } + nsCRT::free(tagStr); + } + } + else + { + nsAutoString itemType; itemType.AssignWithConversion(mTagName); + // Set to the requested paragraph type + //XXX Note: This actually doesn't work for "LI", + // but we currently don't use this for non DL lists anyway. + // Problem: won't this replace any current block paragraph style? + rv = htmlEditor->SetParagraphFormat(itemType); + } + + return rv; +} #ifdef XP_MAC #pragma mark - @@ -497,6 +755,31 @@ nsRemoveListCommand::DoCommand(const nsAReadableString & aCommandName, nsISuppor return rv; } +NS_IMETHODIMP +nsRemoveListCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + // This removes any list type + nsString aListType(nsnull); + rv = editor->RemoveList(aListType); + } + + return rv; +} + +NS_IMETHODIMP +nsRemoveListCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} #ifdef XP_MAC #pragma mark - @@ -534,6 +817,37 @@ nsIndentCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports * return rv; } +NS_IMETHODIMP +nsIndentCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + NS_NAMED_LITERAL_STRING(indentStr, "indent"); + nsAutoString aIndent(indentStr); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (htmlEditor) + rv = htmlEditor->Indent(aIndent); + } + + return rv; +} + +NS_IMETHODIMP +nsIndentCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} + + +//OUTDENT + NS_IMETHODIMP nsOutdentCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) { @@ -572,6 +886,34 @@ nsOutdentCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports return rv; } +NS_IMETHODIMP +nsOutdentCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor && EditingHTML(editor)) + { + NS_NAMED_LITERAL_STRING(indentStr, "outdent"); + nsAutoString aIndent(indentStr); + nsCOMPtr htmlEditor = do_QueryInterface(editor); + if (htmlEditor) + rv = htmlEditor->Indent(aIndent); + } + + return rv; +} + +NS_IMETHODIMP +nsOutdentCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} + #ifdef XP_MAC #pragma mark - #endif @@ -635,6 +977,32 @@ nsMultiStateCommand::DoCommand(const nsAReadableString & aCommandName, nsISuppor return rv; } +NS_IMETHODIMP +nsMultiStateCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + // we have to grab the state attribute on our command node to find out + // what format to set the paragraph to + nsAutoString tValue; + nsresult rv; + if (NS_SUCCEEDED(rv = aParams->GetStringValue(COMMAND_NAME,tValue))) + { + nsAutoString stateAttribute; +#if 0 + rv = GetCommandNodeState(tValue, editor, stateAttribute); + if (NS_FAILED(rv)) return rv; + + rv = SetState(editor, stateAttribute); +#endif + } + } + + return rv; +} NS_IMETHODIMP nsMultiStateCommand::UpdateCommandState(const nsAReadableString & aCommandName, nsISupports *refCon) @@ -664,6 +1032,17 @@ nsMultiStateCommand::UpdateCommandState(const nsAReadableString & aCommandName, return rv; } +NS_IMETHODIMP +nsMultiStateCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + nsresult rv = NS_OK; + if (editor) + { + rv = GetCurrentState(editor, aParams); + } + return rv; +} #ifdef XP_MAC #pragma mark - @@ -686,6 +1065,24 @@ nsParagraphStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& return htmlEditor->GetParagraphState(&outMixed, outStateString); } +nsresult +nsParagraphStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + PRBool outMixed; + nsString outStateString; + nsresult rv = htmlEditor->GetParagraphState(&outMixed, outStateString); + if (NS_SUCCEEDED(rv)) + { + aParams->SetBooleanValue(STATE_MIXED,outMixed); + aParams->SetStringValue(STATE_STRING, outStateString); + } + return rv; +} + nsresult nsParagraphStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) @@ -700,6 +1097,16 @@ nsParagraphStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newSta return htmlEditor->SetParagraphFormat(newState); } +nsresult +nsParagraphStateCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + return htmlEditor->SetParagraphFormat(newState); +} #ifdef XP_MAC #pragma mark - @@ -723,7 +1130,60 @@ nsFontFaceStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& return htmlEditor->GetFontFaceState(&outMixed, outStateString); } +nsresult +nsFontFaceStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + nsString outStateString; + PRBool outMixed; + nsresult rv = htmlEditor->GetFontFaceState(&outMixed, outStateString); + if (NS_SUCCEEDED(rv)) + { + aParams->SetBooleanValue(STATE_MIXED,outMixed); + aParams->SetStringValue(STATE_STRING,outStateString); + } + return rv; +} + +nsresult +nsFontFaceStateCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsresult rv; + + + nsCOMPtr ttAtom = getter_AddRefs(NS_NewAtom("tt")); + nsCOMPtr fontAtom = getter_AddRefs(NS_NewAtom("font")); + + if (newState.Equals(NS_LITERAL_STRING("tt"))) + { + // The old "teletype" attribute + rv = htmlEditor->SetInlineProperty(ttAtom, NS_LITERAL_STRING(""), NS_LITERAL_STRING("")); + // Clear existing font face + rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("face")); + } + else + { + // Remove any existing TT nodes + rv = htmlEditor->RemoveInlineProperty(ttAtom, NS_LITERAL_STRING("")); + + if (newState.IsEmpty() || newState.Equals(NS_LITERAL_STRING("normal"))) { + rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("face")); + } else { + rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("face"), newState); + } + } + + return rv; +} nsresult nsFontFaceStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) { @@ -784,6 +1244,46 @@ nsFontColorStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& return htmlEditor->GetFontColorState(&outMixed, outStateString); } +nsresult +nsFontColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + PRBool outMixed; + nsString outStateString; + nsresult rv = htmlEditor->GetFontColorState(&outMixed, outStateString); + if (NS_SUCCEEDED(rv)) + { + aParams->SetBooleanValue(STATE_MIXED,outMixed); + aParams->SetStringValue(STATE_STRING,outStateString); + } + return rv; +} + +nsresult +nsFontColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsresult rv; + + + nsCOMPtr fontAtom = getter_AddRefs(NS_NewAtom("font")); + + if (newState.IsEmpty() || newState.Equals(NS_LITERAL_STRING("normal"))) { + rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("color")); + } else { + rv = htmlEditor->SetInlineProperty(fontAtom, NS_LITERAL_STRING("color"), newState); + } + + return rv; +} nsresult nsFontColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) @@ -831,6 +1331,45 @@ nsHighlightColorStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsSt return htmlEditor->GetHighlightColorState(&outMixed, outStateString); } +nsresult +nsHighlightColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + PRBool outMixed; + nsString outStateString; + nsresult rv = htmlEditor->GetHighlightColorState(&outMixed, outStateString); + if (NS_SUCCEEDED(rv)) + { + aParams->SetBooleanValue(STATE_MIXED,outMixed); + aParams->SetStringValue(STATE_STRING,outStateString); + } + return rv; +} + +nsresult +nsHighlightColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsresult rv; + + nsCOMPtr fontAtom = getter_AddRefs(NS_NewAtom("font")); + + if (!newState.Length() || newState.Equals(NS_LITERAL_STRING("normal"))) { + rv = htmlEditor->RemoveInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor")); + } else { + rv = htmlEditor->SetCSSInlineProperty(fontAtom, NS_LITERAL_STRING("bgcolor"), newState); + } + + return rv; +} nsresult nsHighlightColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) @@ -905,6 +1444,35 @@ nsBackgroundColorStateCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsS return htmlEditor->GetBackgroundColorState(&outMixed, outStateString); } +nsresult +nsBackgroundColorStateCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + PRBool outMixed; + nsString outStateString; + nsresult rv = htmlEditor->GetBackgroundColorState(&outMixed, outStateString); + if (NS_SUCCEEDED(rv)) + { + aParams->SetBooleanValue(STATE_MIXED, outMixed); + aParams->SetStringValue(STATE_STRING, outStateString); + } + return rv; +} + +nsresult +nsBackgroundColorStateCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + return htmlEditor->SetBackgroundColor(newState); +} nsresult nsBackgroundColorStateCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) @@ -964,6 +1532,56 @@ nsAlignCommand::GetCurrentState(nsIEditorShell *aEditorShell, nsString& outState return NS_OK; } +nsresult +nsAlignCommand::GetCurrentState(nsIEditor *aEditor, nsICommandParams *aParams) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + nsIHTMLEditor::EAlignment firstAlign; + PRBool outMixed; + nsString outStateString; + nsresult rv = htmlEditor->GetAlignment(&outMixed, &firstAlign); + + if (NS_FAILED(rv)) + return rv; + + switch (firstAlign) + { + default: + case nsIHTMLEditor::eLeft: + outStateString.Assign(NS_LITERAL_STRING("left")); + break; + + case nsIHTMLEditor::eCenter: + outStateString.Assign(NS_LITERAL_STRING("center")); + break; + + case nsIHTMLEditor::eRight: + outStateString.Assign(NS_LITERAL_STRING("right")); + break; + + case nsIHTMLEditor::eJustify: + outStateString.Assign(NS_LITERAL_STRING("justify")); + break; + } + aParams->SetBooleanValue(STATE_MIXED, outMixed); + aParams->SetStringValue(STATE_STRING, outStateString); + return NS_OK; +} + +nsresult +nsAlignCommand::SetState(nsIEditor *aEditor, nsString& newState) +{ + NS_ASSERTION(aEditor, "Need an editor shell here"); + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (!htmlEditor) return NS_ERROR_FAILURE; + + return htmlEditor->Align(newState); +} nsresult nsAlignCommand::SetState(nsIEditorShell *aEditorShell, nsString& newState) @@ -987,22 +1605,26 @@ NS_IMETHODIMP nsRemoveStylesCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) { nsCOMPtr editorShell = do_QueryInterface(refCon); - *outCmdEnabled = PR_FALSE; + nsCOMPtreditor; if (editorShell && EditingHTML(editorShell)) { - nsCOMPtr editor; editorShell->GetEditor(getter_AddRefs(editor)); - if (editor) - { - // test if we have any styles? - *outCmdEnabled = PR_TRUE; - } + } + else + editor = do_QueryInterface(refCon); + + *outCmdEnabled = PR_FALSE; + if (editor) + { + // test if we have any styles? + *outCmdEnabled = PR_TRUE; } return NS_OK; } + NS_IMETHODIMP nsRemoveStylesCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *refCon) { @@ -1024,6 +1646,24 @@ nsRemoveStylesCommand::DoCommand(const nsAReadableString & aCommandName, nsISupp return rv; } +NS_IMETHODIMP +nsRemoveStylesCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString, refCon); +} + +NS_IMETHODIMP +nsRemoveStylesCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} + #ifdef XP_MAC #pragma mark - #endif @@ -1032,20 +1672,22 @@ NS_IMETHODIMP nsIncreaseFontSizeCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) { nsCOMPtr editorShell = do_QueryInterface(refCon); - *outCmdEnabled = PR_FALSE; + nsCOMPtreditor; if (editorShell && EditingHTML(editorShell)) { - nsCOMPtr editor; editorShell->GetEditor(getter_AddRefs(editor)); - if (editor) - { - // test if we are at the max size? - *outCmdEnabled = PR_TRUE; - } + } + else + editor = do_QueryInterface(refCon); + + *outCmdEnabled = PR_FALSE; + if (editor) + { + // test if we have any styles? + *outCmdEnabled = PR_TRUE; } - return NS_OK; -} + return NS_OK;} NS_IMETHODIMP @@ -1062,6 +1704,30 @@ nsIncreaseFontSizeCommand::DoCommand(const nsAReadableString & aCommandName, nsI return rv; } +NS_IMETHODIMP +nsIncreaseFontSizeCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + rv = editor->IncreaseFontSize(); + } + + return rv; +} + +NS_IMETHODIMP +nsIncreaseFontSizeCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} + #ifdef XP_MAC #pragma mark - #endif @@ -1070,16 +1736,19 @@ NS_IMETHODIMP nsDecreaseFontSizeCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *refCon, PRBool *outCmdEnabled) { nsCOMPtr editorShell = do_QueryInterface(refCon); - *outCmdEnabled = PR_FALSE; + nsCOMPtreditor; if (editorShell && EditingHTML(editorShell)) { - nsCOMPtr editor; editorShell->GetEditor(getter_AddRefs(editor)); - if (editor) - { - // test if we are at the min size? - *outCmdEnabled = PR_TRUE; - } + } + else + editor = do_QueryInterface(refCon); + + *outCmdEnabled = PR_FALSE; + if (editor) + { + // test if we are at min size? + *outCmdEnabled = PR_TRUE; } return NS_OK; @@ -1099,3 +1768,175 @@ nsDecreaseFontSizeCommand::DoCommand(const nsAReadableString & aCommandName, nsI return rv; } + +NS_IMETHODIMP +nsDecreaseFontSizeCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *refCon) +{ + nsCOMPtr editor = do_QueryInterface(refCon); + + nsresult rv = NS_OK; + if (editor) + { + rv = editor->DecreaseFontSize(); + } + + return rv; +} + +NS_IMETHODIMP +nsDecreaseFontSizeCommand::GetCommandState(nsICommandParams *aParams, nsISupports *refCon) +{ + nsString tString; + PRBool outCmdEnabled = PR_FALSE; + aParams->GetStringValue(COMMAND_NAME,tString); + IsCommandEnabled(tString, refCon, &outCmdEnabled); + return aParams->SetBooleanValue(STATE_ENABLED,outCmdEnabled); +} + +/****************************/ +//HELPER METHODS +/****************************/ + +nsresult +PasteAsQuotation(nsIEditor *aEditor, PRInt32 aSelectionType) +{ + nsresult err = NS_ERROR_NOT_IMPLEMENTED; + + nsCOMPtr mailEditor = do_QueryInterface(aEditor); + if (mailEditor) + err = mailEditor->PasteAsQuotation(aSelectionType); + + return err; +} + +nsresult +GetListState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval) +{ + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + nsresult err = NS_ERROR_NO_INTERFACE; + if (htmlEditor) + { + PRBool bOL, bUL, bDL; + err = htmlEditor->GetListState(aMixed, &bOL, &bUL, &bDL); + if (NS_SUCCEEDED(err)) + { + if (!*aMixed) + { + nsAutoString tagStr; + if (bOL) + tagStr.AssignWithConversion("ol"); + else if (bUL) + tagStr.AssignWithConversion("ul"); + else if (bDL) + tagStr.AssignWithConversion("dl"); + *_retval = ToNewUnicode(tagStr); + } + } + } + return err; +} + +nsresult +RemoveOneProperty(nsIHTMLEditor *aEditor,const nsString& aProp, const nsString &aAttr) +{ + nsresult err = NS_NOINTERFACE; + + if (!aEditor) + return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) + return NS_ERROR_OUT_OF_MEMORY; + + err = aEditor->RemoveInlineProperty(styleAtom, aAttr); + + return err; +} + + +// the name of the attribute here should be the contents of the appropriate +// tag, e.g. 'b' for bold, 'i' for italics. +nsresult +RemoveTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr) +{ + if (!aEditor) + return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr editor = do_QueryInterface(aEditor); + if (!editor) + return NS_ERROR_NOT_INITIALIZED; + // OK, I'm really hacking now. This is just so that we can accept 'all' as input. + nsAutoString allStr(prop); + nsAutoString aAttr(attr); + + ToLowerCase(allStr); + PRBool doingAll = (allStr.Equals(NS_LITERAL_STRING("all"))); + nsresult err = NS_OK; + + if (doingAll) + { + err = editor->RemoveAllInlineProperties(); + } + else + { + nsAutoString aProp(prop); + err = RemoveOneProperty(editor,aProp, aAttr); + } + + return err; +} + +// the name of the attribute here should be the contents of the appropriate +// tag, e.g. 'b' for bold, 'i' for italics. +nsresult +SetTextProperty(nsIEditor *aEditor, const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value) +{ + //static initialization + static const PRUnichar sEmptyStr = PRUnichar('\0'); + + nsresult err = NS_NOINTERFACE; + + if (!aEditor) + return NS_ERROR_NOT_INITIALIZED; + + nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this + if (! styleAtom) + return NS_ERROR_OUT_OF_MEMORY; + + + nsCOMPtr htmlEditor = do_QueryInterface(aEditor,&err); + if (htmlEditor) + err = htmlEditor->SetInlineProperty(styleAtom, + nsDependentString(attr?attr:&sEmptyStr), + nsDependentString(value?value:&sEmptyStr)); + + return err; +} + +nsresult +GetListItemState(nsIEditor *aEditor, PRBool *aMixed, PRUnichar **_retval) +{ + if (!aMixed || !_retval || !aEditor) + return NS_ERROR_NULL_POINTER; + *_retval = nsnull; + *aMixed = PR_FALSE; + + nsresult err = NS_NOINTERFACE; + nsCOMPtr htmlEditor = do_QueryInterface(aEditor); + if (htmlEditor) + { + PRBool bLI,bDT,bDD; + err = htmlEditor->GetListItemState(aMixed, &bLI, &bDT, &bDD); + if (NS_SUCCEEDED(err)) + { + if (!*aMixed) + { + nsAutoString tagStr; + if (bLI) tagStr.Assign(NS_LITERAL_STRING("li")); + else if (bDT) tagStr.Assign(NS_LITERAL_STRING("dt")); + else if (bDD) tagStr.Assign(NS_LITERAL_STRING("dd")); + *_retval = ToNewUnicode(tagStr); + } + } + } + return err; +} diff --git a/mozilla/editor/composer/src/nsComposerCommands.h b/mozilla/editor/composer/src/nsComposerCommands.h index b09ddd90ad2..c814f881ca3 100644 --- a/mozilla/editor/composer/src/nsComposerCommands.h +++ b/mozilla/editor/composer/src/nsComposerCommands.h @@ -77,6 +77,7 @@ protected: // are we in HTML edit mode (not source view or plain text editing) PRBool EditingHTML(nsIEditorShell* inEditorShell); + PRBool EditingHTML(nsIEditor* inEditorShell); }; @@ -110,6 +111,12 @@ protected: // add/remove the style virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName) = 0; + // get the current state (on or off) for this style or block format + virtual nsresult GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) = 0; + + // add/remove the style + virtual nsresult ToggleState(nsIEditor *aEditor, const char* aTagName) = 0; + protected: const char* mTagName; @@ -134,7 +141,13 @@ protected: // add/remove the style virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName); - + + // get the current state (on or off) for this style or block format + virtual nsresult GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams); + + // add/remove the style + virtual nsresult ToggleState(nsIEditor *aEditor, const char* aTagName); + }; @@ -151,6 +164,12 @@ protected: // add/remove the style virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName); + + // get the current state (on or off) for this style or block format + virtual nsresult GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams); + + // add/remove the style + virtual nsresult ToggleState(nsIEditor *aEditor, const char* aTagName); }; class nsListItemCommand : public nsBaseStateUpdatingCommand @@ -166,6 +185,12 @@ protected: // add/remove the style virtual nsresult ToggleState(nsIEditorShell *aEditorShell, const char* aTagName); + + // get the current state (on or off) for this style or block format + virtual nsresult GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams); + + // add/remove the style + virtual nsresult ToggleState(nsIEditor *aEditor, const char* aTagName); }; // Base class for commands whose state consists of a string (e.g. para format) @@ -185,6 +210,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed) = 0; virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState) = 0; + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0; + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0; protected: @@ -203,6 +230,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; class nsFontFaceStateCommand : public nsMultiStateCommand @@ -214,6 +243,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; class nsHighlightColorStateCommand : public nsMultiStateCommand @@ -226,6 +257,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); NS_IMETHOD IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *_retval); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; @@ -238,6 +271,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; class nsAlignCommand : public nsMultiStateCommand @@ -249,6 +284,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; class nsBackgroundColorStateCommand : public nsMultiStateCommand @@ -260,6 +297,8 @@ protected: virtual nsresult GetCurrentState(nsIEditorShell *aEditorShell, nsString& outStateString, PRBool& outMixed); virtual nsresult SetState(nsIEditorShell *aEditorShell, nsString& newState); + virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); + virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); }; diff --git a/mozilla/editor/composer/src/nsComposerController.cpp b/mozilla/editor/composer/src/nsComposerController.cpp index 26890bda252..25b8b081814 100644 --- a/mozilla/editor/composer/src/nsComposerController.cpp +++ b/mozilla/editor/composer/src/nsComposerController.cpp @@ -66,6 +66,7 @@ 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) @@ -91,7 +92,7 @@ NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon) mCommandRefCon = aCommandRefCon; // no addref - mCommandManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv); + mCommandManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; // register the commands. @@ -255,7 +256,7 @@ nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandMan if (!cmdManager) { nsresult rv; - cmdManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv); + cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; // register the commands. This just happens once per instance @@ -271,3 +272,27 @@ nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandMan return NS_OK; } + +//GetCommandState +/* +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 getCommandState (in DOMString aCommandName, inout nsICommandParams aCommandParams); */ +NS_IMETHODIMP nsComposerController::GetCommandState(nsICommandParams *aCommandParams) +{ + if (!mCommandRefCon || !mCommandManager) + return NS_ERROR_NOT_INITIALIZED; + return mCommandManager->GetCommandState(aCommandParams,mCommandRefCon); +} + +/* void doCommand (in DOMString aCommandName, in nsICommandParams aCommandParams); */ +NS_IMETHODIMP nsComposerController::DoCommand(nsICommandParams *aCommandParams) +{ + if (!mCommandRefCon || !mCommandManager) + return NS_ERROR_NOT_INITIALIZED; + return mCommandManager->DoCommandParams(aCommandParams,mCommandRefCon); +} diff --git a/mozilla/editor/composer/src/nsComposerController.h b/mozilla/editor/composer/src/nsComposerController.h index c9ca27dabaf..74d1a916ad5 100644 --- a/mozilla/editor/composer/src/nsComposerController.h +++ b/mozilla/editor/composer/src/nsComposerController.h @@ -48,12 +48,14 @@ #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsIControllerCommand.h" +#include "nsIControllerCommandManager.h" #include "nsWeakPtr.h" // the editor controller is used for composer only (and other HTML compose // areas). The refCon that gets passed to its commands is an nsIEditorShell. class nsComposerController : public nsIController, + public nsICommandController, public nsIEditorController, public nsIInterfaceRequestor { @@ -77,7 +79,10 @@ public: // 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 diff --git a/mozilla/editor/composer/src/nsComposerRegistration.cpp b/mozilla/editor/composer/src/nsComposerRegistration.cpp index 871ad66476d..7d73decbc93 100644 --- a/mozilla/editor/composer/src/nsComposerRegistration.cpp +++ b/mozilla/editor/composer/src/nsComposerRegistration.cpp @@ -39,6 +39,7 @@ #include "nsIGenericFactory.h" #include "nsEditorShell.h" // for the CID +#include "nsEditingSession.h" // for the CID #include "nsComposerController.h" // for the CID //////////////////////////////////////////////////////////////////////// @@ -48,6 +49,7 @@ // NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession) NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController) //////////////////////////////////////////////////////////////////////// @@ -63,6 +65,8 @@ static const nsModuleComponentInfo components[] = { "@mozilla.org/editor/editorshell;1", nsEditorShellConstructor, }, { "Editor Shell Spell Checker", NS_EDITORSHELL_CID, "@mozilla.org/editor/editorspellcheck;1", nsEditorShellConstructor, }, + { "Editing Session", NS_EDITINGSESSION_CID, + "@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, }, }; //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/editor/libeditor/base/Makefile.in b/mozilla/editor/libeditor/base/Makefile.in index 2534b553bac..5bd0b0275bc 100644 --- a/mozilla/editor/libeditor/base/Makefile.in +++ b/mozilla/editor/libeditor/base/Makefile.in @@ -46,6 +46,7 @@ REQUIRES = xpcom \ xuldoc \ unicharutil \ webbrwsr \ + commandhandler \ $(NULL) # Internal header files, needed by other editor sublibs: diff --git a/mozilla/editor/libeditor/base/makefile.win b/mozilla/editor/libeditor/base/makefile.win index fb445cac630..09da99f1cf5 100644 --- a/mozilla/editor/libeditor/base/makefile.win +++ b/mozilla/editor/libeditor/base/makefile.win @@ -40,6 +40,7 @@ REQUIRES = xpcom \ widget \ unicharutil \ webBrowser_core \ + commandhandler \ $(NULL) CPP_OBJS = \ diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.cpp b/mozilla/editor/libeditor/base/nsEditorCommands.cpp index 93b9583c810..b8c1e680c38 100644 --- a/mozilla/editor/libeditor/base/nsEditorCommands.cpp +++ b/mozilla/editor/libeditor/base/nsEditorCommands.cpp @@ -49,6 +49,10 @@ #include "nsEditorCommands.h" +#define COMMAND_NAME NS_ConvertASCIItoUCS2("cmd_name") +#define STATE_ENABLED NS_ConvertASCIItoUCS2("state_enabled") + + nsBaseEditorCommand::nsBaseEditorCommand() { NS_INIT_REFCNT(); @@ -85,6 +89,23 @@ nsUndoCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aC return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsUndoCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsUndoCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} NS_IMETHODIMP nsRedoCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -110,6 +131,23 @@ nsRedoCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aC return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsRedoCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsRedoCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} NS_IMETHODIMP nsCutCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -133,6 +171,24 @@ nsCutCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aCo return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsCutCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsCutCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} + NS_IMETHODIMP nsCutOrDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -164,6 +220,23 @@ nsCutOrDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISuppo return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsCutOrDeleteCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsCutOrDeleteCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} NS_IMETHODIMP nsCopyCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -187,6 +260,23 @@ nsCopyCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *aC return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsCopyCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsCopyCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} NS_IMETHODIMP nsCopyOrDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -218,6 +308,23 @@ nsCopyOrDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupp return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsCopyOrDeleteCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsCopyOrDeleteCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} NS_IMETHODIMP nsPasteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) @@ -252,6 +359,25 @@ nsPasteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports *a return rv; } +NS_IMETHODIMP +nsPasteCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsPasteCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} + + NS_IMETHODIMP nsDeleteCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) { @@ -313,6 +439,24 @@ nsDeleteCommand::DoCommand(const nsAReadableString & aCommandName, nsISupports * return aEditor->DeleteSelection(deleteDir); } +NS_IMETHODIMP +nsDeleteCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsDeleteCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} + NS_IMETHODIMP nsSelectAllCommand::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) { @@ -335,6 +479,25 @@ nsSelectAllCommand::DoCommand(const nsAReadableString & aCommandName, nsISupport return NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsSelectAllCommand::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsSelectAllCommand::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} + + NS_IMETHODIMP nsSelectionMoveCommands::IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *outCmdEnabled) { @@ -446,3 +609,21 @@ nsSelectionMoveCommands::DoCommand(const nsAReadableString & aCommandName, nsISu return NS_ERROR_FAILURE; } + +NS_IMETHODIMP +nsSelectionMoveCommands::DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + return DoCommand(tString,aCommandRefCon); +} + +NS_IMETHODIMP +nsSelectionMoveCommands::GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon) +{ + nsString tString; + aParams->GetStringValue(COMMAND_NAME,tString); + PRBool canUndo; + IsCommandEnabled(tString, aCommandRefCon, &canUndo); + return aParams->SetBooleanValue(STATE_ENABLED,canUndo); +} \ No newline at end of file diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.h b/mozilla/editor/libeditor/base/nsEditorCommands.h index 8fe6fd86080..8cd144d0ba8 100644 --- a/mozilla/editor/libeditor/base/nsEditorCommands.h +++ b/mozilla/editor/libeditor/base/nsEditorCommands.h @@ -67,6 +67,8 @@ class _cmd : public nsBaseEditorCommand \ public: \ NS_IMETHOD IsCommandEnabled(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon, PRBool *_retval); \ NS_IMETHOD DoCommand(const nsAReadableString & aCommandName, nsISupports *aCommandRefCon); \ + NS_IMETHOD DoCommandParams(nsICommandParams *aParams, nsISupports *aCommandRefCon); \ + NS_IMETHOD GetCommandState(nsICommandParams *aParams, nsISupports *aCommandRefCon); \ }; diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp index 3787d62454f..1ecb7ebb10d 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.cpp +++ b/mozilla/editor/libeditor/base/nsEditorController.cpp @@ -224,7 +224,7 @@ nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager if (!cmdManager) { nsresult rv; - cmdManager = do_CreateInstance("@mozilla.org/content/controller-command-manager;1", &rv); + cmdManager = do_CreateInstance(NS_CONTROLLERCOMMANDMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; // register the commands. This just happens once per instance diff --git a/mozilla/editor/libeditor/base/nsEditorController.h b/mozilla/editor/libeditor/base/nsEditorController.h index 82e325b0653..a86135302f2 100644 --- a/mozilla/editor/libeditor/base/nsEditorController.h +++ b/mozilla/editor/libeditor/base/nsEditorController.h @@ -46,6 +46,7 @@ #include "nsIController.h" #include "nsIEditorController.h" #include "nsIControllerCommand.h" +#include "nsIControllerCommandManager.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" diff --git a/mozilla/editor/libeditor/build/Makefile.in b/mozilla/editor/libeditor/build/Makefile.in index 0f51bce440e..18bbd6e1b46 100644 --- a/mozilla/editor/libeditor/build/Makefile.in +++ b/mozilla/editor/libeditor/build/Makefile.in @@ -53,6 +53,7 @@ REQUIRES = xpcom \ htmlparser \ appshell \ xuldoc \ + commandhandler \ $(NULL) ifdef MOZ_PLAINTEXT_EDITOR_ONLY diff --git a/mozilla/editor/libeditor/build/makefile.win b/mozilla/editor/libeditor/build/makefile.win index 194d4499417..14eae538d9e 100644 --- a/mozilla/editor/libeditor/build/makefile.win +++ b/mozilla/editor/libeditor/build/makefile.win @@ -33,6 +33,7 @@ REQUIRES = string \ necko \ appshell \ content_xul \ + commandhandler \ $(NULL) include <$(DEPTH)/config/config.mak> diff --git a/mozilla/editor/macbuild/EditorIDL.xml b/mozilla/editor/macbuild/EditorIDL.xml index 0b5ee789726..853ce1176de 100644 --- a/mozilla/editor/macbuild/EditorIDL.xml +++ b/mozilla/editor/macbuild/EditorIDL.xml @@ -85,6 +85,16 @@ FrameworkPathfalse HostFlagsAll + + SearchPath + Path::composer:public: + PathFormatMacOS + PathRootProject + + Recursivetrue + FrameworkPathfalse + HostFlagsAll + SystemSearchPaths @@ -307,7 +317,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password253zwcn56thc2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -808,6 +818,13 @@ Text + + Name + nsIEditingSession.idl + MacOS + Text + + @@ -880,6 +897,11 @@ nsIURIRefObject.idl MacOS + + Name + nsIEditingSession.idl + MacOS + @@ -914,6 +936,16 @@ FrameworkPathfalse HostFlagsAll + + SearchPath + Path::composer:public: + PathFormatMacOS + PathRootProject + + Recursivetrue + FrameworkPathfalse + HostFlagsAll + SystemSearchPaths @@ -1136,7 +1168,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password253zwcn56thc2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion1 MWFTP_Post_ftp_PathType0 @@ -1637,6 +1669,13 @@ Text + + Name + nsIEditingSession.idl + MacOS + Text + + @@ -1709,6 +1748,11 @@ nsIURIRefObject.idl MacOS + + Name + nsIEditingSession.idl + MacOS + @@ -1803,6 +1847,12 @@ nsIURIRefObject.idl MacOS + + editor.xpt + Name + nsIEditingSession.idl + MacOS + diff --git a/mozilla/editor/macbuild/composer.xml b/mozilla/editor/macbuild/composer.xml index 44825c369e7..7aecd3f3b3e 100644 --- a/mozilla/editor/macbuild/composer.xml +++ b/mozilla/editor/macbuild/composer.xml @@ -527,7 +527,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2643qwan646iha2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -1035,6 +1035,20 @@ Library Debug + + Name + nsEditingSession.cpp + MacOS + Text + Debug + + + Name + nsComposerCommandsUpdater.cpp + MacOS + Text + Debug + @@ -1112,6 +1126,16 @@ nsComposerRegistration.cpp MacOS + + Name + nsEditingSession.cpp + MacOS + + + Name + nsComposerCommandsUpdater.cpp + MacOS + @@ -1588,7 +1612,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2643qwan646iha2ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -2096,6 +2120,20 @@ Library Debug + + Name + nsEditingSession.cpp + MacOS + Text + Debug + + + Name + nsComposerCommandsUpdater.cpp + MacOS + Text + Debug + @@ -2173,6 +2211,16 @@ nsComposerRegistration.cpp MacOS + + Name + nsEditingSession.cpp + MacOS + + + Name + nsComposerCommandsUpdater.cpp + MacOS + @@ -2226,6 +2274,18 @@ nsComposerRegistration.cpp MacOS + + ComposerDebug.shlb + Name + nsEditingSession.cpp + MacOS + + + ComposerDebug.shlb + Name + nsComposerCommandsUpdater.cpp + MacOS + Static Libs diff --git a/mozilla/editor/macbuild/editor.xml b/mozilla/editor/macbuild/editor.xml index c392185a26b..c2f61d40788 100644 --- a/mozilla/editor/macbuild/editor.xml +++ b/mozilla/editor/macbuild/editor.xml @@ -517,7 +517,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jqwun5jqey2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -2048,7 +2048,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jqwun5jqey2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -3567,7 +3567,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jqwun5jqey2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -4942,7 +4942,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password25jqwun5jqey2Ù±ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -6155,7 +6155,7 @@ Static Libs - PlainTextEditor.shlb + HTMLEditor.shlb Name UnicharUtilsStatic.o MacOS @@ -6170,31 +6170,31 @@ NS Libraries Optimized - PlainTextEditor.shlb + HTMLEditor.shlb Name NSStdLib.shlb MacOS - PlainTextEditor.shlb + HTMLEditor.shlb Name NSRuntime.shlb MacOS - PlainTextEditor.shlb + HTMLEditor.shlb Name NSPR20.shlb MacOS - PlainTextEditor.shlb + HTMLEditor.shlb Name xpcom.shlb MacOS - PlainTextEditor.shlb + HTMLEditor.shlb Name JavaScript.shlb MacOS diff --git a/mozilla/embedding/components/Makefile.in b/mozilla/embedding/components/Makefile.in index 7c44044c778..05b640702dd 100644 --- a/mozilla/embedding/components/Makefile.in +++ b/mozilla/embedding/components/Makefile.in @@ -24,6 +24,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = windowwatcher appstartup find ui jsconsole webbrowserpersist build +DIRS = windowwatcher appstartup find ui jsconsole webbrowserpersist commandhandler build include $(topsrcdir)/config/rules.mk diff --git a/mozilla/embedding/components/build/Makefile.in b/mozilla/embedding/components/build/Makefile.in index 36eec28e2ec..5d8cefd62cc 100644 --- a/mozilla/embedding/components/build/Makefile.in +++ b/mozilla/embedding/components/build/Makefile.in @@ -49,6 +49,8 @@ REQUIRES = js \ content \ uriloader \ necko \ + commandhandler \ + content_xul \ $(NULL) CPPSRCS = nsModule.cpp @@ -59,6 +61,7 @@ SHARED_LIBRARY_LIBS = \ $(DIST)/lib/$(LIB_PREFIX)jsconsole_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)find_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)webbrowserpersist_s.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)commandhandler_s.$(LIB_SUFFIX) \ $(NULL) LOCAL_INCLUDES = \ @@ -67,6 +70,7 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../jsconsole/src \ -I$(srcdir)/../find/src \ -I$(srcdir)/../webbrowserpersist/src \ + -I$(srcdir/../commandhandler/src \ $(NULL) EXTRA_DSO_LDOPTS = \ diff --git a/mozilla/embedding/components/build/macbuild/EmbedComponents.xml b/mozilla/embedding/components/build/macbuild/EmbedComponents.xml index cec2b168520..89c0cbd2c6f 100644 --- a/mozilla/embedding/components/build/macbuild/EmbedComponents.xml +++ b/mozilla/embedding/components/build/macbuild/EmbedComponents.xml @@ -534,7 +534,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password264jrwaw64jreeaÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -1077,6 +1077,34 @@ Library Debug + + Name + nsCommandGroup.cpp + MacOS + Text + Debug + + + Name + nsCommandManager.cpp + MacOS + Text + Debug + + + Name + nsCommandParams.cpp + MacOS + Text + Debug + + + Name + nsControllerCommandManager.cpp + MacOS + Text + Debug + @@ -1179,6 +1207,26 @@ UnicharUtilsStaticDebug.o MacOS + + Name + nsCommandGroup.cpp + MacOS + + + Name + nsCommandManager.cpp + MacOS + + + Name + nsCommandParams.cpp + MacOS + + + Name + nsControllerCommandManager.cpp + MacOS + @@ -2205,6 +2253,34 @@ Unknown Debug + + Name + nsCommandGroup.cpp + MacOS + Text + Debug + + + Name + nsCommandManager.cpp + MacOS + Text + Debug + + + Name + nsCommandParams.cpp + MacOS + Text + Debug + + + Name + nsControllerCommandManager.cpp + MacOS + Text + Debug + @@ -2307,6 +2383,26 @@ UnicharUtilsStatic.o MacOS + + Name + nsCommandGroup.cpp + MacOS + + + Name + nsCommandManager.cpp + MacOS + + + Name + nsCommandParams.cpp + MacOS + + + Name + nsControllerCommandManager.cpp + MacOS + @@ -2340,6 +2436,30 @@ CommandHandler + + EmbedComponentsDebug.shlb + Name + nsCommandGroup.cpp + MacOS + + + EmbedComponentsDebug.shlb + Name + nsCommandManager.cpp + MacOS + + + EmbedComponentsDebug.shlb + Name + nsCommandParams.cpp + MacOS + + + EmbedComponentsDebug.shlb + Name + nsControllerCommandManager.cpp + MacOS + WindowWatcher @@ -2413,8 +2533,8 @@ Name UnicharUtilsStaticDebug.o MacOS - - + + NS Libraries Debug diff --git a/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml b/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml index 55cec6989ba..2f130d937e2 100644 --- a/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml +++ b/mozilla/embedding/components/build/macbuild/EmbedComponentsIDL.xml @@ -327,7 +327,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2653rsap653rae3ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -814,6 +814,34 @@ Text + + Name + nsICommandParams.idl + MacOS + Text + + + + Name + nsPICommandUpdater.idl + MacOS + Text + + + + Name + nsIControllerCommand.idl + MacOS + Text + + + + Name + nsIControllerCommandManager.idl + MacOS + Text + + @@ -876,6 +904,26 @@ nsCWebBrowserPersist.idl MacOS + + Name + nsICommandParams.idl + MacOS + + + Name + nsPICommandUpdater.idl + MacOS + + + Name + nsIControllerCommand.idl + MacOS + + + Name + nsIControllerCommandManager.idl + MacOS + @@ -1152,7 +1200,7 @@ MWFTP_Post_hostName MWFTP_Post_username - MWFTP_Post_password0 + MWFTP_Post_password2653rsap653rae3ÀÑ“( MWFTP_Post_remoteDir MWFTP_Post_ftp_PathVersion0 MWFTP_Post_ftp_PathType0 @@ -1639,6 +1687,34 @@ Text + + Name + nsICommandParams.idl + MacOS + Text + + + + Name + nsPICommandUpdater.idl + MacOS + Text + + + + Name + nsIControllerCommand.idl + MacOS + Text + + + + Name + nsIControllerCommandManager.idl + MacOS + Text + + @@ -1701,6 +1777,26 @@ nsCWebBrowserPersist.idl MacOS + + Name + nsICommandParams.idl + MacOS + + + Name + nsPICommandUpdater.idl + MacOS + + + Name + nsIControllerCommand.idl + MacOS + + + Name + nsIControllerCommandManager.idl + MacOS + @@ -1783,6 +1879,30 @@ nsPIWindowWatcher.idl MacOS + + headers + Name + nsICommandParams.idl + MacOS + + + headers + Name + nsPICommandUpdater.idl + MacOS + + + headers + Name + nsIControllerCommand.idl + MacOS + + + headers + Name + nsIControllerCommandManager.idl + MacOS + diff --git a/mozilla/embedding/components/build/makefile.win b/mozilla/embedding/components/build/makefile.win index a6b752262c0..165e30e9c48 100644 --- a/mozilla/embedding/components/build/makefile.win +++ b/mozilla/embedding/components/build/makefile.win @@ -35,6 +35,8 @@ REQUIRES = js \ necko \ content \ uriloader \ + commandhandler \ + content_xul \ $(NULL) include <$(DEPTH)\config\config.mak> @@ -54,6 +56,7 @@ SUB_LIBRARIES = \ $(DIST)\lib\appstartupnotifier_s.lib \ $(DIST)\lib\find_s.lib \ $(DIST)\lib\webbrowserpersist_s.lib \ + $(DIST)\lib\commandhandler_s.lib \ $(NULL) LLIBS = \ @@ -69,6 +72,7 @@ INCS = $(INCS) \ -I$(DEPTH)\embedding\components\appstartup\src \ -I$(DEPTH)\embedding\components\find\src \ -I$(DEPTH)\embedding\components\webbrowserpersist\src \ + -I$(DEPTH)\embedding\components\commandhandler\src \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/embedding/components/build/nsModule.cpp b/mozilla/embedding/components/build/nsModule.cpp index da44c0f0303..681bf9cbe72 100644 --- a/mozilla/embedding/components/build/nsModule.cpp +++ b/mozilla/embedding/components/build/nsModule.cpp @@ -44,6 +44,10 @@ #include "nsJSConsoleService.h" #include "nsWebBrowserFind.h" #include "nsWebBrowserPersist.h" +#include "nsCommandManager.h" +#include "nsControllerCommandManager.h" +#include "nsCommandParams.h" +#include "nsCommandGroup.h" NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPromptService, Init) @@ -52,7 +56,11 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppStartupNotifier) NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSConsoleService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserFind) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWebBrowserPersist) - +NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandManager) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandManager) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCommandParams, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup) + static const nsModuleComponentInfo gComponents[] = { { "Dialog ParamBlock", NS_DIALOGPARAMBLOCK_CID, NS_DIALOGPARAMBLOCK_CONTRACTID, nsDialogParamBlockConstructor }, @@ -61,7 +69,11 @@ static const nsModuleComponentInfo gComponents[] = { { "Window Watcher", NS_WINDOWWATCHER_CID, NS_WINDOWWATCHER_CONTRACTID, nsWindowWatcherConstructor }, { "Find", NS_WEB_BROWSER_FIND_CID, NS_WEB_BROWSER_FIND_CONTRACTID, nsWebBrowserFindConstructor }, { NS_APPSTARTUPNOTIFIER_CLASSNAME, NS_APPSTARTUPNOTIFIER_CID, NS_APPSTARTUPNOTIFIER_CONTRACTID, nsAppStartupNotifierConstructor }, - { "WebBrowserPersist Component", NS_WEBBROWSERPERSIST_CID, NS_WEBBROWSERPERSIST_CONTRACTID, nsWebBrowserPersistConstructor } + { "WebBrowserPersist Component", NS_WEBBROWSERPERSIST_CID, NS_WEBBROWSERPERSIST_CONTRACTID, nsWebBrowserPersistConstructor }, + { "Controller Command Manager", NS_CONTROLLERCOMMANDMANAGER_CID, NS_CONTROLLERCOMMANDMANAGER_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 } }; NS_IMPL_NSGETMODULE(embedcomponents, gComponents) diff --git a/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL b/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL index e51f996e350..8cf29d04e42 100644 --- a/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL +++ b/mozilla/embedding/components/commandhandler/public/MANIFEST_IDL @@ -1,3 +1,5 @@ nsICommandManager.idl nsPICommandUpdater.idl nsICommandParams.idl +nsIControllerCommand.idl +nsIControllerCommandManager.idl \ No newline at end of file diff --git a/mozilla/embedding/components/makefile.win b/mozilla/embedding/components/makefile.win index 944b02fac1f..2d8486121a2 100644 --- a/mozilla/embedding/components/makefile.win +++ b/mozilla/embedding/components/makefile.win @@ -24,6 +24,7 @@ DIRS= \ windowwatcher \ appstartup \ find \ + commandhandler \ jsconsole \ ui \ webbrowserpersist \ diff --git a/mozilla/embedding/tests/mfcembed/BrowserFrm.cpp b/mozilla/embedding/tests/mfcembed/BrowserFrm.cpp index 9375069d960..48bcb684450 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserFrm.cpp +++ b/mozilla/embedding/tests/mfcembed/BrowserFrm.cpp @@ -76,6 +76,7 @@ #include "stdafx.h" #include "MfcEmbed.h" #include "BrowserFrm.h" +#include "BrowserImpl.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -83,6 +84,13 @@ static char THIS_FILE[] = __FILE__; #endif + +//prototypes +nsresult GetStateCommandParams(nsICommandParams **aParams); + + +#define ABOUT_BLANK "about:blank" + ///////////////////////////////////////////////////////////////////////////// // CBrowserFrame @@ -95,6 +103,13 @@ BEGIN_MESSAGE_MAP(CBrowserFrame, CFrameWnd) ON_WM_SIZE() ON_WM_CLOSE() ON_WM_ACTIVATE() + ON_COMMAND(ID_NEW_EDITWINDOW, OnNewEditor) + ON_COMMAND(ID_BOLD, OnBold) + ON_UPDATE_COMMAND_UI(ID_BOLD, OnUpdateBold) + ON_COMMAND(ID_ITALICS, OnItalics) + ON_UPDATE_COMMAND_UI(ID_ITALICS, OnUpdateItalics) + ON_COMMAND(ID_UNDERLINE, OnUnderline) + ON_UPDATE_COMMAND_UI(ID_UNDERLINE, OnUpdateUnderline) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -115,6 +130,8 @@ CBrowserFrame::CBrowserFrame(PRUint32 chromeMask) // will have menubar, toolbar, statusbar etc. m_chromeMask = chromeMask; + mIsEditor = FALSE; + NS_ADDREF(&mToolBarObserver);//make sure no one releases this } CBrowserFrame::~CBrowserFrame() @@ -170,16 +187,22 @@ int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) // Load the Most Recently Used(MRU) Urls into the UrlBar m_wndUrlBar.LoadMRUList(); - // Create the toolbar with Back, Fwd, Stop, etc. buttons.. + UINT resID = IDR_MAINFRAME; + if (mIsEditor) + resID = IDR_EDITOR; + + // Create the toolbar with Back, Fwd, Stop, etc. buttons.. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || - !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) + !m_wndToolBar.LoadToolBar(resID)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } - // Create a ReBar window to which the toolbar and UrlBar + mToolBarObserver.SetFrame(this,ID_TOOLBAR_UPDATE,100); //update if 100 ticks goes by and no more changes + + // Create a ReBar window to which the toolbar and UrlBar // will be added if (!m_wndReBar.Create(this)) { @@ -189,7 +212,8 @@ int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) //Add the ToolBar and UrlBar windows to the rebar m_wndReBar.AddBar(&m_wndToolBar); - m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:"); + if (!mIsEditor) + m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:"); // Create the status bar with two panes - one pane for actual status // text msgs. and the other for the progress control @@ -391,3 +415,98 @@ void CMyStatusBar::OnLButtonDown(UINT nFlags, CPoint point) CStatusBar::OnLButtonDown(nFlags, point); } + +void CBrowserFrame::OnNewEditor() +{ + // TODO: Add your command handler code here + // TODO: Add your command handler code here + // TODO: Add your command handler code here + // TODO: Add your command handler code here + CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); + + CBrowserFrame *pEditorFrame = pApp->CreateNewBrowserFrame(nsIWebBrowserChrome::CHROME_ALL, + -1, -1, -1, -1, + PR_TRUE,PR_TRUE); + if (pEditorFrame) + { + CString tUrl; + m_wndUrlBar.GetEnteredURL(tUrl); + pEditorFrame->m_wndBrowserView.OpenURL(ABOUT_BLANK); + CBrowserImpl *impl = pEditorFrame->GetBrowserImpl(); + if (impl) + { + ((CEditorImpl *)impl)->AddEditorObservers(&mToolBarObserver); + ((CEditorImpl *)impl)->MakeEditable(); + } + } +} + + +/* +"bold" +state_all //setter and getter +state_begin //getter +state_end //getter +state_mixed //getter +*/ +#define COMMAND_NAME NS_ConvertASCIItoUCS2("cmd_name") +#define STATE_ALL NS_ConvertASCIItoUCS2("state_all") + +#define BOLD_COMMAND NS_ConvertASCIItoUCS2("cmd_bold") + +void CBrowserFrame::OnBold() +{ + // TODO: Add your command handler code here + nsresult rv; + nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + if (NS_FAILED(rv) || !params) + return; + params->SetBooleanValue(STATE_ALL,true); + params->SetStringValue(COMMAND_NAME,BOLD_COMMAND); + CEditorImpl *impl = (CEditorImpl *)GetBrowserImpl(); + if (impl) + impl->DoCommand(params); +} + +void CBrowserFrame::OnUpdateBold(CCmdUI* pCmdUI) +{ + // TODO: Add your command update UI handler code here + nsresult rv; + nsCOMPtr params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv); + params->SetStringValue(COMMAND_NAME,BOLD_COMMAND); + CEditorImpl *impl = (CEditorImpl *)GetBrowserImpl(); + if (impl) + { + rv = impl->GetCommandState(params); + if (NS_SUCCEEDED(rv)) + { + //set tri state of button here if we need to + } + } + //just return true for now + pCmdUI->Enable(); +} + +void CBrowserFrame::OnItalics() +{ + // TODO: Add your command handler code here + +} + +void CBrowserFrame::OnUpdateItalics(CCmdUI* pCmdUI) +{ + // TODO: Add your command update UI handler code here + +} + +void CBrowserFrame::OnUnderline() +{ + // TODO: Add your command handler code here + +} + +void CBrowserFrame::OnUpdateUnderline(CCmdUI* pCmdUI) +{ + // TODO: Add your command update UI handler code here + +} diff --git a/mozilla/embedding/tests/mfcembed/BrowserFrm.h b/mozilla/embedding/tests/mfcembed/BrowserFrm.h index df47ef602bc..22cc2410f42 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserFrm.h +++ b/mozilla/embedding/tests/mfcembed/BrowserFrm.h @@ -51,6 +51,7 @@ #include "BrowserView.h" #include "IBrowserFrameGlue.h" #include "MostRecentUrls.h" +#include "CCommandObserver.h" // A simple UrlBar class... class CUrlBar : public CComboBoxEx @@ -191,6 +192,8 @@ protected: public: void SetupFrameChrome(); + void SetEditable(BOOL isEditor){mIsEditor = isEditor;} + BOOL GetEditable(){return mIsEditor;} // Overrides // ClassWizard generated virtual function overrides @@ -215,8 +218,18 @@ protected: afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnClose(); afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized); + afx_msg void OnNewEditor(); + afx_msg void OnBold(); + afx_msg void OnUpdateBold(CCmdUI* pCmdUI); + afx_msg void OnItalics(); + afx_msg void OnUpdateItalics(CCmdUI* pCmdUI); + afx_msg void OnUnderline(); + afx_msg void OnUpdateUnderline(CCmdUI* pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() +private: + BOOL mIsEditor; + CCommandObserver mToolBarObserver; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/embedding/tests/mfcembed/BrowserImpl.cpp b/mozilla/embedding/tests/mfcembed/BrowserImpl.cpp index 0406cdfa093..7650a07fdf0 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserImpl.cpp +++ b/mozilla/embedding/tests/mfcembed/BrowserImpl.cpp @@ -81,6 +81,12 @@ #endif #include "nsIDOMWindow.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDocShell.h" +#include "nsISimpleEnumerator.h" + +#include "nsIEditingSession.h" +#include "nsICommandManager.h" #include "BrowserImpl.h" CBrowserImpl::CBrowserImpl() @@ -381,3 +387,121 @@ NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility) return NS_OK; } + + + +//EDITORIMPL + +NS_METHOD +CEditorImpl::MakeEditable() +{ + nsresult rv; + nsCOMPtr domWindow; + mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (!domWindow) + return NS_ERROR_FAILURE; + nsCOMPtr scriptGlobalObject = do_QueryInterface(domWindow); + if (!scriptGlobalObject) + return NS_ERROR_FAILURE; + nsCOMPtr docShell; + rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); + if (NS_FAILED(rv)) + return rv; + if (!docShell) + return NS_ERROR_FAILURE; + + + + nsCOMPtr editingSession = do_GetInterface(docShell); + if (!editingSession) + return NS_ERROR_FAILURE; + + rv= editingSession->MakeWindowEditable(domWindow, PR_TRUE); + // this can fail for the root (if it's a frameset), but we still want + // to make children editable + + nsCOMPtr docShellEnumerator; + docShell->GetDocShellEnumerator( nsIDocShellTreeItem::typeContent, + nsIDocShell::ENUMERATE_FORWARDS, + getter_AddRefs(docShellEnumerator)); + if (docShellEnumerator) + { + PRBool hasMore; + while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) && hasMore) + { + nsCOMPtr curSupports; + rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports)); + if (NS_FAILED(rv)) break; + + nsCOMPtr curShell = do_QueryInterface(curSupports, &rv); + if (NS_FAILED(rv)) break; + + nsCOMPtr childWindow = do_GetInterface(curShell,&rv); + if (childWindow) + editingSession->MakeWindowEditable(childWindow, PR_FALSE); + } + } + return NS_OK; +} + + +//nsIObserver + +NS_IMETHODIMP +CEditorImpl::AddEditorObservers(nsIObserver *aObserver) +{ + nsCOMPtr commandManager; + nsresult rv; + commandManager = do_GetInterface(mWebBrowser,&rv); + if (commandManager) + { + nsAutoString tString(NS_LITERAL_STRING("cmd_bold")); + rv = commandManager->AddCommandObserver(aObserver,tString); + tString = NS_LITERAL_STRING("cmd_italic"); + rv = commandManager->AddCommandObserver(aObserver,tString); + tString = NS_LITERAL_STRING("cmd_underline"); + rv = commandManager->AddCommandObserver(aObserver,tString); + } + return rv; +} + + +NS_IMETHODIMP +CEditorImpl::DoCommand(nsICommandParams *aCommandParams) +{ + nsCOMPtr commandManager; + nsresult rv = NS_ERROR_FAILURE; + commandManager = do_GetInterface(mWebBrowser,&rv); + if (commandManager) + { + rv = commandManager->DoCommand(aCommandParams); + } + return rv; +} + +NS_IMETHODIMP +CEditorImpl::IsCommandEnabled(const nsAString &aCommand, PRBool *retval) +{ + nsCOMPtr commandManager; + nsresult rv = NS_ERROR_FAILURE; + commandManager = do_GetInterface(mWebBrowser,&rv); + if (commandManager) + { + rv = commandManager->IsCommandEnabled(aCommand,retval); + } + return rv; +} + + +NS_IMETHODIMP +CEditorImpl::GetCommandState(nsICommandParams *aCommandParams) +{ + nsCOMPtr commandManager; + nsresult rv = NS_ERROR_FAILURE; + commandManager = do_GetInterface(mWebBrowser,&rv); + if (commandManager) + { + rv = commandManager->GetCommandState(aCommandParams); + } + return rv; +} \ No newline at end of file diff --git a/mozilla/embedding/tests/mfcembed/BrowserImpl.h b/mozilla/embedding/tests/mfcembed/BrowserImpl.h index 4825f593faf..63a72d78498 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserImpl.h +++ b/mozilla/embedding/tests/mfcembed/BrowserImpl.h @@ -42,6 +42,7 @@ #include "IBrowserFrameGlue.h" #include "nsIWebBrowserChromeFocus.h" +#include "nsICommandParams.h" class CBrowserImpl : public nsIInterfaceRequestor, public nsIWebBrowserChrome, @@ -72,4 +73,16 @@ protected: nsCOMPtr mWebBrowser; }; +class CEditorImpl : public CBrowserImpl +{ +public: + CEditorImpl(){}; + virtual ~CEditorImpl(){}; + NS_METHOD MakeEditable(); + NS_METHOD AddEditorObservers(nsIObserver *aObserver); + NS_METHOD DoCommand(nsICommandParams *aCommandParams); + NS_METHOD IsCommandEnabled(const nsAString &aCommand, PRBool *retval); + NS_METHOD GetCommandState(nsICommandParams *aCommandParams); +}; + #endif //_BROWSERIMPL_H diff --git a/mozilla/embedding/tests/mfcembed/Makefile.in b/mozilla/embedding/tests/mfcembed/Makefile.in index 209e290e88e..9cfab78758a 100644 --- a/mozilla/embedding/tests/mfcembed/Makefile.in +++ b/mozilla/embedding/tests/mfcembed/Makefile.in @@ -47,6 +47,8 @@ REQUIRES = \ windowwatcher \ layout \ webbrowserpersist \ + composer \ + command_handler \ $(NULL) CPPSRCS = \ @@ -57,6 +59,7 @@ CPPSRCS = \ BrowserImpl.cpp \ BrowserImplWebPrgrsLstnr.cpp \ BrowserImplCtxMenuLstnr.cpp \ + CCommandObserver.cpp \ Dialogs.cpp \ ProfileMgr.cpp \ ProfilesDlg.cpp \ diff --git a/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp b/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp index 4536d03c9db..89f5a9fd3fa 100644 --- a/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/mozilla/embedding/tests/mfcembed/MfcEmbed.cpp @@ -330,8 +330,12 @@ BOOL CMfcEmbedApp::InitInstance() CBrowserFrame* CMfcEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, + PRBool bIsEditor, PRBool bShowWindow) { + UINT resId = IDR_MAINFRAME; + if (bIsEditor) + resId = IDR_EDITOR; // Setup a CRect with the requested window dimensions CRect winSize(x, y, cx, cy); @@ -345,8 +349,9 @@ CBrowserFrame* CMfcEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask, // Now, create the browser frame CBrowserFrame* pFrame = new CBrowserFrame(chromeMask); + pFrame->SetEditable(bIsEditor); if (!pFrame->Create(NULL, strTitle, WS_OVERLAPPEDWINDOW, - winSize, NULL, MAKEINTRESOURCE(IDR_MAINFRAME), 0L, NULL)) + winSize, NULL, MAKEINTRESOURCE(resId), 0L, NULL)) { return NULL; } diff --git a/mozilla/embedding/tests/mfcembed/MfcEmbed.h b/mozilla/embedding/tests/mfcembed/MfcEmbed.h index 2a36283202d..c8bbbc5f7ff 100644 --- a/mozilla/embedding/tests/mfcembed/MfcEmbed.h +++ b/mozilla/embedding/tests/mfcembed/MfcEmbed.h @@ -75,7 +75,7 @@ public: CBrowserFrame* CreateNewBrowserFrame(PRUint32 chromeMask = nsIWebBrowserChrome::CHROME_ALL, PRInt32 x = -1, PRInt32 y = -1, - PRInt32 cx = -1, PRInt32 cy = -1, + PRInt32 cx = -1, PRInt32 cy = -1,PRBool bIsEditor=PR_FALSE, PRBool bShowWindow = PR_TRUE); void RemoveFrameFromList(CBrowserFrame* pFrm, BOOL bCloseAppOnLastFrame = TRUE); diff --git a/mozilla/embedding/tests/mfcembed/MfcEmbed.rc b/mozilla/embedding/tests/mfcembed/MfcEmbed.rc index 43621b674c3..3248a032660 100644 --- a/mozilla/embedding/tests/mfcembed/MfcEmbed.rc +++ b/mozilla/embedding/tests/mfcembed/MfcEmbed.rc @@ -77,6 +77,7 @@ IDR_SECURITY_BROKEN ICON DISCARDABLE "res\\broken.ico" // IDR_MAINFRAME BITMAP MOVEABLE PURE "res\\Toolbar.bmp" +IDR_EDITOR BITMAP MOVEABLE PURE "res\\mainfram.bmp" ///////////////////////////////////////////////////////////////////////////// // @@ -96,6 +97,13 @@ BEGIN BUTTON ID_APP_ABOUT END +IDR_EDITOR TOOLBAR DISCARDABLE 20, 18 +BEGIN + BUTTON ID_BOLD + BUTTON ID_ITALICS + BUTTON ID_UNDERLINE +END + ///////////////////////////////////////////////////////////////////////////// // @@ -107,6 +115,7 @@ BEGIN POPUP "&File" BEGIN MENUITEM "&New Browser Window\tCtrl+N", ID_NEW_BROWSER + MENUITEM "&New Editor Window", ID_NEW_EDITWINDOW MENUITEM SEPARATOR MENUITEM "&Open File...\tCtrl+O", ID_FILE_OPEN MENUITEM "&Save Page As...\tCtrl+S", ID_FILE_SAVE_AS @@ -219,6 +228,41 @@ BEGIN END END +IDR_EDITOR MENU PRELOAD DISCARDABLE +BEGIN + POPUP "&File" + BEGIN + MENUITEM "New &Browser Window\tCtrl+N", ID_NEW_BROWSER + MENUITEM SEPARATOR + MENUITEM "&Open File...\tCtrl+O", ID_FILE_OPEN + MENUITEM "&Save Page As...\tCtrl+S", ID_FILE_SAVE_AS + MENUITEM SEPARATOR + MENUITEM "&Print...\tCtrl-P", ID_FILE_PRINT + MENUITEM SEPARATOR + MENUITEM "E&xit\tCtrl+Q", ID_APP_EXIT + MENUITEM "New &Editor Window", ID_NEW_EDITORWINDOW + END + POPUP "&Edit" + BEGIN + MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT + MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY + MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE + MENUITEM SEPARATOR + MENUITEM "Select &All", ID_EDIT_SELECT_ALL + MENUITEM "Select &None", ID_EDIT_SELECT_NONE + MENUITEM SEPARATOR + MENUITEM "&Find in This Page...\tCtrl+F", ID_EDIT_FIND + MENUITEM SEPARATOR + MENUITEM "Profiles...", ID_MANAGE_PROFILES + MENUITEM SEPARATOR + MENUITEM "Preferences...", ID_EDIT_PREFERENCES + END + POPUP "&Help" + BEGIN + MENUITEM "&About MfcEmbed...", ID_APP_ABOUT + END +END + ///////////////////////////////////////////////////////////////////////////// // @@ -525,6 +569,8 @@ BEGIN IDS_ENCRYPTION_LOW_GRADE "Low-grade Encryption (%1% %2!d! bit)" IDS_ENCRYPTION_NONE "Connection Not Encrypted" IDS_SRCH_STR_NOT_FOUND "The text you entered was not found" + IDS_VIEW_FRAME_SOURCE "View Frame Source" + IDS_OPEN_FRAME_IN_NEW_WINDOW "Open Frame in New Window" END STRINGTABLE PRELOAD DISCARDABLE @@ -597,8 +643,6 @@ STRINGTABLE DISCARDABLE BEGIN ID_FILE_PRINTPREVIEW "Print Preview" ID_FILE_PRINTSETUP "Page Setup Dialog" - IDS_VIEW_FRAME_SOURCE "View Frame Source" - IDS_OPEN_FRAME_IN_NEW_WINDOW "Open Frame in New Window" END #endif // English (U.S.) resources diff --git a/mozilla/embedding/tests/mfcembed/makefile.win b/mozilla/embedding/tests/mfcembed/makefile.win index c3dc5b80bbf..39410b07b59 100644 --- a/mozilla/embedding/tests/mfcembed/makefile.win +++ b/mozilla/embedding/tests/mfcembed/makefile.win @@ -39,6 +39,8 @@ REQUIRES = \ windowwatcher \ layout \ webbrowserpersist \ + composer \ + commandhandler \ $(NULL) DIRS=components \ @@ -61,6 +63,7 @@ OBJS = \ .\$(OBJDIR)\BrowserImpl.obj \ .\$(OBJDIR)\BrowserImplWebPrgrsLstnr.obj \ .\$(OBJDIR)\BrowserImplCtxMenuLstnr.obj \ + .\$(OBJDIR)\CCommandObserver.obj \ .\$(OBJDIR)\Dialogs.obj \ .\$(OBJDIR)\ProfileMgr.obj \ .\$(OBJDIR)\ProfilesDlg.obj \ diff --git a/mozilla/embedding/tests/mfcembed/mfcembed.dsp b/mozilla/embedding/tests/mfcembed/mfcembed.dsp index 720ac19f2bb..7734f0fd5d1 100644 --- a/mozilla/embedding/tests/mfcembed/mfcembed.dsp +++ b/mozilla/embedding/tests/mfcembed/mfcembed.dsp @@ -230,6 +230,10 @@ SOURCE=.\res\broken.ico # End Source File # Begin Source File +SOURCE=.\res\mainfram.bmp +# End Source File +# Begin Source File + SOURCE=.\res\mfcembed.ico # End Source File # Begin Source File @@ -245,5 +249,49 @@ SOURCE=.\res\ssecur.ico SOURCE=.\res\Toolbar.bmp # End Source File # End Group +# Begin Group "Interfaces" + +# PROP Default_Filter "*.idl" +# Begin Source File + +SOURCE=..\..\components\commandhandler\public\nsICommandManager.idl +# End Source File +# Begin Source File + +SOURCE=..\..\components\commandhandler\public\nsICommandParams.idl +# End Source File +# Begin Source File + +SOURCE=..\..\..\content\xul\document\public\nsIController.idl +# End Source File +# Begin Source File + +SOURCE=..\..\components\commandhandler\public\nsIControllerCommand.idl +# End Source File +# Begin Source File + +SOURCE=..\..\components\commandhandler\public\nsIControllerCommandManager.idl +# End Source File +# End Group +# Begin Group "implementations" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\components\commandhandler\src\nsCommandManager.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\components\commandhandler\src\nsCommandManager.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\editor\composer\src\nsComposerCommands.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\components\commandhandler\src\nsControllerCommandManager.cpp +# End Source File +# End Group # End Target # End Project diff --git a/mozilla/embedding/tests/mfcembed/resource.h b/mozilla/embedding/tests/mfcembed/resource.h index f9c217fd7a1..4d06ceca5e7 100644 --- a/mozilla/embedding/tests/mfcembed/resource.h +++ b/mozilla/embedding/tests/mfcembed/resource.h @@ -3,8 +3,10 @@ // Used by mfcembed.rc // #define IDD_ABOUTBOX 100 +#define ID_TOOLBAR_UPDATE 101 #define IDR_MAINFRAME 128 #define IDR_MOZEMBTYPE 129 +#define IDR_EDITOR 129 #define IDR_CTXMENU_DOCUMENT 130 #define IDR_CTXMENU_LINK 131 #define IDR_CTXMENU_TEXT 132 @@ -96,8 +98,13 @@ #define ID_EDIT_PREFERENCES 32788 #define ID_FILE_PRINTPREVIEW 32789 #define ID_FILE_PRINTSETUP 32790 +#define ID_NEW_EDITORWINDOW 32790 #define ID_VIEW_FRAME_SOURCE 32791 #define ID_OPEN_FRAME_IN_NEW_WINDOW 32792 +#define ID_BOLD 32793 +#define ID_UNDERLINE 32794 +#define ID_ITALICS 32795 +#define ID_NEW_EDITWINDOW 32796 // Next default values for new objects // @@ -105,8 +112,8 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_3D_CONTROLS 1 #define _APS_NEXT_RESOURCE_VALUE 155 -#define _APS_NEXT_COMMAND_VALUE 32793 +#define _APS_NEXT_COMMAND_VALUE 32797 #define _APS_NEXT_CONTROL_VALUE 1042 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_SYMED_VALUE 102 #endif #endif