From 53953ee69005a4dd6cee2e8213a8514564bdbdd8 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Mon, 7 Oct 2002 20:13:09 +0000 Subject: [PATCH] Fixed broken smileys in Mail Composer. b=70031, r=suresh, sr=kin --- .../ui/composer/content/ComposerCommands.js | 42 ++--- .../composer/content/EditorCommandsDebug.js | 8 +- editor/ui/composer/content/editor.js | 172 +++++++++--------- editor/ui/composer/content/editor.xul | 2 +- 4 files changed, 101 insertions(+), 123 deletions(-) diff --git a/editor/ui/composer/content/ComposerCommands.js b/editor/ui/composer/content/ComposerCommands.js index aa8a748ecc7..53d6562c888 100644 --- a/editor/ui/composer/content/ComposerCommands.js +++ b/editor/ui/composer/content/ComposerCommands.js @@ -3100,19 +3100,14 @@ var nsSetSmiley = { isCommandEnabled: function(aCommand, dummy) { - return ( window.editorShell && window.editorShell.documentEditable && IsEditingRenderedHTML()); - + return (IsDocumentEditable() && IsEditingRenderedHTML()); }, getCommandStateParams: function(aCommand, aParams, aRefCon) {}, - doCommandParams: function(aCommand, aParams, aRefCon) {}, - - doCommand: function(aCommand) + doCommandParams: function(aCommand, aParams, aRefCon) { - - var commandNode = document.getElementById(aCommand); - var smileyCode = commandNode.getAttribute("state"); - + var smileyCode = aParams.getCStringValue("state_attribute"); + var strSml; switch(smileyCode) { @@ -3136,36 +3131,29 @@ var nsSetSmiley = try { - var selection = window.editorShell.editorSelection; - - if (!selection) - return; - - var extElement = editorShell.CreateElementWithDefaults("span"); - if (!extElement) - return; - + var editor = GetCurrentEditor(); + var selection = editor.selection; + var extElement = editor.createElementWithDefaults("span"); extElement.setAttribute("class", "moz-smiley-" + strSml); - - var intElement = editorShell.CreateElementWithDefaults("span"); + var intElement = editor.createElementWithDefaults("span"); if (!intElement) return; - //just for mailnews, because of the way it removes HTML + //just for mailnews, because of the way it removes HTML var smileButMenu = document.getElementById('smileButtonMenu'); if (smileButMenu.getAttribute("padwithspace")) smileyCode = " " + smileyCode + " "; - var txtElement = document.createTextNode(smileyCode); + var txtElement = editor.document.createTextNode(smileyCode); if (!txtElement) - return; + return; intElement.appendChild (txtElement); extElement.appendChild (intElement); - editorShell.InsertElementAtSelection(extElement,true); + editor.insertElementAtSelection(extElement,true); window._content.focus(); } @@ -3173,9 +3161,9 @@ var nsSetSmiley = { dump("Exception occured in smiley InsertElementAtSelection\n"); } - - } - + }, + // This is now deprecated in favor of "doCommandParams" + doCommand: function(aCommand) {} }; diff --git a/editor/ui/composer/content/EditorCommandsDebug.js b/editor/ui/composer/content/EditorCommandsDebug.js index 6f828ca10d5..51815503360 100644 --- a/editor/ui/composer/content/EditorCommandsDebug.js +++ b/editor/ui/composer/content/EditorCommandsDebug.js @@ -43,20 +43,20 @@ function EditorGetText() { - if (editorShell) { + try { dump("Getting text\n"); var outputText = GetCurrentEditor().outputToString("text/plain", 2); dump("<<" + outputText + ">>\n"); - } + } catch (e) {} } function EditorGetHTML() { - if (editorShell) { + try { dump("Getting HTML\n"); var outputHTML = GetCurrentEditor().outputToString("text/html", 256); dump(outputHTML + "\n"); - } + } catch (e) {} } function EditorDumpContent() diff --git a/editor/ui/composer/content/editor.js b/editor/ui/composer/content/editor.js index 78fbc71cf46..4173baf34d0 100644 --- a/editor/ui/composer/content/editor.js +++ b/editor/ui/composer/content/editor.js @@ -63,7 +63,6 @@ const kHTMLMimeType = "text/html"; var gPreviousNonSourceDisplayMode = 1; var gEditorDisplayMode = -1; -var WebCompose = false; // Set true for Web Composer, leave false for Messenger Composer var docWasModified = false; // Check if clean document, if clean then unload when user "Opens" var gContentWindow = 0; var gSourceContentWindow = 0; @@ -164,7 +163,6 @@ function EditorOnLoad() } } - WebCompose = true; window.tryToClose = EditorCanClose; // Continue with normal startup. @@ -207,6 +205,26 @@ function IsEditingRenderedHTML() return isHTMLEditor() && !IsInHTMLSourceMode(); } +function IsWebComposer() +{ + return document.getElementById("WebComposerWindow") != null; +} + +function IsDocumentEditable() +{ + try { + return GetCurrentEditor().isDocumentEditable; + } catch (e) {} + return false; +} + +function IsDocumentModified() +{ + try { + return GetCurrentEditor().documentModified; + } catch(e) {} + return false; +} var DocumentReloadListener = { @@ -234,56 +252,6 @@ function addEditorClickEventListener() } catch (e) {} } -function DoWindowCommandControllerSetting(aEditor) -{ - // Get the window command controller created in SetupComposerWindowCommands() - if (gComposerWindowControllerID != -1) - { - try { - var controller = window.controllers.getControllerById(gComposerWindowControllerID); - controller.SetCommandRefCon(aEditor.QueryInterface(Components.interfaces.nsISupports)); - } catch (e) {} - } -} - -var MessageComposeDocumentStateListener = -{ - NotifyDocumentCreated: function() - { - gEditor = editorShell.editor; - - // do all of our QI'ing here so we don't need to do it elsewhere - DoAllQueryInterfaceOnEditor(); - try { - gEditor.QueryInterface(Components.interfaces.nsIEditorMailSupport); - } catch(e) {} - - // XXX Temporary: This should be set during startup - // once we finish transition from nsIEditorShell is to nsIEditorSession - try { - gEditor.contentsMIMEType = gIsHTMLEditor ? kHTMLMimeType : kTextMimeType; - } catch(e) {} - - addEditorClickEventListener(); - - try { - // Add the base sheet for editor cursor etc. - gEditor.addOverrideStyleSheet(kBaseEditorStyleSheet); - } catch (e) {} - }, - - NotifyDocumentWillBeDestroyed: function() - { - // note that the editor seems to be gone at this point - // so we don't have a way to remove the click listener. - // hopefully it is being cleaned up with all listeners - }, - - NotifyDocumentStateChanged:function() - { - } -}; - function DoAllQueryInterfaceOnEditor() { // do QI here so the interfaces will be accessible on gEditor @@ -303,58 +271,82 @@ function DoAllQueryInterfaceOnEditor() // This is called when the real editor document is created, // before it's loaded. +// IMPORTANT: This is used by ALL Composers, so be careful! var DocumentStateListener = { NotifyDocumentCreated: function() { gEditor = editorShell.editor; - DoWindowCommandControllerSetting(gEditor); + // Just for convenience + gContentWindow = window._content; // do all of our QI'ing here so we don't need to do it elsewhere DoAllQueryInterfaceOnEditor(); + if (editorShell.editorType == "htmlmail" + || editorShell.editorType == "textmail") + { + gEditor.QueryInterface(Components.interfaces.nsIEditorMailSupport); + } + else + { + // Mail Composers start focus in address area + gContentWindow.focus(); + } + + if (!("InsertCharWindow" in window)) + window.InsertCharWindow = null; + + try { + // Add the base sheets for editor cursor etc. + gEditor.addOverrideStyleSheet(kBaseEditorStyleSheet); + + // and extra styles for showing anchors, table borders, smileys, etc + gEditor.addOverrideStyleSheet(kNormalStyleSheet); + } catch (e) {} + // XXX Temporary: This should be set during startup // once we finish transition from nsIEditorShell is to nsIEditorSession try { gEditor.contentsMIMEType = gIsHTMLEditor ? kHTMLMimeType : kTextMimeType; } catch(e) {} - - // Call EditorSetDefaultPrefsAndDoctype first so it gets the default author before initing toolbars - EditorSetDefaultPrefsAndDoctype(); - EditorInitToolbars(); - // Set window title and build "Recent Files" menu - // (to detect empty menu and disable it) - UpdateWindowTitle(); - BuildRecentMenu(); - - // Just for convenience - gContentWindow = window._content; - gContentWindow.focus(); - - // udpate menu items now that we have an editor to play with - // Note: This must be AFTER gContentWindow.focus(); - window.updateCommands("create"); - - if (!("InsertCharWindow" in window)) - window.InsertCharWindow = null; - - // We must wait until document is created to get proper Url - // (Windows may load with local file paths) - SetSaveAndPublishUI(GetDocumentUrl()); - // Add mouse click watcher if right type of editor if (isHTMLEditor()) addEditorClickEventListener(); - try { - // Add the base sheet for editor cursor etc. - gEditor.addOverrideStyleSheet(kBaseEditorStyleSheet); - } catch (e) {} + // udpate menu items now that we have an editor to play with + window.updateCommands("create"); - // Start in "Normal" edit mode - SetDisplayMode(kDisplayModeNormal); + // Do the rest only if a Web Composer application + if (IsWebComposer()) + { + // Get the window command controller created in SetupComposerWindowCommands() + if (gComposerWindowControllerID != -1) + { + try { + var controller = window.controllers.getControllerById(gComposerWindowControllerID); + controller.SetCommandRefCon(gEditor.QueryInterface(Components.interfaces.nsISupports)); + } catch (e) {} + } + + // Call EditorSetDefaultPrefsAndDoctype first so it gets the default author before initing toolbars + EditorSetDefaultPrefsAndDoctype(); + EditorInitToolbars(); + + // Set window title and build "Recent Files" menu + // (to detect empty menu and disable it) + UpdateWindowTitle(); + BuildRecentMenu(); + + // We must wait until document is created to get proper Url + // (Windows may load with local file paths) + SetSaveAndPublishUI(GetDocumentUrl()); + + // Start in "Normal" edit mode + SetDisplayMode(kDisplayModeNormal); + } }, // note that the editor seems to be gone at this point @@ -466,6 +458,7 @@ function EditorSharedStartup() // So we can't use gEditor.AddDocumentStateListener here. if (gIsHTMLEditor) { + //XXX this is replaced by nsIEditor::contentsMIMEType editorShell.contentsMIMEType = kHTMLMimeType; SetupHTMLEditorCommands(); } @@ -476,11 +469,7 @@ function EditorSharedStartup() } // add a listener to be called when document is really done loading - if (editorShell.editorType == "htmlmail" - || editorShell.editorType == "textmail") - editorShell.RegisterDocumentStateListener( MessageComposeDocumentStateListener ); - else - editorShell.RegisterDocumentStateListener( DocumentStateListener ); + editorShell.RegisterDocumentStateListener( DocumentStateListener ); var isMac = (GetOS() == gMac); @@ -1423,10 +1412,11 @@ function EditorClick(event) return; } - // In Show All Tags Mode, + // For Web Composer: In Show All Tags Mode, // single click selects entire element, // except for body and table elements - if (event.target && isHTMLEditor() && gEditorDisplayMode == kDisplayModeAllTags) + if (event.target && IsWebComposer() + && isHTMLEditor() && gEditorDisplayMode == kDisplayModeAllTags) { try { @@ -1813,7 +1803,7 @@ function UpdateWindowTitle() windowTitle += " [" + scheme + ":/.../" + filename + "]"; } // Set window title with " - Composer" appended - var xulWin = document.getElementById("editorWindow"); + var xulWin = document.getElementById("WebComposerWindow"); window.title = windowTitle + xulWin.getAttribute("titlemenuseparator") + xulWin.getAttribute("titlemodifier"); // Save changed title in the recent pages data in prefs diff --git a/editor/ui/composer/content/editor.xul b/editor/ui/composer/content/editor.xul index c36c0402efe..b53007c0374 100644 --- a/editor/ui/composer/content/editor.xul +++ b/editor/ui/composer/content/editor.xul @@ -50,7 +50,7 @@ %brandDTD; ]> -