Bug 398344 - "utilityOverlay.js isElementVisible() is slow" [p=dao r=Mano r=gavin a1.9=schrep]

git-svn-id: svn://10.0.0.236/trunk@237413 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
reed%reedloden.com 2007-10-08 20:17:14 +00:00
parent 085b0db51e
commit 924abe3d9b
6 changed files with 62 additions and 72 deletions

View File

@ -2728,68 +2728,53 @@ const DOMLinkHandler = {
const BrowserSearch = {
addEngine: function(engine, targetDoc) {
// Set the attribute of the (first) search-engine button.
var searchButton = document.getAnonymousElementByAttribute(this.getSearchBar(), "anonid",
"searchbar-engine-button");
if (searchButton) {
var browser = gBrowser.getBrowserForDocument(targetDoc);
// Append the URI and an appropriate title to the browser data.
var iconURL = null;
if (gBrowser.shouldLoadFavIcon(browser.currentURI))
iconURL = browser.currentURI.prePath + "/favicon.ico";
if (!this.searchBar)
return;
var browser = gBrowser.getBrowserForDocument(targetDoc);
// Append the URI and an appropriate title to the browser data.
var iconURL = null;
if (gBrowser.shouldLoadFavIcon(browser.currentURI))
iconURL = browser.currentURI.prePath + "/favicon.ico";
var hidden = false;
// If this engine (identified by title) is already in the list, add it
// to the list of hidden engines rather than to the main list.
// XXX This will need to be changed when engines are identified by URL;
// see bug 335102.
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
if (searchService.getEngineByName(engine.title))
hidden = true;
var hidden = false;
// If this engine (identified by title) is already in the list, add it
// to the list of hidden engines rather than to the main list.
// XXX This will need to be changed when engines are identified by URL;
// see bug 335102.
var searchService = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
if (searchService.getEngineByName(engine.title))
hidden = true;
var engines = [];
if (hidden) {
if (browser.hiddenEngines)
engines = browser.hiddenEngines;
}
else {
if (browser.engines)
engines = browser.engines;
}
var engines = (hidden ? browser.hiddenEngines : browser.engines) || [];
engines.push({ uri: engine.href,
title: engine.title,
icon: iconURL });
engines.push({ uri: engine.href,
title: engine.title,
icon: iconURL });
if (hidden)
browser.hiddenEngines = engines;
else {
browser.engines = engines;
if (browser == gBrowser || browser == gBrowser.mCurrentBrowser)
this.updateSearchButton();
}
if (hidden)
browser.hiddenEngines = engines;
else {
browser.engines = engines;
if (browser == gBrowser || browser == gBrowser.mCurrentBrowser)
this.updateSearchButton();
}
},
/**
* Update the browser UI to show whether or not additional engines are
* available when a page is loaded or the user switches tabs to a page that
* has search engines.
* has search engines.
*/
updateSearchButton: function() {
var searchButton = document.getAnonymousElementByAttribute(this.getSearchBar(),
"anonid", "searchbar-engine-button");
if (!searchButton)
var searchBar = this.searchBar;
if (!searchBar)
return;
var engines = gBrowser.mCurrentBrowser.engines;
if (!engines || engines.length == 0) {
if (searchButton.hasAttribute("addengines"))
searchButton.removeAttribute("addengines");
}
else {
searchButton.setAttribute("addengines", "true");
}
if (engines && engines.length > 0)
searchBar.searchButton.setAttribute("addengines", "true");
else
searchBar.searchButton.removeAttribute("addengines");
},
/**
@ -2821,8 +2806,8 @@ const BrowserSearch = {
return;
}
#endif
var searchBar = this.getSearchBar();
if (searchBar) {
var searchBar = this.searchBar;
if (isElementVisible(searchBar)) {
searchBar.select();
searchBar.focus();
} else {
@ -2851,7 +2836,7 @@ const BrowserSearch = {
// If the search bar is visible, use the current engine, otherwise, fall
// back to the default engine.
if (this.getSearchBar())
if (isElementVisible(this.searchBar))
engine = ss.currentEngine;
else
engine = ss.defaultEngine;
@ -2873,15 +2858,10 @@ const BrowserSearch = {
},
/**
* Returns the search bar element if it is present in the toolbar and not
* hidden, null otherwise.
* Returns the search bar element if it is present in the toolbar, null otherwise.
*/
getSearchBar: function BrowserSearch_getSearchBar() {
var searchBar = document.getElementById("searchbar");
if (searchBar && isElementVisible(searchBar))
return searchBar;
return null;
get searchBar() {
return document.getElementById("searchbar");
},
loadAddEngines: function BrowserSearch_loadAddEngines() {

View File

@ -1042,7 +1042,7 @@ nsContextMenu.prototype = {
var engineName = "";
var ss = Cc["@mozilla.org/browser/search-service;1"].
getService(Ci.nsIBrowserSearchService);
if (BrowserSearch.getSearchBar())
if (isElementVisible(BrowserSearch.searchBar))
engineName = ss.currentEngine.name;
else
engineName = ss.defaultEngine.name;

View File

@ -486,13 +486,13 @@ function buildHelpMenu()
function isElementVisible(aElement)
{
// * When an element is hidden, the width and height of its boxObject
// are set to 0
// * css-visibility (unlike css-display) is inherited.
if (!aElement)
return false;
// If aElement or a direct or indirect parent is hidden or collapsed,
// height, width or both will be 0.
var bo = aElement.boxObject;
return (bo.height != 0 && bo.width != 0 &&
document.defaultView
.getComputedStyle(aElement, null).visibility == "visible");
return (bo.height > 0 && bo.width > 0);
}
function getBrowserFromContentWindow(aContentWindow)

View File

@ -354,7 +354,7 @@ var BookmarkPropertiesPanel = {
this._folderMenuList = this._element("folderMenuList");
this._folderTree = this._element("folderTree");
if (isElementVisible(this._folderMenuList))
if (!this._element("folderRow").hidden)
this._initFolderMenuList();
window.sizeToContent();
@ -896,7 +896,7 @@ var BookmarkPropertiesPanel = {
*/
_getInsertionPointDetails: function BPP__getInsertionPointDetails() {
var containerId, indexInContainer = -1;
if (isElementVisible(this._folderMenuList))
if (!this._element("folderRow").hidden)
containerId = this._getFolderIdFromMenuList();
else {
containerId = this._defaultInsertionPoint.itemId;

View File

@ -649,7 +649,7 @@ var gEditItemOverlay = {
}
// Update folder-tree selection
if (isElementVisible(this._folderTree)) {
if (!this._folderTree.collapsed) {
var selectedNode = this._folderTree.selectedNode;
if (!selectedNode || selectedNode.itemId != container)
this._folderTree.selectFolders([container]);
@ -702,7 +702,7 @@ var gEditItemOverlay = {
toggleTagsSelector: function EIO_toggleTagsSelector() {
var tagsSelector = this._element("tagsSelector");
var expander = this._element("tagsSelectorExpander");
if (!isElementVisible(tagsSelector)) {
if (tagsSelector.collapsed) {
expander.className = "expander-up";
expander.setAttribute("tooltiptext",
expander.getAttribute("tooltiptextup"));
@ -711,14 +711,14 @@ var gEditItemOverlay = {
// This is a no-op if we've added the listener.
tagsSelector.addEventListener("CheckboxStateChange", this, false);
tagsSelector.collapsed = false;
}
else {
expander.className = "expander-down";
expander.setAttribute("tooltiptext",
expander.getAttribute("tooltiptextdown"));
tagsSelector.collapsed = true;
}
tagsSelector.collapsed = !tagsSelector.collapsed;
},
_getTagsArrayFromTagField: function EIO__getTagsArrayFromTagField() {

View File

@ -161,6 +161,16 @@
<field name="_ss">null</field>
<field name="_engines">null</field>
<property name="searchButton" readonly="true">
<getter><![CDATA[
if (!this._searchButton) {
this._searchButton = document.getAnonymousElementByAttribute(
this, "anonid", "searchbar-engine-button");
}
return this._searchButton;
]]></getter>
</property>
<property name="currentEngine"
onset="this.searchService.currentEngine = val; return val;">
<getter><![CDATA[