Bug 261790 port various changes betwen xpfe/toolkit

r=mconnor sr=neil
This commit is contained in:
cbiesinger%web.de 2004-09-30 14:31:42 +00:00
Родитель 9dcc5e779c
Коммит d33896aeeb
31 изменённых файлов: 104 добавлений и 444 удалений

Просмотреть файл

@ -1 +1,2 @@
Makefile
buildconfig.html

Просмотреть файл

@ -80,7 +80,7 @@ function SelectDetector(event, doReload)
str.data = prefvalue;
pref.setComplexValue("intl.charset.detector",
Components.interfaces.nsISupportsString, str);
if (doReload) window._content.location.reload();
if (doReload) window.content.location.reload();
}
catch (ex) {
dump("Failed to set the intl.charset.detector preference.\n");
@ -130,7 +130,7 @@ function UpdateCurrentCharset()
// exctract the charset from DOM
var wnd = document.commandDispatcher.focusedWindow;
if ((window == wnd) || (wnd == null)) wnd = window._content;
if ((window == wnd) || (wnd == null)) wnd = window.content;
menuitem = document.getElementById('charset.' + wnd.document.characterSet);
if (menuitem) {
@ -215,7 +215,7 @@ var gLastBrowserCharset = null;
function charsetLoadListener (event)
{
var charset = window._content.document.characterSet;
var charset = window.content.document.characterSet;
if (charset.length > 0 && (charset != gLastBrowserCharset)) {
gCharsetMenu.SetCurrentCharset(charset);
@ -227,7 +227,7 @@ function charsetLoadListener (event)
function composercharsetLoadListener (event)
{
var charset = window._content.document.characterSet;
var charset = window.content.document.characterSet;
if (charset.length > 0 ) {

Просмотреть файл

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!DOCTYPE window SYSTEM "chrome://global/locale/charsetOverlay.dtd">
<!DOCTYPE overlay SYSTEM "chrome://global/locale/charsetOverlay.dtd">
<overlay id="charsetOverlay"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@ -144,7 +144,7 @@
<menupopup>
</menupopup>
</menu>
<menu label="&charsetMenuMore.label;" accesskey="&charsetMenuMore.accesskey;" datasources="rdf:charset-menu" ref="NC:BrowserMoreCharsetMenuRoot">
<menu label="&charsetMenuMore.label;" accesskey="&charsetMenuMore.accesskey;" datasources="rdf:charset-menu" ref="NC:BrowserMoreCharsetMenuRoot">
<template>
<rule>
<menupopup>

Просмотреть файл

@ -49,8 +49,6 @@
</vbox>
</hbox>
<separator class="thin"/>
<!-- This method is called inline because it may unset hidden="true" on the
above boxes, causing their frames to be build and bindings to load.
So, by calling this inline, we guarantee the textboxes and checkboxes

Просмотреть файл

@ -61,7 +61,7 @@ function goQuitApplication()
{
var domWindow = enumerator.getNext();
if (("tryToClose" in domWindow) && !domWindow.tryToClose())
return false;
return false;
domWindow.close();
};
appShell.quit(Components.interfaces.nsIAppShellService.eAttemptQuit);
@ -96,8 +96,7 @@ function goDoCommand(command)
controller.doCommand(command);
}
catch (e) {
dump("An error occurred executing the "+command+" command\n");
dump(e+"\n")
dump("An error occurred executing the " + command + " command\n" + e + "\n");
}
}

Просмотреть файл

@ -80,7 +80,7 @@ var nsTransferable = {
{
// non-string data.
supports = currData.supports;
length = 0; // kFlavorHasDataProvider
length = 0; // kFlavorHasDataProvider
}
trans.setTransferData(currFlavour, supports, length * 2);
}

Просмотреть файл

@ -411,7 +411,7 @@
<field name="securityUI">
null
</field>
<field name="userTypedClear">
true
</field>
@ -434,7 +434,7 @@
<field name="focusedElement">
null
</field>
</field>
<constructor>
<![CDATA[

Просмотреть файл

@ -472,20 +472,6 @@
]]></body>
</method>
<method name="getElementByanonid">
<parameter name="aValue"/>
<body><![CDATA[
var nodes = document.getAnonymousNodes(this);
var results;
for (var i = 0; i < nodes.length; i++) {
results = nodes[i].getElementsByAttribute("anonid", aValue);
if (results.item(0))
return results[0];
}
return null;
]]></body>
</method>
<method name="showPopup">
<body><![CDATA[
this.mPicker.parentNode.showPopup(this, -1, -1, "popup", "bottomleft", "topleft");

Просмотреть файл

@ -215,7 +215,6 @@
for (dlgtype in buttons) {
var button = buttons[dlgtype];
button.addEventListener("command", this._handleButtonCommand, true);
// don't override custom labels with pre-defined labels on explicit buttons
if (!button.hasAttribute("label")) {

Просмотреть файл

@ -74,10 +74,10 @@
onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebBrowserFind);"/>
<property name="editingSession"
readonly="true"
onget="return this.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIEditingSession);"/>"
onget="return this.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIEditingSession);"/>
<property name="commandManager"
readonly="true"
onget="return this.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsICommandManager);"/>"
onget="return this.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsICommandManager);"/>
</implementation>
</binding>

Просмотреть файл

@ -306,10 +306,7 @@
if (popup)
arr = popup.getElementsByAttribute('label', this.inputField.value);
if (arr && arr.item(0))
this.setSelectionInternal(arr[0]);
else
this.setSelectionInternal(null);
this.setSelectionInternal(arr ? arr.item(0) : null);
]]>
</body>
</method>

Просмотреть файл

@ -33,7 +33,7 @@
return this.stringBundle.formatStringFromName(aStringKey, aStringsArray, aStringsArray.length);
}
catch (e) {
dump("*** Failed to get string " + aStringKey + " in bundle: " + this.src + "\n");
dump("*** Failed to format string " + aStringKey + " in bundle: " + this.src + "\n");
throw e;
}
]]>

Просмотреть файл

@ -192,7 +192,7 @@
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
const nsIChannel = Components.interfaces.nsIChannel;
if (aStateFlags & nsIWebProgressListener.STATE_START &&
if (aStateFlags & nsIWebProgressListener.STATE_START &&
aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
// It's okay to clear what the user typed when we start
// loading a document. If the user types, this flag gets
@ -205,7 +205,7 @@
if (!this.mBlank) {
this.mTab.setAttribute("busy", "true");
this.mTab.label = this.mTabBrowser.mStringBundle.getString("tabs.loading");
this.mTab.removeAttribute("image");
this.mTab.removeAttribute("image");
this.mIcon = "";
if (this.mTabBrowser.mCurrentTab == this.mTab)
@ -227,7 +227,7 @@
var location = aRequest.QueryInterface(nsIChannel).URI;
if (this.mIcon) {
this.mTab.setAttribute("image", this.mIcon);
mIcon = "";
this.mIcon = "";
}
else if (this.mTabBrowser.shouldLoadFavIcon(location))
this.mTabBrowser.loadFavIcon(location, "image", this.mTab);
@ -246,10 +246,10 @@
p.onStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
}
}
}
,
},
onLocationChange : function(aWebProgress, aRequest, aLocation) {
onLocationChange : function(aWebProgress, aRequest, aLocation)
{
// The document loaded correctly, clear the value if we should
if (this.mBrowser.userTypedClear)
this.mBrowser.userTypedValue = null;
@ -263,7 +263,8 @@
}
},
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) {
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
{
if (this.mBlank)
return;
@ -295,8 +296,7 @@
return this;
throw Components.results.NS_NOINTERFACE;
}
});
});
]]>
</body>
</method>
@ -316,7 +316,7 @@
<body>
<![CDATA[
return (aURI && this.mPrefs.getBoolPref("browser.chrome.site_icons") &&
this.mPrefs.getBoolPref("browser.chrome.favicons") &&
this.mPrefs.getBoolPref("browser.chrome.favicons") &&
("schemeIs" in aURI) && (aURI.schemeIs("http") || aURI.schemeIs("https")));
]]>
</body>
@ -484,7 +484,7 @@
// Update the window title.
this.updateTitlebar();
// If the new tab is busy, and our current state is not busy, then
// we need to fire a start to all progress listeners.
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
@ -769,7 +769,9 @@
}
// Wire up a progress listener to our filter.
const listener = this.mTabProgressListener(this.mCurrentTab, this.mCurrentBrowser, false);
const listener = this.mTabProgressListener(this.mCurrentTab,
this.mCurrentBrowser,
false);
filter.addProgressListener(listener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
this.mTabListeners[0] = listener;
]]>
@ -783,16 +785,14 @@
<parameter name="aPostData"/>
<body>
<![CDATA[
var blank = (aURI == "about:blank");
if (!this.mTabbedMode)
this.enterTabbedMode();
var b = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"browser");
var t = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"tab");
var blank = (aURI == "about:blank");
if (blank)
t.setAttribute("label", this.mStringBundle.getString("tabs.untitled"));
else
@ -807,6 +807,8 @@
t.setAttribute("onerror", "this.parentNode.parentNode.parentNode.parentNode.addToMissedIconCache(this.getAttribute('image')); this.removeAttribute('image');");
this.mTabContainer.appendChild(t);
var b = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"browser");
b.setAttribute("type", "content");
b.setAttribute("contextmenu", this.getAttribute("contentcontextmenu"));
b.setAttribute("tooltip", this.getAttribute("contenttooltip"));

