Skip to content

Commit

Permalink
Fixes #29, #30
Browse files Browse the repository at this point in the history
* We used to employ a pretty shady method of ensuring the gMsgCompose object is ready for us to use. No longer! We now register a listener which is notified when the message body is ready - at which point gMsgCompose is usable. This listener is registered in the handler for the "compose-window-init" event. It's magic!
* When calling the `directionCheck()` function on reply message bodies, we were - somehow - not passing the NodeFilter object. Crazy! That bug must have been manifesting for years.
* Trying to be nicer about adding a stylesheet (the quotebar fix) to the editor
* Dropped some commented-out code relevant to earlier TB and SM versions
* Some `let`'s-instead-of-`var`'s
* Avoiding some code duplication in `setInitialDirection()`
* The code we used to obtain the currently-loaded message's URI for a debugging message is no longer working... for now, just skipping the printing of the URI.
* Remove some unnecessary newlines in `console.log()` calls
* Fixed out-of-date variable name in a `console.log()` debug message in `bidimailui-display-logic.js`

+  document.documentElement.setAttribute("platform",Services.appinfo.os);
  • Loading branch information
Eyal Rozenberg committed Sep 2, 2020
1 parent 8da88de commit b6768c2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 123 deletions.
138 changes: 35 additions & 103 deletions src/chrome/content/bidimailui-composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ BiDiMailUI.Composition = {

getCurrentSelectionDirection : function() {
#ifdef DEBUG_GetCurrentSelectionDirection
console.log(
'----- in GetCurrentSelectionDirection() -----');
console.log('----- in GetCurrentSelectionDirection() -----');
#endif

// The current selection is a forest of DOM nodes,
Expand Down Expand Up @@ -381,8 +380,7 @@ BiDiMailUI.Composition = {
}
#ifdef DEBUG_SetDocumentDirection
else {
console.log(
'could not get the "content-frame" by ID - that shouldn\'t be possible');
console.log('could not get the "content-frame" by ID - that shouldn\'t be possible');
}
#endif
if (BiDiMailUI.App.versionIsAtLeast("71")) {
Expand Down Expand Up @@ -428,8 +426,9 @@ BiDiMailUI.Composition = {
dump('handleComposeReplyCSS failed to acquire editor object.');
return;
}
editor.QueryInterface(nsIEditorStyleSheets);
editor.addOverrideStyleSheet("chrome://bidimailui/content/quotebar.css");
let editorStyle = editor.QueryInterface(Components.interfaces.nsIEditorStyleSheets);
// editor.QueryInterface(Components.interfaces.nsIEditorStyleSheets);
editorStyle.addOverrideStyleSheet("chrome://bidimailui/content/quotebar.css");
}
},

Expand Down Expand Up @@ -595,22 +594,6 @@ BiDiMailUI.Composition = {
}

try {
// trying this is a single-message window
// or a 3-pane displaying a single message
#ifdef DEBUG_getDisplayedCopyParams
//console.log('win: ' + win);
//console.log('win.opener: ' + win.opener);
//console.log('win.opener.gFolderDisplay: ' + win.opener.gFolderDisplay);
#endif
//if (win.opener.gFolderDisplay.selectedMessageUris.length > 1) {
// multiple-message-display mode, we don't support that
#ifdef DEBUG_getDisplayedCopyParams
//console.log('treating window as non-tabbed, but have multiple-message display mode, we don\'t support that');
#endif
// continue;
//}
//loadedMessageURI = win.GetLoadedMessage();
//loadedMessageURI = win.opener.gFolderDisplay.selectedMessageUris[0];
displayedCopyBrowser = win.getMessageBrowser();
#ifdef DEBUG_getDisplayedCopyParams
console.log('treating window as non-tabbed and got the (main) message displayed');
Expand Down Expand Up @@ -692,33 +675,33 @@ BiDiMailUI.Composition = {
// direction for new messages
if ( !messageParams.isReply ||
BiDiMailUI.Prefs.getBoolPref("compose.reply_in_default_direction", false)) {
var defaultDirection =
BiDiMailUI.Prefs.getCharPref(
let defaultDirection = BiDiMailUI.Prefs.getCharPref(
"compose.default_direction","ltr").toLowerCase();
let initialDirection;
switch(defaultDirection) {
case "last_used":
BiDiMailUI.Composition.setDocumentDirection(
BiDiMailUI.Prefs.getCharPref("compose.last_used_direction","ltr"));
break;
case "rtl":
case "ltr":
BiDiMailUI.Composition.setDocumentDirection(defaultDirection);
initialDirection = BiDiMailUI.Prefs.getCharPref("compose.last_used_direction","ltr");
break;
default:
initialDirection = defaultDirection;
}
#ifdef DEBUG_setInitialDirection
console.log("Setting initial direction by preference \"" + defaultDirection + "\" to " + initialDirection);
#endif
BiDiMailUI.Composition.setDocumentDirection(initialDirection);
return;
}
else if (messageParams.isReply && messageParams.originalDisplayDirection) {
BiDiMailUI.Composition.setDocumentDirection(messageParams.originalDisplayDirection);
}
else {
#ifdef DEBUG_setInitialDirection
console.log(
"We have a reply, but we don't have its original direction. We'll have to check...");
console.log("We have a reply, but we don't have its original direction. We'll have to check...");
#endif
// We get here for drafts, for messages without URIs, and due to problems
// in locating the original message window/tab
var detectionDirection = BiDiMailUI.directionCheck(
document, document.getElementById("content-frame").contentDocument.body);
let detectionDirection = BiDiMailUI.directionCheck(
document, NodeFilter, document.getElementById("content-frame").contentDocument.body);
#ifdef DEBUG_setInitialDirection
console.log('detectionDirection is ' + detectionDirection );
#endif
Expand All @@ -734,8 +717,7 @@ BiDiMailUI.Composition = {
document.getElementById("content-frame").contentDocument.body;

#ifdef DEBUG_composeWindowOnActualLoad
console.log(
'--- BiDiMailUI.Composition.composeWindowOnActualLoad() --- ');
console.log('--- BiDiMailUI.Composition.composeWindowOnActualLoad() --- ');
#endif
BiDiMailUI.Composition.handleDirectionButtons();
// Track "Show Direction Buttons" pref.
Expand Down Expand Up @@ -816,6 +798,16 @@ BiDiMailUI.Composition = {
BiDiMailUI.Composition.directionSwitchController.setAllCasters();
},

msgComposeStateListener : {
NotifyComposeBodyReady: function() {
#ifdef DEBUG_msgComposeStateListener
console.log("In msgComposeStateListener.NotifyComposeBodyReady()");
#endif
BiDiMailUI.Composition.lastWindowToHaveFocus = null;
BiDiMailUI.Composition.composeWindowOnActualLoad();
}
},

composeWindowOnUnload : function() {
#ifdef DEBUG_composeWindowOnUnload
console.log('in BiDiMailUI.Composition.composeWindowOnUnload()');
Expand All @@ -826,76 +818,18 @@ BiDiMailUI.Composition = {
BiDiMailUI.Composition.directionButtonsPrefListener
);
try {
gMsgCompose.UnregisterStateListener(BiDiMailUI.Composition.bodyReadyListener);
gMsgCompose.UnregisterStateListener(BiDiMailUI.Composition.msgComposeStateListener);
} catch(ex) {};
},

composeWindowOnLoad : function() {
BiDiMailUI.Composition.lastWindowToHaveFocus = null;

if (gMsgCompose) {
BiDiMailUI.Composition.composeWindowOnActualLoad();
document.removeEventListener("load", BiDiMailUI.Composition.composeWindowOnLoad, true);
}
else {
dump("gMsgCompose not ready for this message in BiDiMailUI.Composition.composeWindowOnLoad");
}
},

composeWindowOnReopen : function() {
BiDiMailUI.Composition.lastWindowToHaveFocus = null;

if (gMsgCompose) {
// technically this could be a second call to BiDiMailUI.Composition.composeWindowOnActualLoad(),
// which should only be run once, but what's happening is that the message
// window created initially and never visible, with BiDiMailUI.Composition.composeWindowOnActualLoad()
// having already run once, is being replicated for use with a (possibly)
// different message
BiDiMailUI.Composition.composeWindowOnActualLoad();
document.removeEventListener("compose-window-reopen", BiDiMailUI.Composition.composeWindowOnReopen, true);
document.removeEventListener("load", BiDiMailUI.Composition.composeWindowOnLoad, true);
}
else {
dump("gMsgCompose not ready for this message in BiDiMailUI.Composition.composeWindowOnReopen()");
#ifdef DEBUG_ComposeEvents
console.log(
"gMsgCompose not ready for this message in BiDiMailUI.Composition.composeWindowOnReopen()");
composeWindowOnWindowInit : function() {
#ifdef DEBUG_composeWindowOnWindowInit
console.log('in composeWindowOnWindowInit');
#endif
}
},

#ifdef DEBUG_ComposeEvents
loadCount : 0,
reopenCount : 0,

debugLoadHandler : function(ev) {
BiDiMailUI.Composition.loadCount++;
console.log(
'load event #' + BiDiMailUI.Composition.loadCount + ' :\ncurrentTarget = ' +
ev.currentTarget + ' ; originalTarget = ' + ev.originalTarget +
' ; explicitOriginalTarget = ' + ev.explicitOriginalTarget);
},

debugLoadHandlerNonCapturing : function() {
console.log(
'this is a non-capturing load event');
document.getElementById("msgcomposeWindow").removeEventListener("compose-window-init", BiDiMailUI.Composition.composeWindowOnWindowInit);
gMsgCompose.RegisterStateListener(BiDiMailUI.Composition.msgComposeStateListener);
},

debugReopenHandler : function(ev) {
BiDiMailUI.Composition.reopenCount++;
console.log(
'compose-window-reopen event #' + BiDiMailUI.Composition.reopenCount +
' :\ncurrentTarget = ' + ev.currentTarget + ' ; originalTarget = ' +
ev.originalTarget + ' ; explicitOriginalTarget = ' +
ev.explicitOriginalTarget);
},

debugReopenHandlerNonCapturing : function() {
console.log(
'this is a non-capturing compose-window-reopen event');
},
#endif

installComposeWindowEventHandlers : function() {
top.controllers.appendController(
BiDiMailUI.Composition.directionSwitchController);
Expand Down Expand Up @@ -939,8 +873,7 @@ BiDiMailUI.Composition = {

applyDirectionSetterToSelectionBlockElements : function(newDirectionSetter) {
#ifdef DEBUG_applyDirectionSetterToSelectionBlockElements
console.log(
'----- BiDiMailUI.Composition.applyDirectionSetterToSelectionBlockElements() -----');
console.log('----- BiDiMailUI.Composition.applyDirectionSetterToSelectionBlockElements() -----');
#endif
var editor = GetCurrentEditor();
if (!editor) {
Expand Down Expand Up @@ -1536,7 +1469,6 @@ BiDiMailUI.Composition = {
BiDiMailUI.Composition.lastWindowToHaveFocus = focusedWindow;
BiDiMailUI.Composition.directionSwitchController.setAllCasters();
}

}

BiDiMailUI.Composition.directionSwitchController = {
Expand Down
4 changes: 2 additions & 2 deletions src/chrome/content/bidimailui-display-logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ BiDiMailUI.Display = {
linkStylesheet : function(domDocument, linkId, sheetFileName) {
if (domDocument.getElementById(linkId) != null) {
#ifdef DEBUG_linkStylesheet
console.warn("Repeated call to linkStylesheet() for sheet id " + id);
console.warn("Repeated call to linkStylesheet() for sheet id " + linkId);
#endif
return;
}
Expand Down Expand Up @@ -375,7 +375,7 @@ BiDiMailUI.Display = {
detectDirections : function(body) {
#ifdef DEBUG_detectAndSetDirections
console.log(
"in detectAndSetDirections for message\n" + gFolderDisplay.selectedMessageUris[0]);
"in detectAndSetDirections for message (don't know how to get the currently loaded message's URI)\n");
#endif

var elementsRequiringExplicitDirection = new Array;
Expand Down
27 changes: 9 additions & 18 deletions src/chrome/content/overlay-injectors/messengercompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,15 @@ function onLoad(activatedWhileWindowOpen) {
// We currently use a single CSS file for all of our style (not including the dynamically-injecte quotebar CSS for message documents)
WL.injectCSS("chrome://bidimailui/content/skin/classic/bidimailui.css");

window.top.controllers.appendController(
BiDiMailUI.Composition.directionSwitchController);
const capture = true;
#ifdef DEBUG_ComposeEvents
window.addEventListener("load", BiDiMailUI.Composition.debugLoadHandler, capture);
window.addEventListener("compose-window-reopen", BiDiMailUI.Composition.debugReopenHandler, capture);
window.addEventListener("load", BiDiMailUI.Composition.debugLoadHandlerNonCapturing, ! capture);
window.addEventListener("compose-window-reopen", BiDiMailUI.Composition.debugReopenHandlerNonCapturing, ! capture);
#endif
window.addEventListener("load", BiDiMailUI.Composition.composeWindowOnLoad, ! capture);
window.addEventListener("compose-window-reopen", BiDiMailUI.Composition.composeWindowOnReopen, capture);
window.addEventListener("unload", BiDiMailUI.Composition.composeWindowOnUnload, capture);
window.addEventListener("keypress", BiDiMailUI.Composition.onKeyPress, capture);
if (BiDiMailUI.Prefs.getBoolPref(
"compose.ctrl_shift_switches_direction", true)) {
document.addEventListener("keydown", BiDiMailUI.Composition.onKeyDown, capture);
document.addEventListener("keyup", BiDiMailUI.Composition.onKeyUp, capture);
}
window.top.controllers.appendController(BiDiMailUI.Composition.directionSwitchController);
const capture = true;
document.getElementById("msgcomposeWindow").addEventListener("compose-window-init", BiDiMailUI.Composition.composeWindowOnWindowInit);
window.addEventListener("unload", BiDiMailUI.Composition.composeWindowOnUnload, capture);
window.addEventListener("keypress", BiDiMailUI.Composition.onKeyPress, capture);
if (BiDiMailUI.Prefs.getBoolPref("compose.ctrl_shift_switches_direction", true)) {
document.addEventListener("keydown", BiDiMailUI.Composition.onKeyDown, capture);
document.addEventListener("keyup", BiDiMailUI.Composition.onKeyUp, capture);
}

// Since we no longer have per-platform-skin support, we set this attribute
// on our root element, so that, in our stylesheet, we can contextualize using
Expand Down

0 comments on commit b6768c2

Please sign in to comment.