Bug 1364772 - Adapt Composer editor part for Bug 589199 (top level const/let change). r=jorgk
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Sun, 18 Jun 2017 11:28:00 +0200
changeset 28363 c297dfe79c058e3e8119f12e86d30167a119a5d1
parent 28362 484beb60833c61561f1c447b972e7d4f55e52633
child 28364 ca4f670bb9da29c45608cc6a5d2c0b2cdc01afed
push id1986
push userclokep@gmail.com
push dateWed, 02 Aug 2017 14:43:31 +0000
treeherdercomm-beta@b51c9adf2c9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1364772, 589199, 1209777
Bug 1364772 - Adapt Composer editor part for Bug 589199 (top level const/let change). r=jorgk Followup fix for Bug 1209777.
editor/ui/composer/content/editor.js
editor/ui/composer/content/editorUtilities.js
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -1,35 +1,35 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource:///modules/editorUtilities.jsm");
+Components.utils.import("resource://gre/modules/AppConstants.jsm");
 
 /* Main Composer window UI control */
 
 var gComposerWindowControllerID = 0;
 var prefAuthorString = "";
 
-const kDisplayModeNormal = 0;
-const kDisplayModeAllTags = 1;
-const kDisplayModeSource = 2;
-const kDisplayModePreview = 3;
+var kDisplayModeNormal = 0;
+var kDisplayModeAllTags = 1;
+var kDisplayModeSource = 2;
+var kDisplayModePreview = 3;
+
 const kDisplayModeMenuIDs = ["viewNormalMode", "viewAllTagsMode", "viewSourceMode", "viewPreviewMode"];
 const kDisplayModeTabIDS = ["NormalModeButton", "TagModeButton", "SourceModeButton", "PreviewModeButton"];
 const kNormalStyleSheet = "chrome://editor/content/EditorContent.css";
 const kAllTagsStyleSheet = "chrome://editor/content/EditorAllTags.css";
 const kContentEditableStyleSheet = "resource://gre/res/contenteditable.css";
 
-const kTextMimeType = "text/plain";
-const kHTMLMimeType = "text/html";
-const kXHTMLMimeType = "application/xhtml+xml";
-
-const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
+var kTextMimeType = "text/plain";
+var kHTMLMimeType = "text/html";
+var kXHTMLMimeType = "application/xhtml+xml";
 
 var gPreviousNonSourceDisplayMode = 1;
 var gEditorDisplayMode = -1;
 var gDocWasModified = false;  // Check if clean document, if clean then unload when user "Opens"
 var gContentWindow = 0;
 var gSourceContentWindow = 0;
 var gSourceTextEditor = null;
 var gContentWindowDeck;
@@ -50,21 +50,21 @@ var gReturnInParagraphPrefListener;
 var gLocalFonts = null;
 
 var gLastFocusNode = null;
 var gLastFocusNodeWasSelected = false;
 
 // These must be kept in synch with the XUL <options> lists
 var gFontSizeNames = ["xx-small","x-small","small","medium","large","x-large","xx-large"];
 
