Skip to content

Commit

Permalink
Merge branch 'master' of github.com:protz/GMail-Conversation-View
Browse files Browse the repository at this point in the history
  • Loading branch information
protz committed Dec 2, 2011
2 parents 2cd8f8e + 4f667de commit a05e2d9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 49 deletions.
11 changes: 1 addition & 10 deletions modules/conversation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,16 +1148,7 @@ Conversation.prototype = {
this._runOnceAfterNSignals(function () {
let focusedNode = messageNodes[focusThis];
self._htmlPane.contentWindow.scrollNodeIntoView(focusedNode);

try {
let focusedMessage = self.messages[focusThis].message;
[h.onFocusMessage(focusedMessage)
for each ([, h] in Iterator(getHooks()))
if (typeof(h.onFocusMessage) == "function")];
} catch (e) {
Log.warn("Plugin returned an error:", e);
dumpCallStack(e);
}
self.messages[focusThis].message.onSelected();

for each (let [i, node] in Iterator(messageNodes)) {
// XXX This is bug 611957
Expand Down
13 changes: 6 additions & 7 deletions modules/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ var EXPORTED_SYMBOLS = ['registerHook', 'getHooks', 'removeHook'];
* onReplyComposed (aMessage, aBody) {
* },
*
* // Called when a message has been focused while building a
* // conversation.
* // @param aMessage Focused message instance.
* onFocusMessage (aMessage) {
* // Called when a message is selected.
* // @param aMessage Selected message instance.
* onMessageSelected (aMessage) {
* },
*
*
* // Called whenever a new quickreply Compose-Session was
* // created and all fields are prepared
* // @param aComposeSession created composeSession
Expand All @@ -59,14 +58,14 @@ var EXPORTED_SYMBOLS = ['registerHook', 'getHooks', 'removeHook'];
* // @param aAddress.bcc Same remark.
* onComposeSessionChanged (aComposeSession, aMessage, aAddress) {
* },
*
*
* // Called whenever a recipient is added to the quickreply
* // @param aData list data containing user input
* // @param aType type of changed recipient (to, cc, bcc)
* // @param aCount number of recipients of this type
* onRecipientAdded(aData, aType, aCount) {
* },
*
*
* // Called regardless of whether the Sending operation was successful.
* // @param aMsgID The message id for the mail message
* // @param aStatus Status code for the message send.
Expand Down
60 changes: 59 additions & 1 deletion modules/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ function Message(aConversation) {
// Filled by the conversation, useful to know whether we were initially the
// first message in the conversation or not...
this.initialPosition = -1;

// Selected state for onSelected function
this._selected = false;
}

Message.prototype = {
Expand Down Expand Up @@ -541,6 +544,38 @@ Message.prototype = {
this.register(".top-right-more", function (event) {
event.stopPropagation();
});

// Register event handlers for onSelected.
// Set useCapture: true for preventing this from being canceled
// by stopPropagation. This should be always called.
// Use focus event for shortcut keys 'F', 'B' and Tab.
// When trying to click a link or a collapsed message, focus event
// occurs before click. Update display by focus event has posibility
// to cause click failure. So we use mousedown to cancel focus event.
let mousedown = false;
this._domNode.addEventListener("mousedown", function () {
mousedown = true;
}, true);
this._domNode.addEventListener("blur", function () {
mousedown = false;
}, true);
this._domNode.addEventListener("focus", function () {
if (!mousedown)
self.onSelected();
}, true);
this._domNode.addEventListener("click", function () {
self.onSelected();
}, true);
// For the case when focused by mousedown but not clicked
this._domNode.addEventListener("mousemove", function () {
if (mousedown) {
self.onSelected();
mousedown = false;
}
}, true);
this._domNode.addEventListener("dragstart", function () {
self.onSelected();
}, true);
},

notifiedRemoteContentAlready: false,
Expand All @@ -556,6 +591,29 @@ Message.prototype = {
this._domNode.getElementsByClassName("remoteContent")[0].style.display = "block";
},

// This function should be called whenever the message is selected
// by focus, click, scrollNodeIntoView, etc.
onSelected: function _Message_onSelected() {
if (this._selected)
return;

// We run below code only for the first time after messages selected.
Log.debug("A message is selected: " + this._uri);
this._selected = true;
[message._selected = false
for ([, { message }] in Iterator(this._conversation.messages))
if (message != this)];

try {
[h.onMessageSelected(this)
for each ([, h] in Iterator(getHooks()))
if (typeof(h.onMessageSelected) == "function")];
} catch (e) {
Log.warn("Plugin returned an error:", e);
dumpCallStack(e);
}
},

// Actually, we only do these expensive DOM calls when we need to, i.e. when
// we're expanded for the first time (expand calls us).
registerActions: function _Message_registerActions() {
Expand Down Expand Up @@ -1919,7 +1977,7 @@ let PostStreamingFixesMixIn = {
let self = this;
let iframeDoc = iframe.contentDocument;
let mainWindow = topMail3Pane(this);
for each (let [, a] in Iterator(iframeDoc.getElementsByTagName("a"))) {
for each (let [, a] in Iterator(iframeDoc.querySelectorAll("a"))) {
if (!a)
continue;
let anchor = this._getAnchor(a.href);
Expand Down
34 changes: 3 additions & 31 deletions modules/plugins/enigmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ window.addEventListener("load", function () {
// possible to get a wrong message
message = w._encryptedMimeMessages.shift();
// Use a nsIURI object to identify the message correctly.
// Enigmail patch is required.
// Enigmail <= 1.3.3 doesn't support uri argument.
let uri = arguments[8];
if (uri) {
let msgHdr = uri.QueryInterface(Ci.nsIMsgMessageUrl).messageHeader;
Expand Down Expand Up @@ -305,33 +305,6 @@ function prepareForShowHdrIcons(aMessage, aHasEnc) {

if (aHasEnc)
w._encryptedMimeMessages.push(aMessage);

// Add default focus event listner for keyboard shortcut which moves
// focus to the next or previous message.
if (!conversation._focusListener) {
conversation._focusListener = function () {
w.Enigmail.hdrView.statusBarHide();
};
[message._domNode.addEventListener("focus",
conversation._focusListener, true)
for each ([, { message }] in Iterator(conversation.messages))];
}

// The security info is stored in the message's _updateHdrIcons
// to show it when focusing on the message again.
// If the focus is triggered when clicking a link, showing or hiding
// the security info causes to move the link position and clicking
// the link fails. This hack suppresses focus event when clicking.
let node = aMessage._domNode;
node.removeEventListener("focus", conversation._focusListener, true);
node.addEventListener("focus", function (event) {
let classList = event.target.classList;
if (classList && classList.contains("message"))
updateSecurityInfo(aMessage);
}, true);
node.addEventListener("click", function () {
updateSecurityInfo(aMessage);
}, true);
}

// Update security info display of the message.
Expand Down Expand Up @@ -610,9 +583,8 @@ let enigmailHook = {
return aBody;
},

// For the case when the message which has been already streamed is
// selected at message list.
onFocusMessage: function _enigmailHook_onFocusMessage(aMessage) {
// Update security info when the message is selected.
onMessageSelected: function _enigmailHook_onMessageSelected(aMessage) {
if (hasEnigmail)
updateSecurityInfo(aMessage);
},
Expand Down

0 comments on commit a05e2d9

Please sign in to comment.