Просмотреть файл

@ -30,7 +30,7 @@
<property name="view"
onget="return this.treeBoxObject.view;"
onset="return this.treeBoxObject.view=val;"/>
onset="return this.treeBoxObject.view = val;"/>
<property name="body"
onget="return this.treeBoxObject.treeBody;"/>
@ -57,7 +57,7 @@
<property name="currentIndex"
onget="return this.treeBoxObject.view.selection.currentIndex;"
onset="return this.treeBoxObject.view.selection.currentIndex=val;"/>
onset="return this.treeBoxObject.view.selection.currentIndex = val;"/>
<!-- ///////////////// nsIAccessibleProvider ///////////////// -->
@ -802,16 +802,17 @@
var tree = col.parentNode.parentNode;
var sib;
var column;
if (col.mTargetCol) {
// remove previous insertbefore/after attributes
col.mTargetCol.removeAttribute("insertbefore");
col.mTargetCol.removeAttribute("insertafter");
var column = tree.columns.getColumnFor(col.mTargetCol);
column = tree.columns.getColumnFor(col.mTargetCol);
tree.treeBoxObject.invalidateColumn(column);
sib = col.mTargetCol._previousVisibleColumn;
if (sib) {
sib.removeAttribute("insertafter");
var column = tree.columns.getColumnFor(sib);
column = tree.columns.getColumnFor(sib);
tree.treeBoxObject.invalidateColumn(column);
}
col.mTargetCol = null;
@ -827,11 +828,11 @@
sib = targetCol._previousVisibleColumn;
if (sib) {
sib.setAttribute("insertafter", "true");
var column = tree.columns.getColumnFor(sib);
column = tree.columns.getColumnFor(sib);
tree.treeBoxObject.invalidateColumn(column);
}
}
var column = tree.columns.getColumnFor(targetCol);
column = tree.columns.getColumnFor(targetCol);
tree.treeBoxObject.invalidateColumn(column);
col.mTargetCol = targetCol;
col.mTargetDir = pos.value;

