home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / fil43DA857B0B07337DF7D7D2301F980E4B < prev    next >
Extensible Markup Language  |  2010-07-12  |  15KB  |  344 lines

  1. <?xml version="1.0"?>
  2. <bindings xmlns="http://www.mozilla.org/xbl"
  3.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  4.           xmlns:xbl="http://www.mozilla.org/xbl"
  5.           xmlns:html="http://www.w3.org/1999/xhtml">
  6.  
  7.     <binding id="toolbar"
  8.              extends="../../../yasearch.xml#yasearch-bar"
  9.              inheritstyle="false">
  10.         <resources>
  11.             <stylesheet src="toolbar.css"/>
  12.         </resources>
  13.         
  14.         <content>
  15.             <xul:hbox flex="1">
  16.                 <xul:box class="toolbar-container" flex="1">
  17.                     <children/>
  18.                 </xul:box>
  19.                 <xul:button class="button" oncommand="toggle();"/>
  20.             </xul:hbox>
  21.         </content>
  22.         <implementation implements="nsIDOMEventListener">
  23.             <field name="nodeChevron">document.getAnonymousElementByAttribute(this, "class", "button")</field>
  24.             <field name="nodeContainer">document.getAnonymousElementByAttribute(this, "class", "toolbar-container")</field>
  25.             <field name="applicationName">this.getAttribute("xb-app")</field>
  26.             
  27.             <constructor><![CDATA[
  28.                 this.rules = {
  29.                     multiline: {
  30.                         rule: "\
  31.                             toolbar[xb-app='%application-name%'][xb-toolbar-multiline] > * {\
  32.                                 vertical-align: middle;\
  33.                                 display: -moz-inline-box;\
  34.                             }"
  35.                         },
  36.                     excess: {
  37.                         rule: "\
  38.                             toolbar[xb-app='%application-name%'] > [xb-toolbar-item-excess] {\
  39.                                 visibility: hidden;\
  40.                                 margin-bottom: -512px;\
  41.                             }"
  42.                         },
  43.                     height: {
  44.                         rule: "\
  45.                             toolbar[xb-app='%application-name%'][xb-toolbar-multiline] > * {\
  46.                             }}"
  47.                         }
  48.                 };
  49.                 
  50.                 this.createRules();
  51.                 
  52.                 setTimeout(function(me) {
  53.                     if (me && "_constructorEx" in me)
  54.                         me._constructorEx();
  55.                 }, 100, this);
  56.             ]]></constructor>
  57.             
  58.             <method name="_constructorEx">
  59.                 <body><![CDATA[
  60.                     this.checkVisibility(true);
  61.                     
  62.                     this.nodeContainer.addEventListener("overflow", this, false);
  63.                     this.nodeContainer.addEventListener("underflow", this, false);
  64.                     this.nodeContainer.addEventListener("DOMSubtreeModified", this, false);
  65.                     window.addEventListener("resize", this, false);
  66.                 ]]></body>
  67.             </method>
  68.             
  69.             <destructor><![CDATA[
  70.                 this.destroyRules();
  71.                 
  72.                 this.nodeContainer.removeEventListener("overflow", this, false);
  73.                 this.nodeContainer.removeEventListener("underflow", this, false);
  74.                 this.nodeContainer.removeEventListener("DOMSubtreeModified", this, false);
  75.                 window.removeEventListener("resize", this, false);
  76.             ]]></destructor>
  77.             
  78.             <method name="_getComputedElementHeight">
  79.                 <parameter name="element"/>
  80.                 <body><![CDATA[
  81.                     return parseInt(window.getComputedStyle(element, null).getPropertyValue("height"), 10);
  82.                 ]]></body>
  83.             </method>
  84.             
  85.             <property name="multiline">
  86.                 <getter><![CDATA[
  87.                     return this.hasAttribute("xb-toolbar-multiline");
  88.                 ]]></getter>
  89.                 <setter><![CDATA[
  90.                     if (this.hasAttribute("xb-toolbar-multiline") == !!val)
  91.                         return;
  92.                     
  93.                     if (val) {
  94.                         let items = this.getElementsByAttribute("xb-toolbar-item-excess", "true");
  95.                         for (let i = items.length; i-- > 0;)
  96.                             items[i].removeAttribute("xb-toolbar-item-excess");
  97.                         
  98.                         let height = this._getComputedElementHeight(this);
  99.                         let childNodes = this.childNodes;
  100.                         
  101.                         for (let i = childNodes.length; i-- > 0;)
  102.                             height = Math.min(height, Math.max(16, this._getComputedElementHeight(childNodes[i]) || height));
  103.                         
  104.                         this.setButtonsHeight(height);
  105.                         
  106.                         this.setAttribute("xb-toolbar-multiline", "true");
  107.                     }
  108.                     else {
  109.                         this.setButtonsHeight(null);
  110.                         this.removeAttribute("xb-toolbar-multiline");
  111.                     }
  112.                 ]]></setter>
  113.             </property>
  114.             
  115.             <property name="overflow">
  116.                 <getter><![CDATA[
  117.                     return this.hasAttribute("xb-toolbar-overflow");
  118.                 ]]></getter>
  119.                 <setter><![CDATA[
  120.                     if (val)
  121.                         this.setAttribute("xb-toolbar-overflow", "true");
  122.                     else
  123.                         this.removeAttribute("xb-toolbar-overflow");
  124.                 ]]></setter>
  125.             </property>
  126.             
  127.             <method name="toggle">
  128.                 <body><![CDATA[
  129.                     this.multiline = !this.multiline;
  130.                     this.checkVisibility();
  131.                 ]]></body>
  132.             </method>
  133.             
  134.             <method name="onToolbarCustomize">
  135.                 <parameter name="enabled"/>
  136.                 <body><![CDATA[
  137.                     if (enabled) {
  138.                         this.multilineBeforeCustomizeDialog = this.multiline;
  139.                         this.multiline = true;
  140.                     }
  141.                     else {
  142.                         this.multiline = this.isOverflow() && this.multilineBeforeCustomizeDialog;
  143.                     }
  144.                     this.checkVisibility();
  145.                 ]]></body>
  146.             </method>
  147.             
  148.             <method name="createRules">
  149.                 <body><![CDATA[
  150.                     var stylesheet = window.document.styleSheets[0];
  151.                     var rules = stylesheet.cssRules;
  152.                     
  153.                     for (let name in this.rules) {
  154.                         let item = this.rules[name];
  155.                         let rule = item.rule.replace("%application-name%", this.applicationName);
  156.                         item.object = rules[stylesheet.insertRule(rule, rules.length)];
  157.                     }
  158.                 ]]></body>
  159.             </method>
  160.             
  161.             <method name="destroyRules">
  162.                 <body><![CDATA[
  163.                     for (let name in this.rules) {
  164.                         let rule = this.rules[name].object;
  165.                         let stylesheet = rule.parentStyleSheet;
  166.                         let rules = stylesheet.cssRules;
  167.                         
  168.                         for (let i = rules.length; i--;)
  169.                             if (rules[i] == rule) {
  170.                                 stylesheet.deleteRule(i);
  171.                                 break;
  172.                             } 
  173.                     }
  174.                 ]]></body>
  175.             </method>
  176.             
  177.             <method name="setButtonsHeight">
  178.                 <parameter name="height"/>
  179.                 <body><![CDATA[
  180.                     if (this.rules.height.object)
  181.                         this.rules.height.object.style.minHeight = height ? height + "px" : "";
  182.                 ]]></body>
  183.             </method>
  184.             
  185.             <method name="isOverflow">
  186.                 <body><![CDATA[
  187.                     if (!this.firstVisibleItem)
  188.                         return false;
  189.                     if (this.multiline)
  190.                         return this.firstVisibleItem.getBoundingClientRect().bottom <= this.lastVisibleItem.getBoundingClientRect().top;
  191.                     else
  192.                         return this.lastVisibleItem.getBoundingClientRect().right > this.nodeContainer.getBoundingClientRect().right;
  193.                 ]]></body>
  194.             </method>
  195.             
  196.             <method name="checkOverflow">
  197.                 <parameter name="autoOffMultiline"/>
  198.                 <body><![CDATA[
  199.                     var overflow = this.isOverflow();
  200.                     if (overflow != this.overflow)
  201.                         this.overflow = overflow;
  202.                     
  203.                     if (autoOffMultiline && !overflow && this.multiline)
  204.                         this.multiline = false;
  205.                 ]]></body>
  206.             </method>
  207.             
  208.             <method name="checkVisibilityDefer">
  209.                 <parameter name="autoOffMultiline"/>
  210.                 <body><![CDATA[
  211.                     if (this._checkVisibilityTimeout)
  212.                         clearTimeout(this._checkVisibilityTimeout);
  213.                     
  214.                     function doCheck(context)
  215.                         context.checkVisibility.call(context, autoOffMultiline);
  216.                     
  217.                     this._checkVisibilityTimeout = setTimeout(doCheck, 150, this);
  218.                 ]]></body>
  219.             </method>
  220.             
  221.             <method name="checkVisibility">
  222.                 <parameter name="autoOffMultiline"/>
  223.                 <body><![CDATA[
  224.                     if (!this.lastChild) {
  225.                         this.overflow = false;
  226.                         return;
  227.                     }
  228.                     
  229.                     var right = this.nodeContainer.getBoundingClientRect().right,
  230.                         item = this.lastChild,
  231.                         token = right - item.getBoundingClientRect().right;
  232.                     
  233.                     if (this.token == token)
  234.                         return;
  235.                     this.token = token;
  236.                     
  237.                     this.checkOverflow(autoOffMultiline);
  238.                     
  239.                     var overflowed = this.overflow;
  240.                     
  241.                     while (item) {
  242.                         if (this.isNormalToolbarItem(item)) {
  243.                             if (overflowed)
  244.                                 overflowed = (item.getBoundingClientRect().right > right);
  245.                             
  246.                             if (!overflowed && !item.hasAttribute("xb-toolbar-item-excess"))
  247.                                 break;
  248.                             
  249.                             if (overflowed)
  250.                                 item.setAttribute("xb-toolbar-item-excess", "true");
  251.                             else
  252.                                 item.removeAttribute("xb-toolbar-item-excess");
  253.                         }
  254.                         item = item.previousSibling;
  255.                     }
  256.                 ]]></body>
  257.             </method>
  258.             
  259.             <method name="handleEvent">
  260.                 <parameter name="event"/>
  261.                 <body><![CDATA[
  262.                     switch (event.type) {
  263.                         case "overflow":
  264.                             this.overflow = true;
  265.                             this.checkVisibility();
  266.                             return;
  267.                         break;
  268.                         
  269.                         case "underflow":
  270.                             this.overflow = false;
  271.                             this.checkVisibility();
  272.                             return;
  273.                         break;
  274.                         
  275.                         case "DOMSubtreeModified":
  276.                             this.checkVisibilityDefer();
  277.                         break;
  278.                         
  279.                         case "resize":
  280.                             if (event.eventPhase == event.AT_TARGET)
  281.                                 this.checkVisibilityDefer(true);
  282.                         break;
  283.                         
  284.                         default:
  285.                             return;
  286.                     }
  287.                 ]]></body>
  288.             </method>
  289.             
  290.             <property name="firstVisibleItem" readonly="true">
  291.                 <getter>
  292.                     var node = this.firstChild;
  293.                     while (node) {
  294.                         if (this.isNormalToolbarItem(node))
  295.                             return node;
  296.                         node = node.nextSibling;
  297.                     }
  298.                     return null;
  299.                 </getter>
  300.             </property>
  301.             
  302.             <property name="lastVisibleItem" readonly="true">
  303.                 <getter>
  304.                     var node = this.lastChild;
  305.                     while (node) {
  306.                         if (this.isNormalToolbarItem(node))
  307.                             return node;
  308.                         node = node.previousSibling;
  309.                     }
  310.                     return null;
  311.                 </getter>
  312.             </property>
  313.             
  314.             <method name="isNormalToolbarItem">
  315.                 <parameter name="node"/>
  316.                 <body><![CDATA[
  317.                     return (node.localName != "toolbarseparator") || (window.getComputedStyle(node, null).getPropertyValue("display") != "none");
  318.                 ]]></body>
  319.             </method>
  320.         </implementation>
  321.         <handlers>
  322.             <handler event="scroll"><![CDATA[
  323.                 this.nodeContainer.scrollTop = 0;
  324.                 this.nodeContainer.scrollLeft = 0;
  325.             ]]></handler>
  326.         </handlers>
  327.     </binding>
  328.     
  329.     <binding id="button"
  330.              display="xul:toolbarbutton"
  331.              inheritstyle="false">
  332.         <resources>
  333.             <stylesheet src="button.css"/>
  334.         </resources>
  335.         
  336.         <content>
  337.             <xul:box class="top"/>
  338.             <xul:box class="middle">
  339.                 <xul:image/>
  340.             </xul:box>
  341.             <xul:box class="bottom"/>
  342.         </content>
  343.     </binding>
  344. </bindings>