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 / fil041F7E245CB099473C7C5F52D56E7833 < prev    next >
Extensible Markup Language  |  2010-07-12  |  7KB  |  209 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings xmlns="http://www.mozilla.org/xbl"
  4.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  5.           xmlns:xbl="http://www.mozilla.org/xbl"
  6.           xmlns:html="http://www.w3.org/1999/xhtml">
  7.   
  8.   <binding id="avatar">
  9.     <content>
  10.       <xul:vbox anonid="holder">
  11.         <html:img src="chrome://yasearch/skin/dialogs/images/avatar.default.png"/>
  12.       </xul:vbox>
  13.       <children/>
  14.     </content>
  15.     
  16.     <implementation implements="nsIDOMEventListener">
  17.       <field name="imgMaxSize">50</field>
  18.       <field name="holder">document.getAnonymousElementByAttribute(this, "anonid", "holder")</field>
  19.       <field name="defaultImageSrc">"chrome://yasearch/skin/dialogs/images/avatar.default.png"</field>
  20.       
  21.       <property name="imgHolder" readonly="true">
  22.         <getter><![CDATA[
  23.           return this.holder.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "img")[0];
  24.         ]]></getter>
  25.       </property>
  26.       
  27.       <constructor><![CDATA[
  28.         this.avatarSrc = this.defaultImageSrc;
  29.       ]]></constructor>
  30.       
  31.       <destructor><![CDATA[
  32.         this.imgHolder.parentNode.removeChild(this.imgHolder);
  33.       ]]></destructor>
  34.       
  35.       <property name="avatarSrc">
  36.         <getter><![CDATA[
  37.           return this.getAttribute("avatarSrc");
  38.         ]]></getter>
  39.         
  40.         <setter><![CDATA[
  41.           val = val.replace(/[\r\n]/g, "");//e4x+fx2; keep it...
  42.           
  43.           if (this.avatarSrc != val) {
  44.             this.setAttribute("avatarSrc", val);
  45.             
  46.             var img = document.createElementNS("http://www.w3.org/1999/xhtml", "img");
  47.             var __me = this;
  48.             
  49.             img.onload = function() {
  50.               var response;
  51.               try {
  52.                 const nsIImageLoadingContent = Components.interfaces.nsIImageLoadingContent;
  53.                 if (this instanceof nsIImageLoadingContent)
  54.                   response = this.naturalWidth && this.getRequest(nsIImageLoadingContent.CURRENT_REQUEST).mimeType;
  55.               } catch(e) {}
  56.               
  57.               if (response) {
  58.                 var width = this.naturalWidth,
  59.                     height = this.naturalHeight;
  60.                 
  61.                 var k = 1;
  62.                 if (width > __me.imgMaxSize) k = __me.imgMaxSize / width;
  63.                 if (height > __me.imgMaxSize) k = Math.min(__me.imgMaxSize / height);
  64.                 
  65.                 width = Math.floor(width * k);
  66.                 height = Math.floor(height * k);
  67.                 
  68.                 this.setAttribute("width", width);
  69.                 this.setAttribute("height", height);
  70.                 
  71.                 var currentImage = __me.imgHolder;
  72.                 currentImage.parentNode.replaceChild(this, currentImage);
  73.               }
  74.               
  75.               img = null;
  76.             },
  77.             
  78.             img.onerror = function() {
  79.               img = null;
  80.             }
  81.             
  82.             img.src = val;
  83.           }
  84.           
  85.           return val;
  86.         ]]></setter>
  87.       </property>
  88.     </implementation>
  89.   </binding>
  90.   
  91.   <binding id="checkbox"
  92.            extends="chrome://global/content/bindings/checkbox.xml#checkbox-baseline">
  93.     <resources>
  94.       <stylesheet src="chrome://yasearch/skin/dialogs/checkbox.css"/>
  95.     </resources>
  96.   </binding>
  97.   
  98.   <binding id="cropped">
  99.     <content>
  100.       <xul:stack flex="1">
  101.         <xul:hbox style="overflow:hidden; white-space: nowrap" flex="1">
  102.           <html:span anonid="text-label" xbl:inherits="value" style="position:absolute; width:1px"/>
  103.         </xul:hbox>
  104.         <xul:vbox anonid="canvas-holder"
  105.                   style="overflow:hidden; margin-right:-2px; -moz-box-align:end; -moz-box-pack:center; height:1px;">
  106.           <html:div style="text-align:right; min-width:2.5em;">
  107.             <html:canvas anonid="canvas"
  108.                          style="display:none; width:2.5em; margin:0 !important; padding:0 !important;"></html:canvas>
  109.           </html:div>
  110.         </xul:vbox>
  111.       </xul:stack>
  112.     </content>
  113.     
  114.     <implementation>
  115.       <field name="_label">document.getAnonymousElementByAttribute(this, "anonid", "text-label")</field>
  116.       <field name="_canvas">document.getAnonymousElementByAttribute(this, "anonid", "canvas")</field>
  117.       <field name="_inited">null</field>
  118.       
  119.       <constructor><![CDATA[
  120.         this.value = this.value;
  121.       ]]></constructor>
  122.       
  123.       <property name="value">
  124.         <getter><![CDATA[
  125.           return this.getAttribute("value");
  126.         ]]></getter>
  127.         
  128.         <setter><![CDATA[
  129.           this.setAttribute("value", val);
  130.           this._label.textContent = val;
  131.           
  132.           return val;
  133.         ]]></setter>
  134.       </property>
  135.       
  136.       <method name="drawGradient">
  137.         <body><![CDATA[
  138.           this.setAttribute("yaoverflowed", "true");
  139.           
  140.           setTimeout(function(me) {
  141.             if (me._drawGradient)
  142.               me._drawGradient();
  143.           }, 10, this)
  144.         ]]></body>
  145.       </method>
  146.       
  147.       <method name="_drawGradient">
  148.         <body><![CDATA[
  149.         var canvas = this._canvas;
  150.         
  151.         canvas.style.display = "";//"inline";
  152.         
  153.         var canvasStyle = document.defaultView.getComputedStyle(canvas, "");
  154.         var w = parseInt(canvasStyle.width, 10),
  155.             h = parseInt(canvasStyle.height, 10);
  156.         
  157.         canvas.setAttribute("width", w);
  158.         canvas.setAttribute("height", h);
  159.         
  160.         canvas.width = w;
  161.         canvas.height = h;
  162.         
  163.         var bo = this.boxObject;
  164.         
  165.         var ctx = canvas.getContext("2d");
  166.         ctx.drawWindow(window, bo.x, bo.y, bo.x + w, bo.y + h, "rgb(0,0,0)");
  167.         
  168.         function fillCtx(aPattern) {
  169.           var pattern = typeof aPattern == "string" ? aPattern : ctx.createPattern(aPattern, "no-repeat");
  170.           ctx.fillStyle = pattern;
  171.           ctx.fillRect(0, 0, w, h);
  172.           
  173.           ctx.globalCompositeOperation = "destination-out";
  174.           
  175.           var gradient = ctx.createLinearGradient(w, 0, 0, 0);
  176.           gradient.addColorStop(0.0, "rgba(255, 255, 255, 0.0)");
  177.           gradient.addColorStop(0.2, "rgba(255, 255, 255, 0.2)");
  178.           gradient.addColorStop(0.5, "rgba(255, 255, 255, 0.4)");
  179.           gradient.addColorStop(1.0, "rgba(255, 255, 255, 0.8)");
  180.           
  181.           ctx.fillStyle = gradient;
  182.           ctx.fillRect(0, 0, w, h);
  183.         }
  184.         
  185.         var img = new Image();
  186.         img.src = canvas.toDataURL("image/png", "");
  187.         img.onload = function() {
  188.           setTimeout(function() { fillCtx(img); }, 1)
  189.         }
  190.         
  191.         this._label.style.visibility = "";
  192.         
  193.         ]]></body>
  194.       </method>
  195.     </implementation>
  196.     
  197.     <handlers>
  198.       <handler event="overflow"><![CDATA[
  199.         if (this._inited)
  200.           return;
  201.         
  202.         this._inited = true;
  203.         
  204.         this._label.style.visibility = "hidden";
  205.         this.drawGradient();
  206.       ]]></handler>
  207.     </handlers>
  208.   </binding>
  209. </bindings>