Просмотреть файл

@ -15,19 +15,18 @@
display: -moz-box;
}
/* hide the content, but don't destroy the frames. Make sure this
comes before any rules involving "hidden" */
*[collapsed="true"], *[moz-collapsed="true"] {
visibility: collapse;
}
/* The rule for hidden comes AFTER the rule for collapsed. That way if
both are specified on an element, the hidden rule wins. */
/* hide the content and destroy the frame */
*[hidden="true"] {
display: none;
}
/* hide the content, but don't destroy the frames */
*[collapsed="true"],
*[moz-collapsed="true"] {
visibility: collapse;
}
/* ::::::::::
:: Rules for 'hiding' portions of the chrome for special
:: kinds of windows (not JUST browser windows) with toolbars
@ -471,10 +470,6 @@ listbox {
height: 200px;
}
listhead, listrows, listboxbody {
-moz-user-focus: none;
}
listhead {
-moz-box-orient: vertical;
}
@ -522,7 +517,6 @@ treecol.treecol-image {
tree > treechildren {
display: -moz-box;
-moz-binding: url("chrome://global/content/bindings/tree.xml#treebody");
-moz-user-focus: none;
-moz-user-select: none;
-moz-box-flex: 1;
}
@ -782,14 +776,14 @@ menulist {
-moz-binding: url("chrome://global/content/bindings/menulist.xml#menulist");
}
menulist[type="description"] {
-moz-binding: url("chrome://global/content/bindings/menulist.xml#menulist-description");
}
menulist[editable] {
-moz-binding: url("chrome://global/content/bindings/menulist.xml#menulist-editable");
}
menulist[type="description"] {
-moz-binding: url("chrome://global/content/bindings/menulist.xml#menulist-description");
}
html|*.menulist-editable-input {
-moz-appearance: none !important;
}
@ -842,6 +836,7 @@ scrollbar[value="hidden"] {
scrollbox {
-moz-binding: url("chrome://global/content/bindings/scrollbox.xml#scrollbox");
/* This makes it scrollable! */
overflow:hidden ! important;
}

