home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / bindings / general.xml < prev    next >
Extensible Markup Language  |  2002-11-12  |  13KB  |  322 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.hasAttribute('disabled');"/>                                  
  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.createIFrameAccessible(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="statusbar">
  223.     <content>
  224.       <children/>
  225.       <xul:statusbarpanel class="statusbar-resizerpanel">
  226.         <xul:resizer dir="bottomright" style="-moz-appearance: resizer; cursor: se-resize"/>
  227.       </xul:statusbarpanel>
  228.     </content>
  229.  
  230.     <implementation implements="nsIAccessibleProvider">
  231.       <property name="accessible">
  232.         <getter>
  233.           <![CDATA[
  234.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  235.             return accService.createXULStatusBarAccessible(this);
  236.           ]]>
  237.         </getter>
  238.       </property>
  239.     </implementation>
  240.   </binding>
  241.   
  242.   <binding id="statusbarpanel-iconic" display="xul:button"
  243.            extends="chrome://global/content/bindings/general.xml#statusbarpanel">
  244.     <content>
  245.       <xul:image class="statusbarpanel-icon" xbl:inherits="src"/>
  246.     </content>
  247.   </binding>
  248.  
  249.   <binding id="image">
  250.     <implementation implements="nsIDOMXULImageElement, nsIAccessibleProvider">
  251.       <property name="src"
  252.                 onget="return this.getAttribute('src');"
  253.                 onset="this.setAttribute('src',val); return val;"/>
  254.       <property name="accessible">
  255.         <getter>
  256.           <![CDATA[
  257.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  258.             return accService.createXULImageAccessible(this);
  259.           ]]>
  260.         </getter>
  261.       </property>
  262.     </implementation>
  263.   </binding>
  264.  
  265.   <binding id="deck">
  266.     <implementation>
  267.       <property name="selectedIndex"
  268.                 onget="return this.getAttribute('selectedIndex');">
  269.         <setter>
  270.         <![CDATA[
  271.           if (this.selectedIndex == val)
  272.             return val;
  273.           this.setAttribute("selectedIndex", val);
  274.           var event = document.createEvent('Events');
  275.           event.initEvent('select', false, true);
  276.           this.dispatchEvent(event);
  277.           return val;
  278.         ]]>
  279.         </setter>
  280.       </property>
  281.  
  282.  
  283.       <property name="selectedPanel">
  284.         <getter>
  285.           <![CDATA[
  286.             return this.childNodes[this.selectedIndex];
  287.           ]]>
  288.         </getter>
  289.  
  290.         <setter>
  291.           <![CDATA[
  292.             var selectedIndex = -1;
  293.             for (var panel = val; panel != null; panel = panel.previousSibling)
  294.               ++selectedIndex;
  295.             this.selectedIndex = selectedIndex;
  296.             return val;
  297.           ]]>
  298.         </setter>
  299.       </property>
  300.     </implementation>
  301.   </binding>
  302.  
  303.   <binding id="dropmarker">
  304.     <content>
  305.       <xul:image class="dropmarker-icon"/>
  306.     </content>
  307.  
  308.     <implementation implements="nsIAccessibleProvider">
  309.       <property name="accessible">
  310.         <getter>
  311.           <![CDATA[
  312.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  313.             return accService.createXULDropmarkerAccessible(this);
  314.           ]]>
  315.         </getter>
  316.       </property>
  317.     </implementation>
  318.   </binding>
  319.  
  320. </bindings>
  321.  
  322.