Fix for 32087, custom icon support in tabs and url bar. r=andreww, sr=hewitt

This commit is contained in:
hyatt%netscape.com 2007-03-31 23:06:32 +00:00
Родитель c9231caf80
Коммит 15a937db48
3 изменённых файлов: 147 добавлений и 18 удалений

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

@ -69,7 +69,7 @@
onclick="if (event.button != 1 || event.target.localName != 'tab') return; this.parentNode.parentNode.parentNode.removeTab(event.target);"
ondragover="nsDragAndDrop.dragOver(event, this.parentNode.parentNode.parentNode); event.stopPropagation();"
ondragdrop="nsDragAndDrop.drop(event, this.parentNode.parentNode.parentNode); event.stopPropagation();">
<xul:tab maxwidth="250" width="0" minwidth="30" flex="100000" class="tabbrowser-tab" label="&untitledTab;" crop="end"/>
<xul:tab validate="never" onerror="this.removeAttribute('image');" maxwidth="250" width="0" minwidth="30" flex="100000" class="tabbrowser-tab" label="&untitledTab;" crop="end"/>
</xul:tabs>
</xul:stack>
<xul:tabpanels flex="1" style="margin:0px; padding:0px; border:0px;">
@ -124,6 +124,7 @@
mTabBrowser: aTabBrowser,
mTab: aTab,
mBlank: aStartsBlank,
mIcon: "",
onProgressChange : function (aWebProgress, aRequest,
aCurSelfProgress, aMaxSelfProgress,
@ -156,7 +157,9 @@
aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
this.mTab.setAttribute("busy", "true");
this.mTab.label = this.mTabBrowser.mStringBundle.getString("tabs.loading");
this.mTab.removeAttribute("image");
this.mIcon = "";
if (this.mTabBrowser.mCurrentTab == this.mTab)
this.mTabBrowser.mIsBusy = true;
}
@ -164,14 +167,22 @@
aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
if (this.mBlank)
this.mBlank = false;
else {
this.mTab.removeAttribute("busy");
if (this.mTab.label == this.mTabBrowser.mStringBundle.getString("tabs.loading"))
this.mTab.label = this.mTabBrowser.mStringBundle.getString("tabs.untitled")
if (this.mTabBrowser.mCurrentTab == this.mTab)
this.mTabBrowser.mIsBusy = false;
this.mTab.removeAttribute("busy");
var location = aRequest.QueryInterface(nsIChannel).URI;
if (this.mIcon) {
this.mTab.setAttribute("image", this.mIcon);
mIcon = "";
}
else if (pref.getBoolPref("browser.chrome.site_icons") && location && (location.schemeIs("http") || location.schemeIs("https")))
this.mTab.setAttribute("image", this.mTabBrowser.buildFavIconString(location));
if (this.mTab.label == this.mTabBrowser.mStringBundle.getString("tabs.loading"))
this.mTab.label = this.mTabBrowser.mStringBundle.getString("tabs.untitled")
if (this.mTabBrowser.mCurrentTab == this.mTab)
this.mTabBrowser.mIsBusy = false;
}
if (!oldBlank && this.mTabBrowser.mCurrentTab == this.mTab) {
@ -232,6 +243,16 @@
</body>
</method>
<method name="buildFavIconString">
<parameter name="aURI"/>
<body>
<![CDATA[
var end = (aURI.port == -1) ? "/favicon.ico" : (":" + aURI.port + "/favicon.ico");
return aURI.scheme + "://" + aURI.host + end;
]]>
</body>
</method>
<method name="updateTitlebar">
<body>
<![CDATA[
@ -263,16 +284,20 @@
this.mCurrentTab = this.selectedTab;
// Update the URL bar.
var loc = ({ spec: this.mCurrentBrowser.contentWindow.location.href });
if (loc.spec == "about:blank")
loc.spec = "";
var loc = this.mCurrentBrowser.currentURI;
if (!loc)
loc = ({ spec: "" });
var webProgress = this.mCurrentBrowser.webProgress;
var i, p;
for (i = 0; i < this.mProgressListeners.length; i++) {
p = this.mProgressListeners[i];
if (p)
if (p) {
p.onLocationChange(webProgress, null, loc);
var listener = this.mTabListeners[this.mPanelContainer.selectedIndex];
if (listener.mIcon)
p.onLinkIconAvailable(listener.mIcon);
}
}
// Update the window title.
@ -309,6 +334,75 @@
</body>
</method>
<method name="createCloseBox">
<body>
<![CDATA[
var img = document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'image');
img.setAttribute('class', 'tabbrowser-closebox');
img.setAttribute('label', 'Close Tab');
img.setAttribute('onclick', "var node = this.parentNode; while (node.localName != 'tabbrowser') node = node.parentNode; node.removeCurrentTab();");
var tabdec = document.getAnonymousElementByAttribute(this.mTabContainer, "class", "tabs-misc-dec");
tabdec.appendChild(img);
]]>
</body>
</method>
<method name="onLinkAdded">
<parameter name="event"/>
<body>
<![CDATA[
if (event.target.rel.indexOf("icon") == -1)
return;
// We have an icon.
var href = event.target.href;
if (!href)
return;
// Verify that the load of this icon is legal. We use the same
// content policy that is used for a Web page loading images.
var contentPolicy = Components.classes['@mozilla.org/layout/content-policy;1'].getService(Components.interfaces.nsIContentPolicy);
if (!contentPolicy)
return; // Refuse to load if we can't do a security check.
// Make a URI out of our href.
var uri = Components.classes['@mozilla.org/network/standard-url;1'].createInstance();
uri = uri.QueryInterface(Components.interfaces.nsIURI);
var tabBrowser = this.parentNode.parentNode;
var notifyListeners = true;
if (tabBrowser.mTabbedMode) {
// We need to update a tab.
var i = 0;
for ( ; i < this.childNodes.length; i++) {
if (this.childNodes[i].contentDocument == event.target.ownerDocument) {
if (!contentPolicy.shouldLoad(Components.interfaces.nsIContentPolicy.IMAGE,
uri, event.target, this.childNodes[i].contentWindow))
return;
var listener = tabBrowser.mTabListeners[i];
listener.mIcon = href;
break;
}
}
notifyListeners = (this.childNodes[i] == tabBrowser.mCurrentBrowser);
}
else if (!contentPolicy.shouldLoad(Components.interfaces.nsIContentPolicy.IMAGE,
uri, event.target, tabBrowser.mCurrentBrowser.contentWindow))
return;
if (notifyListeners && tabBrowser.mProgressListeners) {
for (var i = 0; i < tabBrowser.mProgressListeners.length; i++) {
var p = tabBrowser.mProgressListeners[i];
if (p)
p.onLinkIconAvailable(href);
}
}
]]>
</body>
</method>
<method name="onTitleChanged">
<parameter name="evt"/>
<body>
@ -367,9 +461,18 @@
// Going from one tab to two for the first time. Get the first tab all hooked up with a title listener.
this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, false);
if (this.mCurrentBrowser.contentDocument.title != "")
this.mCurrentTab.label = this.mCurrentBrowser.contentDocument.title;
// Create our close box.
this.createCloseBox();
// Hook up our favicon.
var uri = this.mCurrentBrowser.currentURI;
if (pref.getBoolPref("browser.chrome.site_icons") && uri && (uri.schemeIs('http') || uri.schemeIs('https')))
this.mCurrentTab.setAttribute("image", this.buildFavIconString(uri));
// Remove all our progress listeners from the active browser.
if (this.mProgressListeners) {
for (var i = 0; i < this.mProgressListeners.length; i++) {
@ -400,7 +503,8 @@
t.minWidth = 30;
t.width = 0;
t.setAttribute("flex", "100000");
t.setAttribute("validate", "never");
t.setAttribute("onerror", "this.removeAttribute('image');");
this.mTabContainer.appendChild(t);
b.setAttribute("type", "content");
@ -470,7 +574,7 @@
if (l == 1)
return; // Don't allow the last tab to close.
if (l == 2) {
if (l == 2) {
var pref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch(null);
var autohide = pref.getBoolPref("browser.tabs.autoHide");
if (autohide)
@ -494,7 +598,7 @@
// Remove our title change listener
oldBrowser.removeEventListener("DOMTitleChanged", this.onTitleChanged, false);
// We are no longer the primary content area.
oldBrowser.setAttribute("type", "content");
@ -562,12 +666,18 @@
this.mTabbedMode = true;
this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, false);
// Create our close box.
this.createCloseBox();
// Wire up a progress listener to our tab.
var listener = (this.mTabProgressListener)(this, this.mCurrentTab);
this.webProgress.addProgressListener(listener);
this.mTabListeners[0] = listener;
}
// Hook up a listener for <link>s.
this.mPanelContainer.addEventListener("DOMLinkAdded", this.onLinkAdded, false);
}
this.mProgressListeners.push(aListener);
@ -883,6 +993,7 @@
this.mPanelContainer.childNodes[i].removeEventListener("DOMTitleChanged", this.onTitleChanged, false);
}
}
this.mPanelContainer.removeEventListener("DOMLinkAdded", this.onLinkAdded, false);
]]>
</destructor>
</implementation>

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

@ -1,7 +1,15 @@
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
tab[busy] {
.tab-image {
margin-top: 1px;
margin-right: 3px;
width: 16px;
height: 16px;
list-style-image: url("chrome://communicator/skin/bookmarks/bookmark-item.gif");
}
tab[busy] > .tab-box > .tab-image {
list-style-image: url("chrome://global/skin/loading.gif");
}
@ -9,4 +17,5 @@ tab[busy] {
list-style-image: url("chrome://global/skin/closebox.gif");
margin-bottom: 3px;
margin-right: 2px;
margin-left: 4px;
}

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

@ -1,7 +1,15 @@
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
tab[busy] {
.tab-icon {
margin-top: 1px;
margin-right: 3px;
width: 16px;
height: 16px;
list-style-image: url("chrome://communicator/skin/bookmarks/bookmark-item.gif");
}
tab[busy] > .tab-mid > .tab-mid-mid > .tab-icon {
list-style-image: url("chrome://communicator/skin/icons/loading.gif");
}
@ -9,4 +17,5 @@ tab[busy] {
list-style-image: url("chrome://global/skin/icons/closebox.gif");
margin-bottom: 3px;
margin-right: 2px;
margin-left: 4px;
}