1 /* The SpiderMonkey location and history objects implementation. */
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
, jsid id
, jsval
*vp
);
49 static JSBool
unibar_set_property(JSContext
*ctx
, JSObject
*obj
, jsid id
, JSBool strict
, jsval
*vp
);
51 /* Each @menubar_class object must have a @window_class parent. */
52 const JSClass menubar_class
= {
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
= {
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 /* Tinyids of properties. Use negative values to distinguish these
69 * from array indexes (even though this object has no array elements).
70 * ECMAScript code should not use these directly as in menubar[-1];
71 * future versions of ELinks may change the numbers. */
73 JSP_UNIBAR_VISIBLE
= -1,
75 const JSPropertySpec unibar_props
[] = {
76 { "visible", JSP_UNIBAR_VISIBLE
, JSPROP_ENUMERATE
},
81 /* @menubar_class.getProperty, @statusbar_class.getProperty */
83 unibar_get_property(JSContext
*ctx
, JSObject
*obj
, jsid id
, jsval
*vp
)
85 JSObject
*parent_win
; /* instance of @window_class */
86 struct view_state
*vs
;
87 struct document_view
*doc_view
;
88 struct session_status
*status
;
91 /* This can be called if @obj if not itself an instance of either
92 * appropriate class but has one in its prototype chain. Fail
94 if (!JS_InstanceOf(ctx
, obj
, (JSClass
*) &menubar_class
, NULL
)
95 && !JS_InstanceOf(ctx
, obj
, (JSClass
*) &statusbar_class
, NULL
))
97 parent_win
= JS_GetParent(ctx
, obj
);
98 assert(JS_InstanceOf(ctx
, parent_win
, (JSClass
*) &window_class
, NULL
));
99 if_assert_failed
return JS_FALSE
;
101 vs
= JS_GetInstancePrivate(ctx
, parent_win
,
102 (JSClass
*) &window_class
, NULL
);
103 doc_view
= vs
->doc_view
;
104 status
= &doc_view
->session
->status
;
105 bar
= JS_GetPrivate(ctx
, obj
); /* from @menubar_class or @statusbar_class */
107 if (!JSID_IS_INT(id
))
110 switch (JSID_TO_INT(id
)) {
111 case JSP_UNIBAR_VISIBLE
:
112 #define unibar_fetch(bar) \
113 boolean_to_jsval(ctx, vp, status->force_show_##bar##_bar >= 0 \
114 ? status->force_show_##bar##_bar \
115 : status->show_##bar##_bar)
118 unibar_fetch(status
);
124 boolean_to_jsval(ctx
, vp
, 0);
130 /* Unrecognized integer property ID; someone is using
131 * the object as an array. SMJS builtin classes (e.g.
132 * js_RegExpClass) just return JS_TRUE in this case
133 * and leave *@vp unchanged. Do the same here. */
140 /* @menubar_class.setProperty, @statusbar_class.setProperty */
142 unibar_set_property(JSContext
*ctx
, JSObject
*obj
, jsid id
, JSBool strict
, jsval
*vp
)
144 JSObject
*parent_win
; /* instance of @window_class */
145 struct view_state
*vs
;
146 struct document_view
*doc_view
;
147 struct session_status
*status
;
150 /* This can be called if @obj if not itself an instance of either
151 * appropriate class but has one in its prototype chain. Fail
153 if (!JS_InstanceOf(ctx
, obj
, (JSClass
*) &menubar_class
, NULL
)
154 && !JS_InstanceOf(ctx
, obj
, (JSClass
*) &statusbar_class
, NULL
))
156 parent_win
= JS_GetParent(ctx
, obj
);
157 assert(JS_InstanceOf(ctx
, parent_win
, (JSClass
*) &window_class
, NULL
));
158 if_assert_failed
return JS_FALSE
;
160 vs
= JS_GetInstancePrivate(ctx
, parent_win
,
161 (JSClass
*) &window_class
, NULL
);
162 doc_view
= vs
->doc_view
;
163 status
= &doc_view
->session
->status
;
164 bar
= JS_GetPrivate(ctx
, obj
); /* from @menubar_class or @statusbar_class */
166 if (!JSID_IS_INT(id
))
169 switch (JSID_TO_INT(id
)) {
170 case JSP_UNIBAR_VISIBLE
:
173 status
->force_show_status_bar
= jsval_to_boolean(ctx
, vp
);
176 status
->force_show_title_bar
= jsval_to_boolean(ctx
, vp
);
181 register_bottom_half(update_status
, NULL
);
184 /* Unrecognized integer property ID; someone is using
185 * the object as an array. SMJS builtin classes (e.g.
186 * js_RegExpClass) just return JS_TRUE in this case.
187 * Do the same here. */