Просмотреть файл

@ -97,7 +97,7 @@ function nsTreeController_copy()
if (isContainer(this.tree, k))
continue;
var col = this.tree.columns["URL"];
var pageUrl = this.treeView.getCellText(k, col);
var pageUrl = this.treeView.getCellText(k, col);
col = this.tree.columns["Name"];
var pageName = this.treeView.getCellText(k, col);

Просмотреть файл

@ -317,6 +317,10 @@
null
</field>
<property name="userTypedValue"
onget="return this._userTypedValue;"
onset="this.userTypedClear = 0; return this._userTypedValue = val;"/>
<field name="focusedWindow">
null
</field>
@ -325,10 +329,6 @@
null
</field>
<property name="userTypedValue"
onget="return this._userTypedValue;"
onset="this.userTypedClear = 0; return this._userTypedValue = val;"/>
<constructor>
<![CDATA[
try {
@ -394,10 +394,9 @@
var buttonPressed = promptService.confirmEx(window,
this.mStrBundle.GetStringFromName('browsewithcaret.checkWindowTitle'),
this.mStrBundle.GetStringFromName('browsewithcaret.checkLabel'),
(promptService.BUTTON_TITLE_OK * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
null, null, null,
this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'),
(promptService.BUTTON_TITLE_YES * promptService.BUTTON_POS_0) +
(promptService.BUTTON_TITLE_NO * promptService.BUTTON_POS_1),
null, null, null, this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'),
checkValue);
if (buttonPressed != 0)
return;

Просмотреть файл

@ -196,7 +196,8 @@
// add the label and oncommand handler to each button
for (dlgtype in buttons) {
var button = buttons[dlgtype];
buttons[dlgtype].addEventListener("command", this._handleButtonCommand, true);
button.addEventListener("command", this._handleButtonCommand, true);
// don't override custom labels with pre-defined labels on explicit buttons
if (!button.hasAttribute("label")) {
button.setAttribute("label", this.mStrBundle.GetStringFromName("button-"+dlgtype));
@ -206,15 +207,15 @@
}
}
}
// ensure that hitting enter triggers ondialogaccept
buttons["accept"].setAttribute("default", "true");
// if there is a special button configuration, use it
if (aButtons) {
// expect a comma delimitd list of dlgtype values
// expect a comma delimited list of dlgtype values
var list = aButtons.split(",");
// mark shown dlgtypes as true
var shown = { accept: false, cancel: false, help: false,
disclosure: false, extra1: false, extra2: false };
@ -222,12 +223,9 @@
shown[list[i].replace(/ /g, "")] = true;
// hide/show the buttons we want
for (dlgtype in shown) {
if (shown[dlgtype])
buttons[dlgtype].hidden = false;
else
buttons[dlgtype].hidden = true;
}
for (dlgtype in buttons)
buttons[dlgtype].hidden = !shown[dlgtype];
}
]]>
</body>

Просмотреть файл

@ -13,7 +13,13 @@
<parameter name="aStringKey"/>
<body>
<![CDATA[
return this.stringBundle.GetStringFromName(aStringKey);
try {
return this.stringBundle.GetStringFromName(aStringKey);
}
catch (e) {
dump("*** Failed to get string " + aStringKey + " in bundle: " + this.src + "\n");
throw e;
}
]]>
</body>
</method>
@ -23,7 +29,13 @@
<parameter name="aStringsArray"/>
<body>
<![CDATA[
return this.stringBundle.formatStringFromName(aStringKey, aStringsArray, aStringsArray.length);
try {
return this.stringBundle.formatStringFromName(aStringKey, aStringsArray, aStringsArray.length);
}
catch (e) {
dump("*** Failed to format string " + aStringKey + " in bundle: " + this.src + "\n");
throw e;
}
]]>
</body>
</method>

Просмотреть файл

@ -629,10 +629,11 @@
if (!href)
return;
const nsIContentPolicy = Components.interfaces.nsIContentPolicy;
try {
var contentPolicy =
Components.classes['@mozilla.org/layout/content-policy;1']
.getService(Components.interfaces.nsIContentPolicy);
.getService(nsIContentPolicy);
} catch(e) {
return; // Refuse to load if we can't do a security check.
}
@ -673,10 +674,10 @@
// We need to update a tab.
for (i = 0; i < this.browsers.length; i++) {
if (this.browsers[i].contentDocument == event.originalTarget.ownerDocument) {
if (contentPolicy.shouldLoad(Components.interfaces.nsIContentPolicy.TYPE_IMAGE,
if (contentPolicy.shouldLoad(nsIContentPolicy.TYPE_IMAGE,
uri, origURI, event.target,
safeGetProperty(event.target, "type"),
null) != Components.interfaces.nsIContentPolicy.ACCEPT)
null) != nsIContentPolicy.ACCEPT)
return;
this.mTabListeners[i].mIcon = href;
@ -686,10 +687,10 @@
}
}
else if ((this.contentDocument != event.originalTarget.ownerDocument) ||
(contentPolicy.shouldLoad(Components.interfaces.nsIContentPolicy.TYPE_IMAGE,
(contentPolicy.shouldLoad(nsIContentPolicy.TYPE_IMAGE,
uri, origURI, event.target,
safeGetProperty(event.target, "type"),
null) != Components.interfaces.nsIContentPolicy.ACCEPT))
null) != nsIContentPolicy.ACCEPT))
return;
if (notifyListeners && this.mProgressListeners) {

Просмотреть файл

@ -59,7 +59,7 @@
if (val) this.setAttribute('readonly', 'true');
else this.removeAttribute('readonly'); return val;"
onget="return this.inputField.readonly;"/>
<method name="select">
<body>
this.inputField.select();

Просмотреть файл

@ -248,7 +248,7 @@
]]>
</handler>
<handler event="focus" action="this.treeBoxObject.focused = true;"/>
<handler event="blur" action="this.treeBoxObject.focused = false;"/>
<handler event="blur" action="this.treeBoxObject.focused = false;"/>
<handler event="keypress" keycode="vk_enter" action="this.changeOpenState(this.currentIndex);"/>
<handler event="keypress" keycode="vk_return" action="this.changeOpenState(this.currentIndex);"/>
<handler event="keypress" keycode="vk_left">

