chrome/content/tabs.xml
author Vivien Nicolas <21@vingtetun.org>
Mon, 01 Mar 2010 16:10:31 -0500
changeset 1361 368b818ac3dbc33b571e6fdcc79746ac1c48e679
parent 1240 547e8e5221ecd75b45998cfb551c70815a20d613
child 1363 287767d3c66a9287f757048d05d133f00e68fefd
permissions -rw-r--r--
Bug 546273 - Form Assistant misses focus on profiles.yahoo.com [r=mark.finkle]

<?xml version="1.0"?>
<!DOCTYPE bindings PUBLIC "-//MOZILLA//DTD XBL V1.0//EN" "http://www.mozilla.org/xbl">

<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="8" width="106" height="64" moz-opaque="true"
          onclick="document.getBindingParent(this)._onClick()"/>
        <xul:hbox 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="browserView"/>
        <body>
          <![CDATA[
            const tabWidth = 106;
            const tabHeight = 64;

            let destCanvas = document.getAnonymousElementByAttribute(this, "anonid", "canvas");

            if (browserView) {
              browserView.renderToCanvas(destCanvas, tabWidth, tabHeight);
            } else {
              let domWin = browser.contentWindow;
              let ctx = destCanvas.getContext("2d");
              let width = domWin.innerWidth;
              let height = domWin.innerHeight;
              ctx.clearRect(0, 0, tabWidth, tabHeight);
              ctx.save();
              ctx.scale(tabWidth / width, tabHeight / height);
              ctx.drawWindow(domWin, 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 boundingBox = this.firstChild.getBoundingClientRect();
            let columnsCount = Math.ceil(this.childNodes.length / Math.floor(this.style.height / boundingBox.height));
            if (this._columnsCount != columnsCount) {
              this.style.width = (this.lastChild.boxObject.x + boundingBox.width) + "px";
              this._columnsCount = columnsCount;
            }
          ]]>
        </body>
      </method>

    </implementation>
  </binding>

</bindings>