Skip to content

Commit

Permalink
Feature: Compose in tab, bug 449299, Issue #90: WIP: Opens compose do…
Browse files Browse the repository at this point in the history
…cument in tab, some things work, others don't.
  • Loading branch information
Betterbird committed Oct 9, 2022
1 parent 4ec538d commit 76c1eae
Showing 1 changed file with 260 additions and 0 deletions.
260 changes: 260 additions & 0 deletions 102/features/12-feature-compose-in-tab.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# HG changeset patch
# User Betterbird <[email protected]>
# Date 1665305688 -7200
# Parent 815c7aa26fa1c69a44cb5e130b8a1b8bc715690a
Feature: Compose in tab (see https://bugzilla.mozilla.org/show_bug.cgi?id=449299)

diff --git a/mail/themes/shared/mail/messengercompose.css b/mail/themes/shared/mail/messengercompose.css
--- a/mail/themes/shared/mail/messengercompose.css
+++ b/mail/themes/shared/mail/messengercompose.css
@@ -440,16 +440,20 @@
flex: 1 1 0;
min-height: 0;
}

#FindToolbar {
flex: 0 0 auto;
}

+#messageArea {
+ background-color: Window;
+}
+
@media (prefers-color-scheme: dark) {
#messageArea {
background-color: #2a2a2e;
}
}

#attachmentSplitter {
grid-area: attachment-splitter;
diff --git a/mailnews/base/public/moz.build b/mailnews/base/public/moz.build
--- a/mailnews/base/public/moz.build
+++ b/mailnews/base/public/moz.build
@@ -54,16 +54,17 @@ XPIDL_SOURCES += [
"nsIMsgTagService.idl",
"nsIMsgThread.idl",
"nsIMsgUserFeedbackListener.idl",
"nsIMsgWindow.idl",
"nsISpamSettings.idl",
"nsIStatusBarBiffManager.idl",
"nsIStopwatch.idl",
"nsISubscribableServer.idl",
+ "nsITabmail.idl",
"nsIUrlListener.idl",
"nsIUserInfo.idl",
"nsMsgFolderFlags.idl",
"nsMsgMessageFlags.idl",
]

if CONFIG["OS_ARCH"] == "WINNT":
XPIDL_SOURCES += [
diff --git a/mailnews/base/public/nsITabmail.idl b/mailnews/base/public/nsITabmail.idl
new file mode 100644
--- /dev/null
+++ b/mailnews/base/public/nsITabmail.idl
@@ -0,0 +1,22 @@
+/* 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/. */
+
+#include "nsISupports.idl"
+
+interface nsISupportsInterfacePointer;
+
+/**
+ * This service provides any interface to tabmail.
+ * The contractid for this service is "@mozilla.org/mail/tabmail;1".
+ */
+[scriptable,uuid(d581cb0d-d24c-4cc0-b74a-9690178073d1)]
+interface nsITabmail : nsISupports
+{
+ void openInTab(in ACString url, in boolean hideNav, in nsISupportsInterfacePointer params);
+ void removeCurrentTab();
+};
+
+%{C++
+#define NSITABMAIL_CONTRACTID "@mozilla.org/mail/tabmail;1"
+%}
diff --git a/mailnews/base/src/Tabmail.jsm b/mailnews/base/src/Tabmail.jsm
new file mode 100644
--- /dev/null
+++ b/mailnews/base/src/Tabmail.jsm
@@ -0,0 +1,48 @@
+/* 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/. */
+
+"use strict";
+
+var EXPORTED_SYMBOLS = ["Tabmail"];
+
+// This ensures that the service is only created once.
+var gCreated = false;
+
+function Tabmail() {
+ if (gCreated) {
+ throw Components.Exception("", Cr.NS_ERROR_ALREADY_INITIALIZED);
+ }
+ gCreated = true;
+}
+
+Tabmail.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["nsITabmail"]),
+
+ openInTab(url, hideNav, params) {
+ let w = Services.wm.getMostRecentWindow("mail:3pane");
+ if (w) {
+ let tabmail = w.document.getElementById("tabmail");
+ if (tabmail) {
+ // XXX TODO: Consider different tab type here, like composeTab
+ tabmail.openTab("contentTab", { url, params }, "tab");
+ if (hideNav) {
+ let nav = tabmail.currentTabInfo.toolbar?.parentElement;
+ if (nav) {
+ nav.style = "display: none;";
+ }
+ }
+ }
+ }
+ },
+
+ removeCurrentTab() {
+ let w = Services.wm.getMostRecentWindow("mail:3pane");
+ if (w) {
+ let tabmail = w.document.getElementById("tabmail");
+ if (tabmail) {
+ tabmail.removeCurrentTab();
+ }
+ }
+ },
+};
diff --git a/mailnews/base/src/components.conf b/mailnews/base/src/components.conf
--- a/mailnews/base/src/components.conf
+++ b/mailnews/base/src/components.conf
@@ -1,16 +1,22 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.

