1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
#include "config.h"
#define MOZILLA_CLIENT
#include <hildon/hildon.h>
#include <stdlib.h>
#include <gtkmozembed.h>
#include <gtkmozembed_internal.h>
#include <nsCOMPtr.h>
#include <nsIDOMWindow.h>
#include <nsIDOMWindowUtils.h>
#include <nsIInterfaceRequestorUtils.h>
#include <nsEmbedString.h>
static gboolean
expose_event_cb (GtkWidget *widget, GdkEventExpose *event)
{
cairo_t *cr = gdk_cairo_create (widget->window);
GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
gdk_cairo_set_source_pixmap (cr, child->window, child->allocation.x, child->allocation.y);
/* draw no more than our expose event intersects our child */
GdkRegion *region = gdk_region_rectangle (&child->allocation);
gdk_region_intersect (region, event->region);
gdk_cairo_region (cr, region);
cairo_clip (cr);
/* composite, with a 50% opacity */
cairo_paint_with_alpha (cr, 254./255);
/* scollbars */
cairo_set_source_rgba (cr, 0.8, 0.8, 0.8, 0.8);
cairo_rectangle (cr,
child->allocation.x + child->allocation.width -
HILDON_MARGIN_DEFAULT - HILDON_MARGIN_HALF,
child->allocation.y + HILDON_MARGIN_HALF,
HILDON_MARGIN_DEFAULT,
0.6 * (child->allocation.height - HILDON_MARGIN_DOUBLE));
cairo_rectangle (cr,
child->allocation.x + HILDON_MARGIN_HALF,
child->allocation.y + child->allocation.height -
HILDON_MARGIN_DEFAULT - HILDON_MARGIN_HALF,
0.6 * (child->allocation.width - HILDON_MARGIN_DOUBLE),
HILDON_MARGIN_DEFAULT);
cairo_fill (cr);
cairo_destroy (cr);
return FALSE;
}
static GdkEvent *last_button_event = NULL;
#if 0
#include <gdk/gdkx.h>
static const char *
event_name (GdkEventType type)
{
static GEnumClass *enum_class = NULL;
GEnumValue *value;
if (!enum_class)
enum_class = static_cast<GEnumClass *> (g_type_class_ref (GDK_TYPE_EVENT_TYPE));
value = g_enum_get_value (enum_class, type);
return (value ? value->value_nick : "unknown");
}
static void
send_motion_event (GtkWidget *widget, GdkEventMotion *event)
{
XEvent xev;
xev.xmotion.type = MotionNotify;
xev.xmotion.serial = 0;
xev.xmotion.send_event = True;
xev.xmotion.display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget));
xev.xmotion.window = GDK_WINDOW_XWINDOW (gtk_widget_get_window (widget));
xev.xmotion.root = GDK_WINDOW_XWINDOW (gtk_widget_get_root_window (widget));
xev.xmotion.subwindow = GDK_WINDOW_XWINDOW (gtk_widget_get_window (widget));
xev.xmotion.time = event->time;
xev.xmotion.x = event->x;
xev.xmotion.y = event->y;
xev.xmotion.x_root = event->x_root;
xev.xmotion.y_root = event->y_root;
xev.xmotion.same_screen = True;
xev.xmotion.state = event->state;
xev.xmotion.is_hint = event->is_hint;
XSendEvent(xev.xbutton.display, xev.xbutton.window, True, 0, &xev);
}
static void
send_crossing_event (GtkWidget *widget, GdkEventCrossing *event)
{
XEvent xev;
switch (event->type)
{
case GDK_ENTER_NOTIFY:
xev.xcrossing.type = EnterNotify;
break;
case GDK_LEAVE_NOTIFY:
xev.xcrossing.type = LeaveNotify;
break;
default:
g_return_if_reached ();
}
xev.xcrossing.serial = 0;
xev.xcrossing.send_event = True;
xev.xcrossing.display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget));
xev.xcrossing.window = GDK_WINDOW_XWINDOW (gtk_widget_get_window (widget));
xev.xcrossing.root = GDK_WINDOW_XWINDOW (gtk_widget_get_root_window (widget));
xev.xcrossing.subwindow = GDK_WINDOW_XWINDOW (gtk_widget_get_window (widget));
xev.xcrossing.time = event->time;
xev.xcrossing.x = event->x;
xev.xcrossing.y = event->y;
xev.xcrossing.x_root = event->x_root;
xev.xcrossing.y_root = event->y_root;
xev.xcrossing.same_screen = True;
xev.xcrossing.mode = event->mode;
xev.xcrossing.detail = event->detail;
xev.xcrossing.focus = event->focus;
xev.xcrossing.state = event->state;
XSendEvent(xev.xbutton.display, xev.xbutton.window, True, 0, &xev);
}
static gboolean
event_cb (GtkWidget *widget, GdkEvent *event)
{
GtkWidget *child;
g_print ("%s: %s event (%d) for %s (%p/%p)\n",
G_STRFUNC, event_name (event->type),
event->type, gtk_widget_get_name (widget),
widget->window, event->any.window);
if (!GTK_IS_BIN (widget) || widget->window != event->any.window)
return FALSE;
child = gtk_bin_get_child (GTK_BIN (widget));
switch (event->type)
{
case GDK_MOTION_NOTIFY:
send_motion_event (child, &event->motion);
break;
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
send_crossing_event (child, &event->crossing);
break;
default:
break;
}
return FALSE;
}
#endif
static void
send_mouse_event (GtkWidget *embed, GdkEvent *event, const nsAString &name)
{
nsCOMPtr<nsIWebBrowser> browser;
gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED (embed), getter_AddRefs (browser));
nsCOMPtr<nsIDOMWindow> window;
browser->GetContentDOMWindow (getter_AddRefs (window));
nsCOMPtr<nsIDOMWindowUtils> utils (do_GetInterface (window));
utils->SendMouseEvent(name,
float(event->button.x), float(event->button.y),
event->button.button, 1, 0, PR_FALSE);
}
static gboolean
button_press_cb (GtkWidget *widget, GdkEvent *event)
{
g_print ("%s: event-type=%d\n", G_STRFUNC, event->type);
if (last_button_event)
gdk_event_free (last_button_event);
last_button_event = gdk_event_copy (event);
GtkWidget *embed = gtk_bin_get_child (GTK_BIN (widget));
send_mouse_event (embed, event, NS_LITERAL_STRING("mousedown"));
return TRUE;
}
static gboolean
button_release_cb (GtkWidget *widget, GdkEvent *event)
{
g_print ("%s: event-type=%d, %p %p\n", G_STRFUNC, event->type, widget->window, event->any.window);
GtkWidget *embed = gtk_bin_get_child (GTK_BIN (widget));
send_mouse_event (embed, event, NS_LITERAL_STRING("mouseup"));
if (last_button_event)
{
int dx = abs (event->button.x - last_button_event->button.x);
int dy = abs (event->button.y - last_button_event->button.y);
if (3 >= dx && 3 >= dy)
{
g_print ("foo\n");
send_mouse_event (embed, event, NS_LITERAL_STRING("click"));
#if 0
XEvent xev;
xev.xbutton.type = ButtonPress;
xev.xbutton.serial = 0;
xev.xbutton.send_event = True;
xev.xbutton.display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (child));
xev.xbutton.window = GDK_WINDOW_XWINDOW (gtk_widget_get_window (child));
xev.xbutton.root = GDK_WINDOW_XWINDOW (gtk_widget_get_root_window (child));
xev.xbutton.subwindow = GDK_WINDOW_XWINDOW (gtk_widget_get_window (child));
xev.xbutton.time = last_button_event->button.time;
xev.xbutton.x = last_button_event->button.x;
xev.xbutton.y = last_button_event->button.y;
xev.xbutton.x_root = last_button_event->button.x_root;
xev.xbutton.y_root = last_button_event->button.y_root;
xev.xbutton.state = last_button_event->button.state;
xev.xbutton.button = last_button_event->button.button;
xev.xbutton.same_screen = True;
XSendEvent(xev.xbutton.display, xev.xbutton.window, True, 0, &xev);
xev.xbutton.type = ButtonRelease;
xev.xbutton.serial = 0;
xev.xbutton.send_event = True;
xev.xbutton.display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (child));
xev.xbutton.window = GDK_WINDOW_XWINDOW (gtk_widget_get_window (child));
xev.xbutton.root = GDK_WINDOW_XWINDOW (gtk_widget_get_root_window (child));
xev.xbutton.subwindow = GDK_WINDOW_XWINDOW (gtk_widget_get_window (child));
xev.xbutton.time = event->button.time;
xev.xbutton.x = event->button.x;
xev.xbutton.y = event->button.y;
xev.xbutton.x_root = event->button.x_root;
xev.xbutton.y_root = event->button.y_root;
xev.xbutton.state = event->button.state;
xev.xbutton.button = event->button.button;
xev.xbutton.same_screen = True;
XSendEvent(xev.xbutton.display, xev.xbutton.window, True, 0, &xev);
#endif
#if 0
last_button_event->button.window = child->window;
gtk_widget_event (child, last_button_event);
event = gdk_event_copy (event);
event->button.window = child->window;
gtk_widget_event (child, event);
//gdk_event_free (event);
#endif
}
else
gdk_event_free (last_button_event);
last_button_event = NULL;
}
return FALSE;
}
static gboolean
moz_button_press_cb (GtkWidget *widget, GdkEvent *event)
{
g_print ("%s: window=%p/%p, event=%p/%p\n", G_STRFUNC, widget->window, event->any.window, event, last_button_event);
return TRUE;
}
static gboolean
moz_button_release_cb (GtkWidget *widget, GdkEvent *event)
{
g_print ("%s: window=%p/%p, event=%p/%p\n", G_STRFUNC, widget->window, event->any.window, event, last_button_event);
return TRUE;
}
static int
open_uri_cb (GtkMozEmbed *embed, const char *aURI)
{
g_print ("%s: %s\n", __func__, aURI);
return 0;
}
int
main (int argc, char **argv)
{
guint32 chrome;
hildon_gtk_init (&argc, &argv);
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect_after (window, "expose-event", G_CALLBACK (expose_event_cb), NULL);
GtkWidget *ebox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (window), ebox);
gtk_event_box_set_above_child (GTK_EVENT_BOX (ebox), TRUE);
//g_signal_connect (ebox, "event", G_CALLBACK (event_cb), NULL);
g_signal_connect (ebox, "button-press-event", G_CALLBACK (button_press_cb), NULL);
g_signal_connect (ebox, "button-release-event", G_CALLBACK (button_release_cb), NULL);
gtk_widget_add_events (ebox, GDK_POINTER_MOTION_MASK);
gtk_moz_embed_set_path (MOZILLA_LIBDIR);
GtkWidget *embed = gtk_moz_embed_new ();
chrome = gtk_moz_embed_get_chrome_mask (GTK_MOZ_EMBED (embed));
gtk_moz_embed_set_chrome_mask (GTK_MOZ_EMBED (embed), chrome & ~GTK_MOZ_EMBED_FLAG_SCROLLBARSON);
gtk_moz_embed_load_url (GTK_MOZ_EMBED (embed), "file:///home/mathias/.dashboard.html");
g_signal_connect (embed, "button-press-event", G_CALLBACK (moz_button_press_cb), NULL);
g_signal_connect (embed, "button-release-event", G_CALLBACK (moz_button_release_cb), NULL);
g_signal_connect (embed, "open-uri", G_CALLBACK (open_uri_cb), NULL);
//g_signal_connect (embed, "event", G_CALLBACK (event_cb), NULL);
gtk_container_add (GTK_CONTAINER (ebox), embed);
gtk_widget_show_all (window);
gdk_window_set_composited (ebox->window, TRUE);
gtk_main ();
return 0;
}
|