1 module webkit2.WebInspector;
2 
3 private import glib.Str;
4 private import gobject.ObjectG;
5 private import gobject.Signals;
6 private import std.algorithm;
7 private import webkit2.WebViewBase;
8 private import webkit2.c.functions;
9 public  import webkit2.c.types;
10 
11 
12 /**
13  * The WebKit Inspector is a graphical tool to inspect and change the
14  * content of a #WebKitWebView. It also includes an interactive
15  * JavaScript debugger. Using this class one can get a #GtkWidget
16  * which can be embedded into an application to show the inspector.
17  * 
18  * The inspector is available when the #WebKitSettings of the
19  * #WebKitWebView has set the #WebKitSettings:enable-developer-extras
20  * to true, otherwise no inspector is available.
21  * 
22  * <informalexample><programlisting>
23  * /<!-- -->* Enable the developer extras *<!-- -->/
24  * WebKitSettings *setting = webkit_web_view_get_settings (WEBKIT_WEB_VIEW(my_webview));
25  * g_object_set (G_OBJECT(settings), "enable-developer-extras", TRUE, NULL);
26  * 
27  * /<!-- -->* Load some data or reload to be able to inspect the page*<!-- -->/
28  * webkit_web_view_load_uri (WEBKIT_WEB_VIEW(my_webview), "http://www.gnome.org");
29  * 
30  * /<!-- -->* Show the inspector *<!-- -->/
31  * WebKitWebInspector *inspector = webkit_web_view_get_inspector (WEBKIT_WEB_VIEW(my_webview));
32  * webkit_web_inspector_show (WEBKIT_WEB_INSPECTOR(inspector));
33  * </programlisting></informalexample>
34  */
35 public class WebInspector : ObjectG
36 {
37 	/** the main Gtk struct */
38 	protected WebKitWebInspector* webKitWebInspector;
39 
40 	/** Get the main Gtk struct */
41 	public WebKitWebInspector* getWebInspectorStruct(bool transferOwnership = false)
42 	{
43 		if (transferOwnership)
44 			ownedRef = false;
45 		return webKitWebInspector;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected override void* getStruct()
50 	{
51 		return cast(void*)webKitWebInspector;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (WebKitWebInspector* webKitWebInspector, bool ownedRef = false)
58 	{
59 		this.webKitWebInspector = webKitWebInspector;
60 		super(cast(GObject*)webKitWebInspector, ownedRef);
61 	}
62 
63 
64 	/** */
65 	public static GType getType()
66 	{
67 		return webkit_web_inspector_get_type();
68 	}
69 
70 	/**
71 	 * Request @inspector to be attached. The signal #WebKitWebInspector::attach
72 	 * will be emitted. If the inspector is already attached it does nothing.
73 	 */
74 	public void attach()
75 	{
76 		webkit_web_inspector_attach(webKitWebInspector);
77 	}
78 
79 	/**
80 	 * Request @inspector to be closed.
81 	 */
82 	public void close()
83 	{
84 		webkit_web_inspector_close(webKitWebInspector);
85 	}
86 
87 	/**
88 	 * Request @inspector to be detached. The signal #WebKitWebInspector::detach
89 	 * will be emitted. If the inspector is already detached it does nothing.
90 	 */
91 	public void detach()
92 	{
93 		webkit_web_inspector_detach(webKitWebInspector);
94 	}
95 
96 	/**
97 	 * Get the height that the inspector view should have when
98 	 * it's attached. If the inspector view is not attached this
99 	 * returns 0.
100 	 *
101 	 * Returns: the height of the inspector view when attached
102 	 */
103 	public uint getAttachedHeight()
104 	{
105 		return webkit_web_inspector_get_attached_height(webKitWebInspector);
106 	}
107 
108 	/**
109 	 * Whether the @inspector can be attached to the same window that contains
110 	 * the inspected view.
111 	 *
112 	 * Returns: %TRUE if there is enough room for the inspector view inside the
113 	 *     window that contains the inspected view, or %FALSE otherwise.
114 	 *
115 	 * Since: 2.8
116 	 */
117 	public bool getCanAttach()
118 	{
119 		return webkit_web_inspector_get_can_attach(webKitWebInspector) != 0;
120 	}
121 
122 	/**
123 	 * Get the URI that is currently being inspected. This can be %NULL if
124 	 * nothing has been loaded yet in the inspected view, if the inspector
125 	 * has been closed or when inspected view was loaded from a HTML string
126 	 * instead of a URI.
127 	 *
128 	 * Returns: the URI that is currently being inspected or %NULL
129 	 */
130 	public string getInspectedUri()
131 	{
132 		return Str.toString(webkit_web_inspector_get_inspected_uri(webKitWebInspector));
133 	}
134 
135 	/**
136 	 * Get the #WebKitWebViewBase used to display the inspector.
137 	 * This might be %NULL if the inspector hasn't been loaded yet,
138 	 * or it has been closed.
139 	 *
140 	 * Returns: the #WebKitWebViewBase used to display the inspector or %NULL
141 	 */
142 	public WebViewBase getWebView()
143 	{
144 		auto __p = webkit_web_inspector_get_web_view(webKitWebInspector);
145 
146 		if(__p is null)
147 		{
148 			return null;
149 		}
150 
151 		return ObjectG.getDObject!(WebViewBase)(cast(WebKitWebViewBase*) __p);
152 	}
153 
154 	/**
155 	 * Whether the @inspector view is currently attached to the same window that contains
156 	 * the inspected view.
157 	 *
158 	 * Returns: %TRUE if @inspector is currently attached or %FALSE otherwise
159 	 */
160 	public bool isAttached()
161 	{
162 		return webkit_web_inspector_is_attached(webKitWebInspector) != 0;
163 	}
164 
165 	/**
166 	 * Request @inspector to be shown.
167 	 */
168 	public void show()
169 	{
170 		webkit_web_inspector_show(webKitWebInspector);
171 	}
172 
173 	/**
174 	 * Emitted when the inspector is requested to be attached to the window
175 	 * where the inspected web view is.
176 	 * If this signal is not handled the inspector view will be automatically
177 	 * attached to the inspected view, so you only need to handle this signal
178 	 * if you want to attach the inspector view yourself (for example, to add
179 	 * the inspector view to a browser tab).
180 	 *
181 	 * To prevent the inspector view from being attached you can connect to this
182 	 * signal and simply return %TRUE.
183 	 *
184 	 * Returns: %TRUE to stop other handlers from being invoked for the event.
185 	 *     %FALSE to propagate the event further.
186 	 */
187 	gulong addOnAttach(bool delegate(WebInspector) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188 	{
189 		return Signals.connect(this, "attach", dlg, connectFlags ^ ConnectFlags.SWAPPED);
190 	}
191 
192 	/**
193 	 * Emitted when the inspector should be shown.
194 	 *
195 	 * If the inspector is not attached the inspector window should be shown
196 	 * on top of any other windows.
197 	 * If the inspector is attached the inspector view should be made visible.
198 	 * For example, if the inspector view is attached using a tab in a browser
199 	 * window, the browser window should be raised and the tab containing the
200 	 * inspector view should be the active one.
201 	 * In both cases, if this signal is not handled, the default implementation
202 	 * calls gtk_window_present() on the current toplevel #GtkWindow of the
203 	 * inspector view.
204 	 *
205 	 * Returns: %TRUE to stop other handlers from being invoked for the event.
206 	 *     %FALSE to propagate the event further.
207 	 */
208 	gulong addOnBringToFront(bool delegate(WebInspector) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
209 	{
210 		return Signals.connect(this, "bring-to-front", dlg, connectFlags ^ ConnectFlags.SWAPPED);
211 	}
212 
213 	/**
214 	 * Emitted when the inspector page is closed. If you are using your own
215 	 * inspector window, you should connect to this signal and destroy your
216 	 * window.
217 	 */
218 	gulong addOnClosed(void delegate(WebInspector) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
219 	{
220 		return Signals.connect(this, "closed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
221 	}
222 
223 	/**
224 	 * Emitted when the inspector is requested to be detached from the window
225 	 * it is currently attached to. The inspector is detached when the inspector page
226 	 * is about to be closed, and this signal is emitted right before
227 	 * #WebKitWebInspector::closed, or when the user clicks on the detach button
228 	 * in the inspector view to show the inspector in a separate window. In this case
229 	 * the signal #WebKitWebInspector::open-window is emitted after this one.
230 	 *
231 	 * To prevent the inspector view from being detached you can connect to this
232 	 * signal and simply return %TRUE.
233 	 *
234 	 * Returns: %TRUE to stop other handlers from being invoked for the event.
235 	 *     %FALSE to propagate the event further.
236 	 */
237 	gulong addOnDetach(bool delegate(WebInspector) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
238 	{
239 		return Signals.connect(this, "detach", dlg, connectFlags ^ ConnectFlags.SWAPPED);
240 	}
241 
242 	/**
243 	 * Emitted when the inspector is requested to open in a separate window.
244 	 * If this signal is not handled, a #GtkWindow with the inspector will be
245 	 * created and shown, so you only need to handle this signal if you want
246 	 * to use your own window.
247 	 * This signal is emitted after #WebKitWebInspector::detach to show
248 	 * the inspector in a separate window after being detached.
249 	 *
250 	 * To prevent the inspector from being shown you can connect to this
251 	 * signal and simply return %TRUE
252 	 *
253 	 * Returns: %TRUE to stop other handlers from being invoked for the event.
254 	 *     %FALSE to propagate the event further.
255 	 */
256 	gulong addOnOpenWindow(bool delegate(WebInspector) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
257 	{
258 		return Signals.connect(this, "open-window", dlg, connectFlags ^ ConnectFlags.SWAPPED);
259 	}
260 }