utils.js: add function string_hashmap.for_each_value
[conkeror.git] / modules / frameset.js
blob6bdb16f4d0f964355ddc4862f2bfbd3bde2cc5a1
2 function close_frameset_notification_popup(frame)
4     if (frame.frameset_notification_timer)
5     {
6         frame.clearTimeout (frame.frameset_notification_timer);
7         frame.frameset_notification_timer = null;
8         frame.frameset_notification_popup.hidePopup();
9     }
12 function frameset_initialize_frame(frame) {
13     var p = frame.popups.create();
14     p.setAttribute("id", "frameset-notification");
15     p.addEventListener("popuphidden", function () {
16             frame.clearTimeout (frame.frameset_notification_timer);
17             frame.frameset_notification_timer = null;
18         }, true /* capture */, false /* don't allow untrusted */);
19     frame.frameset_notification_popup = p;
20     var desc = create_XUL(frame, "label");
21     desc.setAttribute("id", "frameset-notification-label");
22     p.appendChild(desc);
23     frame.frameset_notification_label = desc;
26 add_hook("frame_initialize_hook", frameset_initialize_frame);
28 add_hook("select_buffer_hook", function (buffer) { close_frameset_notification_popup(buffer.frame); });
30 /* USER PREFERENCE */
31 var frameset_notify_timeout = 1000;
33 function frameset_notify (frame, x, y, text) {
34     frame.frameset_notification_label.setAttribute("value", text);
35     frame.popups.show_absolute(frame.frameset_notification_popup, x, y);
36     frame.frameset_notification_timer = frame.setTimeout (
37         function () {
38             frame.frameset_notification_timer = null;
39             frame.frameset_notification_popup.hidePopup();
40         }, frameset_notify_timeout);
43 function frameset_find_frames_r (doc, types) {
44     var frames = [];
45     for (var j = 0; j < types.length; j++) {
46         var fr = doc.getElementsByTagName (types[j]);
47         for (var i = 0; i < fr.length; i++) {
48             frames.push (fr[i]);
49             frames = frames.concat (frameset_find_frames_r (fr[i].contentDocument, types));
50         }
51     }
52     return frames;
56 function next_frameset_frame (frame, prefix) {
57     var frames = frameset_find_frames_r (frame.buffers.current.content_document, ["FRAME"]);
58     if (frames.length == 0)
59     {
60         frame.minibuffer.message ("no other frameset frame");
61         return;
62     }
64     var w = frame.buffers.current.focused_window();
66     var next = 0;
68     for (var i = 0; i < frames.length; i++) {
69         if (w.document == frames[i].contentDocument) {
70             next = (i + prefix) % frames.length;
71             // the % operator is actually remainder in javascript, so we have
72             // to watch for negative results.
73             if (next < 0)
74                 next += frames.length;
75             break;
76         }
77     }
78     frames[next].scrollIntoView (false);
79     frames[next].contentWindow.focus();
81     var box = frames[next].ownerDocument.getBoxObjectFor (frames[next]);
83     frameset_notify (frame, box.screenX, box.screenY,
84                           "frameset frame "+next);
86 interactive("next-frameset-frame", next_frameset_frame, I.current_frame, I.p);
90 function next_iframe (frame, prefix) {
91     var frames = frame.buffers.current.content_document.getElementsByTagName ("IFRAME");
92     if (frames.length == 0)
93     {
94         frame.minibuffer.message ("no other iframe");
95         return;
96     }
98     var current = frame.buffers.current.focused_window();
100     var pnext = 0;
102     for (var i = 0; i < frames.length; i++) {
103         if (current.document == frames[i].contentDocument) {
104             pnext = (i + prefix) % frames.length;
105             // the % operator is actually remainder in javascript, so we have
106             // to watch for negative results.
107             if (pnext < 0)
108                 pnext += frames.length;
109             break;
110         }
111     }
113     var next = pnext;
114     frames[next].contentWindow.focus();
116     while (frame.buffers.content.focused_window() == current)
117     {
118         next = (next + (prefix < 0 ? -1 : 1)) % frames.length;
119         if (next < 0)
120             next += frames.length;
122         if (next == pnext) {
123             frame.minibuffer.message ("no other iframe visible");
124             return;
125         }
127         frames[next].contentWindow.focus();
128     }
130     var box = frame.buffers.current.content_document.getBoxObjectFor (frames[next]);
131     frames[next].scrollIntoView (false);
133     frameset_notify (frame, box.screenX, box.screenY,
134                           "iframe "+next);
136 interactive("next-iframe", next_iframe, I.current_frame, I.p);
139 function frameset_focus_top (b) {
140     b.content_window.focus();
141     var box = b.frame.buffers.container.boxObject;
142     frameset_notify (b.frame, box.screenX, box.screenY, "frameset top");
144 interactive("frameset-focus-top", frameset_focus_top, I.current_buffer(browser_buffer));
147 function frameset_focus_up (b) {
148     var parent = b.focused_window().parent;
149     parent.focus();
150     frameset_notify (b.frame, parent.screenX, parent.screenY, "frameset up");
152 interactive("frameset-focus-up", frameset_focus_up, I.current_buffer(browser_buffer));