2012-08-21 04:52:26 +04: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">
|
2012-09-26 01:38:58 +04:00
|
|
|
<xul:hbox class="chat-titlebar" xbl:inherits="minimized,selected,activity"
|
2012-09-25 22:59:57 +04:00
|
|
|
onclick="document.getBindingParent(this).toggle();" align="baseline">
|
2012-08-21 04:52:26 +04:00
|
|
|
<xul:image class="chat-status-icon" xbl:inherits="src=image"/>
|
2012-10-30 02:03:16 +04:00
|
|
|
<xul:label class="chat-title" flex="1" xbl:inherits="value=label" crop="center"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
<xul:toolbarbutton class="chat-close-button chat-toolbarbutton"
|
|
|
|
oncommand="document.getBindingParent(this).close();"/>
|
|
|
|
</xul:hbox>
|
|
|
|
<xul:iframe anonid="iframe" class="chat-frame" flex="1"
|
|
|
|
xbl:inherits="src,origin,collapsed=minimized" type="content"/>
|
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation implements="nsIDOMEventListener">
|
|
|
|
<field name="iframe" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "iframe");
|
|
|
|
</field>
|
|
|
|
|
2012-08-24 04:10:07 +04:00
|
|
|
<property name="minimized">
|
|
|
|
<getter>
|
|
|
|
return this.getAttribute("minimized") == "true";
|
|
|
|
</getter>
|
2012-11-20 05:54:50 +04:00
|
|
|
<setter><![CDATA[
|
2012-08-24 04:10:07 +04:00
|
|
|
this.isActive = !val;
|
2012-11-20 05:54:50 +04:00
|
|
|
let parent = this.parentNode;
|
|
|
|
if (val) {
|
2012-08-24 04:10:07 +04:00
|
|
|
this.setAttribute("minimized", "true");
|
2012-11-20 05:54:50 +04:00
|
|
|
// If this chat is the selected one a new one needs to be selected.
|
|
|
|
if (parent.selectedChat == this)
|
|
|
|
parent._selectAnotherChat();
|
|
|
|
} else {
|
2012-08-24 04:10:07 +04:00
|
|
|
this.removeAttribute("minimized");
|
2012-11-20 05:54:50 +04:00
|
|
|
// this chat gets selected.
|
|
|
|
parent.selectedChat = this;
|
|
|
|
}
|
|
|
|
]]></setter>
|
2012-08-24 04:10:07 +04:00
|
|
|
</property>
|
|
|
|
|
|
|
|
<property name="isActive">
|
|
|
|
<getter>
|
|
|
|
return this.iframe.docShell.isActive;
|
|
|
|
</getter>
|
|
|
|
<setter>
|
|
|
|
this.iframe.docShell.isActive = !!val;
|
|
|
|
|
|
|
|
// let the chat frame know if it is being shown or hidden
|
|
|
|
let evt = this.iframe.contentDocument.createEvent("CustomEvent");
|
2012-09-07 02:36:36 +04:00
|
|
|
evt.initCustomEvent(val ? "socialFrameShow" : "socialFrameHide", true, true, {});
|
2012-08-24 04:10:07 +04:00
|
|
|
this.iframe.contentDocument.documentElement.dispatchEvent(evt);
|
|
|
|
</setter>
|
|
|
|
</property>
|
|
|
|
|
2012-08-21 04:52:26 +04:00
|
|
|
<method name="close">
|
|
|
|
<body><![CDATA[
|
|
|
|
this.parentNode.remove(this);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="toggle">
|
|
|
|
<body><![CDATA[
|
2012-08-24 04:10:07 +04:00
|
|
|
this.minimized = !this.minimized;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
</implementation>
|
|
|
|
|
|
|
|
<handlers>
|
|
|
|
<handler event="focus" phase="capturing">
|
|
|
|
this.parentNode.selectedChat = this;
|
|
|
|
</handler>
|
2012-09-26 01:38:58 +04:00
|
|
|
<handler event="DOMTitleChanged"><![CDATA[
|
|
|
|
this.setAttribute('label', this.iframe.contentDocument.title);
|
|
|
|
this.parentNode.updateTitlebar(this);
|
2012-08-24 04:10:07 +04:00
|
|
|
]]></handler>
|
2012-08-21 04:52:26 +04: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;
|
|
|
|
|
|
|
|
let uri = DOMLinkHandler.getLinkIconURI(link);
|
|
|
|
if (!uri)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// we made it this far, use it
|
|
|
|
this.setAttribute('image', uri.spec);
|
2012-09-26 01:38:58 +04:00
|
|
|
this.parentNode.updateTitlebar(this);
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></handler>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
<binding id="chatbar">
|
|
|
|
<content>
|
|
|
|
<xul:hbox align="end" pack="end" anonid="innerbox" class="chatbar-innerbox" mousethrough="always" flex="1">
|
|
|
|
<xul:toolbarbutton anonid="nub" class="chatbar-button" type="menu" collapsed="true" mousethrough="never">
|
2012-10-07 02:23:50 +04:00
|
|
|
<xul:menupopup anonid="nubMenu" oncommand="document.getBindingParent(this).showChat(event.target.chat)"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
</xul:toolbarbutton>
|
|
|
|
<xul:spacer flex="1" anonid="spacer" class="chatbar-overflow-spacer"/>
|
|
|
|
<children/>
|
|
|
|
</xul:hbox>
|
|
|
|
</content>
|
|
|
|
|
|
|
|
<implementation implements="nsIDOMEventListener">
|
2012-10-07 02:23:50 +04:00
|
|
|
<constructor>
|
|
|
|
// to avoid reflows we cache the values for various widths.
|
|
|
|
this.cachedWidthOpen = 0;
|
|
|
|
this.cachedWidthMinimized = 0;
|
|
|
|
this.cachedWidthNub = 0;
|
|
|
|
</constructor>
|
2012-08-21 04:52:26 +04: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-26 01:38:58 +04:00
|
|
|
<field name="nub" readonly="true">
|
|
|
|
document.getAnonymousElementByAttribute(this, "anonid", "nub");
|
|
|
|
</field>
|
|
|
|
|
2012-11-20 05:54:50 +04:00
|
|
|
<method name="focus">
|
|
|
|
<body><![CDATA[
|
|
|
|
if (!this.selectedChat)
|
|
|
|
return;
|
|
|
|
let commandDispatcher = gBrowser.ownerDocument.commandDispatcher;
|
|
|
|
commandDispatcher.advanceFocusIntoSubtree(this.selectedChat);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-09-05 01:42:06 +04:00
|
|
|
<property name="selectedChat">
|
|
|
|
<getter><![CDATA[
|
|
|
|
return this._selectedChat;
|
|
|
|
]]></getter>
|
|
|
|
<setter><![CDATA[
|
2012-10-07 02:23:50 +04: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-11-20 05:54:50 +04:00
|
|
|
this.focus();
|
2012-10-07 02:23:50 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-05 01:42:06 +04:00
|
|
|
if (val) {
|
2012-09-26 01:38:58 +04:00
|
|
|
this._selectedChat.removeAttribute("activity");
|
2012-09-05 01:42:06 +04:00
|
|
|
}
|
|
|
|
]]></setter>
|
|
|
|
</property>
|
2012-08-21 04:52:26 +04:00
|
|
|
|
|
|
|
<field name="menuitemMap">new WeakMap()</field>
|
2012-08-27 03:51:24 +04:00
|
|
|
<field name="chatboxForURL">new Map();</field>
|
2012-08-21 04:52:26 +04:00
|
|
|
|
2012-10-07 02:23:50 +04:00
|
|
|
<property name="hasCollapsedChildren">
|
2012-08-21 04:52:26 +04:00
|
|
|
<getter><![CDATA[
|
2012-10-07 02:23:50 +04: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-08-21 04:52:26 +04:00
|
|
|
let child = this.lastChild;
|
2012-10-07 02:23:50 +04:00
|
|
|
while (child) {
|
|
|
|
if (child.collapsed)
|
|
|
|
yield child;
|
2012-08-21 04:52:26 +04:00
|
|
|
child = child.previousSibling;
|
|
|
|
}
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-10-07 02:23:50 +04:00
|
|
|
<property name="visibleChildren">
|
2012-08-21 04:52:26 +04:00
|
|
|
<getter><![CDATA[
|
2012-10-07 02:23:50 +04:00
|
|
|
// A generator yielding all non-collapsed chatboxes.
|
2012-08-21 04:52:26 +04:00
|
|
|
let child = this.firstChild;
|
2012-10-07 02:23:50 +04:00
|
|
|
while (child) {
|
|
|
|
if (!child.collapsed)
|
|
|
|
yield child;
|
2012-08-21 04:52:26 +04:00
|
|
|
child = child.nextSibling;
|
|
|
|
}
|
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-10-07 02:23:50 +04:00
|
|
|
<property name="collapsibleChildren">
|
2012-08-21 04:52:26 +04:00
|
|
|
<getter><![CDATA[
|
2012-10-07 02:23:50 +04: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-21 04:52:26 +04:00
|
|
|
]]></getter>
|
|
|
|
</property>
|
|
|
|
|
2012-11-20 05:54:50 +04: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.
|
|
|
|
for (let other of this.children) {
|
|
|
|
if (other != this.selectedChat && !other.minimized && !other.collapsed) {
|
|
|
|
this.selectedChat = other;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// can't find another - so set no chat as selected.
|
|
|
|
this.selectedChat = null;
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-09-26 01:38:58 +04: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-07 02:23:50 +04:00
|
|
|
<method name="calcTotalWidthOf">
|
|
|
|
<parameter name="aElement"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
<body><![CDATA[
|
2012-10-07 02:23:50 +04:00
|
|
|
let cs = document.defaultView.getComputedStyle(aElement);
|
|
|
|
let margins = parseInt(cs.marginLeft) + parseInt(cs.marginRight);
|
|
|
|
return aElement.getBoundingClientRect().width + margins;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-10-07 02:23:50 +04:00
|
|
|
<method name="getTotalChildWidth">
|
|
|
|
<parameter name="aChatbox"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
<body><![CDATA[
|
2012-10-07 02:23:50 +04:00
|
|
|
// gets the width of a child, using/setting the cached value for
|
|
|
|
// children of this type.
|
|
|
|
// DOES NOT take collapsed into account - ie, this is the width
|
|
|
|
// of a child assuming it is *not* collapsed. (collapsed chats
|
|
|
|
// have a width of zero as they are not shown).
|
|
|
|
if (aChatbox.minimized) {
|
|
|
|
if (!this.cachedWidthMinimized) {
|
|
|
|
if (aChatbox.collapsed)
|
|
|
|
throw new Error("can't calculate size of collapsed chat!");
|
|
|
|
this.cachedWidthMinimized = this.calcTotalWidthOf(aChatbox);
|
|
|
|
}
|
|
|
|
return this.cachedWidthMinimized;
|
|
|
|
}
|
|
|
|
if (!this.cachedWidthOpen) {
|
|
|
|
if (aChatbox.collapsed)
|
|
|
|
throw new Error("can't calculate size of collapsed chat!");
|
|
|
|
this.cachedWidthOpen = this.calcTotalWidthOf(aChatbox);
|
|
|
|
}
|
|
|
|
return this.cachedWidthOpen;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="collapseChat">
|
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
2012-10-07 02:23:50 +04: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-21 04:52:26 +04:00
|
|
|
aChatbox.collapsed = true;
|
2012-08-24 04:10:07 +04:00
|
|
|
aChatbox.isActive = false;
|
2012-08-21 04:52:26 +04:00
|
|
|
let menu = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
|
2012-09-26 01:38:58 +04:00
|
|
|
menu.setAttribute("class", "menuitem-iconic");
|
2012-08-21 04:52:26 +04:00
|
|
|
menu.setAttribute("label", aChatbox.iframe.contentDocument.title);
|
2012-09-26 01:38:58 +04:00
|
|
|
menu.setAttribute("image", aChatbox.getAttribute("image"));
|
2012-08-21 04:52:26 +04:00
|
|
|
menu.chat = aChatbox;
|
|
|
|
this.menuitemMap.set(aChatbox, menu);
|
|
|
|
this.menupopup.appendChild(menu);
|
2012-10-07 02:23:50 +04:00
|
|
|
this.nub.collapsed = false;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="showChat">
|
|
|
|
<parameter name="aChatbox"/>
|
2012-11-14 08:27:34 +04:00
|
|
|
<parameter name="aMode"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
<body><![CDATA[
|
2012-11-14 08:27:34 +04:00
|
|
|
if ((aMode != "minimized") && aChatbox.minimized)
|
2012-10-07 02:23:50 +04: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-21 04:52:26 +04:00
|
|
|
let menuitem = this.menuitemMap.get(aChatbox);
|
|
|
|
this.menuitemMap.delete(aChatbox);
|
|
|
|
this.menupopup.removeChild(menuitem);
|
|
|
|
aChatbox.collapsed = false;
|
2012-08-24 04:10:07 +04:00
|
|
|
aChatbox.isActive = !aChatbox.minimized;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="remove">
|
2012-10-07 02:23:50 +04:00
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
this._remove(aChatbox);
|
|
|
|
// The removal of a chat may mean a collapsed one can spring up,
|
|
|
|
// or that the popup should be hidden.
|
|
|
|
this.resize();
|
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="_remove">
|
2012-08-21 04:52:26 +04:00
|
|
|
<parameter name="aChatbox"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
if (this.selectedChat == aChatbox) {
|
2012-11-20 05:54:50 +04:00
|
|
|
this._selectAnotherChat();
|
2012-08-21 04:52:26 +04:00
|
|
|
}
|
|
|
|
this.removeChild(aChatbox);
|
2012-10-07 02:23:50 +04:00
|
|
|
// child might have been collapsed.
|
|
|
|
let menuitem = this.menuitemMap.get(aChatbox);
|
|
|
|
if (menuitem) {
|
|
|
|
this.menuitemMap.delete(aChatbox);
|
|
|
|
this.menupopup.removeChild(menuitem);
|
|
|
|
}
|
2012-08-27 03:51:24 +04:00
|
|
|
this.chatboxForURL.delete(aChatbox.getAttribute('src'));
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
<method name="removeAll">
|
|
|
|
<body><![CDATA[
|
2012-11-20 05:54:50 +04:00
|
|
|
this.selectedChat = null;
|
2012-08-21 04:52:26 +04:00
|
|
|
while (this.firstChild) {
|
2012-10-07 02:23:50 +04:00
|
|
|
this._remove(this.firstChild);
|
2012-08-21 04:52:26 +04:00
|
|
|
}
|
2012-10-07 02:23:50 +04:00
|
|
|
// and the nub/popup must also die.
|
|
|
|
this.nub.collapsed = true;
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
2012-11-15 07:54:34 +04:00
|
|
|
<method name="initChatBox">
|
|
|
|
<!-- ideally this would be a method on the chatbox itself, but the
|
|
|
|
vagaries of XBL bindings means that in some edge cases the
|
|
|
|
chatbox methods don't exist yet when we need them to...
|
|
|
|
-->
|
|
|
|
<parameter name="aChatBox"/>
|
|
|
|
<parameter name="aProvider"/>
|
|
|
|
<parameter name="aURL"/>
|
|
|
|
<parameter name="aCallback"/>
|
|
|
|
<body><![CDATA[
|
|
|
|
// callbacks to be called when onload fires - more might be added
|
|
|
|
// if the same chat is requested before onload has fired. Set back
|
|
|
|
// to null in DOMContentLoaded, so null means DOMContentLoaded has
|
|
|
|
// already fired and new callbacks can be made immediately.
|
|
|
|
aChatBox._callbacks = [aCallback];
|
|
|
|
let iframeWindow = aChatBox.iframe.contentWindow;
|
|
|
|
aChatBox.addEventListener("DOMContentLoaded", function DOMContentLoaded() {
|
|
|
|
aChatBox.removeEventListener("DOMContentLoaded", DOMContentLoaded);
|
|
|
|
aChatBox.isActive = !aChatBox.minimized;
|
|
|
|
for (let callback of aChatBox._callbacks) {
|
|
|
|
if (callback)
|
|
|
|
callback(iframeWindow);
|
|
|
|
}
|
|
|
|
aChatBox._callbacks = null;
|
|
|
|
function chatActivity() {
|
|
|
|
aChatBox.setAttribute("activity", true);
|
|
|
|
aChatBox.parentNode.updateTitlebar(aChatBox);
|
|
|
|
};
|
|
|
|
|
|
|
|
iframeWindow.addEventListener("socialChatActivity", chatActivity);
|
|
|
|
iframeWindow.addEventListener("unload", function unload() {
|
|
|
|
iframeWindow.removeEventListener("unload", unload);
|
|
|
|
iframeWindow.removeEventListener("socialChatActivity", chatActivity);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
aChatBox.setAttribute("origin", aProvider.origin);
|
|
|
|
aChatBox.setAttribute("src", aURL);
|
|
|
|
]]></body>
|
|
|
|
</method>
|
2012-08-27 03:51:24 +04:00
|
|
|
<method name="openChat">
|
2012-08-21 04:52:26 +04:00
|
|
|
<parameter name="aProvider"/>
|
|
|
|
<parameter name="aURL"/>
|
|
|
|
<parameter name="aCallback"/>
|
2012-08-27 03:51:24 +04:00
|
|
|
<parameter name="aMode"/>
|
2012-08-21 04:52:26 +04:00
|
|
|
<body><![CDATA[
|
2012-08-27 03:51:24 +04:00
|
|
|
let cb = this.chatboxForURL.get(aURL);
|
|
|
|
if (cb) {
|
|
|
|
cb = cb.get();
|
|
|
|
if (cb.parentNode) {
|
2012-11-14 08:27:34 +04:00
|
|
|
this.showChat(cb, aMode);
|
2012-11-15 07:54:34 +04:00
|
|
|
if (aCallback) {
|
|
|
|
if (cb._callbacks == null) {
|
|
|
|
// DOMContentLoaded has already fired, so callback now.
|
|
|
|
aCallback(cb.iframe.contentWindow);
|
|
|
|
} else {
|
|
|
|
// DOMContentLoaded for this chat is yet to fire...
|
|
|
|
cb._callbacks.push(aCallback);
|
|
|
|
}
|
|
|
|
}
|
2012-08-27 03:51:24 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.chatboxForURL.delete(aURL);
|
|
|
|
}
|
|
|
|
cb = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "chatbox");
|
|
|
|
if (aMode == "minimized")
|
2012-10-16 03:15:52 +04:00
|
|
|
cb.setAttribute("minimized", "true");
|
2012-08-27 03:51:24 +04:00
|
|
|
this.insertBefore(cb, this.firstChild);
|
2012-11-20 05:54:50 +04:00
|
|
|
this.selectedChat = cb;
|
2012-11-15 07:54:34 +04:00
|
|
|
this.initChatBox(cb, aProvider, aURL, aCallback);
|
2012-08-27 03:51:24 +04:00
|
|
|
this.chatboxForURL.set(aURL, Cu.getWeakReference(cb));
|
2012-10-07 02:23:50 +04:00
|
|
|
this.resize();
|
|
|
|
]]></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[
|
|
|
|
if (aEvent.type == "resize") {
|
|
|
|
this.resize();
|
|
|
|
}
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></body>
|
|
|
|
</method>
|
|
|
|
|
|
|
|
</implementation>
|
|
|
|
<handlers>
|
2012-09-26 01:38:58 +04:00
|
|
|
<handler event="popupshown"><![CDATA[
|
|
|
|
this.nub.removeAttribute("activity");
|
|
|
|
]]></handler>
|
2012-10-07 02:23:50 +04:00
|
|
|
<handler event="load"><![CDATA[
|
|
|
|
window.addEventListener("resize", this);
|
|
|
|
]]></handler>
|
|
|
|
<handler event="unload"><![CDATA[
|
|
|
|
window.removeEventListener("resize", this);
|
2012-08-21 04:52:26 +04:00
|
|
|
]]></handler>
|
|
|
|
</handlers>
|
|
|
|
</binding>
|
|
|
|
|
|
|
|
</bindings>
|