Просмотреть файл

@ -208,9 +208,9 @@ function UpdateMenus(event)
// when onmenucomplete is ready then use it instead of oncreate
// see bug 78290 for the detail
UpdateCurrentCharset();
setTimeout("UpdateCurrentCharset()", 0);
setTimeout(UpdateCurrentCharset, 0);
UpdateCharsetDetector();
setTimeout("UpdateCharsetDetector()", 0);
setTimeout(UpdateCharsetDetector, 0);
}
function CreateMenu(node)
@ -225,9 +225,9 @@ function UpdateMailMenus(event)
// when onmenucomplete is ready then use it instead of oncreate
// see bug 78290 for the detail
UpdateCurrentMailCharset();
setTimeout("UpdateCurrentMailCharset()", 0);
setTimeout(UpdateCurrentMailCharset, 0);
UpdateCharsetDetector();
setTimeout("UpdateCharsetDetector()", 0);
setTimeout(UpdateCharsetDetector, 0);
}
var gCharsetMenu = Components.classes['@mozilla.org/rdf/datasource;1?name=charset-menu'].getService().QueryInterface(Components.interfaces.nsICurrentCharsetListener);

Просмотреть файл

@ -208,9 +208,9 @@ function commonDialogOnLoad()
function commonDialogReenableButtons()
{
document.documentElement.getButton("accept").disabled = false;
document.documentElement.getButton("extra1").disabled = false;
document.documentElement.getButton("extra2").disabled = false;
document.documentElement.getButton("accept").disabled = false;
document.documentElement.getButton("extra1").disabled = false;
document.documentElement.getButton("extra2").disabled = false;
}
function initTextbox(aName, aLabelIndex, aValueIndex, aAlwaysLabel)

