2006-07-29 05:33:12 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
|
|
|
*
|
|
|
|
* 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 Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
*
|
|
|
|
* Alec Flett <alecf@netscape.com>
|
|
|
|
* Ben Goodger <ben@netscape.com>
|
|
|
|
* Mike Pinkerton <pinkerton@netscape.com>
|
|
|
|
* Blake Ross <blakeross@telocity.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
var pref = null;
|
|
|
|
pref = Components.classes["@mozilla.org/preferences;1"];
|
|
|
|
pref = pref.getService();
|
|
|
|
pref = pref.QueryInterface(Components.interfaces.nsIPref);
|
2006-07-29 05:33:19 +00:00
|
|
|
|
|
|
|
// Prefill a single text field
|
|
|
|
function prefillTextField(target) {
|
|
|
|
|
|
|
|
// obtain values to be used for prefilling
|
|
|
|
var walletService = Components.classes["@mozilla.org/wallet/wallet-service;1"].getService(Components.interfaces.nsIWalletService);
|
|
|
|
var value = walletService.WALLET_PrefillOneElement(window._content, target);
|
|
|
|
if (value) {
|
|
|
|
|
|
|
|
// result is a linear sequence of values, each preceded by a separator character
|
|
|
|
// convert linear sequence of values into an array of values
|
|
|
|
var separator = value[0];
|
|
|
|
var valueList = value.substring(1, value.length).split(separator);
|
|
|
|
|
|
|
|
target.value = valueList[0];
|
|
|
|
/*
|
|
|
|
* Following code is a replacement for above line. In the case of multiple values, it
|
|
|
|
* presents the user with a dialog containing a list from which he can select the value
|
|
|
|
* he wants. However it is being commented out for now because of several problems, namely
|
|
|
|
*
|
|
|
|
* 1. There is no easy way to put localizable strings for the title and message of
|
|
|
|
* the dialog without introducing a .properties file which currently doesn't exist
|
|
|
|
* 2. Using blank title and messages as shown below have a problem because a zero-length
|
|
|
|
* title is being displayed as some garbage characters (which is why the code below
|
|
|
|
* has a title of " " instead of ""). This is a separate bug which will have to be
|
|
|
|
* investigated further.
|
|
|
|
* 3. The current wallet tables present alternate values for items such as shipping
|
|
|
|
* address -- namely billing address and home address. Up until now, these alternate
|
|
|
|
* values have never been a problem because the preferred value is always first and is
|
|
|
|
* all the user sees when doing a prefill. However now he will be presented with a
|
|
|
|
* list showing all these values and asking him to pick one, even though the wallet
|
|
|
|
* code was clearly able to determine that he meant shipping address and not billing
|
|
|
|
* address.
|
|
|
|
* 4. There is a relatively long delay before the dialog come up whereas values are
|
|
|
|
* filled in quickly when no dialog is involved.
|
|
|
|
*
|
|
|
|
* Once this feature is checked in, a separate bug will be opened asking that the above
|
|
|
|
* problems be examined and this dialog turned on
|
|
|
|
|
|
|
|
if (valueList.length == 1) {
|
|
|
|
// only one value, use it for prefilling
|
|
|
|
target.value = valueList[0];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// more than one value, have user select the one he wants
|
|
|
|
var commonDialogService =
|
|
|
|
Components.classes["@mozilla.org/appshell/commonDialogs;1"].getService();
|
|
|
|
commonDialogService =
|
|
|
|
commonDialogService.QueryInterface(Components.interfaces.nsICommonDialogs);
|
|
|
|
var position = {};
|
|
|
|
var title = " ";
|
|
|
|
var message = "";
|
|
|
|
var ok =
|
|
|
|
commonDialogService.Select
|
|
|
|
(window, title, message, valueList.length, valueList, position)
|
|
|
|
if (ok) {
|
|
|
|
target.value = valueList[position.value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
* End of commented out code
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2006-07-29 05:33:12 +00:00
|
|
|
|
|
|
|
// Called whenever the user clicks in the content area,
|
|
|
|
// except when left-clicking on links (special case)
|
|
|
|
// should always return true for click to go through
|
|
|
|
function contentAreaClick(event)
|
|
|
|
{
|
2006-07-29 05:33:19 +00:00
|
|
|
var target = event.target;
|
2006-07-29 05:33:12 +00:00
|
|
|
var linkNode;
|
|
|
|
switch (target.localName.toLowerCase()) {
|
|
|
|
case "a":
|
2006-07-29 05:33:19 +00:00
|
|
|
linkNode = target;
|
2006-07-29 05:33:12 +00:00
|
|
|
break;
|
|
|
|
case "area":
|
2006-07-29 05:33:19 +00:00
|
|
|
if (target.href)
|
|
|
|
linkNode = target;
|
|
|
|
break;
|
|
|
|
case "input":
|
|
|
|
if ((event.target.type.toLowerCase() == "text" || event.target.type == "") // text field
|
2006-07-29 05:35:46 +00:00
|
|
|
&& event.detail == 2 // double click
|
|
|
|
&& event.button == 0 // left mouse button
|
2006-07-29 05:33:19 +00:00
|
|
|
&& event.target.value.length == 0) { // no text has been entered
|
|
|
|
prefillTextField(target); // prefill the empty text field if possible
|
|
|
|
}
|
2006-07-29 05:33:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
2006-07-29 05:33:19 +00:00
|
|
|
linkNode = findParentNode(event.originalTarget, "a");
|
2006-07-29 05:33:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (linkNode) {
|
|
|
|
handleLinkClick(event, linkNode.href);
|
|
|
|
return true;
|
|
|
|
}
|
2006-07-29 05:35:47 +00:00
|
|
|
if (pref && event.button == 1 &&
|
2006-07-29 05:33:19 +00:00
|
|
|
!findParentNode(event.originalTarget, "scrollbar") &&
|
2006-07-29 05:34:51 +00:00
|
|
|
pref.GetBoolPref("middlemouse.contentLoadURL")) {
|
2006-07-29 05:33:19 +00:00
|
|
|
if (middleMousePaste()) {
|
|
|
|
event.preventBubble();
|
|
|
|
}
|
2006-07-29 05:33:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleLinkClick(event, href)
|
|
|
|
{
|
|
|
|
switch (event.button) {
|
2006-07-29 05:35:46 +00:00
|
|
|
case 0: // if left button clicked
|
2006-07-29 05:33:12 +00:00
|
|
|
if (event.metaKey || event.ctrlKey) { // and meta or ctrl are down
|
|
|
|
openNewWindowWith(href); // open link in new window
|
|
|
|
event.preventBubble();
|
|
|
|
return true;
|
|
|
|
}
|
2006-07-29 05:35:48 +00:00
|
|
|
var saveModifier = true;
|
|
|
|
if (pref) {
|
|
|
|
try {
|
|
|
|
saveModifier = pref.GetBoolPref("ui.key.saveLink.shift");
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
saveModifier = saveModifier ? event.shiftKey : event.metaKey;
|
|
|
|
|
|
|
|
if (saveModifier) { // if saveModifier is down
|
2006-07-29 05:33:12 +00:00
|
|
|
savePage(href); // save the link
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (event.altKey) // if alt is down
|
|
|
|
return true; // do nothing
|
|
|
|
return false;
|
2006-07-29 05:35:46 +00:00
|
|
|
case 1: // if middle button clicked
|
2006-07-29 05:33:12 +00:00
|
|
|
if (pref && pref.GetBoolPref("middlemouse.openNewWindow")) { // and the pref is on
|
|
|
|
openNewWindowWith(href); // open link in new window
|
|
|
|
event.preventBubble();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-07-29 05:33:19 +00:00
|
|
|
function middleMousePaste()
|
2006-07-29 05:33:12 +00:00
|
|
|
{
|
2006-07-29 05:34:50 +00:00
|
|
|
var url = readFromClipboard();
|
|
|
|
if (url) {
|
2006-07-29 05:35:45 +00:00
|
|
|
loadURI(getShortcutOrURI(url));
|
2006-07-29 05:34:50 +00:00
|
|
|
return true;
|
2006-07-29 05:33:12 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|