// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. #include #include #include #include #include "cefclient.h" #include "include/cef_app.h" #include "include/cef_browser.h" #include "include/cef_frame.h" #include "include/cef_runnable.h" #include "client_handler.h" char szWorkingDir[512]; // The current working directory // The global ClientHandler reference. extern CefRefPtr g_handler; void destroy(void) { CefQuitMessageLoop(); } void TerminationSignalHandler(int signatl) { destroy(); } // Callback for when you press enter in the URL box. void URLEntryActivate(GtkEntry* entry) { if (!g_handler.get() || !g_handler->GetBrowserHwnd()) return; const gchar* url = gtk_entry_get_text(entry); g_handler->GetBrowser()->GetMainFrame()->LoadURL(std::string(url).c_str()); } // WebViewDelegate::TakeFocus in the test webview delegate. static gboolean HandleFocus(GtkWidget* widget, GdkEventFocus* focus) { if (g_handler.get() && g_handler->GetBrowserHwnd()) { // Give focus to the browser window. g_handler->GetBrowser()->SetFocus(true); } return TRUE; } int main(int argc, char *argv[]) { if (!getcwd(szWorkingDir, sizeof (szWorkingDir))) return -1; GtkWidget* window; gtk_init(&argc, &argv); CefSettings settings; CefRefPtr app; // Initialize CEF. CefInitialize(settings, app); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Atom"); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); g_signal_connect(window, "focus", G_CALLBACK(&HandleFocus), NULL); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), NULL, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_widget_destroyed), &window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); // Create the handler. g_handler = new ClientHandler(); g_handler->SetMainHwnd(vbox); // Create the browser view. CefWindowInfo window_info; CefBrowserSettings browserSettings; window_info.SetAsChild(vbox); std::string path; path.append("file://"); path.append(szWorkingDir); path.append("/../index.html"); CefBrowser::CreateBrowserSync(window_info, static_cast >(g_handler), path, browserSettings); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show_all(GTK_WIDGET(window)); GdkPixbuf *pixbuf; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_file("atom.ico", &error); if (pixbuf) gtk_window_set_icon(GTK_WINDOW(window), pixbuf); // Install an signal handler so we clean up after ourselves. signal(SIGINT, TerminationSignalHandler); signal(SIGTERM, TerminationSignalHandler); CefRunMessageLoop(); CefShutdown(); return 0; } // Global functions std::string AppGetWorkingDirectory() { return szWorkingDir; }