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-2012 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, literal(/*
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, {
27 ["statusbar", { id: "status-bar", ordinal: "0" }]]
30 highlight.loadCSS(util.compileMacro(literal(/*
31 !AddonBar;#addon-bar {
32 padding-left: 0 !important;
33 min-height: 18px !important;
34 -moz-appearance: none !important;
37 !AddonButton;#addon-bar xul|toolbarbutton {
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: config.OS.isMacOSX ? "padding-right: 10px !important;" : "" }));
47 if (document.getElementById("appmenu-button"))
48 highlight.loadCSS(literal(/*
49 AppmenuButton min-width: 0 !important; padding: 0 .5em !important;
53 let _commandline = "if (window.dactyl) return dactyl.modules.commandline";
55 ["button", { id: "appmenu-button", label: "", image: "chrome://branding/content/icon16.png", highlight: "AppmenuButton", xmlns: "xul" }],
56 ["toolbarbutton", { id: "appmenu-toolbar-button", label: "", image: "chrome://branding/content/icon16.png" }],
57 ["statusbar", { id: "status-bar", highlight: "StatusLine", xmlns: "xul" },
58 // <!-- insertbefore="dactyl.statusBefore;" insertafter="dactyl.statusAfter;" -->
59 ["hbox", { key: "container", hidden: "false", align: "center", flex: "1" },
60 ["stack", { orient: "horizontal", align: "stretch", flex: "1", highlight: "CmdLine StatusCmdLine", class: "dactyl-container" },
61 ["hbox", { highlight: "CmdLine StatusCmdLine", class: "dactyl-container" },
62 ["label", { key: "mode", crop: "end", class: "plain", collapsed: "true" }],
63 ["stack", { id: "dactyl-statusline-stack", flex: "1", highlight: "CmdLine StatusCmdLine", class: "dactyl-container" },
64 ["textbox", { key: "url", crop: "end", flex: "1", style: "background: transparent;", class: "plain dactyl-status-field-url",
66 ["hbox", { key: "message-box" },
67 ["label", { key: "message-pre", highlight: "WarningMsg StatusWarningMsg", class: "plain", readonly: "true" }],
68 ["textbox", { key: "message", crop: "end", flex: "1", highlight: "Normal StatusNormal", class: "plain",
69 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" }]],
75 // just hide them since other elements expect them
76 ["statusbarpanel", { id: "statusbar-display", hidden: "true" }],
77 ["statusbarpanel", { id: "statusbar-progresspanel", hidden: "true" }]]];
80 ary.forEach(function (elem) {
82 elem[1].id = "dactyl-statusline-field-" + elem[1].key;
88 overlay.overlayWindow(window, {
89 objects: this.widgets = { get status() this.container },
94 this.security = content.document.dactylSecurity || "insecure";
99 get visible() !this.statusBar.collapsed && !this.statusBar.hidden,
102 "browser.locationChange": function (webProgress, request, uri) {
103 let win = webProgress.DOMWindow;
105 this.progress = uri && win && win.dactylProgress || "";
107 // if this is not delayed we get the position of the old buffer
108 this.timeout(function () {
109 this.updateBufferPosition();
110 this.updateZoomLevel();
113 "browser.overLink": function (link) {
114 switch (options["showstatuslinks"]) {
116 this.overLink = link ? _("status.link", link) : null;
117 this.status = link ? _("status.link", link) : buffer.uri;
120 this.overLink = null;
122 dactyl.echo(_("status.link", link), commandline.FORCE_SINGLELINE);
128 "browser.progressChange": function onProgressChange(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) {
129 if (webProgress && webProgress.DOMWindow)
130 webProgress.DOMWindow.dactylProgress = curTotalProgress / maxTotalProgress;
131 this.progress = curTotalProgress / maxTotalProgress;
133 "browser.securityChange": function onSecurityChange(webProgress, request, state) {
135 if (state & Ci.nsIWebProgressListener.STATE_IS_BROKEN)
136 this.security = "broken";
137 else if (state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL)
138 this.security = "extended";
139 else if (state & Ci.nsIWebProgressListener.STATE_SECURE_HIGH)
140 this.security = "secure";
141 else // if (state & Ci.nsIWebProgressListener.STATE_IS_INSECURE)
142 this.security = "insecure";
144 if (webProgress && webProgress.DOMWindow)
145 webProgress.DOMWindow.document.dactylSecurity = this.security;
147 "browser.stateChange": function onStateChange(webProgress, request, flags, status) {
148 const L = Ci.nsIWebProgressListener;
150 if (flags & (L.STATE_IS_DOCUMENT | L.STATE_IS_WINDOW))
151 if (flags & L.STATE_START)
153 else if (flags & L.STATE_STOP)
156 if (flags & L.STATE_STOP)
159 "browser.statusChange": function onStatusChange(webProgress, request, status, message) {
160 this.timeout(function () {
161 this.status = message || buffer.uri;
164 "fullscreen": function onFullscreen(fullscreen) {
165 let go = options.get("guioptions");
167 this.wasVisible = go.has("s");
170 else if (this.wasVisible) {
177 * Update the status bar to indicate how secure the website is:
178 * extended - Secure connection with Extended Validation(EV) certificate.
179 * secure - Secure connection with valid certificate.
180 * broken - Secure connection with invalid certificate, or
182 * insecure - Insecure connection.
184 * @param {'extended'|'secure'|'broken'|'insecure'} type
187 this._security = type;
188 const highlightGroup = {
189 extended: "StatusLineExtended",
190 secure: "StatusLineSecure",
191 broken: "StatusLineBroken",
192 insecure: "StatusLineNormal"
195 highlight.highlightNode(this.statusBar, this.baseGroup + highlightGroup[type]);
197 get security() this._security,
199 // update all fields of the statusline
200 update: function update() {
202 this.inputBuffer = "";
204 this.updateTabCount();
205 this.updateBufferPosition();
206 this.updateZoomLevel();
209 unsafeURI: deprecated("util.unsafeURI", { get: function unsafeURI() util.unsafeURI }),
210 losslessDecodeURI: deprecated("util.losslessDecodeURI", function losslessDecodeURI() util.losslessDecodeURI.apply(util, arguments)),
213 * Update the URL displayed in the status line. Also displays status
214 * icons, [+-♥], when there are next and previous pages in the
215 * current tab's history, and when the current URL is bookmarked,
218 * @param {string} url The URL to display.
220 get status() this._uri,
224 if (isinstance(uri, Ci.nsIURI)) {
225 // when session information is available, add [+] when we can go
226 // backwards, [-] when we can go forwards
227 if (uri.equals(buffer.uri) && window.getWebNavigation) {
228 let sh = window.getWebNavigation().sessionHistory;
229 if (sh && sh.index > 0)
231 if (sh && sh.index < sh.count - 1)
234 modified += UTF8("❤");
237 if (modules.quickmarks)
238 modified += quickmarks.find(uri.spec.replace(/#.*/, "")).join("");
240 url = util.losslessDecodeURI(uri.spec);
243 if (url == "about:blank") {
245 url = _("buffer.noName");
248 url = url.replace(RegExp("^dactyl://help/(\\S+)#(.*)"), function (m, n1, n2) n1 + " " + decodeURIComponent(n2) + " " + _("buffer.help"))
249 .replace(RegExp("^dactyl://help/(\\S+)"), "$1 " + _("buffer.help"));
253 url += " [" + modified + "]";
255 this.widgets.url.value = url;
259 get bookmarked() this._bookmarked,
260 set bookmarked(val) {
261 this._bookmarked = val;
263 this.status = this.status;
266 updateStatus: function updateStatus() {
267 this.timeout(function () {
268 this.status = this.overLink || buffer.uri;
272 updateUrl: deprecated("statusline.status", function updateUrl(url) { this.status = url || buffer.uri; }),
275 * Set the contents of the status line's input buffer to the given
276 * string. Used primarily when a key press requires further input
277 * before being processed, including mapping counts and arguments,
278 * along with multi-key mappings.
280 * @param {string} buffer
283 get inputBuffer() this.widgets.inputbuffer.value,
284 set inputBuffer(val) this.widgets.inputbuffer.value = val == null ? "" : val,
285 updateInputBuffer: deprecated("statusline.inputBuffer", function updateInputBuffer(val) { this.inputBuffer = val; }),
288 * Update the page load progress bar.
290 * @param {string|number} progress The current progress, as follows:
291 * A string - Displayed literally.
292 * A ratio 0 < n < 1 - Displayed as a progress bar.
293 * A number n <= 0 - Displayed as a "Loading" message.
294 * Any other number - The progress is cleared.
296 progress: Modes.boundProperty({
297 get: function progress() this._progress,
298 set: function progress(progress) {
299 this._progress = progress || "";
301 if (isinstance(progress, ["String", _]))
302 this.widgets.progress.value = this._progress;
303 else if (typeof progress == "number") {
304 let progressStr = "";
305 if (this._progress <= 0)
306 progressStr = /*L*/"[ Loading... ]";
307 else if (this._progress < 1) {
308 let progress = Math.round(this._progress * 20);
310 + "===================> "
311 .substr(20 - progress, 20)
314 this.widgets.progress.value = progressStr;
318 updateProgress: deprecated("statusline.progress", function updateProgress(progress) {
319 this.progress = progress;
323 * Display the correct tabcount (e.g., [1/5]) on the status bar.
325 * @param {boolean} delayed When true, update count after a brief timeout.
326 * Useful in the many cases when an event that triggers an update is
327 * broadcast before the tab state is fully updated.
330 updateTabCount: function updateTabCount(delayed) {
331 if (dactyl.has("tabs")) {
333 this.timeout(function () this.updateTabCount(false), 0);
337 this.widgets.tabcount.value = "[" + (tabs.index(null, true) + 1) + "/" + tabs.visibleTabs.length + "]";
342 * Display the main content's vertical scroll position in the status
345 * @param {number} percent The position, as a percentage.
348 updateBufferPosition: function updateBufferPosition(percent) {
349 if (percent == null) {
350 let win = document.commandDispatcher.focusedWindow;
353 win.scrollY; // intentional - see Kris
354 percent = win.scrollY == 0 ? 0 : // This prevents a forced rendering
355 win.scrollMaxY == 0 ? -1 : win.scrollY / win.scrollMaxY;
358 percent = Math.round(percent * 100);
361 var position = "All";
362 else if (percent == 0)
364 else if (percent >= 100)
366 else if (percent < 10)
367 position = " " + percent + "%";
369 position = percent + "%";
371 this.widgets.bufferposition.value = position;
375 * Display the main content's zoom level.
377 * @param {number} percent The zoom level, as a percentage. @optional
378 * @param {boolean} full True if full zoom is in operation. @optional
380 updateZoomLevel: function updateZoomLevel(percent, full) {
381 if (arguments.length == 0)
382 [percent, full] = [buffer.zoomLevel, buffer.fullZoom];
385 this.widgets.zoomlevel.value = "";
387 percent = (" " + Math.round(percent)).substr(-3);
389 this.widgets.zoomlevel.value = " [" + percent + "%]";
391 this.widgets.zoomlevel.value = " (" + percent + "%)";
396 // vim: set fdm=marker sw=4 sts=4 ts=8 et: