Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / embedding / browser / gtk / tests / TestGtkEmbedChild.cpp
blob65cb68bea5ce4baf6e642fd866fa7a4c421f0c51
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Christopher Blizzard.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Christopher Blizzard <blizzard@mozilla.org>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "gtkmozembed.h"
39 #include <gtk/gtk.h>
40 #include <gdk/gdkx.h>
41 #include <stdio.h>
42 #include <stdlib.h>
44 #include "nsStringAPI.h"
45 #include "gtkmozembed_glue.cpp"
47 int (*old_handler) (Display *, XErrorEvent *);
49 int error_handler (Display *d, XErrorEvent *e)
51 if ((e->error_code == BadWindow) || (e->error_code == BadDrawable))
53 XID resourceid = e->resourceid;
54 GdkWindow *window = gdk_window_lookup (resourceid);
56 if (window)
58 if (!g_dataset_get_data (window, "bonobo-error"))
60 g_dataset_set_data_full (window, "bonobo-error",
61 g_new (gint, 1),
62 (GDestroyNotify)g_free);
64 g_warning ("Error accessing window %ld", resourceid);
67 return 0;
69 else
71 return (*old_handler)(d, e);
75 void
76 load_page(gpointer data);
78 GtkWidget *embed = 0;
79 GtkWidget *entry = 0;
81 int
82 main(int argc, char **argv)
84 guint32 xid;
86 GtkWidget *window;
87 GtkWidget *hbox;
88 GtkWidget *vbox;
89 GtkWidget *button;
91 gtk_init(&argc, &argv);
93 static const GREVersionRange greVersion = {
94 "1.9a", PR_TRUE,
95 "2", PR_TRUE
98 char xpcomPath[PATH_MAX];
100 nsresult rv = GRE_GetGREPathWithProperties(&greVersion, 1, nsnull, 0,
101 xpcomPath, sizeof(xpcomPath));
102 if (NS_FAILED(rv)) {
103 fprintf(stderr, "Couldn't find a compatible GRE.\n");
104 return 1;
107 rv = XPCOMGlueStartup(xpcomPath);
108 if (NS_FAILED(rv)) {
109 fprintf(stderr, "Couldn't start XPCOM.");
110 return 1;
113 rv = GTKEmbedGlueStartup();
114 if (NS_FAILED(rv)) {
115 fprintf(stderr, "Couldn't find GTKMozEmbed symbols.");
116 return 1;
119 char *lastSlash = strrchr(xpcomPath, '/');
120 if (lastSlash)
121 *lastSlash = '\0';
123 gtk_moz_embed_set_path(xpcomPath);
125 old_handler = XSetErrorHandler (error_handler);
127 if (argc < 2) {
128 fprintf(stderr, "Usage: TestGtkEmbedChild WINDOW_ID\n");
129 exit(1);
132 xid = strtol (argv[1], (char **)NULL, 0);
134 if (xid == 0) {
135 fprintf(stderr, "Invalid window id '%s'\n", argv[1]);
136 exit(1);
139 window = gtk_plug_new(xid);
141 gtk_signal_connect(GTK_OBJECT(window), "destroy",
142 GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
144 gtk_container_border_width(GTK_CONTAINER(window), 0);
146 vbox = gtk_vbox_new (FALSE, 0);
147 gtk_container_add(GTK_CONTAINER(window), vbox);
148 gtk_widget_show(vbox);
150 hbox = gtk_hbox_new (FALSE, 0);
151 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
152 gtk_widget_show (hbox);
154 entry = gtk_entry_new ();
155 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
156 gtk_widget_show (entry);
158 button = gtk_button_new_with_label("Load");
159 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
160 gtk_widget_show(button);
162 gtk_signal_connect(GTK_OBJECT(button), "clicked",
163 GTK_SIGNAL_FUNC(load_page), NULL);
165 embed = gtk_moz_embed_new();
166 gtk_box_pack_start(GTK_BOX(vbox), embed, TRUE, TRUE, 0);
167 gtk_widget_set_usize(embed, 200, 200);
168 gtk_widget_show(embed);
170 gtk_widget_show(window);
172 gtk_main();
174 fprintf(stderr, "exiting.\n");
176 return 0;
179 void
180 load_page(gpointer data)
182 gchar *text = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
183 g_print("load url %s\n", text);
184 gtk_moz_embed_load_url(GTK_MOZ_EMBED(embed), text);
185 g_free(text);