3 define_window_local_hook("mode_line_hook");
5 function generic_element_widget_container(window, container)
8 this.container = container;
10 define_keywords("$flex", "$align", "$class", "$crop");
11 generic_element_widget_container.prototype = {
12 add_text_widget : function (widget) {
14 var flex = arguments.$flex;
15 var class_name = arguments.$class;
16 var align = arguments.$align;
17 var crop = arguments.$crop;
18 var element = create_XUL(this.window, "label");
20 element.setAttribute("flex", flex);
22 element.setAttribute("align", align);
23 if (class_name == null)
24 class_name = widget.name;
25 element.setAttribute("class", class_name);
28 element.setAttribute("crop", crop);
29 element.conkeror_widget = new generic_widget_element(element, widget);
30 this.container.appendChild(element);
31 return element.conkeror_widget;
33 destroy : function() {
34 var children = this.container.childNodes;
35 for (var i = 0; i < children.length; ++i)
36 children.item(i).conkeror_widget.destroy();
40 function mode_line(window)
42 var element = create_XUL(window, "hbox");
43 element.setAttribute("class", "mode-line");
44 /* FIXME: this will need to changed to be buffer-local */
45 var insert_before = window.document.getElementById("minibuffer");
46 insert_before.parentNode.insertBefore(element, insert_before);
47 window.mode_line = this;
48 generic_element_widget_container.call(this, window, element);
49 mode_line_hook.run(window, this);
51 mode_line.prototype = {
52 __proto__: generic_element_widget_container.prototype,
54 uninstall: function () {
55 this.container.parentNode.removeChild(this.window.mode_line.container);
56 this.__proto__.__proto__.destroy.call(this);
61 function generic_widget_element(element, widget)
63 this.element = element;
68 generic_widget_element.prototype = {
70 return this.element.getAttribute("value");
74 this.element.setAttribute("value", v);
77 destroy : function () {
78 this.widget.destroy();
81 remove : function () {
82 this.element.parentNode.removeChild(this.element);
88 function text_widget(window)
90 this.window_hooks = [];
93 text_widget.prototype = {
94 add_hook : function (hook_name, handler)
97 if (handler == null) handler = function () { obj.update(); }
98 add_hook.call(this.window, hook_name, handler);
99 this.window_hooks.push(handler);
104 attach : function (view) {
109 update : function () {
112 destroy : function ()
114 for (var i = 0; i < this.window_hooks.length; ++i)
115 remove_hook.call(this.window, this.window_hooks[i]);
124 define_global_window_mode("mode_line", "window_initialize_early_hook");
126 function current_buffer_name_widget(window) {
127 this.name = "current-buffer-name-widget";
128 text_widget.call(this, window);
130 this.add_hook("current_content_buffer_location_change_hook");
131 this.add_hook("select_buffer_hook");
133 current_buffer_name_widget.prototype.__proto__ = text_widget.prototype;
134 current_buffer_name_widget.prototype.update = function () {
135 this.view.text = this.window.buffers.current.description;
138 function current_buffer_scroll_position_widget(window) {
139 this.name = "current-buffer-scroll-position-widget";
140 text_widget.call(this, window);
141 this.add_hook("current_buffer_scroll_hook");
142 this.add_hook("select_buffer_hook");
143 this.add_hook("current_content_buffer_location_change_hook");
144 this.add_hook("current_content_buffer_focus_change_hook");
146 current_buffer_scroll_position_widget.prototype.__proto__ = text_widget.prototype;
147 current_buffer_scroll_position_widget.prototype.update = function () {
148 var b = this.window.buffers.current;
149 var scrollX, scrollY, scrollMaxX, scrollMaxY;
150 if (b instanceof content_buffer)
152 var w = b.focused_frame;
155 scrollMaxX = w.scrollMaxX;
156 scrollMaxY = w.scrollMaxY;
161 scrollMaxX = b.scrollMaxX;
162 scrollMaxY = b.scrollMaxY;
164 var x = scrollMaxX == 0 ? 100 : Math.round(scrollX / scrollMaxX * 100);
165 var y = scrollMaxY == 0 ? 100 : Math.round(scrollY / scrollMaxY * 100);
166 this.view.text = "(" + x + ", " + y + ")";
169 function clock_widget(window)
171 this.name = "clock-widget";
172 text_widget.call(this, window);
174 this.timer_ID = window.setInterval(function () { obj.update(); }, 60000);
176 clock_widget.prototype.__proto__ = text_widget.prototype;
177 clock_widget.prototype.update = function () {
178 var time = new Date();
179 var hours = time.getHours();
180 var mins = time.getMinutes();
181 this.view.text = (hours<10 ? "0" + hours:hours) + ":" + (mins<10 ?"0" +mins:mins);
183 clock_widget.prototype.destroy = function () {
184 this.window.clearTimeout(this.timer_ID);
187 function mode_line_adder(widget_constructor) {
188 return function (window) { window.mode_line.add_text_widget(new widget_constructor(window)); }
191 add_hook("mode_line_hook", mode_line_adder(current_buffer_name_widget));
192 add_hook("mode_line_hook", mode_line_adder(clock_widget));
193 add_hook("mode_line_hook", mode_line_adder(current_buffer_scroll_position_widget));
195 mode_line_mode(true);