From 846feff6655c64b6730d27fc562b2473668519f4 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 15 Apr 2004 01:51:32 +0000 Subject: [PATCH] Make getElementsByAttribute be an nsContentList so that it's got that live DOMNodeList goodness that all nodelists should have. Change some JS to not break, and some other JS to be a little more efficient with the new world of lazy listness. Bug 240186, r=neil on the JS changes, r=jst on the content changes, sr=jst --- .../prefwindow/content/pref-fonts.js | 12 +-- calendar/resources/content/alertDialog.js | 2 +- calendar/resources/content/dayView.js | 4 +- calendar/resources/content/monthView.js | 22 ++--- calendar/resources/content/multiweekView.js | 22 ++--- calendar/resources/content/weekView.js | 16 +-- content/base/src/nsContentList.cpp | 52 ++++++++-- content/base/src/nsContentList.h | 19 +++- .../content/src/nsHTMLTableRowElement.cpp | 3 +- content/html/document/src/nsHTMLDocument.cpp | 39 ++++---- content/html/document/src/nsHTMLDocument.h | 13 ++- content/xul/content/src/nsXULElement.cpp | 80 +++------------ content/xul/content/src/nsXULElement.h | 7 -- content/xul/document/src/nsXULDocument.cpp | 97 ++++++------------- content/xul/document/src/nsXULDocument.h | 12 +-- .../resources/content/pref-contentpacks.xul | 16 +-- mail/base/content/mailWindowOverlay.js | 5 +- .../prefwindow/content/pref-fonts.js | 12 +-- .../prefs/resources/content/AccountManager.js | 2 +- .../resources/content/smtpEditOverlay.js | 2 +- .../base/resources/content/mailWidgets.xml | 18 ++-- .../search/resources/content/FilterEditor.js | 15 ++- profile/resources/content/selectLang.js | 2 +- .../console/content/consoleBindings.xml | 2 +- .../components/viewconfig/content/config.js | 4 +- toolkit/content/widgets/colorpicker.xml | 4 +- toolkit/content/widgets/listbox.xml | 2 +- toolkit/content/widgets/menulist.xml | 8 +- toolkit/content/widgets/wizard.xml | 4 +- .../resources/content/pref-fonts.js | 12 +-- .../resources/content/pref-search.js | 2 +- .../search/resources/search-editor.js | 2 +- .../content/bindings/colorpicker.xml | 2 +- .../resources/content/bindings/listbox.xml | 2 +- .../resources/content/bindings/menulist.xml | 11 +-- .../resources/content/bindings/wizard.xml | 4 +- xpfe/global/resources/content/config.js | 4 +- 37 files changed, 236 insertions(+), 299 deletions(-) diff --git a/browser/components/prefwindow/content/pref-fonts.js b/browser/components/prefwindow/content/pref-fonts.js index b76452b4163..427b210eba3 100644 --- a/browser/components/prefwindow/content/pref-fonts.js +++ b/browser/components/prefwindow/content/pref-fonts.js @@ -412,7 +412,7 @@ function lazyAppendFontNames( i ) else { var dataEls = selectElement.listElement.getElementsByAttribute( "value", dataVal ); - selectedItem = dataEls.length ? dataEls[0] : defaultItem; + selectedItem = dataEls.item(0) ? dataEls[0] : defaultItem; } } else @@ -424,7 +424,7 @@ function lazyAppendFontNames( i ) var dataEls = selectElement.listElement.getElementsByAttribute( "value", selectVal ); // we need to honor name-list in case name is unavailable - if (!dataEls.length) { + if (!dataEls.item(0)) { var fontListPrefString = "font.name-list." + fontTypes[i] + "." + languageList.value; var nameList = gPrefWindow.pref.CopyUnicharPref( fontListPrefString ); var fontNames = nameList.split(","); @@ -433,11 +433,11 @@ function lazyAppendFontNames( i ) for (j = 0; j < fontNames.length; j++) { selectVal = fontNames[j].replace(stripWhitespace, "$1"); dataEls = selectElement.listElement.getElementsByAttribute("value", selectVal); - if (dataEls.length) + if (dataEls.item(0)) break; // exit loop if we find one } } - selectedItem = dataEls.length ? dataEls[0] : defaultItem; + selectedItem = dataEls.item(0) ? dataEls[0] : defaultItem; } catch(e) { selectedItem = defaultItem; @@ -477,7 +477,7 @@ function saveState() function minSizeSelect(size) { var items = minSize.getElementsByAttribute( "value", size ); - if (items.length > 0) + if (items.item(0)) minSize.selectedItem = items[0]; else if (size < 6) minSizeSelect(6); @@ -595,7 +595,7 @@ function setResolution( resolution ) var userResolution = document.getElementById( "userResolution" ); var items = screenResolution.getElementsByAttribute( "value", resolution ); - if (items.length) + if (items.item(0)) { // If it's one of the hard-coded values, we'll select it directly screenResolution.selectedItem = items[0]; diff --git a/calendar/resources/content/alertDialog.js b/calendar/resources/content/alertDialog.js index 4bec4524e65..b23ed1854fc 100644 --- a/calendar/resources/content/alertDialog.js +++ b/calendar/resources/content/alertDialog.js @@ -200,7 +200,7 @@ function removeAlarmBox( Event ) //if there's no more events left, close the dialog EventAlarmBoxes = document.getElementsByAttribute( "eventbox", "true" ); - if( EventAlarmBoxes.length > 0 ) + if( EventAlarmBoxes.item(0) ) { //there are still boxes left. return( false ); diff --git a/calendar/resources/content/dayView.js b/calendar/resources/content/dayView.js index 0c1595733a9..cb51a8b19b9 100644 --- a/calendar/resources/content/dayView.js +++ b/calendar/resources/content/dayView.js @@ -127,8 +127,8 @@ DayView.prototype.refreshEvents = function dayview_refreshEvents( ) { allDayBox.removeChild( allDayBox.firstChild ); // remove eventboxes - for( var i = 0; i < eventBoxList.length; i++ ) { - eventBox = eventBoxList[ i ]; + while (eventBoxList.item(0)) { + eventBox = eventBoxList[0]; eventBox.parentNode.removeChild( eventBox ); } diff --git a/calendar/resources/content/monthView.js b/calendar/resources/content/monthView.js index 9f468cbe8c2..03c5997b9b5 100644 --- a/calendar/resources/content/monthView.js +++ b/calendar/resources/content/monthView.js @@ -230,9 +230,9 @@ MonthView.prototype.refreshEvents = function monthView_refreshEvents( ) var eventBox = null; - for( var eventBoxIndex = 0; eventBoxIndex < eventBoxList.length; ++eventBoxIndex ) + while ( eventBoxList.item(0) ) { { - eventBox = eventBoxList[ eventBoxIndex ]; + eventBox = eventBoxList[ 0 ]; eventBox.parentNode.removeChild( eventBox ); } @@ -637,9 +637,9 @@ MonthView.prototype.clearSelectedDate = function monthView_clearSelectedDate( ) { var SelectedBoxes = document.getElementsByAttribute( "monthselected", "true" ); - for( var i = 0; i < SelectedBoxes.length; i++ ) + while( SelectedBoxes.item(0) ) { - SelectedBoxes[i].removeAttribute( "monthselected" ); + SelectedBoxes[0].removeAttribute( "monthselected" ); } } @@ -652,9 +652,9 @@ MonthView.prototype.clearSelectedBoxes = function monthView_clearSelectedBoxes( { var SelectedBoxes = document.getElementsByAttribute( "eventselected", "true" ); - for( var i = 0; i < SelectedBoxes.length; i++ ) + while( SelectedBoxes.item(0) ) { - SelectedBoxes[i].removeAttribute( "eventselected" ); + SelectedBoxes[0].removeAttribute( "eventselected" ); } } @@ -666,11 +666,11 @@ MonthView.prototype.clearSelectedBoxes = function monthView_clearSelectedBoxes( MonthView.prototype.hiliteTodaysDate = function monthView_hiliteTodaysDate( ) { // Clear the old selection if there was one - var TodayBox = document.getElementsByAttribute( "today", "true" ); + var TodayBoxes = document.getElementsByAttribute( "today", "true" ); - for( var i = 0; i < TodayBox.length; i++ ) + while( TodayBoxes.item(0) ) { - TodayBox[i].removeAttribute( "today" ); + TodayBoxes[0].removeAttribute( "today" ); } //highlight today. @@ -872,9 +872,9 @@ MonthView.prototype.clearSelectedEvent = function monthView_clearSelectedEvent( debug("clearSelectedEvent"); var ArrayOfBoxes = document.getElementsByAttribute( "eventselected", "true" ); - for( i = 0; i < ArrayOfBoxes.length; i++ ) + while( ArrayOfBoxes.item(0) ) { - ArrayOfBoxes[i].removeAttribute( "eventselected" ); + ArrayOfBoxes[0].removeAttribute( "eventselected" ); } } diff --git a/calendar/resources/content/multiweekView.js b/calendar/resources/content/multiweekView.js index 3567ed77722..db986932549 100644 --- a/calendar/resources/content/multiweekView.js +++ b/calendar/resources/content/multiweekView.js @@ -234,9 +234,9 @@ MultiweekView.prototype.refreshEvents = function multiweekView_refreshEvents( ) var eventBox = null; - for( var eventBoxIndex = 0; eventBoxIndex < eventBoxList.length; ++eventBoxIndex ) + while( eventBoxList.item(0) ) { - eventBox = eventBoxList[ eventBoxIndex ]; + eventBox = eventBoxList[ 0 ]; eventBox.parentNode.removeChild( eventBox ); } @@ -246,9 +246,9 @@ MultiweekView.prototype.refreshEvents = function multiweekView_refreshEvents( ) // remove old todo boxes var toDoBoxList = document.getElementsByAttribute( "todobox", "multiweekview" ); - for( var toDoBoxIndex = 0; toDoBoxIndex < toDoBoxList.length; ++toDoBoxIndex ) + while( toDoBoxList.item(0) ) { - eventBox = toDoBoxList[ toDoBoxIndex ]; + eventBox = toDoBoxList[ 0 ]; eventBox.parentNode.removeChild( eventBox ); } @@ -763,9 +763,9 @@ MultiweekView.prototype.clearSelectedDate = function multiweekView_clearSelected { var SelectedBoxes = document.getElementsByAttribute( "multiweekselected", "true" ); - for( var i = 0; i < SelectedBoxes.length; i++ ) + while( SelectedBoxes.item(0) ) { - SelectedBoxes[i].removeAttribute( "multiweekselected" ); + SelectedBoxes[0].removeAttribute( "multiweekselected" ); } } @@ -778,11 +778,11 @@ MultiweekView.prototype.clearSelectedDate = function multiweekView_clearSelected MultiweekView.prototype.hiliteTodaysDate = function multiweekView_hiliteTodaysDate( ) { // Clear the old selection if there was one - var TodayBox = document.getElementsByAttribute( "today", "true" ); + var TodayBoxes = document.getElementsByAttribute( "today", "true" ); - for( var i = 0; i < TodayBox.length; i++ ) + while( TodayBoxes.item(0) ) { - TodayBox[i].removeAttribute( "today" ); + TodayBoxes[0].removeAttribute( "today" ); } //highlight today. @@ -931,9 +931,9 @@ MultiweekView.prototype.clearSelectedEvent = function multiweekView_clearSelecte var ArrayOfBoxes = document.getElementsByAttribute( "eventselected", "true" ); - for( i = 0; i < ArrayOfBoxes.length; i++ ) + while( ArrayOfBoxes.item(0) ) { - ArrayOfBoxes[i].removeAttribute( "eventselected" ); + ArrayOfBoxes[0].removeAttribute( "eventselected" ); } } diff --git a/calendar/resources/content/weekView.js b/calendar/resources/content/weekView.js index a437e5df479..81c9d32c969 100644 --- a/calendar/resources/content/weekView.js +++ b/calendar/resources/content/weekView.js @@ -151,9 +151,9 @@ WeekView.prototype.refreshEvents = function( ) var eventBoxList = document.getElementsByAttribute( "eventbox", "weekview" ); - for( var eventBoxIndex = 0; eventBoxIndex < eventBoxList.length; ++eventBoxIndex ) + while( eventBoxList.item(0) ) { - var eventBox = eventBoxList[ eventBoxIndex ]; + var eventBox = eventBoxList[ 0 ]; eventBox.parentNode.removeChild( eventBox ); } @@ -774,9 +774,9 @@ WeekView.prototype.hiliteTodaysDate = function( ) { //clear out the old today boxes. var OldTodayArray = document.getElementsByAttribute( "today", "true" ); - for ( var i = 0; i < OldTodayArray.length; i++ ) + while ( OldTodayArray.item(0) ) { - OldTodayArray[i].removeAttribute( "today" ); + OldTodayArray[0].removeAttribute( "today" ); } @@ -821,9 +821,9 @@ WeekView.prototype.clearSelectedEvent = function( ) //Event = gCalendarWindow.getSelectedEvent(); var ArrayOfBoxes = document.getElementsByAttribute( "eventselected", "true" ); - for( var i = 0; i < ArrayOfBoxes.length; i++ ) + while( ArrayOfBoxes.item(0) ) { - ArrayOfBoxes[i].removeAttribute( "eventselected" ); + ArrayOfBoxes[0].removeAttribute( "eventselected" ); } } @@ -855,9 +855,9 @@ WeekView.prototype.clearSelectedDate = function( ) { var SelectedBoxes = document.getElementsByAttribute( "weekselected", "true" ); - for( var i = 0; i < SelectedBoxes.length; i++ ) + while( SelectedBoxes.item(0) ) { - SelectedBoxes[i].removeAttribute( "weekselected" ); + SelectedBoxes[0].removeAttribute( "weekselected" ); } } diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index 3a2fffcfe83..65b81408d4f 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -41,7 +41,6 @@ #include "nsIDOMNode.h" #include "nsIDOM3Node.h" #include "nsIDocument.h" -#include "nsINameSpaceManager.h" #include "nsGenericElement.h" #include "nsContentUtils.h" @@ -348,10 +347,13 @@ nsContentList::nsContentList(nsIDocument *aDocument, nsContentListMatchFunc aFunc, const nsAString& aData, nsIContent* aRootContent, - PRBool aDeep) + PRBool aDeep, + nsIAtom* aMatchAtom, + PRInt32 aMatchNameSpaceId) : nsBaseContentList(), - nsContentListKey(aDocument, nsnull, kNameSpaceID_Unknown, aRootContent), + nsContentListKey(aDocument, aMatchAtom, aMatchNameSpaceId, aRootContent), mFunc(aFunc), + mData(&EmptyString()), mMatchAll(PR_FALSE), mState(LIST_DIRTY), mDeep(aDeep) @@ -361,9 +363,6 @@ nsContentList::nsContentList(nsIDocument *aDocument, mData = new nsString(aData); // If this fails, fail silently } - else { - mData = nsnull; - } Init(aDocument); } @@ -387,7 +386,10 @@ nsContentList::~nsContentList() mDocument->RemoveObserver(this); } - delete mData; + if (mData && mData != &EmptyString()) { + // We actually allocated mData ourselves + delete mData; + } } @@ -523,6 +525,30 @@ nsContentList::NamedItem(const nsAString& aName, nsIDOMNode** aReturn) return NS_OK; } +void +nsContentList::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, + PRInt32 aNameSpaceID, nsIAtom* aAttribute, + PRInt32 aModType) +{ + if (!mFunc || mState == LIST_DIRTY) { + // Either we're already dirty or this notification doesn't affect + // whether we might match aContent. + return; + } + + if (MayContainRelevantNodes(aContent->GetParent())) { + if (Match(aContent)) { + // We may now match a new node. Just dirty ourselves. + mState = LIST_DIRTY; + } else { + // We no longer match aContent. Remove it from our list. If + // it's already not there, this is a no-op, which is fine. + // Either way, no change of mState is required here. + mElements.RemoveElement(aContent); + } + } +} + void nsContentList::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer) @@ -660,6 +686,10 @@ nsContentList::Match(nsIContent *aContent) if (!aContent) return PR_FALSE; + if (mFunc) { + return (*mFunc)(aContent, mMatchNameSpaceId, mMatchAtom, *mData); + } + if (mMatchAtom) { if (!aContent->IsContentOfType(nsIContent::eELEMENT)) { return PR_FALSE; @@ -675,9 +705,6 @@ nsContentList::Match(nsIContent *aContent) return ((mMatchAll && ni->NamespaceEquals(mMatchNameSpaceId)) || ni->Equals(mMatchAtom, mMatchNameSpaceId)); } - else if (mFunc) { - return (*mFunc)(aContent, mData); - } return PR_FALSE; } @@ -904,6 +931,11 @@ nsContentList::DisconnectFromDocument() void nsContentList::RemoveFromHashtable() { + if (mFunc) { + // This can't be in the table anyway + return; + } + if (!gContentListHashTable.ops) return; diff --git a/content/base/src/nsContentList.h b/content/base/src/nsContentList.h index 63e5bf53bb3..79b4961bf34 100644 --- a/content/base/src/nsContentList.h +++ b/content/base/src/nsContentList.h @@ -46,9 +46,16 @@ #include "nsStubDocumentObserver.h" #include "nsIContentList.h" #include "nsIAtom.h" +#include "nsINameSpaceManager.h" +// This is a callback function type that can be used to implement an +// arbitrary matching algorithm. aContent is the content that may +// match the list, while aNamespaceID, aAtom, and aData are whatever +// was passed to the list's constructor. typedef PRBool (*nsContentListMatchFunc)(nsIContent* aContent, - nsString* aData); + PRInt32 aNamespaceID, + nsIAtom* aAtom, + const nsAString& aData); class nsIDocument; class nsIDOMHTMLFormElement; @@ -167,7 +174,9 @@ public: nsContentListMatchFunc aFunc, const nsAString& aData, nsIContent* aRootContent = nsnull, - PRBool aDeep = PR_TRUE); + PRBool aDeep = PR_TRUE, + nsIAtom* aMatchAtom = nsnull, + PRInt32 aMatchNameSpaceId = kNameSpaceID_None); virtual ~nsContentList(); // nsIDOMHTMLCollection @@ -182,6 +191,9 @@ public: virtual void RootDestroyed(); // nsIDocumentObserver + virtual void AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, + PRInt32 aNameSpaceID, nsIAtom* aAttribute, + PRInt32 aModType); virtual void ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer); virtual void ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, @@ -263,7 +275,6 @@ protected: /** * @param aContainer a content node which could be a descendant of * mRootContent - * @return PR_TRUE if mRootContent is null, PR_FALSE if aContainer * is null, PR_TRUE if aContainer is a descendant of mRootContent * (though if mDeep is false, only aContainer == mRootContent @@ -295,7 +306,7 @@ protected: /** * Closure data to pass to mFunc when we call it */ - nsString* mData; + const nsAFlatString* mData; /** * True if we are looking for elements named "*" */ diff --git a/content/html/content/src/nsHTMLTableRowElement.cpp b/content/html/content/src/nsHTMLTableRowElement.cpp index 625dd5168e3..fb63c43dfa1 100644 --- a/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/content/html/content/src/nsHTMLTableRowElement.cpp @@ -303,7 +303,8 @@ nsHTMLTableRowElement::GetSectionRowIndex(PRInt32* aValue) } PR_STATIC_CALLBACK(PRBool) -IsCell(nsIContent *aContent, nsString* aData) +IsCell(nsIContent *aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) { nsIAtom* tag = aContent->Tag(); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index b11a2fb0632..19fe8a0c796 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1836,7 +1836,8 @@ GetHTMLDocumentNamespace(nsIContent *aContent) } PRBool -nsHTMLDocument::MatchLinks(nsIContent *aContent, nsString* aData) +nsHTMLDocument::MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) { nsINodeInfo *ni = aContent->GetNodeInfo(); @@ -1856,7 +1857,7 @@ NS_IMETHODIMP nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks) { if (!mLinks) { - mLinks = new nsContentList(this, MatchLinks, nsString()); + mLinks = new nsContentList(this, MatchLinks, EmptyString()); if (!mLinks) { return NS_ERROR_OUT_OF_MEMORY; } @@ -1869,7 +1870,8 @@ nsHTMLDocument::GetLinks(nsIDOMHTMLCollection** aLinks) } PRBool -nsHTMLDocument::MatchAnchors(nsIContent *aContent, nsString* aData) +nsHTMLDocument::MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) { nsINodeInfo *ni = aContent->GetNodeInfo(); @@ -1888,7 +1890,7 @@ NS_IMETHODIMP nsHTMLDocument::GetAnchors(nsIDOMHTMLCollection** aAnchors) { if (!mAnchors) { - mAnchors = new nsContentList(this, MatchAnchors, nsString()); + mAnchors = new nsContentList(this, MatchAnchors, EmptyString()); if (!mAnchors) { return NS_ERROR_OUT_OF_MEMORY; } @@ -2459,32 +2461,28 @@ nsHTMLDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI, } PRBool -nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, nsString* aData) +nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) { - // Most elements don't have a name attribute, so lets call the - // faster HasAttr() method before we create a string object and call - // GetAttr(). - - if (!aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name) || !aData) { + NS_PRECONDITION(aContent, "Must have content node to work with!"); + + // Getting attrs is expensive, so use HasAttr() first. + if (!aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name)) { return PR_FALSE; } - nsAutoString name; + nsAutoString value; + nsresult rv = aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, value); - nsresult rv = aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, name); - - if (NS_SUCCEEDED(rv) && name.Equals(*aData)) { - return PR_TRUE; - } - - return PR_FALSE; + return NS_SUCCEEDED(rv) && value.Equals(aData); } NS_IMETHODIMP nsHTMLDocument::GetElementsByName(const nsAString& aElementName, nsIDOMNodeList** aReturn) { - nsContentList* elements = new nsContentList(this, MatchNameAttribute, + nsContentList* elements = new nsContentList(this, + MatchNameAttribute, aElementName); NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY); @@ -2513,7 +2511,8 @@ nsHTMLDocument::GetNumFormsSynchronous() } PRBool -nsHTMLDocument::MatchFormControls(nsIContent* aContent, nsString* aData) +nsHTMLDocument::MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) { return aContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL); } diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 425358008b2..ffdb168115f 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -226,11 +226,14 @@ protected: virtual nsIStyleSheet* InternalGetStyleSheetAt(PRInt32 aIndex) const; virtual PRInt32 InternalGetNumberOfStyleSheets() const; - static PRBool MatchLinks(nsIContent *aContent, nsString* aData); - static PRBool MatchAnchors(nsIContent *aContent, nsString* aData); - static PRBool MatchLayers(nsIContent *aContent, nsString* aData); - static PRBool MatchNameAttribute(nsIContent* aContent, nsString* aData); - static PRBool MatchFormControls(nsIContent* aContent, nsString* aData); + static PRBool MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData); + static PRBool MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData); + static PRBool MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData); + static PRBool MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData); static nsresult GetSourceDocumentURI(nsIURI** sourceURI); diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index f1d22dd4215..badb6c67b21 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -1310,17 +1310,20 @@ nsXULElement::GetElementsByAttribute(const nsAString& aAttribute, const nsAString& aValue, nsIDOMNodeList** aReturn) { - // XXX This should use nsContentList, but that does not support - // _two_ strings being passed to the match func. Ah, the ability - // to create real closures, where art thou? - nsRDFDOMNodeList* elements = new nsRDFDOMNodeList(); - NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(elements); + nsCOMPtr attrAtom(do_GetAtom(aAttribute)); + NS_ENSURE_TRUE(attrAtom, NS_ERROR_OUT_OF_MEMORY); - GetElementsByAttribute(this, aAttribute, aValue, elements); + nsCOMPtr list = + new nsContentList(GetDocument(), + nsXULDocument::MatchAttribute, + aValue, + this, + PR_TRUE, + attrAtom, + kNameSpaceID_None); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - *aReturn = elements; - return NS_OK; + return CallQueryInterface(list, aReturn); } @@ -3011,65 +3014,6 @@ nsXULElement::EnsureContentsGenerated(void) const return NS_OK; } -nsresult -nsXULElement::GetElementsByAttribute(nsIDOMNode* aNode, - const nsAString& aAttribute, - const nsAString& aValue, - nsRDFDOMNodeList* aElements) -{ - nsresult rv; - - nsCOMPtr children; - if (NS_FAILED(rv = aNode->GetChildNodes( getter_AddRefs(children) ))) { - NS_ERROR("unable to get node's children"); - return rv; - } - - // no kids: terminate the recursion - if (! children) - return NS_OK; - - PRUint32 length; - if (NS_FAILED(children->GetLength(&length))) { - NS_ERROR("unable to get node list's length"); - return rv; - } - - for (PRUint32 i = 0; i < length; ++i) { - nsCOMPtr child; - if (NS_FAILED(rv = children->Item(i, getter_AddRefs(child) ))) { - NS_ERROR("unable to get child from list"); - return rv; - } - - nsCOMPtr element; - element = do_QueryInterface(child); - if (!element) - continue; - - nsAutoString attrValue; - if (NS_FAILED(rv = element->GetAttribute(aAttribute, attrValue))) { - NS_ERROR("unable to get attribute value"); - return rv; - } - - if ((attrValue.Equals(aValue)) || (!attrValue.IsEmpty() && aValue.Equals(NS_LITERAL_STRING("*")))) { - if (NS_FAILED(rv = aElements->AppendNode(child))) { - NS_ERROR("unable to append element to node list"); - return rv; - } - } - - // Now recursively look for children - if (NS_FAILED(rv = GetElementsByAttribute(child, aAttribute, aValue, aElements))) { - NS_ERROR("unable to recursively get elements by attribute"); - return rv; - } - } - - return NS_OK; -} - // nsIStyledContent Implementation NS_IMETHODIMP nsXULElement::GetID(nsIAtom** aResult) const diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index 61b731105af..c98e1751c43 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -557,13 +557,6 @@ protected: static nsresult ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent); - // Static helpers - static nsresult - GetElementsByAttribute(nsIDOMNode* aNode, - const nsAString& aAttributeName, - const nsAString& aAttributeValue, - nsRDFDOMNodeList* aElements); - static PRBool IsAncestor(nsIDOMNode* aParentNode, nsIDOMNode* aChildNode); // Helper routine that crawls a parent chain looking for a tree element. diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 754c51dbb8e..d7ecb2e75ae 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -1411,24 +1411,19 @@ nsXULDocument::GetElementsByAttribute(const nsAString& aAttribute, const nsAString& aValue, nsIDOMNodeList** aReturn) { - // XXX This should use nsContentList, but that does not support - // _two_ strings being passed to the match func. Ah, the ability - // to create real closures, where art thou? - nsRDFDOMNodeList* elements = new nsRDFDOMNodeList(); - NS_ENSURE_TRUE(elements, NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(elements); + nsCOMPtr attrAtom(do_GetAtom(aAttribute)); + NS_ENSURE_TRUE(attrAtom, NS_ERROR_OUT_OF_MEMORY); - nsCOMPtr domRoot = do_QueryInterface(mRootContent); - NS_ASSERTION(domRoot, "no doc root"); + nsCOMPtr list = new nsContentList(this, + MatchAttribute, + aValue, + nsnull, + PR_TRUE, + attrAtom, + kNameSpaceID_None); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - nsresult rv = NS_OK; - if (domRoot) { - rv = GetElementsByAttribute(domRoot, aAttribute, aValue, elements); - } - - *aReturn = elements; - - return rv; + return CallQueryInterface(list, aReturn); } @@ -2187,67 +2182,31 @@ nsXULDocument::StartLayout(void) } -nsresult -nsXULDocument::GetElementsByAttribute(nsIDOMNode* aNode, - const nsAString& aAttribute, - const nsAString& aValue, - nsRDFDOMNodeList* aElements) +/* static */ +PRBool +nsXULDocument::MatchAttribute(nsIContent* aContent, + PRInt32 aNamespaceID, + nsIAtom* aAttrName, + const nsAString& aAttrValue) { - nsresult rv; - - nsCOMPtr element; - element = do_QueryInterface(aNode); - if (!element) - return NS_OK; - - nsAutoString attrValue; - if (NS_FAILED(rv = element->GetAttribute(aAttribute, attrValue))) { - NS_ERROR("unable to get attribute value"); - return rv; + NS_PRECONDITION(aContent, "Must have content node to work with!"); + + // Getting attrs is expensive, so use HasAttr() first. + if (!aContent->HasAttr(aNamespaceID, aAttrName)) { + return PR_FALSE; } - if ((attrValue.Equals(aValue)) || - (!attrValue.IsEmpty() && aValue.Equals(NS_LITERAL_STRING("*")))) { - if (NS_FAILED(rv = aElements->AppendNode(aNode))) { - NS_ERROR("unable to append element to node list"); - return rv; - } + if (aAttrValue == NS_LITERAL_STRING("*")) { + // Wildcard. We already know we have this attr, so we match + return PR_TRUE; } - nsCOMPtr children; - if (NS_FAILED(rv = aNode->GetChildNodes( getter_AddRefs(children) ))) { - NS_ERROR("unable to get node's children"); - return rv; - } + nsAutoString value; + nsresult rv = aContent->GetAttr(aNamespaceID, aAttrName, value); - // no kids: terminate the recursion - if (! children) - return NS_OK; - - PRUint32 length; - if (NS_FAILED(children->GetLength(&length))) { - NS_ERROR("unable to get node list's length"); - return rv; - } - - for (PRUint32 i = 0; i < length; ++i) { - nsCOMPtr child; - if (NS_FAILED(rv = children->Item(i, getter_AddRefs(child) ))) { - NS_ERROR("unable to get child from list"); - return rv; - } - - if (NS_FAILED(rv = GetElementsByAttribute(child, aAttribute, aValue, - aElements))) { - NS_ERROR("unable to recursively get elements by attribute"); - return rv; - } - } - - return NS_OK; + return NS_SUCCEEDED(rv) && value.Equals(aAttrValue); } - nsresult nsXULDocument::PrepareToLoad(nsISupports* aContainer, const char* aCommand, diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 6c3854e2aa6..028ce2eea63 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -164,6 +164,12 @@ public: // nsIDOMNSDocument NS_IMETHOD GetContentType(nsAString& aContentType); + static PRBool + MatchAttribute(nsIContent* aContent, + PRInt32 aNameSpaceID, + nsIAtom* aAttrName, + const nsAString& aValue); + protected: // Implementation methods friend nsresult @@ -186,12 +192,6 @@ protected: nsIContent* aElement, void* aClosure); - static nsresult - GetElementsByAttribute(nsIDOMNode* aNode, - const nsAString& aAttribute, - const nsAString& aValue, - nsRDFDOMNodeList* aElements); - void SetIsPopup(PRBool isPopup) { mIsPopup = isPopup; }; nsresult PrepareToLoad(nsISupports* aContainer, diff --git a/extensions/content-packs/resources/content/pref-contentpacks.xul b/extensions/content-packs/resources/content/pref-contentpacks.xul index 7a8f1dbf67e..ccfecd408b2 100644 --- a/extensions/content-packs/resources/content/pref-contentpacks.xul +++ b/extensions/content-packs/resources/content/pref-contentpacks.xul @@ -41,18 +41,18 @@ var regionName = contentList.getAttribute("prefvalue"); var regionElements = contentList.getElementsByAttribute("value", regionName); - if (regionElements.length) { - contentList.selectItem(regionElements[0]); + if (regionElements.item(0)) { + contentList.selectItem(regionElements.item(0)); } else { contentList.selectedIndex = 0; } var languageList = document.getElementById( "languagePackList" ); var languageName = languageList.getAttribute("prefvalue"); - var languageElements =languageList.getElementsByAttribute("value", languageName); + var languageElements = languageList.getElementsByAttribute("value", languageName); - if (languageElements.length) { - languageList.selectItem(languageElements[0]); + if (languageElements.item(0)) { + languageList.selectItem(languageElements.item(0)); } else { languageList.selectedIndex = 0; } @@ -105,7 +105,7 @@ faslFile.remove(false); } catch(e) {} } - return true; + return true; } function SelectPack(listbox, button) @@ -150,8 +150,8 @@ var listSelection = list.getElementsByAttribute("value", list.getAttribute("prefvalue")); //find and select the list item corresponding to the current chrome provider - if (listSelection.length) - list.selectedItem = listSelection[0]; + if (listSelection.item(0)) + list.selectedItem = listSelection.item(0); else list.selectedIndex = 0; } diff --git a/mail/base/content/mailWindowOverlay.js b/mail/base/content/mailWindowOverlay.js index 694a2aa95aa..9901b86b347 100644 --- a/mail/base/content/mailWindowOverlay.js +++ b/mail/base/content/mailWindowOverlay.js @@ -317,9 +317,10 @@ function viewRefreshCustomMailViews(aCurrentViewValue) // remove any existing entries... var menupopupNode = document.getElementById('viewMessageViewPopup'); var userDefinedItems = menupopupNode.getElementsByAttribute("userdefined","true"); - for (var i=0; i 0) + if (items.item(0)) minSize.selectedItem = items[0]; else if (size < 6) minSizeSelect(6); @@ -644,7 +644,7 @@ function setResolution( resolution ) var userResolution = document.getElementById( "userResolution" ); var items = screenResolution.getElementsByAttribute( "value", resolution ); - if (items.length) + if (items.item(0)) { // If it's one of the hard-coded values, we'll select it directly screenResolution.selectedItem = items[0]; diff --git a/mailnews/base/prefs/resources/content/AccountManager.js b/mailnews/base/prefs/resources/content/AccountManager.js index 6e8f181a657..5cd0f00ae98 100644 --- a/mailnews/base/prefs/resources/content/AccountManager.js +++ b/mailnews/base/prefs/resources/content/AccountManager.js @@ -434,7 +434,7 @@ function ReloadSmtpPanel() if (smtpAuthMethod.getAttribute("value") == "1") smtpUseUsername.checked = true; var elements = smtpTrySSL.getElementsByAttribute("value", defaultServer.trySSL); - if (elements.length == 0) + if (!elements.item(0)) elements = smtpTrySSL.getElementsByAttribute("value", "1"); smtpTrySSL.selectedItem = elements[0]; } diff --git a/mailnews/base/prefs/resources/content/smtpEditOverlay.js b/mailnews/base/prefs/resources/content/smtpEditOverlay.js index 5c5e2c0973b..f9856696ba8 100644 --- a/mailnews/base/prefs/resources/content/smtpEditOverlay.js +++ b/mailnews/base/prefs/resources/content/smtpEditOverlay.js @@ -75,7 +75,7 @@ function initSmtpSettings(server) { gSmtpAuthMethod.setAttribute("value", server.authMethod); var elements = gSmtpTrySSL.getElementsByAttribute("value", server.trySSL); - if (elements.length == 0) + if (!elements.item(0)) elements = gSmtpTrySSL.getElementsByAttribute("value", "1"); gSmtpTrySSL.selectedItem = elements[0]; } else { diff --git a/mailnews/base/resources/content/mailWidgets.xml b/mailnews/base/resources/content/mailWidgets.xml index d9a661cf1e0..1ff1ddc50f3 100644 --- a/mailnews/base/resources/content/mailWidgets.xml +++ b/mailnews/base/resources/content/mailWidgets.xml @@ -1046,7 +1046,7 @@ 0) + if (dataItems.item(0)) menulist.selectedItem = dataItems[0]; // now notify targets of new parent's value @@ -1303,7 +1303,7 @@ if (this.internalOperator != Components.interfaces.nsMsgSearchOp.IsntInAB && this.internalOperator != Components.interfaces.nsMsgSearchOp.IsInAB) { var abs = children[4].getElementsByAttribute("value", "moz-abmdbdirectory://abook.mab"); - if (abs.length > 0) + if (abs.item(0)) children[4].selectedItem = abs[0]; this.setAttribute("selectedIndex", "4"); } @@ -1358,7 +1358,7 @@ { var children = document.getAnonymousNodes(this); var abs = children[5].getElementsByAttribute("value", "1"); - if (abs.length > 0) + if (abs.item(0)) children[5].selectedItem = abs[0]; this.setAttribute("selectedIndex", "5"); } @@ -1388,13 +1388,13 @@ if (attrib == nsMsgSearchAttrib.Priority) { var matchingPriority = children[1].getElementsByAttribute("value", val.priority); - if (matchingPriority.length > 0) + if (matchingPriority.item(0)) children[1].selectedItem = matchingPriority[0]; } else if (attrib == nsMsgSearchAttrib.MsgStatus) { var matchingStatus = children[2].getElementsByAttribute("value", val.status); - if (matchingStatus.length > 0) + if (matchingStatus.item(0)) children[2].selectedItem = matchingStatus[0]; } else if (attrib == nsMsgSearchAttrib.AgeInDays) @@ -1406,7 +1406,7 @@ if (this.internalOperator == Components.interfaces.nsMsgSearchOp.IsntInAB || this.internalOperator == Components.interfaces.nsMsgSearchOp.IsInAB) { var abs = children[4].getElementsByAttribute("value", val.str); - if (abs.length > 0) + if (abs.item(0)) children[4].selectedItem = abs[0]; } else @@ -1415,19 +1415,19 @@ else if (attrib == nsMsgSearchAttrib.Label) { var labelVal = children[5].getElementsByAttribute("value", val.label); - if (labelVal.length > 0) + if (labelVal.item(0)) children[5].selectedItem = labelVal[0]; } else if (attrib == nsMsgSearchAttrib.JunkStatus) { var junkStatus = children[6].getElementsByAttribute("value", val.junkStatus); - if (junkStatus.length > 0) + if (junkStatus.item(0)) children[6].selectedItem = junkStatus[0]; } else if (attrib == nsMsgSearchAttrib.HasAttachmentStatus) { var hasAttachmentStatus = children[7].getElementsByAttribute("value", val.hasAttachmentStatus); - if (hasAttachmentStatus.length > 0) + if (hasAttachmentStatus.item(0)) children[7].selectedItem = hasAttachmentStatus[0]; } else diff --git a/mailnews/base/search/resources/content/FilterEditor.js b/mailnews/base/search/resources/content/FilterEditor.js index cb615f41cce..4198a2b228a 100644 --- a/mailnews/base/search/resources/content/FilterEditor.js +++ b/mailnews/base/search/resources/content/FilterEditor.js @@ -310,11 +310,10 @@ function initializeDialog(filter) { gChangePriorityCheckbox.checked = true; // initialize priority - var selectedPriority = gActionPriority.getElementsByAttribute("value", filterAction.priority); + var selectedPriority = gActionPriority.getElementsByAttribute("value", filterAction.priority).item(0); - if (selectedPriority && selectedPriority.length > 0) + if (selectedPriority) { - selectedPriority = selectedPriority[0]; gActionPriority.selectedItem = selectedPriority; } } @@ -322,10 +321,9 @@ function initializeDialog(filter) { gLabelCheckbox.checked = true; // initialize label - var selectedLabel = gActionLabel.getElementsByAttribute("value", filterAction.label); - if (selectedLabel && selectedLabel.length > 0) + var selectedLabel = gActionLabel.getElementsByAttribute("value", filterAction.label).item(0); + if (selectedLabel) { - selectedLabel = selectedLabel[0]; gActionLabel.selectedItem = selectedLabel; } } @@ -333,11 +331,10 @@ function initializeDialog(filter) { gChangeJunkScoreCheckbox.checked = true; // initialize junk score - var selectedJunkScore = gActionJunkScore.getElementsByAttribute("value", filterAction.junkScore); + var selectedJunkScore = gActionJunkScore.getElementsByAttribute("value", filterAction.junkScore).item(0); - if (selectedJunkScore && selectedJunkScore.length > 0) + if (selectedJunkScore) { - selectedJunkScore = selectedJunkScore[0]; gActionJunkScore.selectedItem = selectedJunkScore; } } diff --git a/profile/resources/content/selectLang.js b/profile/resources/content/selectLang.js index c0529d6c50e..821a1715fcd 100644 --- a/profile/resources/content/selectLang.js +++ b/profile/resources/content/selectLang.js @@ -50,7 +50,7 @@ function SelectListItem(listRef, itemValue) if (itemValue) { var elements = listRef.getElementsByAttribute("value", itemValue); - selectedItem = elements.length ? elements[0] : null; + selectedItem = elements.item(0); } if (selectedItem) diff --git a/toolkit/components/console/content/consoleBindings.xml b/toolkit/components/console/content/consoleBindings.xml index d33fdd7b451..7dad243ed57 100644 --- a/toolkit/components/console/content/consoleBindings.xml +++ b/toolkit/components/console/content/consoleBindings.xml @@ -262,7 +262,7 @@ if (kids[i].getAttribute(aAttr) == aVal) return kids[i]; var kids2 = kids[i].getElementsByAttribute(aAttr, aVal); - if (kids2.length > 0) + if (kids2.item(0)) return kids2[0]; } return null; diff --git a/toolkit/components/viewconfig/content/config.js b/toolkit/components/viewconfig/content/config.js index 3b2e52f7e0d..ea76ed549b7 100644 --- a/toolkit/components/viewconfig/content/config.js +++ b/toolkit/components/viewconfig/content/config.js @@ -335,13 +335,13 @@ function onConfigLoad() } var descending = document.getElementsByAttribute("sortDirection", "descending"); - if (descending.length) { + if (descending.item(0)) { gSortedColumn = descending[0].id; gSortDirection = -1; } else { var ascending = document.getElementsByAttribute("sortDirection", "ascending"); - if (ascending.length) + if (ascending.item(0)) gSortedColumn = ascending[0].id; else document.getElementById(gSortedColumn).setAttribute("sortDirection", "ascending"); diff --git a/toolkit/content/widgets/colorpicker.xml b/toolkit/content/widgets/colorpicker.xml index 37a47777ffc..cb1cf13b783 100644 --- a/toolkit/content/widgets/colorpicker.xml +++ b/toolkit/content/widgets/colorpicker.xml @@ -167,7 +167,7 @@ } } var cells = this.mBox.getElementsByAttribute("color", val); - if (cells.length > 0) { + if (cells.item(0)) { this.selectCell(cells[0]); this.hoverCell(this.mSelectedCell); } @@ -479,7 +479,7 @@ var results; for (var i = 0; i < nodes.length; i++) { results = nodes[i].getElementsByAttribute("anonid", aValue); - if (results.length > 0) + if (results.item(0)) return results[0]; } return null; diff --git a/toolkit/content/widgets/listbox.xml b/toolkit/content/widgets/listbox.xml index 3d25e589019..19257051922 100644 --- a/toolkit/content/widgets/listbox.xml +++ b/toolkit/content/widgets/listbox.xml @@ -158,7 +158,7 @@ diff --git a/toolkit/content/widgets/menulist.xml b/toolkit/content/widgets/menulist.xml index 0b59c5b8190..5b75779853b 100644 --- a/toolkit/content/widgets/menulist.xml +++ b/toolkit/content/widgets/menulist.xml @@ -57,10 +57,10 @@ if (popup) { var arr = popup.getElementsByAttribute('selected', 'true'); - if (!arr.length && this.value) + if (!arr.item(0) && this.value) arr = popup.getElementsByAttribute('value', this.value); - if (arr.length) + if (arr.item(0)) this.selectedItem = arr[0]; else this.selectedIndex = 0; @@ -77,7 +77,7 @@ if (popup) arr = popup.getElementsByAttribute('value', val); - if (arr && arr.length) + if (arr && arr.item(0)) this.selectedItem = arr[0]; else this.setAttribute('value', val); @@ -287,7 +287,7 @@ if (popup) arr = popup.getElementsByAttribute('label', this.inputField.value); - if (arr && arr.length) + if (arr && arr.item(0)) this.setSelectionInternal(arr[0]); else this.setSelectionInternal(null); diff --git a/toolkit/content/widgets/wizard.xml b/toolkit/content/widgets/wizard.xml index 73140baeb32..0e70eb1e34d 100644 --- a/toolkit/content/widgets/wizard.xml +++ b/toolkit/content/widgets/wizard.xml @@ -116,7 +116,7 @@ 0 ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType); + return btns.item(0) ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType); ]]> @@ -182,7 +182,7 @@ 0 ? els[0] : null; + return els.item(0); ]]> diff --git a/xpfe/components/prefwindow/resources/content/pref-fonts.js b/xpfe/components/prefwindow/resources/content/pref-fonts.js index 10492591d49..64eff221675 100644 --- a/xpfe/components/prefwindow/resources/content/pref-fonts.js +++ b/xpfe/components/prefwindow/resources/content/pref-fonts.js @@ -361,7 +361,7 @@ function lazyAppendFontNames( i ) else { var dataEls = selectElement.listElement.getElementsByAttribute( "value", dataVal ); - selectedItem = dataEls.length ? dataEls[0] : defaultItem; + selectedItem = dataEls.item(0) ? dataEls.item(0) : defaultItem; } } else @@ -373,7 +373,7 @@ function lazyAppendFontNames( i ) var dataEls = selectElement.listElement.getElementsByAttribute( "value", selectVal ); // we need to honor name-list in case name is unavailable - if (!dataEls.length) { + if (!dataEls.item(0)) { var fontListPrefString = "font.name-list." + fontTypes[i] + "." + languageList.value; var nameList = parent.hPrefWindow.pref.getComplexValue( fontListPrefString, Components.interfaces.nsISupportsString ).data; var fontNames = nameList.split(","); @@ -382,11 +382,11 @@ function lazyAppendFontNames( i ) for (j = 0; j < fontNames.length; j++) { selectVal = fontNames[j].replace(stripWhitespace, "$1"); dataEls = selectElement.listElement.getElementsByAttribute("value", selectVal); - if (dataEls.length) + if (dataEls.item(0)) break; // exit loop if we find one } } - selectedItem = dataEls.length ? dataEls[0] : defaultItem; + selectedItem = dataEls.item(0) ? dataEls.item(0) : defaultItem; } catch(e) { selectedItem = defaultItem; @@ -515,7 +515,7 @@ function saveState() function minSizeSelect(size) { var items = minSize.getElementsByAttribute( "value", size ); - if (items.length > 0) + if (items.item(0)) minSize.selectedItem = items[0]; else if (size < 6) minSizeSelect(6); @@ -623,7 +623,7 @@ function setResolution( resolution ) var userResolution = document.getElementById( "userResolution" ); var items = screenResolution.getElementsByAttribute( "value", resolution ); - if (items.length) + if (items.item(0)) { // If it's one of the hard-coded values, we'll select it directly screenResolution.selectedItem = items[0]; diff --git a/xpfe/components/prefwindow/resources/content/pref-search.js b/xpfe/components/prefwindow/resources/content/pref-search.js index e0fb4386f28..68b8e939e5f 100755 --- a/xpfe/components/prefwindow/resources/content/pref-search.js +++ b/xpfe/components/prefwindow/resources/content/pref-search.js @@ -37,7 +37,7 @@ function checkEngine() var strDefaultSearchEngineName = parent.hPrefWindow.getPref("localizedstring", "browser.search.defaultenginename"); var engineListSelection = engineList.getElementsByAttribute( "label", strDefaultSearchEngineName ); - var selectedItem = engineListSelection.length ? engineListSelection[0] : null; + var selectedItem = engineListSelection.item(0); if (selectedItem) { diff --git a/xpfe/components/search/resources/search-editor.js b/xpfe/components/search/resources/search-editor.js index 8fb93064f0e..9552cb1223a 100644 --- a/xpfe/components/search/resources/search-editor.js +++ b/xpfe/components/search/resources/search-editor.js @@ -494,7 +494,7 @@ function NewCategory() // try and select the new category var categoryList = document.getElementById( "categoryList" ); var select_list = categoryList.getElementsByAttribute("id", categoryID); - if (select_list && select_list.length > 0) + if (select_list && select_list.item(0)) { categoryList.selectedItem = select_list[0]; chooseCategory(categoryList.selectedItem); diff --git a/xpfe/global/resources/content/bindings/colorpicker.xml b/xpfe/global/resources/content/bindings/colorpicker.xml index 0693ba01878..ac0afafab1f 100644 --- a/xpfe/global/resources/content/bindings/colorpicker.xml +++ b/xpfe/global/resources/content/bindings/colorpicker.xml @@ -167,7 +167,7 @@ } } var cells = this.mBox.getElementsByAttribute("color", val); - if (cells.length > 0) { + if (cells.item(0)) { this.selectCell(cells[0]); this.hoverCell(this.mSelectedCell); } diff --git a/xpfe/global/resources/content/bindings/listbox.xml b/xpfe/global/resources/content/bindings/listbox.xml index da14f72e806..27bb40b6a64 100644 --- a/xpfe/global/resources/content/bindings/listbox.xml +++ b/xpfe/global/resources/content/bindings/listbox.xml @@ -154,7 +154,7 @@ diff --git a/xpfe/global/resources/content/bindings/menulist.xml b/xpfe/global/resources/content/bindings/menulist.xml index a6a9e163dcc..15b782f4120 100644 --- a/xpfe/global/resources/content/bindings/menulist.xml +++ b/xpfe/global/resources/content/bindings/menulist.xml @@ -49,10 +49,10 @@ if (popup) { var arr = popup.getElementsByAttribute('selected', 'true'); - if (!arr.length && this.value) + if (!arr.item(0) && this.value) arr = popup.getElementsByAttribute('value', this.value); - if (arr.length) + if (arr.item(0)) this.selectedItem = arr[0]; else this.selectedIndex = 0; @@ -69,7 +69,7 @@ if (popup) arr = popup.getElementsByAttribute('value', val); - if (arr && arr.length) + if (arr && arr.item(0)) this.selectedItem = arr[0]; else this.setAttribute('value', val); @@ -279,10 +279,7 @@ if (popup) arr = popup.getElementsByAttribute('label', this.inputField.value); - if (arr && arr.length) - this.setSelectionInternal(arr[0]); - else - this.setSelectionInternal(null); + this.setSelectionInternal(arr ? arr.item(0) : null); ]]> diff --git a/xpfe/global/resources/content/bindings/wizard.xml b/xpfe/global/resources/content/bindings/wizard.xml index 8469941c688..59e82f20471 100644 --- a/xpfe/global/resources/content/bindings/wizard.xml +++ b/xpfe/global/resources/content/bindings/wizard.xml @@ -118,7 +118,7 @@ 0 ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType); + return btns.item(0) ? btns[0] : document.getAnonymousElementByAttribute(this._wizardButtons, "dlgtype", aDlgType); ]]> @@ -184,7 +184,7 @@ 0 ? els[0] : null; + return els.item(0); ]]> diff --git a/xpfe/global/resources/content/config.js b/xpfe/global/resources/content/config.js index 67d9277c9bf..ba41733d086 100644 --- a/xpfe/global/resources/content/config.js +++ b/xpfe/global/resources/content/config.js @@ -320,13 +320,13 @@ function onConfigLoad() } var descending = document.getElementsByAttribute("sortDirection", "descending"); - if (descending.length) { + if (descending.item(0)) { gSortedColumn = descending[0].id; gSortDirection = -1; } else { var ascending = document.getElementsByAttribute("sortDirection", "ascending"); - if (ascending.length) + if (ascending.item(0)) gSortedColumn = ascending[0].id; else document.getElementById(gSortedColumn).setAttribute("sortDirection", "ascending");