Пример #1
0
static void
mozilla_embed_new_window (GtkMozEmbed *embed, 
			  GtkMozEmbed **newEmbed,
                          guint chromemask)
{
	MozillaEmbed *membed = MOZILLA_EMBED (embed);
	int i;
	EmbedChromeMask mask = EMBED_CHROME_OPENASPOPUP;
	GaleonEmbed *new_embed = NULL;

	struct
	{
		guint chromemask;
		EmbedChromeMask embed_mask;
	}
	conversion_map [] =
	{
		{ GTK_MOZ_EMBED_FLAG_DEFAULTCHROME, EMBED_CHROME_DEFAULT },
		{ GTK_MOZ_EMBED_FLAG_MENUBARON, EMBED_CHROME_MENUBARON },
		{ GTK_MOZ_EMBED_FLAG_TOOLBARON, EMBED_CHROME_TOOLBARON },
		/* Map the bookmarks bar to the default, as otherwise _blank
		 * pages don't honour the gconf settings, and always have the
		 * bookmarks bar, which just confuses people (bug 122410) */
		{ GTK_MOZ_EMBED_FLAG_PERSONALTOOLBARON, EMBED_CHROME_DEFAULT },
		{ GTK_MOZ_EMBED_FLAG_STATUSBARON, EMBED_CHROME_STATUSBARON },
		{ GTK_MOZ_EMBED_FLAG_WINDOWRAISED, EMBED_CHROME_WINDOWRAISED },
		{ GTK_MOZ_EMBED_FLAG_WINDOWLOWERED, EMBED_CHROME_WINDOWLOWERED },
		{ GTK_MOZ_EMBED_FLAG_CENTERSCREEN, EMBED_CHROME_CENTERSCREEN },
		{ GTK_MOZ_EMBED_FLAG_OPENASDIALOG, EMBED_CHROME_OPENASDIALOG },
		{ GTK_MOZ_EMBED_FLAG_OPENASCHROME, EMBED_CHROME_OPENASCHROME },
		{ 0, EMBED_CHROME_NONE }
	};

	for (i = 0; conversion_map[i].chromemask != 0; i++)
	{
		if (chromemask & conversion_map[i].chromemask)
		{
			mask = (EmbedChromeMask) (mask | conversion_map[i].embed_mask);	
		}
	}
	
	g_signal_emit_by_name (membed, "ge_new_window", mask, &new_embed);

	g_assert (new_embed != NULL);
	
	gtk_moz_embed_set_chrome_mask (GTK_MOZ_EMBED(new_embed), chromemask);

	*newEmbed = GTK_MOZ_EMBED(new_embed);
}
MozillaRenderer::MozillaRenderer()
{
	gtk_moz_embed_push_startup();

	// Create our web browser component
	m_htmlWidget = gtk_moz_embed_new();
	if (m_htmlWidget != NULL)
	{
		// Turn off all features
		gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(m_htmlWidget), GTK_MOZ_EMBED_FLAG_SCROLLBARSON);
#ifdef DEBUG
		cout << "MozillaRenderer::ctor: embedded Mozilla" << endl;
#endif
	}
#ifdef DEBUG
	else cerr << "MozillaRenderer::ctor: failed to embed Mozilla" << endl;
#endif
	m_rendering = false;
}
Пример #3
0
/**
 * Initialise the engine (must be called AFTER gtk_init())
 *
 * @param config - the config container in use
 */