-const nsIFilePicker = Components.interfaces.nsIFilePicker;
-
-const kEditorToolbarPrefs = "editor.toolbars.showbutton.";
-const kUseCssPref         = "editor.use_css";
-const kCRInParagraphsPref = "editor.CR_creates_new_p";
+var nsIFilePicker = Components.interfaces.nsIFilePicker;
+
+var kEditorToolbarPrefs = "editor.toolbars.showbutton.";
+var kUseCssPref         = "editor.use_css";
+var kCRInParagraphsPref = "editor.CR_creates_new_p";
 
 function ShowHideToolbarSeparators(toolbar) {
   // Make sure the toolbar actually exists.
   if (!toolbar)
     return;
   var childNodes = toolbar.childNodes;
   var separator = null;
   var hideSeparator = true;
@@ -400,21 +400,21 @@ function SetFocusOnStartup()
 {
   gContentWindow.focus();
 }
 
 function EditorLoadUrl(url)
 {
   try {
     if (url)
-      GetCurrentEditorElement().webNavigation.loadURI(url, // uri string
-             nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE,     // load flags
-             null,                                         // referrer
-             null,                                         // post-data stream
-             null);
+      GetCurrentEditorElement().webNavigation.loadURI(url,                // uri string
+         Components.interfaces.nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE,  // load flags
+         null,                                                            // referrer
+         null,                                                            // post-data stream
+         null);
   } catch (e) { dump(" EditorLoadUrl failed: "+e+"\n"); }
 }
 
 // This should be called by all Composer types
 function EditorSharedStartup()
 {
   // Just for convenience
   gContentWindow = window.content;
@@ -440,17 +440,17 @@ function EditorSharedStartup()
     commandManager.addCommandObserver(gEditorDocumentObserver, "obs_documentLocationChanged");
 
     // Until nsIControllerCommandGroup-based code is implemented,
     //  we will observe just the bold command to trigger update of
     //  all toolbar style items
     commandManager.addCommandObserver(gEditorDocumentObserver, "cmd_bold");
   } catch (e) { dump(e); }
 
-  var isMac = (GetOS() == gMac);
+  var isMac = AppConstants.platform == "macosx";
 
   // Set platform-specific hints for how to select cells
   // Mac uses "Cmd", all others use "Ctrl"
   var tableKey = GetString(isMac ? "XulKeyMac" : "TableSelectKey");
   var dragStr = tableKey+GetString("Drag");
   var clickStr = tableKey+GetString("Click");
 
   var delStr = GetString(isMac ? "Clear" : "Del");
--- a/editor/ui/composer/content/editorUtilities.js
+++ b/editor/ui/composer/content/editorUtilities.js
@@ -8,37 +8,28 @@ Components.utils.import("resource://gre/
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 // Each editor window must include this file
 // Variables  shared by all dialogs:
 
 // Object to attach commonly-used widgets (all dialogs should use this)
 var gDialog = {};
 
-const kOutputEncodeBasicEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeBasicEntities;
-const kOutputEncodeHTMLEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeHTMLEntities;
-const kOutputEncodeLatin1Entities = Components.interfaces.nsIDocumentEncoder.OutputEncodeLatin1Entities;
-const kOutputEncodeW3CEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeW3CEntities;
-const kOutputFormatted = Components.interfaces.nsIDocumentEncoder.OutputFormatted;
-const kOutputLFLineBreak = Components.interfaces.nsIDocumentEncoder.OutputLFLineBreak;
-const kOutputSelectionOnly = Components.interfaces.nsIDocumentEncoder.OutputSelectionOnly;
-const kOutputWrap = Components.interfaces.nsIDocumentEncoder.OutputWrap;
+var kOutputEncodeBasicEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeBasicEntities;
+var kOutputEncodeHTMLEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeHTMLEntities;
+var kOutputEncodeLatin1Entities = Components.interfaces.nsIDocumentEncoder.OutputEncodeLatin1Entities;
+var kOutputEncodeW3CEntities = Components.interfaces.nsIDocumentEncoder.OutputEncodeW3CEntities;
+var kOutputFormatted = Components.interfaces.nsIDocumentEncoder.OutputFormatted;
+var kOutputLFLineBreak = Components.interfaces.nsIDocumentEncoder.OutputLFLineBreak;
+var kOutputSelectionOnly = Components.interfaces.nsIDocumentEncoder.OutputSelectionOnly;
+var kOutputWrap = Components.interfaces.nsIDocumentEncoder.OutputWrap;
 
 var gStringBundle;
 var gFilePickerDirectory;
 
-var gOS = "";
-const gWin = "Win";
-const gUNIX = "UNIX";
-const gMac = "Mac";
-
-const kWebComposerWindowID = "editorWindow";
-const kMailComposerWindowID = "msgcomposeWindow";
-
-var gIsHTMLEditor;
 /************* Message dialogs ***************/
 
 // Optional: Caller may supply text to substitue for "Ok" and/or "Cancel"
 function ConfirmWithTitle(title, message, okButtonText, cancelButtonText)
 {
   let okFlag = okButtonText ? Services.prompt.BUTTON_TITLE_IS_STRING : Services.prompt.BUTTON_TITLE_OK;
   let cancelFlag = cancelButtonText ? Services.prompt.BUTTON_TITLE_IS_STRING : Services.prompt.BUTTON_TITLE_CANCEL;
 
@@ -863,36 +854,16 @@ function InsertUsernameIntoUrl(urlspec, 
     let URI = Services.io.newURI(urlspec, GetCurrentEditor().documentCharacterSet);
     URI.username = username;
     return URI.spec;
   } catch (e) {}
 
   return urlspec;
 }
 
-function GetOS()
-{
-  if (gOS)
-    return gOS;
-
-  var platform = navigator.platform.toLowerCase();
-
-  if (platform.includes("win"))
-    gOS = gWin;
-  else if (platform.includes("mac"))
-    gOS = gMac;
-  else if (platform.includes("unix") || platform.includes("linux") || platform.includes("sun"))
-    gOS = gUNIX;
-  else
-    gOS = "";
-  // Add other tests?
-
-  return gOS;
-}
-
 function ConvertRGBColorIntoHEXColor(color)
 {
   if ( /rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/.test(color) ) {
     var r = Number(RegExp.$1).toString(16);
     if (r.length == 1) r = "0"+r;
     var g = Number(RegExp.$2).toString(16);
     if (g.length == 1) g = "0"+g;
     var b = Number(RegExp.$3).toString(16);