home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / widgets / browser.xml < prev    next >
Extensible Markup Language  |  2002-10-07  |  17KB  |  493 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!--
  4.    - The contents of this file are subject to the Mozilla Public
  5.    - License Version 1.1 (the "License"); you may not use this file
  6.    - except in compliance with the License. You may obtain a copy of
  7.    - the License at http://www.mozilla.org/MPL/
  8.    -
  9.    - Software distributed under the License is distributed on an "AS
  10.    - IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11.    - implied. See the License for the specific language governing
  12.    - rights and limitations under the License.
  13.    -
  14.    - The Original Code is this file as it was released on
  15.    - March 28, 2001.
  16.    -
  17.    - The Initial Developer of the Original Code is Peter Annema.
  18.    - Portions created by Peter Annema are Copyright (C) 2001
  19.    - Peter Annema.  All Rights Reserved.
  20.    -
  21.    - Contributor(s):
  22.    -   Peter Annema <disttsc@bart.nl> (Original Author of <browser>)
  23.    -
  24.    - Alternatively, the contents of this file may be used under the
  25.    - terms of the GNU General Public License Version 2 or later (the
  26.    - "GPL"), in which case the provisions of the GPL are applicable
  27.    - instead of those above.  If you wish to allow use of your
  28.    - version of this file only under the terms of the GPL and not to
  29.    - allow others to use your version of this file under the MPL,
  30.    - indicate your decision by deleting the provisions above and
  31.    - replace them with the notice and other provisions required by
  32.    - the GPL.  If you do not delete the provisions above, a recipient
  33.    - may use your version of this file under either the MPL or the
  34.    - GPL.
  35.   -->
  36.  
  37. <bindings id="browserBindings"
  38.           xmlns="http://www.mozilla.org/xbl"
  39.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  40.  
  41.   <binding id="browser" extends="xul:browser">
  42.     <implementation type="application/x-javascript" implements="nsIAccessibleProvider">
  43.       <property name="accessible">
  44.         <getter>
  45.           <![CDATA[
  46.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  47.             return accService.createIFrameAccessible(this);
  48.           ]]>
  49.         </getter>
  50.       </property>
  51.  
  52.       <property name="canGoBack"
  53.                 onget="return this.webNavigation.canGoBack;"
  54.                 readonly="true"/>
  55.  
  56.       <property name="canGoForward"
  57.                 onget="return this.webNavigation.canGoForward;"
  58.                 readonly="true"/>
  59.  
  60.       <method name="goBack">
  61.         <body>
  62.           <![CDATA[
  63.             var webNavigation = this.webNavigation;
  64.             if (webNavigation.canGoBack)
  65.               webNavigation.goBack();
  66.           ]]>
  67.         </body>
  68.       </method>
  69.  
  70.       <method name="goForward">
  71.         <body>
  72.           <![CDATA[
  73.             var webNavigation = this.webNavigation;
  74.             if (webNavigation.canGoForward)
  75.               webNavigation.goForward();
  76.           ]]>
  77.         </body>
  78.       </method>
  79.  
  80.       <method name="reload">
  81.         <body>
  82.           <![CDATA[
  83.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  84.             const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
  85.             this.reloadWithFlags(flags);
  86.           ]]>
  87.         </body>
  88.       </method>
  89.  
  90.       <method name="reloadWithFlags">
  91.         <parameter name="aFlags"/>
  92.         <body>
  93.           <![CDATA[
  94.             this.webNavigation.reload(aFlags);
  95.           ]]>
  96.         </body>
  97.       </method>
  98.  
  99.       <method name="stop">
  100.         <body>
  101.           <![CDATA[
  102.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  103.             const flags = nsIWebNavigation.STOP_ALL;
  104.             this.webNavigation.stop(flags);
  105.           ]]>
  106.         </body>
  107.       </method>
  108.  
  109.       <!-- throws exception for unknown schemes -->
  110.       <method name="loadURI">
  111.         <parameter name="aURI"/>
  112.         <parameter name="aReferrerURI"/>
  113.         <body>
  114.           <![CDATA[
  115.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  116.             const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
  117.             this.loadURIWithFlags(aURI, flags, aReferrerURI);
  118.           ]]>
  119.         </body>
  120.       </method>
  121.  
  122.       <!-- throws exception for unknown schemes -->
  123.       <method name="loadURIWithFlags">
  124.         <parameter name="aURI"/>
  125.         <parameter name="aFlags"/>
  126.         <parameter name="aReferrerURI"/>
  127.         <body>
  128.           <![CDATA[
  129.             if (!aURI)
  130.               aURI = "about:blank";
  131.  
  132.             this.webNavigation.loadURI(aURI, aFlags, aReferrerURI, null, null);
  133.           ]]>
  134.         </body>
  135.       </method>
  136.  
  137.       <method name="goHome">
  138.         <body>
  139.           <![CDATA[
  140.             try {
  141.               this.loadURI(this.homePage);
  142.             }
  143.             catch (e) {
  144.             }
  145.           ]]>
  146.         </body>
  147.       </method>
  148.  
  149.       <property name="homePage">
  150.         <getter>
  151.           <![CDATA[
  152.             var uri;
  153.  
  154.             if (this.hasAttribute("homepage"))
  155.               uri = this.getAttribute("homepage");
  156.             else
  157.               uri = "http://www.mozilla.org/"; // widget pride
  158.  
  159.             return uri;
  160.           ]]>
  161.         </getter>
  162.         <setter>
  163.           <![CDATA[
  164.             this.setAttribute("homepage", val);
  165.             return val;
  166.           ]]>
  167.         </setter>
  168.       </property>
  169.  
  170.       <method name="gotoIndex">
  171.         <parameter name="aIndex"/>
  172.         <body>
  173.           <![CDATA[
  174.             this.webNavigation.gotoIndex(aIndex);
  175.           ]]>
  176.         </body>
  177.       </method>
  178.  
  179.       <property name="currentURI"
  180.                 onget="return this.webNavigation.currentURI;"
  181.                 readonly="true"/>
  182.  
  183.       <property name="preferences"
  184.                 onget="return Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService);"
  185.                 readonly="true"/>
  186.  
  187.       <property name="docShell"
  188.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIBrowserBoxObject).docShell;"
  189.                 readonly="true"/>
  190.  
  191.       <property name="webNavigation"
  192.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  193.                 readonly="true"/>
  194.  
  195.       <property name="webBrowserFind"
  196.                 readonly="true"
  197.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebBrowserFind);"/>
  198.  
  199.       <property name="webProgress"
  200.                 readonly="true"
  201.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);"/>
  202.  
  203.       <property name="contentWindow"
  204.                 readonly="true"
  205.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);"/>
  206.  
  207.       <property name="sessionHistory"
  208.                 onget="return this.webNavigation.sessionHistory;"
  209.                 readonly="true"/>
  210.  
  211.       <property name="markupDocumentViewer"
  212.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);"
  213.                 readonly="true"/>
  214.  
  215.       <property name="contentViewerEdit"
  216.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerEdit);"
  217.                 readonly="true"/>
  218.  
  219.       <property name="contentViewerFile"
  220.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerFile);"
  221.                 readonly="true"/>
  222.  
  223.       <property name="documentCharsetInfo"
  224.                 onget="return this.docShell.documentCharsetInfo;"
  225.                 readonly="true"/>
  226.  
  227.       <property name="contentDocument"
  228.                 onget="return this.webNavigation.document;"
  229.                 readonly="true"/>
  230.  
  231.       <property name="contentTitle"
  232.                 onget="return Components.lookupMethod(this.contentDocument, 'title').call(this.contentDocument);"
  233.                 readonly="true"/>
  234.  
  235.       <field name="mPrefs" readonly="true">
  236.         Components.classes['@mozilla.org/preferences-service;1']
  237.                   .getService(Components.interfaces.nsIPrefService)
  238.                   .getBranch(null);
  239.       </field>
  240.  
  241.       <field name="_mStrBundle">null</field>
  242.  
  243.       <property name="mStrBundle">
  244.         <getter>
  245.         <![CDATA[
  246.           if (!this._mStrBundle) {
  247.             // need to create string bundle manually instead of using <xul:stringbundle/>
  248.             // see bug 63370 for details
  249.             var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  250.                                   .getService(Components.interfaces.nsILocaleService);
  251.             var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  252.                                   .getService(Components.interfaces.nsIStringBundleService);
  253.             var bundleURL = "chrome://global/locale/tabbrowser.properties";
  254.             this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
  255.           }
  256.           return this._mStrBundle;
  257.         ]]></getter>
  258.       </property>
  259.  
  260.       <method name="addProgressListener">
  261.         <parameter name="aListener"/>
  262.         <body>
  263.           <![CDATA[
  264.             this.webProgress.addProgressListener(aListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  265.           ]]>
  266.         </body>
  267.       </method>
  268.  
  269.       <method name="removeProgressListener">
  270.         <parameter name="aListener"/>
  271.         <body>
  272.           <![CDATA[
  273.             this.webProgress.removeProgressListener(aListener);
  274.          ]]>
  275.         </body>
  276.       </method>
  277.  
  278.       <method name="attachFormFill">
  279.         <body>
  280.           <![CDATA[
  281.           if (!this.mFormFillAttached && this.hasAttribute("autocompletepopup")) {
  282.             // hoop up the form fill autocomplete controller
  283.             var controller = Components.classes["@mozilla.org/satchel/form-fill-controller;1"].
  284.                                getService(Components.interfaces.nsIFormFillController);
  285.  
  286.             var popup = document.getElementById(this.getAttribute("autocompletepopup"));
  287.             if (popup)
  288.               controller.attachToBrowser(this.docShell, popup.QueryInterface(Components.interfaces.nsIAutoCompletePopup));
  289.             
  290.             this.mFormFillAttached = true;
  291.           }
  292.           ]]>
  293.         </body>
  294.       </method>
  295.  
  296.       <method name="detachFormFill">
  297.         <body>
  298.           <![CDATA[
  299.           if (this.mFormFillAttached) {
  300.             // hoop up the form fill autocomplete controller
  301.             var controller = Components.classes["@mozilla.org/satchel/form-fill-controller;1"].
  302.                                getService(Components.interfaces.nsIFormFillController);
  303.             controller.detachFromBrowser(this.docShell);
  304.             
  305.             this.mFormFillAttached = false;
  306.           }
  307.           ]]>
  308.         </body>
  309.       </method>
  310.       
  311.       <method name="onLoad">
  312.         <parameter name="aEvent"/>
  313.         <body>
  314.           <![CDATA[
  315.             this.removeEventListener("load", this.handleEvent, true);
  316.             this.attachFormFill();
  317.          ]]>
  318.         </body>
  319.       </method>
  320.  
  321.       <method name="onUnload">
  322.         <parameter name="aEvent"/>
  323.         <body>
  324.           <![CDATA[
  325.             if (this.pageReport) {
  326.               this.pageReport = null;
  327.               this.updatePageReport();
  328.             }
  329.          ]]>
  330.         </body>
  331.       </method>
  332.  
  333.       <method name="updatePageReport">
  334.         <body>
  335.           <![CDATA[
  336.             var n = this.parentNode;
  337.             while (n && n.localName != "tabbrowser")
  338.               n = n.parentNode;
  339.  
  340.             if (!n || n.mCurrentBrowser != this) return;
  341.            
  342.             var event = document.createEvent("Events");
  343.             event.initEvent("DOMUpdatePageReport", true, true);
  344.             n.dispatchEvent(event);
  345.           ]]>
  346.         </body>
  347.       </method>
  348.  
  349.       <method name="onPopupBlocked">
  350.         <parameter name="evt"/>
  351.         <body>
  352.           <![CDATA[
  353.             if (!this.pageReport) {
  354.               this.pageReport = new Array();
  355.               this.updatePageReport(); 
  356.             }
  357.  
  358.             this.pageReport.push(evt.target.location);
  359.           ]]> 
  360.         </body>
  361.       </method>
  362.  
  363.       <field name="pageReport">null</field>
  364.  
  365.       <field name="mDragDropHandler">
  366.         null
  367.       </field>
  368.  
  369.       <field name="securityUI">
  370.         null
  371.       </field>
  372.  
  373.       <field name="mFormFillAttached">
  374.         false
  375.       </field>
  376.  
  377.       <constructor>
  378.         <![CDATA[
  379.           try {
  380.             if (!this.hasAttribute("disablehistory")) {
  381.               // wire up session history
  382.               this.webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"].createInstance(Components.interfaces.nsISHistory);
  383.  
  384.               // wire up global history
  385.               var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
  386.  
  387.               this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory;      
  388.             }
  389.           }
  390.           catch (e) {
  391.           }
  392.           try {
  393.             this.mDragDropHandler = Components.classes["@mozilla.org:/content/content-area-dragdrop;1"].createInstance(Components.interfaces.nsIDragDropHandler);
  394.             this.mDragDropHandler.hookupTo(this, null, null, null);
  395.           }
  396.           catch (e) {
  397.           }
  398.           try {
  399.             const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
  400.             if (!this.hasAttribute("disablesecurity") &&
  401.                 SECUREBROWSERUI_CONTRACTID in Components.classes) {
  402.               this.securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
  403.               this.securityUI.init(this.contentWindow);
  404.             }
  405.           }
  406.           catch (e) {
  407.           }
  408.  
  409.           // Listen for first load for lazy attachment to form fill controller
  410.           this.addEventListener("load", this.onLoad, true);
  411.           this.addEventListener("unload", this.onUnload, true);
  412.           this.addEventListener("DOMPopupBlocked", this.onPopupBlocked, false);
  413.         ]]>
  414.       </constructor>
  415.       
  416.       <destructor>
  417.         <![CDATA[
  418.           this.destroy();
  419.         ]]>
  420.       </destructor>
  421.  
  422.       <!-- This is necessary because the destructor doesn't always get called when
  423.            we are removed from a tabbrowser. This will be explicitly called by tabbrowser -->
  424.       <method name="destroy">
  425.         <body>
  426.           <![CDATA[
  427.           if (this.mDragDropHandler)
  428.             this.mDragDropHandler.detach();
  429.  
  430.           this.detachFormFill();
  431.           
  432.           this.securityUI = null;
  433.           this.mDragDropHandler = null;
  434.  
  435.           this.removeEventListener("unload", this.onUnload, true);
  436.           ]]>
  437.         </body>
  438.       </method>
  439.     </implementation>
  440.  
  441.     <handlers>
  442.       <handler event="keypress" keycode="VK_F7">
  443.         <![CDATA[
  444.           // Toggle browse with caret mode
  445.           var browseWithCaretOn = false;
  446.           var warn = true;
  447.  
  448.           try {
  449.             warn = this.mPrefs.getBoolPref("accessibility.warn_on_browsewithcaret");
  450.           } catch (ex) {
  451.           }
  452.  
  453.           try {
  454.             browseWithCaretOn = this.mPrefs.getBoolPref("accessibility.browsewithcaret");
  455.           } catch (ex) {
  456.           }
  457.           if (warn && !browseWithCaretOn) {
  458.             var checkValue = {value:false};
  459.             promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  460.  
  461.             var buttonPressed = promptService.confirmEx(window, 
  462.               this.mStrBundle.GetStringFromName('browsewithcaret.checkWindowTitle'), 
  463.               this.mStrBundle.GetStringFromName('browsewithcaret.checkLabel'),
  464.               (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) +
  465.               (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
  466.               this.mStrBundle.GetStringFromName('browsewithcaret.checkButtonLabel'),
  467.               null, null,
  468.               this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'), 
  469.               checkValue);
  470.             if (buttonPressed != 0)
  471.               return;
  472.             if (checkValue.value) {
  473.               try {
  474.                 this.mPrefs.setBoolPref("accessibility.warn_on_browsewithcaret", false);
  475.               }
  476.               catch (ex) {
  477.               }
  478.             }
  479.           }
  480.  
  481.           // Toggle the pref
  482.           try {
  483.             this.mPrefs.setBoolPref("accessibility.browsewithcaret",!browseWithCaretOn);
  484.           } catch (ex) {
  485.           }
  486.         ]]>
  487.       </handler>
  488.     </handlers>
  489.  
  490.   </binding>
  491.  
  492. </bindings>
  493.