gecko/mobile/chrome/content/tabs.xml

145 lines
4.4 KiB
XML

<?xml version="1.0"?>
<bindings
xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="documenttab">
<content>
<xul:stack anonid="page" class="documenttab-container" flex="1">
<html:canvas anonid="canvas" class="documenttab-canvas" left="0" width="106" height="64" moz-opaque="true"
onclick="document.getBindingParent(this)._onClick()" xbl:inherits="selected"/>
<xul:hbox class="documenttab-close-container" left="0" top="10" height="64" width="55" align="center" onclick="document.getBindingParent(this)._close()">
<xul:image anonid="close" class="documenttab-close" mousethrough="always"/>
</xul:hbox>
</xul:stack>
</content>
<implementation>
<method name="_onClick">
<body>
<![CDATA[
this.parentNode.selectedTab = this;
let selectFn = new Function("event", this.parentNode.getAttribute('onselect'));
selectFn.call(this);
]]>
</body>
</method>
<method name="_close">
<body>
<![CDATA[
let closeFn = new Function("event", this.parentNode.getAttribute('onclosetab'));
closeFn.call(this);
]]>
</body>
</method>
<method name="updateThumbnail">
<parameter name="browser"/>
<parameter name="width"/>
<parameter name="height"/>
<body>
<![CDATA[
const tabWidth = 106;
const tabHeight = 64;
let canvas = document.getAnonymousElementByAttribute(this, "anonid", "canvas");
let renderer = rendererFactory(browser, canvas)
renderer.drawContent(function(ctx, callback) {
ctx.clearRect(0, 0, tabWidth, tabHeight);
ctx.save();
ctx.scale(tabWidth / width, tabHeight / height);
callback(browser, 0, 0, width, height, "white");
ctx.restore();
});
]]>
</body>
</method>
</implementation>
</binding>
<binding id="tablist">
<implementation>
<field name="_selectedTab">null</field>
<property name="selectedTab">
<getter>
<![CDATA[
return this._selectedTab;
]]>
</getter>
<setter>
<![CDATA[
if (this._selectedTab)
this._selectedTab.removeAttribute('selected');
if (val)
val.setAttribute('selected', 'true');
this._selectedTab = val;
]]>
</setter>
</property>
<method name="addTab">
<body>
<![CDATA[
let tab = document.createElement("box");
tab.setAttribute("type", "documenttab");
this.appendChild(tab);
this._updateWidth();
return tab;
]]>
</body>
</method>
<method name="removeTab">
<parameter name="aTab"/>
<body>
<![CDATA[
this.removeChild(aTab);
this._updateWidth();
]]>
</body>
</method>
<method name="resize">
<body>
<![CDATA[
let container = this.parentNode.getBoundingClientRect();
let element = this.getBoundingClientRect();
let height = (element.top - container.top) +
((container.top + container.height) - (element.top + element.height));
this.style.height = height + "px";
this._updateWidth();
]]>
</body>
</method>
<field name="_columnsCount">1</field>
<method name="_updateWidth">
<body>
<![CDATA[
let firstBox = this.firstChild.getBoundingClientRect();
let lastBox = this.lastChild.getBoundingClientRect();
let columnsCount = Math.ceil(this.childNodes.length / Math.floor(this.style.height / firstBox.height));
if (this._columnsCount != columnsCount) {
let width = Math.max(lastBox.right - firstBox.left, firstBox.right - lastBox.left);
this.style.width = width + "px";
this._columnsCount = columnsCount;
}
]]>
</body>
</method>
</implementation>
</binding>
</bindings>