/tags/Galeking/WebKitTools/DumpRenderTree/bal/gtk/DumpRenderTreeGtk.cpp

https://github.com/weissms/owb-mirror · C++ · 93 lines · 73 code · 18 blank · 2 comment · 1 complexity · c0eafd9e4224e14727a043848327e2b1 MD5 · raw file

  1. #include <gtk/gtk.h>
  2. #include "cairo.h"
  3. #include <WebKit.h>
  4. #include <DumpRenderTree.h>
  5. // Choose some default values.
  6. const unsigned int maxViewWidth = 800;
  7. const unsigned int maxViewHeight = 600;
  8. unsigned int waitToDumpWatchdog = 0;
  9. static GtkWidget* main_window;
  10. static void destroy_cb (GtkWidget* widget, gpointer data)
  11. {
  12. gtk_main_quit ();
  13. }
  14. BalRectangle clientRect(bool isSVGW3CTest)
  15. {
  16. GdkRectangle clientRect = {0, 0, isSVGW3CTest ? 480 : maxViewWidth, isSVGW3CTest ? 360 : maxViewHeight};
  17. return clientRect;
  18. }
  19. static GtkWidget* create_window (BalRectangle rect)
  20. {
  21. GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  22. gtk_window_set_default_size (GTK_WINDOW (window), rect.width, rect.height);
  23. gtk_widget_set_name (window, "GtkLauncher");
  24. g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy_cb), NULL);
  25. return window;
  26. }
  27. void init(int argc, char *argv[])
  28. {
  29. gtk_init (&argc, &argv);
  30. }
  31. BalWidget* createWindow(WebView *webView, BalRectangle rect)
  32. {
  33. main_window = create_window(rect);
  34. GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  35. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  36. BalWidget *view = webView->viewWindow();
  37. gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (view));
  38. gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);
  39. gtk_widget_realize(main_window);
  40. return view;
  41. }
  42. void startEventLoop(BalWidget *view)
  43. {
  44. done = false;
  45. gtk_widget_grab_focus (view);
  46. gtk_widget_realize(view);
  47. //gtk_widget_show_all (main_window);
  48. while (!done)
  49. g_main_context_iteration(NULL, true);
  50. }
  51. void stopEventLoop()
  52. {
  53. done = true;
  54. }
  55. static gboolean waitToDumpWatchdogFired(void*)
  56. {
  57. const char* message = "FAIL: Timed out waiting for notifyDone to be called\n";
  58. fprintf(stderr, "%s", message);
  59. fprintf(stdout, "%s", message);
  60. waitToDumpWatchdog = 0;
  61. dump();
  62. return FALSE;
  63. }
  64. void addTimetoDump(int timeoutSeconds)
  65. {
  66. #if GLIB_CHECK_VERSION(2,14,0)
  67. waitToDumpWatchdog = g_timeout_add_seconds(timeoutSeconds, waitToDumpWatchdogFired, 0);
  68. #else
  69. waitToDumpWatchdog = g_timeout_add(timeoutSeconds * 1000, waitToDumpWatchdogFired, 0);
  70. #endif
  71. }
  72. void removeTimer()
  73. {
  74. g_source_remove(waitToDumpWatchdog);
  75. }