2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2010 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
12 var define_buffer_local_hook = local_hook_definer("window");
14 function define_current_buffer_hook (hook_name, existing_hook) {
15 define_buffer_local_hook(hook_name);
16 add_hook(existing_hook, function (buffer) {
17 if (!buffer.window.buffers || buffer != buffer.window.buffers.current)
19 var hook = conkeror[hook_name];
20 hook.run.apply(hook, Array.prototype.slice.call(arguments));
24 define_buffer_local_hook("buffer_title_change_hook");
25 define_buffer_local_hook("buffer_description_change_hook");
26 define_buffer_local_hook("select_buffer_hook");
27 define_buffer_local_hook("create_buffer_early_hook");
28 define_buffer_local_hook("create_buffer_hook");
29 define_buffer_local_hook("kill_buffer_hook");
30 define_buffer_local_hook("buffer_scroll_hook");
31 define_buffer_local_hook("buffer_dom_content_loaded_hook");
32 define_buffer_local_hook("buffer_loaded_hook");
34 define_current_buffer_hook("current_buffer_title_change_hook", "buffer_title_change_hook");
35 define_current_buffer_hook("current_buffer_description_change_hook", "buffer_description_change_hook");
36 define_current_buffer_hook("current_buffer_scroll_hook", "buffer_scroll_hook");
37 define_current_buffer_hook("current_buffer_dom_content_loaded_hook", "buffer_dom_content_loaded_hook");
40 define_keywords("$opener");
41 function buffer_creator (type) {
42 var args = forward_keywords(arguments);
43 return function (window) {
44 return new type(window, args);
48 define_variable("allow_browser_window_close", true,
49 "If this is set to true, if a content buffer page calls " +
50 "window.close() from JavaScript and is not prevented by the " +
51 "normal Mozilla mechanism that restricts pages from closing " +
52 "a window that was not opened by a script, the buffer will be " +
53 "killed, deleting the window as well if it is the only buffer.");
55 function buffer (window) {
56 this.constructor_begin();
58 this.opener = arguments.$opener;
60 var element = create_XUL(window, "vbox");
61 element.setAttribute("flex", "1");
62 var browser = create_XUL(window, "browser");
63 browser.setAttribute("type", "content");
64 browser.setAttribute("flex", "1");
65 browser.setAttribute("autocompletepopup", "popup_autocomplete");
66 element.appendChild(browser);
67 this.window.buffers.container.appendChild(element);
68 this.window.buffers.buffer_list.push(this);
69 this.element = element;
70 this.browser = element.firstChild;
71 this.element.conkeror_buffer_object = this;
73 this.local = { __proto__: conkeror };
75 this.enabled_modes = [];
76 this.default_browser_object_classes = {};
80 this.browser.addEventListener("scroll", function (event) {
81 buffer_scroll_hook.run(buffer);
82 }, true /* capture */);
84 this.browser.addEventListener("DOMContentLoaded", function (event) {
85 buffer_dom_content_loaded_hook.run(buffer);
86 }, true /* capture */);
88 this.browser.addEventListener("load", function (event) {
89 buffer_loaded_hook.run(buffer);
90 }, true /* capture */);
92 this.browser.addEventListener("DOMWindowClose", function (event) {
93 /* This call to preventDefault is very important; without
94 * it, somehow Mozilla does something bad and as a result
95 * the window loses focus, causing keyboard commands to
97 event.preventDefault();
99 if (allow_browser_window_close)
100 kill_buffer(buffer, true);
103 this.browser.addEventListener("focus", function (event) {
104 if (buffer.focusblocker &&
105 event.target instanceof Ci.nsIDOMHTMLElement &&
106 buffer.focusblocker(buffer, event))
110 buffer.set_input_mode();
113 this.browser.addEventListener("blur", function (event) {
114 buffer.set_input_mode();
117 this.modalities = [];
119 this.override_keymaps = [];
121 // When create_buffer_hook_early runs, basic buffer properties
122 // will be available, but not the properties subclasses.
123 create_buffer_early_hook.run(this);
125 this.constructor_end();
130 /* Saved focus state */
131 saved_focused_frame: null,
132 saved_focused_element: null,
134 // get title () [must be defined by subclasses]
135 // get name () [must be defined by subclasses]
136 dead: false, /* This is set when the buffer is killed */
141 // The property focusblocker is available for an external module to
142 // put a function on which takes a buffer as its argument and returns
143 // true to block a focus event, or false to let normal processing
144 // occur. Having this one property explicitly handled by the buffer
145 // class allows for otherwise modular focus-blockers.
150 set_default_message: function (str) {
151 this.default_message = str;
152 if (this == this.window.buffers.current)
153 this.window.minibuffer.set_default_message(str);
156 constructors_running: 0,
158 constructor_begin: function () {
159 this.constructors_running++;
162 constructor_end: function () {
163 if (--this.constructors_running == 0) {
164 create_buffer_hook.run(this);
165 this.set_input_mode();
170 destroy: function () {
174 this.saved_focused_frame = null;
175 this.saved_focused_element = null;
176 // prevent modalities from accessing dead browser
177 this.modalities = [];
180 set_input_mode: function () {
182 conkeror[this.input_mode](this, false);
184 this.modalities.map(function (m) m(this), this);
187 /* Browser accessors */
188 get top_frame () { return this.browser.contentWindow; },
189 get document () { return this.browser.contentDocument; },
190 get web_navigation () { return this.browser.webNavigation; },
191 get doc_shell () { return this.browser.docShell; },
192 get markup_document_viewer () { return this.browser.markupDocumentViewer; },
193 get current_uri () { return this.browser.currentURI; },
195 is_child_element: function (element) {
196 return (element && this.is_child_frame(element.ownerDocument.defaultView));
199 is_child_frame: function (frame) {
200 return (frame && frame.top == this.top_frame);
203 // This method is like focused_frame, except that if no content
204 // frame actually has focus, this returns null.
205 get focused_frame_or_null () {
206 var frame = this.window.document.commandDispatcher.focusedWindow;
207 if (this.is_child_frame(frame))
212 get focused_frame () {
213 var frame = this.window.document.commandDispatcher.focusedWindow;
214 if (this.is_child_frame(frame))
216 return this.top_frame;
219 get focused_element () {
220 var element = this.window.document.commandDispatcher.focusedElement;
221 if (this.is_child_element(element))
226 get focused_selection_controller () {
227 var child_docshells = this.doc_shell.getDocShellEnumerator(
228 Ci.nsIDocShellTreeItem.typeContent,
229 Ci.nsIDocShell.ENUMERATE_FORWARDS);
230 while (child_docshells.hasMoreElements()) {
231 let ds = child_docshells.getNext()
232 .QueryInterface(Ci.nsIDocShell);
234 let display = ds.QueryInterface(Ci.nsIInterfaceRequestor)
235 .getInterface(Ci.nsISelectionDisplay);
238 return display.QueryInterface(Ci.nsISelectionController);
241 return this.doc_shell
242 .QueryInterface(Ci.nsIInterfaceRequestor)
243 .getInterface(Ci.nsISelectionDisplay)
244 .QueryInterface(Ci.nsISelectionController);
247 do_command: function (command) {
248 function attempt_command (element, command) {
250 if (element.controllers
251 && (controller = element.controllers.getControllerForCommand(command)) != null
252 && controller.isCommandEnabled(command))
254 controller.doCommand(command);
260 var element = this.focused_element;
261 if (element && attempt_command(element, command))
263 var win = this.focused_frame;
265 if (attempt_command(win, command))
267 if (!win.parent || win == win.parent)
274 function with_current_buffer (buffer, callback) {
275 return callback(new interactive_context(buffer));
278 function check_buffer (obj, type) {
279 if (!(obj instanceof type))
280 throw interactive_error("Buffer has invalid type.");
282 throw interactive_error("Buffer has already been killed.");
286 function caret_enabled (buffer) {
287 return buffer.browser.getAttribute('showcaret');
290 function clear_selection (buffer) {
291 let sel_ctrl = buffer.focused_selection_controller;
293 let sel = sel_ctrl.getSelection(sel_ctrl.SELECTION_NORMAL);
294 if (caret_enabled(buffer)) {
296 sel.collapseToStart();
298 sel.removeAllRanges();
304 function buffer_container (window, create_initial_buffer) {
305 this.window = window;
306 this.container = window.document.getElementById("buffer-container");
307 this.buffer_list = [];
308 window.buffers = this;
309 create_initial_buffer(window, this.container.firstChild);
311 buffer_container.prototype = {
312 constructor: buffer_container,
315 return this.container.selectedPanel.conkeror_buffer_object;
318 set current (buffer) {
319 var old_value = this.current;
320 if (old_value == buffer)
323 this.buffer_list.splice(this.buffer_list.indexOf(buffer), 1);
324 this.buffer_list.unshift(buffer);
326 this._switch_away_from(this.current);
327 this._switch_to(buffer);
330 select_buffer_hook.run(buffer);
333 _switch_away_from: function (old_value) {
335 old_value.saved_focused_frame = old_value.focused_frame;
336 old_value.saved_focused_element = old_value.focused_element;
338 old_value.browser.setAttribute("type", "content");
341 _switch_to: function (buffer) {
342 // Select new buffer in the XUL deck
343 this.container.selectedPanel = buffer.element;
345 buffer.browser.setAttribute("type", "content-primary");
348 * This next focus call seems to be needed to avoid focus
349 * somehow getting lost (and the keypress handler therefore
350 * not getting called at all) when killing buffers.
354 // Restore focus state
355 buffer.browser.focus();
356 if (buffer.saved_focused_element)
357 set_focus_no_scroll(this.window, buffer.saved_focused_element);
358 else if (buffer.saved_focused_frame)
359 set_focus_no_scroll(this.window, buffer.saved_focused_frame);
361 buffer.saved_focused_element = null;
362 buffer.saved_focused_frame = null;
364 this.window.minibuffer.set_default_message(buffer.default_message);
368 return this.container.childNodes.length;
371 get_buffer: function (index) {
372 if (index >= 0 && index < this.count)
373 return this.container.childNodes.item(index).conkeror_buffer_object;
377 get selected_index () {
378 var nodes = this.container.childNodes;
379 var count = nodes.length;
380 for (var i = 0; i < count; ++i)
381 if (nodes.item(i) == this.container.selectedPanel)
386 index_of: function (b) {
387 var nodes = this.container.childNodes;
388 var count = nodes.length;
389 for (var i = 0; i < count; ++i)
390 if (nodes.item(i) == b.element)
395 get unique_name_list () {
396 var existing_names = new string_hashset();
398 this.for_each(function(b) {
399 var base_name = b.name;
400 var name = base_name;
402 while (existing_names.contains(name)) {
404 name = base_name + "<" + index + ">";
406 existing_names.add(name);
407 bufs.push([name, b]);
412 kill_buffer: function (b) {
415 var count = this.count;
418 var new_buffer = this.buffer_list[0];
420 if (b == new_buffer) {
421 new_buffer = this.buffer_list[1];
424 this._switch_away_from(this.current);
425 // The removeChild call below may trigger events in progress
426 // listeners. This call to `destroy' gives buffer subclasses a
427 // chance to remove such listeners, so that they cannot try to
428 // perform UI actions based upon a xul:browser that no longer
430 var element = b.element;
432 this.container.removeChild(element);
433 this.buffer_list.splice(this.buffer_list.indexOf(b), 1);
434 this._switch_to(new_buffer);
436 select_buffer_hook.run(new_buffer);
437 this.buffer_list.splice(this.buffer_list.indexOf(new_buffer), 1);
438 this.buffer_list.unshift(new_buffer);
440 kill_buffer_hook.run(b);
444 bury_buffer: function (b) {
445 var new_buffer = this.buffer_list[0];
447 new_buffer = this.buffer_list[1];
448 this.buffer_list.splice(this.buffer_list.indexOf(b), 1);
449 this.buffer_list.push(b);
450 this.current = new_buffer;
454 for_each: function (f) {
455 var count = this.count;
456 for (var i = 0; i < count; ++i)
457 f(this.get_buffer(i));
461 function buffer_initialize_window_early (window) {
463 * Use content_buffer by default to handle an unusual case where
464 * browser.chromeURI is used perhaps. In general this default
465 * should not be needed.
467 var create_initial_buffer =
468 window.args.initial_buffer_creator || buffer_creator(content_buffer);
469 new buffer_container(window, create_initial_buffer);
472 add_hook("window_initialize_early_hook", buffer_initialize_window_early);
475 define_buffer_local_hook("buffer_kill_before_hook", RUN_HOOK_UNTIL_FAILURE);
476 function buffer_before_window_close (window) {
477 var bs = window.buffers;
478 var count = bs.count;
479 for (let i = 0; i < count; ++i) {
480 if (!buffer_kill_before_hook.run(bs.get_buffer(i)))
485 add_hook("window_before_close_hook", buffer_before_window_close);
487 function buffer_window_close_handler (window) {
488 var bs = window.buffers;
489 var count = bs.count;
490 for (let i = 0; i < count; ++i) {
491 let b = bs.get_buffer(i);
495 add_hook("window_close_hook", buffer_window_close_handler);
497 /* open/follow targets */
498 const OPEN_CURRENT_BUFFER = 0; // only valid for open if the current
499 // buffer is a content_buffer.
500 const OPEN_NEW_BUFFER = 1;
501 const OPEN_NEW_BUFFER_BACKGROUND = 2;
502 const OPEN_NEW_WINDOW = 3;
504 const FOLLOW_DEFAULT = 4; // for open, implies OPEN_CURRENT_BUFFER
505 const FOLLOW_CURRENT_FRAME = 5; // for open, implies OPEN_CURRENT_BUFFER
507 var TARGET_PROMPTS = [" in current buffer",
509 " in new buffer (background)",
512 " in current frame"];
514 var TARGET_NAMES = ["current buffer",
516 "new buffer (background)",
522 function create_buffer (window, creator, target) {
524 case OPEN_NEW_BUFFER:
525 window.buffers.current = creator(window, null);
527 case OPEN_NEW_BUFFER_BACKGROUND:
528 creator(window, null);
530 case OPEN_NEW_WINDOW:
531 make_window(creator);
534 throw new Error("invalid target");
538 let (queued_buffer_creators = null) {
539 function create_buffer_in_current_window (creator, target, focus_existing) {
540 function process_queued_buffer_creators (window) {
541 for (var i = 0; i < queued_buffer_creators.length; ++i) {
542 var x = queued_buffer_creators[i];
543 create_buffer(window, x[0], x[1]);
545 queued_buffer_creators = null;
548 if (target == OPEN_NEW_WINDOW)
549 throw new Error("invalid target");
550 var window = get_recent_conkeror_window();
554 create_buffer(window, creator, target);
555 } else if (queued_buffer_creators != null) {
556 queued_buffer_creators.push([creator,target]);
558 queued_buffer_creators = [];
559 window = make_window(creator);
560 add_hook.call(window, "window_initialize_late_hook", process_queued_buffer_creators);
569 minibuffer_auto_complete_preferences["buffer"] = true;
570 define_keywords("$default");
571 minibuffer.prototype.read_buffer = function () {
572 var window = this.window;
573 var buffer = this.window.buffers.current;
574 keywords(arguments, $prompt = "Buffer:",
576 $history = "buffer");
577 var completer = all_word_completer(
578 $completions = function (visitor) window.buffers.for_each(visitor),
579 $get_string = function (x) x.description,
580 $get_description = function (x) x.title);
581 var result = yield this.read(
582 $keymap = read_buffer_keymap,
583 $prompt = arguments.$prompt,
584 $history = arguments.$history,
585 $completer = completer,
586 $match_required = true,
587 $auto_complete = "buffer",
588 $auto_complete_initial = true,
589 $auto_complete_delay = 0,
590 $default_completion = arguments.$default);
591 yield co_return(result);
595 interactive("buffer-reset-input-mode",
596 "Force a reset of the input mode. Used by quote-next.",
598 I.buffer.set_input_mode();
602 function buffer_next (window, count) {
603 var index = window.buffers.selected_index;
604 var total = window.buffers.count;
606 throw new interactive_error("No other buffer");
607 index = (index + count) % total;
610 window.buffers.current = window.buffers.get_buffer(index);
612 interactive("buffer-next",
613 "Switch to the next buffer.",
614 function (I) { buffer_next(I.window, I.p); });
615 interactive("buffer-previous",
616 "Switch to the previous buffer.",
617 function (I) { buffer_next(I.window, -I.p); });
619 function switch_to_buffer (window, buffer) {
620 if (buffer && !buffer.dead)
621 window.buffers.current = buffer;
623 interactive("switch-to-buffer",
624 "Switch to a buffer specified in the minibuffer.",
628 (yield I.minibuffer.read_buffer(
629 $prompt = "Switch to buffer:",
630 $default = (I.window.buffers.count > 1 ?
631 I.window.buffers.buffer_list[1] :
635 define_variable("can_kill_last_buffer", true,
636 "If this is set to true, kill-buffer can kill the last "+
637 "remaining buffer, and close the window.");
639 function kill_other_buffers (buffer) {
642 var bs = buffer.window.buffers;
644 while ((b = bs.get_buffer(0)) != buffer)
646 var count = bs.count;
648 bs.kill_buffer(bs.get_buffer(1));
650 interactive("kill-other-buffers",
651 "Kill all buffers except current one.\n",
652 function (I) { kill_other_buffers(I.buffer); });
655 function kill_buffer (buffer, force) {
658 var buffers = buffer.window.buffers;
659 if (buffers.count == 1 && buffer == buffers.current) {
660 if (can_kill_last_buffer || force) {
661 delete_window(buffer.window);
664 throw interactive_error("Can't kill last buffer.");
666 buffers.kill_buffer(buffer);
668 interactive("kill-buffer",
669 "Kill a buffer specified in the minibuffer.\n" +
670 "If `can_kill_last_buffer' is set to true, an attempt to kill the "+
671 "last remaining buffer in a window will cause the window to be closed.",
673 kill_buffer((yield I.minibuffer.read_buffer($prompt = "Kill buffer:")));
676 interactive("kill-current-buffer",
677 "Kill the current buffer.\n" +
678 "If `can_kill_last_buffer' is set to true, an attempt to kill the "+
679 "last remaining buffer in a window will cause the window to be closed.",
680 function (I) { kill_buffer(I.buffer); });
682 interactive("read-buffer-kill-buffer",
683 "Kill the current selected buffer in the completions list "+
684 "in a read buffer minibuffer interaction.",
686 var s = I.window.minibuffer.current_state;
687 var i = s.selected_completion_index;
688 var c = s.completions;
691 kill_buffer(c.get_value(i));
692 s.completer.refresh();
693 s.handle_input(I.window.minibuffer);
696 interactive("bury-buffer",
697 "Bury the current buffer.\n Put the current buffer at the end of " +
698 "the buffer list, so that it is the least likely buffer to be " +
699 "selected by `switch-to-buffer'.",
700 function (I) { I.window.buffers.bury_buffer(I.buffer); });
702 function change_directory (buffer, dir) {
703 if (buffer.page != null)
704 delete buffer.page.local.cwd;
705 buffer.local.cwd = make_file(dir);
707 interactive("change-directory",
708 "Change the current directory of the selected buffer.",
712 (yield I.minibuffer.read_existing_directory_path(
713 $prompt = "Change to directory:",
714 $initial_value = make_file(I.local.cwd).path)));
717 interactive("shell-command", null,
719 var cwd = I.local.cwd;
720 var cmd = (yield I.minibuffer.read_shell_command($cwd = cwd));
721 yield shell_command(cmd, $cwd = cwd);
726 * unfocus is a high-level command for unfocusing hyperlinks, inputs,
727 * frames, iframes, plugins, and also clearing the selection.
729 define_buffer_local_hook("unfocus_hook");
730 function unfocus (window, buffer) {
731 // 1. if there is a selection, clear it.
732 var selc = buffer.focused_selection_controller;
734 var sel = selc.getSelection(selc.SELECTION_NORMAL);
735 var active = ! sel.isCollapsed;
736 clear_selection(buffer);
738 window.minibuffer.message("cleared selection");
742 // 2. if there is a focused element, unfocus it.
743 if (buffer.focused_element) {
744 buffer.focused_element.blur();
745 // if an element in a detached fragment has focus, blur() will
746 // not work, and we need to take more drastic measures. the
747 // action taken was found through experiment, so it is possibly
748 // not the most concise way to unfocus such an element.
749 if (buffer.focused_element) {
750 buffer.element.focus();
751 buffer.top_frame.focus();
753 window.minibuffer.message("unfocused element");
756 // 3. if an iframe has focus, we must blur it.
757 if (buffer.focused_frame_or_null &&
758 buffer.focused_frame_or_null.frameElement)
760 buffer.focused_frame_or_null.frameElement.blur();
762 // 4. return focus to top-frame from subframes and plugins.
763 buffer.top_frame.focus();
764 buffer.top_frame.focus(); // needed to get focus back from plugins
765 window.minibuffer.message("refocused top frame");
766 // give page-modes an opportunity to set focus specially
767 unfocus_hook.run(buffer);
769 interactive("unfocus",
770 "Unfocus is a high-level command for unfocusing hyperlinks, inputs, "+
771 "frames, iframes, plugins, and also for clearing the selection. "+
772 "The action that it takes is based on precedence. If there is a "+
773 "focused hyperlink or input, it will unfocus that. Otherwise, if "+
774 "there is a selection, it will clear the selection. Otherwise, it "+
775 "will return focus to the top frame from a focused frame, iframe, "+
776 "or plugin. In the case of plugins, since they steal keyboard "+
777 "control away from Conkeror, the normal way to unfocus them is "+
778 "to use command-line remoting externally: conkeror -batch -f "+
779 "unfocus. Page-modes also have an opportunity to alter the default"+
780 "focus via the hook, `focus_hook'.",
782 unfocus(I.window, I.buffer);
786 function for_each_buffer (f) {
787 for_each_window(function (w) { w.buffers.for_each(f); });
795 var mode_functions = {};
796 var mode_display_names = {};
798 define_buffer_local_hook("buffer_mode_change_hook");
799 define_current_buffer_hook("current_buffer_mode_change_hook", "buffer_mode_change_hook");
801 define_keywords("$display_name", "$class", "$enable", "$disable", "$doc");
802 function define_buffer_mode (name) {
805 var hyphen_name = name.replace("_","-","g");
806 var display_name = arguments.$display_name;
807 var mode_class = arguments.$class;
808 var enable = arguments.$enable;
809 var disable = arguments.$disable;
811 mode_display_names[name] = display_name;
815 if (disable == false) {
821 var state = (mode_class != null) ? mode_class : (name + "_enabled");
822 var enable_hook_name = name + "_enable_hook";
823 var disable_hook_name = name + "_disable_hook";
824 define_buffer_local_hook(enable_hook_name);
825 define_buffer_local_hook(disable_hook_name);
827 var change_hook_name = null;
830 mode_functions[name] = { enable: enable,
832 mode_class: mode_class,
833 disable_hook_name: disable_hook_name };
834 change_hook_name = mode_class + "_change_hook";
835 define_buffer_local_hook(change_hook_name);
838 function func (buffer, arg) {
839 var old_state = buffer[state];
840 var cur_state = (old_state == name);
841 var new_state = (arg == null) ? !cur_state : (arg > 0);
842 if ((new_state == cur_state) || (!can_disable && !new_state))
843 // perhaps show a message if (!can_disable && !new_state)
844 // to tell the user that this mode cannot be disabled. do
845 // we have any existing modes that would benefit by it?
848 if (mode_class && old_state != null) {
849 // Another buffer-mode of our same mode-class is
850 // enabled. Buffer-modes within a mode-class are
851 // mutually exclusive, so turn the old one off.
852 buffer.enabled_modes.splice(buffer.enabled_modes.indexOf(old_state), 1);
853 let x = mode_functions[old_state];
856 conkeror[x.disable_hook_name].run(buffer);
858 buffer[state] = name;
861 conkeror[enable_hook_name].run(buffer);
862 buffer.enabled_modes.push(name);
864 buffer.enabled_modes.splice(buffer.enabled_modes.indexOf(name), 1);
866 conkeror[disable_hook_name].run(buffer);
867 buffer[state] = null;
869 if (change_hook_name)
870 conkeror[change_hook_name].run(buffer, buffer[state]);
871 buffer_mode_change_hook.run(buffer);
875 conkeror[name] = func;
876 interactive(hyphen_name, arguments.$doc, function (I) {
878 var new_state = func(I.buffer, arg && univ_arg_to_number(arg));
879 I.minibuffer.message(hyphen_name + (new_state ? " enabled" : " disabled"));
882 ignore_function_for_get_caller_source_code_reference("define_buffer_mode");
885 function minibuffer_mode_indicator (window) {
886 this.window = window;
887 var element = create_XUL(window, "label");
888 element.setAttribute("id", "minibuffer-mode-indicator");
889 element.collapsed = true;
890 element.setAttribute("class", "minibuffer");
891 window.document.getElementById("minibuffer").appendChild(element);
892 this.element = element;
893 this.hook_func = method_caller(this, this.update);
894 add_hook.call(window, "select_buffer_hook", this.hook_func);
895 add_hook.call(window, "current_buffer_mode_change_hook", this.hook_func);
898 minibuffer_mode_indicator.prototype = {
899 constructor: minibuffer_mode_indicator,
900 update: function () {
901 var buf = this.window.buffers.current;
902 var modes = buf.enabled_modes;
905 let y = mode_display_names[x];
907 return "[" + y + "]";
910 }).filter(function (x) x != null).join(" ");
911 this.element.collapsed = (str.length == 0);
912 this.element.value = str;
914 uninstall: function () {
915 remove_hook.call(window, "select_buffer_hook", this.hook_fun);
916 remove_hook.call(window, "current_buffer_mode_change_hook", this.hook_fun);
917 this.element.parentNode.removeChild(this.element);
920 define_global_window_mode("minibuffer_mode_indicator", "window_initialize_hook");
921 minibuffer_mode_indicator_mode(true);
928 define_current_buffer_hook("current_buffer_input_mode_change_hook", "input_mode_change_hook");
929 define_keywords("$display_name", "$doc");
930 function define_input_mode (base_name, keymap_name) {
932 var name = base_name + "_input_mode";
933 define_buffer_mode(name,
934 $class = "input_mode",
935 $enable = function (buffer) {
936 check_buffer(buffer, content_buffer);
937 buffer.keymaps.push(conkeror[keymap_name]);
939 $disable = function (buffer) {
940 var i = buffer.keymaps.indexOf(conkeror[keymap_name]);
942 buffer.keymaps.splice(i, 1);
944 forward_keywords(arguments));
946 ignore_function_for_get_caller_source_code_reference("define_input_mode");
949 function minibuffer_input_mode_indicator (window) {
950 this.window = window;
951 this.hook_func = method_caller(this, this.update);
952 add_hook.call(window, "select_buffer_hook", this.hook_func);
953 add_hook.call(window, "current_buffer_input_mode_change_hook", this.hook_func);
956 minibuffer_input_mode_indicator.prototype = {
957 constructor: minibuffer_input_mode_indicator,
958 update: function () {
959 var buf = this.window.buffers.current;
960 var mode = buf.input_mode;
961 var classname = mode ? ("minibuffer-" + buf.input_mode.replace("_","-","g")) : "";
962 this.window.minibuffer.element.className = classname;
964 uninstall: function () {
965 remove_hook.call(window, "select_buffer_hook", this.hook_func);
966 remove_hook.call(window, "current_buffer_input_mode_change_hook", this.hook_func);
970 define_global_window_mode("minibuffer_input_mode_indicator", "window_initialize_hook");
971 minibuffer_input_mode_indicator_mode(true);