gecko-dev/toolkit/content/widgets/browser.xml

672 строки
24 KiB
XML
Исходник Обычный вид История

2002-09-28 10:25:03 +04:00
<?xml version="1.0"?>
<!--
- The contents of this file are subject to the Mozilla Public
- License Version 1.1 (the "License"); you may not use this file
- except in compliance with the License. You may obtain a copy of
- the License at http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS
- IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- implied. See the License for the specific language governing
- rights and limitations under the License.
-
- The Original Code is this file as it was released on
- March 28, 2001.
-
- The Initial Developer of the Original Code is Peter Annema.
- Portions created by Peter Annema are Copyright (C) 2001
- Peter Annema. All Rights Reserved.
-
- Contributor(s):
- Peter Annema <disttsc@bart.nl> (Original Author of <browser>)
-
- Alternatively, the contents of this file may be used under the
- terms of the GNU General Public License Version 2 or later (the
- "GPL"), in which case the provisions of the GPL are applicable
- instead of those above. If you wish to allow use of your
- version of this file only under the terms of the GPL and not to
- allow others to use your version of this file under the MPL,
- indicate your decision by deleting the provisions above and
- replace them with the notice and other provisions required by
- the GPL. If you do not delete the provisions above, a recipient
- may use your version of this file under either the MPL or the
- GPL.
-->
<bindings id="browserBindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="browser" extends="xul:browser">
<implementation type="application/x-javascript" implements="nsIAccessibleProvider">
<property name="accessible">
<getter>
<![CDATA[
var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
return accService.createIFrameAccessible(this);
]]>
</getter>
</property>
<property name="canGoBack"
onget="return this.webNavigation.canGoBack;"
readonly="true"/>
<property name="canGoForward"
onget="return this.webNavigation.canGoForward;"
readonly="true"/>
<method name="goBack">
<body>
<![CDATA[
var webNavigation = this.webNavigation;
if (webNavigation.canGoBack)
webNavigation.goBack();
]]>
</body>
</method>
<method name="goForward">
<body>
<![CDATA[
var webNavigation = this.webNavigation;
if (webNavigation.canGoForward)
webNavigation.goForward();
]]>
</body>
</method>
<method name="reload">
<body>
<![CDATA[
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
this.reloadWithFlags(flags);
]]>
</body>
</method>
<method name="reloadWithFlags">
<parameter name="aFlags"/>
<body>
<![CDATA[
this.webNavigation.reload(aFlags);
]]>
</body>
</method>
<method name="stop">
<body>
<![CDATA[
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
const flags = nsIWebNavigation.STOP_ALL;
this.webNavigation.stop(flags);
]]>
</body>
</method>
<!-- throws exception for unknown schemes -->
<method name="loadURI">
<parameter name="aURI"/>
<parameter name="aReferrerURI"/>
<body>
<![CDATA[
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
this.loadURIWithFlags(aURI, flags, aReferrerURI);
]]>
</body>
</method>
<!-- throws exception for unknown schemes -->
<method name="loadURIWithFlags">
<parameter name="aURI"/>
<parameter name="aFlags"/>
<parameter name="aReferrerURI"/>
<body>
<![CDATA[
if (!aURI)
aURI = "about:blank";
this.webNavigation.loadURI(aURI, aFlags, aReferrerURI, null, null);
]]>
</body>
</method>
<method name="goHome">
<body>
<![CDATA[
try {
this.loadURI(this.homePage);
}
catch (e) {
}
]]>
</body>
</method>
<property name="homePage">
<getter>
<![CDATA[
var uri;
if (this.hasAttribute("homepage"))
uri = this.getAttribute("homepage");
else
uri = "http://www.mozilla.org/"; // widget pride
return uri;
]]>
</getter>
<setter>
<![CDATA[
this.setAttribute("homepage", val);
return val;
]]>
</setter>
</property>
<method name="gotoIndex">
<parameter name="aIndex"/>
<body>
<![CDATA[
this.webNavigation.gotoIndex(aIndex);
]]>
</body>
</method>
<property name="currentURI"
onget="return this.webNavigation.currentURI;"
readonly="true"/>
<property name="preferences"
onget="return Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService);"
readonly="true"/>
<property name="docShell"
onget="return this.boxObject.QueryInterface(Components.interfaces.nsIBrowserBoxObject).docShell;"
readonly="true"/>
<property name="webNavigation"
onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
readonly="true"/>
<property name="webBrowserFind"
readonly="true"
onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebBrowserFind);"/>
<property name="webProgress"
readonly="true"
onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);"/>
<property name="contentWindow"
readonly="true"
onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);"/>
<property name="sessionHistory"
onget="return this.webNavigation.sessionHistory;"
readonly="true"/>
<property name="markupDocumentViewer"
onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);"
readonly="true"/>
<property name="contentViewerEdit"
onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerEdit);"
readonly="true"/>
<property name="contentViewerFile"
onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerFile);"
readonly="true"/>
<property name="documentCharsetInfo"
onget="return this.docShell.documentCharsetInfo;"
readonly="true"/>
<property name="contentDocument"
onget="return this.webNavigation.document;"
readonly="true"/>
<property name="contentTitle"
onget="return Components.lookupMethod(this.contentDocument, 'title').call(this.contentDocument);"
readonly="true"/>
<field name="mPrefs" readonly="true">
Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService)
.getBranch(null);
</field>
<field name="_mStrBundle">null</field>
<property name="mStrBundle">
<getter>
<![CDATA[
if (!this._mStrBundle) {
// need to create string bundle manually instead of using <xul:stringbundle/>
// see bug 63370 for details
var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
.getService(Components.interfaces.nsILocaleService);
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var bundleURL = "chrome://global/locale/tabbrowser.properties";
this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
}
return this._mStrBundle;
]]></getter>
</property>
<method name="addProgressListener">
<parameter name="aListener"/>
<body>
<![CDATA[
this.webProgress.addProgressListener(aListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
]]>
</body>
</method>
<method name="removeProgressListener">
<parameter name="aListener"/>
<body>
<![CDATA[
this.webProgress.removeProgressListener(aListener);
]]>
</body>
</method>
<method name="attachFormFill">
<body>
<![CDATA[
if (!this.mFormFillAttached && this.hasAttribute("autocompletepopup")) {
// hoop up the form fill autocomplete controller
var controller = Components.classes["@mozilla.org/satchel/form-fill-controller;1"].
getService(Components.interfaces.nsIFormFillController);
var popup = document.getElementById(this.getAttribute("autocompletepopup"));
if (popup)
controller.attachToBrowser(this.docShell, popup.QueryInterface(Components.interfaces.nsIAutoCompletePopup));
this.mFormFillAttached = true;
}
]]>
</body>
</method>
<method name="detachFormFill">
<body>
<![CDATA[
if (this.mFormFillAttached) {
// hoop up the form fill autocomplete controller
var controller = Components.classes["@mozilla.org/satchel/form-fill-controller;1"].
getService(Components.interfaces.nsIFormFillController);
controller.detachFromBrowser(this.docShell);
this.mFormFillAttached = false;
}
]]>
</body>
</method>
<method name="onLoad">
<parameter name="aEvent"/>
<body>
<![CDATA[
this.removeEventListener("load", this.handleEvent, true);
this.attachFormFill();
]]>
</body>
</method>
2002-10-08 07:23:38 +04:00
<method name="onUnload">
<parameter name="aEvent"/>
<body>
<![CDATA[
if (this.pageReport) {
this.pageReport = null;
this.updatePageReport();
}
]]>
</body>
</method>
<method name="updatePageReport">
<body>
<![CDATA[
var n = this.parentNode;
while (n && n.localName != "tabbrowser")
n = n.parentNode;
if (!n || n.mCurrentBrowser != this) return;
var event = document.createEvent("Events");
event.initEvent("DOMUpdatePageReport", true, true);
n.dispatchEvent(event);
]]>
</body>
</method>
<method name="onPopupBlocked">
<parameter name="evt"/>
<body>
<![CDATA[
if (!this.pageReport) {
this.pageReport = new Array();
this.updatePageReport();
}
2002-10-08 07:28:02 +04:00
this.pageReport.push(evt.target.location);
2002-10-08 07:23:38 +04:00
]]>
</body>
</method>
<field name="pageReport">null</field>
2002-09-28 10:25:03 +04:00
<field name="mDragDropHandler">
null
</field>
<field name="securityUI">
null
</field>
<field name="mFormFillAttached">
false
</field>
<constructor>
<![CDATA[
try {
if (!this.hasAttribute("disablehistory")) {
// wire up session history
this.webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"].createInstance(Components.interfaces.nsISHistory);
// wire up global history
var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory;
}
}
catch (e) {
}
try {
this.mDragDropHandler = Components.classes["@mozilla.org:/content/content-area-dragdrop;1"].createInstance(Components.interfaces.nsIDragDropHandler);
this.mDragDropHandler.hookupTo(this, null, null, null);
}
catch (e) {
}
try {
const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
if (!this.hasAttribute("disablesecurity") &&
SECUREBROWSERUI_CONTRACTID in Components.classes) {
this.securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
this.securityUI.init(this.contentWindow);
}
}
catch (e) {
}
// Listen for first load for lazy attachment to form fill controller
this.addEventListener("load", this.onLoad, true);
2002-10-08 07:23:38 +04:00
this.addEventListener("unload", this.onUnload, true);
this.addEventListener("DOMPopupBlocked", this.onPopupBlocked, false);
2002-09-28 10:25:03 +04:00
]]>
</constructor>
<destructor>
<![CDATA[
this.destroy();
]]>
</destructor>
<!-- This is necessary because the destructor doesn't always get called when
we are removed from a tabbrowser. This will be explicitly called by tabbrowser -->
<method name="destroy">
<body>
<![CDATA[
if (this.mDragDropHandler)
this.mDragDropHandler.detach();
this.detachFormFill();
this.securityUI = null;
this.mDragDropHandler = null;
2002-10-08 07:23:38 +04:00
this.removeEventListener("unload", this.onUnload, true);
2002-09-28 10:25:03 +04:00
]]>
</body>
</method>
2003-07-06 09:23:05 +04:00
#ifdef XP_WIN
<field name="_scrollObj">null</field>
2003-07-06 09:23:05 +04:00
<field name="_isScrolling">false</field>
<field name="_autoScrollMarkerImage">null</field>
<field name="_scrollingFingerFree">false</field>
<field name="_scrollPeriod">40</field>
<field name="_scrollInterval">null</field>
2003-07-06 09:23:05 +04:00
<field name="_startX">null</field>
<field name="_distanceX">null</field>
2003-07-06 09:23:05 +04:00
<field name="_startY">null</field>
<field name="_distanceY">null</field>
<field name="_startTime">null</field>
2003-07-06 09:23:05 +04:00
<method name="autoScrollLoop1">
<body>
<![CDATA[
this._scrollObj.clientFrame.scrollBy(this._distanceX, this._distanceY);
]]>
</body>
</method>
<method name="autoScrollLoop2">
<body>
<![CDATA[
this._scrollObj.nodeToScroll.scrollLeft += this._distanceX;
this._scrollObj.nodeToScroll.scrollTop += this._distanceY;
]]>
</body>
</method>
<method name="isLink">
<parameter name="node"/>
<body>
<![CDATA[
if (!node) return false;
if (node.nodeName == "A" || node.nodeName == "AREA") return true;
return this.isLink(node.parentNode);
]]>
</body>
</method>
<method name="showAutoscrollMarker">
<parameter name="evt"/>
<body>
<![CDATA[
function scrollCursorType(neededW, availW, neededH, availH, scrollBarSize) {
if (neededW <= availW && neededH <= availH) return 3;
if (neededW > availW && neededH > availH) return 0;
if (neededW > availW) return ((neededH <= (availH - scrollBarSize)) - 0) << 1; // 0 or 2
return (neededW <= (availW - scrollBarSize)) - 0;
}
var initialNode = evt.originalTarget;
var targetDoc = initialNode.ownerDocument;
var docEl = targetDoc.documentElement;
var insertionNode = (docEl) ? docEl : targetDoc;
var docBox = targetDoc.getBoxObjectFor(insertionNode);
this._scrollObj = {scrollType: 3, isXML: false, nodeToScroll: null, clientFrame: null};
var nextNode = initialNode, currNode;
if (docEl && docEl.nodeName.toLowerCase() == "html") { // walk the tree up looking for something to scroll
do
try {
currNode = nextNode;
nextNode = currNode.parentNode;
if (currNode.clientWidth && currNode.clientHeight) {
this._scrollObj.scrollType = scrollCursorType(currNode.scrollWidth, currNode.clientWidth,
currNode.scrollHeight, currNode.clientHeight, 0);
if (this._scrollObj.scrollType != 3) break;
}
}
catch(err) {}
while (currNode && currNode != docEl);
this._scrollObj.nodeToScroll = currNode;
}
else { // XML document; do our best
this._scrollObj.clientFrame = initialNode.ownerDocument.defaultView;
var renderingArea = document.getElementById("content").mPanelContainer;
if (docBox) this._scrollObj.scrollType = scrollCursorType(docBox.width, renderingArea.boxObject.width, docBox.height, renderingArea.boxObject.height, 16);
this._scrollObj.isXML = true;
}
if (this._scrollObj.scrollType == 3) { // nothing to scroll
this._scrollingFingerFree = true; // exit on next mouse up
return 2;
}
const scrollCursor = ["move", "n-resize", "e-resize"];
const scrollImages = ["chrome://global/content/widgets/autoscroll_all.png",
"chrome://global/content/widgets/autoscroll_v.png",
"chrome://global/content/widgets/autoscroll_h.png"];
const imageWidth = 28;
const imageHeight = 28;
// marker
var el = targetDoc.createElementNS("http://www.w3.org/1999/xhtml", "img");
el.src = scrollImages[this._scrollObj.scrollType];
el.style.position = "fixed";
el.style.left = evt.screenX - docBox.screenX - imageWidth / 2 + "px";
el.style.top = evt.screenY - docBox.screenY - imageHeight / 2 + "px";
el.style.width = imageWidth + "px";
el.style.height = imageHeight + "px";
el.style.border = "0px";
el.style.zIndex = 10000;
el.style.cursor = scrollCursor[this._scrollObj.scrollType];
insertionNode.appendChild(el);
this._autoScrollMarkerImage = el;
return this._scrollObj.isXML - 0;
]]>
</body>
</method>
2003-07-06 09:23:05 +04:00
#endif
2002-09-28 10:25:03 +04:00
</implementation>
<handlers>
<handler event="keypress" keycode="VK_F7">
<![CDATA[
// Toggle browse with caret mode
var browseWithCaretOn = false;
var warn = true;
try {
warn = this.mPrefs.getBoolPref("accessibility.warn_on_browsewithcaret");
} catch (ex) {
}
try {
browseWithCaretOn = this.mPrefs.getBoolPref("accessibility.browsewithcaret");
} catch (ex) {
}
if (warn && !browseWithCaretOn) {
var checkValue = {value:false};
promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
var buttonPressed = promptService.confirmEx(window,
this.mStrBundle.GetStringFromName('browsewithcaret.checkWindowTitle'),
this.mStrBundle.GetStringFromName('browsewithcaret.checkLabel'),
(promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
null, null, null, this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'),
2002-09-28 10:25:03 +04:00
checkValue);
if (buttonPressed != 0)
return;
if (checkValue.value) {
try {
this.mPrefs.setBoolPref("accessibility.warn_on_browsewithcaret", false);
}
catch (ex) {
}
}
}
// Toggle the pref
try {
this.mPrefs.setBoolPref("accessibility.browsewithcaret",!browseWithCaretOn);
} catch (ex) {
}
]]>
</handler>
2003-07-06 09:23:05 +04:00
#ifdef XP_WIN
<handler event="mouseup">
<![CDATA[
if (!this._isScrolling) return;
event.preventDefault(); event.stopPropagation();
if (this._scrollingFingerFree || (event.timeStamp - this._startTime) > 500) {
if (this._scrollInterval) window.clearInterval(this._scrollInterval);
this._scrollInterval = null;
this._isScrolling = false;
if (this._autoScrollMarkerImage) {
this._autoScrollMarkerImage.style.display = 'none'; // seems to avoid blocking when autoscroll is initited during pageload
this._autoScrollMarkerImage.parentNode.removeChild(this._autoScrollMarkerImage);
}
this._autoScrollMarkerImage = null;
}
else this._scrollingFingerFree = true;
]]>
</handler>
2003-07-06 05:02:48 +04:00
<handler event="mousedown">
<![CDATA[
2003-07-24 15:21:07 +04:00
if (this.getAttribute("autoscroll") != "false" && !this._isScrolling && event.button == 1 && !this.isLink(event.originalTarget)) {
this._startX = event.clientX; this._startY = event.clientY;
this._distanceX = 0; this._distanceY = 0;
this._scrollingFingerFree = false;
this._startTime = event.timeStamp;
event.preventDefault(); event.stopPropagation();
switch (this.showAutoscrollMarker(event)) {
case 0: this._scrollInterval = window.setInterval(function foo(a) {a.autoScrollLoop2()}, this._scrollPeriod, this);
this._isScrolling = true;
break;
case 1: this._scrollInterval = window.setInterval(function foo(a) {a.autoScrollLoop1()}, this._scrollPeriod, this);
this._isScrolling = true;
break;
case 2: ;
2003-07-06 05:02:48 +04:00
}
}
]]>
</handler>
<handler event="mousemove">
<![CDATA[
function logDistance(aDist) {
const dist = [0, 20, 40, 60, 80, 100, 130, 180, 300, 5000];
const ratio = [0, .067, .083, .108, .145, .2, .3, .45, .65, .9];
const sofar = [0, 0, 1.34, 3, 5.16, 8.06, 12.06, 21.06, 43.56, 121.56];
var absDistance = Math.abs(aDist);
for (var i = 1; i < dist.length; ++i)
if (absDistance < dist[i]) {
absDistance = Math.round(sofar[i] + (absDistance - dist[i-1]) * ratio[i]);
break;
}
return (aDist < 0) ? -absDistance : absDistance;
}
if (this._isScrolling) {
var dX = event.clientX - this._startX;
var dY = event.clientY - this._startY;
this._distanceX = 0; this._distanceY = 0;
switch (this._scrollObj.scrollType) {
case 0: if (Math.abs(dX) > Math.abs(dY)) this._distanceX = logDistance(dX); // diagonal scrolling is jerky; never do it
else this._distanceY = logDistance(dY);
break;
case 1: this._distanceY = logDistance(dY);
break;
case 2: this._distanceX = logDistance(dX);
break;
case 3: ;
}
}
]]>
</handler>
2003-07-06 09:23:05 +04:00
#endif
2002-09-28 10:25:03 +04:00
</handlers>
</binding>
</bindings>