1 // Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
2 // Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
3 // Copyright (c) 2008-2011 by Kris Maglione <maglione.k@gmail.com>
5 // This work is licensed for reuse under an MIT license. Details are
6 // given in the LICENSE.txt file included with this file.
11 var StatusLine = Module("statusline", {
12 init: function init() {
13 this._statusLine = document.getElementById("status-bar");
14 this.statusBar = document.getElementById("addon-bar") || this._statusLine;
15 this.baseGroup = this.statusBar == this._statusLine ? "StatusLine " : "";
17 if (this.statusBar.localName == "toolbar") {
18 styles.system.add("addon-bar", config.styleableChrome, <css><![CDATA[
19 #status-bar { margin-top: 0 !important; }
20 #addon-bar > statusbar { -moz-box-flex: 1 }
21 #addon-bar > #addonbar-closebutton { visibility: collapse; }
22 #addon-bar > xul|toolbarspring { visibility: collapse; }
25 overlay.overlayWindow(window, { append: <><statusbar id="status-bar" ordinal="0"/></> });
27 highlight.loadCSS(util.compileMacro(<![CDATA[
28 !AddonBar;#addon-bar {
30 padding-left: 0 !important;
31 min-height: 18px !important;
32 -moz-appearance: none !important;
35 !AddonButton;#addon-bar xul|toolbarbutton {
36 /* An Add-on Bar button */
37 -moz-appearance: none !important;
38 padding: 0 !important;
39 border-width: 0px !important;
40 min-width: 0 !important;
41 color: inherit !important;
43 AddonButton:not(:hover) background: transparent;
44 ]]>)({ padding: config.OS.isMacOSX ? "padding-right: 10px !important;" : "" }));
46 if (document.getElementById("appmenu-button"))
47 highlight.loadCSS(<![CDATA[
48 AppmenuButton /* The app-menu button */ \
49 min-width: 0 !important; padding: 0 .5em !important;
53 XML.ignoreWhitespace = true;
54 let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
55 let prepend = <e4x xmlns={XUL} xmlns:dactyl={NS}>
56 <button id="appmenu-button" label="" image="chrome://branding/content/icon16.png" highlight="AppmenuButton" />
57 <toolbarbutton id="appmenu-toolbar-button" label="" image="chrome://branding/content/icon16.png" />
58 <statusbar id="status-bar" highlight="StatusLine">
59 <!-- insertbefore="dactyl.statusBefore;" insertafter="dactyl.statusAfter;" -->
60 <hbox key="container" hidden="false" align="center" flex="1">
61 <stack orient="horizontal" align="stretch" flex="1" highlight="CmdLine StatusCmdLine" class="dactyl-container">
62 <hbox highlight="CmdLine StatusCmdLine" class="dactyl-container">
63 <label key="mode" crop="end" class="plain" collapsed="true"/>
64 <stack id="dactyl-statusline-stack" flex="1" highlight="CmdLine StatusCmdLine" class="dactyl-container">
65 <textbox key="url" crop="end" flex="1" style="background: transparent;" class="plain dactyl-status-field-url" readonly="true"/>
66 <textbox key="message" crop="end" flex="1" highlight="Normal StatusNormal" class="plain" readonly="true"/>
70 <label class="plain" key="inputbuffer" flex="0"/>
71 <label class="plain" key="progress" flex="0"/>
72 <label class="plain" key="tabcount" flex="0"/>
73 <label class="plain" key="bufferposition" flex="0"/>
74 <label class="plain" key="zoomlevel" flex="0"/>
76 <!-- just hide them since other elements expect them -->
77 <statusbarpanel id="statusbar-display" hidden="true"/>
78 <statusbarpanel id="statusbar-progresspanel" hidden="true"/>
82 for each (let attr in prepend..@key)
83 attr.parent().@id = "dactyl-statusline-field-" + attr;
85 overlay.overlayWindow(window, {
86 objects: this.widgets = { get status() this.container },
87 prepend: prepend.elements()
91 this.security = content.document.dactylSecurity || "insecure";
96 get visible() !this.statusBar.collapsed && !this.statusBar.hidden,
99 "browser.locationChange": function (webProgress, request, uri) {
100 let win = webProgress.DOMWindow;
102 this.progress = uri && win && win.dactylProgress || "";
104 // if this is not delayed we get the position of the old buffer
105 this.timeout(function () {
106 this.updateBufferPosition();
107 this.updateZoomLevel();
110 "browser.overLink": function (link) {
111 switch (options["showstatuslinks"]) {
113 this.status = link ? _("status.link", link) : buffer.uri;
117 dactyl.echo(_("status.link", link), commandline.FORCE_SINGLELINE);
123 "browser.progressChange": function onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
124 if (webProgress && webProgress.DOMWindow)
125 webProgress.DOMWindow.dactylProgress = curTotalProgress / maxTotalProgress;
126 this.progress = curTotalProgress / maxTotalProgress;
128 "browser.securityChange": function onSecurityChange(webProgress, request, state) {
130 if (state & Ci.nsIWebProgressListener.STATE_IS_BROKEN)
131 this.security = "broken";
132 else if (state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
133 this.security = "extended";
134 else if (state & Ci.nsIWebProgressListener.STATE_SECURE_HIGH)
135 this.security = "secure";
136 else // if (state & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
137 this.security = "insecure";
139 if (webProgress && webProgress.DOMWindow)
140 webProgress.DOMWindow.document.dactylSecurity = this.security;
142 "browser.stateChange": function onStateChange(webProgress, request, flags, status) {
143 const L = Ci.nsIWebProgressListener;
145 if (flags & (L.STATE_IS_DOCUMENT | L.STATE_IS_WINDOW))
146 if (flags & L.STATE_START)
148 else if (flags & L.STATE_STOP)
151 if (flags & L.STATE_STOP)
154 "browser.statusChange": function onStatusChange(webProgress, request, status, message) {
155 this.timeout(function () {
156 this.status = message || buffer.uri;
162 * Update the status bar to indicate how secure the website is:
163 * extended - Secure connection with Extended Validation(EV) certificate.
164 * secure - Secure connection with valid certificate.
165 * broken - Secure connection with invalid certificate, or
167 * insecure - Insecure connection.
169 * @param {'extended'|'secure'|'broken'|'insecure'} type
172 this._security = type;
173 const highlightGroup = {
174 extended: "StatusLineExtended",
175 secure: "StatusLineSecure",
176 broken: "StatusLineBroken",
177 insecure: "StatusLineNormal"
180 highlight.highlightNode(this.statusBar, this.baseGroup + highlightGroup[type]);
182 get security() this._security,
184 // update all fields of the statusline
185 update: function update() {
187 this.inputBuffer = "";
189 this.updateTabCount();
190 this.updateBufferPosition();
191 this.updateZoomLevel();
194 unsafeURI: deprecated("util.unsafeURI", { get: function unsafeURI() util.unsafeURI }),
195 losslessDecodeURI: deprecated("util.losslessDecodeURI", function losslessDecodeURI() util.losslessDecodeURI.apply(util, arguments)),
198 * Update the URL displayed in the status line. Also displays status
199 * icons, [+-♥], when there are next and previous pages in the
200 * current tab's history, and when the current URL is bookmarked,
203 * @param {string} url The URL to display.
205 get status() this._uri,
209 if (isinstance(uri, Ci.nsIURI)) {
210 // when session information is available, add [+] when we can go
211 // backwards, [-] when we can go forwards
212 if (uri.equals(buffer.uri) && window.getWebNavigation) {
213 let sh = window.getWebNavigation().sessionHistory;
214 if (sh && sh.index > 0)
216 if (sh && sh.index < sh.count - 1)
219 modified += UTF8("❤");
222 if (modules.quickmarks)
223 modified += quickmarks.find(uri.spec.replace(/#.*/, "")).join("");
225 url = util.losslessDecodeURI(uri.spec);
228 if (url == "about:blank") {
230 url = _("buffer.noName");
233 url = url.replace(RegExp("^dactyl://help/(\\S+)#(.*)"), function (m, n1, n2) n1 + " " + decodeURIComponent(n2) + " " + _("buffer.help"))
234 .replace(RegExp("^dactyl://help/(\\S+)"), "$1 " + _("buffer.help"));
238 url += " [" + modified + "]";
240 this.widgets.url.value = url;
244 get bookmarked() this._bookmarked,
245 set bookmarked(val) {
246 this._bookmarked = val;
248 this.status = this.status;
251 updateStatus: function updateStatus() {
252 this.timeout(function () {
253 this.status = buffer.uri;
257 updateUrl: deprecated("statusline.status", function updateUrl(url) { this.status = url || buffer.uri }),
260 * Set the contents of the status line's input buffer to the given
261 * string. Used primarily when a key press requires further input
262 * before being processed, including mapping counts and arguments,
263 * along with multi-key mappings.
265 * @param {string} buffer
268 get inputBuffer() this.widgets.inputbuffer.value,
269 set inputBuffer(val) this.widgets.inputbuffer.value = val == null ? "" : val,
270 updateInputBuffer: deprecated("statusline.inputBuffer", function updateInputBuffer(val) { this.inputBuffer = val; }),
273 * Update the page load progress bar.
275 * @param {string|number} progress The current progress, as follows:
276 * A string - Displayed literally.
277 * A ratio 0 < n < 1 - Displayed as a progress bar.
278 * A number n <= 0 - Displayed as a "Loading" message.
279 * Any other number - The progress is cleared.
281 progress: Modes.boundProperty({
282 get: function progress() this._progress,
283 set: function progress(progress) {
284 this._progress = progress || "";
286 if (isinstance(progress, ["String", _]))
287 this.widgets.progress.value = this._progress;
288 else if (typeof progress == "number") {
289 let progressStr = "";
290 if (this._progress <= 0)
291 progressStr = /*L*/"[ Loading... ]";
292 else if (this._progress < 1) {
293 let progress = Math.round(this._progress * 20);
295 + "===================> "
296 .substr(20 - progress, 20)
299 this.widgets.progress.value = progressStr;
303 updateProgress: deprecated("statusline.progress", function updateProgress(progress) {
304 this.progress = progress;
308 * Display the correct tabcount (e.g., [1/5]) on the status bar.
310 * @param {boolean} delayed When true, update count after a brief timeout.
311 * Useful in the many cases when an event that triggers an update is
312 * broadcast before the tab state is fully updated.
315 updateTabCount: function updateTabCount(delayed) {
316 if (dactyl.has("tabs")) {
318 this.timeout(function () this.updateTabCount(false), 0);
322 this.widgets.tabcount.value = "[" + (tabs.index(null, true) + 1) + "/" + tabs.visibleTabs.length + "]";
327 * Display the main content's vertical scroll position in the status
330 * @param {number} percent The position, as a percentage.
333 updateBufferPosition: function updateBufferPosition(percent) {
334 if (percent == null) {
335 let win = document.commandDispatcher.focusedWindow;
338 win.scrollY; // intentional - see Kris
339 percent = win.scrollY == 0 ? 0 : // This prevents a forced rendering
340 win.scrollMaxY == 0 ? -1 : win.scrollY / win.scrollMaxY;
343 percent = Math.round(percent * 100);
346 var position = "All";
347 else if (percent == 0)
349 else if (percent >= 100)
351 else if (percent < 10)
352 position = " " + percent + "%";
354 position = percent + "%";
356 this.widgets.bufferposition.value = position;
360 * Display the main content's zoom level.
362 * @param {number} percent The zoom level, as a percentage. @optional
363 * @param {boolean} full True if full zoom is in operation. @optional
365 updateZoomLevel: function updateZoomLevel(percent, full) {
366 if (arguments.length == 0)
367 [percent, full] = [buffer.zoomLevel, buffer.fullZoom];
370 this.widgets.zoomlevel.value = "";
372 percent = (" " + Math.round(percent)).substr(-3);
374 this.widgets.zoomlevel.value = " [" + percent + "%]";
376 this.widgets.zoomlevel.value = " (" + percent + "%)";
381 // vim: set fdm=marker sw=4 ts=4 et: