"Fossies" - the Fresh Open Source Software Archive

Member "xombrero-1.6.4/inspector.c" (17 Feb 2015, 4567 Bytes) of package /linux/www/old/xombrero-1.6.4.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "inspector.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
    3  * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
    4  *
    5  * Permission to use, copy, modify, and distribute this software for any
    6  * purpose with or without fee is hereby granted, provided that the above
    7  * copyright notice and this permission notice appear in all copies.
    8  *
    9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   16  */
   17 
   18 #include <xombrero.h>
   19 
   20 gboolean
   21 inspector_attach_window(WebKitWebInspector *inspector, struct tab *t)
   22 {
   23     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   24 
   25     return (FALSE); /* NOT handled */
   26 }
   27 
   28 gboolean
   29 inspector_close_window(WebKitWebInspector *inspector, struct tab *t)
   30 {
   31     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   32 
   33     if (t->inspector_window) {
   34         gtk_widget_hide(t->inspector_window);
   35         return (TRUE); /* handled */
   36     }
   37 
   38     return (FALSE); /* NOT handled */
   39 }
   40 
   41 gboolean
   42 inspector_detach_window(WebKitWebInspector *inspector, struct tab *t)
   43 {
   44     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   45 
   46     return (FALSE); /* NOT handled */
   47 }
   48 
   49 gboolean
   50 inspector_delete(GtkWidget *inspector_window, GdkEvent *e, struct tab *t)
   51 {
   52     inspector_close_window(t->inspector, t);
   53 
   54     return (TRUE); /* handled */
   55 }
   56 
   57 WebKitWebView*
   58 inspector_inspect_web_view_cb(WebKitWebInspector *inspector, WebKitWebView* wv,
   59     struct tab *t)
   60 {
   61     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   62 
   63     if (t->inspector_window)
   64         goto done;
   65 
   66     t->inspector_window = create_window("inspector");
   67     t->inspector_view = webkit_web_view_new();
   68     gtk_container_add(GTK_CONTAINER(t->inspector_window), t->inspector_view);
   69 
   70     g_signal_connect(t->inspector_window,
   71         "delete-event", G_CALLBACK(inspector_delete), t);
   72 done:
   73     return WEBKIT_WEB_VIEW(t->inspector_view);
   74 }
   75 
   76 gboolean
   77 inspector_show_window(WebKitWebInspector *inspector, struct tab *t)
   78 {
   79     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   80 
   81     if (t->inspector_window) {
   82         g_signal_emit_by_name(inspector, "attach-window", t, NULL);
   83         gtk_widget_show_all(t->inspector_window);
   84         gtk_window_present(GTK_WINDOW(t->inspector_window));
   85         return (TRUE); /* handled */
   86     }
   87 
   88     return (FALSE); /* NOT handled */
   89 }
   90 
   91 void
   92 inspector_finished(WebKitWebInspector *inspector, struct tab *t)
   93 {
   94     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
   95 
   96     if (t->inspector_window) {
   97         g_signal_handlers_disconnect_by_func(
   98             t->inspector, inspector_attach_window, t);
   99         g_signal_handlers_disconnect_by_func(
  100             t->inspector, inspector_close_window, t);
  101         g_signal_handlers_disconnect_by_func(
  102             t->inspector, inspector_detach_window, t);
  103         g_signal_handlers_disconnect_by_func(
  104             t->inspector, inspector_finished, t);
  105         g_signal_handlers_disconnect_by_func(
  106             t->inspector, inspector_inspect_web_view_cb, t);
  107         g_signal_handlers_disconnect_by_func(
  108             t->inspector, inspector_show_window, t);
  109 
  110         gtk_widget_hide(t->inspector_window);
  111 
  112         /* XXX it seems that the window is disposed automatically */
  113         t->inspector_window = NULL;
  114         t->inspector_view = NULL;
  115     }
  116 }
  117 
  118 void
  119 setup_inspector(struct tab *t)
  120 {
  121 
  122     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
  123 
  124     t->inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(t->wv));
  125     g_object_connect(G_OBJECT(t->inspector),
  126         "signal::attach-window", G_CALLBACK(inspector_attach_window), t,
  127         "signal::close-window", G_CALLBACK(inspector_close_window), t,
  128         "signal::detach-window", G_CALLBACK(inspector_detach_window), t,
  129         "signal::finished", G_CALLBACK(inspector_finished), t,
  130         "signal::inspect-web-view", G_CALLBACK(inspector_inspect_web_view_cb), t,
  131         "signal::show-window", G_CALLBACK(inspector_show_window), t,
  132         (char *)NULL);
  133 
  134 }
  135 
  136 int
  137 inspector_cmd(struct tab *t, struct karg *args)
  138 {
  139     DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);
  140 
  141     if (t == NULL)
  142         return (1);
  143 
  144     if (args->i & XT_INS_SHOW)
  145         webkit_web_inspector_show(t->inspector);
  146     else if (args->i & XT_INS_HIDE)
  147         webkit_web_inspector_close(t->inspector);
  148     else if (args->i & XT_INS_CLOSE)
  149         inspector_finished(t->inspector, t);
  150 
  151     return (XT_CB_PASSTHROUGH);
  152 }