зеркало из https://github.com/mozilla/pjs.git
Make nsXULElement::GetChildNodes use the same (live) node list that
nsGenericElement uses. Bug 240633, r+sr=jst on the C++ changes, r=neil, sr=jst on the JS changes.
This commit is contained in:
Родитель
3c4f0316f6
Коммит
4cba32786b
|
@ -1962,7 +1962,7 @@ function createRadioMenuItem( aParent, aIndex, aLabel, aChecked)
|
|||
function deleteHistoryItems(aParent)
|
||||
{
|
||||
var children = aParent.childNodes;
|
||||
for (var i = 0; i < children.length; i++)
|
||||
for (var i = children.length - 1; i >= 0; --i)
|
||||
{
|
||||
var index = children[i].getAttribute("index");
|
||||
if (index)
|
||||
|
|
|
@ -51,7 +51,6 @@ REQUIRES = xpcom \
|
|||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsRDFDOMNodeList.cpp \
|
||||
nsXULElement.cpp \
|
||||
nsXULPopupListener.cpp \
|
||||
$(NULL)
|
||||
|
|
|
@ -112,7 +112,6 @@
|
|||
#include "nsLayoutCID.h"
|
||||
#include "nsContentCID.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsRDFDOMNodeList.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsXULControllers.h"
|
||||
|
@ -125,7 +124,6 @@
|
|||
#include "nsCSSDeclaration.h"
|
||||
#include "nsIListBoxObject.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsGenericElement.h"
|
||||
#include "nsContentList.h"
|
||||
#include "nsMutationEvent.h"
|
||||
#include "nsIDOMMutationEvent.h"
|
||||
|
@ -642,31 +640,17 @@ nsXULElement::GetParentNode(nsIDOMNode** aParentNode)
|
|||
NS_IMETHODIMP
|
||||
nsXULElement::GetChildNodes(nsIDOMNodeList** aChildNodes)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = EnsureSlots();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsRDFDOMNodeList* children = new nsRDFDOMNodeList();
|
||||
NS_ENSURE_TRUE(children, NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ADDREF(children);
|
||||
|
||||
PRUint32 count = GetChildCount();
|
||||
|
||||
for (PRUint32 i = 0; i < count; ++i) {
|
||||
nsIContent *child = GetChildAt(i);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(child);
|
||||
if (!domNode) {
|
||||
NS_WARNING("child content doesn't support nsIDOMNode");
|
||||
continue;
|
||||
if (!mSlots->mChildNodes) {
|
||||
mSlots->mChildNodes = new nsChildContentList(this);
|
||||
if (!mSlots->mChildNodes) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
rv = children->AppendNode(domNode);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to append node to list");
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
}
|
||||
|
||||
// Create() addref'd for us
|
||||
*aChildNodes = children;
|
||||
|
||||
NS_ADDREF(*aChildNodes = mSlots->mChildNodes);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -4029,6 +4013,10 @@ nsXULElement::Slots::Slots()
|
|||
nsXULElement::Slots::~Slots()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsXULElement::Slots);
|
||||
|
||||
if (mChildNodes) {
|
||||
mChildNodes->DropReference();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -82,13 +82,13 @@
|
|||
#include "nsAttrAndChildArray.h"
|
||||
#include "nsXULAtoms.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsGenericElement.h"
|
||||
|
||||
class nsIDocument;
|
||||
class nsIRDFService;
|
||||
class nsISupportsArray;
|
||||
class nsIXULContentUtils;
|
||||
class nsIXULPrototypeDocument;
|
||||
class nsRDFDOMNodeList;
|
||||
class nsString;
|
||||
class nsVoidArray;
|
||||
class nsIDocShell;
|
||||
|
@ -595,6 +595,7 @@ protected:
|
|||
nsCOMPtr<nsIControllers> mControllers; // [OWNER]
|
||||
nsRefPtr<nsDOMCSSDeclaration> mDOMStyle; // [OWNER]
|
||||
nsRefPtr<nsDOMAttributeMap> mAttributeMap; // [OWNER]
|
||||
nsRefPtr<nsChildContentList> mChildNodes; // [OWNER]
|
||||
PRUint32 mLazyState;
|
||||
};
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@
|
|||
#include "nsPIBoxObject.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsILocalStore.h"
|
||||
#include "nsRDFDOMNodeList.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsXULCommandDispatcher.h"
|
||||
|
|
|
@ -259,9 +259,11 @@ DeleteRangeTxn::CreateTxnsToDeleteBetween(nsIDOMNode *aStartParent,
|
|||
if (NS_FAILED(result)) return result;
|
||||
if (!children) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
#ifdef DEBUG
|
||||
PRUint32 childCount;
|
||||
children->GetLength(&childCount);
|
||||
NS_ASSERTION(aEndOffset<=childCount, "bad aEndOffset");
|
||||
#endif
|
||||
PRUint32 i;
|
||||
for (i=aStartOffset; i<aEndOffset; i++)
|
||||
{
|
||||
|
|
|
@ -3251,8 +3251,9 @@ function UpdateStructToolbar()
|
|||
var childNodesLength = childNodes.length;
|
||||
// We need to leave the <label> to flex the buttons to the left
|
||||
// so, don't remove the last child at position length - 1
|
||||
for (var i = childNodesLength - 2; i >= 0; i--) {
|
||||
toolbar.removeChild(childNodes.item(i));
|
||||
while (childNodes.length > 1) {
|
||||
// Remove back to front so there's less moving about.
|
||||
toolbar.removeChild(childNodes.item(childNodes.length - 2));
|
||||
}
|
||||
|
||||
toolbar.removeAttribute("label");
|
||||
|
|
|
@ -295,9 +295,8 @@ function BuildTOC(update)
|
|||
}
|
||||
else {
|
||||
// we can keep the list itself but let's get rid of the TOC entries
|
||||
var nodeList = toc.childNodes, l = nodeList.length;
|
||||
for (j = l - 1; j >= 0; --j)
|
||||
toc.removeChild(nodeList.item(j));
|
||||
while (toc.hasChildNodes()) {
|
||||
toc.removeChild(toc.lastChild);
|
||||
}
|
||||
}
|
||||
var commentText = "mozToc ";
|
||||
|
|
|
@ -257,7 +257,7 @@ inTreeBuilder.prototype =
|
|||
resetTree: function()
|
||||
{
|
||||
var kids = this.mTree.childNodes;
|
||||
for (var i = 0 ; i < kids.length; ++i)
|
||||
for (var i = kids.length - 1; i >= 0; --i)
|
||||
if (kids[i].localName != "treechildren")
|
||||
this.mTree.removeChild(kids[i]);
|
||||
|
||||
|
@ -268,7 +268,7 @@ inTreeBuilder.prototype =
|
|||
|
||||
clearChildren: function(aEl)
|
||||
{
|
||||
while (aEl.childNodes.length)
|
||||
while (aEl.hasChildNodes())
|
||||
aEl.removeChild(aEl.lastChild);
|
||||
},
|
||||
|
||||
|
|
|
@ -184,9 +184,8 @@ JSObjectViewer.prototype =
|
|||
|
||||
emptyTree: function(aTreeKids)
|
||||
{
|
||||
var kids = aTreeKids.childNodes;
|
||||
for (var i = 0; i < kids.length; ++i) {
|
||||
aTreeKids.removeChild(kids[i]);
|
||||
while (aTreeKids.hasChildNodes()) {
|
||||
aTreeKids.removeChild(aTreeKids.lastChild);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -386,9 +386,8 @@ XBLBindings.prototype =
|
|||
|
||||
clearChildren: function(aEl)
|
||||
{
|
||||
var kids = aEl.childNodes;
|
||||
for (var i = kids.length-1; i >=0; --i)
|
||||
aEl.removeChild(kids[i]);
|
||||
while (aEl.hasChildNodes())
|
||||
aEl.removeChild(aEl.lastChild);
|
||||
},
|
||||
|
||||
readDOMText: function(aEl)
|
||||
|
|
|
@ -116,6 +116,12 @@ function transferToDocument(aResult, aResultDocument)
|
|||
else {
|
||||
aResultDocument.insertBefore(childNode, aResultDocument.documentElement);
|
||||
}
|
||||
// We removed the node from the list, which will cause it
|
||||
// to shrink by one element. "i" is now pointing to the
|
||||
// node that used to be _after_ the node we just removed.
|
||||
// Decrement i, so when it increments (at the start of the
|
||||
// next iteration) we'll point at the right place.
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1250,8 +1250,8 @@ function ClearAttachmentList()
|
|||
// clear selection
|
||||
var list = document.getElementById('attachmentList');
|
||||
|
||||
while (list.childNodes.length)
|
||||
list.removeChild(list.firstChild);
|
||||
while (list.hasChildNodes())
|
||||
list.removeChild(list.lastChild);
|
||||
}
|
||||
|
||||
function ShowEditMessageButton()
|
||||
|
|
|
@ -402,7 +402,7 @@ function cvSetNode(node, text)
|
|||
{
|
||||
if ( node )
|
||||
{
|
||||
if ( node.childNodes.length == 0 )
|
||||
if ( !node.hasChildNodes() )
|
||||
{
|
||||
var textNode = document.createTextNode(text);
|
||||
node.appendChild(textNode);
|
||||
|
@ -437,8 +437,8 @@ function cvAddAddressNodes(node, uri)
|
|||
if (addressList) {
|
||||
var total = addressList.Count();
|
||||
if (total > 0) {
|
||||
for (var i = node.childNodes.length - 1; i >= 0; i--) {
|
||||
node.removeChild(node.childNodes[i]);
|
||||
while (node.hasChildNodes()) {
|
||||
node.removeChild(node.lastChild);
|
||||
}
|
||||
for (i = 0; i < total; i++ ) {
|
||||
var descNode = document.createElement("description");
|
||||
|
|
|
@ -1996,8 +1996,8 @@ function queryISupportsArray(supportsArray, iid) {
|
|||
function ClearIdentityListPopup(popup)
|
||||
{
|
||||
if (popup)
|
||||
for (var i = popup.childNodes.length - 1; i >= 0; i--)
|
||||
popup.removeChild(popup.childNodes[i]);
|
||||
while (popup.hasChildNodes())
|
||||
popup.removeChild(popup.lastChild);
|
||||
}
|
||||
|
||||
function compareAccountSortOrder(account1, account2)
|
||||
|
@ -2432,9 +2432,9 @@ function RemoveAllAttachments()
|
|||
{
|
||||
var child;
|
||||
var bucket = document.getElementById("attachmentBucket");
|
||||
for (var i = bucket.childNodes.length - 1; i >= 0; i--)
|
||||
while (bucket.hasChildNodes())
|
||||
{
|
||||
child = bucket.removeChild(bucket.childNodes[i]);
|
||||
child = bucket.removeChild(bucket.lastChild);
|
||||
// Let's release the attachment object hold by the node else it won't go away until the window is destroyed
|
||||
child.attachment = null;
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ function onEditDirectories()
|
|||
var popup = document.getElementById("directoriesListPopup");
|
||||
if (popup)
|
||||
{
|
||||
while (popup.childNodes.length)
|
||||
popup.removeChild(popup.childNodes[0]);
|
||||
while (popup.hasChildNodes())
|
||||
popup.removeChild(popup.lastChild);
|
||||
}
|
||||
gAvailDirectories = null;
|
||||
LoadDirectories(popup);
|
||||
|
|
|
@ -403,7 +403,7 @@ function cvSetNode(node, text)
|
|||
{
|
||||
if ( node )
|
||||
{
|
||||
if ( node.childNodes.length == 0 )
|
||||
if ( !node.hasChildNodes() )
|
||||
{
|
||||
var textNode = document.createTextNode(text);
|
||||
node.appendChild(textNode);
|
||||
|
@ -438,8 +438,8 @@ function cvAddAddressNodes(node, uri)
|
|||
if (addressList) {
|
||||
var total = addressList.Count();
|
||||
if (total > 0) {
|
||||
for (var i = node.childNodes.length - 1; i >= 0; i--) {
|
||||
node.removeChild(node.childNodes[i]);
|
||||
while (node.hasChildNodes()) {
|
||||
node.removeChild(node.lastChild);
|
||||
}
|
||||
for (i = 0; i < total; i++ ) {
|
||||
var descNode = document.createElement("description");
|
||||
|
|
|
@ -1894,8 +1894,8 @@ function queryISupportsArray(supportsArray, iid) {
|
|||
function ClearIdentityListPopup(popup)
|
||||
{
|
||||
if (popup)
|
||||
for (var i = popup.childNodes.length - 1; i >= 0; i--)
|
||||
popup.removeChild(popup.childNodes[i]);
|
||||
while (popup.hasChildNodes())
|
||||
popup.removeChild(popup.lastChild);
|
||||
}
|
||||
|
||||
function compareAccountSortOrder(account1, account2)
|
||||
|
@ -2300,9 +2300,9 @@ function RemoveAllAttachments()
|
|||
{
|
||||
var child;
|
||||
var bucket = document.getElementById("attachmentBucket");
|
||||
for (var i = bucket.childNodes.length - 1; i >= 0; i--)
|
||||
while (bucket.hasChildNodes())
|
||||
{
|
||||
child = bucket.removeChild(bucket.childNodes[i]);
|
||||
child = bucket.removeChild(bucket.lastChild);
|
||||
// Let's release the attachment object hold by the node else it won't go away until the window is destroyed
|
||||
child.attachment = null;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ function SetDivText(id, text)
|
|||
var div = document.getElementById(id);
|
||||
|
||||
if (div) {
|
||||
if (!div.childNodes.length) {
|
||||
if (!div.hasChildNodes()) {
|
||||
var textNode = document.createTextNode(text);
|
||||
div.appendChild(textNode);
|
||||
}
|
||||
|
@ -321,10 +321,8 @@ function ListModules() {
|
|||
return;
|
||||
|
||||
var body = document.getElementById( "moduleList");
|
||||
var max = body.childNodes.length - 1;
|
||||
while (max >= 0) {
|
||||
body.removeChild( body.childNodes[max]);
|
||||
max--;
|
||||
while (body.hasChildNodes()) {
|
||||
body.removeChild(body.lastChild);
|
||||
}
|
||||
|
||||
var count = top.importService.GetModuleCount(top.importType);
|
||||
|
|
|
@ -413,7 +413,7 @@ function createMenuItem( aParent, aIndex, aLabel)
|
|||
function deleteHistoryItems(aParent)
|
||||
{
|
||||
var children = aParent.childNodes;
|
||||
for (var i = 0; i < children.length; i++)
|
||||
for (var i = children.length - 1; i >= 0; --i)
|
||||
{
|
||||
var index = children[i].getAttribute("index");
|
||||
if (index)
|
||||
|
|
|
@ -304,7 +304,7 @@ function createRadioMenuItem( aParent, aIndex, aLabel, aChecked)
|
|||
function deleteHistoryItems(aParent)
|
||||
{
|
||||
var children = aParent.childNodes;
|
||||
for (var i = 0; i < children.length; i++ )
|
||||
for (var i = children.length - 1; i >= 0; --i )
|
||||
{
|
||||
var index = children[i].getAttribute( "index" );
|
||||
if (index)
|
||||
|
|
|
@ -191,9 +191,8 @@
|
|||
|
||||
<method name="clearEngines">
|
||||
<body><![CDATA[
|
||||
var kids = this.mSearchBox.childNodes;
|
||||
for (var i = kids.length-1; i >= 0; --i)
|
||||
this.mSearchBox.removeChild(kids[i]);
|
||||
while (this.mSearchBox.hasChildNodes())
|
||||
this.mSearchBox.removeChild(this.mSearchBox.lastChild);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
|
|
|
@ -1,448 +0,0 @@
|
|||
/* ***** 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 Robert John Churchill.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert John Churchill <rjc@netscape.com> (Original Author)
|
||||
* Karsten Duesterloh <kd-moz@tprac.de>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either 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 ***** */
|
||||
|
||||
function fillContextMenu(name, treeName)
|
||||
{
|
||||
if (!name) return(false);
|
||||
var popupNode = document.getElementById(name);
|
||||
if (!popupNode) return(false);
|
||||
// remove the menu node (which tosses all of its kids);
|
||||
// do this in case any old command nodes are hanging around
|
||||
while (popupNode.childNodes.length)
|
||||
{
|
||||
popupNode.removeChild(popupNode.childNodes[0]);
|
||||
}
|
||||
|
||||
var treeNode = document.getElementById(treeName);
|
||||
if (!treeNode) return(false);
|
||||
var db = treeNode.database;
|
||||
if (!db) return(false);
|
||||
|
||||
var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
if (!compositeDB) return(false);
|
||||
|
||||
var isupports = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
|
||||
if (!isupports) return(false);
|
||||
var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!rdf) return(false);
|
||||
|
||||
var target_item = document.popupNode.parentNode.parentNode;
|
||||
if (target_item && target_item.nodeName == "treeitem")
|
||||
{
|
||||
if (target_item.getAttribute('selected') != 'true') {
|
||||
treeNode.selectItem(target_item);
|
||||
}
|
||||
}
|
||||
|
||||
var select_list = treeNode.selectedItems;
|
||||
|
||||
var separatorResource = rdf.GetResource("http://home.netscape.com/NC-rdf#BookmarkSeparator");
|
||||
if (!separatorResource) return(false);
|
||||
|
||||
// perform intersection of commands over selected nodes
|
||||
var cmdArray = new Array();
|
||||
var selectLength = select_list.length;
|
||||
if (selectLength == 0) selectLength = 1;
|
||||
for (var nodeIndex=0; nodeIndex < selectLength; nodeIndex++)
|
||||
{
|
||||
var id = null;
|
||||
|
||||
// if nothing is selected, get commands for the "ref" of the tree root
|
||||
if (select_list.length == 0)
|
||||
{
|
||||
id = treeNode.getAttribute("ref");
|
||||
if (!id) break;
|
||||
}
|
||||
else
|
||||
{
|
||||
var node = select_list[nodeIndex];
|
||||
if (!node) break;
|
||||
id = node.getAttribute("id");
|
||||
if (!id) break;
|
||||
}
|
||||
|
||||
var rdfNode = rdf.GetResource(id);
|
||||
if (!rdfNode) break;
|
||||
var cmdEnum = db.GetAllCmds(rdfNode);
|
||||
if (!cmdEnum) break;
|
||||
|
||||
var nextCmdArray = new Array();
|
||||
while (cmdEnum.hasMoreElements())
|
||||
{
|
||||
var cmd = cmdEnum.getNext();
|
||||
if (!cmd) break;
|
||||
if (nodeIndex == 0)
|
||||
{
|
||||
cmdArray[cmdArray.length] = cmd;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextCmdArray[cmdArray.length] = cmd;
|
||||
}
|
||||
}
|
||||
if (nodeIndex > 0)
|
||||
{
|
||||
// perform command intersection calculation
|
||||
for (var cmdIndex = 0; cmdIndex < cmdArray.length; cmdIndex++)
|
||||
{
|
||||
var cmdFound = false;
|
||||
for (var nextCmdIndex = 0; nextCmdIndex < nextCmdArray.length; nextCmdIndex++)
|
||||
{
|
||||
if (nextCmdArray[nextCmdIndex] == cmdArray[cmdIndex])
|
||||
{
|
||||
cmdFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((cmdFound == false) && (cmdArray[cmdIndex]))
|
||||
{
|
||||
var cmdResource = cmdArray[cmdIndex].QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if ((cmdResource) && (cmdResource != separatorResource))
|
||||
{
|
||||
cmdArray[cmdIndex] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// need a resource to ask RDF for each command's name
|
||||
var rdfNameResource = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
|
||||
if (!rdfNameResource) return(false);
|
||||
|
||||
// build up menu items
|
||||
if (cmdArray.length < 1) return(false);
|
||||
|
||||
var lastWasSep = false;
|
||||
|
||||
for (var cmdIndex = 0; cmdIndex < cmdArray.length; cmdIndex++)
|
||||
{
|
||||
var cmd = cmdArray[cmdIndex];
|
||||
if (!cmd) continue;
|
||||
var cmdResource = cmd.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (!cmdResource) break;
|
||||
|
||||
// handle separators
|
||||
if (cmdResource == separatorResource)
|
||||
{
|
||||
if (lastWasSep != true)
|
||||
{
|
||||
lastWasSep = true;
|
||||
var menuItem = document.createElement("menuseparator");
|
||||
popupNode.appendChild(menuItem);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
lastWasSep = false;
|
||||
|
||||
var cmdNameNode = compositeDB.GetTarget(cmdResource, rdfNameResource, true);
|
||||
if (!cmdNameNode) break;
|
||||
cmdNameLiteral = cmdNameNode.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (!cmdNameLiteral) break;
|
||||
cmdName = cmdNameLiteral.Value;
|
||||
if (!cmdName) break;
|
||||
|
||||
var menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("label", cmdName);
|
||||
popupNode.appendChild(menuItem);
|
||||
// work around bug # 26402 by setting "oncommand" attribute AFTER appending menuitem
|
||||
menuItem.setAttribute("oncommand", "return doContextCmd('" + cmdResource.Value + "', '" + treeName + "');");
|
||||
}
|
||||
|
||||
// strip off leading/trailing menuseparators
|
||||
while (popupNode.childNodes.length > 0)
|
||||
{
|
||||
if (popupNode.childNodes[0].tagName != "menuseparator")
|
||||
break;
|
||||
popupNode.removeChild(popupNode.childNodes[0]);
|
||||
}
|
||||
while (popupNode.childNodes.length > 0)
|
||||
{
|
||||
if (popupNode.childNodes[popupNode.childNodes.length - 1].tagName != "menuseparator")
|
||||
break;
|
||||
popupNode.removeChild(popupNode.childNodes[popupNode.childNodes.length - 1]);
|
||||
}
|
||||
|
||||
var searchMode = 0;
|
||||
if (pref) searchMode = pref.getIntPref("browser.search.mode");
|
||||
if (pref && bundle)
|
||||
{
|
||||
// then add a menu separator (if necessary)
|
||||
if (popupNode.childNodes.length > 0)
|
||||
{
|
||||
if (popupNode.childNodes[popupNode.childNodes.length - 1].tagName != "menuseparator")
|
||||
{
|
||||
var menuSep = document.createElement("menuseparator");
|
||||
popupNode.appendChild(menuSep);
|
||||
}
|
||||
}
|
||||
// And then add a "Search Mode" menu item
|
||||
var propMenuName = (searchMode == 0) ? bundle.GetStringFromName("enableAdvanced") : bundle.GetStringFromName("disableAdvanced");
|
||||
var menuItem = document.createElement("menuitem");
|
||||
menuItem.setAttribute("label", propMenuName);
|
||||
popupNode.appendChild(menuItem);
|
||||
// Work around bug # 26402 by setting "oncommand" attribute
|
||||
// AFTER appending menuitem
|
||||
menuItem.setAttribute("oncommand", "return setSearchMode();");
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setSearchMode()
|
||||
{
|
||||
var searchMode = 0;
|
||||
if (pref) searchMode = pref.getIntPref("browser.search.mode");
|
||||
if (searchMode == 0) searchMode = 1;
|
||||
else searchMode = 0;
|
||||
if (pref) pref.setIntPref("browser.search.mode", searchMode);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function doContextCmd(cmdName, treeName)
|
||||
{
|
||||
var treeNode = document.getElementById(treeName);
|
||||
if (!treeNode) return(false);
|
||||
var db = treeNode.database;
|
||||
if (!db) return(false);
|
||||
|
||||
var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
||||
if (!compositeDB) return(false);
|
||||
|
||||
var isupports = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
|
||||
if (!isupports) return(false);
|
||||
var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
if (!rdf) return(false);
|
||||
|
||||
// need a resource for the command
|
||||
var cmdResource = rdf.GetResource(cmdName);
|
||||
if (!cmdResource) return(false);
|
||||
cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
if (!cmdResource) return(false);
|
||||
|
||||
// set up selection nsISupportsArray
|
||||
var selectionInstance = Components.classes["@mozilla.org/supports-array;1"].createInstance();
|
||||
var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
|
||||
// set up arguments nsISupportsArray
|
||||
var argumentsInstance = Components.classes["@mozilla.org/supports-array;1"].createInstance();
|
||||
var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);
|
||||
|
||||
// get argument (parent)
|
||||
var parentArc = rdf.GetResource("http://home.netscape.com/NC-rdf#parent");
|
||||
if (!parentArc) return(false);
|
||||
|
||||
var select_list = treeNode.selectedItems;
|
||||
if (select_list.length < 1)
|
||||
{
|
||||
// if nothing is selected, default to using the "ref" on the root of the tree
|
||||
var uri = treeNode.getAttribute("ref");
|
||||
if (!uri || uri=="") return(false);
|
||||
var rdfNode = rdf.GetResource(uri);
|
||||
// add node into selection array
|
||||
if (rdfNode)
|
||||
{
|
||||
selectionArray.AppendElement(rdfNode);
|
||||
}
|
||||
}
|
||||
else for (var nodeIndex=0; nodeIndex<select_list.length; nodeIndex++)
|
||||
{
|
||||
var node = select_list[nodeIndex];
|
||||
if (!node) break;
|
||||
var uri = node.getAttribute("ref");
|
||||
if ((uri) || (uri == ""))
|
||||
{
|
||||
uri = node.getAttribute("id");
|
||||
}
|
||||
if (!uri) return(false);
|
||||
|
||||
var rdfNode = rdf.GetResource(uri);
|
||||
if (!rdfNode) break;
|
||||
|
||||
// add node into selection array
|
||||
selectionArray.AppendElement(rdfNode);
|
||||
|
||||
// get the parent's URI
|
||||
var parentURI="";
|
||||
var theParent = node;
|
||||
while (theParent)
|
||||
{
|
||||
theParent = theParent.parentNode;
|
||||
|
||||
parentURI = theParent.getAttribute("ref");
|
||||
if ((!parentURI) || (parentURI == ""))
|
||||
{
|
||||
parentURI = theParent.getAttribute("id");
|
||||
}
|
||||
if (parentURI != "") break;
|
||||
}
|
||||
if (parentURI == "") return(false);
|
||||
|
||||
var parentNode = rdf.GetResource(parentURI, true);
|
||||
if (!parentNode) return(false);
|
||||
|
||||
// add parent arc and node into arguments array
|
||||
argumentsArray.AppendElement(parentArc);
|
||||
argumentsArray.AppendElement(parentNode);
|
||||
}
|
||||
|
||||
// do the command
|
||||
compositeDB.DoCommand( selectionArray, cmdResource, argumentsArray );
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Note: doSort() does NOT support natural order sorting, unless naturalOrderResource is valid,
|
||||
in which case we sort ascending on naturalOrderResource
|
||||
*/
|
||||
function doSort(sortColName, naturalOrderResource)
|
||||
{
|
||||
var node = document.getElementById(sortColName);
|
||||
// determine column resource to sort on
|
||||
var sortResource = node.getAttribute('resource');
|
||||
if (!sortResource) return(false);
|
||||
|
||||
var sortDirection="ascending";
|
||||
var isSortActive = node.getAttribute('sortActive');
|
||||
if (isSortActive == "true")
|
||||
{
|
||||
sortDirection = "ascending";
|
||||
|
||||
var currentDirection = node.getAttribute('sortDirection');
|
||||
if (currentDirection == "ascending")
|
||||
{
|
||||
if (sortResource != naturalOrderResource)
|
||||
{
|
||||
sortDirection = "descending";
|
||||
}
|
||||
}
|
||||
else if (currentDirection == "descending")
|
||||
{
|
||||
if (naturalOrderResource != null && naturalOrderResource != "")
|
||||
{
|
||||
sortResource = naturalOrderResource;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isupports = Components.classes["@mozilla.org/xul/xul-sort-service;1"].getService();
|
||||
if (!isupports) return(false);
|
||||
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
|
||||
if (!xulSortService) return(false);
|
||||
try
|
||||
{
|
||||
xulSortService.sort(node, sortResource, sortDirection);
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
debug("Exception calling xulSortService.sort()");
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function setInitialSort(node, sortDirection)
|
||||
{
|
||||
// determine column resource to sort on
|
||||
var sortResource = node.getAttribute('resource');
|
||||
if (!sortResource) return(false);
|
||||
|
||||
try
|
||||
{
|
||||
var isupports = Components.classes["@mozilla.org/xul/xul-sort-service;1"].getService();
|
||||
if (!isupports) return(false);
|
||||
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
|
||||
if (!xulSortService) return(false);
|
||||
xulSortService.sort(node, sortResource, sortDirection);
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
function switchTab(aPageIndex)
|
||||
{
|
||||
var deck = document.getElementById("advancedDeck");
|
||||
if (!deck)
|
||||
{ // get the search-panel deck the hard way
|
||||
// otherwise the switchTab call from internetresults.xul would fail
|
||||
var oSearchPanel = getNavigatorWindow(false).sidebarObj.panels.get_panel_from_id("urn:sidebar:panel:search");
|
||||
if (!oSearchPanel)
|
||||
return;
|
||||
deck = oSearchPanel.get_iframe().contentDocument.getElementById("advancedDeck")
|
||||
}
|
||||
deck.setAttribute("selectedIndex", aPageIndex);
|
||||
}
|
||||
|
||||
|
||||
// retrieves the most recent navigator window
|
||||
function getNavigatorWindow(aOpenFlag)
|
||||
{
|
||||
var navigatorWindow;
|
||||
|
||||
// if this is a browser window, just use it
|
||||
if ("document" in top) {
|
||||
var possibleNavigator = top.document.getElementById("main-window");
|
||||
if (possibleNavigator &&
|
||||
possibleNavigator.getAttribute("windowtype") == "navigator:browser")
|
||||
navigatorWindow = top;
|
||||
}
|
||||
|
||||
// if not, get the most recently used browser window
|
||||
if (!navigatorWindow) {
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
navigatorWindow = wm.getMostRecentWindow("navigator:browser");
|
||||
}
|
||||
|
||||
// if no browser window available and it's ok to open a new one, do so
|
||||
if (!navigatorWindow && aOpenFlag) {
|
||||
var navigatorChromeURL = search_getBrowserURL();
|
||||
navigatorWindow = openDialog(navigatorChromeURL, "_blank", "chrome,all,dialog=no");
|
||||
}
|
||||
return navigatorWindow;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче