2012-08-20 17:52:26 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
<bindings id="socialChatBindings"
|
|
|
|
xmlns="http://www.mozilla.org/xbl"
|
|
|
|
xmlns:xbl="http://www.mozilla.org/xbl"
|
|
|
|
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
|
|
|
|
|
|
<binding id="chatbox">
|
|
|
|
<content orient="vertical" mousethrough="never">
|
2013-06-21 10:07:27 -07:00
|
|
|
<xul:hbox class="chat-titlebar" xbl:inherits="minimized,selected,activity" align="baseline">
|
|
|
|
<xul:hbox flex="1" onclick="document.getBindingParent(this).onTitlebarClick(event);">
|
|
|
|
<xul:image class="chat-status-icon" xbl:inherits="src=image"/>
|
|
|
|
<xul:label class="chat-title" flex="1" xbl:inherits="value=label" crop="center"/>
|
|
|
|
</xul:hbox>
|
2013-06-27 06:20:18 -07:00
|
|
|
<xul:toolbarbutton anonid="notification-icon" class="notification-anchor-icon chat-toolbarbutton"
|
|
|
|
oncommand="document.getBindingParent(this).showNotifications(); event.stopPropagation();"/>
|
2013-06-21 10:07:27 -07:00
|
|
|
<xul:toolbarbutton anonid="minimize" class="chat-minimize-button chat-toolbarbutton"
|
|
|
|
oncommand="document.getBindingParent(this).toggle();"/>
|
|
|
|
<xul:toolbarbutton anonid="swap" class="chat-swap-button chat-toolbarbutton"
|
|
|
|
oncommand="document.getBindingParent(this).swapWindows();"/>
|
|
|
|
<xul:toolbarbutton anonid="close" class="chat-close-button chat-toolbarbutton"
|
2012-08-20 17:52:26 -07:00
|
|
|
oncommand="document.getBindingParent(this).close();"/>
|
|
|
|
</xul:hbox>
|
2013-06-21 10:07:27 -07:00
|
|
|
<xul:browser anonid="content" class="chat-frame" flex="1"
|
2013-01-27 10:31:14 -08:00
|
|
|
context="contentAreaContextMenu"
|
2013-06-21 10:07:27 -07:00
|
|
|
disableglobalhistory="true"
|
2013-03-18 12:43:51 -07:00
|
|
|
tooltip="aHTMLTooltip"
|
2013-06-21 10:07:27 -07:00
|
|
|
xbl:inherits="src,origin" type="content"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation implements="nsIDOMEventListener">
|
2013-02-28 19:04:29 -08:00
|
|
|
<constructor><![CDATA[
|
2013-06-21 16:14:22 -07:00
|
|
|
this.content.__defineGetter__("popupnotificationanchor",
|
2013-06-27 06:20:18 -07:00
|
|
|
() => document.getAnonymousElementByAttribute(this, "anonid", "notification-icon"));
|
2014-05-09 19:03:07 -07:00
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
if (!this.chatbar) {
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "minimize").hidden = true;
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "close").hidden = true;
|
|
|
|
}
|
|
|
|
let contentWindow = this.contentWindow;
|
2014-05-09 19:03:07 -07:00
|
|
|
// process this._callbacks, then set to null so the chatbox creator
|
|
|
|
// knows to make new callbacks immediately.
|
|
|
|
if (this._callbacks) {
|
|
|
|
for (let callback of this._callbacks) {
|
|
|
|
callback(this);
|
|
|
|
}
|
|
|
|
this._callbacks = null;
|
|
|
|
}
|
2013-04-02 18:17:44 -07:00
|
|
|
this.addEventListener("DOMContentLoaded", function DOMContentLoaded(event) {
|
2013-06-21 10:07:27 -07:00
|
|
|
if (event.target != this.contentDocument)
|
2013-04-02 18:17:44 -07:00
|
|
|
return;
|
|
|
|
this.removeEventListener("DOMContentLoaded", DOMContentLoaded, true);
|
2013-02-28 19:04:29 -08:00
|
|
|
this.isActive = !this.minimized;
|
2014-05-09 19:03:07 -07:00
|
|
|
this._deferredChatLoaded.resolve(this);
|
2013-04-02 18:17:44 -07:00
|
|
|
}, true);
|
2013-06-21 10:07:27 -07:00
|
|
|
if (this.src)
|
|
|
|
this.setAttribute("src", this.src);
|
2013-02-28 19:04:29 -08:00
|
|
|
]]></constructor>
|
|
|
|
|
2014-05-09 19:03:07 -07:00
|
|
|
<field name="_deferredChatLoaded" readonly="true">
|
|
|
|
Promise.defer();
|
|
|
|
</field>
|
|
|
|
|
|
|
|
<property name="promiseChatLoaded">
|
|
|
|
<getter>
|
|
|
|
return this._deferredChatLoaded.promise;
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
<field name="content" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "content");
|
2012-08-20 17:52:26 -07:00
|
|
|
</field>
|
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
<property name="contentWindow">
|
|
|
|
<getter>
|
|
|
|
return this.content.contentWindow;
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="contentDocument">
|
|
|
|
<getter>
|
|
|
|
return this.content.contentDocument;
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
2012-08-23 17:10:07 -07:00
|
|
|
<property name="minimized">
|
|
|
|
<getter>
|
|
|
|
return this.getAttribute("minimized") == "true";
|
|
|
|
</getter>
|
2012-11-19 17:54:50 -08:00
|
|
|
<setter><![CDATA[
|
2013-04-16 18:29:03 -07:00
|
|
|
// Note that this.isActive is set via our transitionend handler so
|
|
|
|
// the content doesn't see intermediate values.
|
2013-06-21 10:07:27 -07:00
|
|
|
let parent = this.chatbar;
|
2012-11-19 17:54:50 -08:00
|
|
|
if (val) {
|
2012-08-23 17:10:07 -07:00
|
|
|
this.setAttribute("minimized", "true");
|
2012-11-19 17:54:50 -08:00
|
|
|
// If this chat is the selected one a new one needs to be selected.
|
2013-06-21 10:07:27 -07:00
|
|
|
if (parent && parent.selectedChat == this)
|
2012-11-19 17:54:50 -08:00
|
|
|
parent._selectAnotherChat();
|
|
|
|
} else {
|
2012-08-23 17:10:07 -07:00
|
|
|
this.removeAttribute("minimized");
|
2012-11-19 17:54:50 -08:00
|
|
|
// this chat gets selected.
|
2013-06-21 10:07:27 -07:00
|
|
|
if (parent)
|
|
|
|
parent.selectedChat = this;
|
2012-11-19 17:54:50 -08:00
|
|
|
}
|
|
|
|
]]></setter>
|
2012-08-23 17:10:07 -07:00
|
|
|
</property>
|
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
<property name="chatbar">
|
|
|
|
<getter>
|
|
|
|
if (this.parentNode.nodeName == "chatbar")
|
|
|
|
return this.parentNode;
|
|
|
|
return null;
|
|
|
|
</getter>
|
|
|
|
</property>
|
|
|
|
|
2012-08-23 17:10:07 -07:00
|
|
|
<property name="isActive">
|
|
|
|
<getter>
|
2013-06-21 10:07:27 -07:00
|
|
|
return this.content.docShell.isActive;
|
2012-08-23 17:10:07 -07:00
|
|
|
</getter>
|
|
|
|
<setter>
|
2013-06-21 10:07:27 -07:00
|
|
|
this.content.docShell.isActive = !!val;
|
2012-08-23 17:10:07 -07:00
|
|
|
|
|
|
|
// let the chat frame know if it is being shown or hidden
|
2013-06-21 10:07:27 -07:00
|
|
|
let evt = this.contentDocument.createEvent("CustomEvent");
|
2012-09-06 15:36:36 -07:00
|
|
|
evt.initCustomEvent(val ? "socialFrameShow" : "socialFrameHide", true, true, {});
|
2013-06-21 10:07:27 -07:00
|
|
|
this.contentDocument.documentElement.dispatchEvent(evt);
|
2012-08-23 17:10:07 -07:00
|
|
|
</setter>
|
|
|
|
</property>
|
2014-05-09 19:03:07 -07:00
|
|
|
|
2013-06-21 16:14:22 -07:00
|
|
|
<method name="showNotifications">
|
|
|
|
<body><![CDATA[
|
|
|
|
PopupNotifications._reshowNotifications(this.content.popupnotificationanchor,
|
|
|
|
this.content);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2012-08-23 17:10:07 -07:00
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
<method name="swapDocShells">
|
|
|
|
<parameter name="aTarget"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
aTarget.setAttribute('label', this.contentDocument.title);
|
2014-01-14 14:08:20 -08:00
|
|
|
aTarget.src = this.src;
|
2013-06-21 10:07:27 -07:00
|
|
|
aTarget.content.setAttribute("origin", this.content.getAttribute("origin"));
|
2013-06-21 19:17:34 -07:00
|
|
|
aTarget.content.popupnotificationanchor.className = this.content.popupnotificationanchor.className;
|
2013-06-21 10:07:27 -07:00
|
|
|
this.content.swapDocShells(aTarget.content);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2013-01-03 17:25:36 -08:00
|
|
|
<method name="onTitlebarClick">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2013-06-21 10:07:27 -07:00
|
|
|
if (!this.chatbar)
|
|
|
|
return;
|
2013-02-25 18:47:39 -08:00
|
|
|
if (aEvent.button == 0) { // left-click: toggle minimized.
|
2013-01-03 17:25:36 -08:00
|
|
|
this.toggle();
|
2013-02-25 18:47:39 -08:00
|
|
|
// if we restored it, we want to focus it.
|
|
|
|
if (!this.minimized)
|
2013-06-21 10:07:27 -07:00
|
|
|
this.chatbar.focus();
|
2013-02-25 18:47:39 -08:00
|
|
|
} else if (aEvent.button == 1) // middle-click: close chat
|
2013-01-03 17:25:36 -08:00
|
|
|
this.close();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-08-20 17:52:26 -07:00
|
|
|
<method name="close">
|
|
|
|
<body><![CDATA[
|
2013-06-21 10:07:27 -07:00
|
|
|
if (this.chatbar)
|
|
|
|
this.chatbar.remove(this);
|
|
|
|
else
|
|
|
|
window.close();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="swapWindows">
|
|
|
|
<body><![CDATA[
|
2014-05-09 19:03:07 -07:00
|
|
|
let deferred = Promise.defer();
|
|
|
|
let title = this.getAttribute("label");
|
2013-06-21 10:07:27 -07:00
|
|
|
if (this.chatbar) {
|
2014-05-09 19:03:07 -07:00
|
|
|
this.chatbar.detachChatbox(this, { "centerscreen": "yes" }).then(
|
|
|
|
chatbox => {
|
|
|
|
chatbox.contentWindow.document.title = title;
|
|
|
|
deferred.resolve(chatbox);
|
|
|
|
}
|
|
|
|
);
|
2013-06-21 10:07:27 -07:00
|
|
|
} else {
|
|
|
|
// attach this chatbox to the topmost browser window
|
2014-05-09 19:03:07 -07:00
|
|
|
let Chat = Cu.import("resource:///modules/Chat.jsm").Chat;
|
|
|
|
let win = Chat.findChromeWindowForChats();
|
|
|
|
let chatbar = win.document.getElementById("pinnedchats");
|
|
|
|
let origin = this.content.getAttribute("origin");
|
|
|
|
let cb = chatbar.openChat(origin, title, "about:blank");
|
|
|
|
cb.promiseChatLoaded.then(
|
|
|
|
() => {
|
|
|
|
this.swapDocShells(cb);
|
|
|
|
|
|
|
|
// chatboxForURL is a map of URL -> chatbox used to avoid opening
|
|
|
|
// duplicate chat windows. Ensure reattached chat windows aren't
|
|
|
|
// registered with about:blank as their URL, otherwise reattaching
|
|
|
|
// more than one chat window isn't possible.
|
|
|
|
chatbar.chatboxForURL.delete("about:blank");
|
|
|
|
chatbar.chatboxForURL.set(this.src, Cu.getWeakReference(cb));
|
|
|
|
|
|
|
|
chatbar.focus();
|
|
|
|
this.close();
|
|
|
|
deferred.resolve(cb);
|
|
|
|
}
|
|
|
|
);
|
2013-06-21 10:07:27 -07:00
|
|
|
}
|
2014-05-09 19:03:07 -07:00
|
|
|
return deferred.promise;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="toggle">
|
|
|
|
<body><![CDATA[
|
2012-08-23 17:10:07 -07:00
|
|
|
this.minimized = !this.minimized;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
2013-05-06 12:48:57 -07:00
|
|
|
<handler event="focus" phase="capturing">
|
2013-06-21 10:07:27 -07:00
|
|
|
if (this.chatbar)
|
|
|
|
this.chatbar.selectedChat = this;
|
2012-08-20 17:52:26 -07:00
|
|
|
</handler>
|
2012-09-25 14:38:58 -07:00
|
|
|
<handler event="DOMTitleChanged"><![CDATA[
|
2013-06-21 10:07:27 -07:00
|
|
|
this.setAttribute('label', this.contentDocument.title);
|
|
|
|
if (this.chatbar)
|
|
|
|
this.chatbar.updateTitlebar(this);
|
2012-08-23 17:10:07 -07:00
|
|
|
]]></handler>
|
2012-08-20 17:52:26 -07:00
|
|
|
<handler event="DOMLinkAdded"><![CDATA[
|
|
|
|
// much of this logic is from DOMLinkHandler in browser.js
|
|
|
|
// this sets the presence icon for a chat user, we simply use favicon style updating
|
|
|
|
let link = event.originalTarget;
|
|
|
|
let rel = link.rel && link.rel.toLowerCase();
|
|
|
|
if (!link || !link.ownerDocument || !rel || !link.href)
|
|
|
|
return;
|
|
|
|
if (link.rel.indexOf("icon") < 0)
|
|
|
|
return;
|
|
|
|
|
2014-02-08 17:41:34 -08:00
|
|
|
let ContentLinkHandler = Cu.import("resource:///modules/ContentLinkHandler.jsm", {}).ContentLinkHandler;
|
|
|
|
let uri = ContentLinkHandler.getLinkIconURI(link);
|
2012-08-20 17:52:26 -07:00
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we made it this far, use it
|
|
|
|
this.setAttribute('image', uri.spec);
|
2013-06-21 10:07:27 -07:00
|
|
|
if (this.chatbar)
|
|
|
|
this.chatbar.updateTitlebar(this);
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></handler>
|
2013-04-16 18:29:03 -07:00
|
|
|
<handler event="transitionend">
|
|
|
|
if (this.isActive == this.minimized)
|
|
|
|
this.isActive = !this.minimized;
|
|
|
|
</handler>
|
2012-08-20 17:52:26 -07:00
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="chatbar">
|
|
|
|
<content>
|
|
|
|
<xul:hbox align="end" pack="end" anonid="innerbox" class="chatbar-innerbox" mousethrough="always" flex="1">
|
2013-05-05 19:48:20 -07:00
|
|
|
<xul:spacer flex="1" anonid="spacer" class="chatbar-overflow-spacer"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<xul:toolbarbutton anonid="nub" class="chatbar-button" type="menu" collapsed="true" mousethrough="never">
|
2012-10-06 15:23:50 -07:00
|
|
|
<xul:menupopup anonid="nubMenu" oncommand="document.getBindingParent(this).showChat(event.target.chat)"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
</xul:toolbarbutton>
|
|
|
|
<children/>
|
|
|
|
</xul:hbox>
|
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation implements="nsIDOMEventListener">
|
2012-10-06 15:23:50 -07:00
|
|
|
<constructor>
|
2013-04-16 18:29:03 -07:00
|
|
|
// to avoid reflows we cache the width of the nub.
|
2012-10-06 15:23:50 -07:00
|
|
|
this.cachedWidthNub = 0;
|
2013-03-18 12:40:51 -07:00
|
|
|
this._selectedChat = null;
|
2012-10-06 15:23:50 -07:00
|
|
|
</constructor>
|
2012-08-20 17:52:26 -07:00
|
|
|
|
|
|
|
<field name="innerbox" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "innerbox");
|
|
|
|
</field>
|
|
|
|
|
|
|
|
<field name="menupopup" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "nubMenu");
|
|
|
|
</field>
|
|
|
|
|
2012-09-25 14:38:58 -07:00
|
|
|
<field name="nub" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "nub");
|
|
|
|
</field>
|
|
|
|
|
2012-11-19 17:54:50 -08:00
|
|
|
<method name="focus">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!this.selectedChat)
|
|
|
|
return;
|
2013-06-21 10:07:27 -07:00
|
|
|
Services.focus.focusedWindow = this.selectedChat.contentWindow;
|
2013-02-25 18:47:39 -08:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_isChatFocused">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// If there are no XBL bindings for the chat it can't be focused.
|
2013-06-21 10:07:27 -07:00
|
|
|
if (!aChatbox.content)
|
2013-02-25 18:47:39 -08:00
|
|
|
return false;
|
|
|
|
let fw = Services.focus.focusedWindow;
|
|
|
|
if (!fw)
|
|
|
|
return false;
|
2013-06-21 10:07:27 -07:00
|
|
|
// We want to see if the focused window is in the subtree below our browser...
|
2013-02-25 18:47:39 -08:00
|
|
|
let containingBrowser = fw.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler;
|
2013-06-21 10:07:27 -07:00
|
|
|
return containingBrowser == aChatbox.content;
|
2012-11-19 17:54:50 -08:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-09-04 14:42:06 -07:00
|
|
|
<property name="selectedChat">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this._selectedChat;
|
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
// this is pretty horrible, but we:
|
|
|
|
// * want to avoid doing touching 'selected' attribute when the
|
|
|
|
// specified chat is already selected.
|
|
|
|
// * remove 'activity' attribute on newly selected tab *even if*
|
|
|
|
// newly selected is already selected.
|
|
|
|
// * need to handle either current or new being null.
|
|
|
|
if (this._selectedChat != val) {
|
|
|
|
if (this._selectedChat) {
|
|
|
|
this._selectedChat.removeAttribute("selected");
|
|
|
|
}
|
|
|
|
this._selectedChat = val;
|
|
|
|
if (val) {
|
|
|
|
this._selectedChat.setAttribute("selected", "true");
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 14:42:06 -07:00
|
|
|
if (val) {
|
2012-09-25 14:38:58 -07:00
|
|
|
this._selectedChat.removeAttribute("activity");
|
2012-09-04 14:42:06 -07:00
|
|
|
}
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
2012-08-20 17:52:26 -07:00
|
|
|
|
|
|
|
<field name="menuitemMap">new WeakMap()</field>
|
2012-08-26 16:51:24 -07:00
|
|
|
<field name="chatboxForURL">new Map();</field>
|
2012-08-20 17:52:26 -07:00
|
|
|
|
2012-10-06 15:23:50 -07:00
|
|
|
<property name="hasCollapsedChildren">
|
2012-08-20 17:52:26 -07:00
|
|
|
<getter><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
return !!this.querySelector("[collapsed]");
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="collapsedChildren">
|
|
|
|
<getter><![CDATA[
|
|
|
|
// A generator yielding all collapsed chatboxes, in the order in
|
|
|
|
// which they should be restored.
|
2012-11-19 17:54:12 -08:00
|
|
|
let child = this.lastElementChild;
|
2012-10-06 15:23:50 -07:00
|
|
|
while (child) {
|
|
|
|
if (child.collapsed)
|
|
|
|
yield child;
|
2012-11-19 17:54:12 -08:00
|
|
|
child = child.previousElementSibling;
|
2012-08-20 17:52:26 -07:00
|
|
|
}
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-10-06 15:23:50 -07:00
|
|
|
<property name="visibleChildren">
|
2012-08-20 17:52:26 -07:00
|
|
|
<getter><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
// A generator yielding all non-collapsed chatboxes.
|
2012-11-19 17:54:12 -08:00
|
|
|
let child = this.firstElementChild;
|
2012-10-06 15:23:50 -07:00
|
|
|
while (child) {
|
|
|
|
if (!child.collapsed)
|
|
|
|
yield child;
|
2012-11-19 17:54:12 -08:00
|
|
|
child = child.nextElementSibling;
|
2012-08-20 17:52:26 -07:00
|
|
|
}
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-10-06 15:23:50 -07:00
|
|
|
<property name="collapsibleChildren">
|
2012-08-20 17:52:26 -07:00
|
|
|
<getter><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
// A generator yielding all children which are able to be collapsed
|
|
|
|
// in the order in which they should be collapsed.
|
|
|
|
// (currently this is all visible ones other than the selected one.)
|
|
|
|
for (let child of this.visibleChildren)
|
|
|
|
if (child != this.selectedChat)
|
|
|
|
yield child;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-11-19 17:54:50 -08:00
|
|
|
<method name="_selectAnotherChat">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Select a different chat (as the currently selected one is no
|
|
|
|
// longer suitable as the selection - maybe it is being minimized or
|
|
|
|
// closed.) We only select non-minimized and non-collapsed chats,
|
|
|
|
// and if none are found, set the selectedChat to null.
|
|
|
|
// It's possible in the future we will track most-recently-selected
|
|
|
|
// chats or similar to find the "best" candidate - for now though
|
|
|
|
// the choice is somewhat arbitrary.
|
2013-02-25 18:47:39 -08:00
|
|
|
let moveFocus = this.selectedChat && this._isChatFocused(this.selectedChat);
|
2012-11-19 17:54:50 -08:00
|
|
|
for (let other of this.children) {
|
|
|
|
if (other != this.selectedChat && !other.minimized && !other.collapsed) {
|
|
|
|
this.selectedChat = other;
|
2013-02-25 18:47:39 -08:00
|
|
|
if (moveFocus)
|
|
|
|
this.focus();
|
2012-11-19 17:54:50 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// can't find another - so set no chat as selected.
|
|
|
|
this.selectedChat = null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-09-25 14:38:58 -07:00
|
|
|
<method name="updateTitlebar">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (aChatbox.collapsed) {
|
|
|
|
let menuitem = this.menuitemMap.get(aChatbox);
|
|
|
|
if (aChatbox.getAttribute("activity")) {
|
|
|
|
menuitem.setAttribute("activity", true);
|
|
|
|
this.nub.setAttribute("activity", true);
|
|
|
|
}
|
|
|
|
menuitem.setAttribute("label", aChatbox.getAttribute("label"));
|
|
|
|
menuitem.setAttribute("image", aChatbox.getAttribute("image"));
|
|
|
|
}
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-10-06 15:23:50 -07:00
|
|
|
<method name="calcTotalWidthOf">
|
|
|
|
<parameter name="aElement"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<body><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
let cs = document.defaultView.getComputedStyle(aElement);
|
|
|
|
let margins = parseInt(cs.marginLeft) + parseInt(cs.marginRight);
|
|
|
|
return aElement.getBoundingClientRect().width + margins;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-10-06 15:23:50 -07:00
|
|
|
<method name="getTotalChildWidth">
|
|
|
|
<parameter name="aChatbox"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<body><![CDATA[
|
2013-04-16 18:29:03 -07:00
|
|
|
// These are from the CSS for the chatbox and must be kept in sync.
|
|
|
|
// We can't use calcTotalWidthOf due to the transitions...
|
|
|
|
const CHAT_WIDTH_OPEN = 260;
|
|
|
|
const CHAT_WIDTH_MINIMIZED = 160;
|
|
|
|
return aChatbox.minimized ? CHAT_WIDTH_MINIMIZED : CHAT_WIDTH_OPEN;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="collapseChat">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
2012-10-06 15:23:50 -07:00
|
|
|
// we ensure that the cached width for a child of this type is
|
|
|
|
// up-to-date so we can use it when resizing.
|
|
|
|
this.getTotalChildWidth(aChatbox);
|
2012-08-20 17:52:26 -07:00
|
|
|
aChatbox.collapsed = true;
|
2012-08-23 17:10:07 -07:00
|
|
|
aChatbox.isActive = false;
|
2012-08-20 17:52:26 -07:00
|
|
|
let menu = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
|
2012-09-25 14:38:58 -07:00
|
|
|
menu.setAttribute("class", "menuitem-iconic");
|
2013-06-21 10:07:27 -07:00
|
|
|
menu.setAttribute("label", aChatbox.contentDocument.title);
|
2012-09-25 14:38:58 -07:00
|
|
|
menu.setAttribute("image", aChatbox.getAttribute("image"));
|
2012-08-20 17:52:26 -07:00
|
|
|
menu.chat = aChatbox;
|
|
|
|
this.menuitemMap.set(aChatbox, menu);
|
|
|
|
this.menupopup.appendChild(menu);
|
2012-10-06 15:23:50 -07:00
|
|
|
this.nub.collapsed = false;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="showChat">
|
|
|
|
<parameter name="aChatbox"/>
|
2012-11-13 20:27:34 -08:00
|
|
|
<parameter name="aMode"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<body><![CDATA[
|
2012-11-13 20:27:34 -08:00
|
|
|
if ((aMode != "minimized") && aChatbox.minimized)
|
2012-10-06 15:23:50 -07:00
|
|
|
aChatbox.minimized = false;
|
|
|
|
if (this.selectedChat != aChatbox)
|
|
|
|
this.selectedChat = aChatbox;
|
|
|
|
if (!aChatbox.collapsed)
|
|
|
|
return; // already showing - no more to do.
|
|
|
|
this._showChat(aChatbox);
|
|
|
|
// showing a collapsed chat might mean another needs to be collapsed
|
|
|
|
// to make room...
|
|
|
|
this.resize();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_showChat">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// the actual implementation - doesn't check for overflow, assumes
|
|
|
|
// collapsed, etc.
|
2012-08-20 17:52:26 -07:00
|
|
|
let menuitem = this.menuitemMap.get(aChatbox);
|
|
|
|
this.menuitemMap.delete(aChatbox);
|
|
|
|
this.menupopup.removeChild(menuitem);
|
|
|
|
aChatbox.collapsed = false;
|
2012-08-23 17:10:07 -07:00
|
|
|
aChatbox.isActive = !aChatbox.minimized;
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="remove">
|
2012-10-06 15:23:50 -07:00
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this._remove(aChatbox);
|
|
|
|
// The removal of a chat may mean a collapsed one can spring up,
|
2013-02-13 17:07:34 -08:00
|
|
|
// or that the popup should be hidden. We also defer the selection
|
|
|
|
// of another chat until after a resize, as a new candidate may
|
|
|
|
// become uncollapsed after the resize.
|
2012-10-06 15:23:50 -07:00
|
|
|
this.resize();
|
2013-02-13 17:07:34 -08:00
|
|
|
if (this.selectedChat == aChatbox) {
|
|
|
|
this._selectAnotherChat();
|
|
|
|
}
|
2012-10-06 15:23:50 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_remove">
|
2012-08-20 17:52:26 -07:00
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this.removeChild(aChatbox);
|
2012-10-06 15:23:50 -07:00
|
|
|
// child might have been collapsed.
|
|
|
|
let menuitem = this.menuitemMap.get(aChatbox);
|
|
|
|
if (menuitem) {
|
|
|
|
this.menuitemMap.delete(aChatbox);
|
|
|
|
this.menupopup.removeChild(menuitem);
|
|
|
|
}
|
2014-01-14 14:08:20 -08:00
|
|
|
this.chatboxForURL.delete(aChatbox.src);
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-08-26 16:51:24 -07:00
|
|
|
<method name="openChat">
|
2014-05-09 19:03:07 -07:00
|
|
|
<parameter name="aOrigin"/>
|
|
|
|
<parameter name="aTitle"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<parameter name="aURL"/>
|
2014-05-07 13:56:28 -07:00
|
|
|
<parameter name="aMode"/>
|
2014-05-09 19:03:07 -07:00
|
|
|
<parameter name="aCallback"/>
|
2012-08-20 17:52:26 -07:00
|
|
|
<body><![CDATA[
|
2012-08-26 16:51:24 -07:00
|
|
|
let cb = this.chatboxForURL.get(aURL);
|
|
|
|
if (cb) {
|
|
|
|
cb = cb.get();
|
|
|
|
if (cb.parentNode) {
|
2012-11-13 20:27:34 -08:00
|
|
|
this.showChat(cb, aMode);
|
2012-11-14 19:54:34 -08:00
|
|
|
if (aCallback) {
|
|
|
|
if (cb._callbacks == null) {
|
2014-05-09 19:03:07 -07:00
|
|
|
// Chatbox has already been created, so callback now.
|
|
|
|
aCallback(cb);
|
2012-11-14 19:54:34 -08:00
|
|
|
} else {
|
2014-05-09 19:03:07 -07:00
|
|
|
// Chatbox is yet to have bindings created...
|
2012-11-14 19:54:34 -08:00
|
|
|
cb._callbacks.push(aCallback);
|
|
|
|
}
|
|
|
|
}
|
2014-05-09 19:03:07 -07:00
|
|
|
return cb;
|
2012-08-26 16:51:24 -07:00
|
|
|
}
|
|
|
|
this.chatboxForURL.delete(aURL);
|
|
|
|
}
|
|
|
|
cb = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "chatbox");
|
2014-05-09 19:03:07 -07:00
|
|
|
cb._callbacks = [];
|
|
|
|
if (aCallback) {
|
|
|
|
// _callbacks is a javascript property instead of a <field> as it
|
|
|
|
// must exist before the (possibly delayed) bindings are created.
|
|
|
|
cb._callbacks.push(aCallback);
|
|
|
|
}
|
2013-02-28 19:04:29 -08:00
|
|
|
// src also a javascript property; the src attribute is set in the ctor.
|
|
|
|
cb.src = aURL;
|
2012-08-26 16:51:24 -07:00
|
|
|
if (aMode == "minimized")
|
2012-10-15 16:15:52 -07:00
|
|
|
cb.setAttribute("minimized", "true");
|
2014-05-09 19:03:07 -07:00
|
|
|
cb.setAttribute("origin", aOrigin);
|
|
|
|
cb.setAttribute("label", aTitle);
|
2012-08-26 16:51:24 -07:00
|
|
|
this.insertBefore(cb, this.firstChild);
|
2012-11-19 17:54:50 -08:00
|
|
|
this.selectedChat = cb;
|
2012-08-26 16:51:24 -07:00
|
|
|
this.chatboxForURL.set(aURL, Cu.getWeakReference(cb));
|
2012-10-06 15:23:50 -07:00
|
|
|
this.resize();
|
2014-05-09 19:03:07 -07:00
|
|
|
return cb;
|
2012-10-06 15:23:50 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="resize">
|
|
|
|
<body><![CDATA[
|
|
|
|
// Checks the current size against the collapsed state of children
|
|
|
|
// and collapses or expands as necessary such that as many as possible
|
|
|
|
// are shown.
|
|
|
|
// So 2 basic strategies:
|
|
|
|
// * Collapse/Expand one at a time until we can't collapse/expand any
|
|
|
|
// more - but this is one reflow per change.
|
|
|
|
// * Calculate the dimensions ourself and choose how many to collapse
|
|
|
|
// or expand based on this, then do them all in one go. This is one
|
|
|
|
// reflow regardless of how many we change.
|
|
|
|
// So we go the more complicated but more efficient second option...
|
|
|
|
let availWidth = this.getBoundingClientRect().width;
|
|
|
|
let currentWidth = 0;
|
|
|
|
if (!this.nub.collapsed) { // the nub is visible.
|
|
|
|
if (!this.cachedWidthNub)
|
|
|
|
this.cachedWidthNub = this.calcTotalWidthOf(this.nub);
|
|
|
|
currentWidth += this.cachedWidthNub;
|
|
|
|
}
|
|
|
|
for (let child of this.visibleChildren) {
|
|
|
|
currentWidth += this.getTotalChildWidth(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentWidth > availWidth) {
|
|
|
|
// we need to collapse some.
|
|
|
|
let toCollapse = [];
|
|
|
|
for (let child of this.collapsibleChildren) {
|
|
|
|
if (currentWidth <= availWidth)
|
|
|
|
break;
|
|
|
|
toCollapse.push(child);
|
|
|
|
currentWidth -= this.getTotalChildWidth(child);
|
|
|
|
}
|
|
|
|
if (toCollapse.length) {
|
|
|
|
for (let child of toCollapse)
|
|
|
|
this.collapseChat(child);
|
|
|
|
}
|
|
|
|
} else if (currentWidth < availWidth) {
|
|
|
|
// we *might* be able to expand some - see how many.
|
|
|
|
// XXX - if this was clever, it could know when removing the nub
|
|
|
|
// leaves enough space to show all collapsed
|
|
|
|
let toShow = [];
|
|
|
|
for (let child of this.collapsedChildren) {
|
|
|
|
currentWidth += this.getTotalChildWidth(child);
|
|
|
|
if (currentWidth > availWidth)
|
|
|
|
break;
|
|
|
|
toShow.push(child);
|
|
|
|
}
|
|
|
|
for (let child of toShow)
|
|
|
|
this._showChat(child);
|
|
|
|
|
|
|
|
// If none remain collapsed remove the nub.
|
|
|
|
if (!this.hasCollapsedChildren) {
|
|
|
|
this.nub.collapsed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else: achievement unlocked - we are pixel-perfect!
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="handleEvent">
|
|
|
|
<parameter name="aEvent"/>
|
|
|
|
<body><![CDATA[
|
2014-05-05 22:25:58 -07:00
|
|
|
if (aEvent.type == "resize") {
|
2012-10-06 15:23:50 -07:00
|
|
|
this.resize();
|
|
|
|
}
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2013-06-21 10:07:27 -07:00
|
|
|
<method name="_getDragTarget">
|
|
|
|
<parameter name="event"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
return event.target.localName == "chatbox" ? event.target : null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2014-05-09 19:03:07 -07:00
|
|
|
<!-- Moves a chatbox to a new window. Returns a promise that is resolved
|
|
|
|
once the move to the other window is complete.
|
|
|
|
-->
|
2013-06-21 10:07:27 -07:00
|
|
|
<method name="detachChatbox">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<parameter name="aOptions"/>
|
|
|
|
<body><![CDATA[
|
2014-05-09 19:03:07 -07:00
|
|
|
let deferred = Promise.defer();
|
2013-06-21 10:07:27 -07:00
|
|
|
let options = "";
|
|
|
|
for (let name in aOptions)
|
|
|
|
options += "," + name + "=" + aOptions[name];
|
|
|
|
|
2014-01-14 14:08:20 -08:00
|
|
|
let otherWin = window.openDialog("chrome://browser/content/chatWindow.xul",
|
|
|
|
"_blank", "chrome,all,dialog=no" + options);
|
2013-06-21 10:07:27 -07:00
|
|
|
|
|
|
|
otherWin.addEventListener("load", function _chatLoad(event) {
|
|
|
|
if (event.target != otherWin.document)
|
|
|
|
return;
|
|
|
|
|
|
|
|
otherWin.removeEventListener("load", _chatLoad, true);
|
|
|
|
let otherChatbox = otherWin.document.getElementById("chatter");
|
|
|
|
aChatbox.swapDocShells(otherChatbox);
|
|
|
|
aChatbox.close();
|
2014-05-09 19:03:07 -07:00
|
|
|
deferred.resolve(otherChatbox);
|
2013-06-21 10:07:27 -07:00
|
|
|
}, true);
|
2014-05-09 19:03:07 -07:00
|
|
|
return deferred.promise;
|
2013-06-21 10:07:27 -07:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-08-20 17:52:26 -07:00
|
|
|
</implementation>
|
2013-06-21 10:07:27 -07:00
|
|
|
|
2012-08-20 17:52:26 -07:00
|
|
|
<handlers>
|
2012-09-25 14:38:58 -07:00
|
|
|
<handler event="popupshown"><![CDATA[
|
|
|
|
this.nub.removeAttribute("activity");
|
|
|
|
]]></handler>
|
2012-10-06 15:23:50 -07:00
|
|
|
<handler event="load"><![CDATA[
|
2014-05-05 22:25:58 -07:00
|
|
|
window.addEventListener("resize", this, true);
|
2012-10-06 15:23:50 -07:00
|
|
|
]]></handler>
|
|
|
|
<handler event="unload"><![CDATA[
|
2014-05-05 22:25:58 -07:00
|
|
|
window.removeEventListener("resize", this, true);
|
2012-08-20 17:52:26 -07:00
|
|
|
]]></handler>
|
2013-06-21 10:07:27 -07:00
|
|
|
|
|
|
|
<handler event="dragstart"><![CDATA[
|
|
|
|
// chat window dragging is essentially duplicated from tabbrowser.xml
|
|
|
|
// to acheive the same visual experience
|
|
|
|
let chatbox = this._getDragTarget(event);
|
|
|
|
if (!chatbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dt = event.dataTransfer;
|
|
|
|
// we do not set a url in the drag data to prevent moving to tabbrowser
|
|
|
|
// or otherwise having unexpected drop handlers do something with our
|
|
|
|
// chatbox
|
|
|
|
dt.mozSetDataAt("application/x-moz-chatbox", chatbox, 0);
|
|
|
|
|
|
|
|
// Set the cursor to an arrow during tab drags.
|
|
|
|
dt.mozCursor = "default";
|
|
|
|
|
|
|
|
// Create a canvas to which we capture the current tab.
|
|
|
|
// Until canvas is HiDPI-aware (bug 780362), we need to scale the desired
|
|
|
|
// canvas size (in CSS pixels) to the window's backing resolution in order
|
|
|
|
// to get a full-resolution drag image for use on HiDPI displays.
|
|
|
|
let windowUtils = window.getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
let scale = windowUtils.screenPixelsPerCSSPixel / windowUtils.fullZoom;
|
|
|
|
let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
canvas.mozOpaque = true;
|
|
|
|
canvas.width = 160 * scale;
|
|
|
|
canvas.height = 90 * scale;
|
|
|
|
PageThumbs.captureToCanvas(chatbox.contentWindow, canvas);
|
|
|
|
dt.setDragImage(canvas, -16 * scale, -16 * scale);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
]]></handler>
|
|
|
|
|
|
|
|
<handler event="dragend"><![CDATA[
|
|
|
|
let dt = event.dataTransfer;
|
|
|
|
let draggedChat = dt.mozGetDataAt("application/x-moz-chatbox", 0);
|
|
|
|
if (dt.mozUserCancelled || dt.dropEffect != "none") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let eX = event.screenX;
|
|
|
|
let eY = event.screenY;
|
|
|
|
// screen.availLeft et. al. only check the screen that this window is on,
|
|
|
|
// but we want to look at the screen the tab is being dropped onto.
|
|
|
|
let sX = {}, sY = {}, sWidth = {}, sHeight = {};
|
|
|
|
Cc["@mozilla.org/gfx/screenmanager;1"]
|
|
|
|
.getService(Ci.nsIScreenManager)
|
|
|
|
.screenForRect(eX, eY, 1, 1)
|
|
|
|
.GetAvailRect(sX, sY, sWidth, sHeight);
|
|
|
|
// default size for the chat window as used in chatWindow.xul, use them
|
|
|
|
// here to attempt to keep the window fully within the screen when
|
|
|
|
// opening at the drop point. If the user has resized the window to
|
|
|
|
// something larger (which gets persisted), at least a good portion of
|
|
|
|
// the window should still be within the screen.
|
|
|
|
let winWidth = 400;
|
|
|
|
let winHeight = 420;
|
|
|
|
// ensure new window entirely within screen
|
|
|
|
let left = Math.min(Math.max(eX, sX.value),
|
|
|
|
sX.value + sWidth.value - winWidth);
|
|
|
|
let top = Math.min(Math.max(eY, sY.value),
|
|
|
|
sY.value + sHeight.value - winHeight);
|
|
|
|
|
2014-05-09 19:03:07 -07:00
|
|
|
let title = draggedChat.content.getAttribute("title");
|
|
|
|
this.detachChatbox(draggedChat, { screenX: left, screenY: top }).then(
|
|
|
|
chatbox => {
|
|
|
|
chatbox.contentWindow.document.title = title;
|
|
|
|
}
|
|
|
|
);
|
2013-06-21 10:07:27 -07:00
|
|
|
event.stopPropagation();
|
|
|
|
]]></handler>
|
2012-08-20 17:52:26 -07:00
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
</bindings>
|