home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / bindings / general.xml < prev    next >
Extensible Markup Language  |  2005-07-29  |  13KB  |  337 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="generalBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  6.    xmlns:xbl="http://www.mozilla.org/xbl">
  7.   
  8.   <binding id="basetext">
  9.     <implementation>
  10.       <!-- public implementation -->
  11.       <property name="label"      onset="return this.setAttribute('label',val);"
  12.                                   onget="return this.getAttribute('label');"/>
  13.       <property name="crop"       onset="return this.setAttribute('crop',val);"
  14.                                   onget="return this.getAttribute('crop');"/>
  15.       <property name="disabled"   onset="if (val) this.setAttribute('disabled', 'true');
  16.                                          else this.removeAttribute('disabled');
  17.                                          return val;"
  18.                                   onget="return this.getAttribute('disabled') == 'true';"/>
  19.       <property name="image"      onset="return this.setAttribute('image',val);"
  20.                                   onget="return this.getAttribute('image');"/>
  21.       <property name="accessKey"  onset="return this.setAttribute('accesskey',val);"
  22.                                   onget="return this.getAttribute('accesskey');"/>
  23.     </implementation>      
  24.   </binding>
  25.  
  26.   <binding id="control-item" extends="chrome://global/content/bindings/general.xml#basetext">
  27.     <implementation>
  28.       <property name="value"      onset="return this.setAttribute('value', val);"
  29.                                   onget="return this.getAttribute('value');"/>
  30.     </implementation>
  31.   </binding>
  32.  
  33.   
  34.   <!--
  35.     Inline Editable UI Element
  36.     - This binding forms the basis of the inline edit treecell and the inline edit
  37.     - buttons. 
  38.     - TODO: investigate creating extensions to the wrapper widgets (tree, toolbar)
  39.     -       to make them provide some object implementing an interface similar to
  40.     -       tree's so we can build in some of the ILE behavior (such as going
  41.     -       in and out of the mode, asking isEditable etc) so as to remove some of
  42.     -       the burden from the implementor. 
  43.     -
  44.     - Note that this widget will be no longer used in the bookmarks window once 
  45.     - tree is extended to have this functionality built in. 
  46.     -->
  47.   <binding id="inline-edit-base" extends="chrome://global/content/bindings/general.xml#basetext">
  48.     <implementation>
  49.       <field name="_mode">0</field>
  50.       <method name="setMode">
  51.         <parameter name="val"/>
  52.         <body>
  53.         <![CDATA[
  54.           var ctr = document.getAnonymousElementByAttribute(this, "ileattr", "text-container");
  55.           var txt = document.getAnonymousElementByAttribute(this, "ileattr", "text");
  56.           this.setAttribute("mode", val);
  57.           if (val == "edit") {
  58.             var nodes = document.getAnonymousNodes(this);
  59.  
  60.             if (txt.getAttribute("hidden") != "true") {
  61.               ctr.setAttribute("mode", "edit");
  62.               var width = ctr.boxObject.width;
  63.               txt.setAttribute("hidden", "true");
  64.               const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  65.               var field = document.createElementNS(kXULNS, "textbox");
  66.               field.className = "textbox-inline-edit";
  67.               field.setAttribute("flex", "1");
  68.               field.setAttribute("value", txt.getAttribute("value"));
  69.               field.setAttribute("ileattr", "field");
  70.               field.setAttribute("rootcontent", txt.getAttribute("rootcontent"));
  71.               field.setAttribute("style", "width: " + width + "px");
  72.               ctr.appendChild(field);
  73.               field.addEventListener("keydown", this.fieldKeyDown, false);
  74.               field.addEventListener("change", this.fieldChange, false);
  75.               field.select();
  76.             }
  77.           }
  78.           else {
  79.             nodes = document.getAnonymousNodes(this);
  80.             var fld = document.getAnonymousElementByAttribute(this, "ileattr", "field");
  81.             if (fld && txt.getAttribute("hidden") == "true") {
  82.               ctr.removeAttribute("mode");
  83.               fld.blur();
  84.               ctr.removeChild(fld);
  85.               txt.removeAttribute("hidden");
  86.             }
  87.           }
  88.         ]]>
  89.         </body>
  90.       </method>
  91.       <field name="_observers">
  92.       <![CDATA[
  93.         ({
  94.           reject: [], 
  95.           accept: []
  96.         })
  97.       ]]>
  98.       </field>
  99.       <field name="valueIsRejected">false</field>
  100.       <method name="addObserver">
  101.         <parameter name="aObserver"/>
  102.         <parameter name="aTopic"/>
  103.         <parameter name="aParams"/>
  104.         <body>
  105.           this._observers[aTopic].push({ callback: aObserver, params: aParams });
  106.         </body>
  107.       </method>
  108.       <method name="fieldKeyDown">
  109.         <parameter name="aEvent"/>
  110.         <body>
  111.         <![CDATA[
  112.           var rootLocalName = aEvent.target.getAttribute("rootcontent");
  113.           if (rootLocalName) {
  114.             // Root content is the bound element. 
  115.             var rootContent = aEvent.target;
  116.             while (rootContent && rootContent.localName != rootLocalName) 
  117.               rootContent = rootContent.parentNode;
  118.             
  119.             if (rootContent) {
  120.               var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
  121.               if (aEvent.keyCode == 13) {
  122.                 rootContent.valueIsRejected = false;
  123.                 rootContent.fieldChange(aEvent);
  124.               }
  125.               if (aEvent.keyCode == 27) {
  126.                 rootContent.valueIsRejected = true;
  127.                 var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
  128.                 for (i = 0; i < rootContent._observers["reject"].length; ++i) 
  129.                   rootContent._observers["reject"][i].callback(rootContent._observers["reject"][i].params.concat(fld.value), "reject");
  130.                 if ("setMode" in rootContent) 
  131.                   rootContent.setMode("normal");
  132.               }
  133.             }
  134.           }
  135.           aEvent.preventBubble();
  136.         ]]>
  137.         </body>
  138.       </method>
  139.       <field name="valueIsAccepted">false</field>
  140.       <method name="fieldChange">
  141.         <parameter name="aEvent"/>
  142.         <body>
  143.         <![CDATA[
  144.           var rootLocalName = this.getAttribute("rootcontent");
  145.           if (rootLocalName) {
  146.             // Root content is the bound element. 
  147.             var rootContent = this;
  148.             while (rootContent && rootContent.localName != rootLocalName) 
  149.               rootContent = rootContent.parentNode;
  150.             
  151.             if (rootContent) {
  152.               var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
  153.               if (!rootContent.valueIsRejected) {
  154.                 var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
  155.                 for (var i = 0; i < rootContent._observers["accept"].length; ++i)
  156.                   rootContent._observers["accept"][i].callback(rootContent._observers["accept"][i].params.concat(fld.value), "accept");
  157.                 if ("setMode" in rootContent)
  158.                   rootContent.setMode("normal");
  159.               }
  160.             }
  161.           }
  162.         ]]>
  163.         </body>
  164.       </method>
  165.     </implementation>
  166.   </binding>
  167.  
  168.   <!-- inline editable buttons -->
  169.   <binding id="buttonleft-ile" extends="chrome://global/content/bindings/general.xml#inline-edit-base">
  170.     <content>
  171.       <xul:hbox class="button-internal-box" align="center" flex="1">
  172.         <xul:image class="button-icon" xbl:inherits="src"/>
  173.         <xul:hbox class="button-text-container" flex="1" ileattr="text-container">
  174.           <xul:label class="button-text" xbl:inherits="value=label,accesskey,crop,dragover-top" ileattr="text" rootcontent="button" flex="1"/>
  175.         </xul:hbox>
  176.       </xul:hbox>
  177.       <children includes="menupopup"/>
  178.     </content>
  179.   </binding>
  180.  
  181.   <binding id="iframe">
  182.     <implementation implements="nsIAccessibleProvider">
  183.       <property name="accessible">
  184.         <getter>
  185.           <![CDATA[
  186.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  187.             return accService.createOuterDocAccessible(this);
  188.           ]]>
  189.         </getter>
  190.       </property>
  191.       <property name="docShell"
  192.                 readonly="true"
  193.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIIFrameBoxObject).docShell"/>
  194.       <property name="contentWindow"
  195.                 readonly="true"
  196.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);"/>
  197.       <property name="webNavigation"
  198.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  199.                 readonly="true"/>
  200.       <property name="contentDocument" readonly="true"
  201.                 onget="return this.webNavigation.document;"/>
  202.     </implementation>
  203.   </binding>
  204.  
  205.   <binding id="statusbarpanel" display="xul:button">
  206.     <content>
  207.       <children>
  208.         <xul:label class="statusbarpanel-text" xbl:inherits="value=label,crop" crop="right" flex="1"/>
  209.       </children>
  210.     </content>
  211.  
  212.     <implementation>
  213.       <property name="label"
  214.                 onget="return this.getAttribute('label');"
  215.                 onset="this.setAttribute('label',val); return val;"/>
  216.       <property name="src"
  217.                 onget="return this.getAttribute('src');"
  218.                 onset="this.setAttribute('src',val); return val;"/>
  219.     </implementation>
  220.   </binding>
  221.  
  222.   <binding id="statusbarpanel-menu-iconic" display="xul:menu" extends="chrome://global/content/bindings/general.xml#statusbarpanel">
  223.     <content>
  224.       <xul:image class="statusbarpanel-icon" xbl:inherits="src"/>
  225.       <children/>
  226.     </content>
  227.   </binding>
  228.  
  229.   <binding id="statusbar">
  230.     <content>
  231.       <children/>
  232.       <xul:statusbarpanel class="statusbar-resizerpanel">
  233.         <xul:resizer dir="bottomright"/>
  234.       </xul:statusbarpanel>
  235.     </content>
  236.  
  237.     <implementation implements="nsIAccessibleProvider">
  238.       <property name="accessible">
  239.         <getter>
  240.           <![CDATA[
  241.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  242.             return accService.createXULStatusBarAccessible(this);
  243.           ]]>
  244.         </getter>
  245.       </property>
  246.     </implementation>
  247.   </binding>
  248.   
  249.   <binding id="statusbarpanel-iconic" display="xul:button"
  250.            extends="chrome://global/content/bindings/general.xml#statusbarpanel">
  251.     <content>
  252.       <xul:image class="statusbarpanel-icon" xbl:inherits="src"/>
  253.     </content>
  254.   </binding>
  255.  
  256.   <binding id="statusbarpanel-iconic-text" display="xul:button"
  257.            extends="chrome://global/content/bindings/general.xml#statusbarpanel">
  258.     <content>
  259.       <xul:image class="statusbarpanel-icon" xbl:inherits="src"/>
  260.       <xul:label class="statusbarpanel-text" xbl:inherits="value=label,crop"/>
  261.     </content>
  262.   </binding>
  263.  
  264.   <binding id="image">
  265.     <implementation implements="nsIDOMXULImageElement, nsIAccessibleProvider">
  266.       <property name="src"
  267.                 onget="return this.getAttribute('src');"
  268.                 onset="this.setAttribute('src',val); return val;"/>
  269.       <property name="accessible">
  270.         <getter>
  271.           <![CDATA[
  272.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  273.             return accService.createXULImageAccessible(this);
  274.           ]]>
  275.         </getter>
  276.       </property>
  277.     </implementation>
  278.   </binding>
  279.  
  280.   <binding id="deck">
  281.     <implementation>
  282.       <property name="selectedIndex"
  283.                 onget="return this.getAttribute('selectedIndex');">
  284.         <setter>
  285.         <![CDATA[
  286.           if (this.selectedIndex == val)
  287.             return val;
  288.           this.setAttribute("selectedIndex", val);
  289.           var event = document.createEvent('Events');
  290.           event.initEvent('select', false, true);
  291.           this.dispatchEvent(event);
  292.           return val;
  293.         ]]>
  294.         </setter>
  295.       </property>
  296.  
  297.  
  298.       <property name="selectedPanel">
  299.         <getter>
  300.           <![CDATA[
  301.             return this.childNodes[this.selectedIndex];
  302.           ]]>
  303.         </getter>
  304.  
  305.         <setter>
  306.           <![CDATA[
  307.             var selectedIndex = -1;
  308.             for (var panel = val; panel != null; panel = panel.previousSibling)
  309.               ++selectedIndex;
  310.             this.selectedIndex = selectedIndex;
  311.             return val;
  312.           ]]>
  313.         </setter>
  314.       </property>
  315.     </implementation>
  316.   </binding>
  317.  
  318.   <binding id="dropmarker">
  319.     <content>
  320.       <xul:image class="dropmarker-icon"/>
  321.     </content>
  322.  
  323.     <implementation implements="nsIAccessibleProvider">
  324.       <property name="accessible">
  325.         <getter>
  326.           <![CDATA[
  327.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  328.             return accService.createXULDropmarkerAccessible(this);
  329.           ]]>
  330.         </getter>
  331.       </property>
  332.     </implementation>
  333.   </binding>
  334.  
  335. </bindings>
  336.  
  337.