Просмотреть файл

@ -106,7 +106,7 @@ var view = {
isContainerOpen : function(index) { return false; },
isContainerEmpty : function(index) { return false; },
isSorted : function() { return true; },
canDrop : function(index, orienation) { return false; },
canDrop : function(index, orientation) { return false; },
drop : function(row, orientation) {},
setTree : function(out) { this.treebox = out; },
getParentIndex: function(rowIndex) { return -1; },

Просмотреть файл

@ -105,4 +105,3 @@
<treechildren id="configTreeBody" ondblclick="if (event.button == 0) ModifySelected();"/>
</tree>
</window>

Просмотреть файл

@ -5,8 +5,8 @@
<!DOCTYPE overlay SYSTEM "chrome://global/locale/dialogOverlay.dtd">
<overlay id="dialogOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://global/content/dialogOverlay.js"/>
<script type="application/x-javascript" src="chrome://global/content/dialogOverlay.js"/>
</overlay>

Просмотреть файл

@ -39,7 +39,7 @@
-
- ***** END LICENSE BLOCK ***** -->
<?xml-stylesheet href="chrome://communicator/skin" type="text/css"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://global/locale/fontpackage.dtd">
<dialog title="&window.title;"

Просмотреть файл

@ -69,7 +69,7 @@ function goDoCommand(command)
controller.doCommand(command);
}
catch (e) {
dump("An error occurred executing the "+command+" command\n");
dump("An error occurred executing the " + command + " command\n" + e + "\n");
}
}

Просмотреть файл

