home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / bindings / general.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-21  |  10.0 KB  |  230 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.   
  7.   <binding id="basetext">
  8.     <implementation>
  9.       <!-- public implementation -->
  10.       <property name="label"      onset="return this.setAttribute('label',val);"
  11.                                   onget="return this.getAttribute('label');"/>
  12.       <property name="crop"       onset="return this.setAttribute('crop',val);"
  13.                                   onget="return this.getAttribute('crop');"/>
  14.       <property name="disabled"   onset="if (val) this.setAttribute('disabled', 'true');
  15.                                          else this.removeAttribute('disabled');
  16.                                          return val;"
  17.                                   onget="var v = this.getAttribute('disabled');
  18.                                          if (v == 'true') return true; return false;"/>                                  
  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="text-label">
  27.     <handlers>
  28.       <handler event="click" action="var forElementID = this.getAttribute('for');
  29.                                      if (forElementID)
  30.                                        var forElement = document.getElementById(forElementID);
  31.                                      if(forElement)
  32.                                        forElement.focus();
  33.                                     "/>
  34.     </handlers>
  35.   </binding>
  36.   
  37.   <!--
  38.     Inline Editable UI Element
  39.     - This binding forms the basis of the inline edit treecell and the inline edit
  40.     - buttons. 
  41.     - TODO: investigate creating extensions to the wrapper widgets (tree, toolbar)
  42.     -       to make them provide some object implementing an interface similar to
  43.     -       outliner's so we can build in some of the ile behavior (such as going
  44.     -       in and out of the mode, asking isEditable etc) so as to remove some of
  45.     -       the burden from the implementor. 
  46.     -
  47.     - Note that this widget will be no longer used in the bookmarks window once 
  48.     - outliner is extended to have this functionality built in. 
  49.     -->
  50.   <binding id="inline-edit-base" extends="chrome://global/content/bindings/general.xml#basetext">
  51.     <implementation>
  52.       <property name="_mode">0</property>
  53.       <method name="setMode">
  54.         <parameter name="val"/>
  55.         <body>
  56.         <![CDATA[
  57.           var ctr = document.getAnonymousElementByAttribute(this, "ileattr", "text-container");
  58.           var txt = document.getAnonymousElementByAttribute(this, "ileattr", "text");
  59.           this.setAttribute("mode", val);
  60.           if (val == "edit") {
  61.             var nodes = document.getAnonymousNodes(this);
  62.  
  63.             if (txt.getAttribute("hidden") != "true") {
  64.               ctr.setAttribute("mode", "edit");
  65.               var width = ctr.boxObject.width;
  66.               txt.setAttribute("hidden", "true");
  67.               const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  68.               var field = document.createElementNS(kXULNS, "textbox");
  69.               field.className = "textbox-inline-edit";
  70.               field.setAttribute("flex", "1");
  71.               field.setAttribute("value", txt.getAttribute("value"));
  72.               field.setAttribute("ileattr", "field");
  73.               field.setAttribute("rootcontent", txt.getAttribute("rootcontent"));
  74.               field.setAttribute("style", "width: " + width + "px");
  75.               ctr.appendChild(field);
  76.               field.addEventListener("keydown", this.fieldKeyDown, false);
  77.               field.addEventListener("change", this.fieldChange, false);
  78.               field.select();
  79.             }
  80.           }
  81.           else {
  82.             nodes = document.getAnonymousNodes(this);
  83.             var fld = document.getAnonymousElementByAttribute(this, "ileattr", "field");
  84.             if (fld && txt.getAttribute("hidden") == "true") {
  85.               ctr.removeAttribute("mode");
  86.               fld.blur();
  87.               ctr.removeChild(fld);
  88.               txt.removeAttribute("hidden");
  89.             }
  90.           }
  91.         ]]>
  92.         </body>
  93.       </method>
  94.       <property name="_observers">
  95.       <![CDATA[
  96.         ({
  97.           reject: [], 
  98.           accept: []
  99.         })
  100.       ]]>
  101.       </property>
  102.       <property name="valueIsRejected">false</property>
  103.       <method name="addObserver">
  104.         <parameter name="aObserver"/>
  105.         <parameter name="aTopic"/>
  106.         <parameter name="aParams"/>
  107.         <body>
  108.           this._observers[aTopic].push({ callback: aObserver, params: aParams });
  109.         </body>
  110.       </method>
  111.       <method name="fieldKeyDown">
  112.         <parameter name="aEvent"/>
  113.         <body>
  114.         <![CDATA[
  115.           var rootLocalName = aEvent.target.getAttribute("rootcontent");
  116.           if (rootLocalName) {
  117.             // Root content is the bound element. 
  118.             var rootContent = aEvent.target;
  119.             while (rootContent && rootContent.localName != rootLocalName) 
  120.               rootContent = rootContent.parentNode;
  121.             
  122.             if (rootContent) {
  123.               var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
  124.               if (aEvent.keyCode == 13) {
  125.                 rootContent.valueIsRejected = false;
  126.                 rootContent.fieldChange(aEvent);
  127.               }
  128.               if (aEvent.keyCode == 27) {
  129.                 rootContent.valueIsRejected = true;
  130.                 var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
  131.                 for (i = 0; i < rootContent._observers["reject"].length; ++i) 
  132.                   rootContent._observers["reject"][i].callback(rootContent._observers["reject"][i].params.concat(fld.value), "reject");
  133.                 if ("setMode" in rootContent) 
  134.                   rootContent.setMode("normal");
  135.               }
  136.             }
  137.           }
  138.           aEvent.preventBubble();
  139.         ]]>
  140.         </body>
  141.       </method>
  142.       <property name="valueIsAccepted">false</property>
  143.       <method name="fieldChange">
  144.         <parameter name="aEvent"/>
  145.         <body>
  146.         <![CDATA[
  147.           var rootLocalName = this.getAttribute("rootcontent");
  148.           if (rootLocalName) {
  149.             // Root content is the bound element. 
  150.             var rootContent = this;
  151.             while (rootContent && rootContent.localName != rootLocalName) 
  152.               rootContent = rootContent.parentNode;
  153.             
  154.             if (rootContent) {
  155.               var ctr = document.getAnonymousElementByAttribute(rootContent, "ileattr", "text-container");
  156.               if (!rootContent.valueIsRejected) {
  157.                 var fld = document.getAnonymousElementByAttribute(rootContent, "ileattr", "field");
  158.                 for (var i = 0; i < rootContent._observers["accept"].length; ++i)
  159.                   rootContent._observers["accept"][i].callback(rootContent._observers["accept"][i].params.concat(fld.value), "accept");
  160.                 if ("setMode" in rootContent)
  161.                   rootContent.setMode("normal");
  162.               }
  163.             }
  164.           }
  165.         ]]>
  166.         </body>
  167.       </method>
  168.     </implementation>
  169.   </binding>
  170.  
  171.   <!-- inline editable buttons -->
  172.   <binding id="buttonleft-ile" extends="chrome://global/content/bindings/general.xml#inline-edit-base">
  173.     <content>
  174.       <xul:hbox class="button-internal-box" align="center" flex="1">
  175.         <xul:image class="button-icon" inherits="src"/>
  176.         <xul:hbox class="button-text-container" flex="1" ileattr="text-container">
  177.           <xul:text class="button-text" inherits="value=label,accesskey,crop,dragover-top" ileattr="text" rootcontent="button" flex="1"/>
  178.         </xul:hbox>
  179.       </xul:hbox>
  180.       <children includes="menupopup"/>
  181.     </content>
  182.   </binding>
  183.   
  184.   <binding id="editor">
  185.     <implementation>
  186.       <property name="editorShell"
  187.                 readonly="true"
  188.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).editorShell"/>
  189.       <property name="webNavigation"
  190.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  191.                 readonly="true"/>
  192.       <property name="contentDocument" readonly="true"
  193.                 onget="return this.webNavigation.document;"/>
  194.     </implementation>
  195.   </binding>
  196.  
  197.   <binding id="iframe">
  198.     <implementation>
  199.       <property name="docShell"
  200.                 readonly="true"
  201.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIIFrameBoxObject).docShell"/>
  202.       <property name="webNavigation"
  203.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  204.                 readonly="true"/>
  205.       <property name="contentDocument" readonly="true"
  206.                 onget="return this.webNavigation.document;"/>
  207.     </implementation>
  208.   </binding>
  209.  
  210.   <binding id="statusbar-panel" extends="xul:button">
  211.     <content>
  212.       <xul:hbox class="statusbar-panel-box" align="center" flex="1">
  213.         <xul:image class="statusbar-panel-icon" inherits="src"/>
  214.         <xul:text class="statusbar-panel-text" inherits="value=label,crop" crop="right" flex="1"/>
  215.       </xul:hbox>
  216.     </content>
  217.  
  218.     <implementation>
  219.       <property name="label"
  220.                 onget="return this.getAttribute('label');"
  221.                 onset="this.setAttribute('label',val); return val;"/>
  222.       <property name="src"
  223.                 onget="return this.getAttribute('src');"
  224.                 onset="this.setAttribute('src',val); return val;"/>
  225.     </implementation>
  226.   </binding>
  227.  
  228. </bindings>
  229.  
  230.