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.statusBar.collapsed = true;
16 this.baseGroup = this.statusBar == this._statusLine ? "StatusLine " : "";
18 if (this.statusBar.localName == "toolbar") {
19 styles.system.add("addon-bar", config.styleableChrome, <css><![CDATA[
20 #status-bar { margin-top: 0 !important; }
21 #addon-bar > statusbar { -moz-box-flex: 1 }
22 #addon-bar > #addonbar-closebutton { visibility: collapse; }
23 #addon-bar > xul|toolbarspring { visibility: collapse; }
26 util.overlayWindow(window, { append: <><statusbar id="status-bar" ordinal="0"/></> });
28 highlight.loadCSS(util.compileMacro(<![CDATA[
29 !AddonBar;#addon-bar {
31 padding-left: 0 !important;
32 min-height: 18px !important;
33 -moz-appearance: none !important;
36 !AddonButton;#addon-bar xul|toolbarbutton {
37 /* An Add-on Bar button */
38 -moz-appearance: none !important;
39 padding: 0 !important;
40 border-width: 0px !important;
41 min-width: 0 !important;
42 color: inherit !important;
44 AddonButton:not(:hover) background: transparent;
45 ]]>)({ padding: util.OS.isMacOSX ? "padding-right: 10px !important;" : "" }));
47 if (document.getElementById("appmenu-button"))
48 highlight.loadCSS(<![CDATA[
49 AppmenuButton /* The app-menu button */ \
50 min-width: 0 !important; padding: 0 .5em !important;
54 XML.ignoreWhitespace = true;
55 let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
56 let prepend = <e4x xmlns={XUL} xmlns:dactyl={NS}>
57 <button id="appmenu-button" label="" image="chrome://branding/content/icon16.png" highlight="AppmenuButton" />
58 <toolbarbutton id="appmenu-toolbar-button" label="" image="chrome://branding/content/icon16.png" />
59 <statusbar id="status-bar" highlight="StatusLine">
60 <!-- insertbefore="dactyl.statusBefore;" insertafter="dactyl.statusAfter;" -->
61 <hbox key="container" hidden="false" align="center" flex="1">
62 <stack orient="horizontal" align="stretch" flex="1" highlight="CmdLine StatusCmdLine" class="dactyl-container">
63 <hbox highlight="CmdLine StatusCmdLine" class="dactyl-container">
64 <label key="mode" crop="end" class="plain" collapsed="true"/>
65 <stack id="dactyl-statusline-stack" flex="1" highlight="CmdLine StatusCmdLine" class="dactyl-container">
66 <textbox key="url" crop="end" flex="1" style="background: transparent;" class="plain dactyl-status-field-url" readonly="true"/>
67 <textbox key="message" crop="end" flex="1" highlight="Normal StatusNormal" class="plain" readonly="true"/>
71 <label class="plain" key="inputbuffer" flex="0"/>
72 <label class="plain" key="progress" flex="0"/>
73 <label class="plain" key="tabcount" flex="0"/>
74 <label class="plain" key="bufferposition" flex="0"/>
75 <label class="plain" key="zoomlevel" flex="0"/>
77 <!-- just hide them since other elements expect them -->
78 <statusbarpanel id="statusbar-display" hidden="true"/>
79 <statusbarpanel id="statusbar-progresspanel" hidden="true"/>
83 for each (let attr in prepend..@key)
84 attr.parent().@id = "dactyl-statusline-field-" + attr;
86 util.overlayWindow(window, {
87 objects: this.widgets = { get status() this.container },
88 prepend: prepend.elements()
92 this.security = content.document.dactylSecurity || "insecure";
97 get visible() !this.statusBar.collapsed && !this.statusBar.hidden,
100 "browser.locationChange": function (webProgress, request, uri) {
101 let win = webProgress.DOMWindow;
103 this.progress = uri && win && win.dactylProgress || "";
105 // if this is not delayed we get the position of the old buffer
106 this.timeout(function () {
107 this.updateBufferPosition();
108 this.updateZoomLevel();
111 "browser.overLink": function (link) {
112 switch (options["showstatuslinks"]) {
114 this.status = link ? _("status.link", link) : buffer.uri;
118 dactyl.echo(_("status.link", link), commandline.FORCE_SINGLELINE);
124 "browser.progressChange": function onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
125 if (webProgress && webProgress.DOMWindow)
126 webProgress.DOMWindow.dactylProgress = curTotalProgress / maxTotalProgress;
127 this.progress = curTotalProgress / maxTotalProgress;
129 "browser.securityChange": function onSecurityChange(webProgress, request, state) {
131 if (state & Ci.nsIWebProgressListener.STATE_IS_BROKEN)
132 this.security = "broken";
133 else if (state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
134 this.security = "extended";
135 else if (state & Ci.nsIWebProgressListener.STATE_SECURE_HIGH)
136 this.security = "secure";
137 else // if (state & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
138 this.security = "insecure";
140 if (webProgress && webProgress.DOMWindow)
141 webProgress.DOMWindow.document.dactylSecurity = this.security;
143 "browser.stateChange": function onStateChange(webProgress, request, flags, status) {
144 if (flags & Ci.nsIWebProgressListener.STATE_START)
146 if (flags & Ci.nsIWebProgressListener.STATE_STOP) {
151 "browser.statusChange": function onStatusChange(webProgress, request, status, message) {
152 this.timeout(function () {
153 this.status = message || buffer.uri;
159 * Update the status bar to indicate how secure the website is:
160 * extended - Secure connection with Extended Validation(EV) certificate.
161 * secure - Secure connection with valid certificate.
162 * broken - Secure connection with invalid certificate, or
164 * insecure - Insecure connection.
166 * @param {'extended'|'secure'|'broken'|'insecure'} type
169 this._security = type;
170 const highlightGroup = {
171 extended: "StatusLineExtended",
172 secure: "StatusLineSecure",
173 broken: "StatusLineBroken",
174 insecure: "StatusLineNormal"
177 highlight.highlightNode(this.statusBar, this.baseGroup + highlightGroup[type]);
179 get security() this._security,
181 // update all fields of the statusline
182 update: function update() {
184 this.inputBuffer = "";
186 this.updateTabCount();
187 this.updateBufferPosition();
188 this.updateZoomLevel();
191 unsafeURI: deprecated("util.unsafeURI", { get: function unsafeURI() util.unsafeURI }),
192 losslessDecodeURI: deprecated("util.losslessDecodeURI", function losslessDecodeURI() util.losslessDecodeURI.apply(util, arguments)),
195 * Update the URL displayed in the status line. Also displays status
196 * icons, [+-♥], when there are next and previous pages in the
197 * current tab's history, and when the current URL is bookmarked,
200 * @param {string} url The URL to display.
202 get status() this._uri,
206 if (isinstance(uri, Ci.nsIURI)) {
207 // when session information is available, add [+] when we can go
208 // backwards, [-] when we can go forwards
209 if (uri.equals(buffer.uri) && window.getWebNavigation) {
210 let sh = window.getWebNavigation().sessionHistory;
211 if (sh && sh.index > 0)
213 if (sh && sh.index < sh.count - 1)
216 modified += UTF8("❤");
219 if (modules.quickmarks)
220 modified += quickmarks.find(uri.spec.replace(/#.*/, "")).join("");
222 url = util.losslessDecodeURI(uri.spec);
225 if (url == "about:blank") {
227 url = _("buffer.noName");
230 url = url.replace(RegExp("^dactyl://help/(\\S+)#(.*)"), function (m, n1, n2) n1 + " " + decodeURIComponent(n2) + " " + _("buffer.help"))
231 .replace(RegExp("^dactyl://help/(\\S+)"), "$1 " + _("buffer.help"));
235 url += " [" + modified + "]";
237 this.widgets.url.value = url;
241 get bookmarked() this._bookmarked,
242 set bookmarked(val) {
243 this._bookmarked = val;
245 this.status = this.status;
248 updateStatus: function updateStatus() {
249 this.timeout(function () {
250 this.status = buffer.uri;
254 updateUrl: deprecated("statusline.status", function updateUrl(url) { this.status = url || buffer.uri }),
257 * Set the contents of the status line's input buffer to the given
258 * string. Used primarily when a key press requires further input
259 * before being processed, including mapping counts and arguments,
260 * along with multi-key mappings.
262 * @param {string} buffer
265 get inputBuffer() this.widgets.inputbuffer.value,
266 set inputBuffer(val) this.widgets.inputbuffer.value = val == null ? "" : val,
267 updateInputBuffer: deprecated("statusline.inputBuffer", function updateInputBuffer(val) { this.inputBuffer = val; }),
270 * Update the page load progress bar.
272 * @param {string|number} progress The current progress, as follows:
273 * A string - Displayed literally.
274 * A ratio 0 < n < 1 - Displayed as a progress bar.
275 * A number n <= 0 - Displayed as a "Loading" message.
276 * Any other number - The progress is cleared.
278 progress: Modes.boundProperty({
279 get: function progress() this._progress,
280 set: function progress(progress) {
281 this._progress = progress || "";
283 if (isinstance(progress, ["String", _]))
284 this.widgets.progress.value = this._progress;
285 else if (typeof progress == "number") {
286 let progressStr = "";
287 if (this._progress <= 0)
288 progressStr = /*L*/"[ Loading... ]";
289 else if (this._progress < 1) {
290 let progress = Math.round(this._progress * 20);
292 + "===================> "
293 .substr(20 - progress, 20)
296 this.widgets.progress.value = progressStr;
300 updateProgress: deprecated("statusline.progress", function updateProgress(progress) {
301 this.progress = progress;
305 * Display the correct tabcount (e.g., [1/5]) on the status bar.
307 * @param {boolean} delayed When true, update count after a brief timeout.
308 * Useful in the many cases when an event that triggers an update is
309 * broadcast before the tab state is fully updated.
312 updateTabCount: function updateTabCount(delayed) {
313 if (dactyl.has("tabs")) {
315 this.timeout(function () this.updateTabCount(false), 0);
319 this.widgets.tabcount.value = "[" + (tabs.index(null, true) + 1) + "/" + tabs.visibleTabs.length + "]";
324 * Display the main content's vertical scroll position in the status
327 * @param {number} percent The position, as a percentage.
330 updateBufferPosition: function updateBufferPosition(percent) {
331 if (percent == null) {
332 let win = document.commandDispatcher.focusedWindow;
335 win.scrollY; // intentional - see Kris
336 percent = win.scrollY == 0 ? 0 : // This prevents a forced rendering
337 win.scrollMaxY == 0 ? -1 : win.scrollY / win.scrollMaxY;
340 percent = Math.round(percent * 100);
343 var position = "All";
344 else if (percent == 0)
346 else if (percent >= 100)
348 else if (percent < 10)
349 position = " " + percent + "%";
351 position = percent + "%";
353 this.widgets.bufferposition.value = position;
357 * Display the main content's zoom level.
359 * @param {number} percent The zoom level, as a percentage. @optional
360 * @param {boolean} full True if full zoom is in operation. @optional
362 updateZoomLevel: function updateZoomLevel(percent, full) {
363 if (arguments.length == 0)
364 [percent, full] = [buffer.zoomLevel, buffer.fullZoom];
367 this.widgets.zoomlevel.value = "";
369 percent = (" " + Math.round(percent)).substr(-3);
371 this.widgets.zoomlevel.value = " [" + percent + "%]";
373 this.widgets.zoomlevel.value = " (" + percent + "%)";
378 // vim: set fdm=marker sw=4 ts=4 et: