зеркало из https://github.com/mozilla/pjs.git
Sync tab and friends with the trunk
This commit is contained in:
Родитель
16f13e76be
Коммит
17685e1355
|
@ -11,7 +11,7 @@
|
|||
</resources>
|
||||
</binding>
|
||||
|
||||
<binding id="tabbox"
|
||||
<binding id="tabbox" display="xul:box"
|
||||
extends="chrome://global/content/widgets/tabbox.xml#tab-base">
|
||||
<implementation implements="nsIAccessibleProvider">
|
||||
<property name="accessible">
|
||||
|
@ -109,44 +109,72 @@
|
|||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<field name="_keyEventHandler" readonly="true">
|
||||
<![CDATA[({
|
||||
tabbox: this,
|
||||
handleEvent: function handleEvent(event) {
|
||||
switch (event.keyCode) {
|
||||
case event.DOM_VK_TAB:
|
||||
if (event.ctrlKey && !event.altKey && !event.metaKey)
|
||||
if (this.tabbox._tabs && this.tabbox.handleCtrlTab) {
|
||||
this.tabbox._tabs.advanceSelectedTab(event.shiftKey ? -1 : 1);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
case event.DOM_VK_PAGE_UP:
|
||||
if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
|
||||
if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
|
||||
this.tabbox._tabs.advanceSelectedTab(-1);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
case event.DOM_VK_PAGE_DOWN:
|
||||
if (event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey)
|
||||
if (this.tabbox._tabs && this.tabbox.handleCtrlPageUpDown) {
|
||||
this.tabbox._tabs.advanceSelectedTab(1);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
})]]>
|
||||
</field>
|
||||
|
||||
<field name="_eventNode">
|
||||
var eventNode = this;
|
||||
switch (this.getAttribute("eventnode")) {
|
||||
case "parent": eventNode = this.parentNode; break;
|
||||
case "window": eventNode = window; break;
|
||||
case "document": eventNode = document; break;
|
||||
}
|
||||
eventNode;
|
||||
</field>
|
||||
|
||||
<property name="eventNode" onget="return this._eventNode;">
|
||||
<setter>
|
||||
<![CDATA[
|
||||
if (val != this._eventNode) {
|
||||
val.addEventListener("keypress", this._keyEventHandler, false);
|
||||
this._eventNode.removeEventListener("keypress", this._keyEventHandler, false);
|
||||
this._eventNode = val;
|
||||
}
|
||||
return val;
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<constructor>
|
||||
this._eventNode.addEventListener("keypress", this._keyEventHandler, false);
|
||||
</constructor>
|
||||
|
||||
<destructor>
|
||||
this._eventNode.removeEventListener("keypress", this._keyEventHandler, false);
|
||||
</destructor>
|
||||
</implementation>
|
||||
|
||||
<handlers>
|
||||
<handler event="keypress" keycode="vk_tab" modifiers="control">
|
||||
<![CDATA[
|
||||
if (this._tabs && this.handleCtrlTab) {
|
||||
this._tabs.advanceSelectedTab(1);
|
||||
event.preventDefault();
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
||||
<handler event="keypress" keycode="vk_tab" modifiers="control,shift">
|
||||
<![CDATA[
|
||||
if (this._tabs && this.handleCtrlTab) {
|
||||
this._tabs.advanceSelectedTab(-1);
|
||||
event.preventDefault();
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
||||
<handler event="keypress" keycode="vk_page_up" modifiers="control">
|
||||
<![CDATA[
|
||||
if (this._tabs && this.handleCtrlPageUpDown) {
|
||||
this._tabs.advanceSelectedTab(-1);
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
||||
<handler event="keypress" keycode="vk_page_down" modifiers="control">
|
||||
<![CDATA[
|
||||
if (this._tabs && this.handleCtrlPageUpDown) {
|
||||
this._tabs.advanceSelectedTab(1);
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
<binding id="tabs" display="xul:box"
|
||||
|
@ -162,18 +190,11 @@
|
|||
<![CDATA[
|
||||
// first and last tabs need to be able to have unique styles
|
||||
// and also need to select first tab on startup.
|
||||
var tabs = this.getElementsByTagNameNS(
|
||||
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
"tab");
|
||||
if (tabs.length) {
|
||||
if (tabs.length > 1) {
|
||||
tabs[0].setAttribute("first-tab", "true");
|
||||
tabs[tabs.length - 1].setAttribute("last-tab", "true");
|
||||
}
|
||||
else if (tabs.length == 1)
|
||||
tabs[0].setAttribute("first-tab", "true");
|
||||
}
|
||||
this.selectedItem = tabs[0];
|
||||
if (this.firstChild)
|
||||
this.firstChild.setAttribute("first-tab", "true");
|
||||
if (this.lastChild)
|
||||
this.lastChild.setAttribute("last-tab", "true");
|
||||
this.selectedIndex = 0;
|
||||
var o = this.getAttribute("orient");
|
||||
if (!o)
|
||||
this.setAttribute("orient", "horizontal");
|
||||
|
@ -192,73 +213,70 @@
|
|||
<property name="selectedIndex">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
if (this.childNodes[i].selected)
|
||||
const tabs = this.childNodes;
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
if (tabs.selected)
|
||||
return i;
|
||||
}
|
||||
// throw an exception when no tab is selected (we shouldn't get here)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
]]></getter>
|
||||
|
||||
<setter>
|
||||
<![CDATA[
|
||||
var tabs = this.getElementsByTagNameNS(
|
||||
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
"tab");
|
||||
var tab = tabs.length >= val ? null : tabs[val];
|
||||
if (tab)
|
||||
this.selectedItem = tab;
|
||||
return tab;
|
||||
]]></setter>
|
||||
</property>
|
||||
|
||||
<property name="selectedItem">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
if (this.childNodes[i].selected)
|
||||
return this.childNodes[i];
|
||||
}
|
||||
// throw an exception when no tab is selected (we shouldn't get here)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
]]>
|
||||
</getter>
|
||||
|
||||
<setter>
|
||||
<![CDATA[
|
||||
const tabs = this.childNodes;
|
||||
if (0 <= val && val < tabs.length && !tabs[val].selected) {
|
||||
|
||||
for (var i = 0; i < tabs.length; i++)
|
||||
if (i != val && tabs[i].selected)
|
||||
tabs[i].selected = false;
|
||||
|
||||
tabs[val].selected = true;
|
||||
|
||||
for (var parent = this.parentNode; parent; parent = parent.parentNode) {
|
||||
if (parent.localName == 'tabbox') {
|
||||
var tabpanels = parent._tabpanels;
|
||||
// This will cause an onselect event to fire for the tabpanel element.
|
||||
if (tabpanels)
|
||||
tabpanels.selectedIndex = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fire an onselect event for the tabs element.
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('select', false, true);
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
return val;
|
||||
]]>
|
||||
</setter>
|
||||
</property>
|
||||
|
||||
<property name="selectedItem">
|
||||
<getter>
|
||||
<![CDATA[
|
||||
const tabs = this.childNodes;
|
||||
for (var i = 0; i < tabs.length; i++) {
|
||||
if (tabs[i].selected)
|
||||
return tabs[i];
|
||||
}
|
||||
// throw an exception when no tab is selected (we shouldn't get here)
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
]]>
|
||||
</getter>
|
||||
|
||||
<setter>
|
||||
<![CDATA[
|
||||
if (!val)
|
||||
throw Components.results.NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!val.selected)
|
||||
val.selected = true;
|
||||
var selectedIndex = 0;
|
||||
for (var i = 0; i < this.childNodes.length; i++) {
|
||||
if (this.childNodes[i].selected) {
|
||||
if (this.childNodes[i] != val)
|
||||
this.childNodes[i].selected = false;
|
||||
else
|
||||
selectedIndex = i;
|
||||
}
|
||||
if (!val.selected) {
|
||||
const tabs = this.childNodes;
|
||||
for (var i = 0; i < tabs.length; i++)
|
||||
if (tabs[i] == val)
|
||||
this.selectedIndex = i;
|
||||
}
|
||||
|
||||
// Fire an onselect event for the tabs element.
|
||||
var event = document.createEvent('Events');
|
||||
event.initEvent('select', false, true);
|
||||
this.dispatchEvent(event);
|
||||
|
||||
var parent = this.parentNode;
|
||||
while (parent && parent.localName != 'tabbox')
|
||||
parent = parent.parentNode;
|
||||
|
||||
if (!parent)
|
||||
return val;
|
||||
|
||||
var tabpanels = parent.getElementsByTagNameNS(
|
||||
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
||||
"tabpanels");
|
||||
tabpanels = tabpanels.length ? tabpanels[0] : null;
|
||||
// This will cause an onselect event to fire for the tabpanel element.
|
||||
if (tabpanels)
|
||||
tabpanels.selectedIndex = selectedIndex;
|
||||
return val;
|
||||
]]>
|
||||
</setter>
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
- The Original Code is this file as it was released on
|
||||
- March 28, 2001.
|
||||
-
|
||||
- The Initial Developer of the Original Code is David Hyatt
|
||||
- Portions created by David Hyatt are Copyright (C) 2001
|
||||
- David Hyatt. All Rights Reserved.
|
||||
- The Initial Developer of the Original Code is Peter Annema.
|
||||
- Portions created by Peter Annema are Copyright (C) 2001
|
||||
- Peter Annema. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- David Hyatt <hyatt@netscape.com> (Original Author of <tabbrowser>)
|
||||
|
@ -51,7 +51,7 @@
|
|||
|
||||
<content>
|
||||
<xul:stringbundle src="chrome://global/locale/tabbrowser.properties"/>
|
||||
<xul:tabbox flex="1"
|
||||
<xul:tabbox flex="1" eventnode="document"
|
||||
onselect="if (!('updateCurrentBrowser' in this.parentNode) || event.target.localName != 'tabpanels') return; this.parentNode.updateCurrentBrowser();">
|
||||
<xul:hbox class="tabbrowser-strip chromeclass-toolbar" collapsed="true" tooltip="_child" context="_child">
|
||||
<xul:tooltip onpopupshowing="event.preventBubble(); if (document.tooltipNode.hasAttribute('label')) { this.setAttribute('label', document.tooltipNode.getAttribute('label')); return true; } return false;"/>
|
||||
|
@ -79,6 +79,7 @@
|
|||
</xul:menupopup>
|
||||
|
||||
<xul:tabs class="tabbrowser-tabs" closebutton="true" flex="1"
|
||||
tooltiptextnew="&newTabButton.tooltip;"
|
||||
onclick="this.parentNode.parentNode.parentNode.onTabClick(event);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, this.parentNode.parentNode.parentNode);
|
||||
event.stopPropagation();"
|
||||
|
@ -97,7 +98,7 @@
|
|||
</xul:tabs>
|
||||
</xul:hbox>
|
||||
<xul:tabpanels flex="1" class="plain">
|
||||
<xul:browser type="content-primary" xbl:inherits="tooltip=contenttooltip,contextmenu=contentcontextmenu,autocompletepopup"/>
|
||||
<xul:browser type="content-primary" xbl:inherits="tooltip=contenttooltip,contextmenu=contentcontextmenu"/>
|
||||
</xul:tabpanels>
|
||||
</xul:tabbox>
|
||||
<children/>
|
||||
|
@ -108,6 +109,10 @@
|
|||
.getService(Components.interfaces.nsIPrefService)
|
||||
.getBranch(null);
|
||||
</field>
|
||||
<field name="mURIFixup" readonly="true">
|
||||
Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||
.getService(Components.interfaces.nsIURIFixup);
|
||||
</field>
|
||||
<field name="mTabBox">
|
||||
document.getAnonymousNodes(this)[1]
|
||||
</field>
|
||||
|
@ -350,7 +355,7 @@
|
|||
var newTitle = "";
|
||||
var docTitle;
|
||||
if (this.docShell.contentViewer)
|
||||
docTitle = this.contentDocument.title;
|
||||
docTitle = this.contentTitle;
|
||||
|
||||
if (docTitle) {
|
||||
newTitle += this.ownerDocument.documentElement.getAttribute("titlepreface");
|
||||
|
@ -383,23 +388,12 @@
|
|||
if (this.mCurrentBrowser)
|
||||
this.mCurrentBrowser.setAttribute("type", "content");
|
||||
|
||||
var updatePageReport = false;
|
||||
if ((this.mCurrentBrowser.pageReport && !newBrowser.pageReport) ||
|
||||
(!this.mCurrentBrowser.pageReport && newBrowser.pageReport))
|
||||
updatePageReport = true;
|
||||
|
||||
newBrowser.setAttribute("type", "content-primary");
|
||||
this.mCurrentBrowser = newBrowser;
|
||||
this.mCurrentTab = this.selectedTab;
|
||||
|
||||
if (updatePageReport)
|
||||
this.mCurrentBrowser.updatePageReport();
|
||||
|
||||
// Update the URL bar.
|
||||
var loc = this.mCurrentBrowser.currentURI;
|
||||
if (!loc)
|
||||
loc = ({ spec: "" });
|
||||
|
||||
var webProgress = this.mCurrentBrowser.webProgress;
|
||||
var securityUI = this.mCurrentBrowser.securityUI;
|
||||
var i, p;
|
||||
|
@ -552,18 +546,38 @@
|
|||
<body>
|
||||
<![CDATA[
|
||||
var browser = this.getBrowserForTab(aTab);
|
||||
var title = browser.contentTitle;
|
||||
var crop = "end";
|
||||
var titleViaGetter = browser.contentDocument.__proto__.__lookupGetter__('title').call(browser.contentDocument);
|
||||
var title;
|
||||
|
||||
if (titleViaGetter)
|
||||
title = titleViaGetter
|
||||
else if (browser.currentURI.spec && browser.currentURI.spec != "about:blank") {
|
||||
title = browser.currentURI.spec;
|
||||
crop = "center";
|
||||
if (!title) {
|
||||
if (browser.currentURI.spec) {
|
||||
try {
|
||||
title = this.mURIFixup.createExposableURI(browser.currentURI).spec;
|
||||
}
|
||||
catch(ex) {
|
||||
title = browser.currentURI.spec;
|
||||
}
|
||||
}
|
||||
|
||||
if (title && title != "about:blank") {
|
||||
// At this point, we now have a URI.
|
||||
// Let's try to unescape it using a character set
|
||||
// in case the URI is not ASCII.
|
||||
try {
|
||||
var characterSet = Components.lookupMethod(browser.contentDocument, 'characterSet')
|
||||
.call(browser.contentDocument);
|
||||
const textToSubURI = Components.classes["@mozilla.org/intl/texttosuburi;1"]
|
||||
.getService(Components.interfaces.nsITextToSubURI);
|
||||
title = textToSubURI.unEscapeNonAsciiURI(characterSet, title);
|
||||
}
|
||||
catch(ex) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
crop = "center";
|
||||
} else // Still no title? Fall back to our untitled string.
|
||||
title = this.mStringBundle.getString("tabs.untitled");
|
||||
}
|
||||
else
|
||||
title = this.mStringBundle.getString("tabs.untitled");
|
||||
|
||||
aTab.label = title;
|
||||
aTab.setAttribute("crop", crop);
|
||||
|
@ -603,9 +617,9 @@
|
|||
<![CDATA[
|
||||
this.mTabbedMode = true; // Welcome to multi-tabbed mode.
|
||||
|
||||
// Get the first tab all hooked up with a title listener and popup blocking listener.
|
||||
// Get the first tab all hooked up with a title listener.
|
||||
this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, false);
|
||||
|
||||
|
||||
this.setTabTitle(this.mCurrentTab);
|
||||
|
||||
// Hook up our favicon.
|
||||
|
@ -773,7 +787,7 @@
|
|||
this.mTabFilters.splice(index, 1);
|
||||
this.mTabListeners.splice(index, 1);
|
||||
|
||||
// Remove our title change and blocking listeners
|
||||
// Remove our title change listener
|
||||
oldBrowser.removeEventListener("DOMTitleChanged", this.onTitleChanged, false);
|
||||
|
||||
// We are no longer the primary content area.
|
||||
|
@ -782,9 +796,6 @@
|
|||
// Now select the new tab before nuking the old one.
|
||||
var currentIndex = this.mPanelContainer.selectedIndex;
|
||||
|
||||
// Now select the new tab before nuking the old one.
|
||||
var currentIndex = this.mPanelContainer.selectedIndex;
|
||||
|
||||
var newIndex = -1;
|
||||
if (currentIndex > index)
|
||||
newIndex = currentIndex-1;
|
||||
|
@ -800,9 +811,6 @@
|
|||
// clean up the before/afterselected attributes before removing the tab
|
||||
oldTab.selected = false;
|
||||
|
||||
// XXX browser's destructor isn't always called, so we force a cleanup ourselves
|
||||
oldBrowser.destroy();
|
||||
|
||||
this.mTabContainer.removeChild(oldTab);
|
||||
this.mPanelContainer.removeChild(oldBrowser);
|
||||
|
||||
|
@ -1096,10 +1104,6 @@
|
|||
</body>
|
||||
</method>
|
||||
|
||||
<property name="pageReport"
|
||||
onget="return this.mCurrentBrowser.pageReport;"
|
||||
readonly="true"/>
|
||||
|
||||
<property name="currentURI"
|
||||
onget="return this.mCurrentBrowser.currentURI;"
|
||||
readonly="true"/>
|
||||
|
@ -1148,6 +1152,10 @@
|
|||
onget="return this.mCurrentBrowser.contentDocument;"
|
||||
readonly="true"/>
|
||||
|
||||
<property name="contentTitle"
|
||||
onget="return this.mCurrentBrowser.contentTitle;"
|
||||
readonly="true"/>
|
||||
|
||||
<property name="securityUI"
|
||||
onget="return this.mCurrentBrowser.securityUI;"
|
||||
readonly="true"/>
|
||||
|
@ -1156,7 +1164,6 @@
|
|||
<![CDATA[
|
||||
this.mCurrentBrowser = this.mPanelContainer.firstChild;
|
||||
this.mCurrentTab = this.mTabContainer.firstChild;
|
||||
this.mTabBox.setAttribute("handleCtrlTab", "false");
|
||||
]]>
|
||||
</constructor>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче