home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / chrome / toolkit.jar / content / global / bindings / dialog.xml < prev    next >
Encoding:
Extensible Markup Language  |  2006-10-24  |  14.8 KB  |  407 lines

  1. <?xml version="1.0"?>
  2.  
  3. <bindings id="dialogBindings"
  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="dialog-base">
  9.     <resources>
  10.       <stylesheet src="chrome://global/skin/dialog.css"/>
  11.     </resources>
  12.   </binding>
  13.   
  14.   <binding id="dialog" extends="chrome://global/content/bindings/dialog.xml#dialog-base">
  15.     <content>
  16.       <xul:vbox class="box-inherit dialog-content-box" flex="1">
  17.         <children/>
  18.       </xul:vbox>
  19.           
  20.       <xul:hbox class="dialog-button-box" anonid="buttons"
  21.                 xbl:inherits="pack=buttonpack,align=buttonalign,dir=buttondir,orient=buttonorient"
  22.                 >
  23.         <xul:button dlgtype="disclosure" class="dialog-button" hidden="true"/>
  24.         <xul:button dlgtype="help" class="dialog-button" hidden="true"/>
  25.         <xul:button dlgtype="extra2" class="dialog-button" hidden="true"/>
  26.         <xul:button dlgtype="extra1" class="dialog-button" hidden="true"/>
  27.         <xul:spacer anonid="spacer" flex="1"/>
  28.         <xul:button dlgtype="cancel" class="dialog-button"/>
  29.         <xul:button dlgtype="accept" class="dialog-button" xbl:inherits="disabled=buttondisabledaccept"/>
  30.       </xul:hbox>
  31.     </content>
  32.  
  33.     <implementation>
  34.       <field name="_mStrBundle">null</field>
  35.       <field name="_closeHandler">(function(event) {
  36.         if (!document.documentElement.cancelDialog())
  37.           event.preventDefault();
  38.       })</field>
  39.  
  40.       <property name="buttons"
  41.                 onget="return this.getAttribute('buttons');"
  42.                 onset="this._configureButtons(val); return val;"/>
  43.  
  44.       <property name="defaultButton">
  45.         <getter>
  46.         <![CDATA[
  47.           if (this.hasAttribute("defaultButton"))
  48.             return this.getAttribute("defaultButton");
  49.           else // default to the accept button
  50.             return "accept";
  51.         ]]>
  52.         </getter>
  53.         <setter>
  54.         <![CDATA[
  55.           this._setDefaultButton(val);
  56.           return val;
  57.         ]]>
  58.         </setter>
  59.       </property>
  60.  
  61.       <method name="acceptDialog">
  62.         <body>
  63.         <![CDATA[
  64.           return this._doButtonCommand("accept");
  65.         ]]>
  66.         </body>
  67.       </method>
  68.       
  69.       <method name="cancelDialog">
  70.         <body>
  71.         <![CDATA[
  72.           return this._doButtonCommand("cancel");
  73.         ]]>
  74.         </body>
  75.       </method>
  76.       
  77.       <method name="getButton">
  78.         <parameter name="aDlgType"/>
  79.         <body>
  80.         <![CDATA[
  81.           return this._buttons[aDlgType];
  82.         ]]>
  83.         </body>
  84.       </method>
  85.  
  86.       <method name="moveToAlertPosition">
  87.         <body>
  88.         <![CDATA[
  89.           // hack. we need this so the window has something like its final size
  90.           if (window.outerWidth == 1) {
  91.             dump("Trying to position a sizeless window; caller should have called sizeToContent() or sizeTo(). See bug 75649.\n");
  92.             sizeToContent();
  93.           }
  94.  
  95.           var xOffset = (opener.outerWidth - window.outerWidth) / 2;
  96.           var yOffset = opener.outerHeight / 5;
  97.  
  98.           var newX = opener.screenX + xOffset;
  99.           var newY = opener.screenY + yOffset;
  100.  
  101.           // ensure the window is fully onscreen (if smaller than the screen)
  102.           if (newX < screen.availLeft)
  103.             newX = screen.availLeft + 20;
  104.           if ((newX + window.outerWidth) > (screen.availLeft + screen.availWidth))
  105.             newX = (screen.availLeft + screen.availWidth) - window.outerWidth - 20;
  106.  
  107.           if (newY < screen.availTop)
  108.             newY = screen.availTop + 20;
  109.           if ((newY + window.outerHeight) > (screen.availTop + screen.availHeight))
  110.             newY = (screen.availTop + screen.availHeight) - window.outerHeight - 60;
  111.  
  112.           window.moveTo( newX, newY );
  113.         ]]>
  114.         </body>
  115.       </method>
  116.  
  117.       <method name="centerWindowOnScreen">
  118.         <body>
  119.         <![CDATA[
  120.           var xOffset = screen.availWidth/2 - window.outerWidth/2;
  121.           var yOffset = screen.availHeight/2 - window.outerHeight/2; //(opener.outerHeight *2)/10;
  122.   
  123.           xOffset = xOffset > 0 ? xOffset : 0;
  124.           yOffset = yOffset > 0 ? yOffset : 0;
  125.           window.moveTo(xOffset, yOffset);
  126.         ]]>
  127.         </body>
  128.       </method>
  129.  
  130.       <constructor>
  131.       <![CDATA[
  132.         this._configureButtons(this.buttons);
  133.  
  134.         // listen for when window is closed via native close buttons
  135.         window.addEventListener("close", this._closeHandler, false);
  136.  
  137.         // for things that we need to initialize after onload fires
  138.         window.addEventListener("load", this.postLoadInit, false);
  139.  
  140.         window.moveToAlertPosition = this.moveToAlertPosition;
  141.         window.centerWindowOnScreen = this.centerWindowOnScreen;
  142.       ]]>
  143.       </constructor>
  144.  
  145.       <method name="postLoadInit">
  146.         <parameter name="aEvent"/>
  147.         <body>
  148.         <![CDATA[
  149.           function focusInit() {
  150.             // give focus to the first focusable element in the dialog
  151.             if (!document.commandDispatcher.focusedElement) {
  152.               document.commandDispatcher.advanceFocusIntoSubtree(document.documentElement);
  153.               var focusedElt = document.commandDispatcher.focusedElement;
  154.               if (focusedElt) {
  155.                 if (focusedElt.localName == 'tab') {
  156.                   // Move focus into the tab
  157.                   document.commandDispatcher.advanceFocusIntoSubtree(focusedElt);
  158.                   if (document.commandDispatcher.focusedElement.hasAttribute("dlgtype")) {
  159.                     // We don't want to focus on anonymous OK, Cancel, etc. buttons,
  160.                     // so return focus to the tab itself
  161.                     focusedElt.focus();
  162.                   }
  163.                 }
  164.                 else {
  165.                   const dialog = document.documentElement;
  166.                   const defaultButton = dialog.getButton(dialog.defaultButton);
  167.                   if (focusedElt.hasAttribute("dlgtype") && focusedElt != defaultButton)
  168.                     defaultButton.focus();
  169.                 }
  170.               }
  171.             }
  172.           }
  173.  
  174.           // Give focus after onload completes, see bug 103197.
  175.           setTimeout(focusInit, 0);
  176.         ]]>
  177.         </body>
  178.       </method>                
  179.  
  180.       <property name="mStrBundle">
  181.         <getter>
  182.         <![CDATA[
  183.           if (!this._mStrBundle) {
  184.             // need to create string bundle manually instead of using <xul:stringbundle/>
  185.             // see bug 63370 for details
  186.             var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  187.                                   .getService(Components.interfaces.nsILocaleService);
  188.             var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  189.                                   .getService(Components.interfaces.nsIStringBundleService);
  190.             var bundleURL = "chrome://global/locale/dialog.properties";
  191.             this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.getApplicationLocale());
  192.           }
  193.           return this._mStrBundle;
  194.         ]]></getter>
  195.       </property>
  196.       
  197.       <method name="_configureButtons">
  198.         <parameter name="aButtons"/>
  199.         <body>
  200.         <![CDATA[
  201.           // by default, get all the anonymous button elements
  202.           var buttons = {};
  203.           this._buttons = buttons;
  204.           buttons.accept = document.getAnonymousElementByAttribute(this, "dlgtype", "accept");
  205.           buttons.cancel = document.getAnonymousElementByAttribute(this, "dlgtype", "cancel");
  206.           buttons.extra1 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra1");
  207.           buttons.extra2 = document.getAnonymousElementByAttribute(this, "dlgtype", "extra2");
  208.           buttons.help = document.getAnonymousElementByAttribute(this, "dlgtype", "help");
  209.           buttons.disclosure = document.getAnonymousElementByAttribute(this, "dlgtype", "disclosure");
  210.  
  211.           // look for any overriding explicit button elements
  212.           var exBtns = this.getElementsByAttribute("dlgtype", "*");
  213.           var dlgtype;
  214.           var i;
  215.           for (i = 0; i < exBtns.length; ++i) {
  216.             dlgtype = exBtns[i].getAttribute("dlgtype");
  217.             buttons[dlgtype].hidden = true; // hide the anonymous button
  218.             buttons[dlgtype] = exBtns[i];
  219.           }
  220.  
  221.           // add the label and oncommand handler to each button
  222.           for (dlgtype in buttons) {
  223.             var button = buttons[dlgtype];
  224.             button.addEventListener("command", this._handleButtonCommand, true);
  225.  
  226.             // don't override custom labels with pre-defined labels on explicit buttons
  227.             if (!button.hasAttribute("label")) {
  228.               // dialog attributes override the default labels in dialog.properties
  229.               if (this.hasAttribute("buttonlabel"+dlgtype)) {
  230.                 button.setAttribute("label", this.getAttribute("buttonlabel"+dlgtype));
  231.                 if (this.hasAttribute("buttonaccesskey"+dlgtype))
  232.                   button.setAttribute("accesskey", this.getAttribute("buttonaccesskey"+dlgtype));
  233.               } else if (dlgtype != "extra1" && dlgtype != "extra2") {
  234.                 button.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+dlgtype));
  235.                 var accessKey = this.mStrBundle.GetStringFromName("accesskey-"+dlgtype);
  236.                 if (accessKey)
  237.                   button.setAttribute("accesskey", accessKey);
  238.               }
  239.             }
  240.             // allow specifying alternate icons in the dialog header
  241.             if (!button.hasAttribute("icon")) {
  242.               // if there's an icon specified, use that
  243.               if (this.hasAttribute("buttonicon"+dlgtype))
  244.                 button.setAttribute("icon", this.getAttribute("buttonicon"+dlgtype));
  245.               // otherwise set defaults
  246.               else
  247.                 switch (dlgtype) {
  248.                   case "accept":
  249.                     button.setAttribute("icon","accept");
  250.                     break;
  251.                   case "cancel":
  252.                     button.setAttribute("icon","cancel");
  253.                     break;
  254.                   case "disclosue":
  255.                     button.setAttribute("icon","properties");
  256.                     break;
  257.                   case "help":
  258.                     button.setAttribute("icon","help");
  259.                     break;
  260.                   default:
  261.                     break;
  262.                 }
  263.             }
  264.           }
  265.  
  266.           // ensure that hitting enter triggers the default button command
  267.           this.defaultButton = this.defaultButton;
  268.           
  269.           // if there is a special button configuration, use it
  270.           if (aButtons) {
  271.             // expect a comma delimited list of dlgtype values
  272.             var list = aButtons.split(",");
  273.  
  274.             // mark shown dlgtypes as true
  275.             var shown = { accept: false, cancel: false, help: false,
  276.                           disclosure: false, extra1: false, extra2: false };
  277.             for (i = 0; i < list.length; ++i)
  278.               shown[list[i].replace(/ /g, "")] = true;
  279.  
  280.             // hide/show the buttons we want
  281.             for (dlgtype in buttons) 
  282.               buttons[dlgtype].hidden = !shown[dlgtype];
  283.  
  284.  
  285.           }
  286.         ]]>
  287.         </body>
  288.       </method>
  289.  
  290.       <method name="_setDefaultButton">
  291.         <parameter name="aNewDefault"/>
  292.         <body>
  293.         <![CDATA[
  294.           // remove the default attribute from the previous default button, if any
  295.           var oldDefaultButton = this.getButton(this.defaultButton);
  296.           if (oldDefaultButton)
  297.             oldDefaultButton.removeAttribute("default");
  298.  
  299.           var newDefaultButton = this.getButton(aNewDefault);
  300.           if (newDefaultButton) {
  301.             this.setAttribute("defaultButton", aNewDefault);
  302.             newDefaultButton.setAttribute("default", "true");
  303.           }
  304.           else {
  305.             this.setAttribute("defaultButton", "none");
  306.             if (aNewDefault != "none")
  307.               dump("invalid new default button: " +  aNewDefault + ", assuming: none\n");
  308.           }
  309.         ]]>
  310.         </body>
  311.       </method>
  312.  
  313.       <method name="_handleButtonCommand">
  314.         <parameter name="aEvent"/>
  315.         <body>
  316.         <![CDATA[
  317.           return document.documentElement._doButtonCommand(
  318.                                         aEvent.target.getAttribute("dlgtype"));
  319.         ]]>
  320.         </body>
  321.       </method>
  322.       
  323.       <method name="_doButtonCommand">
  324.         <parameter name="aDlgType"/>
  325.         <body>
  326.         <![CDATA[
  327.           var button = this.getButton(aDlgType);
  328.           if (!button.disabled) {
  329.             var noCancel = this._fireButtonEvent(aDlgType);
  330.             if (noCancel) {
  331.               if (aDlgType == "accept" || aDlgType == "cancel")
  332.                 window.close();
  333.             }
  334.             return noCancel;
  335.           }
  336.           return true;
  337.         ]]>
  338.         </body>
  339.       </method>
  340.       
  341.       <method name="_fireButtonEvent">
  342.         <parameter name="aDlgType"/>
  343.         <body>
  344.         <![CDATA[
  345.           var event = document.createEvent("Events");
  346.           event.initEvent("dialog"+aDlgType, true, true);
  347.           
  348.           // handle dom event handlers
  349.           var noCancel = this.dispatchEvent(event);
  350.           
  351.           // handle any xml attribute event handlers
  352.           var handler = this.getAttribute("ondialog"+aDlgType);
  353.           if (handler != "") {
  354.             var fn = new Function("event", handler);
  355.             var returned = fn(event);
  356.             if (returned == false)
  357.               noCancel = false;
  358.           }
  359.           
  360.           return noCancel;
  361.         ]]>
  362.         </body>
  363.       </method>
  364.  
  365.       <method name="_hitEnter">
  366.         <parameter name="evt"/>
  367.         <body>
  368.         <![CDATA[
  369.           if (evt.getPreventDefault())
  370.             return;
  371.  
  372.           var btn = this.getButton(this.defaultButton);
  373.           if (btn)
  374.             this._doButtonCommand(this.defaultButton);
  375.         ]]>
  376.         </body>
  377.       </method>
  378.  
  379.     </implementation>
  380.     
  381.     <handlers>
  382.       <handler event="keypress" keycode="VK_ENTER"
  383.                group="system" action="this._hitEnter(event);"/>
  384.       <handler event="keypress" keycode="VK_RETURN"
  385.                group="system" action="this._hitEnter(event);"/>
  386.       <handler event="keypress" keycode="VK_ESCAPE" group="system">
  387.         if (!event.getPreventDefault())
  388.           this.cancelDialog();
  389.       </handler>
  390.       <handler event="focus" phase="capturing">
  391.         var btn = this.getButton(this.defaultButton);
  392.         if (btn)
  393.           btn.setAttribute("default", event.originalTarget == btn || !(event.originalTarget instanceof Components.interfaces.nsIDOMXULButtonElement));
  394.       </handler>
  395.     </handlers>
  396.  
  397.   </binding>
  398.  
  399.   <binding id="dialogheader" extends="chrome://global/content/bindings/dialog.xml#dialog-base">
  400.     <content>
  401.       <xul:label class="dialogheader-title" xbl:inherits="value=title,crop" crop="right" flex="1"/>
  402.       <xul:label class="dialogheader-description" xbl:inherits="value=description"/>
  403.     </content>
  404.   </binding>
  405.  
  406. </bindings>
  407.