diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp
index 54b3c2b961f..3996c577cb2 100644
--- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp
+++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp
@@ -1132,18 +1132,12 @@ nsHTMLInputElement::GetControllers(nsIControllers** aResult)
NS_ERROR_FAILURE);
if (!mControllers) { return NS_ERROR_NULL_POINTER; }
- nsCOMPtr controller;
- NS_ENSURE_SUCCESS (
- nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller",
- nsnull,
- NS_GET_IID(nsIController),
- getter_AddRefs(controller)),
- NS_ERROR_FAILURE);
- if (!controller) { return NS_ERROR_NULL_POINTER; }
nsresult rv;
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
nsCOMPtr editorController = do_QueryInterface(controller, &rv);
if (NS_FAILED(rv)) return rv;
- rv = editorController->Init();
+ rv = editorController->Init(nsnull);
if (NS_FAILED(rv)) return rv;
mControllers->AppendController(controller);
}
diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp
index 9f87e0983c6..0dd86122736 100644
--- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp
+++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp
@@ -605,19 +605,12 @@ nsHTMLTextAreaElement::GetControllers(nsIControllers** aResult)
NS_ERROR_FAILURE);
if (!mControllers) { return NS_ERROR_NULL_POINTER; }
- nsCOMPtr controller;
- NS_ENSURE_SUCCESS (
- nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller",
- nsnull,
- NS_GET_IID(nsIController),
- getter_AddRefs(controller)),
- NS_ERROR_FAILURE);
-
- if (!controller) { return NS_ERROR_NULL_POINTER; }
nsresult rv;
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
nsCOMPtr editorController = do_QueryInterface(controller, &rv);
if (NS_FAILED(rv)) return rv;
- rv = editorController->Init();
+ rv = editorController->Init(nsnull);
if (NS_FAILED(rv)) return rv;
mControllers->AppendController(controller);
diff --git a/mozilla/editor/base/nsEditorCommands.cpp b/mozilla/editor/base/nsEditorCommands.cpp
index 2a623f6dff2..c4db3ecb12a 100644
--- a/mozilla/editor/base/nsEditorCommands.cpp
+++ b/mozilla/editor/base/nsEditorCommands.cpp
@@ -38,13 +38,12 @@ nsBaseCommand::nsBaseCommand()
NS_INIT_REFCNT();
}
-
-nsBaseCommand::~nsBaseCommand()
-{
-}
-
NS_IMPL_ISUPPORTS(nsBaseCommand, NS_GET_IID(nsIControllerCommand));
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
NS_IMETHODIMP
nsUndoCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
diff --git a/mozilla/editor/base/nsEditorCommands.h b/mozilla/editor/base/nsEditorCommands.h
index 497b1da716f..95cd5c15059 100644
--- a/mozilla/editor/base/nsEditorCommands.h
+++ b/mozilla/editor/base/nsEditorCommands.h
@@ -34,7 +34,7 @@ class nsBaseCommand : public nsIControllerCommand
public:
nsBaseCommand();
- virtual ~nsBaseCommand();
+ virtual ~nsBaseCommand() {}
NS_DECL_ISUPPORTS
@@ -44,13 +44,16 @@ public:
};
-#define NS_DECL_EDITOR_COMMAND(_cmd) \
-class _cmd : public nsBaseCommand \
-{ \
-public: \
- NS_DECL_NSICONTROLLERCOMMAND \
+#define NS_DECL_EDITOR_COMMAND(_cmd) \
+class _cmd : public nsBaseCommand \
+{ \
+public: \
+ NS_DECL_NSICONTROLLERCOMMAND \
};
+
+
+// basic editor commands
NS_DECL_EDITOR_COMMAND(nsUndoCommand)
NS_DECL_EDITOR_COMMAND(nsRedoCommand)
@@ -63,4 +66,23 @@ NS_DECL_EDITOR_COMMAND(nsSelectAllCommand)
NS_DECL_EDITOR_COMMAND(nsSelectionMoveCommands)
+
+#if 0
+// template for new command
+NS_IMETHODIMP
+nsFooCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+
+NS_IMETHODIMP
+nsFooCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+
+#endif
+
#endif // nsIEditorCommand_h_
diff --git a/mozilla/editor/base/nsEditorController.cpp b/mozilla/editor/base/nsEditorController.cpp
index 5b9e2ce5bac..9f5ab309c8f 100644
--- a/mozilla/editor/base/nsEditorController.cpp
+++ b/mozilla/editor/base/nsEditorController.cpp
@@ -24,6 +24,7 @@
#include "nsIComponentManager.h"
#include "nsEditorController.h"
#include "nsIEditor.h"
+#include "nsIEditorShell.h"
#include "nsIEditorMailSupport.h"
#include "nsIFormControlFrame.h"
#include "nsIDOMSelection.h"
@@ -36,7 +37,7 @@
#include "nsIPresShell.h"
#include "nsEditorCommands.h"
-
+#include "nsComposerCommands.h"
#define kMaxStackCommandNameLength 128
@@ -47,31 +48,49 @@ NS_IMPL_RELEASE(nsEditorController)
NS_INTERFACE_MAP_BEGIN(nsEditorController)
NS_INTERFACE_MAP_ENTRY(nsIController)
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
+ NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
NS_INTERFACE_MAP_END
nsEditorController::nsEditorController()
-: mContent(NULL)
-, mEditor(NULL)
+: mCommandRefCon(nsnull)
{
NS_INIT_REFCNT();
}
nsEditorController::~nsEditorController()
{
- // if the singleton command manger has a refcount of 1 at this point, we need to
- // set it to null
}
-NS_IMETHODIMP nsEditorController::Init()
+NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon)
{
nsresult rv;
// get our ref to the singleton command manager
- rv = GetCommandManager(getter_AddRefs(mCommandManager));
+ rv = GetEditorCommandManager(getter_AddRefs(mCommandManager));
if (NS_FAILED(rv)) return rv;
+
+ mCommandRefCon = aCommandRefCon; // no addref
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsEditorController::SetCommandRefCon(nsISupports *aCommandRefCon)
+{
+ mCommandRefCon = aCommandRefCon; // no addref
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsEditorController::GetInterface(const nsIID & aIID, void * *result)
+{
+ NS_ENSURE_ARG_POINTER(result);
+
+ if (NS_SUCCEEDED(QueryInterface(aIID, result)))
+ return NS_OK;
- return rv;
+ if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
+ return mCommandManager->QueryInterface(aIID, result);
+
+ return NS_NOINTERFACE;
}
@@ -100,6 +119,8 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
nsresult rv;
// now register all our commands
+ // These are commands that will be used in text widgets, and in composer
+
NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo");
NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
@@ -107,8 +128,7 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
- NS_REGISTER_FIRST_COMMAND(nsPasteCommand, "cmd_paste");
- NS_REGISTER_LAST_COMMAND(nsPasteCommand, "cmd_pasteQuote");
+ NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");
NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete");
NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward");
@@ -166,106 +186,23 @@ nsresult nsEditorController::RegisterOneCommand(const PRUnichar* aCommandName,
return inCommandManager->RegisterCommand(aCommandName, editorCommand); // this is the owning ref
}
-
-NS_IMETHODIMP nsEditorController::SetContent(nsIHTMLContent *aContent)
-{
- // indiscriminately sets mContent, no ref counting here
- mContent = aContent;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsEditorController::SetEditor(nsIEditor *aEditor)
-{
- // null editors are allowed
- mEditor = aEditor;
- return NS_OK;
-}
-
-
/* =======================================================================
* nsIController
* ======================================================================= */
NS_IMETHODIMP nsEditorController::IsCommandEnabled(const PRUnichar *aCommand, PRBool *aResult)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- NS_ENSURE_ARG_POINTER(aResult);
-
- *aResult = PR_FALSE;
-
- nsCOMPtr editor;
- NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE);
- // a null editor is a legal state
- if (!editor)
- return NS_OK; // just say we don't handle the command
-
- if (!mCommandManager)
- {
- NS_ASSERTION(0, "No command handler!");
- return NS_ERROR_UNEXPECTED;
- }
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- if (!commandHandler)
- {
-#if DEBUG
- nsCAutoString msg("EditorController asked about a command that it does not handle -- ");
- msg.AppendWithConversion(aCommand);
- NS_WARNING(msg);
-#endif
- return NS_OK; // we don't handle this command
- }
-
- return commandHandler->IsCommandEnabled(aCommand, editor, aResult);
+ return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::SupportsCommand(const PRUnichar *aCommand, PRBool *aResult)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- NS_ENSURE_ARG_POINTER(aResult);
-
- // XXX: need to check the readonly and disabled states
-
- *aResult = PR_FALSE;
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- *aResult = (commandHandler.get() != NULL);
- return NS_OK;
+ return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::DoCommand(const PRUnichar *aCommand)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- nsCOMPtr editor;
- nsCOMPtr selCont;
- NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE);
- if (!editor)
- { // Q: What does it mean if there is no editor?
- // A: It means we've never had focus, so we can't do anything
- return NS_OK;
- }
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- if (!commandHandler)
- {
-#if DEBUG
- nsCAutoString msg("EditorController asked to do a command that it does not handle -- ");
- msg.AppendWithConversion(aCommand);
- NS_WARNING(msg);
-#endif
- return NS_OK; // we don't handle this command
- }
-
- return commandHandler->DoCommand(aCommand, editor);
+ return mCommandManager->DoCommand(aCommand, mCommandRefCon);
}
NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName)
@@ -275,52 +212,6 @@ NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName)
return NS_OK;
}
-
-NS_IMETHODIMP nsEditorController::GetEditor(nsIEditor ** aEditor)
-{
- NS_ENSURE_ARG_POINTER(aEditor);
- if (mEditor)
- {
- *aEditor = mEditor;
- NS_ADDREF(*aEditor);
- return NS_OK;
- }
- return NS_OK;
-}
-
-NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController ** aSelCon)
-{
- nsCOMPtreditor;
- nsresult result = GetEditor(getter_AddRefs(editor));
- if (NS_FAILED(result) || !editor)
- return result ? result : NS_ERROR_FAILURE;
-
- return editor->GetSelectionController(aSelCon);
-}
-
-NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame)
-{
- NS_ENSURE_ARG_POINTER(aFrame);
- //DEPRICATED. WILL REMOVE LATER
-/*
- *aFrame = nsnull;
- NS_ENSURE_STATE(mContent);
-
- nsIFormControlFrame *frame = nsnull;
- NS_ENSURE_SUCCESS(
- nsGenericHTMLElement::GetPrimaryFrame(mContent, frame),
- NS_ERROR_FAILURE
- );
- if (!frame) { return NS_ERROR_FAILURE; }
-
- NS_ENSURE_SUCCESS(
- frame->QueryInterface(NS_GET_IID(nsIGfxTextControlFrame), (void**)aFrame),
- NS_ERROR_FAILURE
- );
- */
- return NS_OK;
-}
-
PRBool nsEditorController::IsEnabled()
{
return PR_TRUE; // XXX: need to implement this
@@ -331,18 +222,15 @@ PRBool nsEditorController::IsEnabled()
*/
}
-#ifdef XP_MAC
-#pragma mark -
-#endif
-nsWeakPtr nsEditorController::sCommandManager = NULL;
+nsWeakPtr nsEditorController::sEditorCommandManager = NULL;
// static
-nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *outCommandManager)
+nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager)
{
NS_ENSURE_ARG_POINTER(outCommandManager);
- nsCOMPtr cmdManager = do_QueryReferent(sCommandManager);
+ nsCOMPtr cmdManager = do_QueryReferent(sEditorCommandManager);
if (!cmdManager)
{
nsresult rv;
@@ -354,7 +242,7 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out
if (NS_FAILED(rv)) return rv;
// save the singleton in our static weak reference
- sCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
+ sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
if (NS_FAILED(rv)) return rv;
}
@@ -363,3 +251,132 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out
}
+
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
+nsComposerController::nsComposerController()
+{
+}
+
+nsComposerController::~nsComposerController()
+{
+}
+
+NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon)
+{
+ nsresult rv;
+
+ rv = nsEditorController::Init(aCommandRefCon);
+ if (NS_FAILED(rv)) return rv;
+
+ // get our ref to the singleton command manager
+ rv = GetComposerCommandManager(getter_AddRefs(mCommandManager));
+ if (NS_FAILED(rv)) return rv;
+
+ return NS_OK;
+}
+
+#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \
+ { \
+ _cmdClass* theCmd = new _cmdClass(_styleTag); \
+ rv = RegisterOneCommand(NS_ConvertASCIItoUCS2(_cmdName).GetUnicode(), inCommandManager, theCmd); \
+ }
+
+
+// static
+nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager)
+{
+ nsresult rv;
+
+ // These are composer-only commands
+
+ // File menu
+ NS_REGISTER_ONE_COMMAND(nsSaveCommand, "cmd_save");
+ NS_REGISTER_ONE_COMMAND(nsSaveAsCommand, "cmd_saveAs");
+ NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close");
+
+ NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print");
+ NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup");
+ NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview");
+
+ // Edit menu
+ NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
+
+ // indent/outdent
+ NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
+ NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
+
+ // Styles
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
+
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
+
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
+
+ // lists
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
+
+ // format stuff
+ NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
+ NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
+ NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
+ NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
+ NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
+
+ return NS_OK;
+}
+
+
+nsWeakPtr nsComposerController::sComposerCommandManager = NULL;
+
+nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager)
+{
+ NS_ENSURE_ARG_POINTER(outCommandManager);
+
+/*
+ nsCOMPtr cmdManager = do_QueryReferent(sComposerCommandManager);
+ if (!cmdManager)
+ {
+ nsresult rv;
+ cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ // register the commands. This just happens once per instance
+ rv = nsComposerController::RegisterComposerCommands(cmdManager);
+ if (NS_FAILED(rv)) return rv;
+
+ // save the singleton in our static weak reference
+ sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
+ if (NS_FAILED(rv)) return rv;
+ }
+*/
+ // always make a new one
+ nsresult rv;
+ nsCOMPtr cmdManager;
+ cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ // register the commands.
+ rv = nsComposerController::RegisterComposerCommands(cmdManager);
+ if (NS_FAILED(rv)) return rv;
+
+ NS_ADDREF(*outCommandManager = cmdManager);
+ return NS_OK;
+}
+
+
diff --git a/mozilla/editor/base/nsEditorController.h b/mozilla/editor/base/nsEditorController.h
index d2b6eff42c0..09412862636 100644
--- a/mozilla/editor/base/nsEditorController.h
+++ b/mozilla/editor/base/nsEditorController.h
@@ -23,23 +23,30 @@
#define NS_EDITORCONTROLLER_CID \
{ 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } }
+#define NS_COMPOSERCONTROLLER_CID \
+{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
+
+
#include "nsIController.h"
#include "nsIEditorController.h"
#include "nsIControllerCommand.h"
+#include "nsIInterfaceRequestor.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsWeakPtr.h"
-class nsIHTMLContent;
-class nsIGfxTextControlFrame;
class nsIEditor;
-class nsISelectionController;
+class nsIEditorShell;
class nsBaseCommand;
+// the editor controller is used for both text widgets, and basic text editing
+// commands in composer. The refCon that gets passed to its commands is an nsIEditor.
+
class nsEditorController : public nsIController,
- public nsIEditorController
+ public nsIEditorController,
+ public nsIInterfaceRequestor
{
public:
@@ -53,48 +60,68 @@ public:
NS_DECL_NSICONTROLLER
/** init the controller */
- NS_IMETHOD Init();
-
- /** set the content for this controller instance */
- NS_IMETHOD SetContent(nsIHTMLContent *aContent);
-
- /** set the editor for this controller. Mutually exclusive with setContent*/
- NS_IMETHOD SetEditor(nsIEditor *aEditor);
+ NS_IMETHOD Init(nsISupports *aCommandRefCon);
+ /** Set the cookie that is passed to commands
+ */
+ NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
+ // nsIInterfaceRequestor
+ NS_DECL_NSIINTERFACEREQUESTOR
+
protected:
- /** fetch the primary frame associated with mContent */
- NS_IMETHOD GetFrame(nsIGfxTextControlFrame **aFrame);
-
- /** fetch the editor associated with mContent */
- NS_IMETHOD GetEditor(nsIEditor ** aEditor);
-
- NS_IMETHOD GetSelectionController(nsISelectionController ** aSelCon);
/** return PR_TRUE if the editor associated with mContent is enabled */
- PRBool IsEnabled();
+ PRBool IsEnabled();
/* register a command */
nsresult RegisterEditorCommand(nsBaseCommand* aCommand);
protected:
- nsIHTMLContent* mContent; // weak reference, the content object owns this object
-
//if editor is null then look to mContent. this is for dual use of window and content
//attached controller.
- nsIEditor *mEditor;
+ nsISupports *mCommandRefCon;
nsCOMPtr mCommandManager; // our reference to the command manager
+protected:
+
+ static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand);
+
private:
- static nsresult GetCommandManager(nsIControllerCommandManager* *outCommandManager);
+ static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager);
static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager);
- static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand);
// the singleton command manager
- static nsWeakPtr sCommandManager;
+ static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands
};
+
+
+
+// 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 nsEditorController
+{
+public:
+
+ nsComposerController();
+ virtual ~nsComposerController();
+
+ /** init the controller */
+ NS_IMETHOD Init(nsISupports *aCommandRefCon);
+
+protected:
+
+private:
+
+ static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager);
+ static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager);
+
+ // the singleton command manager
+ static nsWeakPtr sComposerCommandManager; // composer-specific commands (lots of them)
+};
diff --git a/mozilla/editor/base/nsEditorRegistration.cpp b/mozilla/editor/base/nsEditorRegistration.cpp
index 241a8b038ed..46c79b16a65 100644
--- a/mozilla/editor/base/nsEditorRegistration.cpp
+++ b/mozilla/editor/base/nsEditorRegistration.cpp
@@ -36,6 +36,7 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService)
#ifdef ENABLE_EDITOR_API_LOG
@@ -58,8 +59,10 @@ static nsModuleComponentInfo components[] = {
{ "HTML Editor", NS_HTMLEDITOR_CID,
"component://netscape/editor/htmleditor", nsHTMLEditorConstructor, },
#endif
- { "Editor Shell Controller", NS_EDITORCONTROLLER_CID,
+ { "Editor Controller", NS_EDITORCONTROLLER_CID,
"component://netscape/editor/editorcontroller", nsEditorControllerConstructor, },
+ { "Composer Controller", NS_COMPOSERCONTROLLER_CID,
+ "component://netscape/editor/composercontroller", nsComposerControllerConstructor, },
{ "Editor Shell Component", NS_EDITORSHELL_CID,
"component://netscape/editor/editorshell", nsEditorShellConstructor, },
{ "Editor Shell Spell Checker", NS_EDITORSHELL_CID,
diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp
index 2dea300809e..8066c1b42f1 100644
--- a/mozilla/editor/base/nsEditorShell.cpp
+++ b/mozilla/editor/base/nsEditorShell.cpp
@@ -215,10 +215,11 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow)
/////////////////////////////////////////////////////////////////////////
nsEditorShell::nsEditorShell()
-: mToolbarWindow(nsnull)
-, mContentWindow(nsnull)
-, mParserObserver(nsnull)
+: mParserObserver(nsnull)
, mStateMaintainer(nsnull)
+, mWebShellWindow(nsnull)
+, mContentWindow(nsnull)
+, mEditorController(nsnull)
, mDocShell(nsnull)
, mContentAreaDocShell(nsnull)
, mCloseWindowWhenLoaded(PR_FALSE)
@@ -295,13 +296,14 @@ nsEditorShell::Init()
// XXX: why are we returning NS_OK here rather than res?
// is it ok to fail to get a string bundle? if so, it should be documented.
+
return NS_OK;
}
nsresult
nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl)
{
- if (!mContentAreaDocShell)
+ if (!mContentAreaDocShell || !mContentWindow)
return NS_ERROR_NOT_INITIALIZED;
if (mEditor)
@@ -322,6 +324,13 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
NS_IF_RELEASE(mStateMaintainer);
}
}
+
+ // clear this editor out of the controller
+ if (mEditorController)
+ {
+ mEditorController->SetCommandRefCon(nsnull);
+ }
+
mEditorType = eUninitializedEditorType;
mEditor = 0; // clear out the nsCOMPtr
@@ -394,29 +403,12 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
{
txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer));
}
-
- if (NS_SUCCEEDED(rv) && mContentWindow)
+
+ // set the editor in the editor controller
+ if (mEditorController)
{
- nsCOMPtr controller;
- nsCOMPtr controllers;
- rv = nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller",
- nsnull,
- NS_GET_IID(nsIController),
- getter_AddRefs(controller));
- if (NS_SUCCEEDED(rv) && controller)
- {
- rv = mContentWindow->GetControllers(getter_AddRefs(controllers));
- if (NS_SUCCEEDED(rv) && controllers)
- {
- nsCOMPtr editorController = do_QueryInterface(controller);
- rv = editorController->Init();
- if (NS_FAILED(rv)) return rv;
-
- editorController->SetEditor(editor);//weak link
-
- rv = controllers->InsertControllerAt(0, controller);
- }
- }
+ nsCOMPtr editorAsISupports = do_QueryInterface(editor);
+ mEditorController->SetCommandRefCon(editorAsISupports);
}
// now all the listeners are set up, we can call PostCreate
@@ -488,18 +480,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
return NS_OK;
}
-NS_IMETHODIMP
-nsEditorShell::SetToolbarWindow(nsIDOMWindow* aWin)
-{
- NS_PRECONDITION(aWin != nsnull, "null ptr");
- if (!aWin)
- return NS_ERROR_NULL_POINTER;
-
- mToolbarWindow = aWin;
-
- return NS_OK;
-}
-
NS_IMETHODIMP
nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
{
@@ -520,7 +500,52 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
return NS_ERROR_FAILURE;
mContentAreaDocShell = docShell; // dont AddRef
- return docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this);
+ rv = docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this);
+ if (NS_FAILED(rv)) return rv;
+
+ // we make two controllers
+ nsCOMPtr controllers;
+ rv = mContentWindow->GetControllers(getter_AddRefs(controllers));
+ if (NS_FAILED(rv)) return rv;
+
+ {
+ // the first is an editor controller, and takes an nsIEditor as the refCon
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
+ nsCOMPtr editorController = do_QueryInterface(controller);
+ rv = editorController->Init(nsnull); // we set the editor later when we have one
+ if (NS_FAILED(rv)) return rv;
+
+ mEditorController = editorController; // temp weak link, so we can get it and set the editor later
+
+ rv = controllers->InsertControllerAt(0, controller);
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ {
+ // the first is a composer controller, and takes an nsIEditorShell as the refCon
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/composercontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
+ nsCOMPtr editorController = do_QueryInterface(controller);
+
+ nsCOMPtr shellAsISupports = do_QueryInterface((nsIEditorShell*)this);
+ rv = editorController->Init(shellAsISupports);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = controllers->InsertControllerAt(1, controller);
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsEditorShell::GetContentWindow(nsIDOMWindow * *aContentWindow)
+{
+ NS_ENSURE_ARG_POINTER(aContentWindow);
+ NS_IF_ADDREF(*aContentWindow = mContentWindow);
+ return NS_OK;
}
@@ -531,6 +556,8 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
if (!aWin)
return NS_ERROR_NULL_POINTER;
+ mWebShellWindow = aWin; // no addref
+
nsCOMPtr globalObj( do_QueryInterface(aWin) );
if (!globalObj) {
return NS_ERROR_FAILURE;
@@ -544,7 +571,6 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
return NS_ERROR_NOT_INITIALIZED;
mDocShell = docShell;
- //NS_ADDREF(mWebShell);
/*
#ifdef APP_DEBUG
@@ -562,6 +588,14 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
return rv;
}
+NS_IMETHODIMP
+nsEditorShell::GetWebShellWindow(nsIDOMWindow * *aWebShellWindow)
+{
+ NS_ENSURE_ARG_POINTER(aWebShellWindow);
+ NS_IF_ADDREF(*aWebShellWindow = mWebShellWindow);
+ return NS_OK;
+}
+
// tell the appcore what type of editor to instantiate
// this must be called before the editor has been instantiated,
// otherwise, an error is returned.
@@ -672,14 +706,34 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell)
NS_IMETHODIMP
-nsEditorShell::UpdateInterfaceState(void)
+nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate)
{
if (!mStateMaintainer)
return NS_ERROR_NOT_INITIALIZED;
- return mStateMaintainer->ForceUpdate();
+ return mStateMaintainer->ForceUpdate(tagToUpdate);
}
+NS_IMETHODIMP
+nsEditorShell::SetCommandStateData(const PRUnichar *commandName, void * stateData)
+{
+ if (!mStateMaintainer)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE);
+ return mStateMaintainer->SetCommandStateData(commandStr, stateData);
+}
+
+NS_IMETHODIMP
+nsEditorShell::GetCommandStateData(const PRUnichar *commandName, void * *outStateData)
+{
+ if (!mStateMaintainer)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE);
+ return mStateMaintainer->GetCommandStateData(commandStr, outStateData);
+}
+
// Deletion routines
nsresult
nsEditorShell::ScrollSelectionIntoView()
@@ -768,7 +822,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const
nsAutoString valueStr(value);
result = editor->SetAttribute(element, attributeStr, valueStr);
}
- UpdateInterfaceState();
+ UpdateInterfaceState(nsnull);
return result;
}
@@ -784,7 +838,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr)
nsAutoString attributeStr(attr);
result = editor->RemoveAttribute(element, attributeStr);
}
- UpdateInterfaceState();
+ UpdateInterfaceState(nsnull);
return result;
}
@@ -793,16 +847,10 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr)
NS_IMETHODIMP
nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value)
{
- nsIAtom *styleAtom = nsnull;
nsresult err = NS_NOINTERFACE;
- styleAtom = NS_NewAtom(prop); /// XXX Hack alert! Look in nsIEditProperty.h for this
-
- if (! styleAtom)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // addref it while we're using it
- NS_ADDREF(styleAtom);
+ nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this
+ if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
nsAutoString attributeStr(attr);
nsAutoString valueStr(value);
@@ -817,8 +865,8 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
- UpdateInterfaceState();
- NS_RELEASE(styleAtom);
+
+ UpdateInterfaceState(prop);
return err;
}
@@ -827,16 +875,10 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con
nsresult
nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
{
- nsIAtom *styleAtom = nsnull;
nsresult err = NS_NOINTERFACE;
- styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this
-
- if (! styleAtom)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // addref it while we're using it
- NS_ADDREF(styleAtom);
+ nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this
+ if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
switch (mEditorType)
{
@@ -849,8 +891,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
err = NS_ERROR_NOT_IMPLEMENTED;
}
- UpdateInterfaceState();
- NS_RELEASE(styleAtom);
+ UpdateInterfaceState(aProp.GetUnicode());
return err;
}
@@ -1520,7 +1561,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval)
} else {
// File was saved successfully
*_retval = PR_TRUE;
-
+
// Update window title to show possibly different filename
if (mustShowFileDialog)
UpdateWindowTitle();
@@ -1545,12 +1586,12 @@ nsEditorShell::CloseWindow( PRBool *_retval )
// Don't close the window if there was an error saving file or
// user canceled an action along the way
if (NS_SUCCEEDED(rv) && *_retval)
- {
+ {
nsCOMPtr baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
baseWindow->Destroy();
- }
+ }
return rv;
}
@@ -2911,6 +2952,29 @@ nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
return NS_NOINTERFACE;
}
+
+NS_IMETHODIMP
+nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable)
+{
+ *aDocumentEditable = PR_FALSE; // default return value
+ nsCOMPtr editor = do_QueryInterface(mEditor);
+ if (!editor) return NS_OK;
+
+ PRUint32 editorFlags;
+ editor->GetFlags(&editorFlags);
+
+ if (editorFlags & nsIHTMLEditor::eEditorReadonlyMask)
+ return NS_OK;
+
+ nsCOMPtr doc;
+ editor->GetDocument(getter_AddRefs(doc));
+ if (!doc) return NS_OK;
+
+ *aDocumentEditable = PR_TRUE;
+ return NS_OK;
+}
+
+
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
diff --git a/mozilla/editor/base/nsEditorShell.h b/mozilla/editor/base/nsEditorShell.h
index 4fd0bc37906..92e96452ba6 100644
--- a/mozilla/editor/base/nsEditorShell.h
+++ b/mozilla/editor/base/nsEditorShell.h
@@ -30,6 +30,7 @@
#include "nsISupports.h"
#include "nsIEditorShell.h"
+#include "nsIEditorController.h"
#include "nsIDocumentLoaderObserver.h"
#include "nsIDOMSelectionListener.h"
#include "nsIPrompt.h"
@@ -157,13 +158,14 @@ class nsEditorShell : public nsIEditorShell,
nsCOMPtr mAllTagsModeStyleSheet;
nsCOMPtr mParagraphMarksStyleSheet;
- nsIDOMWindow *mToolbarWindow; // weak reference
- nsIDOMWindow *mContentWindow; // weak reference
+ nsIDOMWindow *mWebShellWindow; // weak reference
+ nsIDOMWindow *mContentWindow; // weak reference
- nsEditorParserObserver* mParserObserver; // we hold the owning ref to this.
- nsInterfaceState* mStateMaintainer; // we hold the owning ref to this.
+ nsEditorParserObserver *mParserObserver; // we hold the owning ref to this.
+ nsInterfaceState *mStateMaintainer; // we hold the owning ref to this.
- nsIDocShell *mDocShell; // weak reference
+ nsIEditorController *mEditorController; // temporary weak ref to the editor controller
+ nsIDocShell *mDocShell; // weak reference
// The webshell that contains the document being edited.
// Don't assume that webshell directly contains the document being edited;
diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp
index f29f6489c90..daf5e9c57fe 100644
--- a/mozilla/editor/base/nsHTMLEditor.cpp
+++ b/mozilla/editor/base/nsHTMLEditor.cpp
@@ -1779,7 +1779,7 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty,
iter->Init(range);
nsCOMPtr content;
- result = iter->CurrentNode(getter_AddRefs(content));
+ iter->CurrentNode(getter_AddRefs(content));
while (NS_ENUMERATOR_FALSE == iter->IsDone())
{
//if (gNoisy) { printf(" checking node %p\n", content.get()); }
diff --git a/mozilla/editor/base/nsInterfaceState.cpp b/mozilla/editor/base/nsInterfaceState.cpp
index d920c303218..ca715716533 100644
--- a/mozilla/editor/base/nsInterfaceState.cpp
+++ b/mozilla/editor/base/nsInterfaceState.cpp
@@ -35,7 +35,6 @@
#include "nsIDOMElement.h"
#include "nsIDOMSelection.h"
#include "nsIDOMAttr.h"
-#include "nsIDOMXULCommandDispatcher.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsITimer.h"
@@ -46,6 +45,33 @@
#include "nsInterfaceState.h"
+
+/*
+static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure)
+{
+ nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData);
+ delete stringData;
+ return PR_FALSE;
+}
+
+static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure)
+{
+ nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData);
+ if (stringData)
+ {
+ nsString* newString = new nsString(*stringData);
+ return newString;
+ }
+
+ return nsnull;
+}
+
+*/
+
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
nsInterfaceState::nsInterfaceState()
: mEditor(nsnull)
, mChromeDoc(nsnull)
@@ -261,7 +287,8 @@ void nsInterfaceState::TimerCallback()
mSelectionCollapsed = isCollapsed;
}
- (void)ForceUpdate();
+ // (void)ForceUpdate();
+ CallUpdateCommands(NS_ConvertASCIItoUCS2("style"));
}
@@ -291,42 +318,44 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand)
}
NS_IMETHODIMP
-nsInterfaceState::ForceUpdate()
+nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate)
{
+ PRBool updateEverything = !tagToUpdate || !*tagToUpdate;
+
+#if 0
+ // This code is obsolete now that commanders are doing the work
nsresult rv;
-
- // we don't really care if any of these fail.
-
+
// update bold
- if (mUpdateBold)
+ if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate)))
{
- rv = UpdateTextState("b", "Editor:Bold", "bold", mBoldState);
+ rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update italic
- if (mUpdateItalics)
+ if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate)))
{
- rv = UpdateTextState("i", "Editor:Italic", "italic", mItalicState);
+ rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update underline
- if (mUpdateUnderline)
+ if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate)))
{
- rv = UpdateTextState("u", "Editor:Underline", "underline", mUnderlineState);
+ rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update the paragraph format popup
- if (mUpdateParagraph)
+ if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate)))
{
rv = UpdateParagraphState("Editor:Paragraph:Format", "format");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// udpate the font face
- if (mUpdateFont)
+ if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate)))
{
rv = UpdateFontFace("Editor:Font:Face", "font");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
@@ -335,15 +364,42 @@ nsInterfaceState::ForceUpdate()
// TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize)
// update the list buttons
- if (mUpdateList)
+ if (mUpdateList && (updateEverything ||
+ nsAutoString("ol").Equals(tagToUpdate) ||
+ nsAutoString("ul").Equals(tagToUpdate)))
{
rv = UpdateListState("Editor:Paragraph:ListType");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
+#endif
return NS_OK;
}
+
+NS_IMETHODIMP
+nsInterfaceState::SetCommandStateData(const nsString& commandName, void* stateData)
+{
+ nsStringKey commandKey(commandName);
+ mCommandStateTable.Put(&commandKey, stateData);
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsInterfaceState::GetCommandStateData(const nsString& commandName, void* *outStateData)
+{
+ nsStringKey commandKey(commandName);
+
+ // sucks that we have to do two hash lookups
+ if (!mCommandStateTable.Exists(&commandKey))
+ return NS_ERROR_UNEXPECTED;
+
+ *outStateData = mCommandStateTable.Get(&commandKey);
+ return NS_OK;
+}
+
+
PRBool
nsInterfaceState::SelectionIsCollapsed()
{
@@ -573,10 +629,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
{
if (mDirtyState != aNowDirty)
{
- nsresult rv; // = SetNodeAttribute("Editor:Save", "disabled", aNowDirty ? "true" : "false");
-
- rv = SetNodeAttribute("Editor:Save", "disabled", NS_ConvertASCIItoUCS2(aNowDirty ? "false" : "true"));
- if (NS_FAILED(rv)) return rv;
+ CallUpdateCommands(NS_ConvertASCIItoUCS2("save"));
mDirtyState = aNowDirty;
}
diff --git a/mozilla/editor/base/nsInterfaceState.h b/mozilla/editor/base/nsInterfaceState.h
index fa57893641d..4727553ea74 100644
--- a/mozilla/editor/base/nsInterfaceState.h
+++ b/mozilla/editor/base/nsInterfaceState.h
@@ -32,6 +32,8 @@
#include "nsITimer.h"
#include "nsITimerCallback.h"
+#include "nsHashTable.h"
+
class nsIHTMLEditor;
class nsIDOMXULDocument;
@@ -54,11 +56,14 @@ public:
// force an update of the UI. At some point, we could pass flags
// here to target certain things for updating.
- NS_IMETHOD ForceUpdate();
+ NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate);
// nsIDOMSelectionListener interface
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsIDOMSelection *aSel, short aReason);
+ NS_IMETHOD SetCommandStateData(const nsString& commandName, void* stateData);
+ NS_IMETHOD GetCommandStateData(const nsString& commandName, void* *outStateData);
+
NS_DECL_NSIDOCUMENTSTATELISTENER
// nsITimerCallback interfaces
@@ -128,6 +133,8 @@ protected:
PRPackedBool mUpdateItalics;
PRPackedBool mUpdateUnderline;
+ nsHashtable mCommandStateTable;
+
// current state
PRInt8 mBoldState;
PRInt8 mItalicState;
diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp
index 2dea300809e..8066c1b42f1 100644
--- a/mozilla/editor/composer/src/nsEditorShell.cpp
+++ b/mozilla/editor/composer/src/nsEditorShell.cpp
@@ -215,10 +215,11 @@ GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow)
/////////////////////////////////////////////////////////////////////////
nsEditorShell::nsEditorShell()
-: mToolbarWindow(nsnull)
-, mContentWindow(nsnull)
-, mParserObserver(nsnull)
+: mParserObserver(nsnull)
, mStateMaintainer(nsnull)
+, mWebShellWindow(nsnull)
+, mContentWindow(nsnull)
+, mEditorController(nsnull)
, mDocShell(nsnull)
, mContentAreaDocShell(nsnull)
, mCloseWindowWhenLoaded(PR_FALSE)
@@ -295,13 +296,14 @@ nsEditorShell::Init()
// XXX: why are we returning NS_OK here rather than res?
// is it ok to fail to get a string bundle? if so, it should be documented.
+
return NS_OK;
}
nsresult
nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl)
{
- if (!mContentAreaDocShell)
+ if (!mContentAreaDocShell || !mContentWindow)
return NS_ERROR_NOT_INITIALIZED;
if (mEditor)
@@ -322,6 +324,13 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
NS_IF_RELEASE(mStateMaintainer);
}
}
+
+ // clear this editor out of the controller
+ if (mEditorController)
+ {
+ mEditorController->SetCommandRefCon(nsnull);
+ }
+
mEditorType = eUninitializedEditorType;
mEditor = 0; // clear out the nsCOMPtr
@@ -394,29 +403,12 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
{
txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer));
}
-
- if (NS_SUCCEEDED(rv) && mContentWindow)
+
+ // set the editor in the editor controller
+ if (mEditorController)
{
- nsCOMPtr controller;
- nsCOMPtr controllers;
- rv = nsComponentManager::CreateInstance("component://netscape/editor/editorcontroller",
- nsnull,
- NS_GET_IID(nsIController),
- getter_AddRefs(controller));
- if (NS_SUCCEEDED(rv) && controller)
- {
- rv = mContentWindow->GetControllers(getter_AddRefs(controllers));
- if (NS_SUCCEEDED(rv) && controllers)
- {
- nsCOMPtr editorController = do_QueryInterface(controller);
- rv = editorController->Init();
- if (NS_FAILED(rv)) return rv;
-
- editorController->SetEditor(editor);//weak link
-
- rv = controllers->InsertControllerAt(0, controller);
- }
- }
+ nsCOMPtr editorAsISupports = do_QueryInterface(editor);
+ mEditorController->SetCommandRefCon(editorAsISupports);
}
// now all the listeners are set up, we can call PostCreate
@@ -488,18 +480,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUr
return NS_OK;
}
-NS_IMETHODIMP
-nsEditorShell::SetToolbarWindow(nsIDOMWindow* aWin)
-{
- NS_PRECONDITION(aWin != nsnull, "null ptr");
- if (!aWin)
- return NS_ERROR_NULL_POINTER;
-
- mToolbarWindow = aWin;
-
- return NS_OK;
-}
-
NS_IMETHODIMP
nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
{
@@ -520,7 +500,52 @@ nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
return NS_ERROR_FAILURE;
mContentAreaDocShell = docShell; // dont AddRef
- return docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this);
+ rv = docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this);
+ if (NS_FAILED(rv)) return rv;
+
+ // we make two controllers
+ nsCOMPtr controllers;
+ rv = mContentWindow->GetControllers(getter_AddRefs(controllers));
+ if (NS_FAILED(rv)) return rv;
+
+ {
+ // the first is an editor controller, and takes an nsIEditor as the refCon
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
+ nsCOMPtr editorController = do_QueryInterface(controller);
+ rv = editorController->Init(nsnull); // we set the editor later when we have one
+ if (NS_FAILED(rv)) return rv;
+
+ mEditorController = editorController; // temp weak link, so we can get it and set the editor later
+
+ rv = controllers->InsertControllerAt(0, controller);
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ {
+ // the first is a composer controller, and takes an nsIEditorShell as the refCon
+ nsCOMPtr controller = do_CreateInstance("component://netscape/editor/composercontroller", &rv);
+ if (NS_FAILED(rv)) return rv;
+ nsCOMPtr editorController = do_QueryInterface(controller);
+
+ nsCOMPtr shellAsISupports = do_QueryInterface((nsIEditorShell*)this);
+ rv = editorController->Init(shellAsISupports);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = controllers->InsertControllerAt(1, controller);
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsEditorShell::GetContentWindow(nsIDOMWindow * *aContentWindow)
+{
+ NS_ENSURE_ARG_POINTER(aContentWindow);
+ NS_IF_ADDREF(*aContentWindow = mContentWindow);
+ return NS_OK;
}
@@ -531,6 +556,8 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
if (!aWin)
return NS_ERROR_NULL_POINTER;
+ mWebShellWindow = aWin; // no addref
+
nsCOMPtr globalObj( do_QueryInterface(aWin) );
if (!globalObj) {
return NS_ERROR_FAILURE;
@@ -544,7 +571,6 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
return NS_ERROR_NOT_INITIALIZED;
mDocShell = docShell;
- //NS_ADDREF(mWebShell);
/*
#ifdef APP_DEBUG
@@ -562,6 +588,14 @@ nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
return rv;
}
+NS_IMETHODIMP
+nsEditorShell::GetWebShellWindow(nsIDOMWindow * *aWebShellWindow)
+{
+ NS_ENSURE_ARG_POINTER(aWebShellWindow);
+ NS_IF_ADDREF(*aWebShellWindow = mWebShellWindow);
+ return NS_OK;
+}
+
// tell the appcore what type of editor to instantiate
// this must be called before the editor has been instantiated,
// otherwise, an error is returned.
@@ -672,14 +706,34 @@ nsEditorShell::DoEditorMode(nsIDocShell *aDocShell)
NS_IMETHODIMP
-nsEditorShell::UpdateInterfaceState(void)
+nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate)
{
if (!mStateMaintainer)
return NS_ERROR_NOT_INITIALIZED;
- return mStateMaintainer->ForceUpdate();
+ return mStateMaintainer->ForceUpdate(tagToUpdate);
}
+NS_IMETHODIMP
+nsEditorShell::SetCommandStateData(const PRUnichar *commandName, void * stateData)
+{
+ if (!mStateMaintainer)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE);
+ return mStateMaintainer->SetCommandStateData(commandStr, stateData);
+}
+
+NS_IMETHODIMP
+nsEditorShell::GetCommandStateData(const PRUnichar *commandName, void * *outStateData)
+{
+ if (!mStateMaintainer)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ nsSubsumeStr commandStr((PRUnichar *)commandName, PR_FALSE);
+ return mStateMaintainer->GetCommandStateData(commandStr, outStateData);
+}
+
// Deletion routines
nsresult
nsEditorShell::ScrollSelectionIntoView()
@@ -768,7 +822,7 @@ nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const
nsAutoString valueStr(value);
result = editor->SetAttribute(element, attributeStr, valueStr);
}
- UpdateInterfaceState();
+ UpdateInterfaceState(nsnull);
return result;
}
@@ -784,7 +838,7 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr)
nsAutoString attributeStr(attr);
result = editor->RemoveAttribute(element, attributeStr);
}
- UpdateInterfaceState();
+ UpdateInterfaceState(nsnull);
return result;
}
@@ -793,16 +847,10 @@ nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr)
NS_IMETHODIMP
nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value)
{
- nsIAtom *styleAtom = nsnull;
nsresult err = NS_NOINTERFACE;
- styleAtom = NS_NewAtom(prop); /// XXX Hack alert! Look in nsIEditProperty.h for this
-
- if (! styleAtom)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // addref it while we're using it
- NS_ADDREF(styleAtom);
+ nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this
+ if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
nsAutoString attributeStr(attr);
nsAutoString valueStr(value);
@@ -817,8 +865,8 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con
default:
err = NS_ERROR_NOT_IMPLEMENTED;
}
- UpdateInterfaceState();
- NS_RELEASE(styleAtom);
+
+ UpdateInterfaceState(prop);
return err;
}
@@ -827,16 +875,10 @@ nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, con
nsresult
nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
{
- nsIAtom *styleAtom = nsnull;
nsresult err = NS_NOINTERFACE;
- styleAtom = NS_NewAtom(aProp); /// XXX Hack alert! Look in nsIEditProperty.h for this
-
- if (! styleAtom)
- return NS_ERROR_OUT_OF_MEMORY;
-
- // addref it while we're using it
- NS_ADDREF(styleAtom);
+ nsCOMPtr styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this
+ if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
switch (mEditorType)
{
@@ -849,8 +891,7 @@ nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
err = NS_ERROR_NOT_IMPLEMENTED;
}
- UpdateInterfaceState();
- NS_RELEASE(styleAtom);
+ UpdateInterfaceState(aProp.GetUnicode());
return err;
}
@@ -1520,7 +1561,7 @@ nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval)
} else {
// File was saved successfully
*_retval = PR_TRUE;
-
+
// Update window title to show possibly different filename
if (mustShowFileDialog)
UpdateWindowTitle();
@@ -1545,12 +1586,12 @@ nsEditorShell::CloseWindow( PRBool *_retval )
// Don't close the window if there was an error saving file or
// user canceled an action along the way
if (NS_SUCCEEDED(rv) && *_retval)
- {
+ {
nsCOMPtr baseWindow;
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
baseWindow->Destroy();
- }
+ }
return rv;
}
@@ -2911,6 +2952,29 @@ nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
return NS_NOINTERFACE;
}
+
+NS_IMETHODIMP
+nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable)
+{
+ *aDocumentEditable = PR_FALSE; // default return value
+ nsCOMPtr editor = do_QueryInterface(mEditor);
+ if (!editor) return NS_OK;
+
+ PRUint32 editorFlags;
+ editor->GetFlags(&editorFlags);
+
+ if (editorFlags & nsIHTMLEditor::eEditorReadonlyMask)
+ return NS_OK;
+
+ nsCOMPtr doc;
+ editor->GetDocument(getter_AddRefs(doc));
+ if (!doc) return NS_OK;
+
+ *aDocumentEditable = PR_TRUE;
+ return NS_OK;
+}
+
+
NS_IMETHODIMP
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
{
diff --git a/mozilla/editor/composer/src/nsEditorShell.h b/mozilla/editor/composer/src/nsEditorShell.h
index 4fd0bc37906..92e96452ba6 100644
--- a/mozilla/editor/composer/src/nsEditorShell.h
+++ b/mozilla/editor/composer/src/nsEditorShell.h
@@ -30,6 +30,7 @@
#include "nsISupports.h"
#include "nsIEditorShell.h"
+#include "nsIEditorController.h"
#include "nsIDocumentLoaderObserver.h"
#include "nsIDOMSelectionListener.h"
#include "nsIPrompt.h"
@@ -157,13 +158,14 @@ class nsEditorShell : public nsIEditorShell,
nsCOMPtr mAllTagsModeStyleSheet;
nsCOMPtr mParagraphMarksStyleSheet;
- nsIDOMWindow *mToolbarWindow; // weak reference
- nsIDOMWindow *mContentWindow; // weak reference
+ nsIDOMWindow *mWebShellWindow; // weak reference
+ nsIDOMWindow *mContentWindow; // weak reference
- nsEditorParserObserver* mParserObserver; // we hold the owning ref to this.
- nsInterfaceState* mStateMaintainer; // we hold the owning ref to this.
+ nsEditorParserObserver *mParserObserver; // we hold the owning ref to this.
+ nsInterfaceState *mStateMaintainer; // we hold the owning ref to this.
- nsIDocShell *mDocShell; // weak reference
+ nsIEditorController *mEditorController; // temporary weak ref to the editor controller
+ nsIDocShell *mDocShell; // weak reference
// The webshell that contains the document being edited.
// Don't assume that webshell directly contains the document being edited;
diff --git a/mozilla/editor/composer/src/nsInterfaceState.cpp b/mozilla/editor/composer/src/nsInterfaceState.cpp
index d920c303218..ca715716533 100644
--- a/mozilla/editor/composer/src/nsInterfaceState.cpp
+++ b/mozilla/editor/composer/src/nsInterfaceState.cpp
@@ -35,7 +35,6 @@
#include "nsIDOMElement.h"
#include "nsIDOMSelection.h"
#include "nsIDOMAttr.h"
-#include "nsIDOMXULCommandDispatcher.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
#include "nsITimer.h"
@@ -46,6 +45,33 @@
#include "nsInterfaceState.h"
+
+/*
+static PRBool StringHashDestroyFunc(nsHashKey *aKey, void *aData, void* closure)
+{
+ nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData);
+ delete stringData;
+ return PR_FALSE;
+}
+
+static void* StringHashCloneElementFunc(nsHashKey *aKey, void *aData, void* closure)
+{
+ nsString* stringData = NS_REINTERPRET_CAST(nsString*, aData);
+ if (stringData)
+ {
+ nsString* newString = new nsString(*stringData);
+ return newString;
+ }
+
+ return nsnull;
+}
+
+*/
+
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
nsInterfaceState::nsInterfaceState()
: mEditor(nsnull)
, mChromeDoc(nsnull)
@@ -261,7 +287,8 @@ void nsInterfaceState::TimerCallback()
mSelectionCollapsed = isCollapsed;
}
- (void)ForceUpdate();
+ // (void)ForceUpdate();
+ CallUpdateCommands(NS_ConvertASCIItoUCS2("style"));
}
@@ -291,42 +318,44 @@ nsresult nsInterfaceState::CallUpdateCommands(const nsString& aCommand)
}
NS_IMETHODIMP
-nsInterfaceState::ForceUpdate()
+nsInterfaceState::ForceUpdate(const PRUnichar *tagToUpdate)
{
+ PRBool updateEverything = !tagToUpdate || !*tagToUpdate;
+
+#if 0
+ // This code is obsolete now that commanders are doing the work
nsresult rv;
-
- // we don't really care if any of these fail.
-
+
// update bold
- if (mUpdateBold)
+ if (mUpdateBold && (updateEverything || nsAutoString("b").Equals(tagToUpdate)))
{
- rv = UpdateTextState("b", "Editor:Bold", "bold", mBoldState);
+ rv = UpdateTextState("b", "cmd_bold", "bold", mBoldState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update italic
- if (mUpdateItalics)
+ if (mUpdateItalics && (updateEverything || nsAutoString("i").Equals(tagToUpdate)))
{
- rv = UpdateTextState("i", "Editor:Italic", "italic", mItalicState);
+ rv = UpdateTextState("i", "cmd_italic", "italic", mItalicState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update underline
- if (mUpdateUnderline)
+ if (mUpdateUnderline && (updateEverything || nsAutoString("u").Equals(tagToUpdate)))
{
- rv = UpdateTextState("u", "Editor:Underline", "underline", mUnderlineState);
+ rv = UpdateTextState("u", "cmd_underline", "underline", mUnderlineState);
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// update the paragraph format popup
- if (mUpdateParagraph)
+ if (mUpdateParagraph && (updateEverything || nsAutoString("format").Equals(tagToUpdate)))
{
rv = UpdateParagraphState("Editor:Paragraph:Format", "format");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
// udpate the font face
- if (mUpdateFont)
+ if (mUpdateFont && (updateEverything || nsAutoString("font").Equals(tagToUpdate)))
{
rv = UpdateFontFace("Editor:Font:Face", "font");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
@@ -335,15 +364,42 @@ nsInterfaceState::ForceUpdate()
// TODO: FINISH FONT FACE AND ADD FONT SIZE ("Editor:Font:Size", "fontsize", mFontSize)
// update the list buttons
- if (mUpdateList)
+ if (mUpdateList && (updateEverything ||
+ nsAutoString("ol").Equals(tagToUpdate) ||
+ nsAutoString("ul").Equals(tagToUpdate)))
{
rv = UpdateListState("Editor:Paragraph:ListType");
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to update state");
}
+#endif
return NS_OK;
}
+
+NS_IMETHODIMP
+nsInterfaceState::SetCommandStateData(const nsString& commandName, void* stateData)
+{
+ nsStringKey commandKey(commandName);
+ mCommandStateTable.Put(&commandKey, stateData);
+ return NS_OK;
+}
+
+
+NS_IMETHODIMP
+nsInterfaceState::GetCommandStateData(const nsString& commandName, void* *outStateData)
+{
+ nsStringKey commandKey(commandName);
+
+ // sucks that we have to do two hash lookups
+ if (!mCommandStateTable.Exists(&commandKey))
+ return NS_ERROR_UNEXPECTED;
+
+ *outStateData = mCommandStateTable.Get(&commandKey);
+ return NS_OK;
+}
+
+
PRBool
nsInterfaceState::SelectionIsCollapsed()
{
@@ -573,10 +629,7 @@ nsInterfaceState::UpdateDirtyState(PRBool aNowDirty)
{
if (mDirtyState != aNowDirty)
{
- nsresult rv; // = SetNodeAttribute("Editor:Save", "disabled", aNowDirty ? "true" : "false");
-
- rv = SetNodeAttribute("Editor:Save", "disabled", NS_ConvertASCIItoUCS2(aNowDirty ? "false" : "true"));
- if (NS_FAILED(rv)) return rv;
+ CallUpdateCommands(NS_ConvertASCIItoUCS2("save"));
mDirtyState = aNowDirty;
}
diff --git a/mozilla/editor/composer/src/nsInterfaceState.h b/mozilla/editor/composer/src/nsInterfaceState.h
index fa57893641d..4727553ea74 100644
--- a/mozilla/editor/composer/src/nsInterfaceState.h
+++ b/mozilla/editor/composer/src/nsInterfaceState.h
@@ -32,6 +32,8 @@
#include "nsITimer.h"
#include "nsITimerCallback.h"
+#include "nsHashTable.h"
+
class nsIHTMLEditor;
class nsIDOMXULDocument;
@@ -54,11 +56,14 @@ public:
// force an update of the UI. At some point, we could pass flags
// here to target certain things for updating.
- NS_IMETHOD ForceUpdate();
+ NS_IMETHOD ForceUpdate(const PRUnichar *tagToUpdate);
// nsIDOMSelectionListener interface
NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *aDoc, nsIDOMSelection *aSel, short aReason);
+ NS_IMETHOD SetCommandStateData(const nsString& commandName, void* stateData);
+ NS_IMETHOD GetCommandStateData(const nsString& commandName, void* *outStateData);
+
NS_DECL_NSIDOCUMENTSTATELISTENER
// nsITimerCallback interfaces
@@ -128,6 +133,8 @@ protected:
PRPackedBool mUpdateItalics;
PRPackedBool mUpdateUnderline;
+ nsHashtable mCommandStateTable;
+
// current state
PRInt8 mBoldState;
PRInt8 mItalicState;
diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl
index e6c49557589..cff84799a7e 100644
--- a/mozilla/editor/idl/nsIEditorShell.idl
+++ b/mozilla/editor/idl/nsIEditorShell.idl
@@ -47,6 +47,9 @@ interface nsIEditorShell : nsISupports
readonly attribute nsIDOMSelection editorSelection;
readonly attribute nsISelectionController selectionController;
+ attribute nsIDOMWindow webShellWindow;
+ attribute nsIDOMWindow contentWindow;
+
[noscript] readonly attribute nsIEditor editor;
%{C++
@@ -64,15 +67,13 @@ interface nsIEditorShell : nsISupports
%}
readonly attribute boolean documentModified;
readonly attribute boolean documentIsEmpty;
+ readonly attribute boolean documentEditable; // do we have a doc and editor yet?
readonly attribute long documentLength;
attribute long wrapColumn;
/* Setup */
void SetEditorType(in wstring editorType);
- void SetToolbarWindow(in nsIDOMWindow win);
- void SetContentWindow(in nsIDOMWindow win);
- void SetWebShellWindow(in nsIDOMWindow win);
void LoadUrl(in wstring url);
/* Set the value of the tag in the of a document
@@ -158,9 +159,15 @@ interface nsIEditorShell : nsISupports
/* General Utilities */
- /* UI updating */
- void UpdateInterfaceState();
+ /* UI updating
+ * tagToUpdate can be null or "" to update everything
+ */
+ void UpdateInterfaceState(in wstring tagToUpdate);
+ /* Used to associate state with a command */
+ [noscript] void SetCommandStateData(in wstring commandName, in voidStar stateData);
+ [noscript] voidStar GetCommandStateData(in wstring commandName);
+
/* Get string from the Editor's localized string bundle */
wstring GetString(in wstring name);
diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.cpp b/mozilla/editor/libeditor/base/nsEditorCommands.cpp
index 2a623f6dff2..c4db3ecb12a 100644
--- a/mozilla/editor/libeditor/base/nsEditorCommands.cpp
+++ b/mozilla/editor/libeditor/base/nsEditorCommands.cpp
@@ -38,13 +38,12 @@ nsBaseCommand::nsBaseCommand()
NS_INIT_REFCNT();
}
-
-nsBaseCommand::~nsBaseCommand()
-{
-}
-
NS_IMPL_ISUPPORTS(nsBaseCommand, NS_GET_IID(nsIControllerCommand));
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
NS_IMETHODIMP
nsUndoCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
diff --git a/mozilla/editor/libeditor/base/nsEditorCommands.h b/mozilla/editor/libeditor/base/nsEditorCommands.h
index 497b1da716f..95cd5c15059 100644
--- a/mozilla/editor/libeditor/base/nsEditorCommands.h
+++ b/mozilla/editor/libeditor/base/nsEditorCommands.h
@@ -34,7 +34,7 @@ class nsBaseCommand : public nsIControllerCommand
public:
nsBaseCommand();
- virtual ~nsBaseCommand();
+ virtual ~nsBaseCommand() {}
NS_DECL_ISUPPORTS
@@ -44,13 +44,16 @@ public:
};
-#define NS_DECL_EDITOR_COMMAND(_cmd) \
-class _cmd : public nsBaseCommand \
-{ \
-public: \
- NS_DECL_NSICONTROLLERCOMMAND \
+#define NS_DECL_EDITOR_COMMAND(_cmd) \
+class _cmd : public nsBaseCommand \
+{ \
+public: \
+ NS_DECL_NSICONTROLLERCOMMAND \
};
+
+
+// basic editor commands
NS_DECL_EDITOR_COMMAND(nsUndoCommand)
NS_DECL_EDITOR_COMMAND(nsRedoCommand)
@@ -63,4 +66,23 @@ NS_DECL_EDITOR_COMMAND(nsSelectAllCommand)
NS_DECL_EDITOR_COMMAND(nsSelectionMoveCommands)
+
+#if 0
+// template for new command
+NS_IMETHODIMP
+nsFooCommand::IsCommandEnabled(const PRUnichar *aCommand, nsISupports * refCon, PRBool *outCmdEnabled)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+
+NS_IMETHODIMP
+nsFooCommand::DoCommand(const PRUnichar *aCommand, nsISupports * refCon)
+{
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+
+#endif
+
#endif // nsIEditorCommand_h_
diff --git a/mozilla/editor/libeditor/base/nsEditorController.cpp b/mozilla/editor/libeditor/base/nsEditorController.cpp
index 5b9e2ce5bac..9f5ab309c8f 100644
--- a/mozilla/editor/libeditor/base/nsEditorController.cpp
+++ b/mozilla/editor/libeditor/base/nsEditorController.cpp
@@ -24,6 +24,7 @@
#include "nsIComponentManager.h"
#include "nsEditorController.h"
#include "nsIEditor.h"
+#include "nsIEditorShell.h"
#include "nsIEditorMailSupport.h"
#include "nsIFormControlFrame.h"
#include "nsIDOMSelection.h"
@@ -36,7 +37,7 @@
#include "nsIPresShell.h"
#include "nsEditorCommands.h"
-
+#include "nsComposerCommands.h"
#define kMaxStackCommandNameLength 128
@@ -47,31 +48,49 @@ NS_IMPL_RELEASE(nsEditorController)
NS_INTERFACE_MAP_BEGIN(nsEditorController)
NS_INTERFACE_MAP_ENTRY(nsIController)
NS_INTERFACE_MAP_ENTRY(nsIEditorController)
+ NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIEditorController)
NS_INTERFACE_MAP_END
nsEditorController::nsEditorController()
-: mContent(NULL)
-, mEditor(NULL)
+: mCommandRefCon(nsnull)
{
NS_INIT_REFCNT();
}
nsEditorController::~nsEditorController()
{
- // if the singleton command manger has a refcount of 1 at this point, we need to
- // set it to null
}
-NS_IMETHODIMP nsEditorController::Init()
+NS_IMETHODIMP nsEditorController::Init(nsISupports *aCommandRefCon)
{
nsresult rv;
// get our ref to the singleton command manager
- rv = GetCommandManager(getter_AddRefs(mCommandManager));
+ rv = GetEditorCommandManager(getter_AddRefs(mCommandManager));
if (NS_FAILED(rv)) return rv;
+
+ mCommandRefCon = aCommandRefCon; // no addref
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsEditorController::SetCommandRefCon(nsISupports *aCommandRefCon)
+{
+ mCommandRefCon = aCommandRefCon; // no addref
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsEditorController::GetInterface(const nsIID & aIID, void * *result)
+{
+ NS_ENSURE_ARG_POINTER(result);
+
+ if (NS_SUCCEEDED(QueryInterface(aIID, result)))
+ return NS_OK;
- return rv;
+ if (mCommandManager && aIID.Equals(NS_GET_IID(nsIControllerCommandManager)))
+ return mCommandManager->QueryInterface(aIID, result);
+
+ return NS_NOINTERFACE;
}
@@ -100,6 +119,8 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
nsresult rv;
// now register all our commands
+ // These are commands that will be used in text widgets, and in composer
+
NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo");
NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
@@ -107,8 +128,7 @@ nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandManager
NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
- NS_REGISTER_FIRST_COMMAND(nsPasteCommand, "cmd_paste");
- NS_REGISTER_LAST_COMMAND(nsPasteCommand, "cmd_pasteQuote");
+ NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");
NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete");
NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward");
@@ -166,106 +186,23 @@ nsresult nsEditorController::RegisterOneCommand(const PRUnichar* aCommandName,
return inCommandManager->RegisterCommand(aCommandName, editorCommand); // this is the owning ref
}
-
-NS_IMETHODIMP nsEditorController::SetContent(nsIHTMLContent *aContent)
-{
- // indiscriminately sets mContent, no ref counting here
- mContent = aContent;
- return NS_OK;
-}
-
-NS_IMETHODIMP nsEditorController::SetEditor(nsIEditor *aEditor)
-{
- // null editors are allowed
- mEditor = aEditor;
- return NS_OK;
-}
-
-
/* =======================================================================
* nsIController
* ======================================================================= */
NS_IMETHODIMP nsEditorController::IsCommandEnabled(const PRUnichar *aCommand, PRBool *aResult)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- NS_ENSURE_ARG_POINTER(aResult);
-
- *aResult = PR_FALSE;
-
- nsCOMPtr editor;
- NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE);
- // a null editor is a legal state
- if (!editor)
- return NS_OK; // just say we don't handle the command
-
- if (!mCommandManager)
- {
- NS_ASSERTION(0, "No command handler!");
- return NS_ERROR_UNEXPECTED;
- }
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- if (!commandHandler)
- {
-#if DEBUG
- nsCAutoString msg("EditorController asked about a command that it does not handle -- ");
- msg.AppendWithConversion(aCommand);
- NS_WARNING(msg);
-#endif
- return NS_OK; // we don't handle this command
- }
-
- return commandHandler->IsCommandEnabled(aCommand, editor, aResult);
+ return mCommandManager->IsCommandEnabled(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::SupportsCommand(const PRUnichar *aCommand, PRBool *aResult)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- NS_ENSURE_ARG_POINTER(aResult);
-
- // XXX: need to check the readonly and disabled states
-
- *aResult = PR_FALSE;
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- *aResult = (commandHandler.get() != NULL);
- return NS_OK;
+ return mCommandManager->SupportsCommand(aCommand, mCommandRefCon, aResult);
}
NS_IMETHODIMP nsEditorController::DoCommand(const PRUnichar *aCommand)
{
- NS_ENSURE_ARG_POINTER(aCommand);
- nsCOMPtr editor;
- nsCOMPtr selCont;
- NS_ENSURE_SUCCESS(GetEditor(getter_AddRefs(editor)), NS_ERROR_FAILURE);
- if (!editor)
- { // Q: What does it mean if there is no editor?
- // A: It means we've never had focus, so we can't do anything
- return NS_OK;
- }
-
- // find the command
- nsCOMPtr commandHandler;
- mCommandManager->FindCommandHandler(aCommand, getter_AddRefs(commandHandler));
-
- if (!commandHandler)
- {
-#if DEBUG
- nsCAutoString msg("EditorController asked to do a command that it does not handle -- ");
- msg.AppendWithConversion(aCommand);
- NS_WARNING(msg);
-#endif
- return NS_OK; // we don't handle this command
- }
-
- return commandHandler->DoCommand(aCommand, editor);
+ return mCommandManager->DoCommand(aCommand, mCommandRefCon);
}
NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName)
@@ -275,52 +212,6 @@ NS_IMETHODIMP nsEditorController::OnEvent(const PRUnichar *aEventName)
return NS_OK;
}
-
-NS_IMETHODIMP nsEditorController::GetEditor(nsIEditor ** aEditor)
-{
- NS_ENSURE_ARG_POINTER(aEditor);
- if (mEditor)
- {
- *aEditor = mEditor;
- NS_ADDREF(*aEditor);
- return NS_OK;
- }
- return NS_OK;
-}
-
-NS_IMETHODIMP nsEditorController::GetSelectionController(nsISelectionController ** aSelCon)
-{
- nsCOMPtreditor;
- nsresult result = GetEditor(getter_AddRefs(editor));
- if (NS_FAILED(result) || !editor)
- return result ? result : NS_ERROR_FAILURE;
-
- return editor->GetSelectionController(aSelCon);
-}
-
-NS_IMETHODIMP nsEditorController::GetFrame(nsIGfxTextControlFrame **aFrame)
-{
- NS_ENSURE_ARG_POINTER(aFrame);
- //DEPRICATED. WILL REMOVE LATER
-/*
- *aFrame = nsnull;
- NS_ENSURE_STATE(mContent);
-
- nsIFormControlFrame *frame = nsnull;
- NS_ENSURE_SUCCESS(
- nsGenericHTMLElement::GetPrimaryFrame(mContent, frame),
- NS_ERROR_FAILURE
- );
- if (!frame) { return NS_ERROR_FAILURE; }
-
- NS_ENSURE_SUCCESS(
- frame->QueryInterface(NS_GET_IID(nsIGfxTextControlFrame), (void**)aFrame),
- NS_ERROR_FAILURE
- );
- */
- return NS_OK;
-}
-
PRBool nsEditorController::IsEnabled()
{
return PR_TRUE; // XXX: need to implement this
@@ -331,18 +222,15 @@ PRBool nsEditorController::IsEnabled()
*/
}
-#ifdef XP_MAC
-#pragma mark -
-#endif
-nsWeakPtr nsEditorController::sCommandManager = NULL;
+nsWeakPtr nsEditorController::sEditorCommandManager = NULL;
// static
-nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *outCommandManager)
+nsresult nsEditorController::GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager)
{
NS_ENSURE_ARG_POINTER(outCommandManager);
- nsCOMPtr cmdManager = do_QueryReferent(sCommandManager);
+ nsCOMPtr cmdManager = do_QueryReferent(sEditorCommandManager);
if (!cmdManager)
{
nsresult rv;
@@ -354,7 +242,7 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out
if (NS_FAILED(rv)) return rv;
// save the singleton in our static weak reference
- sCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
+ sEditorCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
if (NS_FAILED(rv)) return rv;
}
@@ -363,3 +251,132 @@ nsresult nsEditorController::GetCommandManager(nsIControllerCommandManager* *out
}
+
+#ifdef XP_MAC
+#pragma mark -
+#endif
+
+nsComposerController::nsComposerController()
+{
+}
+
+nsComposerController::~nsComposerController()
+{
+}
+
+NS_IMETHODIMP nsComposerController::Init(nsISupports *aCommandRefCon)
+{
+ nsresult rv;
+
+ rv = nsEditorController::Init(aCommandRefCon);
+ if (NS_FAILED(rv)) return rv;
+
+ // get our ref to the singleton command manager
+ rv = GetComposerCommandManager(getter_AddRefs(mCommandManager));
+ if (NS_FAILED(rv)) return rv;
+
+ return NS_OK;
+}
+
+#define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag) \
+ { \
+ _cmdClass* theCmd = new _cmdClass(_styleTag); \
+ rv = RegisterOneCommand(NS_ConvertASCIItoUCS2(_cmdName).GetUnicode(), inCommandManager, theCmd); \
+ }
+
+
+// static
+nsresult nsComposerController::RegisterComposerCommands(nsIControllerCommandManager *inCommandManager)
+{
+ nsresult rv;
+
+ // These are composer-only commands
+
+ // File menu
+ NS_REGISTER_ONE_COMMAND(nsSaveCommand, "cmd_save");
+ NS_REGISTER_ONE_COMMAND(nsSaveAsCommand, "cmd_saveAs");
+ NS_REGISTER_ONE_COMMAND(nsCloseCommand, "cmd_close");
+
+ NS_REGISTER_FIRST_COMMAND(nsPrintingCommands, "cmd_print");
+ NS_REGISTER_NEXT_COMMAND(nsPrintingCommands, "cmd_printSetup");
+ NS_REGISTER_LAST_COMMAND(nsPrintingCommands, "cmd_printPreview");
+
+ // Edit menu
+ NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
+
+ // indent/outdent
+ NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
+ NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
+
+ // Styles
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
+
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
+
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
+ NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
+
+ // lists
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ol", "ol");
+ NS_REGISTER_STYLE_COMMAND(nsListCommand, "cmd_ul", "ul");
+
+ // format stuff
+ NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand, "cmd_paragraphState");
+ NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
+ NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
+ NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
+ NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
+
+ return NS_OK;
+}
+
+
+nsWeakPtr nsComposerController::sComposerCommandManager = NULL;
+
+nsresult nsComposerController::GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager)
+{
+ NS_ENSURE_ARG_POINTER(outCommandManager);
+
+/*
+ nsCOMPtr cmdManager = do_QueryReferent(sComposerCommandManager);
+ if (!cmdManager)
+ {
+ nsresult rv;
+ cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ // register the commands. This just happens once per instance
+ rv = nsComposerController::RegisterComposerCommands(cmdManager);
+ if (NS_FAILED(rv)) return rv;
+
+ // save the singleton in our static weak reference
+ sComposerCommandManager = getter_AddRefs(NS_GetWeakReference(cmdManager, &rv));
+ if (NS_FAILED(rv)) return rv;
+ }
+*/
+ // always make a new one
+ nsresult rv;
+ nsCOMPtr cmdManager;
+ cmdManager = do_CreateInstance("component://netscape/rdf/controller-command-manager", &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ // register the commands.
+ rv = nsComposerController::RegisterComposerCommands(cmdManager);
+ if (NS_FAILED(rv)) return rv;
+
+ NS_ADDREF(*outCommandManager = cmdManager);
+ return NS_OK;
+}
+
+
diff --git a/mozilla/editor/libeditor/base/nsEditorController.h b/mozilla/editor/libeditor/base/nsEditorController.h
index d2b6eff42c0..09412862636 100644
--- a/mozilla/editor/libeditor/base/nsEditorController.h
+++ b/mozilla/editor/libeditor/base/nsEditorController.h
@@ -23,23 +23,30 @@
#define NS_EDITORCONTROLLER_CID \
{ 0x26fb965c, 0x9de6, 0x11d3, { 0xbc, 0xcc, 0x0, 0x60, 0xb0, 0xfc, 0x76, 0xbd } }
+#define NS_COMPOSERCONTROLLER_CID \
+{ 0x50e95301, 0x17a8, 0x11d4, { 0x9f, 0x7e, 0xdd, 0x53, 0x0d, 0x5f, 0x05, 0x7c } }
+
+
#include "nsIController.h"
#include "nsIEditorController.h"
#include "nsIControllerCommand.h"
+#include "nsIInterfaceRequestor.h"
#include "nsHashtable.h"
#include "nsString.h"
#include "nsWeakPtr.h"
-class nsIHTMLContent;
-class nsIGfxTextControlFrame;
class nsIEditor;
-class nsISelectionController;
+class nsIEditorShell;
class nsBaseCommand;
+// the editor controller is used for both text widgets, and basic text editing
+// commands in composer. The refCon that gets passed to its commands is an nsIEditor.
+
class nsEditorController : public nsIController,
- public nsIEditorController
+ public nsIEditorController,
+ public nsIInterfaceRequestor
{
public:
@@ -53,48 +60,68 @@ public:
NS_DECL_NSICONTROLLER
/** init the controller */
- NS_IMETHOD Init();
-
- /** set the content for this controller instance */
- NS_IMETHOD SetContent(nsIHTMLContent *aContent);
-
- /** set the editor for this controller. Mutually exclusive with setContent*/
- NS_IMETHOD SetEditor(nsIEditor *aEditor);
+ NS_IMETHOD Init(nsISupports *aCommandRefCon);
+ /** Set the cookie that is passed to commands
+ */
+ NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon);
+ // nsIInterfaceRequestor
+ NS_DECL_NSIINTERFACEREQUESTOR
+
protected:
- /** fetch the primary frame associated with mContent */
- NS_IMETHOD GetFrame(nsIGfxTextControlFrame **aFrame);
-
- /** fetch the editor associated with mContent */
- NS_IMETHOD GetEditor(nsIEditor ** aEditor);
-
- NS_IMETHOD GetSelectionController(nsISelectionController ** aSelCon);
/** return PR_TRUE if the editor associated with mContent is enabled */
- PRBool IsEnabled();
+ PRBool IsEnabled();
/* register a command */
nsresult RegisterEditorCommand(nsBaseCommand* aCommand);
protected:
- nsIHTMLContent* mContent; // weak reference, the content object owns this object
-
//if editor is null then look to mContent. this is for dual use of window and content
//attached controller.
- nsIEditor *mEditor;
+ nsISupports *mCommandRefCon;
nsCOMPtr mCommandManager; // our reference to the command manager
+protected:
+
+ static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand);
+
private:
- static nsresult GetCommandManager(nsIControllerCommandManager* *outCommandManager);
+ static nsresult GetEditorCommandManager(nsIControllerCommandManager* *outCommandManager);
static nsresult RegisterEditorCommands(nsIControllerCommandManager* inCommandManager);
- static nsresult RegisterOneCommand(const PRUnichar* aCommandName, nsIControllerCommandManager *inCommandManager, nsBaseCommand* aCommand);
// the singleton command manager
- static nsWeakPtr sCommandManager;
+ static nsWeakPtr sEditorCommandManager; // common editor (i.e. text widget) commands
};
+
+
+
+// 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 nsEditorController
+{
+public:
+
+ nsComposerController();
+ virtual ~nsComposerController();
+
+ /** init the controller */
+ NS_IMETHOD Init(nsISupports *aCommandRefCon);
+
+protected:
+
+private:
+
+ static nsresult GetComposerCommandManager(nsIControllerCommandManager* *outCommandManager);
+ static nsresult RegisterComposerCommands(nsIControllerCommandManager* inCommandManager);
+
+ // the singleton command manager
+ static nsWeakPtr sComposerCommandManager; // composer-specific commands (lots of them)
+};
diff --git a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp
index 241a8b038ed..46c79b16a65 100644
--- a/mozilla/editor/libeditor/build/nsEditorRegistration.cpp
+++ b/mozilla/editor/libeditor/build/nsEditorRegistration.cpp
@@ -36,6 +36,7 @@
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorShell)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorController)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsComposerController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService)
#ifdef ENABLE_EDITOR_API_LOG
@@ -58,8 +59,10 @@ static nsModuleComponentInfo components[] = {
{ "HTML Editor", NS_HTMLEDITOR_CID,
"component://netscape/editor/htmleditor", nsHTMLEditorConstructor, },
#endif
- { "Editor Shell Controller", NS_EDITORCONTROLLER_CID,
+ { "Editor Controller", NS_EDITORCONTROLLER_CID,
"component://netscape/editor/editorcontroller", nsEditorControllerConstructor, },
+ { "Composer Controller", NS_COMPOSERCONTROLLER_CID,
+ "component://netscape/editor/composercontroller", nsComposerControllerConstructor, },
{ "Editor Shell Component", NS_EDITORSHELL_CID,
"component://netscape/editor/editorshell", nsEditorShellConstructor, },
{ "Editor Shell Spell Checker", NS_EDITORSHELL_CID,
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
index f29f6489c90..daf5e9c57fe 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
@@ -1779,7 +1779,7 @@ NS_IMETHODIMP nsHTMLEditor::GetInlineProperty(nsIAtom *aProperty,
iter->Init(range);
nsCOMPtr content;
- result = iter->CurrentNode(getter_AddRefs(content));
+ iter->CurrentNode(getter_AddRefs(content));
while (NS_ENUMERATOR_FALSE == iter->IsDone())
{
//if (gNoisy) { printf(" checking node %p\n", content.get()); }
diff --git a/mozilla/editor/public/nsIEditorController.h b/mozilla/editor/public/nsIEditorController.h
index 41184d50a02..869d0b4c6e0 100644
--- a/mozilla/editor/public/nsIEditorController.h
+++ b/mozilla/editor/public/nsIEditorController.h
@@ -30,22 +30,22 @@
{ 0x99, 0x33, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }}
-class nsIHTMLContent;
class nsIEditor;
+class nsCString;
class nsIEditorController : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IEDITORCONTROLLER_IID)
- /** init the controller */
- NS_IMETHOD Init() = 0;
+ /** init the controller
+ * aCommandRefCon = a cookie that is passed to commands
+ */
+ NS_IMETHOD Init(nsISupports *aCommandRefCon) = 0;
- /** set the content for this controller instance */
- NS_IMETHOD SetContent(nsIHTMLContent *aContent) = 0;
-
- /** set the editor for this controller. Mutually exclusive with setContent*/
- NS_IMETHOD SetEditor(nsIEditor *aEditor) = 0;
+ /** Set the cookie that is passed to commands
+ */
+ NS_IMETHOD SetCommandRefCon(nsISupports *aCommandRefCon) = 0;
};
diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js
index 1efd4e04704..8f8c6b0970c 100644
--- a/mozilla/editor/ui/composer/content/EditorCommands.js
+++ b/mozilla/editor/ui/composer/content/EditorCommands.js
@@ -45,7 +45,7 @@ var gStyleTags = {
};
const nsIFilePicker = Components.interfaces.nsIFilePicker;
-
+
function EditorOnLoad()
{
// See if argument was passed.
@@ -82,7 +82,7 @@ function TextEditorOnLoad()
function PageIsEmptyAndUntouched()
{
- return (editorShell.documentIsEmpty == true) && (docWasModified == false);
+ return (editorShell != null) && (editorShell.documentIsEmpty == true) && (docWasModified == false);
}
// This is called when the real editor document is created,
@@ -91,10 +91,14 @@ var DocumentStateListener =
{
NotifyDocumentCreated: function()
{
+ // Call EditorSetDefaultPrefs first so it gets the default author before initing toolbars
EditorSetDefaultPrefs();
- // Call EditorSetDefaultPrefs first
- // so it gets the default author before initing toolbars
EditorInitToolbars();
+
+ // udpate menu items now that we have an editor to play with
+ //dump("Updating 'create' commands\n");
+ content.focus();
+ window.updateCommands("create");
},
NotifyDocumentWillBeDestroyed: function() {},
@@ -104,6 +108,10 @@ var DocumentStateListener =
another document is opened */
if (isNowDirty)
docWasModified = true;
+
+ // hack! Should not need this, but there is some controller bug that this
+ // works around.
+ window.updateCommands("create");
}
};
@@ -115,11 +123,17 @@ function EditorStartup(editorType, editorElement)
editorShell = editorElement.editorShell;
editorShell.Init();
- editorShell.SetWebShellWindow(window);
- editorShell.SetToolbarWindow(window)
editorShell.SetEditorType(editorType);
- editorShell.SetContentWindow(contentWindow);
+ editorShell.webShellWindow = window;
+ editorShell.contentWindow = contentWindow;
+
+ // hide UI that we don't have components for
+ HideInapplicableUIElements();
+
+ // set up JS-implemented commands
+ SetupControllerCommands();
+
// add a listener to be called when document is really done loading
editorShell.RegisterDocumentStateListener( DocumentStateListener );
@@ -132,6 +146,8 @@ function EditorStartup(editorType, editorElement)
// This still doesn't work!
// It works after using a toolbar button, however!
contentWindow.focus();
+ // call updateCommands to disable while we're loading the page
+ window.updateCommands("create");
}
@@ -140,6 +156,11 @@ function _EditorNotImplemented()
dump("Function not implemented\n");
}
+function _EditorObsolete()
+{
+ dump("Function is obsolete\n");
+}
+
function EditorShutdown()
{
dump("In EditorShutdown..\n");
@@ -278,56 +299,12 @@ function FindAndSelectEditorWindowWithURL(urlToMatch)
function EditorOpen()
{
- dump("In EditorOpen..\n");
-
- var fp = Components.classes["component://mozilla/filepicker"].createInstance(nsIFilePicker);
- fp.init(window, editorShell.GetString("OpenHTMLFile"), nsIFilePicker.modeOpen);
-
- // While we include "All", include filters that prefer HTML and Text files
- fp.setFilters(nsIFilePicker.filterText | nsIFilePicker.filterHTML | nsIFilePicker.filterAll);
-
- /* doesn't handle *.shtml files */
- try {
- fp.show();
- /* need to handle cancel (uncaught exception at present) */
- }
- catch (ex) {
- dump("filePicker.chooseInputFile threw an exception\n");
- }
-
- /* check for already open window and activate it...
- * note that we have to test the native path length
- * since fileURL.spec will be "file:///" if no filename picked (Cancel button used)
- */
- if (fp.file && fp.file.path.length > 0) {
-
- var found = FindAndSelectEditorWindowWithURL(fp.fileURL.spec);
- if (!found)
- {
- // if the existing window is untouched, just load there
- if (PageIsEmptyAndUntouched())
- {
- editorShell.LoadUrl(fp.fileURL.spec);
- }
- else
- {
- /* open new window */
- window.openDialog("chrome://editor/content",
- "_blank",
- "chrome,dialog=no,all",
- fp.fileURL.spec);
- }
- }
- }
+ return _EditorObsolete();
}
function EditorOpenRemote()
{
- /* The last parameter is the current browser window.
- Use 0 and the default checkbox will be to load into an editor
- and loading into existing browser option is removed
- */
- window.openDialog( "chrome://navigator/content/openLocation.xul", "_blank", "chrome,modal", 0);
+ return _EditorObsolete();
}
// used by openLocation. see navigator.js for additional notes.
@@ -357,29 +334,32 @@ function EditorSaveDocument(doSaveAs, doSaveCopy)
function EditorSave()
{
- dump("In EditorSave...\n");
- EditorSaveDocument(false, false)
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorSaveAs()
{
- EditorSaveDocument(true, false);
- contentWindow.focus();
+ return _EditorObsolete();
}
-
function EditorPrint()
{
- dump("In EditorPrint..\n");
- editorShell.Print();
- contentWindow.focus();
+ return _EditorObsolete();
+}
+
+function EditorPrintSetup()
+{
+ return _EditorObsolete();
+}
+
+function EditorPrintPreview()
+{
+ return _EditorObsolete();
}
function EditorClose()
{
- dump("In EditorClose...\n");
- return editorShell.CloseWindow();
+ return _EditorObsolete();
}
// Check for changes to document and allow saving before closing
@@ -438,18 +418,12 @@ function EditorSelectAll()
function EditorFind()
{
- editorShell.Find();
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorFindNext()
{
- editorShell.FindNext();
-}
-
-function EditorShowClipboard()
-{
- dump("EditorShowClipboard not implemented\n");
+ return _EditorObsolete();
}
// --------------------------- View menu ---------------------------
@@ -497,6 +471,15 @@ function EditorSetTextProperty(property, attribute, value)
contentWindow.focus();
}
+/*
+function EditorSelectParagraphFormat(commandID, select)
+{
+ content.focus(); // required hack for now
+
+ if (select.selectedIndex != -1)
+ EditorSetParagraphFormat(commandID, gParagraphTagNames[select.selectedIndex]);
+}
+*/
function onParagraphFormatChange()
{
@@ -509,7 +492,7 @@ function onParagraphFormatChange()
var format = select.getAttribute("format");
if ( format == "mixed")
{
-dump("Mixed paragraph format *******\n");
+//dump("Mixed paragraph format *******\n");
// No single type selected
newIndex = -1;
}
@@ -529,10 +512,14 @@ dump("Mixed paragraph format *******\n");
}
}
-function EditorSetParagraphFormat(paraFormat)
+function EditorSetParagraphFormat(commandID, paraFormat)
{
- editorShell.SetParagraphFormat(paraFormat);
- contentWindow.focus();
+ // editorShell.SetParagraphFormat(paraFormat);
+ var commandNode = document.getElementById(commandID);
+ dump("Saving para format state " + paraFormat + "\n");
+ commandNode.setAttribute("state", paraFormat);
+ window.content.focus(); // needed for command dispatch to work
+ goDoCommand(commandID);
}
@@ -569,7 +556,7 @@ function onFontFaceChange()
function EditorSetFontFace(fontFace)
{
- if( fontFace == "tt") {
+ if (fontFace == "tt") {
// The old "teletype" attribute
editorShell.SetTextProperty("tt", "", "");
// Clear existing font face
@@ -584,14 +571,14 @@ function EditorSetFontFace(fontFace)
editorShell.SetTextProperty("font", "face", fontFace);
}
}
-dump("Setting focus to content window...\n");
+//dump("Setting focus to content window...\n");
contentWindow.focus();
}
function EditorSelectFontSize()
{
var select = document.getElementById("FontSizeSelect");
-dump("EditorSelectFontSize: "+gFontSizeNames[select.selectedIndex]+"\n");
+//dump("EditorSelectFontSize: "+gFontSizeNames[select.selectedIndex]+"\n");
if (select)
{
if (select.selectedIndex == -1)
@@ -679,20 +666,18 @@ function EditorSetFontSize(size)
function EditorIncreaseFontSize()
{
- editorShell.IncreaseFontSize();
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorDecreaseFontSize()
{
- editorShell.DecreaseFontSize();
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorSelectTextColor(ColorPickerID, ColorWellID)
{
var color = getColorAndSetColorWell(ColorPickerID, ColorWellID);
-dump("EditorSelectTextColor: "+color+"\n");
+// dump("EditorSelectTextColor: "+color+"\n");
// Close appropriate menupopup
var menupopup;
@@ -771,8 +756,7 @@ function EditorApplyStyle(tagName)
function EditorRemoveStyle(tagName)
{
- editorShell.RemoveTextProperty(tagName, "");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorToggleStyle(styleName)
@@ -825,17 +809,17 @@ function GetSelectedElementOrParentCell()
function EditorObjectProperties()
{
var element = GetSelectedElementOrParentCell();
- dump("EditorObjectProperties: element="+element+"\n");
+ // dump("EditorObjectProperties: element="+element+"\n");
if (element)
{
- dump("TagName="+element.nodeName+"\n");
+ // dump("TagName="+element.nodeName+"\n");
switch (element.nodeName)
{
case 'IMG':
- EditorInsertOrEditImage();
+ goDoCommand("cmd_image");
break;
case 'HR':
- EditorInsertOrEditHLine();
+ goDoCommand("cmd_hline");
break;
case 'TABLE':
EditorInsertOrEditTable(false);
@@ -845,188 +829,81 @@ function EditorObjectProperties()
break;
case 'A':
if(element.href)
- EditorInsertOrEditLink();
+ goDoCommand("cmd_link");
else if (element.name)
- EditorInsertOrEditNamedAnchor();
+ goDoCommand("cmd_anchor");
break;
}
} else {
// We get a partially-selected link if asked for specifically
element = editorShell.GetSelectedElement("href");
if (element)
- EditorInsertOrEditLink();
+ goDoCommand("cmd_link");
}
}
function EditorListProperties()
{
- window.openDialog("chrome://editor/content/EdListProps.xul","_blank", "chrome,close,titlebar,modal");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorPageProperties()
{
- window.openDialog("chrome://editor/content/EdPageProps.xul","_blank", "chrome,close,titlebar,modal,resizable", "");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorColorProperties()
{
- window.openDialog("chrome://editor/content/EdColorProps.xul","_blank", "chrome,close,titlebar,modal", "");
- contentWindow.focus();
+ return _EditorObsolete();
}
// --------------------------- Dialogs ---------------------------
function EditorInsertHTML()
{
- // Resizing doesn't work!
- window.openDialog("chrome://editor/content/EdInsSrc.xul","_blank", "chrome,close,titlebar,modal,resizable");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorInsertOrEditLink()
{
- window.openDialog("chrome://editor/content/EdLinkProps.xul","_blank", "chrome,close,titlebar,modal");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorInsertOrEditImage()
{
- window.openDialog("chrome://editor/content/EdImageProps.xul","_blank", "chrome,close,titlebar,modal");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorInsertOrEditHLine()
{
- // Inserting an HLine is different in that we don't use properties dialog
- // unless we are editing an existing line's attributes
- // We get the last-used attributes from the prefs and insert immediately
-
- tagName = "hr";
- hLine = editorShell.GetSelectedElement(tagName);
-
- if (hLine) {
- dump("HLine was found -- opening dialog...!\n");
-
- // We only open the dialog for an existing HRule
- window.openDialog("chrome://editor/content/EdHLineProps.xul", "_blank", "chrome,close,titlebar,modal");
- } else {
- hLine = editorShell.CreateElementWithDefaults(tagName);
-
- if (hLine) {
- // We change the default attributes to those saved in the user prefs
- var prefs = Components.classes['component://netscape/preferences'];
- if (prefs) {
- prefs = prefs.getService();
- }
- if (prefs) {
- prefs = prefs.QueryInterface(Components.interfaces.nsIPref);
- }
- if (prefs) {
- dump(" We found the Prefs Service\n");
- var percent;
- var height;
- var shading;
- var ud = "undefined";
-
- try {
- var align = prefs.GetIntPref("editor.hrule.align");
- dump("Align pref: "+align+"\n");
- if (align == 0 ) {
- hLine.setAttribute("align", "left");
- } else if (align == 2) {
- hLine.setAttribute("align", "right");
- } else {
- // Default is center
- hLine.setAttribute("align", "center");
- }
-
- var width = prefs.GetIntPref("editor.hrule.width");
- var percent = prefs.GetBoolPref("editor.hrule.width_percent");
- dump("Width pref: "+width+", percent:"+percent+"\n");
- if (percent)
- width = width +"%";
-
- hLine.setAttribute("width", width);
-
- var height = prefs.GetIntPref("editor.hrule.height");
- dump("Size pref: "+height+"\n");
- hLine.setAttribute("size", String(height));
-
- var shading = prefs.GetBoolPref("editor.hrule.shading");
- dump("Shading pref:"+shading+"\n");
- if (shading) {
- hLine.removeAttribute("noshade");
- } else {
- hLine.setAttribute("noshade", "");
- }
- }
- catch (ex) {
- dump("failed to get HLine prefs\n");
- }
- }
- try {
- editorShell.InsertElementAtSelection(hLine, true);
- } catch (e) {
- dump("Exception occured in InsertElementAtSelection\n");
- }
- }
- }
- contentWindow.focus();
-}
+ return _EditorObsolete();}
function EditorInsertChars()
{
- window.openDialog("chrome://editor/content/EdInsertChars.xul", "_blank", "chrome,close,titlebar", "");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorInsertOrEditNamedAnchor()
{
- window.openDialog("chrome://editor/content/EdNamedAnchorProps.xul", "_blank", "chrome,close,titlebar,modal", "");
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorIndent(indent)
{
- dump(indent+"\n");
- editorShell.Indent(indent);
- contentWindow.focus();
+ return _EditorObsolete();
}
function EditorMakeOrChangeList(listType)
{
- // check the observer node,
- // which is the appropriate button
- var theButton = document.getElementById(listType + "Button");
-
- if (theButton)
- {
- var buttonFormat = theButton.getAttribute("format");
- var isOn = (listType == buttonFormat);
-
- if (isOn == 1)
- {
- editorShell.RemoveList(listType);
- }
- else
- {
- editorShell.MakeOrChangeList(listType);
- }
-
- contentWindow.focus();
- }
- else
- {
- dump("No button found for the " + listType + " style\n");
- }
+ return _EditorObsolete();
}
-function EditorAlign(align)
+function EditorAlign(commandID, alignType)
{
- editorShell.Align(align);
- contentWindow.focus();
+ var commandNode = document.getElementById(commandID);
+ // dump("Saving para format state " + alignType + "\n");
+ commandNode.setAttribute("state", alignType);
+ goDoCommand(commandID);
}
function EditorSetDisplayMode(mode)
@@ -1043,11 +920,6 @@ function EditorSetDisplayMode(mode)
contentWindow.focus();
}
-function EditorEditHTML()
-{
- dump("EditorEditHTML NOT IMPLEMENTED\n");
-}
-
function EditorToggleParagraphMarks()
{
var menuItem = document.getElementById("viewParagraphMarks");
@@ -1071,78 +943,12 @@ function EditorToggleParagraphMarks()
function EditorPreview()
{
- if (!editorShell.CheckAndSaveDocument(editorShell.GetString("BeforePreview")))
- return;
-
- fileurl = "";
- try {
- fileurl = window.content.location;
- } catch (e) {
- return;
- }
-
- // CheckAndSave doesn't tell us if the user said "Don't Save",
- // so make sure we have a url:
- if (fileurl != "" && fileurl != "about:blank") {
- window.openDialog(getBrowserURL(),
- "EditorPreview",
- "chrome,all,dialog=no",
- fileurl );
- }
-}
-
-function EditorPrintSetup()
-{
- // Old code? Browser no longer is doing this
- //window.openDialog("resource:/res/samples/printsetup.html", "_blank", "chrome,close,titlebar", "");
- _EditorNotImplemented();
- contentWindow.focus();
-}
-
-function EditorPrintPreview()
-{
- _EditorNotImplemented();
- contentWindow.focus();
+ return _EditorObsolete();
}
function CheckSpelling()
{
- var spellChecker = editorShell.QueryInterface(Components.interfaces.nsIEditorSpellCheck);
- if (spellChecker)
- {
- dump("Check Spelling starting...\n");
- // Start the spell checker module. Return is first misspelled word
- try {
- firstMisspelledWord = spellChecker.StartSpellChecking();
- }
- catch(ex) {
- dump("*** Exception error: StartSpellChecking\n");
- return;
- }
- if( firstMisspelledWord == "")
- {
- try {
- spellChecker.CloseSpellChecking();
- }
- catch(ex) {
- dump("*** Exception error: CloseSpellChecking\n");
- return;
- }
- // No misspelled word - tell user
- editorShell.AlertWithTitle(editorShell.GetString("CheckSpelling"), editorShell.GetString("NoMisspelledWord"));
- } else {
- // Set spellChecker variable on window
- window.spellChecker = spellChecker;
- try {
- window.openDialog("chrome://editor/content/EdSpellCheck.xul", "_blank", "chrome,close,titlebar,modal", "", firstMisspelledWord);
- }
- catch(ex) {
- dump("*** Exception error: SpellChecker Dialog Closing\n");
- return;
- }
- }
- }
- contentWindow.focus();
+ return _EditorObsolete();
}
function SetBackColorString(xulElementID)
@@ -1499,23 +1305,56 @@ function EditorSetSelectionFromOffsets(selRanges)
function EditorExit()
{
- dump("Exiting in EditorExit\n");
- // This is in globalOverlay.js
- goQuitApplication();
+ return _EditorObsolete();
}
+
+//--------------------------------------------------------------------
+function initFontStyleMenu(menuPopup)
+{
+ for (var i = 0; i < menuPopup.childNodes.length; i++)
+ {
+ var menuItem = menuPopup.childNodes[i];
+ var theStyle = menuItem.getAttribute("state");
+ if (theStyle)
+ {
+ menuItem.setAttribute("checked", theStyle);
+ }
+ }
+}
+
+//--------------------------------------------------------------------
+function onButtonUpdate(button, commmandID)
+{
+ var commandNode = document.getElementById(commmandID);
+ var state = commandNode.getAttribute("state");
+
+ button.setAttribute("toggled", state);
+}
+
+
// --------------------------- Status calls ---------------------------
function onStyleChange(theStyle)
{
+ dump("in onStyleChange with " + theStyle + "\n");
+
+ var broadcaster = document.getElementById("cmd_" + theStyle);
+ var isOn = broadcaster.getAttribute("state");
+
+ // PrintObject(broadcaster);
+
var theButton = document.getElementById(theStyle + "Button");
if (theButton)
{
- var isOn = theButton.getAttribute(theStyle);
- if (isOn == "true") {
- theButton.setAttribute("toggled", 1);
- } else {
- theButton.setAttribute("toggled", 0);
- }
+ // dump("setting button to " + isOn + "\n");
+ theButton.setAttribute("toggled", (isOn == "true") ? 1 : 0);
+ }
+
+ var theMenuItem = document.getElementById(theStyle + "MenuItem");
+ if (theMenuItem)
+ {
+ // dump("setting menuitem to " + isOn + "\n");
+ theMenuItem.setAttribute("checked", isOn);
}
}
@@ -1540,11 +1379,11 @@ function onListFormatChange(listType)
var theButton = document.getElementById(listType + "Button");
if (theButton)
{
- var listFormat = theButton.getAttribute("format");
- if (listFormat == listType) {
- theButton.setAttribute("toggled", 1);
+ var isOn = theButton.getAttribute(listType);
+ if (isOn == "true") {
+ theButton.setAttribute("toggled", "true");
} else {
- theButton.setAttribute("toggled", 0);
+ theButton.setAttribute("toggled", "false");
}
}
}
@@ -1558,7 +1397,6 @@ function getColorAndSetColorWell(ColorPickerID, ColorWellID)
var colorPicker = document.getElementById(ColorPickerID);
if (colorPicker)
{
-dump("ColorPicker found\n");
// Extract color from colorPicker and assign to colorWell.
var color = colorPicker.getAttribute('color');
dump("setColor to: "+color+"\n");
@@ -1704,3 +1542,39 @@ function EditorDeleteTableCellContents()
contentWindow.focus();
}
+var gHaveSpellChecker = false;
+var gSoughtSpellChecker = false;
+
+//-----------------------------------------------------------------------------------
+function IsSpellCheckerInstalled()
+{
+ return true; // fix me when kin checks in
+
+ if (gSoughtSpellChecker)
+ return gHaveSpellChecker;
+
+ var spellcheckerClass = Components.classes["org.mozilla.spellchecker.1"];
+ gHaveSpellChecker = (spellcheckerClass != null);
+ gSoughtSpellChecker = true;
+ return gHaveSpellChecker;
+}
+
+//-----------------------------------------------------------------------------------
+function HideInapplicableUIElements()
+{
+ // if no spell checker, remove spell checker ui
+ if (!IsSpellCheckerInstalled())
+ {
+ dump("Hiding spell checker items\n");
+
+ var spellingButton = document.getElementById("spellingButton");
+ if (spellingButton)
+ spellingButton.setAttribute("hidden", "true");
+
+ var spellingMenuItem = document.getElementById("menu_checkspelling");
+ if (spellingMenuItem)
+ spellingMenuItem.setAttribute("hidden", "true");
+ }
+
+}
+
diff --git a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js
index 86d85929a1c..ca79e6a9095 100644
--- a/mozilla/editor/ui/composer/content/EditorCommandsDebug.js
+++ b/mozilla/editor/ui/composer/content/EditorCommandsDebug.js
@@ -29,7 +29,7 @@ function EditorGetText()
if (editorShell) {
dump("Getting text\n");
var outputText = editorShell.GetContentsAs("text/plain", 2);
- dump(outputText + "\n");
+ dump("<<" + outputText + ">>\n");
}
}
diff --git a/mozilla/editor/ui/composer/content/editor.xul b/mozilla/editor/ui/composer/content/editor.xul
index 6fba1122c27..ad92181a370 100644
--- a/mozilla/editor/ui/composer/content/editor.xul
+++ b/mozilla/editor/ui/composer/content/editor.xul
@@ -48,14 +48,21 @@
persist="screenX screenY width height"
>
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -67,7 +74,7 @@
-
+
diff --git a/mozilla/editor/ui/composer/content/editorOverlay.xul b/mozilla/editor/ui/composer/content/editorOverlay.xul
index d117a316c30..c5b9031ce69 100644
--- a/mozilla/editor/ui/composer/content/editorOverlay.xul
+++ b/mozilla/editor/ui/composer/content/editorOverlay.xul
@@ -40,12 +40,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
@@ -55,99 +55,165 @@
-
+
-
+
-
-
+
+
-
-
-
+
+
+
-
-
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -168,22 +234,22 @@
-
-
+
+
-
-
-
+
+
+
-
+
-
-
-
+
+
+
-
+
@@ -203,11 +269,11 @@
-
+
-
+
-
+
@@ -315,16 +381,16 @@
@@ -348,8 +414,8 @@
accesskey="&formatsizemenu.accesskey;"
position="2">
-
-
+
+
@@ -365,23 +431,23 @@
@@ -450,7 +516,7 @@
+ oncommand="goDoCommand('cmd_removeStyles')" position="6"/>
@@ -460,7 +526,7 @@