@ -1,326 +0,0 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
////////////////////////////////////////////////////////////////////////////
// XXX - WARNING - DRAG AND DROP API CHANGE ALERT - XXX
// This file has been extensively modified in a checkin planned for Mozilla
// 0.8, and the API has been modified. DO NOT MODIFY THIS FILE without
// approval from ben@netscape.com, otherwise your changes will be lost.
/**
* nsTransferable - a wrapper for nsITransferable that simplifies
* javascript clipboard and drag&drop. for use in
* these situations you should use the nsClipboard
* and nsDragAndDrop wrappers for more convenience
**/
var nsTransferable = {
/**
* nsITransferable set (TransferData aTransferData) ;
*
* Creates a transferable with data for a list of supported types ("flavours")
*
* @param TransferData aTransferData
* a javascript object in the format described above
**/
set: function (aTransferDataSet)
{
var trans = this.createTransferable();
for (var i = 0; i < aTransferDataSet.dataList.length; ++i)
{
var currData = aTransferDataSet.dataList[i];
var currFlavour = currData.flavour.contentType;
trans.addDataFlavor(currFlavour);
var supports = null; // nsISupports data
var length = 0;
if (currData.flavour.dataIIDKey == "nsISupportsString")
{
supports = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
supports.data = currData.supports;
length = supports.data.length;
}
else
{
// non-string data.
supports = currData.supports;
length = 0; // kFlavorHasDataProvider
}
trans.setTransferData(currFlavour, supports, length * 2);
}
return trans;
},
/**
* TransferData/TransferDataSet get (FlavourSet aFlavourSet,
* Function aRetrievalFunc, Boolean aAnyFlag) ;
*
* Retrieves data from the transferable provided in aRetrievalFunc, formatted
* for more convenient access.
*
* @param FlavourSet aFlavourSet
* a FlavourSet object that contains a list of supported flavours.
* @param Function aRetrievalFunc
* a reference to a function that returns a nsISupportsArray of nsITransferables
* for each item from the specified source (clipboard/drag&drop etc)
* @param Boolean aAnyFlag
* a flag specifying whether or not a specific flavour is requested. If false,
* data of the type of the first flavour in the flavourlist parameter is returned,
* otherwise the best flavour supported will be returned.
**/
get: function (aFlavourSet, aRetrievalFunc, aAnyFlag)
{
if (!aRetrievalFunc)
throw "No data retrieval handler provided!";
var supportsArray = aRetrievalFunc(aFlavourSet);
var dataArray = [];
var count = supportsArray.Count();
// Iterate over the number of items returned from aRetrievalFunc. For
// clipboard operations, this is 1, for drag and drop (where multiple
// items may have been dragged) this could be >1.
for (var i = 0; i < count; i++)
{
var trans = supportsArray.GetElementAt(i);
if (!trans) continue;
trans = trans.QueryInterface(Components.interfaces.nsITransferable);
var data = { };
var length = { };
var currData = null;
if (aAnyFlag)
{
var flavour = { };
trans.getAnyTransferData(flavour, data, length);
if (data && flavour)
{
var selectedFlavour = aFlavourSet.flavourTable[flavour.value];
if (selectedFlavour)
dataArray[i] = FlavourToXfer(data.value, length.value, selectedFlavour);
}
}
else
{
var firstFlavour = aFlavourSet.flavours[0];
trans.getTransferData(firstFlavour, data, length);
if (data && firstFlavour)
dataArray[i] = FlavourToXfer(data.value, length.value, firstFlavour);
}
}
return new TransferDataSet(dataArray);
},
/**
* nsITransferable createTransferable (void) ;
*
* Creates and returns a transferable object.
**/
createTransferable: function ()
{
const kXferableContractID = "@mozilla.org/widget/transferable;1";
const kXferableIID = Components.interfaces.nsITransferable;
return Components.classes[kXferableContractID].createInstance(kXferableIID);
}
};
/**
* A FlavourSet is a simple type that represents a collection of Flavour objects.
* FlavourSet is constructed from an array of Flavours, and stores this list as
* an array and a hashtable. The rationale for the dual storage is as follows:
*
* Array: Ordering is important when adding data flavours to a transferable.
* Flavours added first are deemed to be 'preferred' by the client.
* Hash: Convenient lookup of flavour data using the content type (MIME type)
* of data as a key.
*/
function FlavourSet(aFlavourList)
{
this.flavours = aFlavourList || [];
this.flavourTable = { };
this._XferID = "FlavourSet";
for (var i = 0; i < this.flavours.length; ++i)
this.flavourTable[this.flavours[i].contentType] = this.flavours[i];
}
FlavourSet.prototype = {
appendFlavour: function (aFlavour, aFlavourIIDKey)
{
var flavour = new Flavour (aFlavour, aFlavourIIDKey);
this.flavours.push(flavour);
this.flavourTable[flavour.contentType] = flavour;
}
};
/**
* A Flavour is a simple type that represents a data type that can be handled.
* It takes a content type (MIME type) which is used when storing data on the
* system clipboard/drag and drop, and an IIDKey (string interface name
* which is used to QI data to an appropriate form. The default interface is
* assumed to be wide-string.
*/
function Flavour(aContentType, aDataIIDKey)
{
this.contentType = aContentType;
this.dataIIDKey = aDataIIDKey || "nsISupportsString";
this._XferID = "Flavour";
}
function TransferDataBase() {}
TransferDataBase.prototype = {
push: function (aItems)
{
this.dataList.push(aItems);
},
get first ()
{
return "dataList" in this && this.dataList.length ? this.dataList[0] : null;
}
};
/**
* TransferDataSet is a list (array) of TransferData objects, which represents
* data dragged from one or more elements.
*/
function TransferDataSet(aTransferDataList)
{
this.dataList = aTransferDataList || [];
this._XferID = "TransferDataSet";
}
TransferDataSet.prototype = TransferDataBase.prototype;
/**
* TransferData is a list (array) of FlavourData for all the applicable content
* types associated with a drag from a single item.
*/
function TransferData(aFlavourDataList)
{
this.dataList = aFlavourDataList || [];
this._XferID = "TransferData";
}
TransferData.prototype = {
__proto__: TransferDataBase.prototype,
addDataForFlavour: function (aFlavourString, aData, aLength, aDataIIDKey)
{
this.dataList.push(new FlavourData(aData, aLength,
new Flavour(aFlavourString, aDataIIDKey)));
}
};
/**
* FlavourData is a type that represents data retrieved from the system
* clipboard or drag and drop. It is constructed internally by the Transferable
* using the raw (nsISupports) data from the clipboard, the length of the data,
* and an object of type Flavour representing the type. Clients implementing
* IDragDropObserver receive an object of this type in their implementation of
* onDrop. They access the 'data' property to retrieve data, which is either data
* QI'ed to a usable form, or unicode string.
*/
function FlavourData(aData, aLength, aFlavour)
{
this.supports = aData;
this.contentLength = aLength;
this.flavour = aFlavour || null;
this._XferID = "FlavourData";
}
FlavourData.prototype = {
get data ()
{
if (this.flavour &&
this.flavour.dataIIDKey != "nsISupportsString" )
return this.supports.QueryInterface(Components.interfaces[this.flavour.dataIIDKey]);
else {
var unicode = this.supports.QueryInterface(Components.interfaces.nsISupportsString);
if (unicode)
return unicode.data.substring(0, this.contentLength/2);
return this.supports;
}
return "";
}
}
/**
* Create a TransferData object with a single FlavourData entry. Used when
* unwrapping data of a specific flavour from the drag service.
*/
function FlavourToXfer(aData, aLength, aFlavour)
{
return new TransferData([new FlavourData(aData, aLength, aFlavour)]);
}
var transferUtils = {
retrieveURLFromData: function (aData, flavour)
{
switch (flavour) {
case "text/unicode":
return aData;
case "text/x-moz-url":
return aData.toString().split("\n")[0];
case "application/x-moz-file":
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var fileHandler = ioService.getProtocolHandler("file")
.QueryInterface(Components.interfaces.nsIFileProtocolHandler);
return fileHandler.getURLSpecFromFile(aData);
}
return null;
}
}
/*
function DUMP_obj (aObj)
{
for (var i in aObj)
dump("*** aObj[" + i + "] = " + aObj[i] + "\n");
}
*/

Просмотреть файл

@ -59,8 +59,7 @@ menulist.uri-element
/****** elements that have no visual representation ******/
script,
data,
script, data,
xbl|children,
commands, commandset, command,
broadcasterset, broadcaster, observes,