Classes = [
{
+ "cid": "{d581cb0d-d24c-4cc0-b74a-9690178073d1}",
+ "contract_ids": ["@mozilla.org/mail/tabmail;1"],
+ "jsm": "resource:///modules/Tabmail.jsm",
+ "constructor": "Tabmail",
+ },
+ {
"cid": "{a30be08c-afc8-4fed-9af7-79778a23db23}",
"contract_ids": ["@mozilla.org/mail/folder-lookup;1"],
"jsm": "resource:///modules/FolderLookupService.jsm",
"constructor": "FolderLookupService",
},
{
"cid": "{49b04761-23dd-45d7-903d-619418a4d319}",
"contract_ids": ["@mozilla.org/messenger/msgAsyncPrompter;1"],
diff --git a/mailnews/base/src/moz.build b/mailnews/base/src/moz.build
--- a/mailnews/base/src/moz.build
+++ b/mailnews/base/src/moz.build
@@ -123,16 +123,17 @@ EXTRA_JS_MODULES += [
"MailStringUtils.jsm",
"MsgAsyncPrompter.jsm",
"MsgDBCacheManager.jsm",
"MsgIncomingServer.jsm",
"MsgKeySet.jsm",
"OAuth2.jsm",
"OAuth2Module.jsm",
"OAuth2Providers.jsm",
+ "Tabmail.jsm",
"TemplateUtils.jsm",
"VirtualFolderWrapper.jsm",
"WinUnreadBadge.jsm",
]

USE_LIBS += [
"jsoncpp",
]
diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -8,16 +8,17 @@
#include "nsIMsgSend.h"
#include "nsIServiceManager.h"
#include "nsIObserverService.h"
#include "nsIMsgIdentity.h"
#include "nsISmtpUrl.h"
#include "nsIURI.h"
#include "nsMsgI18N.h"
#include "nsIMsgComposeParams.h"
+#include "nsITabmail.h"
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "mozIDOMWindow.h"
#include "nsIContentViewer.h"
#include "nsIMsgWindow.h"
#include "nsIDocShell.h"
#include "nsPIDOMWindow.h"
@@ -175,26 +176,33 @@ nsMsgComposeService::OpenComposeWindowWi

nsCOMPtr<nsISupportsInterfacePointer> msgParamsWrapper =
do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);

msgParamsWrapper->SetData(params);
msgParamsWrapper->SetDataIID(&NS_GET_IID(nsIMsgComposeParams));

- nsCOMPtr<mozIDOMWindowProxy> newWindow;
+ bool inTab = mozilla::Preferences::GetBool("mail.compose.compose_in_tab", false);
nsAutoCString chromeURL;
if (chrome && *chrome) {
chromeURL = nsDependentCString(chrome);
} else {
chromeURL = DEFAULT_CHROME;
}
- rv = wwatch->OpenWindow(0, chromeURL, "_blank"_ns,
- "all,chrome,dialog=no,status,toolbar"_ns,
- msgParamsWrapper, getter_AddRefs(newWindow));
+ if (inTab) {
+ nsCOMPtr<nsITabmail> tabmail(do_GetService(NSITABMAIL_CONTRACTID, &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = tabmail->OpenInTab(chromeURL, true, msgParamsWrapper);
+ } else {
+ nsCOMPtr<mozIDOMWindowProxy> newWindow;
+ rv = wwatch->OpenWindow(0, chromeURL, "_blank"_ns,
+ "all,chrome,dialog=no,status,toolbar"_ns,
+ msgParamsWrapper, getter_AddRefs(newWindow));
+ }

return rv;
}

NS_IMETHODIMP
nsMsgComposeService::DetermineComposeHTML(nsIMsgIdentity* aIdentity,
MSG_ComposeFormat aFormat,
bool* aComposeHTML) {
diff --git a/mailnews/mailnews.js b/mailnews/mailnews.js
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -957,16 +957,19 @@ pref("mail.compose.add_undisclosed_recip
pref("mail.compose.dontWarnMail2Newsgroup", false);

// Attach http image resources to composed messages.
pref("mail.compose.attach_http_images", false);

// Headers to check to find the right from identity to use when catchAll is active.
pref("mail.compose.catchAllHeaders", "envelope-to, x-original-to, to, cc");

+// Open compose window in tab?
+pref("mail.compose.compose_in_tab", false);
+
// these prefs (in minutes) are here to help QA test this feature
// "mail.purge.min_delay", never purge a junk folder more than once every 480 minutes (60 mins/hour * 8 hours)
// "mail.purge.timer_interval", fire the purge timer every 5 minutes, starting 5 minutes after we load accounts
pref("mail.purge.min_delay", 480);
pref("mail.purge.timer_interval", 5);

// Set to false if opening a message in the standalone message window or viewing
// it in the message pane should never mark it as read.

0 comments on commit 76c1eae

Please sign in to comment.