home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / toolkit.jar / content / global / bindings / popup.xml < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-17  |  17.4 KB  |  525 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="popupBindings"
  4.    xmlns="http://www.mozilla.org/xbl"
  5.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  6.  
  7.   <binding id="popup-base">
  8.     <resources>
  9.       <stylesheet src="chrome://global/skin/popup.css"/>
  10.     </resources>
  11.   </binding>
  12.  
  13.   <binding id="popup" extends="chrome://global/content/bindings/popup.xml#popup-base">
  14.     <content>
  15.       <xul:arrowscrollbox class="popup-internal-box" flex="1" orient="vertical">
  16.         <children/>
  17.       </xul:arrowscrollbox>
  18.     </content>
  19.  
  20.     <implementation>
  21.       <property name="position" onget="return this.getAttribute('position');"
  22.                                 onset="this.setAttribute('position', val); return val;"/>
  23.       <method name="openPopup">
  24.         <parameter name="element"/>
  25.         <parameter name="xpos"/>
  26.         <parameter name="ypos"/>
  27.         <parameter name="popuptype"/>
  28.         <parameter name="anchoralignment"/>
  29.         <parameter name="popupalignment"/>
  30.         <body>
  31.         <![CDATA[
  32.           try {
  33.             var popupBox = this.boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  34.           } catch(e) {}
  35.           try {
  36.             var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
  37.           } catch(e) {}
  38.           if (menuBox)
  39.             menuBox.openMenu(true);
  40.           else if (popupBox)
  41.             popupBox.showPopup(element, this, xpos, ypos, popuptype, anchoralignment, popupalignment);
  42.         ]]>
  43.         </body>
  44.       </method>
  45.       <method name="closePopup">
  46.         <body>
  47.         <![CDATA[
  48.           try {
  49.             var popupBox = this.boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  50.           } catch(e) {}
  51.           try {
  52.             var menuBox = this.parentNode.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
  53.           } catch(e) {}
  54.           if (menuBox)
  55.             menuBox.openMenu(false);
  56.           else if (popupBox)
  57.             popupBox.hidePopup();
  58.         ]]>
  59.         </body>
  60.       </method>
  61.     </implementation>     
  62.  
  63.     <handlers>
  64.       <handler event="contextmenu" action="event.preventDefault();"/>
  65.     </handlers>
  66.   </binding>
  67.  
  68.   <binding id="tooltips" extends="chrome://global/content/bindings/popup.xml#popup">
  69.     <content>
  70.       <xul:vbox class="popup-internal-box" flex="1">
  71.         <children/>
  72.       </xul:vbox>
  73.     </content>
  74.   </binding>
  75.   
  76.   <binding id="titletip" extends="chrome://global/content/bindings/popup.xml#popup">
  77.     <content>
  78.       <xul:text inherits="value=label"/>
  79.     </content>
  80.   </binding>
  81.   
  82.   <binding id="resizerbase" extends="xul:box">
  83.     <implementation>
  84.       <method name="findPopup">
  85.         <body>
  86.         <![CDATA[
  87.           var currNode = this.parentNode;
  88.           while (currNode) {
  89.             if (currNode.localName == "popup" ||
  90.                 currNode.localName == "menupopup")
  91.               return currNode;
  92.             currNode = currNode.parentNode;
  93.           }
  94.           return null;
  95.         ]]>
  96.         </body>
  97.       </method>
  98.       
  99.       <method name="handleMouseMove">
  100.         <parameter name="aEvent"/>
  101.         <body>
  102.         <![CDATA[
  103.           throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  104.         ]]>
  105.         </body>
  106.       </method> 
  107.       
  108.       <property name="screenLeft">0</property>
  109.       <property name="screenTop">0</property>
  110.       <property name="direction">0</property>
  111.       <property name="popup">0</property>
  112.     </implementation>
  113.     
  114.     <handlers>
  115.       <handler event="mousedown" phase="capturing"> 
  116.       <![CDATA[
  117.         var popup = event.target.findPopup();
  118.         var boxObject = popup.boxObject;
  119.         boxObject.captureMouseEvents = true;
  120.         event.target.screenLeft = event.screenX;
  121.         event.target.screenTop = event.screenY;
  122.         event.target.setMode();
  123.         event.preventDefault();
  124.       ]]>
  125.       </handler>
  126.       <handler event="mouseup" phase="capturing">
  127.       <![CDATA[
  128.         var popup = event.target.findPopup();
  129.         var boxObject = popup.boxObject;
  130.         boxObject.captureMouseEvents = false;
  131.         event.target.screenLeft = event.screenX;
  132.         event.target.screenTop = event.screenY;
  133.         event.target.direction = 0;
  134.         event.preventDefault();
  135.       ]]>
  136.       </handler>
  137.       <handler event="mousemove" phase="capturing">
  138.       <![CDATA[
  139.         event.target.handleMouseMove(event);
  140.         event.preventDefault();
  141.       ]]>
  142.       </handler>
  143.     </handlers>
  144.   </binding>
  145.   
  146.   <!-- Right horizontal resizer -->
  147.   <binding id="r-resizer" extends="xul:box"> <!-- extends="chrome://global/content/bindings/popup.xml#resizerbase"> -->
  148.     <content>
  149.       <xul:hbox class="b-resizer-box" flex="1"/>
  150.     </content>
  151.     <!--
  152.     <implementation>
  153.       <method name="handleMouseMove">
  154.         <parameter name="aEvent"/>
  155.         <body>
  156.         <![CDATA[
  157.           if (!this.popup) this.popup = aEvent.target.findPopup();
  158.           var boxObject = this.popup.boxObject;
  159.           if (boxObject.captureMouseEvents && this.direction == "right") {
  160.             var popupBoxObject = boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  161.             var width = this.popup.boxObject.width;
  162.             var delta = aEvent.screenX - this.screenLeft;
  163.             this.screenLeft = aEvent.screenX;
  164.             popupBoxObject.width = width + delta;
  165.           }
  166.         ]]>
  167.         </body>
  168.       </method>
  169.       <method name="setMode">
  170.         <body>
  171.         <![CDATA[
  172.           this.direction = "right";
  173.         ]]>
  174.         </body>
  175.       </method>
  176.     </implementation>
  177.     -->
  178.   </binding>
  179.   
  180.   <!-- Bottom vertical resizer -->
  181.   <binding id="b-resizer" extends="xul:box"> <!-- extends="chrome://global/content/bindings/popup.xml#resizerbase"> -->
  182.     <content>
  183.       <xul:hbox class="b-resizer-box" flex="1"/>
  184.     </content>
  185.     <!--
  186.     <implementation>
  187.       <method name="handleMouseMove">
  188.         <parameter name="aEvent"/>
  189.         <body>
  190.         <![CDATA[
  191.           if (!this.popup) this.popup = aEvent.target.findPopup();
  192.           var boxObject = this.popup.boxObject;
  193.           if (boxObject.captureMouseEvents && this.direction == "bottom") {
  194.             var popupBoxObject = boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  195.             var height = this.popup.boxObject.height;
  196.             var delta = aEvent.screenY - this.screenTop;
  197.             this.screenTop = aEvent.screenY;
  198.             popupBoxObject.height = height + delta;
  199.           }
  200.         ]]>
  201.         </body>
  202.       </method>
  203.       <method name="setMode">
  204.         <body>
  205.         <![CDATA[
  206.           this.direction = "bottom";
  207.         ]]>
  208.         </body>
  209.       </method>
  210.     </implementation>
  211.     -->
  212.   </binding>
  213.   
  214.   <!-- Right/Bottom diagonal resizer -->
  215.   <binding id="rb-resizer" extends="xul:box"> <!-- extends="chrome://global/content/bindings/popup.xml#resizerbase"> -->
  216.     <content>
  217.       <xul:hbox class="rb-resizer-box" align="center" flex="1">
  218.         <xul:image class="rb-resizer-image"/>
  219.       </xul:hbox>
  220.     </content>
  221.     <!--
  222.     <implementation>
  223.       <method name="handleMouseMove">
  224.         <parameter name="aEvent"/>
  225.         <body>
  226.         <![CDATA[
  227.           if (!this.popup) this.popup = aEvent.target.findPopup();
  228.           var boxObject = this.popup.boxObject;
  229.           if (boxObject.captureMouseEvents && this.direction == "bottomright") {
  230.             if (!this.screenLeft || !this.screenTop) {
  231.               this.screenLeft = aEvent.screenX; this.screenTop = aEvent.screenY;
  232.             }
  233.             var popupBoxObject = boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  234.             var deltaX = aEvent.screenX - this.screenLeft;
  235.             var deltaY = aEvent.screenY - this.screenTop;
  236.             this.screenLeft = aEvent.screenX;
  237.             this.screenTop = aEvent.screenY;
  238.             popupBoxObject.width += deltaX;
  239.             popupBoxObject.height += deltaY;
  240.           }
  241.         ]]>
  242.         </body>
  243.       </method>
  244.       <method name="setMode">
  245.         <body>
  246.         <![CDATA[
  247.           this.direction = "bottomright";
  248.         ]]>
  249.         </body>
  250.       </method>
  251.     </implementation>
  252.     -->
  253.   </binding>
  254.   
  255.   <binding id="titlebar" extends="xul:box"> <!-- extends="chrome://global/content/bindings/popup.xml#resizerbase"> -->
  256.     <content>
  257.       <xul:hbox class="titlebar-box" flex="1">
  258.         <xul:hbox class="titlebar-title-box" flex="1" tooltip="aTooltip" tooltiptext="Click and drag to float">
  259.           <xul:text class="titlebar-title" inherits="value=title" flex="1" crop="right"/>
  260.         </xul:hbox>
  261.         <xul:button class="popupClose" tooltip="aTooltip" tooltiptext="Close"/>
  262.       </xul:hbox>
  263.     </content>
  264.     <!--
  265.     <implementation>
  266.       <method name="handleMouseMove">
  267.         <parameter name="aEvent"/>
  268.         <body>
  269.         <![CDATA[
  270.           if (!this.popup) this.popup = aEvent.target.findPopup();
  271.           var boxObject = this.popup.boxObject;
  272.           if (boxObject.captureMouseEvents && this.direction == "titlebar") {
  273.             if (!this.screenLeft || !this.screenTop) {
  274.               this.screenLeft = aEvent.screenX; this.screenTop = aEvent.screenY;
  275.             }
  276.             var popupBoxObject = boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  277.             var deltaX = aEvent.screenX - this.screenLeft;
  278.             var deltaY = aEvent.screenY - this.screenTop;
  279.             this.screenLeft = aEvent.screenX;
  280.             this.screenTop = aEvent.screenY;
  281.             popupBoxObject.left += deltaX;
  282.             popupBoxObject.top += deltaY;
  283.           }
  284.         ]]>
  285.         </body>
  286.       </method>
  287.       <method name="setMode">
  288.         <body>
  289.         <![CDATA[
  290.           this.direction = "titlebar";
  291.         ]]>
  292.         </body>
  293.       </method>
  294.     </implementation>
  295.     -->
  296.   </binding>          
  297.  
  298.   <binding id="floater-base" extends="xul:popup">
  299.     <implementation>
  300.       <method name="findPopup">
  301.         <body>
  302.         <![CDATA[
  303.           var currNode = this.parentNode;
  304.           while (currNode) {
  305.             if (currNode.localName == "popup" ||
  306.                 currNode.localName == "menupopup")
  307.               return currNode;
  308.             currNode = currNode.parentNode;
  309.           }
  310.           return null;
  311.         ]]>
  312.         </body>
  313.       </method>
  314.       <method name="handleMouseMove">
  315.         <parameter name="aEvent"/>
  316.         <body>
  317.         <![CDATA[
  318.           var boxObject = this.boxObject;
  319.           if (boxObject.captureMouseEvents) {
  320.             var pBO = boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  321.             var dX, dY;
  322.             var eScreenX = aEvent.screenX; 
  323.             var eScreenY = aEvent.screenY;
  324.             switch (this.direction) {
  325.               case "right":
  326.                 var width = boxObject.width;
  327.                 dX = eScreenX - this.screenLeft;
  328.                 pBO.sizeTo(width + dX, pBO.height);
  329.                 break;
  330.               case "bottom":
  331.                 var height = boxObject.height;
  332.                 dY = eScreenY - this.screenTop;
  333.                 pBO.sizeTo(pBO.width, height + dY);
  334.                 break;
  335.               case "bottomright":
  336.                 dX = eScreenX - this.screenLeft;
  337.                 dY = eScreenY - this.screenTop;
  338.                 pBO.sizeTo(pBO.width + dX, pBO.height + dY);
  339.                 break;
  340.               case "titlebar":
  341.                 pBO.autoPosition = false;
  342.                 pBO.enableRollup(false);
  343.                 pBO.enableKeyboardNavigator(false);
  344.                 if (this.doDock(pBO, aEvent, eScreenX, eScreenY)) break;
  345.                 dX = eScreenX - this.screenLeft;
  346.                 dY = eScreenY - this.screenTop;
  347.                 pBO.moveTo(pBO.left + dX, pBO.top + dY);
  348.                 this.docked = 0;
  349.                 break;
  350.               default:
  351.                 break;                      
  352.             }
  353.             this.screenLeft = eScreenX;
  354.             this.screenTop = eScreenY;
  355.           }
  356.         ]]>
  357.         </body>
  358.       </method> 
  359.       <method name="findParentByLocalName">
  360.         <parameter name="aNode"/>
  361.         <parameter name="aLocalName"/>
  362.         <body>
  363.         <![CDATA[
  364.           var parent = aNode;
  365.           var names = [].concat(aLocalName);
  366.           while (parent) {
  367.             for (var i = 0; i < names.length; ++i) {
  368.               if (parent.localName == names[i])
  369.                 return parent;
  370.             }
  371.             parent = parent.parentNode;
  372.           }
  373.           return null;
  374.         ]]>
  375.         </body>
  376.       </method>
  377.       <method name="setMode">
  378.         <parameter name="aEvent"/>
  379.         <body>
  380.         <![CDATA[
  381.           var widget = this.findParentByLocalName(aEvent.originalTarget, ["resizer", "titlebar"]);
  382.           if (widget) {
  383.             if (widget.localName == "titlebar")
  384.               this.direction = "titlebar";
  385.             else 
  386.               this.direction = widget.getAttribute("direction");
  387.           }
  388.         ]]>
  389.         </body>
  390.       </method>
  391.       <method name="doDock">
  392.         <parameter name="aPBO"/>
  393.         <parameter name="aEvent"/>
  394.         <parameter name="xCoord"/>
  395.         <parameter name="yCoord"/>
  396.         <body>
  397.         <![CDATA[
  398.           const kDragZone = 20;
  399.           if (xCoord < kDragZone) {
  400.             if (!this.docked) {
  401.               aPBO.sizeTo(aPBO.width, screen.availHeight);
  402.               aPBO.moveTo(0,22);
  403.               this.docked = "left";
  404.               this.cleanUp(aEvent);
  405.               //this.setAttribute("docked", "left");
  406.             }
  407.             return true;
  408.           }
  409.           else if (xCoord > (screen.availWidth - kDragZone)) {
  410.             if (!this.docked) {
  411.               aPBO.sizeTo(aPBO.width, screen.availHeight);
  412.               aPBO.moveTo(screen.availWidth - aPBO.width,22);
  413.               this.docked = "right";
  414.               this.cleanUp(aEvent);
  415.               //this.setAttribute("docked", "right");
  416.             }
  417.           }
  418.           return false;
  419.         ]]>
  420.         </body>
  421.       </method>
  422.       <method name="cleanUp">
  423.         <parameter name="aEvent"/>
  424.         <body>
  425.         <![CDATA[
  426.           this.boxObject.captureMouseEvents = false;
  427.           this.screenLeft = aEvent.screenX;
  428.           this.screenTop = aEvent.screenY;
  429.           this.direction = 0;
  430.           aEvent.preventDefault();
  431.         ]]>
  432.         </body>
  433.       </method>
  434.       <property name="screenLeft">0</property>
  435.       <property name="screenTop">0</property>
  436.       <property name="direction">0</property>
  437.       <property name="docked">0</property>
  438.       <property name="popup">0</property>
  439.     </implementation>
  440.     <handlers>
  441.       <handler event="mousedown" phase="capturing"> 
  442.       <![CDATA[
  443.         this.boxObject.captureMouseEvents = true;
  444.         this.screenLeft = event.screenX;
  445.         this.screenTop = event.screenY;
  446.         this.setMode(event);
  447.       ]]>
  448.       </handler>
  449.       <handler event="mouseup" phase="capturing">
  450.       <![CDATA[
  451.         this.cleanUp(event);
  452.       ]]>
  453.       </handler>
  454.       <handler event="mousemove" phase="capturing">
  455.       <![CDATA[
  456.         this.handleMouseMove(event);
  457.         event.preventDefault();
  458.       ]]>
  459.       </handler>
  460.       <!-- clean up, release the mouse, etc -->
  461.       <handler event="popuphiding">
  462.       <![CDATA[
  463.         dump("*** destroy: releasing mouse\n");
  464.         this.cleanUp(event);
  465.       ]]>
  466.       </handler>
  467.       <handler event="click">
  468.       <![CDATA[
  469.         dump("*** clicked\n");
  470.         if (event.originalTarget.className.indexOf("popupClose") != -1) {
  471.           var popupBoxObject = this.boxObject.QueryInterface(Components.interfaces.nsIPopupBoxObject);
  472.           dump("*** hiding the popup\n");
  473.           popupBoxObject.hide();
  474.         }
  475.       ]]>
  476.       </handler>
  477.     </handlers>
  478.   </binding>
  479.  
  480.   <binding id="floater-normal" extends="chrome://global/content/bindings/popup.xml#floater-base">
  481.     <content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
  482.       <vbox class="floater-box" flex="1">
  483.         <box class="floater-box-top">
  484.           <titlebar flex="1" inherits="title"/>
  485.         </box>
  486.         <box class="floater-box-center" flex="1">
  487.           <box class="floater-children" flex="1"> 
  488.             <children/>
  489.           </box>
  490.         </box>
  491.         <box class="floater-box-bottom">
  492.           <resizer direction="bottom" flex="1"/>
  493.           <resizer direction="bottomright" tooltip="aTooltip" tooltiptext="Click and drag to resize"/>
  494.         </box>
  495.       </vbox>
  496.     </content>
  497.   </binding>
  498.  
  499.   <binding id="floater-dock-left" extends="chrome://global/content/bindings/popup.xml#floater-base">
  500.     <content xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
  501.       <vbox class="floater-box" flex="1">
  502.         <box class="floater-box-top">
  503.           <titlebar flex="1" inherits="title"/>
  504.         </box>
  505.         <box class="floater-box-center" flex="1">
  506.           <box class="floater-children" flex="1"> 
  507.             <children/>
  508.           </box>
  509.           <resizer direction="right" tooltip="aTooltip" tooltiptext="Click and drag to resize"/>
  510.         </box>
  511.       </vbox>
  512.     </content>
  513.   </binding>  
  514.   
  515.   <binding id="close-button" extends="chrome://global/content/bindings/button.xml#button-base">
  516.     <content>
  517.       <xul:hbox align="center" flex="1">
  518.         <xul:image class="close-button-x"/>
  519.       </xul:hbox>
  520.     </content>
  521.   </binding>
  522.  
  523. </bindings>
  524.  
  525.