grafthistory: support curl
[elinks/elinks-j605.git] / src / ecmascript / spidermonkey / unibar.c
blob8abc666ca77471b508d78420d0470fd34e35d128
1 /* The SpiderMonkey location and history objects implementation. */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 #include "elinks.h"
13 #include "ecmascript/spidermonkey/util.h"
15 #include "bfu/dialog.h"
16 #include "cache/cache.h"
17 #include "cookies/cookies.h"
18 #include "dialogs/menu.h"
19 #include "dialogs/status.h"
20 #include "document/html/frames.h"
21 #include "document/document.h"
22 #include "document/forms.h"
23 #include "document/view.h"
24 #include "ecmascript/ecmascript.h"
25 #include "ecmascript/spidermonkey/unibar.h"
26 #include "ecmascript/spidermonkey/window.h"
27 #include "intl/gettext/libintl.h"
28 #include "main/select.h"
29 #include "osdep/newwin.h"
30 #include "osdep/sysname.h"
31 #include "protocol/http/http.h"
32 #include "protocol/uri.h"
33 #include "session/history.h"
34 #include "session/location.h"
35 #include "session/session.h"
36 #include "session/task.h"
37 #include "terminal/tab.h"
38 #include "terminal/terminal.h"
39 #include "util/conv.h"
40 #include "util/memory.h"
41 #include "util/string.h"
42 #include "viewer/text/draw.h"
43 #include "viewer/text/form.h"
44 #include "viewer/text/link.h"
45 #include "viewer/text/vs.h"
48 static JSBool unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
49 static JSBool unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp);
51 /* Each @menubar_class object must have a @window_class parent. */
52 const JSClass menubar_class = {
53 "menubar",
54 JSCLASS_HAS_PRIVATE, /* const char * "t" */
55 JS_PropertyStub, JS_PropertyStub,
56 unibar_get_property, unibar_set_property,
57 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
59 /* Each @statusbar_class object must have a @window_class parent. */
60 const JSClass statusbar_class = {
61 "statusbar",
62 JSCLASS_HAS_PRIVATE, /* const char * "s" */
63 JS_PropertyStub, JS_PropertyStub,
64 unibar_get_property, unibar_set_property,
65 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
68 enum unibar_prop { JSP_UNIBAR_VISIBLE };
69 const JSPropertySpec unibar_props[] = {
70 { "visible", JSP_UNIBAR_VISIBLE, JSPROP_ENUMERATE },
71 { NULL }
75 /* @menubar_class.getProperty, @statusbar_class.getProperty */
76 static JSBool
77 unibar_get_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
79 JSObject *parent_win; /* instance of @window_class */
80 struct view_state *vs;
81 struct document_view *doc_view;
82 struct session_status *status;
83 unsigned char *bar;
85 /* This can be called if @obj if not itself an instance of either
86 * appropriate class but has one in its prototype chain. Fail
87 * such calls. */
88 if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
89 && !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
90 return JS_FALSE;
91 parent_win = JS_GetParent(ctx, obj);
92 assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
93 if_assert_failed return JS_FALSE;
95 vs = JS_GetInstancePrivate(ctx, parent_win,
96 (JSClass *) &window_class, NULL);
97 doc_view = vs->doc_view;
98 status = &doc_view->session->status;
99 bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
101 if (!JSVAL_IS_INT(id))
102 return JS_TRUE;
104 switch (JSVAL_TO_INT(id)) {
105 case JSP_UNIBAR_VISIBLE:
106 #define unibar_fetch(bar) \
107 boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
108 ? status->force_show_##bar##_bar \
109 : status->show_##bar##_bar)
110 switch (*bar) {
111 case 's':
112 unibar_fetch(status);
113 break;
114 case 't':
115 unibar_fetch(title);
116 break;
117 default:
118 boolean_to_jsval(ctx, vp, 0);
119 break;
121 #undef unibar_fetch
122 break;
123 default:
124 /* Unrecognized integer property ID; someone is using
125 * the object as an array. SMJS builtin classes (e.g.
126 * js_RegExpClass) just return JS_TRUE in this case
127 * and leave *@vp unchanged. Do the same here. */
128 break;
131 return JS_TRUE;
134 /* @menubar_class.setProperty, @statusbar_class.setProperty */
135 static JSBool
136 unibar_set_property(JSContext *ctx, JSObject *obj, jsval id, jsval *vp)
138 JSObject *parent_win; /* instance of @window_class */
139 struct view_state *vs;
140 struct document_view *doc_view;
141 struct session_status *status;
142 unsigned char *bar;
144 /* This can be called if @obj if not itself an instance of either
145 * appropriate class but has one in its prototype chain. Fail
146 * such calls. */
147 if (!JS_InstanceOf(ctx, obj, (JSClass *) &menubar_class, NULL)
148 && !JS_InstanceOf(ctx, obj, (JSClass *) &statusbar_class, NULL))
149 return JS_FALSE;
150 parent_win = JS_GetParent(ctx, obj);
151 assert(JS_InstanceOf(ctx, parent_win, (JSClass *) &window_class, NULL));
152 if_assert_failed return JS_FALSE;
154 vs = JS_GetInstancePrivate(ctx, parent_win,
155 (JSClass *) &window_class, NULL);
156 doc_view = vs->doc_view;
157 status = &doc_view->session->status;
158 bar = JS_GetPrivate(ctx, obj); /* from @menubar_class or @statusbar_class */
160 if (!JSVAL_IS_INT(id))
161 return JS_TRUE;
163 switch (JSVAL_TO_INT(id)) {
164 case JSP_UNIBAR_VISIBLE:
165 switch (*bar) {
166 case 's':
167 status->force_show_status_bar = jsval_to_boolean(ctx, vp);
168 break;
169 case 't':
170 status->force_show_title_bar = jsval_to_boolean(ctx, vp);
171 break;
172 default:
173 break;
175 register_bottom_half(update_status, NULL);
176 break;
177 default:
178 /* Unrecognized integer property ID; someone is using
179 * the object as an array. SMJS builtin classes (e.g.
180 * js_RegExpClass) just return JS_TRUE in this case.
181 * Do the same here. */
182 return JS_TRUE;
185 return JS_TRUE;