canmove, Confirmed users
2,056
edits
(make the set of changes discussed in the forum) |
(revise and expand spec based on pre-implementation review) |
||
Line 1: | Line 1: | ||
= JEP 110 - Tabs = | |||
* Champion: | * Champion: Myk Melez <myk@mozilla.org> | ||
* Status: | * Status: Approved | ||
* Bug Ticket: | * Bug Ticket: {{bug|549317}} | ||
* Type: API | * Type: API | ||
= Introduction = | |||
Tabs are a fundamental element of the browser. Add-ons should have access to them. | |||
= Use Cases = | |||
* move a tab to be the first tab, or re-order tabs based on semantic grouping; | |||
* close a set of tabs; | |||
* open a new tab to a contextually aware location; | |||
* change the background color of the currently active tab; | |||
* change the color of the background of a tab-handle; | |||
* show the Delicious tab-o-meter of the current tab. | |||
= Interface = | |||
== <tt>tabs</tt> module == | |||
/ | The <tt>tabs</tt> module provides the API. It exports one symbol: the <tt>tabs</tt> singleton. | ||
let tabs = require("tabs").tabs; | |||
tabs | |||
/ | == <tt>tabs</tt> singleton == | ||
=== Properties === | |||
/ | The <tt>tabs</tt> singleton has one property, <tt>activeTab</tt>, which is a <tt>Tab</tt> object that represents the currently active tab. | ||
=== Methods === | |||
/ | The <tt>tabs</tt> singleton has one method, <tt>open</tt>, which opens a new tab: | ||
/** | /** | ||
* Open a new tab. | |||
* @param url {URL} the URL to load in the tab; optional; | |||
* if not provided, about:blank will be loaded in the tab | |||
* @param window {Window} the window in which to open the tab; | |||
* optional; if not provided, the tab will be opened | |||
* in the most recently active application window | |||
**/ | **/ | ||
tabs.open(url, window) | tabs.open(url, window) | ||
=== Callbacks === | |||
/ | The <tt>tabs</tt> singleton has a number of event callback properties with which consumers can register callback functions via the standard mechanisms as described in the [[Labs/Jetpack/Design_Guidelines|design guidelines]]: | ||
; onActivate: a tab is activated, whether programmatically or by user action (clicking on the tab, switching windows, etc.) | |||
; onDeactivate: a tab is deactivated | |||
; onOpen: a tab is opened | |||
; onClose: a tab is closed | |||
tab. | ; onDOMReady: the text content of a top-level document in a tab has been loaded and parsed into a DOMDocument object (i.e. the <tt>DOMContentLoaded</tt> event has occurred) | ||
; onLoad: the text, image, style, and script content of a top-level document in a tab has been loaded (i.e. the DOM <tt>load</tt> event has occurred) | |||
; onPaint: the visual representation of a top-level document in a tab has changed (i.e. the <tt>MozAfterPaint</tt> event has occurred) | |||
When a callback function is called, its first parameter is an <tt>Event</tt> object representing the event that occurred, and its second parameter is a <tt>Tab</tt> object representing the tab on which it occurred, i.e.: | |||
tab. | |||
tabs.onActivate = function(event, tab) { ... }; | |||
/ | When the <tt>tabs</tt> singleton is iterated via <tt>[https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/for_each...in for each...in]</tt>, it yields a sequence of <tt>Tab</tt> objects representing the tabs in all application windows: | ||
for each (let tab in tabs) { ... } | |||
The order by which tabs are returned in the iteration is not specified, may change in the future, and should not be counted upon. | |||
/ | == <tt>Tab</tt> objects == | ||
=== Properties === | |||
/ | <tt>Tab</tt> objects have the following properties: | ||
/** | /** | ||
* The properties for the tabs. | |||
* @prop title {String} | |||
* the title of the page currently loaded in the tab | |||
* @prop location {URL} | |||
* the URL of the page currently loaded in the tab | |||
**/ | * @prop contentWindow {DOMWindow} | ||
tab. | * the window object for the page currently loaded in the tab | ||
* @prop contentDocument {DOMDocument} | |||
* the document object for the page currently loaded in the tab | |||
* @prop favicon {URL} | |||
* the URL of the favicon for the page currently loaded in the tab | |||
* @prop style {String} | |||
* the CSS style for the tab | |||
* @prop index {Number} | |||
* the index of the tab relative to other tabs in the application window | |||
* @prop window {Window} | |||
* the window to which the tab belongs | |||
* @prop thumbnail {Canvas} | |||
* a thumbnail of the page currently loaded in the tab | |||
**/ | |||
tab.property | |||
=== Methods === | |||
</ | <tt>Tab</tt> objects have the following methods: | ||
/** | |||
* Make this the active tab. | |||
**/ | |||
tab.activate() | |||
/** | |||
* Load a URL in the tab. | |||
* @param url {URL} the URL to load in the tab | |||
**/ | |||
tab.load(url) | |||
/** | |||
* Close the tab. | |||
**/ | |||
tab.close() | |||
/** | |||
* Move the tab within the window-specific set of tabs to which it belongs. | |||
* @param index {Number} | |||
* the new location in the tab set | |||
* @param window {Window} | |||
* the new window; optional if moving to a new location | |||
* within the existing window | |||
**/ | |||
tab.move(index, window) | |||
=== Callbacks === | |||
<tt>Tab</tt> objects have the same event callback properties as the <tt>tabs</tt> singleton, except that they don't have the <tt>onOpen</tt> callback. | |||
= Implementation Phases = | |||
=== | == Phase One == | ||
In the first phase of development, the following elements of the API should be implemented: | |||
* <tt>tabs</tt> singleton | |||
* | ** properties: | ||
*** activeTab | |||
** methods: | |||
*** open | |||
* | ** callbacks: | ||
*** onActivate | |||
*** onDeactivate | |||
*** onOpen | |||
*** onClose | |||
* | *** onLoad | ||
* | * <tt>Tab</tt> objects | ||
* | ** properties | ||
* | *** title | ||
* | *** location | ||
* | *** contentWindow | ||
*** contentDocument | |||
** methods | |||
*** activate | |||
*** load | |||
*** close | |||
** callbacks | |||
*** onActivate | |||
*** onDeactivate | |||
*** onClose | |||
*** onLoad |