home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / widgets / general.xml < prev    next >
Extensible Markup Language  |  2002-10-13  |  14KB  |  344 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="editor">
  182.     <implementation>
  183.       <property name="editorShell"
  184.                 readonly="true"
  185.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).editorShell"/>
  186.       <property name="editor"
  187.                 readonly="true"
  188.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).editorShell.editor"/>
  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.       <property name="docShell"
  195.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;"
  196.                 readonly="true"/>
  197.       <property name="webBrowserFind"
  198.                 readonly="true"
  199.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebBrowserFind);"/>
  200.     </implementation>
  201.   </binding>
  202.  
  203.   <binding id="iframe">
  204.     <implementation implements="nsIAccessibleProvider">
  205.       <property name="accessible">
  206.         <getter>
  207.           <![CDATA[
  208.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  209.             return accService.createIFrameAccessible(this);
  210.           ]]>
  211.         </getter>
  212.       </property>
  213.       <property name="docShell"
  214.                 readonly="true"
  215.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIIFrameBoxObject).docShell"/>
  216.       <property name="contentWindow"
  217.                 readonly="true"
  218.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);"/>
  219.       <property name="webNavigation"
  220.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  221.                 readonly="true"/>
  222.       <property name="contentDocument" readonly="true"
  223.                 onget="return this.webNavigation.document;"/>
  224.     </implementation>
  225.   </binding>
  226.  
  227.   <binding id="statusbarpanel" display="xul:button">
  228.     <content>
  229.       <children>
  230.         <xul:label class="statusbarpanel-text" xbl:inherits="value=label,crop" crop="right" flex="1"/>
  231.       </children>
  232.     </content>
  233.  
  234.     <implementation>
  235.       <property name="label"
  236.                 onget="return this.getAttribute('label');"
  237.                 onset="this.setAttribute('label',val); return val;"/>
  238.       <property name="src"
  239.                 onget="return this.getAttribute('src');"
  240.                 onset="this.setAttribute('src',val); return val;"/>
  241.     </implementation>
  242.   </binding>
  243.  
  244.   <binding id="statusbar">
  245.     <content>
  246.       <children/>
  247.       <xul:statusbarpanel class="statusbar-resizerpanel">
  248.         <xul:resizer dir="bottomright" style="-moz-appearance: resizer; cursor: se-resize"/>
  249.       </xul:statusbarpanel>
  250.     </content>
  251.  
  252.     <implementation implements="nsIAccessibleProvider">
  253.       <property name="accessible">
  254.         <getter>
  255.           <![CDATA[
  256.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  257.             return accService.createXULStatusBarAccessible(this);
  258.           ]]>
  259.         </getter>
  260.       </property>
  261.     </implementation>
  262.   </binding>
  263.   
  264.   <binding id="statusbarpanel-iconic" display="xul:button"
  265.            extends="chrome://global/content/bindings/general.xml#statusbarpanel">
  266.     <content>
  267.       <xul:image class="statusbarpanel-icon" xbl:inherits="src"/>
  268.     </content>
  269.   </binding>
  270.  
  271.   <binding id="image">
  272.     <implementation implements="nsIDOMXULImageElement, nsIAccessibleProvider">
  273.       <property name="src"
  274.                 onget="return this.getAttribute('src');"
  275.                 onset="this.setAttribute('src',val); return val;"/>
  276.       <property name="accessible">
  277.         <getter>
  278.           <![CDATA[
  279.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  280.             return accService.createXULImageAccessible(this);
  281.           ]]>
  282.         </getter>
  283.       </property>
  284.     </implementation>
  285.   </binding>
  286.  
  287.   <binding id="deck">
  288.     <implementation>
  289.       <property name="selectedIndex"
  290.                 onget="return this.getAttribute('selectedIndex');">
  291.         <setter>
  292.         <![CDATA[
  293.           if (this.selectedIndex == val)
  294.             return val;
  295.           this.setAttribute("selectedIndex", val);
  296.           var event = document.createEvent('Events');
  297.           event.initEvent('select', false, true);
  298.           this.dispatchEvent(event);
  299.           return val;
  300.         ]]>
  301.         </setter>
  302.       </property>
  303.  
  304.  
  305.       <property name="selectedPanel">
  306.         <getter>
  307.           <![CDATA[
  308.             return this.childNodes[this.selectedIndex];
  309.           ]]>
  310.         </getter>
  311.  
  312.         <setter>
  313.           <![CDATA[
  314.             var selectedIndex = -1;
  315.             for (var panel = val; panel != null; panel = panel.previousSibling)
  316.               ++selectedIndex;
  317.             this.selectedIndex = selectedIndex;
  318.             return val;
  319.           ]]>
  320.         </setter>
  321.       </property>
  322.     </implementation>
  323.   </binding>
  324.  
  325.   <binding id="dropmarker">
  326.     <content>
  327.       <xul:image class="dropmarker-icon"/>
  328.     </content>
  329.  
  330.     <implementation implements="nsIAccessibleProvider">
  331.       <property name="accessible">
  332.         <getter>
  333.           <![CDATA[
  334.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  335.             return accService.createXULDropmarkerAccessible(this);
  336.           ]]>
  337.         </getter>
  338.       </property>
  339.     </implementation>
  340.   </binding>
  341.  
  342. </bindings>
  343.  
  344.