void GeckoEmbed::init(ConfigContainer config) {
	// Set the environment
	Environment env;
	string configProfilePath = env.getUserGeckoProfilePath();
	string configProfileName = "medes-gecko";
	gtk_moz_embed_set_profile_path(configProfilePath.c_str(),configProfileName.c_str());
	GtkMozEmbed *mozEmbed = GTK_MOZ_EMBED(gtk_moz_embed_new());
	gtk_moz_embed_set_chrome_mask(mozEmbed, GTK_MOZ_EMBED_FLAG_ALLCHROME);
	// Attach to functors
	gtk_signal_connect(GTK_OBJECT(mozEmbed), "open_uri", GTK_SIGNAL_FUNC(&GeckoEmbed::open_uri_cb), this);
	gtk_signal_connect(GTK_OBJECT(mozEmbed), "progress", GTK_SIGNAL_FUNC(&GeckoEmbed::progress_change_cb), this);
	gtk_signal_connect(GTK_OBJECT(mozEmbed), "net_start", GTK_SIGNAL_FUNC(&GeckoEmbed::load_started_cb), this);
	gtk_signal_connect(GTK_OBJECT(mozEmbed), "net_stop", GTK_SIGNAL_FUNC(&GeckoEmbed::load_finished_cb), this);
	// Initial object configuration
	setMozEmbed(mozEmbed);
	setConfig(config);
	setUrl(config.getAppUrl());
	dataSize = 0;
	status = NULL;
}
Пример #4
0
void WebBrowserObject::BrowserSetChrome(guint chromemask)
{
    if (toplevel) {
        gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(mozilla), chromemask);
    }
}
Пример #5
0
int WebBrowserObject::BrowserOpen(void)
{
    Lock();
    if (!area.w) {
        area.w = systemObject->configGetInt("video_width", systemObject->GetScreenWidth());
    }
    if (!area.h) {
        area.h = systemObject->configGetInt("video_height", systemObject->GetScreenHeight());
    }
    if (!toplevel) {
        toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_realize(toplevel);
        gdk_window_set_decorations(toplevel->window, (GdkWMDecoration)0);
        toplevelVBox = gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER(toplevel), toplevelVBox);

        mozilla = gtk_moz_embed_new();
        gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(mozilla), GTK_MOZ_EMBED_FLAG_ALLCHROME);

        toolbarHBox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(toplevelVBox), toolbarHBox, FALSE, FALSE, 0);
        toolbar = gtk_toolbar_new();
        g_object_ref(toolbar);
        gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
        if (toolbar_flag) {
            gtk_box_pack_start(GTK_BOX(toolbarHBox), toolbar, FALSE, FALSE, 0);
        }
        backButton = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Back", "Go Back", "Go Back", 0, GTK_SIGNAL_FUNC(back_clicked_cb), this);
        stopButton = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Stop", "Stop", "Stop", 0, GTK_SIGNAL_FUNC(stop_clicked_cb), this);
        forwardButton = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Forward", "Forward", "Forward", 0, GTK_SIGNAL_FUNC(forward_clicked_cb), this);
        reloadButton = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Reload", "Reload", "Reload", 0, GTK_SIGNAL_FUNC(reload_clicked_cb), this);
        closeButton = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar), "Close", "Close window", "Close window", 0, GTK_SIGNAL_FUNC(close_clicked_cb), this);
        urlEntry = gtk_entry_new();
        g_object_ref(urlEntry);
        if (toolbar_flag) {
            gtk_box_pack_start(GTK_BOX(toolbarHBox), urlEntry, TRUE, TRUE, 0);
        }
        gtk_box_pack_start(GTK_BOX(toplevelVBox), mozilla, TRUE, TRUE, 0);
        progressAreaHBox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(toplevelVBox), progressAreaHBox, FALSE, FALSE, 0);
        progressBar = gtk_progress_bar_new();
        gtk_box_pack_start(GTK_BOX(progressAreaHBox), progressBar, FALSE, FALSE, 0);
        statusAlign = gtk_alignment_new(0, 0, 1, 1);
        gtk_widget_set_usize(statusAlign, 1, -1);
        statusBar = gtk_statusbar_new();
        gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusBar), 0);
        gtk_container_add(GTK_CONTAINER(statusAlign), statusBar);
        gtk_box_pack_start(GTK_BOX(progressAreaHBox), statusAlign, TRUE, TRUE, 0);

        gtk_widget_set_sensitive(closeButton, TRUE);
        gtk_widget_set_sensitive(backButton, FALSE);
        gtk_widget_set_sensitive(stopButton, FALSE);
        gtk_widget_set_sensitive(forwardButton, FALSE);
        gtk_widget_set_sensitive(reloadButton, FALSE);

        gtk_signal_connect(GTK_OBJECT(urlEntry), "activate", GTK_SIGNAL_FUNC(url_activate_cb), this);
        
        gtk_signal_connect(GTK_OBJECT(toplevel), "delete_event", GTK_SIGNAL_FUNC(delete_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "destroy", GTK_SIGNAL_FUNC(destroy_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "destroy_browser", GTK_SIGNAL_FUNC(destroy_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "title", GTK_SIGNAL_FUNC(title_changed_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "new_window", GTK_SIGNAL_FUNC(new_window_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "visibility", GTK_SIGNAL_FUNC(visibility_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "size_to", GTK_SIGNAL_FUNC(size_to_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "location", GTK_SIGNAL_FUNC(location_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "net_start", GTK_SIGNAL_FUNC(net_start_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "net_stop", GTK_SIGNAL_FUNC(net_stop_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "net_state",  GTK_SIGNAL_FUNC(net_state_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "progress", GTK_SIGNAL_FUNC(progress_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "link_message", GTK_SIGNAL_FUNC(link_message_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "js_status", GTK_SIGNAL_FUNC(js_status_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "open_uri", GTK_SIGNAL_FUNC(open_uri_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_key_down", GTK_SIGNAL_FUNC(dom_key_down_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_key_up", GTK_SIGNAL_FUNC(dom_key_up_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_down", GTK_SIGNAL_FUNC(dom_mouse_down_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_up", GTK_SIGNAL_FUNC(dom_mouse_up_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_key_press", GTK_SIGNAL_FUNC(dom_key_press_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_click", GTK_SIGNAL_FUNC(dom_mouse_click_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_dbl_click", GTK_SIGNAL_FUNC(dom_mouse_dbl_click_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_over", GTK_SIGNAL_FUNC(dom_mouse_over_cb), this);
        gtk_signal_connect(GTK_OBJECT(mozilla), "dom_mouse_out", GTK_SIGNAL_FUNC(dom_mouse_out_cb), this);
    }
    Unlock();
    SetPosition(area.x, area.y, area.w, area.h);
    SetVisible(1);
    if (location) {
        gtk_moz_embed_load_url(GTK_MOZ_EMBED(mozilla), location);
    }
    systemObject->RegisterExternalEventHandler(this);
    return 0;
}
Пример #6
0
static TestGtkBrowser *
new_gtk_browser(guint32 chromeMask)
{
    guint32         actualChromeMask = chromeMask;
    TestGtkBrowser *browser = 0;

    num_browsers++;

    browser = g_new0(TestGtkBrowser, 1);

    browser_list = g_list_prepend(browser_list, browser);

    browser->menuBarOn = FALSE;
    browser->toolBarOn = FALSE;
    browser->locationBarOn = FALSE;
    browser->statusBarOn = FALSE;

    g_print("new_gtk_browser\n");

    if (chromeMask == GTK_MOZ_EMBED_FLAG_DEFAULTCHROME)
        actualChromeMask = GTK_MOZ_EMBED_FLAG_ALLCHROME;

    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_MENUBARON)
    {
        browser->menuBarOn = TRUE;
        g_print("\tmenu bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_TOOLBARON)
    {
        browser->toolBarOn = TRUE;
        g_print("\ttool bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_LOCATIONBARON)
    {
        browser->locationBarOn = TRUE;
        g_print("\tlocation bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_STATUSBARON)
    {
        browser->statusBarOn = TRUE;
        g_print("\tstatus bar\n");
    }

    // create our new toplevel window
    browser->topLevelWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    // new vbox
    browser->topLevelVBox = gtk_vbox_new(FALSE, 0);
    // add it to the toplevel window
    gtk_container_add(GTK_CONTAINER(browser->topLevelWindow),
                      browser->topLevelVBox);
    // create our menu bar
    browser->menuBar = gtk_menu_bar_new();
    // create the file menu
    browser->fileMenuItem = gtk_menu_item_new_with_label("File");
    browser->fileMenu = gtk_menu_new();
    gtk_menu_item_set_submenu (GTK_MENU_ITEM(browser->fileMenuItem),
                               browser->fileMenu);

    browser->fileOpenNewBrowser =
        gtk_menu_item_new_with_label("Open New Browser");
    gtk_menu_append(GTK_MENU(browser->fileMenu),
                    browser->fileOpenNewBrowser);

    browser->fileStream =
        gtk_menu_item_new_with_label("Test Stream");
    gtk_menu_append(GTK_MENU(browser->fileMenu),
                    browser->fileStream);

    browser->fileClose =
        gtk_menu_item_new_with_label("Close");
    gtk_menu_append(GTK_MENU(browser->fileMenu),
                    browser->fileClose);

    browser->fileQuit =
        gtk_menu_item_new_with_label("Quit");
    gtk_menu_append(GTK_MENU(browser->fileMenu),
                    browser->fileQuit);

    // append it
    gtk_menu_bar_append(GTK_MENU_BAR(browser->menuBar), browser->fileMenuItem);

    // add it to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),
                       browser->menuBar,
                       FALSE, // expand
                       FALSE, // fill
                       0);    // padding
    // create the hbox that will contain the toolbar and the url text entry bar
    browser->toolbarHBox = gtk_hbox_new(FALSE, 0);
    // add that hbox to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),
                       browser->toolbarHBox,
                       FALSE, // expand
                       FALSE, // fill
                       0);    // padding
    // new horiz toolbar with buttons + icons
#ifdef MOZ_WIDGET_GTK
    browser->toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
                                       GTK_TOOLBAR_BOTH);
#endif /* MOZ_WIDGET_GTK */

#ifdef MOZ_WIDGET_GTK2
    browser->toolbar = gtk_toolbar_new();
    gtk_toolbar_set_orientation(GTK_TOOLBAR(browser->toolbar),
                                GTK_ORIENTATION_HORIZONTAL);
    gtk_toolbar_set_style(GTK_TOOLBAR(browser->toolbar),
                          GTK_TOOLBAR_BOTH);
#endif /* MOZ_WIDGET_GTK2 */

    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->toolbar,
                       FALSE, // expand
                       FALSE, // fill
                       0);    // padding
    // new back button
    browser->backButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
                                "Back",
                                "Go Back",
                                "Go Back",
                                0, // XXX replace with icon
                                GTK_SIGNAL_FUNC(back_clicked_cb),
                                browser);
    // new stop button
    browser->stopButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
                                "Stop",
                                "Stop",
                                "Stop",
                                0, // XXX replace with icon
                                GTK_SIGNAL_FUNC(stop_clicked_cb),
                                browser);
    // new forward button
    browser->forwardButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
                                "Forward",
                                "Forward",
                                "Forward",
                                0, // XXX replace with icon
                                GTK_SIGNAL_FUNC(forward_clicked_cb),
                                browser);
    // new reload button
    browser->reloadButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
                                "Reload",
                                "Reload",
                                "Reload",
                                0, // XXX replace with icon
                                GTK_SIGNAL_FUNC(reload_clicked_cb),
                                browser);
    // create the url text entry
    browser->urlEntry = gtk_entry_new();
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->urlEntry,
                       TRUE, // expand
                       TRUE, // fill
                       0);    // padding
    // create our new gtk moz embed widget
    browser->mozEmbed = gtk_moz_embed_new();
    // add it to the toplevel vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->mozEmbed,
                       TRUE, // expand
                       TRUE, // fill
                       0);   // padding
    // create the new hbox for the progress area
    browser->progressAreaHBox = gtk_hbox_new(FALSE, 0);
    // add it to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->progressAreaHBox,
                       FALSE, // expand
                       FALSE, // fill
                       0);   // padding
    // create our new progress bar
    browser->progressBar = gtk_progress_bar_new();
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->progressBar,
                       FALSE, // expand
                       FALSE, // fill
                       0); // padding

    // create our status area and the alignment object that will keep it
    // from expanding
    browser->statusAlign = gtk_alignment_new(0, 0, 1, 1);
    gtk_widget_set_usize(browser->statusAlign, 1, -1);
    // create the status bar
    browser->statusBar = gtk_statusbar_new();
    gtk_container_add(GTK_CONTAINER(browser->statusAlign), browser->statusBar);
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->statusAlign,
                       TRUE, // expand
                       TRUE, // fill
                       0);   // padding
    // by default none of the buttons are marked as sensitive.
    gtk_widget_set_sensitive(browser->backButton, FALSE);
    gtk_widget_set_sensitive(browser->stopButton, FALSE);
    gtk_widget_set_sensitive(browser->forwardButton, FALSE);
    gtk_widget_set_sensitive(browser->reloadButton, FALSE);

    // catch the destruction of the toplevel window
    gtk_signal_connect(GTK_OBJECT(browser->topLevelWindow), "delete_event",
                       GTK_SIGNAL_FUNC(delete_cb), browser);

    // hook up the activate signal to the right callback
    gtk_signal_connect(GTK_OBJECT(browser->urlEntry), "activate",
                       GTK_SIGNAL_FUNC(url_activate_cb), browser);

    // hook up to the open new browser activation
    gtk_signal_connect(GTK_OBJECT(browser->fileOpenNewBrowser), "activate",
                       GTK_SIGNAL_FUNC(menu_open_new_cb), browser);
    // hook up to the stream test
    gtk_signal_connect(GTK_OBJECT(browser->fileStream), "activate",
                       GTK_SIGNAL_FUNC(menu_stream_cb), browser);
    // close this window
    gtk_signal_connect(GTK_OBJECT(browser->fileClose), "activate",
                       GTK_SIGNAL_FUNC(menu_close_cb), browser);
    // quit the application
    gtk_signal_connect(GTK_OBJECT(browser->fileQuit), "activate",
                       GTK_SIGNAL_FUNC(menu_quit_cb), browser);

    // hook up the location change to update the urlEntry
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "location",
                       GTK_SIGNAL_FUNC(location_changed_cb), browser);
    // hook up the title change to update the window title
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "title",
                       GTK_SIGNAL_FUNC(title_changed_cb), browser);
    // hook up the start and stop signals
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "net_start",
                       GTK_SIGNAL_FUNC(load_started_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "net_stop",
                       GTK_SIGNAL_FUNC(load_finished_cb), browser);
    // hook up to the change in network status
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "net_state",
                       GTK_SIGNAL_FUNC(net_state_change_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "net_state_all",
                       GTK_SIGNAL_FUNC(net_state_change_all_cb), browser);
    // hookup to changes in progress
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "progress",
                       GTK_SIGNAL_FUNC(progress_change_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "progress_all",
                       GTK_SIGNAL_FUNC(progress_change_all_cb), browser);
    // hookup to changes in over-link message
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "link_message",
                       GTK_SIGNAL_FUNC(link_message_cb), browser);
    // hookup to changes in js status message
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "js_status",
                       GTK_SIGNAL_FUNC(js_status_cb), browser);
    // hookup to see whenever a new window is requested
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "new_window",
                       GTK_SIGNAL_FUNC(new_window_cb), browser);
    // hookup to any requested visibility changes
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "visibility",
                       GTK_SIGNAL_FUNC(visibility_cb), browser);
    // hookup to the signal that says that the browser requested to be
    // destroyed
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "destroy_browser",
                       GTK_SIGNAL_FUNC(destroy_brsr_cb), browser);
    // hookup to the signal that is called when someone clicks on a link
    // to load a new uri
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "open_uri",
                       GTK_SIGNAL_FUNC(open_uri_cb), browser);
    // this signal is emitted when there's a request to change the
    // containing browser window to a certain height, like with width
    // and height args for a window.open in javascript
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "size_to",
                       GTK_SIGNAL_FUNC(size_to_cb), browser);
    // key event signals
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_key_down",
                       GTK_SIGNAL_FUNC(dom_key_down_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_key_press",
                       GTK_SIGNAL_FUNC(dom_key_press_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_key_up",
                       GTK_SIGNAL_FUNC(dom_key_up_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_down",
                       GTK_SIGNAL_FUNC(dom_mouse_down_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_up",
                       GTK_SIGNAL_FUNC(dom_mouse_up_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_click",
                       GTK_SIGNAL_FUNC(dom_mouse_click_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_dbl_click",
                       GTK_SIGNAL_FUNC(dom_mouse_dbl_click_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_over",
                       GTK_SIGNAL_FUNC(dom_mouse_over_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_mouse_out",
                       GTK_SIGNAL_FUNC(dom_mouse_out_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_activate",
                       GTK_SIGNAL_FUNC(dom_activate_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_focus_in",
                       GTK_SIGNAL_FUNC(dom_focus_in_cb), browser);
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "dom_focus_out",
                       GTK_SIGNAL_FUNC(dom_focus_out_cb), browser);
    // hookup to when the window is destroyed
    gtk_signal_connect(GTK_OBJECT(browser->mozEmbed), "destroy",
                       GTK_SIGNAL_FUNC(destroy_cb), browser);

    // set the chrome type so it's stored in the object
    gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(browser->mozEmbed),
                                  actualChromeMask);

    return browser;
}
Пример #7
0
GtkBrowser *
new_gtk_browser(guint32 chromeMask)
{
    guint32 actualChromeMask = chromeMask;
    GtkBrowser *browser = 0;

    browser = g_new0(GtkBrowser, 1);

    browser->menuBarOn = FALSE;
    browser->toolBarOn = FALSE;
    browser->locationBarOn = FALSE;
    browser->statusBarOn = FALSE;

    g_print("new_gtk_browser\n");

    if (chromeMask == GTK_MOZ_EMBED_FLAG_DEFAULTCHROME)
        actualChromeMask = GTK_MOZ_EMBED_FLAG_ALLCHROME;

    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_MENUBARON)
    {
        browser->menuBarOn = TRUE;
        g_print("\tmenu bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_TOOLBARON)
    {
        browser->toolBarOn = TRUE;
        g_print("\ttool bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_LOCATIONBARON)
    {
        browser->locationBarOn = TRUE;
        g_print("\tlocation bar\n");
    }
    if (actualChromeMask & GTK_MOZ_EMBED_FLAG_STATUSBARON)
    {
        browser->statusBarOn = TRUE;
        g_print("\tstatus bar\n");
    }

    // create our new toplevel window
    browser->topLevelWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    // new vbox
    browser->topLevelVBox = gtk_vbox_new(FALSE, 0);
    // add it to the toplevel window
    gtk_container_add(GTK_CONTAINER(browser->topLevelWindow),
        browser->topLevelVBox);
    // create our menu bar
    browser->menuBar = gtk_menu_bar_new();
    // create the file menu
    browser->fileMenuItem = gtk_menu_item_new_with_label("File");
    browser->fileMenu = gtk_menu_new();
    gtk_menu_item_set_submenu (GTK_MENU_ITEM(browser->fileMenuItem),
        browser->fileMenu);

    browser->fileClose =
        gtk_menu_item_new_with_label("Close");
    gtk_menu_append(GTK_MENU(browser->fileMenu),
        browser->fileClose);

    // append it
    gtk_menu_bar_append(GTK_MENU_BAR(browser->menuBar), browser->fileMenuItem);

    // add it to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),
        browser->menuBar,
        FALSE, // expand
        FALSE, // fill
        0);    // padding
    // create the hbox that will contain the toolbar and the url text entry bar
    browser->toolbarHBox = gtk_hbox_new(FALSE, 0);
    // add that hbox to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox),
        browser->toolbarHBox,
        FALSE, // expand
        FALSE, // fill
        0);    // padding

    // new horiz toolbar with buttons + icons
#ifdef MOZ_WIDGET_GTK
    browser->toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
        GTK_TOOLBAR_BOTH);
#endif /* MOZ_WIDGET_GTK */

#ifdef MOZ_WIDGET_GTK2
    browser->toolbar = gtk_toolbar_new();
    gtk_toolbar_set_orientation(GTK_TOOLBAR(browser->toolbar),
        GTK_ORIENTATION_HORIZONTAL);
    gtk_toolbar_set_style(GTK_TOOLBAR(browser->toolbar),
        GTK_TOOLBAR_BOTH);
#endif /* MOZ_WIDGET_GTK2 */

    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->toolbar,
        FALSE, // expand
        FALSE, // fill
        0);    // padding
    // new back button
    browser->backButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
        "Back",
        "Go Back",
        "Go Back",
        0, // XXX replace with icon
        GTK_SIGNAL_FUNC(back_clicked_cb),
        browser);
    // new stop button
    browser->stopButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
        "Stop",
        "Stop",
        "Stop",
        0, // XXX replace with icon
        GTK_SIGNAL_FUNC(stop_clicked_cb),
        browser);
    // new forward button
    browser->forwardButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
        "Forward",
        "Forward",
        "Forward",
        0, // XXX replace with icon
        GTK_SIGNAL_FUNC(forward_clicked_cb),
        browser);
    // new reload button
    browser->reloadButton =
        gtk_toolbar_append_item(GTK_TOOLBAR(browser->toolbar),
        "Reload",
        "Reload",
        "Reload",
        0, // XXX replace with icon
        GTK_SIGNAL_FUNC(reload_clicked_cb),
        browser);
    // create the url text entry
    browser->urlEntry = gtk_entry_new();
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->toolbarHBox), browser->urlEntry,
        TRUE, // expand
        TRUE, // fill
        0);    // padding

    // create our new gtk moz embed widget
    browser->mozEmbed = gtk_moz_embed_new();
    // add it to the toplevel vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->mozEmbed,
        TRUE, // expand
        TRUE, // fill
        0);   // padding

    // create the new hbox for the progress area
    browser->progressAreaHBox = gtk_hbox_new(FALSE, 0);
    // add it to the vbox
    gtk_box_pack_start(GTK_BOX(browser->topLevelVBox), browser->progressAreaHBox,
        FALSE, // expand
        FALSE, // fill
        0);   // padding
    // create our new progress bar
    browser->progressBar = gtk_progress_bar_new();
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->progressBar,
        FALSE, // expand
        FALSE, // fill
        0); // padding

    // create our status area and the alignment object that will keep it
    // from expanding
    browser->statusAlign = gtk_alignment_new(0, 0, 1, 1);
    gtk_widget_set_usize(browser->statusAlign, 1, -1);
    // create the status bar
    browser->statusBar = gtk_statusbar_new();
    gtk_container_add(GTK_CONTAINER(browser->statusAlign), browser->statusBar);
    // add it to the hbox
    gtk_box_pack_start(GTK_BOX(browser->progressAreaHBox), browser->statusAlign,
        TRUE, // expand
        TRUE, // fill
        0);   // padding
    // by default none of the buttons are marked as sensitive.
    gtk_widget_set_sensitive(browser->backButton, FALSE);
    gtk_widget_set_sensitive(browser->stopButton, FALSE);
    gtk_widget_set_sensitive(browser->forwardButton, FALSE);
    gtk_widget_set_sensitive(browser->reloadButton, FALSE);

    // catch the destruction of the toplevel window
    gtk_signal_connect(GTK_OBJECT(browser->topLevelWindow), "delete_event",
        GTK_SIGNAL_FUNC(delete_cb), browser);

    // hook up the activate signal to the right callback
    gtk_signal_connect(GTK_OBJECT(browser->urlEntry), "activate",
        GTK_SIGNAL_FUNC(url_activate_cb), browser);

    // close this window
    gtk_signal_connect(GTK_OBJECT(browser->fileClose), "activate",
        GTK_SIGNAL_FUNC(menu_close_cb), browser);

    install_mozembed_cb(browser);

    // set the chrome type so it's stored in the object
    gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(browser->mozEmbed),
        actualChromeMask);

    return browser;
}
Пример #8
0
void 
HandleSocketMessage(gpointer data, gpointer user_data)
{
    int instance, type;
    char mMsgBuf[1024];
    char *msg = (char *)data;

    int i = sscanf(msg, "%d,%d,%s", &instance, &type, mMsgBuf);

    NS_ASSERTION(i >= 2, "Wrong message format\n");

    // In case that the last message string argument contains spaces, sscanf 
    // returns before the first space. Below line returns the complete message
    // string.
    char* mMsgString = (char*)strchr(msg, ',');
    mMsgString++;
    mMsgString = (char*)strchr(mMsgString, ',');
    mMsgString++;

    GtkBrowser *pBrowser;
    switch (type) {
    case JEVENT_INIT:
        break;
    case JEVENT_CREATEWINDOW:
        {
            // only create new browser window when the instance does not exist
            if (instance < gBrowserArray.GetSize() && gBrowserArray[instance] != NULL)
                break;
            if (i != 3)
                break;
            int javaXId = atoi(mMsgString);
            NS_ASSERTION(javaXId, "Invalid X window handle\n");
            pBrowser = g_new0(GtkBrowser, 1);
            pBrowser->topLevelWindow = gtk_plug_new(javaXId);
            pBrowser->mozEmbed = gtk_moz_embed_new();
            if (pBrowser->mozEmbed) {
                gtk_container_add(GTK_CONTAINER(pBrowser->topLevelWindow), pBrowser->mozEmbed);
                install_mozembed_cb(pBrowser);
                gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(pBrowser->mozEmbed),
                    GTK_MOZ_EMBED_FLAG_DEFAULTCHROME);
                gtk_widget_realize(pBrowser->topLevelWindow);
                gtk_widget_show_all(pBrowser->topLevelWindow);
                pBrowser->id = instance;
                gBrowserArray.SetAtGrow(instance, pBrowser);
                SendSocketMessage(instance, CEVENT_INIT_WINDOW_SUCC);
            }

            gtk_signal_connect(GTK_OBJECT(pBrowser->topLevelWindow), 
                  "set-focus", GTK_SIGNAL_FUNC(set_focus_cb), pBrowser);

        }
        break;
    case JEVENT_DESTROYWINDOW:
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        if(pBrowser != NULL){
            gtk_widget_destroy(pBrowser->mozEmbed);
            gtk_object_destroy((GtkObject *)pBrowser->topLevelWindow);
            gBrowserArray.SetAt(instance, NULL);
        }
        SendSocketMessage(instance, CEVENT_DISTORYWINDOW_SUCC);
        break;
    case JEVENT_SHUTDOWN:
        gtk_main_quit();
        break;
    case JEVENT_SET_BOUNDS:
        {
            NS_ASSERTION(i == 3, "Wrong message format\n");
            int x, y, w, h;
            i = sscanf(mMsgString, "%d,%d,%d,%d", &x, &y, &w, &h);
            if (i == 4) {
                pBrowser = (GtkBrowser *)gBrowserArray[instance];
                NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
                gtk_widget_set_usize(pBrowser->topLevelWindow, w, h);
            }
        }
        break;
    case JEVENT_NAVIGATE:
        NS_ASSERTION(i == 3, "Wrong message format\n");
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
        gtk_moz_embed_load_url(GTK_MOZ_EMBED(pBrowser->mozEmbed), mMsgString);
        break;
    case JEVENT_NAVIGATE_POST:
        NS_ASSERTION(i == 3, "Wrong message format\n");
        strncpy(gCachedURL, mMsgString, sizeof(gCachedURL));
        break;
    case JEVENT_NAVIGATE_POSTDATA:
        NS_ASSERTION(i == 3, "Wrong message format\n");
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        OpenURL(pBrowser, gCachedURL, mMsgString, POST_HEADER);
        break;
    case JEVENT_GOBACK:
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
        gtk_moz_embed_go_back(GTK_MOZ_EMBED(pBrowser->mozEmbed));
        break;
    case JEVENT_GOFORWARD:
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
        gtk_moz_embed_go_forward(GTK_MOZ_EMBED(pBrowser->mozEmbed));
        break;
    case JEVENT_REFRESH:
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
        gtk_moz_embed_reload(GTK_MOZ_EMBED(pBrowser->mozEmbed), GTK_MOZ_EMBED_FLAG_RELOADNORMAL);
        break;
    case JEVENT_STOP:
        pBrowser = (GtkBrowser *)gBrowserArray[instance];
        NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
        gtk_moz_embed_stop_load(GTK_MOZ_EMBED(pBrowser->mozEmbed));
        break;
    case JEVENT_GETURL:
        {
            pBrowser = (GtkBrowser *)gBrowserArray[instance];
            NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
            nsCOMPtr<nsIWebBrowser> webBrowser;
            gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(pBrowser->mozEmbed), getter_AddRefs(webBrowser));
            nsCOMPtr<nsIWebNavigation> webNavigation(do_QueryInterface(webBrowser));
            nsCOMPtr<nsIURI> currentURI;
            webNavigation->GetCurrentURI(getter_AddRefs(currentURI));
            if (currentURI == NULL)
                SendSocketMessage(instance, CEVENT_RETURN_URL, "");
            else { 
            	nsEmbedCString uriString;
                currentURI->GetAsciiSpec(uriString);
                SendSocketMessage(instance, CEVENT_RETURN_URL, uriString.get());
            }
        }
        break;

    case JEVENT_FOCUSGAINED:
    case JEVENT_FOCUSLOST:
        {
            pBrowser = (GtkBrowser *)gBrowserArray[instance];
            NS_ASSERTION(pBrowser, "Can't get native browser instance\n");

            if (!pBrowser->topLevelWindow) {
                ReportError("Top level Window is Null!\n");
                break;
            }

            GtkWidget *widget = GTK_WIDGET (pBrowser->topLevelWindow);
            GdkEvent event;

            GtkWindowClass *parent_class = (GtkWindowClass*) gtk_type_class (GTK_TYPE_WINDOW);

            if (!widget) {
                ReportError("Failed to get browser's toplevel window !\n");
                break;
            }
            if (!parent_class) {
                ReportError("Failed to get gtk window class !\n");
                break;
            }

            event.focus_change.type = GDK_FOCUS_CHANGE;
            event.focus_change.window = widget->window;
            event.focus_change.send_event = TRUE;

            if (type == JEVENT_FOCUSGAINED) {
                event.focus_change.in = TRUE;
                GTK_WIDGET_CLASS (parent_class)->focus_in_event
                            (widget, (GdkEventFocus *)&event);
            }
            else {
                event.focus_change.in = FALSE;
                GTK_WIDGET_CLASS (parent_class)->focus_out_event
                            (widget, (GdkEventFocus *)&event);
            }
        }
        break;
    case JEVENT_GETCONTENT:
        {
            pBrowser = (GtkBrowser *)gBrowserArray[instance];
            NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
            nsCOMPtr<nsIWebBrowser> webBrowser;
            gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(pBrowser->mozEmbed), 
                    getter_AddRefs(webBrowser));
            nsCOMPtr<nsIWebNavigation> 
                webNavigation(do_QueryInterface(webBrowser));
                                                                                                            
            char *retStr = GetContent(webNavigation);
            if (retStr == NULL)
                SendSocketMessage(instance, CEVENT_GETCONTENT, "");
            else
                SendSocketMessage(instance, CEVENT_GETCONTENT, retStr);
        } 
        break;
    case JEVENT_SETCONTENT:
        {
            NS_ASSERTION(i == 3, "Wrong message format\n");
            pBrowser = (GtkBrowser *)gBrowserArray[instance];
            NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
            nsCOMPtr<nsIWebBrowser> webBrowser;
            gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(pBrowser->mozEmbed), 
                    getter_AddRefs(webBrowser));
            nsCOMPtr<nsIWebNavigation> 
                webNavigation(do_QueryInterface(webBrowser));
            
            SetContent(webNavigation, mMsgString);
        }
        break;
    case JEVENT_EXECUTESCRIPT:
        {
            NS_ASSERTION(i == 3, "Wrong message format\n");
            pBrowser = (GtkBrowser *)gBrowserArray[instance];
            NS_ASSERTION(pBrowser, "Can't get native browser instance\n");
            nsCOMPtr<nsIWebBrowser> webBrowser;
            gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(pBrowser->mozEmbed), 
                    getter_AddRefs(webBrowser));
            nsCOMPtr<nsIWebNavigation> 
                webNavigation(do_QueryInterface(webBrowser));
                                                                                                            
            char *retStr = ExecuteScript(webNavigation, mMsgString);
            if (retStr == NULL)
                SendSocketMessage(instance, CEVENT_EXECUTESCRIPT, "");
            else
                SendSocketMessage(instance, CEVENT_EXECUTESCRIPT, retStr);
        } 
        break;
    }
}