2009-03-12 Gustavo Noronha Silva <gns@gnome.org>
[WebKit-https.git] / WebKit / gtk / webkit / webkitwebview.cpp
1 /*
2  *  Copyright (C) 2007, 2008 Holger Hans Peter Freyther
3  *  Copyright (C) 2007, 2008, 2009 Christian Dywan <christian@imendio.com>
4  *  Copyright (C) 2007 Xan Lopez <xan@gnome.org>
5  *  Copyright (C) 2007, 2008 Alp Toker <alp@atoker.com>
6  *  Copyright (C) 2008 Jan Alonzo <jmalonzo@unpluggable.com>
7  *  Copyright (C) 2008 Gustavo Noronha Silva <gns@gnome.org>
8  *  Copyright (C) 2008 Nuanti Ltd.
9  *  Copyright (C) 2008 Collabora Ltd.
10  *  Copyright (C) 2009 Igalia S.L.
11  *
12  *  This library is free software; you can redistribute it and/or
13  *  modify it under the terms of the GNU Lesser General Public
14  *  License as published by the Free Software Foundation; either
15  *  version 2 of the License, or (at your option) any later version.
16  *
17  *  This library is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  *  Lesser General Public License for more details.
21  *
22  *  You should have received a copy of the GNU Lesser General Public
23  *  License along with this library; if not, write to the Free Software
24  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25  */
26
27 #include "config.h"
28
29 #include "webkitdownload.h"
30 #include "webkitwebview.h"
31 #include "webkitenumtypes.h"
32 #include "webkitmarshal.h"
33 #include "webkitprivate.h"
34 #include "webkitwebinspector.h"
35 #include "webkitwebbackforwardlist.h"
36 #include "webkitwebhistoryitem.h"
37
38 #include "AXObjectCache.h"
39 #include "NotImplemented.h"
40 #include "BackForwardList.h"
41 #include "CString.h"
42 #include "ChromeClientGtk.h"
43 #include "ContextMenu.h"
44 #include "ContextMenuClientGtk.h"
45 #include "ContextMenuController.h"
46 #include "Cursor.h"
47 #include "Document.h"
48 #include "DocumentLoader.h"
49 #include "DragClientGtk.h"
50 #include "Editor.h"
51 #include "EditorClientGtk.h"
52 #include "EventHandler.h"
53 #include "FloatQuad.h"
54 #include "FocusController.h"
55 #include "FrameLoaderTypes.h"
56 #include "HitTestRequest.h"
57 #include "HitTestResult.h"
58 #include "GraphicsContext.h"
59 #include "InspectorClientGtk.h"
60 #include "FrameLoader.h"
61 #include "FrameView.h"
62 #include "PasteboardHelper.h"
63 #include "PlatformKeyboardEvent.h"
64 #include "PlatformWheelEvent.h"
65 #include "ResourceHandle.h"
66 #include "ScriptValue.h"
67 #include "Scrollbar.h"
68 #include <wtf/GOwnPtr.h>
69
70 #include <gdk/gdkkeysyms.h>
71
72 /**
73  * SECTION:webkitwebview
74  * @short_description: The central class of the WebKit/Gtk+ API
75  * @see_also: #WebKitWebSettings, #WebKitWebFrame
76  *
77  * #WebKitWebView is the central class of the WebKit/Gtk+ API. It is a
78  * #GtkWidget implementing the scrolling interface which means you can
79  * embed in a #GtkScrolledWindow. It is responsible for managing the
80  * drawing of the content, forwarding of events. You can load any URI
81  * into the #WebKitWebView or any kind of data string. With #WebKitWebSettings
82  * you can control various aspects of the rendering and loading of the content.
83  * Each #WebKitWebView has exactly one #WebKitWebFrame as main frame. A
84  * #WebKitWebFrame can have n children.
85  *
86  * <programlisting>
87  * /<!-- -->* Create the widgets *<!-- -->/
88  * GtkWidget *main_window = gtk_window_new (GTK_WIDGET_TOPLEVEL);
89  * GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
90  * GtkWidget *web_view = webkit_web_view_new ();
91  *
92  * /<!-- -->* Place the WebKitWebView in the GtkScrolledWindow *<!-- -->/
93  * gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
94  * gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);
95  *
96  * /<!-- -->* Open a webpage *<!-- -->/
97  * webkit_web_view_open (WEBKIT_WEB_VIEW (web_view), "http://www.gnome.org");
98  *
99  * /<!-- -->* Show the result *<!-- -->/
100  * gtk_window_set_default_size (GTK_WINDOW (main_window), 800, 600);
101  * gtk_widget_show_all (main_window);
102  * </programlisting>
103  */
104
105 static const double defaultDPI = 96.0;
106
107 using namespace WebKit;
108 using namespace WebCore;
109
110 extern "C" {
111
112 enum {
113     /* normal signals */
114     NAVIGATION_REQUESTED,
115     NAVIGATION_POLICY_DECISION_REQUESTED,
116     MIME_TYPE_POLICY_DECISION_REQUESTED,
117     CREATE_WEB_VIEW,
118     WEB_VIEW_READY,
119     WINDOW_OBJECT_CLEARED,
120     LOAD_STARTED,
121     LOAD_COMMITTED,
122     LOAD_PROGRESS_CHANGED,
123     LOAD_FINISHED,
124     TITLE_CHANGED,
125     HOVERING_OVER_LINK,
126     POPULATE_POPUP,
127     STATUS_BAR_TEXT_CHANGED,
128     ICOND_LOADED,
129     SELECTION_CHANGED,
130     CONSOLE_MESSAGE,
131     SCRIPT_ALERT,
132     SCRIPT_CONFIRM,
133     SCRIPT_PROMPT,
134     SELECT_ALL,
135     COPY_CLIPBOARD,
136     PASTE_CLIPBOARD,
137     CUT_CLIPBOARD,
138     DOWNLOAD_REQUESTED,
139     LAST_SIGNAL
140 };
141
142 enum {
143     PROP_0,
144
145     PROP_COPY_TARGET_LIST,
146     PROP_PASTE_TARGET_LIST,
147     PROP_EDITABLE,
148     PROP_SETTINGS,
149     PROP_WEB_INSPECTOR,
150     PROP_WINDOW_FEATURES,
151     PROP_TRANSPARENT,
152     PROP_ZOOM_LEVEL,
153     PROP_FULL_CONTENT_ZOOM,
154     PROP_ENCODING,
155     PROP_CUSTOM_ENCODING
156 };
157
158 static guint webkit_web_view_signals[LAST_SIGNAL] = { 0, };
159
160 G_DEFINE_TYPE(WebKitWebView, webkit_web_view, GTK_TYPE_CONTAINER)
161
162 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView);
163 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures);
164
165 static void webkit_web_view_context_menu_position_func(GtkMenu*, gint* x, gint* y, gboolean* pushIn, WebKitWebViewPrivate* data)
166 {
167     *pushIn = FALSE;
168     *x = data->lastPopupXPosition;
169     *y = data->lastPopupYPosition;
170 }
171
172 static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event)
173 {
174     Page* page = core(webView);
175     page->contextMenuController()->clearContextMenu();
176     Frame* focusedFrame = page->focusController()->focusedOrMainFrame();
177
178     if (!focusedFrame->view())
179         return FALSE;
180
181     focusedFrame->view()->setCursor(pointerCursor());
182     bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event);
183     if (!handledEvent)
184         return FALSE;
185
186     ContextMenu* coreMenu = page->contextMenuController()->contextMenu();
187     if (!coreMenu)
188         return FALSE;
189
190     GtkMenu* menu = GTK_MENU(coreMenu->platformDescription());
191     if (!menu)
192         return FALSE;
193
194     g_signal_emit(webView, webkit_web_view_signals[POPULATE_POPUP], 0, menu);
195
196     GList* items = gtk_container_get_children(GTK_CONTAINER(menu));
197     bool empty = !g_list_nth(items, 0);
198     g_list_free(items);
199     if (empty)
200         return FALSE;
201
202     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
203     priv->lastPopupXPosition = event.globalX();
204     priv->lastPopupYPosition = event.globalY();
205     gtk_menu_popup(menu, NULL, NULL,
206                    reinterpret_cast<GtkMenuPositionFunc>(webkit_web_view_context_menu_position_func),
207                    priv, event.button() + 1, gtk_get_current_event_time());
208     return TRUE;
209 }
210
211 static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget)
212 {
213     static const int contextMenuMargin = 1;
214
215     // The context menu event was generated from the keyboard, so show the context menu by the current selection.
216     Page* page = core(WEBKIT_WEB_VIEW(widget));
217     FrameView* view = page->mainFrame()->view();
218     if (!view)
219         return FALSE;    
220
221     Position start = page->mainFrame()->selection()->selection().start();
222     Position end = page->mainFrame()->selection()->selection().end();
223
224     int rightAligned = FALSE;
225     IntPoint location;
226
227     if (!start.node() || !end.node())
228         location = IntPoint(rightAligned ? view->contentsWidth() - contextMenuMargin : contextMenuMargin, contextMenuMargin);
229     else {
230         RenderObject* renderer = start.node()->renderer();
231         if (!renderer)
232             return FALSE;
233
234         // Calculate the rect of the first line of the selection (cribbed from -[WebCoreFrameBridge firstRectForDOMRange:],
235         // now Frame::firstRectForRange(), which perhaps this should call).
236         int extraWidthToEndOfLine = 0;
237
238         InlineBox* startInlineBox;
239         int startCaretOffset;
240         start.getInlineBoxAndOffset(DOWNSTREAM, startInlineBox, startCaretOffset);
241         IntRect startCaretRect = renderer->localCaretRect(startInlineBox, startCaretOffset, &extraWidthToEndOfLine);
242         if (startCaretRect != IntRect())
243             startCaretRect = renderer->localToAbsoluteQuad(FloatRect(startCaretRect)).enclosingBoundingBox();
244
245         InlineBox* endInlineBox;
246         int endCaretOffset;
247         end.getInlineBoxAndOffset(UPSTREAM, endInlineBox, endCaretOffset);
248         IntRect endCaretRect = renderer->localCaretRect(endInlineBox, endCaretOffset);
249         if (endCaretRect != IntRect())
250             endCaretRect = renderer->localToAbsoluteQuad(FloatRect(endCaretRect)).enclosingBoundingBox();
251
252         IntRect firstRect;
253         if (startCaretRect.y() == endCaretRect.y())
254             firstRect = IntRect(MIN(startCaretRect.x(), endCaretRect.x()),
255                                 startCaretRect.y(),
256                                 abs(endCaretRect.x() - startCaretRect.x()),
257                                 MAX(startCaretRect.height(), endCaretRect.height()));
258         else
259             firstRect = IntRect(startCaretRect.x(),
260                                 startCaretRect.y(),
261                                 startCaretRect.width() + extraWidthToEndOfLine,
262                                 startCaretRect.height());
263
264         location = IntPoint(rightAligned ? firstRect.right() : firstRect.x(), firstRect.bottom());
265     }
266
267     int x, y;
268     gdk_window_get_origin(GTK_WIDGET(view->hostWindow()->platformWindow())->window, &x, &y);
269
270     // FIXME: The IntSize(0, -1) is a hack to get the hit-testing to result in the selected element.
271     // Ideally we'd have the position of a context menu event be separate from its target node.
272     location = view->contentsToWindow(location) + IntSize(0, -1);
273     IntPoint global = location + IntSize(x, y);
274     PlatformMouseEvent event(location, global, NoButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
275
276     return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event);
277 }
278
279 static void webkit_web_view_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
280 {
281     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
282
283     switch(prop_id) {
284 #if GTK_CHECK_VERSION(2,10,0)
285     case PROP_COPY_TARGET_LIST:
286         g_value_set_boxed(value, webkit_web_view_get_copy_target_list(webView));
287         break;
288     case PROP_PASTE_TARGET_LIST:
289         g_value_set_boxed(value, webkit_web_view_get_paste_target_list(webView));
290         break;
291 #endif
292     case PROP_EDITABLE:
293         g_value_set_boolean(value, webkit_web_view_get_editable(webView));
294         break;
295     case PROP_SETTINGS:
296         g_value_set_object(value, webkit_web_view_get_settings(webView));
297         break;
298     case PROP_WEB_INSPECTOR:
299         g_value_set_object(value, webkit_web_view_get_inspector(webView));
300         break;
301     case PROP_WINDOW_FEATURES:
302         g_value_set_object(value, webkit_web_view_get_window_features(webView));
303         break;
304     case PROP_TRANSPARENT:
305         g_value_set_boolean(value, webkit_web_view_get_transparent(webView));
306         break;
307     case PROP_ZOOM_LEVEL:
308         g_value_set_float(value, webkit_web_view_get_zoom_level(webView));
309         break;
310     case PROP_FULL_CONTENT_ZOOM:
311         g_value_set_boolean(value, webkit_web_view_get_full_content_zoom(webView));
312         break;
313     case PROP_ENCODING:
314         g_value_set_string(value, webkit_web_view_get_encoding(webView));
315         break;
316     case PROP_CUSTOM_ENCODING:
317         g_value_set_string(value, webkit_web_view_get_custom_encoding(webView));
318         break;
319     default:
320         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
321     }
322 }
323
324 static void webkit_web_view_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec)
325 {
326     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
327
328     switch(prop_id) {
329     case PROP_EDITABLE:
330         webkit_web_view_set_editable(webView, g_value_get_boolean(value));
331         break;
332     case PROP_SETTINGS:
333         webkit_web_view_set_settings(webView, WEBKIT_WEB_SETTINGS(g_value_get_object(value)));
334         break;
335     case PROP_WINDOW_FEATURES:
336         webkit_web_view_set_window_features(webView, WEBKIT_WEB_WINDOW_FEATURES(g_value_get_object(value)));
337         break;
338     case PROP_TRANSPARENT:
339         webkit_web_view_set_transparent(webView, g_value_get_boolean(value));
340         break;
341     case PROP_ZOOM_LEVEL:
342         webkit_web_view_set_zoom_level(webView, g_value_get_float(value));
343         break;
344     case PROP_FULL_CONTENT_ZOOM:
345         webkit_web_view_set_full_content_zoom(webView, g_value_get_boolean(value));
346         break;
347     case PROP_CUSTOM_ENCODING:
348         webkit_web_view_set_custom_encoding(webView, g_value_get_string(value));
349         break;
350     default:
351         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
352     }
353 }
354
355 static bool shouldCoalesce(GdkRectangle rect, GdkRectangle* rects, int count)
356 {
357     const int cRectThreshold = 10;
358     const float cWastedSpaceThreshold = 0.75f;
359     bool useUnionedRect = (count <= 1) || (count > cRectThreshold);
360     if (!useUnionedRect) {
361         // Attempt to guess whether or not we should use the unioned rect or the individual rects.
362         // We do this by computing the percentage of "wasted space" in the union.  If that wasted space
363         // is too large, then we will do individual rect painting instead.
364         float unionPixels = (rect.width * rect.height);
365         float singlePixels = 0;
366         for (int i = 0; i < count; ++i)
367             singlePixels += rects[i].width * rects[i].height;
368         float wastedSpace = 1 - (singlePixels / unionPixels);
369         if (wastedSpace <= cWastedSpaceThreshold)
370             useUnionedRect = true;
371     }
372     return useUnionedRect;
373 }
374
375 static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* event)
376 {
377     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
378     WebKitWebViewPrivate* priv = webView->priv;
379
380     Frame* frame = core(webView)->mainFrame();
381     if (frame->contentRenderer() && frame->view()) {
382         frame->view()->layoutIfNeededRecursive();
383
384         cairo_t* cr = gdk_cairo_create(event->window);
385         GraphicsContext ctx(cr);
386         cairo_destroy(cr);
387         ctx.setGdkExposeEvent(event);
388
389         GOwnPtr<GdkRectangle> rects;
390         int rectCount;
391         gdk_region_get_rectangles(event->region, &rects.outPtr(), &rectCount);
392
393         // Avoid recursing into the render tree excessively
394         bool coalesce = shouldCoalesce(event->area, rects.get(), rectCount);
395
396         if (coalesce) {
397             IntRect rect = event->area;
398             ctx.clip(rect);
399             if (priv->transparent)
400                 ctx.clearRect(rect);
401             frame->view()->paint(&ctx, rect);
402         } else {
403             for (int i = 0; i < rectCount; i++) {
404                 IntRect rect = rects.get()[i];
405                 ctx.save();
406                 ctx.clip(rect);
407                 if (priv->transparent)
408                     ctx.clearRect(rect);
409                 frame->view()->paint(&ctx, rect);
410                 ctx.restore();
411             }
412         }
413     }
414
415     return FALSE;
416 }
417
418 static gboolean webkit_web_view_key_press_event(GtkWidget* widget, GdkEventKey* event)
419 {
420     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
421
422     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
423     PlatformKeyboardEvent keyboardEvent(event);
424
425     if (!frame->view())
426         return FALSE;
427
428     if (frame->eventHandler()->keyEvent(keyboardEvent))
429         return TRUE;
430
431     FrameView* view = frame->view();
432     SelectionController::EAlteration alteration;
433     if (event->state & GDK_SHIFT_MASK)
434         alteration = SelectionController::EXTEND;
435     else
436         alteration = SelectionController::MOVE;
437
438     // TODO: We probably want to use GTK+ key bindings here and perhaps take an
439     // approach more like the Win and Mac ports for key handling.
440     switch (event->keyval) {
441     case GDK_Down:
442         view->scrollBy(IntSize(0, cScrollbarPixelsPerLineStep));
443         return TRUE;
444     case GDK_Up:
445         view->scrollBy(IntSize(0, -cScrollbarPixelsPerLineStep));
446         return TRUE;
447     case GDK_Right:
448         view->scrollBy(IntSize(cScrollbarPixelsPerLineStep, 0));
449         return TRUE;
450     case GDK_Left:
451         view->scrollBy(IntSize(-cScrollbarPixelsPerLineStep, 0));
452         return TRUE;
453     case GDK_space:
454         if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
455             view->scrollBy(IntSize(0, -view->visibleHeight()));
456         else
457             view->scrollBy(IntSize(0, view->visibleHeight()));
458         return TRUE;
459     case GDK_Page_Up:
460         view->scrollBy(IntSize(0, -view->visibleHeight()));
461         return TRUE;
462     case GDK_Page_Down:
463         view->scrollBy(IntSize(0, view->visibleHeight()));
464         return TRUE;
465     case GDK_Home:
466         view->scrollBy(IntSize(0, -view->contentsHeight()));
467         return TRUE;
468     case GDK_End:
469         view->scrollBy(IntSize(0, view->contentsHeight()));
470         return TRUE;
471     }
472
473     /* Chain up to our parent class for binding activation */
474     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_press_event(widget, event);
475 }
476
477 static gboolean webkit_web_view_key_release_event(GtkWidget* widget, GdkEventKey* event)
478 {
479     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
480
481     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
482     if (!frame->view())
483         return FALSE;
484
485     PlatformKeyboardEvent keyboardEvent(event);
486
487     if (frame->eventHandler()->keyEvent(keyboardEvent))
488         return TRUE;
489
490     /* Chain up to our parent class for binding activation */
491     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->key_release_event(widget, event);
492 }
493
494 static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventButton* event)
495 {
496     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
497
498     // FIXME: need to keep track of subframe focus for key events
499     gtk_widget_grab_focus(widget);
500
501     if (event->button == 3)
502         return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event));
503
504     Frame* frame = core(webView)->mainFrame();
505     if (!frame->view())
506         return FALSE;
507
508     return frame->eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
509 }
510
511 static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEventButton* event)
512 {
513     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
514
515     Frame* focusedFrame = core(webView)->focusController()->focusedFrame();
516
517     if (focusedFrame && focusedFrame->editor()->canEdit()) {
518 #ifdef MAEMO_CHANGES
519         WebKitWebViewPrivate* priv = webView->priv;
520         hildon_gtk_im_context_filter_event(priv->imContext, (GdkEvent*)event);
521 #endif
522     }
523
524     Frame* mainFrame = core(webView)->mainFrame();
525     if (mainFrame->view())
526         mainFrame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
527
528     /* We always return FALSE here because WebKit can, for the same click, decide
529      * to not handle press-event but handle release-event, which can totally confuse
530      * some GTK+ containers when there are no other events in between. This way we
531      * guarantee that this case never happens, and that if press-event goes through
532      * release-event also goes through.
533      */
534
535     return FALSE;
536 }
537
538 static gboolean webkit_web_view_motion_event(GtkWidget* widget, GdkEventMotion* event)
539 {
540     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
541
542     Frame* frame = core(webView)->mainFrame();
543     if (!frame->view())
544         return FALSE;
545
546     return frame->eventHandler()->mouseMoved(PlatformMouseEvent(event));
547 }
548
549 static gboolean webkit_web_view_scroll_event(GtkWidget* widget, GdkEventScroll* event)
550 {
551     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
552
553     Frame* frame = core(webView)->mainFrame();
554     if (!frame->view())
555         return FALSE;
556
557     PlatformWheelEvent wheelEvent(event);
558     return frame->eventHandler()->handleWheelEvent(wheelEvent);
559 }
560
561 static void webkit_web_view_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
562 {
563     GTK_WIDGET_CLASS(webkit_web_view_parent_class)->size_allocate(widget,allocation);
564
565     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
566
567     Frame* frame = core(webView)->mainFrame();
568     if (!frame->view())
569         return;
570
571     frame->view()->resize(allocation->width, allocation->height);
572     frame->view()->forceLayout();
573     frame->view()->adjustViewSize();
574 }
575
576 static gboolean webkit_web_view_focus_in_event(GtkWidget* widget, GdkEventFocus* event)
577 {
578     // TODO: Improve focus handling as suggested in
579     // http://bugs.webkit.org/show_bug.cgi?id=16910
580     GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
581     if (GTK_WIDGET_TOPLEVEL(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
582         WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
583
584         Frame* frame = core(webView)->mainFrame();
585         core(webView)->focusController()->setActive(frame);
586     }
587     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_in_event(widget, event);
588 }
589
590 static gboolean webkit_web_view_focus_out_event(GtkWidget* widget, GdkEventFocus* event)
591 {
592     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
593
594     core(webView)->focusController()->setActive(false);
595
596     return GTK_WIDGET_CLASS(webkit_web_view_parent_class)->focus_out_event(widget, event);
597 }
598
599 static void webkit_web_view_realize(GtkWidget* widget)
600 {
601     GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
602
603     GdkWindowAttr attributes;
604     attributes.window_type = GDK_WINDOW_CHILD;
605     attributes.x = widget->allocation.x;
606     attributes.y = widget->allocation.y;
607     attributes.width = widget->allocation.width;
608     attributes.height = widget->allocation.height;
609     attributes.wclass = GDK_INPUT_OUTPUT;
610     attributes.visual = gtk_widget_get_visual (widget);
611     attributes.colormap = gtk_widget_get_colormap (widget);
612     attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK
613                             | GDK_EXPOSURE_MASK
614                             | GDK_BUTTON_PRESS_MASK
615                             | GDK_BUTTON_RELEASE_MASK
616                             | GDK_POINTER_MOTION_MASK
617                             | GDK_KEY_PRESS_MASK
618                             | GDK_KEY_RELEASE_MASK
619                             | GDK_BUTTON_MOTION_MASK
620                             | GDK_BUTTON1_MOTION_MASK
621                             | GDK_BUTTON2_MOTION_MASK
622                             | GDK_BUTTON3_MOTION_MASK;
623
624     gint attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
625     widget->window = gdk_window_new(gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
626     gdk_window_set_user_data(widget->window, widget);
627
628     widget->style = gtk_style_attach(widget->style, widget->window);
629     gdk_window_set_background(widget->window, &widget->style->base[GTK_WIDGET_STATE(widget)]);
630
631     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
632     WebKitWebViewPrivate* priv = webView->priv;
633     gtk_im_context_set_client_window(priv->imContext, widget->window);
634 }
635
636 static void webkit_web_view_set_scroll_adjustments(WebKitWebView* webView, GtkAdjustment* hadj, GtkAdjustment* vadj)
637 {
638     if (!core(webView))
639         return;
640
641     FrameView* view = core(webkit_web_view_get_main_frame(webView))->view();
642
643     if (hadj)
644         g_object_ref(hadj);
645     if (vadj)
646         g_object_ref(vadj);
647
648     WebKitWebViewPrivate* priv = webView->priv;
649
650     if (priv->horizontalAdjustment)
651         g_object_unref(priv->horizontalAdjustment);
652     if (priv->verticalAdjustment)
653         g_object_unref(priv->verticalAdjustment);
654
655     priv->horizontalAdjustment = hadj;
656     priv->verticalAdjustment = vadj;
657
658     if (!view)
659         return;
660
661     view->setGtkAdjustments(hadj, vadj);
662 }
663
664 static void webkit_web_view_container_add(GtkContainer* container, GtkWidget* widget)
665 {
666     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
667     WebKitWebViewPrivate* priv = webView->priv;
668
669     priv->children.add(widget);
670     if (GTK_WIDGET_REALIZED(container))
671         gtk_widget_set_parent_window(widget, GTK_WIDGET(webView)->window);
672     gtk_widget_set_parent(widget, GTK_WIDGET(container));
673 }
674
675 static void webkit_web_view_container_remove(GtkContainer* container, GtkWidget* widget)
676 {
677     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
678     WebKitWebViewPrivate* priv = webView->priv;
679
680     if (priv->children.contains(widget)) {
681         gtk_widget_unparent(widget);
682         priv->children.remove(widget);
683     }
684 }
685
686 static void webkit_web_view_container_forall(GtkContainer* container, gboolean, GtkCallback callback, gpointer callbackData)
687 {
688     WebKitWebView* webView = WEBKIT_WEB_VIEW(container);
689     WebKitWebViewPrivate* priv = webView->priv;
690
691     HashSet<GtkWidget*> children = priv->children;
692     HashSet<GtkWidget*>::const_iterator end = children.end();
693     for (HashSet<GtkWidget*>::const_iterator current = children.begin(); current != end; ++current)
694         (*callback)(*current, callbackData);
695 }
696
697 static WebKitWebView* webkit_web_view_real_create_web_view(WebKitWebView*, WebKitWebFrame*)
698 {
699     return 0;
700 }
701
702 static gboolean webkit_web_view_real_web_view_ready(WebKitWebView*)
703 {
704     return FALSE;
705 }
706
707 static WebKitNavigationResponse webkit_web_view_real_navigation_requested(WebKitWebView*, WebKitWebFrame*, WebKitNetworkRequest*)
708 {
709     return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
710 }
711
712 static void webkit_web_view_real_window_object_cleared(WebKitWebView*, WebKitWebFrame*, JSGlobalContextRef context, JSObjectRef window_object)
713 {
714     notImplemented();
715 }
716
717 static gchar* webkit_web_view_real_choose_file(WebKitWebView*, WebKitWebFrame*, const gchar* old_name)
718 {
719     notImplemented();
720     return g_strdup(old_name);
721 }
722
723 typedef enum {
724     WEBKIT_SCRIPT_DIALOG_ALERT,
725     WEBKIT_SCRIPT_DIALOG_CONFIRM,
726     WEBKIT_SCRIPT_DIALOG_PROMPT
727  } WebKitScriptDialogType;
728
729 static gboolean webkit_web_view_script_dialog(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, WebKitScriptDialogType type, const gchar* defaultValue, gchar** value)
730 {
731     GtkMessageType messageType;
732     GtkButtonsType buttons;
733     gint defaultResponse;
734     GtkWidget* window;
735     GtkWidget* dialog;
736     GtkWidget* entry = 0;
737     gboolean didConfirm = FALSE;
738
739     switch (type) {
740     case WEBKIT_SCRIPT_DIALOG_ALERT:
741         messageType = GTK_MESSAGE_WARNING;
742         buttons = GTK_BUTTONS_CLOSE;
743         defaultResponse = GTK_RESPONSE_CLOSE;
744         break;
745     case WEBKIT_SCRIPT_DIALOG_CONFIRM:
746         messageType = GTK_MESSAGE_QUESTION;
747         buttons = GTK_BUTTONS_YES_NO;
748         defaultResponse = GTK_RESPONSE_YES;
749         break;
750     case WEBKIT_SCRIPT_DIALOG_PROMPT:
751         messageType = GTK_MESSAGE_QUESTION;
752         buttons = GTK_BUTTONS_OK_CANCEL;
753         defaultResponse = GTK_RESPONSE_OK;
754         break;
755     default:
756         g_warning("Unknown value for WebKitScriptDialogType.");
757         return FALSE;
758     }
759
760     window = gtk_widget_get_toplevel(GTK_WIDGET(webView));
761     dialog = gtk_message_dialog_new(GTK_WIDGET_TOPLEVEL(window) ? GTK_WINDOW(window) : 0, GTK_DIALOG_DESTROY_WITH_PARENT, messageType, buttons, "%s", message);
762     gchar* title = g_strconcat("JavaScript - ", webkit_web_frame_get_uri(frame), NULL);
763     gtk_window_set_title(GTK_WINDOW(dialog), title);
764     g_free(title);
765
766     if (type == WEBKIT_SCRIPT_DIALOG_PROMPT) {
767         entry = gtk_entry_new();
768         gtk_entry_set_text(GTK_ENTRY(entry), defaultValue);
769         gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);
770         gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
771         gtk_widget_show(entry);
772     }
773
774     gtk_dialog_set_default_response(GTK_DIALOG(dialog), defaultResponse);
775     gint response = gtk_dialog_run(GTK_DIALOG(dialog));
776
777     switch (response) {
778     case GTK_RESPONSE_YES:
779         didConfirm = TRUE;
780         break;
781     case GTK_RESPONSE_OK:
782         didConfirm = TRUE;
783         if (entry)
784             *value = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
785         else
786             *value = 0;
787         break;
788     case GTK_RESPONSE_NO:
789     case GTK_RESPONSE_CANCEL:
790         didConfirm = FALSE;
791         break;
792
793     }
794     gtk_widget_destroy(GTK_WIDGET(dialog));
795     return didConfirm;
796 }
797
798 static gboolean webkit_web_view_real_script_alert(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message)
799 {
800     webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_ALERT, 0, 0);
801     return TRUE;
802 }
803
804 static gboolean webkit_web_view_real_script_confirm(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, gboolean* didConfirm)
805 {
806     *didConfirm = webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_CONFIRM, 0, 0);
807     return TRUE;
808 }
809
810 static gboolean webkit_web_view_real_script_prompt(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, const gchar* defaultValue, gchar** value)
811 {
812     if (!webkit_web_view_script_dialog(webView, frame, message, WEBKIT_SCRIPT_DIALOG_PROMPT, defaultValue, value))
813         *value = NULL;
814     return TRUE;
815 }
816
817 static gboolean webkit_web_view_real_console_message(WebKitWebView* webView, const gchar* message, unsigned int line, const gchar* sourceId)
818 {
819     g_print("console message: %s @%d: %s\n", sourceId, line, message);
820     return TRUE;
821 }
822
823 static void webkit_web_view_real_select_all(WebKitWebView* webView)
824 {
825     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
826     frame->editor()->command("SelectAll").execute();
827 }
828
829 static void webkit_web_view_real_cut_clipboard(WebKitWebView* webView)
830 {
831     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
832     frame->editor()->command("Cut").execute();
833 }
834
835 static void webkit_web_view_real_copy_clipboard(WebKitWebView* webView)
836 {
837     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
838     frame->editor()->command("Copy").execute();
839 }
840
841 static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
842 {
843     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
844     frame->editor()->command("Paste").execute();
845 }
846
847 static void webkit_web_view_dispose(GObject* object)
848 {
849     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
850     WebKitWebViewPrivate* priv = webView->priv;
851
852     priv->disposing = TRUE;
853
854     if (priv->corePage) {
855         webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(object));
856
857         core(priv->mainFrame)->loader()->detachChildren();
858         delete priv->corePage;
859         priv->corePage = NULL;
860     }
861
862     if (priv->horizontalAdjustment) {
863         g_object_unref(priv->horizontalAdjustment);
864         priv->horizontalAdjustment = NULL;
865     }
866
867     if (priv->verticalAdjustment) {
868         g_object_unref(priv->verticalAdjustment);
869         priv->verticalAdjustment = NULL;
870     }
871
872     if (priv->backForwardList) {
873         g_object_unref(priv->backForwardList);
874         priv->backForwardList = NULL;
875
876         g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
877         g_object_unref(priv->webSettings);
878         priv->webSettings = NULL;
879
880         g_object_unref(priv->webInspector);
881         priv->webInspector = NULL;
882
883         g_object_unref(priv->webWindowFeatures);
884         priv->webWindowFeatures = NULL;
885
886         g_object_unref(priv->imContext);
887         priv->imContext = NULL;
888
889         gtk_target_list_unref(priv->copy_target_list);
890         priv->copy_target_list = NULL;
891
892         gtk_target_list_unref(priv->paste_target_list);
893         priv->paste_target_list = NULL;
894
895         delete priv->userAgent;
896         priv->userAgent = NULL;
897     }
898
899     G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
900 }
901
902 static void webkit_web_view_finalize(GObject* object)
903 {
904     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
905     WebKitWebViewPrivate* priv = webView->priv;
906
907     g_free(priv->encoding);
908     g_free(priv->customEncoding);
909
910     G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);
911 }
912
913 static gboolean webkit_create_web_view_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
914 {
915     gpointer newWebView = g_value_get_object(handlerReturn);
916     g_value_set_object(returnAccu, newWebView);
917
918     // Continue if we don't have a newWebView
919     return !newWebView;
920 }
921
922 static gboolean webkit_navigation_request_handled(GSignalInvocationHint* ihint, GValue* returnAccu, const GValue* handlerReturn, gpointer dummy)
923 {
924     WebKitNavigationResponse navigationResponse = (WebKitNavigationResponse)g_value_get_enum(handlerReturn);
925     g_value_set_enum(returnAccu, navigationResponse);
926
927     if (navigationResponse != WEBKIT_NAVIGATION_RESPONSE_ACCEPT)
928         return FALSE;
929
930     return TRUE;
931 }
932
933 static AtkObject* webkit_web_view_get_accessible(GtkWidget* widget)
934 {
935     WebKitWebView* webView = WEBKIT_WEB_VIEW(widget);
936     if (!core(webView))
937         return NULL;
938
939     AXObjectCache::enableAccessibility();
940
941     Frame* coreFrame = core(webView)->mainFrame();
942     if (!coreFrame)
943         return NULL;
944
945     Document* doc = coreFrame->document();
946     if (!doc)
947         return NULL;
948
949     AccessibilityObject* coreAccessible = doc->axObjectCache()->get(doc->renderer());
950     if (!coreAccessible || !coreAccessible->wrapper())
951         return NULL;
952
953     return coreAccessible->wrapper();
954 }
955
956 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
957 {
958     GtkBindingSet* binding_set;
959
960     webkit_init();
961
962     /*
963      * Signals
964      */
965
966     /**
967      * WebKitWebView::create-web-view:
968      * @web_view: the object on which the signal is emitted
969      * @frame: the #WebKitWebFrame
970      * @return: a newly allocated #WebKitWebView or %NULL
971      *
972      * Emitted when the creation of a new window is requested.
973      * If this signal is handled the signal handler should return the
974      * newly created #WebKitWebView.
975      *
976      * The new #WebKitWebView should not be displayed to the user
977      * until the #WebKitWebView::web-view-ready signal is emitted.
978      *
979      * The signal handlers should not try to deal with the reference
980      * count for the new #WebKitWebView. The widget to which the
981      * widget is added will handle that.
982      *
983      * Since 1.0.3
984      */
985     webkit_web_view_signals[CREATE_WEB_VIEW] = g_signal_new("create-web-view",
986             G_TYPE_FROM_CLASS(webViewClass),
987             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
988             G_STRUCT_OFFSET (WebKitWebViewClass, create_web_view),
989             webkit_create_web_view_request_handled,
990             NULL,
991             webkit_marshal_OBJECT__OBJECT,
992             WEBKIT_TYPE_WEB_VIEW , 1,
993             WEBKIT_TYPE_WEB_FRAME);
994
995     /**
996      * WebKitWebView::web-view-ready:
997      * @web_view: the object on which the signal is emitted
998      * @return: %TRUE to stop other handlers from being invoked for
999      * the event, %FALSE to propagate the event further
1000      *
1001      * Emitted after #WebKitWebView::create-web-view when the new #WebKitWebView
1002      * should be displayed to the user. When this signal is emitted
1003      * all the information about how the window should look, including
1004      * size, position, whether the location, status and scroll bars
1005      * should be displayed, is already set on the
1006      * #WebKitWebWindowFeatures object contained by the #WebKitWebView.
1007      *
1008      * Notice that some of that information may change during the life
1009      * time of the window, so you may want to connect to the ::notify
1010      * signal of the #WebKitWebWindowFeatures object to handle those.
1011      *
1012      * Since 1.0.3
1013      */
1014     webkit_web_view_signals[WEB_VIEW_READY] = g_signal_new("web-view-ready",
1015             G_TYPE_FROM_CLASS(webViewClass),
1016             (GSignalFlags)(G_SIGNAL_RUN_LAST),
1017             G_STRUCT_OFFSET (WebKitWebViewClass, web_view_ready),
1018             g_signal_accumulator_true_handled,
1019             NULL,
1020             webkit_marshal_BOOLEAN__VOID,
1021             G_TYPE_BOOLEAN, 0);
1022
1023     /**
1024      * WebKitWebView::navigation-requested:
1025      * @web_view: the object on which the signal is emitted
1026      * @frame: the #WebKitWebFrame that required the navigation
1027      * @request: a #WebKitNetworkRequest
1028      * @return: a WebKitNavigationResponse
1029      *
1030      * Emitted when @frame requests a navigation to another page.
1031      *
1032      * Deprecated: Use WebKitWebView::navigation-policy-decision-requested
1033      * instead
1034      */
1035     webkit_web_view_signals[NAVIGATION_REQUESTED] = g_signal_new("navigation-requested",
1036             G_TYPE_FROM_CLASS(webViewClass),
1037             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1038             G_STRUCT_OFFSET (WebKitWebViewClass, navigation_requested),
1039             webkit_navigation_request_handled,
1040             NULL,
1041             webkit_marshal_ENUM__OBJECT_OBJECT,
1042             WEBKIT_TYPE_NAVIGATION_RESPONSE, 2,
1043             WEBKIT_TYPE_WEB_FRAME,
1044             WEBKIT_TYPE_NETWORK_REQUEST);
1045
1046     /**
1047      * WebKitWebView::navigation-policy-decision-requested:
1048      * @web_view: the object on which the signal is emitted
1049      * @frame: the #WebKitWebFrame that required the navigation
1050      * @request: a #WebKitNetworkRequest
1051      * @navigation_action: a #WebKitWebNavigation
1052      * @policy_decision: a #WebKitWebPolicyDecision
1053      * @return: TRUE if the signal will be handled, FALSE to have the
1054      *          default behavior apply
1055      *
1056      * Emitted when @frame requests a navigation to another page.
1057      * If this signal is not handled, the default behavior is to allow the
1058      * navigation.
1059      *
1060      * Since: 1.0.3
1061      */
1062     webkit_web_view_signals[NAVIGATION_POLICY_DECISION_REQUESTED] = g_signal_new("navigation-policy-decision-requested",
1063             G_TYPE_FROM_CLASS(webViewClass),
1064             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1065             0,
1066             g_signal_accumulator_true_handled,
1067             NULL,
1068             webkit_marshal_BOOLEAN__OBJECT_OBJECT_OBJECT_OBJECT,
1069             G_TYPE_BOOLEAN, 4,
1070             WEBKIT_TYPE_WEB_FRAME,
1071             WEBKIT_TYPE_NETWORK_REQUEST,
1072             WEBKIT_TYPE_WEB_NAVIGATION_ACTION,
1073             WEBKIT_TYPE_WEB_POLICY_DECISION);
1074
1075     /**
1076      * WebKitWebView::mime-type-policy-decision-requested:
1077      * @web_view: the object on which the signal is emitted
1078      * @frame: the #WebKitWebFrame that required the policy decision
1079      * @request: a WebKitNetworkRequest
1080      * @mimetype: the MIME type attempted to load
1081      * @policy_decision: a #WebKitWebPolicyDecision
1082      * @return: TRUE if the signal will be handled, FALSE to have the
1083      *          default behavior apply
1084      *
1085      * Decide whether or not to display the given MIME type.  If this
1086      * signal is not handled, the default behavior is to show the
1087      * content of the requested URI if WebKit can show this MIME
1088      * type; if WebKit is not able to show the MIME type nothing
1089      * happens.
1090      *
1091      * Since: 1.0.3
1092      */
1093     webkit_web_view_signals[MIME_TYPE_POLICY_DECISION_REQUESTED] = g_signal_new("mime-type-policy-decision-requested",
1094             G_TYPE_FROM_CLASS(webViewClass),
1095             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1096             0,
1097             g_signal_accumulator_true_handled,
1098             NULL,
1099             webkit_marshal_BOOLEAN__OBJECT_OBJECT_STRING_OBJECT,
1100             G_TYPE_BOOLEAN, 4,
1101             WEBKIT_TYPE_WEB_FRAME,
1102             WEBKIT_TYPE_NETWORK_REQUEST,
1103             G_TYPE_STRING,
1104             WEBKIT_TYPE_WEB_POLICY_DECISION);
1105
1106     /**
1107      * WebKitWebView::window-object-cleared:
1108      * @web_view: the object on which the signal is emitted
1109      * @frame: the #WebKitWebFrame to which @window_object belongs
1110      * @context: the #JSGlobalContextRef holding the global object and other
1111      * execution state; equivalent to the return value of
1112      * webkit_web_frame_get_global_context(@frame)
1113      *
1114      * @window_object: the #JSObjectRef representing the frame's JavaScript
1115      * window object
1116      *
1117      * Emitted when the JavaScript window object in a #WebKitWebFrame has been
1118      * cleared in preparation for a new load. This is the preferred place to
1119      * set custom properties on the window object using the JavaScriptCore API.
1120      */
1121     webkit_web_view_signals[WINDOW_OBJECT_CLEARED] = g_signal_new("window-object-cleared",
1122             G_TYPE_FROM_CLASS(webViewClass),
1123             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1124             G_STRUCT_OFFSET (WebKitWebViewClass, window_object_cleared),
1125             NULL,
1126             NULL,
1127             webkit_marshal_VOID__OBJECT_POINTER_POINTER,
1128             G_TYPE_NONE, 3,
1129             WEBKIT_TYPE_WEB_FRAME,
1130             G_TYPE_POINTER,
1131             G_TYPE_POINTER);
1132
1133     /**
1134      * WebKitWebView::download-requested:
1135      * @web_view: the object on which the signal is emitted
1136      * @download: the message text
1137      * @return: TRUE if the download was handled.
1138      *
1139      * A new Download is being requested. By default, if the signal is
1140      * not handled, the download is cancelled.
1141      *
1142      * Since: 1.1.2
1143      */
1144     webkit_web_view_signals[DOWNLOAD_REQUESTED] = g_signal_new("download-requested",
1145             G_TYPE_FROM_CLASS(webViewClass),
1146             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1147             0,
1148             g_signal_accumulator_true_handled,
1149             NULL,
1150             webkit_marshal_BOOLEAN__OBJECT,
1151             G_TYPE_BOOLEAN, 1,
1152             G_TYPE_OBJECT);
1153
1154     /**
1155      * WebKitWebView::load-started:
1156      * @web_view: the object on which the signal is emitted
1157      * @frame: the frame going to do the load
1158      *
1159      * When a #WebKitWebFrame begins to load this signal is emitted.
1160      */
1161     webkit_web_view_signals[LOAD_STARTED] = g_signal_new("load-started",
1162             G_TYPE_FROM_CLASS(webViewClass),
1163             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1164             0,
1165             NULL,
1166             NULL,
1167             g_cclosure_marshal_VOID__OBJECT,
1168             G_TYPE_NONE, 1,
1169             WEBKIT_TYPE_WEB_FRAME);
1170
1171     /**
1172      * WebKitWebView::load-committed:
1173      * @web_view: the object on which the signal is emitted
1174      * @frame: the main frame that received the first data
1175      *
1176      * When a #WebKitWebFrame loaded the first data this signal is emitted.
1177      */
1178     webkit_web_view_signals[LOAD_COMMITTED] = g_signal_new("load-committed",
1179             G_TYPE_FROM_CLASS(webViewClass),
1180             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1181             0,
1182             NULL,
1183             NULL,
1184             g_cclosure_marshal_VOID__OBJECT,
1185             G_TYPE_NONE, 1,
1186             WEBKIT_TYPE_WEB_FRAME);
1187
1188
1189     /**
1190      * WebKitWebView::load-progress-changed:
1191      * @web_view: the #WebKitWebView
1192      * @progress: the global progress
1193      */
1194     webkit_web_view_signals[LOAD_PROGRESS_CHANGED] = g_signal_new("load-progress-changed",
1195             G_TYPE_FROM_CLASS(webViewClass),
1196             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1197             0,
1198             NULL,
1199             NULL,
1200             g_cclosure_marshal_VOID__INT,
1201             G_TYPE_NONE, 1,
1202             G_TYPE_INT);
1203
1204     webkit_web_view_signals[LOAD_FINISHED] = g_signal_new("load-finished",
1205             G_TYPE_FROM_CLASS(webViewClass),
1206             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1207             0,
1208             NULL,
1209             NULL,
1210             g_cclosure_marshal_VOID__OBJECT,
1211             G_TYPE_NONE, 1,
1212             WEBKIT_TYPE_WEB_FRAME);
1213
1214     /**
1215      * WebKitWebView::title-changed:
1216      * @web_view: the object on which the signal is emitted
1217      * @frame: the main frame
1218      * @title: the new title
1219      *
1220      * When a #WebKitWebFrame changes the document title this signal is emitted.
1221      */
1222     webkit_web_view_signals[TITLE_CHANGED] = g_signal_new("title-changed",
1223             G_TYPE_FROM_CLASS(webViewClass),
1224             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1225             0,
1226             NULL,
1227             NULL,
1228             webkit_marshal_VOID__OBJECT_STRING,
1229             G_TYPE_NONE, 2,
1230             WEBKIT_TYPE_WEB_FRAME,
1231             G_TYPE_STRING);
1232
1233     /**
1234      * WebKitWebView::hovering-over-link:
1235      * @web_view: the object on which the signal is emitted
1236      * @title: the link's title
1237      * @uri: the URI the link points to
1238      *
1239      * When the cursor is over a link, this signal is emitted.
1240      */
1241     webkit_web_view_signals[HOVERING_OVER_LINK] = g_signal_new("hovering-over-link",
1242             G_TYPE_FROM_CLASS(webViewClass),
1243             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1244             0,
1245             NULL,
1246             NULL,
1247             webkit_marshal_VOID__STRING_STRING,
1248             G_TYPE_NONE, 2,
1249             G_TYPE_STRING,
1250             G_TYPE_STRING);
1251
1252     /**
1253      * WebKitWebView::populate-popup:
1254      * @web_view: the object on which the signal is emitted
1255      * @menu: the context menu
1256      *
1257      * When a context menu is about to be displayed this signal is emitted.
1258      *
1259      * Add menu items to #menu to extend the context menu.
1260      */
1261     webkit_web_view_signals[POPULATE_POPUP] = g_signal_new("populate-popup",
1262             G_TYPE_FROM_CLASS(webViewClass),
1263             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1264             0,
1265             NULL,
1266             NULL,
1267             g_cclosure_marshal_VOID__OBJECT,
1268             G_TYPE_NONE, 1,
1269             GTK_TYPE_MENU);
1270
1271     webkit_web_view_signals[STATUS_BAR_TEXT_CHANGED] = g_signal_new("status-bar-text-changed",
1272             G_TYPE_FROM_CLASS(webViewClass),
1273             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1274             0,
1275             NULL,
1276             NULL,
1277             g_cclosure_marshal_VOID__STRING,
1278             G_TYPE_NONE, 1,
1279             G_TYPE_STRING);
1280
1281     webkit_web_view_signals[ICOND_LOADED] = g_signal_new("icon-loaded",
1282             G_TYPE_FROM_CLASS(webViewClass),
1283             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1284             0,
1285             NULL,
1286             NULL,
1287             g_cclosure_marshal_VOID__VOID,
1288             G_TYPE_NONE, 0);
1289
1290     webkit_web_view_signals[SELECTION_CHANGED] = g_signal_new("selection-changed",
1291             G_TYPE_FROM_CLASS(webViewClass),
1292             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1293             0,
1294             NULL,
1295             NULL,
1296             g_cclosure_marshal_VOID__VOID,
1297             G_TYPE_NONE, 0);
1298
1299     /**
1300      * WebKitWebView::console-message:
1301      * @web_view: the object on which the signal is emitted
1302      * @message: the message text
1303      * @line: the line where the error occured
1304      * @source_id: the source id
1305      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1306      *
1307      * A JavaScript console message was created.
1308      */
1309     webkit_web_view_signals[CONSOLE_MESSAGE] = g_signal_new("console-message",
1310             G_TYPE_FROM_CLASS(webViewClass),
1311             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1312             G_STRUCT_OFFSET(WebKitWebViewClass, console_message),
1313             g_signal_accumulator_true_handled,
1314             NULL,
1315             webkit_marshal_BOOLEAN__STRING_INT_STRING,
1316             G_TYPE_BOOLEAN, 3,
1317             G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING);
1318
1319     /**
1320      * WebKitWebView::script-alert:
1321      * @web_view: the object on which the signal is emitted
1322      * @frame: the relevant frame
1323      * @message: the message text
1324      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1325      *
1326      * A JavaScript alert dialog was created.
1327      */
1328     webkit_web_view_signals[SCRIPT_ALERT] = g_signal_new("script-alert",
1329             G_TYPE_FROM_CLASS(webViewClass),
1330             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1331             G_STRUCT_OFFSET(WebKitWebViewClass, script_alert),
1332             g_signal_accumulator_true_handled,
1333             NULL,
1334             webkit_marshal_BOOLEAN__OBJECT_STRING,
1335             G_TYPE_BOOLEAN, 2,
1336             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING);
1337
1338     /**
1339      * WebKitWebView::script-confirm:
1340      * @web_view: the object on which the signal is emitted
1341      * @frame: the relevant frame
1342      * @message: the message text
1343      * @confirmed: whether the dialog has been confirmed
1344      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1345      *
1346      * A JavaScript confirm dialog was created, providing Yes and No buttons.
1347      */
1348     webkit_web_view_signals[SCRIPT_CONFIRM] = g_signal_new("script-confirm",
1349             G_TYPE_FROM_CLASS(webViewClass),
1350             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1351             G_STRUCT_OFFSET(WebKitWebViewClass, script_confirm),
1352             g_signal_accumulator_true_handled,
1353             NULL,
1354             webkit_marshal_BOOLEAN__OBJECT_STRING_BOOLEAN,
1355             G_TYPE_BOOLEAN, 3,
1356             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_BOOLEAN);
1357
1358     /**
1359      * WebKitWebView::script-prompt:
1360      * @web_view: the object on which the signal is emitted
1361      * @frame: the relevant frame
1362      * @message: the message text
1363      * @default: the default value
1364      * @text: To be filled with the return value or NULL if the dialog was cancelled.
1365      * @return: TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
1366      *
1367      * A JavaScript prompt dialog was created, providing an entry to input text.
1368      */
1369     webkit_web_view_signals[SCRIPT_PROMPT] = g_signal_new("script-prompt",
1370             G_TYPE_FROM_CLASS(webViewClass),
1371             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1372             G_STRUCT_OFFSET(WebKitWebViewClass, script_prompt),
1373             g_signal_accumulator_true_handled,
1374             NULL,
1375             webkit_marshal_BOOLEAN__OBJECT_STRING_STRING_STRING,
1376             G_TYPE_BOOLEAN, 4,
1377             WEBKIT_TYPE_WEB_FRAME, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
1378
1379     /**
1380      * WebKitWebView::select-all:
1381      * @web_view: the object which received the signal
1382      *
1383      * The #WebKitWebView::select-all signal is a keybinding signal which gets emitted to
1384      * select the complete contents of the text view.
1385      *
1386      * The default bindings for this signal is Ctrl-a.
1387      */
1388     webkit_web_view_signals[SELECT_ALL] = g_signal_new("select-all",
1389             G_TYPE_FROM_CLASS(webViewClass),
1390             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1391             G_STRUCT_OFFSET(WebKitWebViewClass, select_all),
1392             NULL, NULL,
1393             g_cclosure_marshal_VOID__VOID,
1394             G_TYPE_NONE, 0);
1395
1396     /**
1397      * WebKitWebView::cut-clipboard:
1398      * @web_view: the object which received the signal
1399      *
1400      * The #WebKitWebView::cut-clipboard signal is a keybinding signal which gets emitted to
1401      * cut the selection to the clipboard.
1402      *
1403      * The default bindings for this signal are Ctrl-x and Shift-Delete.
1404      */
1405     webkit_web_view_signals[CUT_CLIPBOARD] = g_signal_new("cut-clipboard",
1406             G_TYPE_FROM_CLASS(webViewClass),
1407             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1408             G_STRUCT_OFFSET(WebKitWebViewClass, cut_clipboard),
1409             NULL, NULL,
1410             g_cclosure_marshal_VOID__VOID,
1411             G_TYPE_NONE, 0);
1412
1413     /**
1414      * WebKitWebView::copy-clipboard:
1415      * @web_view: the object which received the signal
1416      *
1417      * The #WebKitWebView::copy-clipboard signal is a keybinding signal which gets emitted to
1418      * copy the selection to the clipboard.
1419      *
1420      * The default bindings for this signal are Ctrl-c and Ctrl-Insert.
1421      */
1422     webkit_web_view_signals[COPY_CLIPBOARD] = g_signal_new("copy-clipboard",
1423             G_TYPE_FROM_CLASS(webViewClass),
1424             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1425             G_STRUCT_OFFSET(WebKitWebViewClass, copy_clipboard),
1426             NULL, NULL,
1427             g_cclosure_marshal_VOID__VOID,
1428             G_TYPE_NONE, 0);
1429
1430     /**
1431      * WebKitWebView::paste-clipboard:
1432      * @web_view: the object which received the signal
1433      *
1434      * The #WebKitWebView::paste-clipboard signal is a keybinding signal which gets emitted to
1435      * paste the contents of the clipboard into the Web view.
1436      *
1437      * The default bindings for this signal are Ctrl-v and Shift-Insert.
1438      */
1439     webkit_web_view_signals[PASTE_CLIPBOARD] = g_signal_new("paste-clipboard",
1440             G_TYPE_FROM_CLASS(webViewClass),
1441             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1442             G_STRUCT_OFFSET(WebKitWebViewClass, paste_clipboard),
1443             NULL, NULL,
1444             g_cclosure_marshal_VOID__VOID,
1445             G_TYPE_NONE, 0);
1446
1447     /*
1448      * implementations of virtual methods
1449      */
1450     webViewClass->create_web_view = webkit_web_view_real_create_web_view;
1451     webViewClass->web_view_ready = webkit_web_view_real_web_view_ready;
1452     webViewClass->navigation_requested = webkit_web_view_real_navigation_requested;
1453     webViewClass->window_object_cleared = webkit_web_view_real_window_object_cleared;
1454     webViewClass->choose_file = webkit_web_view_real_choose_file;
1455     webViewClass->script_alert = webkit_web_view_real_script_alert;
1456     webViewClass->script_confirm = webkit_web_view_real_script_confirm;
1457     webViewClass->script_prompt = webkit_web_view_real_script_prompt;
1458     webViewClass->console_message = webkit_web_view_real_console_message;
1459     webViewClass->select_all = webkit_web_view_real_select_all;
1460     webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
1461     webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
1462     webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
1463
1464     GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
1465     objectClass->dispose = webkit_web_view_dispose;
1466     objectClass->finalize = webkit_web_view_finalize;
1467     objectClass->get_property = webkit_web_view_get_property;
1468     objectClass->set_property = webkit_web_view_set_property;
1469
1470     GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webViewClass);
1471     widgetClass->realize = webkit_web_view_realize;
1472     widgetClass->expose_event = webkit_web_view_expose_event;
1473     widgetClass->key_press_event = webkit_web_view_key_press_event;
1474     widgetClass->key_release_event = webkit_web_view_key_release_event;
1475     widgetClass->button_press_event = webkit_web_view_button_press_event;
1476     widgetClass->button_release_event = webkit_web_view_button_release_event;
1477     widgetClass->motion_notify_event = webkit_web_view_motion_event;
1478     widgetClass->scroll_event = webkit_web_view_scroll_event;
1479     widgetClass->size_allocate = webkit_web_view_size_allocate;
1480     widgetClass->popup_menu = webkit_web_view_popup_menu_handler;
1481     widgetClass->focus_in_event = webkit_web_view_focus_in_event;
1482     widgetClass->focus_out_event = webkit_web_view_focus_out_event;
1483     widgetClass->get_accessible = webkit_web_view_get_accessible;
1484
1485     GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewClass);
1486     containerClass->add = webkit_web_view_container_add;
1487     containerClass->remove = webkit_web_view_container_remove;
1488     containerClass->forall = webkit_web_view_container_forall;
1489
1490     /*
1491      * make us scrollable (e.g. addable to a GtkScrolledWindow)
1492      */
1493     webViewClass->set_scroll_adjustments = webkit_web_view_set_scroll_adjustments;
1494     GTK_WIDGET_CLASS(webViewClass)->set_scroll_adjustments_signal = g_signal_new("set-scroll-adjustments",
1495             G_TYPE_FROM_CLASS(webViewClass),
1496             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1497             G_STRUCT_OFFSET(WebKitWebViewClass, set_scroll_adjustments),
1498             NULL, NULL,
1499             webkit_marshal_VOID__OBJECT_OBJECT,
1500             G_TYPE_NONE, 2,
1501             GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
1502
1503     /*
1504      * Key bindings
1505      */
1506
1507     binding_set = gtk_binding_set_by_class(webViewClass);
1508
1509     gtk_binding_entry_add_signal(binding_set, GDK_a, GDK_CONTROL_MASK,
1510                                  "select_all", 0);
1511
1512     /* Cut/copy/paste */
1513
1514     gtk_binding_entry_add_signal(binding_set, GDK_x, GDK_CONTROL_MASK,
1515                                  "cut_clipboard", 0);
1516     gtk_binding_entry_add_signal(binding_set, GDK_c, GDK_CONTROL_MASK,
1517                                  "copy_clipboard", 0);
1518     gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK,
1519                                  "paste_clipboard", 0);
1520
1521     gtk_binding_entry_add_signal(binding_set, GDK_Delete, GDK_SHIFT_MASK,
1522                                  "cut_clipboard", 0);
1523     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_CONTROL_MASK,
1524                                  "copy_clipboard", 0);
1525     gtk_binding_entry_add_signal(binding_set, GDK_Insert, GDK_SHIFT_MASK,
1526                                  "paste_clipboard", 0);
1527
1528     /*
1529      * properties
1530      */
1531
1532 #if GTK_CHECK_VERSION(2,10,0)
1533     /**
1534     * WebKitWebView:copy-target-list:
1535     *
1536     * The list of targets this web view supports for clipboard copying.
1537     *
1538     * Since: 1.0.2
1539     */
1540     g_object_class_install_property(objectClass, PROP_COPY_TARGET_LIST,
1541                                     g_param_spec_boxed("copy-target-list",
1542                                                        "Copy target list",
1543                                                        "The list of targets this web view supports for clipboard copying",
1544                                                        GTK_TYPE_TARGET_LIST,
1545                                                        WEBKIT_PARAM_READABLE));
1546
1547     /**
1548     * WebKitWebView:paste-target-list:
1549     *
1550     * The list of targets this web view supports for clipboard pasting.
1551     *
1552     * Since: 1.0.2
1553     */
1554     g_object_class_install_property(objectClass, PROP_PASTE_TARGET_LIST,
1555                                     g_param_spec_boxed("paste-target-list",
1556                                                        "Paste target list",
1557                                                        "The list of targets this web view supports for clipboard pasting",
1558                                                        GTK_TYPE_TARGET_LIST,
1559                                                        WEBKIT_PARAM_READABLE));
1560 #endif
1561
1562     g_object_class_install_property(objectClass, PROP_SETTINGS,
1563                                     g_param_spec_object("settings",
1564                                                         "Settings",
1565                                                         "An associated WebKitWebSettings instance",
1566                                                         WEBKIT_TYPE_WEB_SETTINGS,
1567                                                         WEBKIT_PARAM_READWRITE));
1568
1569     /**
1570     * WebKitWebView:web-inspector:
1571     *
1572     * The associated WebKitWebInspector instance.
1573     *
1574     * Since: 1.0.3
1575     */
1576     g_object_class_install_property(objectClass, PROP_WEB_INSPECTOR,
1577                                     g_param_spec_object("web-inspector",
1578                                                         "Web Inspector",
1579                                                         "The associated WebKitWebInspector instance",
1580                                                         WEBKIT_TYPE_WEB_INSPECTOR,
1581                                                         WEBKIT_PARAM_READABLE));
1582
1583     /**
1584     * WebKitWebView:window-features:
1585     *
1586     * An associated WebKitWebWindowFeatures instance.
1587     *
1588     * Since: 1.0.3
1589     */
1590     g_object_class_install_property(objectClass, PROP_WINDOW_FEATURES,
1591                                     g_param_spec_object("window-features",
1592                                                         "Window Features",
1593                                                         "An associated WebKitWebWindowFeatures instance",
1594                                                         WEBKIT_TYPE_WEB_WINDOW_FEATURES,
1595                                                         WEBKIT_PARAM_READWRITE));
1596
1597     g_object_class_install_property(objectClass, PROP_EDITABLE,
1598                                     g_param_spec_boolean("editable",
1599                                                          "Editable",
1600                                                          "Whether content can be modified by the user",
1601                                                          FALSE,
1602                                                          WEBKIT_PARAM_READWRITE));
1603
1604     g_object_class_install_property(objectClass, PROP_TRANSPARENT,
1605                                     g_param_spec_boolean("transparent",
1606                                                          "Transparent",
1607                                                          "Whether content has a transparent background",
1608                                                          FALSE,
1609                                                          WEBKIT_PARAM_READWRITE));
1610
1611     /**
1612     * WebKitWebView:zoom-level:
1613     *
1614     * The level of zoom of the content.
1615     *
1616     * Since: 1.0.1
1617     */
1618     g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL,
1619                                     g_param_spec_float("zoom-level",
1620                                                        "Zoom level",
1621                                                        "The level of zoom of the content",
1622                                                        G_MINFLOAT,
1623                                                        G_MAXFLOAT,
1624                                                        1.0f,
1625                                                        WEBKIT_PARAM_READWRITE));
1626
1627     /**
1628     * WebKitWebView:full-content-zoom:
1629     *
1630     * Whether the full content is scaled when zooming.
1631     *
1632     * Since: 1.0.1
1633     */
1634     g_object_class_install_property(objectClass, PROP_FULL_CONTENT_ZOOM,
1635                                     g_param_spec_boolean("full-content-zoom",
1636                                                          "Full content zoom",
1637                                                          "Whether the full content is scaled when zooming",
1638                                                          FALSE,
1639                                                          WEBKIT_PARAM_READWRITE));
1640
1641     /**
1642      * WebKitWebView:encoding:
1643      *
1644      * The default encoding of the web view.
1645      *
1646      * Since: 1.1.2
1647      */
1648     g_object_class_install_property(objectClass, PROP_ENCODING,
1649                                     g_param_spec_string("encoding",
1650                                                         "Encoding",
1651                                                         "The default encoding of the web view",
1652                                                         NULL,
1653                                                         WEBKIT_PARAM_READABLE));
1654
1655     /**
1656      * WebKitWebView:custom-encoding:
1657      *
1658      * The custom encoding of the web view.
1659      *
1660      * Since: 1.1.2
1661      */
1662     g_object_class_install_property(objectClass, PROP_CUSTOM_ENCODING,
1663                                     g_param_spec_string("custom-encoding",
1664                                                         "Custom Encoding",
1665                                                         "The custom encoding of the web view",
1666                                                         NULL,
1667                                                         WEBKIT_PARAM_READWRITE));
1668
1669     g_type_class_add_private(webViewClass, sizeof(WebKitWebViewPrivate));
1670 }
1671
1672 static gdouble webViewGetDPI(WebKitWebView* webView)
1673 {
1674     WebKitWebViewPrivate* priv = webView->priv;
1675     WebKitWebSettings* webSettings = priv->webSettings;
1676     gboolean enforce96DPI;
1677     g_object_get(webSettings, "enforce-96-dpi", &enforce96DPI, NULL);
1678     if (enforce96DPI)
1679         return 96.0;
1680
1681     gdouble DPI = defaultDPI;
1682 #if GTK_CHECK_VERSION(2,10,0)
1683     GdkScreen* screen = gtk_widget_has_screen(GTK_WIDGET(webView)) ? gtk_widget_get_screen(GTK_WIDGET(webView)) : gdk_screen_get_default();
1684     if (screen) {
1685         DPI = gdk_screen_get_resolution(screen);
1686         // gdk_screen_get_resolution() returns -1 when no DPI is set.
1687         if (DPI == -1)
1688             DPI = defaultDPI;
1689     }
1690 #endif
1691     ASSERT(DPI > 0);
1692     return DPI;
1693 }
1694
1695 static void webkit_web_view_screen_changed(WebKitWebView* webView, GdkScreen* previousScreen, gpointer userdata)
1696 {
1697     WebKitWebViewPrivate* priv = webView->priv;
1698     WebKitWebSettings* webSettings = priv->webSettings;
1699     Settings* settings = core(webView)->settings();
1700     gdouble DPI = webViewGetDPI(webView);
1701
1702     guint defaultFontSize, defaultMonospaceFontSize, minimumFontSize, minimumLogicalFontSize;
1703
1704     g_object_get(webSettings,
1705                  "default-font-size", &defaultFontSize,
1706                  "default-monospace-font-size", &defaultMonospaceFontSize,
1707                  "minimum-font-size", &minimumFontSize,
1708                  "minimum-logical-font-size", &minimumLogicalFontSize,
1709                  NULL);
1710
1711     settings->setDefaultFontSize(defaultFontSize / 72.0 * DPI);
1712     settings->setDefaultFixedFontSize(defaultMonospaceFontSize / 72.0 * DPI);
1713     settings->setMinimumFontSize(minimumFontSize / 72.0 * DPI);
1714     settings->setMinimumLogicalFontSize(minimumLogicalFontSize / 72.0 * DPI);
1715 }
1716
1717 static void webkit_web_view_update_settings(WebKitWebView* webView)
1718 {
1719     WebKitWebViewPrivate* priv = webView->priv;
1720     WebKitWebSettings* webSettings = priv->webSettings;
1721     Settings* settings = core(webView)->settings();
1722
1723     gchar* defaultEncoding, *cursiveFontFamily, *defaultFontFamily, *fantasyFontFamily, *monospaceFontFamily, *sansSerifFontFamily, *serifFontFamily, *userStylesheetUri;
1724     gboolean autoLoadImages, autoShrinkImages, printBackgrounds,
1725         enableScripts, enablePlugins, enableDeveloperExtras, resizableTextAreas,
1726         enablePrivateBrowsing;
1727
1728     g_object_get(webSettings,
1729                  "default-encoding", &defaultEncoding,
1730                  "cursive-font-family", &cursiveFontFamily,
1731                  "default-font-family", &defaultFontFamily,
1732                  "fantasy-font-family", &fantasyFontFamily,
1733                  "monospace-font-family", &monospaceFontFamily,
1734                  "sans-serif-font-family", &sansSerifFontFamily,
1735                  "serif-font-family", &serifFontFamily,
1736                  "auto-load-images", &autoLoadImages,
1737                  "auto-shrink-images", &autoShrinkImages,
1738                  "print-backgrounds", &printBackgrounds,
1739                  "enable-scripts", &enableScripts,
1740                  "enable-plugins", &enablePlugins,
1741                  "resizable-text-areas", &resizableTextAreas,
1742                  "user-stylesheet-uri", &userStylesheetUri,
1743                  "enable-developer-extras", &enableDeveloperExtras,
1744                  "enable-private-browsing", &enablePrivateBrowsing,
1745                  NULL);
1746
1747     settings->setDefaultTextEncodingName(defaultEncoding);
1748     settings->setCursiveFontFamily(cursiveFontFamily);
1749     settings->setStandardFontFamily(defaultFontFamily);
1750     settings->setFantasyFontFamily(fantasyFontFamily);
1751     settings->setFixedFontFamily(monospaceFontFamily);
1752     settings->setSansSerifFontFamily(sansSerifFontFamily);
1753     settings->setSerifFontFamily(serifFontFamily);
1754     settings->setLoadsImagesAutomatically(autoLoadImages);
1755     settings->setShrinksStandaloneImagesToFit(autoShrinkImages);
1756     settings->setShouldPrintBackgrounds(printBackgrounds);
1757     settings->setJavaScriptEnabled(enableScripts);
1758     settings->setPluginsEnabled(enablePlugins);
1759     settings->setTextAreasAreResizable(resizableTextAreas);
1760     settings->setUserStyleSheetLocation(KURL(KURL(), userStylesheetUri));
1761     settings->setDeveloperExtrasEnabled(enableDeveloperExtras);
1762     settings->setPrivateBrowsingEnabled(enablePrivateBrowsing);
1763
1764     g_free(defaultEncoding);
1765     g_free(cursiveFontFamily);
1766     g_free(defaultFontFamily);
1767     g_free(fantasyFontFamily);
1768     g_free(monospaceFontFamily);
1769     g_free(sansSerifFontFamily);
1770     g_free(serifFontFamily);
1771     g_free(userStylesheetUri);
1772
1773     webkit_web_view_screen_changed(webView, NULL, NULL);
1774 }
1775
1776 static inline gint pixelsFromSize(WebKitWebView* webView, gint size)
1777 {
1778     gdouble DPI = webViewGetDPI(webView);
1779     return size / 72.0 * DPI;
1780 }
1781
1782 static void webkit_web_view_settings_notify(WebKitWebSettings* webSettings, GParamSpec* pspec, WebKitWebView* webView)
1783 {
1784     Settings* settings = core(webView)->settings();
1785
1786     const gchar* name = g_intern_string(pspec->name);
1787     GValue value = { 0, { { 0 } } };
1788     g_value_init(&value, pspec->value_type);
1789     g_object_get_property(G_OBJECT(webSettings), name, &value);
1790
1791     if (name == g_intern_string("default-encoding"))
1792         settings->setDefaultTextEncodingName(g_value_get_string(&value));
1793     else if (name == g_intern_string("cursive-font-family"))
1794         settings->setCursiveFontFamily(g_value_get_string(&value));
1795     else if (name == g_intern_string("default-font-family"))
1796         settings->setStandardFontFamily(g_value_get_string(&value));
1797     else if (name == g_intern_string("fantasy-font-family"))
1798         settings->setFantasyFontFamily(g_value_get_string(&value));
1799     else if (name == g_intern_string("monospace-font-family"))
1800         settings->setFixedFontFamily(g_value_get_string(&value));
1801     else if (name == g_intern_string("sans-serif-font-family"))
1802         settings->setSansSerifFontFamily(g_value_get_string(&value));
1803     else if (name == g_intern_string("serif-font-family"))
1804         settings->setSerifFontFamily(g_value_get_string(&value));
1805     else if (name == g_intern_string("default-font-size"))
1806         settings->setDefaultFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1807     else if (name == g_intern_string("default-monospace-font-size"))
1808         settings->setDefaultFixedFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1809     else if (name == g_intern_string("minimum-font-size"))
1810         settings->setMinimumFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1811     else if (name == g_intern_string("minimum-logical-font-size"))
1812         settings->setMinimumLogicalFontSize(pixelsFromSize(webView, g_value_get_int(&value)));
1813     else if (name == g_intern_string("enforce-96-dpi"))
1814         webkit_web_view_screen_changed(webView, NULL, NULL);
1815     else if (name == g_intern_string("auto-load-images"))
1816         settings->setLoadsImagesAutomatically(g_value_get_boolean(&value));
1817     else if (name == g_intern_string("auto-shrink-images"))
1818         settings->setShrinksStandaloneImagesToFit(g_value_get_boolean(&value));
1819     else if (name == g_intern_string("print-backgrounds"))
1820         settings->setShouldPrintBackgrounds(g_value_get_boolean(&value));
1821     else if (name == g_intern_string("enable-scripts"))
1822         settings->setJavaScriptEnabled(g_value_get_boolean(&value));
1823     else if (name == g_intern_string("enable-plugins"))
1824         settings->setPluginsEnabled(g_value_get_boolean(&value));
1825     else if (name == g_intern_string("resizable-text-areas"))
1826         settings->setTextAreasAreResizable(g_value_get_boolean(&value));
1827     else if (name == g_intern_string("user-stylesheet-uri"))
1828         settings->setUserStyleSheetLocation(KURL(KURL(), g_value_get_string(&value)));
1829     else if (name == g_intern_string("enable-developer-extras"))
1830         settings->setDeveloperExtrasEnabled(g_value_get_boolean(&value));
1831     else if (name == g_intern_string("enable-private-browsing"))
1832         settings->setPrivateBrowsingEnabled(g_value_get_boolean(&value));
1833     else if (!g_object_class_find_property(G_OBJECT_GET_CLASS(webSettings), name))
1834         g_warning("Unexpected setting '%s'", name);
1835     g_value_unset(&value);
1836 }
1837
1838 static void webkit_web_view_init(WebKitWebView* webView)
1839 {
1840     WebKitWebViewPrivate* priv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView);
1841     webView->priv = priv;
1842
1843     priv->imContext = gtk_im_multicontext_new();
1844
1845     WebKit::InspectorClient* inspectorClient = new WebKit::InspectorClient(webView);
1846     priv->corePage = new Page(new WebKit::ChromeClient(webView), new WebKit::ContextMenuClient(webView), new WebKit::EditorClient(webView), new WebKit::DragClient, inspectorClient);
1847
1848     // We also add a simple wrapper class to provide the public
1849     // interface for the Web Inspector.
1850     priv->webInspector = WEBKIT_WEB_INSPECTOR(g_object_new(WEBKIT_TYPE_WEB_INSPECTOR, NULL));
1851     webkit_web_inspector_set_inspector_client(priv->webInspector, priv->corePage);
1852
1853     priv->horizontalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
1854     priv->verticalAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
1855
1856     g_object_ref_sink(priv->horizontalAdjustment);
1857     g_object_ref_sink(priv->verticalAdjustment);
1858
1859     GTK_WIDGET_SET_FLAGS(webView, GTK_CAN_FOCUS);
1860     priv->mainFrame = WEBKIT_WEB_FRAME(webkit_web_frame_new(webView));
1861     priv->lastPopupXPosition = priv->lastPopupYPosition = -1;
1862     priv->editable = false;
1863
1864     priv->backForwardList = webkit_web_back_forward_list_new_with_web_view(webView);
1865
1866     priv->zoomFullContent = FALSE;
1867
1868 #if GTK_CHECK_VERSION(2,10,0)
1869     GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
1870 #else
1871     GdkAtom textHtml = gdk_atom_intern("text/html", false);
1872 #endif
1873     /* Targets for copy */
1874     priv->copy_target_list = gtk_target_list_new(NULL, 0);
1875     gtk_target_list_add(priv->copy_target_list, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
1876     gtk_target_list_add_text_targets(priv->copy_target_list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
1877
1878     /* Targets for pasting */
1879     priv->paste_target_list = gtk_target_list_new(NULL, 0);
1880     gtk_target_list_add(priv->paste_target_list, textHtml, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
1881     gtk_target_list_add_text_targets(priv->paste_target_list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
1882
1883     priv->webSettings = webkit_web_settings_new();
1884     webkit_web_view_update_settings(webView);
1885     g_signal_connect(webView, "screen-changed", G_CALLBACK(webkit_web_view_screen_changed), NULL);
1886     g_signal_connect(priv->webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
1887
1888     priv->webWindowFeatures = webkit_web_window_features_new();
1889 }
1890
1891 GtkWidget* webkit_web_view_new(void)
1892 {
1893     WebKitWebView* webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL));
1894
1895     return GTK_WIDGET(webView);
1896 }
1897
1898 // for internal use only
1899 void webkit_web_view_notify_ready(WebKitWebView* webView)
1900 {
1901     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1902
1903     gboolean isHandled = FALSE;
1904     g_signal_emit(webView, webkit_web_view_signals[WEB_VIEW_READY], 0, &isHandled);
1905 }
1906
1907
1908 void webkit_web_view_set_settings(WebKitWebView* webView, WebKitWebSettings* webSettings)
1909 {
1910     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1911     g_return_if_fail(WEBKIT_IS_WEB_SETTINGS(webSettings));
1912
1913     WebKitWebViewPrivate* priv = webView->priv;
1914     g_signal_handlers_disconnect_by_func(priv->webSettings, (gpointer)webkit_web_view_settings_notify, webView);
1915     g_object_unref(priv->webSettings);
1916     g_object_ref(webSettings);
1917     priv->webSettings = webSettings;
1918     webkit_web_view_update_settings(webView);
1919     g_signal_connect(webSettings, "notify", G_CALLBACK(webkit_web_view_settings_notify), webView);
1920     g_object_notify(G_OBJECT(webView), "settings");
1921 }
1922
1923 WebKitWebSettings* webkit_web_view_get_settings(WebKitWebView* webView)
1924 {
1925     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1926
1927     WebKitWebViewPrivate* priv = webView->priv;
1928     return priv->webSettings;
1929 }
1930
1931 /**
1932  * webkit_web_view_get_inspector:
1933  * @web_view: a #WebKitWebView
1934  *
1935  * Obtains the #WebKitWebInspector associated with the
1936  * #WebKitWebView. Every #WebKitWebView object has a
1937  * #WebKitWebInspector object attached to it as soon as it is created,
1938  * so this function will only return NULL if the argument is not a
1939  * valid #WebKitWebView.
1940  *
1941  * Returns: the #WebKitWebInspector instance associated with the
1942  * #WebKitWebView; %NULL is only returned if the argument is not a
1943  * valid #WebKitWebView.
1944  *
1945  * Since: 1.0.3
1946  */
1947 WebKitWebInspector* webkit_web_view_get_inspector(WebKitWebView* webView)
1948 {
1949     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1950
1951     WebKitWebViewPrivate* priv = webView->priv;
1952     return priv->webInspector;
1953 }
1954
1955 // internal
1956 static void webkit_web_view_set_window_features(WebKitWebView* webView, WebKitWebWindowFeatures* webWindowFeatures)
1957 {
1958     WebKitWebViewPrivate* priv = webView->priv;
1959
1960     if(webkit_web_window_features_equal(priv->webWindowFeatures, webWindowFeatures))
1961       return;
1962
1963     g_object_unref(priv->webWindowFeatures);
1964     g_object_ref(webWindowFeatures);
1965     priv->webWindowFeatures = webWindowFeatures;
1966 }
1967
1968 /**
1969  * webkit_web_view_get_window_features
1970  * @web_view: a #WebKitWebView
1971  *
1972  * Returns the instance of #WebKitWebWindowFeatures held by the given
1973  * #WebKitWebView.
1974  *
1975  * Return value: the #WebKitWebWindowFeatures
1976  *
1977  * Since: 1.0.3
1978  */
1979 WebKitWebWindowFeatures* webkit_web_view_get_window_features(WebKitWebView* webView)
1980 {
1981     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
1982
1983     WebKitWebViewPrivate* priv = webView->priv;
1984     return priv->webWindowFeatures;
1985 }
1986
1987 /**
1988  * webkit_web_view_set_maintains_back_forward_list:
1989  * @web_view: a #WebKitWebView
1990  * @flag: to tell the view to maintain a back or forward list
1991  *
1992  * Set the view to maintain a back or forward list of history items.
1993  */
1994 void webkit_web_view_set_maintains_back_forward_list(WebKitWebView* webView, gboolean flag)
1995 {
1996     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
1997
1998     core(webView)->backForwardList()->setEnabled(flag);
1999 }
2000
2001 /**
2002  * webkit_web_view_get_back_forward_list:
2003  * @web_view: a #WebKitWebView
2004  *
2005  * Returns a #WebKitWebBackForwardList
2006  *
2007  * Return value: the #WebKitWebBackForwardList
2008  */
2009 WebKitWebBackForwardList* webkit_web_view_get_back_forward_list(WebKitWebView* webView)
2010 {
2011     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2012
2013     WebKitWebViewPrivate* priv = webView->priv;
2014
2015     if (!core(webView) || !core(webView)->backForwardList()->enabled())
2016         return NULL;
2017
2018     return priv->backForwardList;
2019 }
2020
2021 /**
2022  * webkit_web_view_go_to_back_forward_item:
2023  * @web_view: a #WebKitWebView
2024  * @item: a #WebKitWebHistoryItem*
2025  *
2026  * Go to the specified #WebKitWebHistoryItem
2027  *
2028  * Return value: %TRUE if loading of item is successful, %FALSE if not
2029  */
2030 gboolean webkit_web_view_go_to_back_forward_item(WebKitWebView* webView, WebKitWebHistoryItem* item)
2031 {
2032     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2033     g_return_val_if_fail(WEBKIT_IS_WEB_HISTORY_ITEM(item), FALSE);
2034
2035     WebKitWebBackForwardList* backForwardList = webkit_web_view_get_back_forward_list(webView);
2036     if (!webkit_web_back_forward_list_contains_item(backForwardList, item))
2037         return FALSE;
2038
2039     core(webView)->goToItem(core(item), FrameLoadTypeIndexedBackForward);
2040     return TRUE;
2041 }
2042
2043 /**
2044  * webkit_web_view_go_back:
2045  * @web_view: a #WebKitWebView
2046  *
2047  * Loads the previous history item.
2048  */
2049 void webkit_web_view_go_back(WebKitWebView* webView)
2050 {
2051     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2052
2053     core(webView)->goBack();
2054 }
2055
2056 /**
2057  * webkit_web_view_go_back_or_forward:
2058  * @web_view: a #WebKitWebView
2059  * @steps: the number of steps
2060  *
2061  * Loads the history item that is the number of @steps away from the current
2062  * item. Negative values represent steps backward while positive values
2063  * represent steps forward.
2064  */
2065 void webkit_web_view_go_back_or_forward(WebKitWebView* webView, gint steps)
2066 {
2067     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2068
2069     Frame* frame = core(webView)->mainFrame();
2070     frame->loader()->goBackOrForward(steps);
2071 }
2072
2073 /**
2074  * webkit_web_view_go_forward:
2075  * @web_view: a #WebKitWebView
2076  *
2077  * Loads the next history item.
2078  */
2079 void webkit_web_view_go_forward(WebKitWebView* webView)
2080 {
2081     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2082
2083     core(webView)->goForward();
2084 }
2085
2086 /**
2087  * webkit_web_view_can_go_back:
2088  * @web_view: a #WebKitWebView
2089  *
2090  * Determines whether #web_view has a previous history item.
2091  *
2092  * Return value: %TRUE if able to move back, %FALSE otherwise
2093  */
2094 gboolean webkit_web_view_can_go_back(WebKitWebView* webView)
2095 {
2096     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2097
2098     if (!core(webView) || !core(webView)->backForwardList()->backItem())
2099         return FALSE;
2100
2101     return TRUE;
2102 }
2103
2104 /**
2105  * webkit_web_view_can_go_back_or_forward:
2106  * @web_view: a #WebKitWebView
2107  * @steps: the number of steps
2108  *
2109  * Determines whether #web_view has a history item of @steps. Negative values
2110  * represent steps backward while positive values represent steps forward.
2111  *
2112  * Return value: %TRUE if able to move back or forward the given number of
2113  * steps, %FALSE otherwise
2114  */
2115 gboolean webkit_web_view_can_go_back_or_forward(WebKitWebView* webView, gint steps)
2116 {
2117     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2118
2119     Frame* frame = core(webView)->mainFrame();
2120     return frame->loader()->canGoBackOrForward(steps);
2121 }
2122
2123 /**
2124  * webkit_web_view_can_go_forward:
2125  * @web_view: a #WebKitWebView
2126  *
2127  * Determines whether #web_view has a next history item.
2128  *
2129  * Return value: %TRUE if able to move forward, %FALSE otherwise
2130  */
2131 gboolean webkit_web_view_can_go_forward(WebKitWebView* webView)
2132 {
2133     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2134
2135     Page* page = core(webView);
2136
2137     if (!page)
2138         return FALSE;
2139
2140     if (!page->backForwardList()->forwardItem())
2141         return FALSE;
2142
2143     return TRUE;
2144 }
2145
2146 /**
2147  * webkit_web_view_open:
2148  * @web_view: a #WebKitWebView
2149  * @uri: an URI
2150  *
2151  * Requests loading of the specified URI string.
2152  *
2153  * Deprecated: 1.1.1: Use webkit_web_view_load_uri() instead.
2154   */
2155 void webkit_web_view_open(WebKitWebView* webView, const gchar* uri)
2156 {
2157     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2158     g_return_if_fail(uri);
2159
2160     // We used to support local paths, unlike the newer
2161     // function webkit_web_view_load_uri
2162     if (g_path_is_absolute(uri)) {
2163         gchar* fileUri = g_strdup_printf("file://%s", uri);
2164         webkit_web_view_load_uri(webView, fileUri);
2165         g_free(fileUri);
2166     }
2167     else
2168         webkit_web_view_load_uri(webView, uri);
2169 }
2170
2171 void webkit_web_view_reload(WebKitWebView* webView)
2172 {
2173     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2174
2175     core(webView)->mainFrame()->loader()->reload();
2176 }
2177
2178 /**
2179  * webkit_web_view_reload_bypass_cache:
2180  * @web_view: a #WebKitWebView
2181  *
2182  * Reloads the @web_view without using any cached data.
2183  *
2184  * Since: 1.0.3
2185  */
2186 void webkit_web_view_reload_bypass_cache(WebKitWebView* webView)
2187 {
2188     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2189
2190     core(webView)->mainFrame()->loader()->reload(true);
2191 }
2192
2193 /**
2194  * webkit_web_view_load_uri:
2195  * @web_view: a #WebKitWebView
2196  * @uri: an URI string
2197  *
2198  * Requests loading of the specified URI string.
2199  *
2200  * Since: 1.1.1
2201  */
2202 void webkit_web_view_load_uri(WebKitWebView* webView, const gchar* uri)
2203 {
2204     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2205     g_return_if_fail(uri);
2206
2207     WebKitWebFrame* frame = webView->priv->mainFrame;
2208     webkit_web_frame_load_uri(frame, uri);
2209 }
2210
2211 /**
2212 +  * webkit_web_view_load_string:
2213 +  * @web_view: a #WebKitWebView
2214 +  * @content: an URI string
2215 +  * @mime_type: the MIME type, or %NULL
2216 +  * @encoding: the encoding, or %NULL
2217 +  * @base_uri: the base URI for relative locations
2218 +  *
2219 +  * Requests loading of the given @content with the specified @mime_type,
2220 +  * @encoding and @base_uri.
2221 +  *
2222 +  * If @mime_type is %NULL, "text/html" is assumed.
2223 +  *
2224 +  * If @encoding is %NULL, "UTF-8" is assumed.
2225 +  */
2226 void webkit_web_view_load_string(WebKitWebView* webView, const gchar* content, const gchar* mimeType, const gchar* encoding, const gchar* baseUri)
2227 {
2228     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2229     g_return_if_fail(content);
2230
2231     WebKitWebFrame* frame = webView->priv->mainFrame;
2232     webkit_web_frame_load_string(frame, content, mimeType, encoding, baseUri);
2233 }
2234 /**
2235  * webkit_web_view_load_html_string:
2236  * @web_view: a #WebKitWebView
2237  * @content: an URI string
2238  * @base_uri: the base URI for relative locations
2239  *
2240  * Requests loading of the given @content with the specified @base_uri.
2241  *
2242  * Deprecated: 1.1.1: Use webkit_web_view_load_string() instead.
2243  */
2244 void webkit_web_view_load_html_string(WebKitWebView* webView, const gchar* content, const gchar* baseUri)
2245 {
2246     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2247     g_return_if_fail(content);
2248
2249     webkit_web_view_load_string(webView, content, NULL, NULL, baseUri);
2250 }
2251
2252 /**
2253  * webkit_web_view_load_request:
2254  * @web_view: a #WebKitWebView
2255  * @request: a #WebKitNetworkRequest
2256  *
2257  * Requests loading of the specified asynchronous client request.
2258  *
2259  * Creates a provisional data source that will transition to a committed data
2260  * source once any data has been received. Use webkit_web_view_stop_loading() to
2261  * stop the load.
2262  *
2263  * Since: 1.1.1
2264  */
2265 void webkit_web_view_load_request(WebKitWebView* webView, WebKitNetworkRequest* request)
2266 {
2267     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2268     g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request));
2269
2270     WebKitWebFrame* frame = webView->priv->mainFrame;
2271     webkit_web_frame_load_request(frame, request);
2272 }
2273
2274 void webkit_web_view_stop_loading(WebKitWebView* webView)
2275 {
2276     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2277
2278     Frame* frame = core(webView)->mainFrame();
2279
2280     if (FrameLoader* loader = frame->loader())
2281         loader->stopAllLoaders();
2282 }
2283
2284 /**
2285  * webkit_web_view_search_text:
2286  * @web_view: a #WebKitWebView
2287  * @text: a string to look for
2288  * @forward: whether to find forward or not
2289  * @case_sensitive: whether to respect the case of text
2290  * @wrap: whether to continue looking at the beginning after reaching the end
2291  *
2292  * Looks for a specified string inside #web_view.
2293  *
2294  * Return value: %TRUE on success or %FALSE on failure
2295  */
2296 gboolean webkit_web_view_search_text(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, gboolean forward, gboolean shouldWrap)
2297 {
2298     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2299     g_return_val_if_fail(string, FALSE);
2300
2301     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
2302     FindDirection direction = forward ? FindDirectionForward : FindDirectionBackward;
2303
2304     return core(webView)->findString(String::fromUTF8(string), caseSensitivity, direction, shouldWrap);
2305 }
2306
2307 /**
2308  * webkit_web_view_mark_text_matches:
2309  * @web_view: a #WebKitWebView
2310  * @string: a string to look for
2311  * @case_sensitive: whether to respect the case of text
2312  * @limit: the maximum number of strings to look for or %0 for all
2313  *
2314  * Attempts to highlight all occurances of #string inside #web_view.
2315  *
2316  * Return value: the number of strings highlighted
2317  */
2318 guint webkit_web_view_mark_text_matches(WebKitWebView* webView, const gchar* string, gboolean caseSensitive, guint limit)
2319 {
2320     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
2321     g_return_val_if_fail(string, 0);
2322
2323     TextCaseSensitivity caseSensitivity = caseSensitive ? TextCaseSensitive : TextCaseInsensitive;
2324
2325     return core(webView)->markAllMatchesForText(String::fromUTF8(string), caseSensitivity, false, limit);
2326 }
2327
2328 /**
2329  * webkit_web_view_set_highlight_text_matches:
2330  * @web_view: a #WebKitWebView
2331  * @highlight: whether to highlight text matches
2332  *
2333  * Highlights text matches previously marked by webkit_web_view_mark_text_matches.
2334  */
2335 void webkit_web_view_set_highlight_text_matches(WebKitWebView* webView, gboolean shouldHighlight)
2336 {
2337     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2338
2339     core(webView)->mainFrame()->setMarkedTextMatchesAreHighlighted(shouldHighlight);
2340 }
2341
2342 /**
2343  * webkit_web_view_unmark_text_matches:
2344  * @web_view: a #WebKitWebView
2345  *
2346  * Removes highlighting previously set by webkit_web_view_mark_text_matches.
2347  */
2348 void webkit_web_view_unmark_text_matches(WebKitWebView* webView)
2349 {
2350     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2351
2352     return core(webView)->unmarkAllTextMatches();
2353 }
2354
2355 WebKitWebFrame* webkit_web_view_get_main_frame(WebKitWebView* webView)
2356 {
2357     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2358
2359     WebKitWebViewPrivate* priv = webView->priv;
2360     return priv->mainFrame;
2361 }
2362
2363 /**
2364  * webkit_web_view_get_focused_frame:
2365  * @web_view: a #WebKitWebView
2366  *
2367  * Returns the frame that has focus or an active text selection.
2368  *
2369  * Return value: The focused #WebKitWebFrame or %NULL if no frame is focused
2370  */
2371 WebKitWebFrame* webkit_web_view_get_focused_frame(WebKitWebView* webView)
2372 {
2373     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2374
2375     Frame* focusedFrame = core(webView)->focusController()->focusedFrame();
2376     return kit(focusedFrame);
2377 }
2378
2379 void webkit_web_view_execute_script(WebKitWebView* webView, const gchar* script)
2380 {
2381     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2382     g_return_if_fail(script);
2383
2384     if (FrameLoader* loader = core(webView)->mainFrame()->loader())
2385         loader->executeScript(String::fromUTF8(script), true);
2386 }
2387
2388 /**
2389  * webkit_web_view_cut_clipboard:
2390  * @web_view: a #WebKitWebView
2391  *
2392  * Determines whether or not it is currently possible to cut to the clipboard.
2393  *
2394  * Return value: %TRUE if a selection can be cut, %FALSE if not
2395  */
2396 gboolean webkit_web_view_can_cut_clipboard(WebKitWebView* webView)
2397 {
2398     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2399
2400     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2401     return frame->editor()->canCut() || frame->editor()->canDHTMLCut();
2402 }
2403
2404 /**
2405  * webkit_web_view_copy_clipboard:
2406  * @web_view: a #WebKitWebView
2407  *
2408  * Determines whether or not it is currently possible to copy to the clipboard.
2409  *
2410  * Return value: %TRUE if a selection can be copied, %FALSE if not
2411  */
2412 gboolean webkit_web_view_can_copy_clipboard(WebKitWebView* webView)
2413 {
2414     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2415
2416     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2417     return frame->editor()->canCopy() || frame->editor()->canDHTMLCopy();
2418 }
2419
2420 /**
2421  * webkit_web_view_paste_clipboard:
2422  * @web_view: a #WebKitWebView
2423  *
2424  * Determines whether or not it is currently possible to paste from the clipboard.
2425  *
2426  * Return value: %TRUE if a selection can be pasted, %FALSE if not
2427  */
2428 gboolean webkit_web_view_can_paste_clipboard(WebKitWebView* webView)
2429 {
2430     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2431
2432     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2433     return frame->editor()->canPaste() || frame->editor()->canDHTMLPaste();
2434 }
2435
2436 /**
2437  * webkit_web_view_cut_clipboard:
2438  * @web_view: a #WebKitWebView
2439  *
2440  * Cuts the current selection inside the @web_view to the clipboard.
2441  */
2442 void webkit_web_view_cut_clipboard(WebKitWebView* webView)
2443 {
2444     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2445
2446     if (webkit_web_view_can_cut_clipboard(webView))
2447         g_signal_emit(webView, webkit_web_view_signals[CUT_CLIPBOARD], 0);
2448 }
2449
2450 /**
2451  * webkit_web_view_copy_clipboard:
2452  * @web_view: a #WebKitWebView
2453  *
2454  * Copies the current selection inside the @web_view to the clipboard.
2455  */
2456 void webkit_web_view_copy_clipboard(WebKitWebView* webView)
2457 {
2458     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2459
2460     if (webkit_web_view_can_copy_clipboard(webView))
2461         g_signal_emit(webView, webkit_web_view_signals[COPY_CLIPBOARD], 0);
2462 }
2463
2464 /**
2465  * webkit_web_view_paste_clipboard:
2466  * @web_view: a #WebKitWebView
2467  *
2468  * Pastes the current contents of the clipboard to the @web_view.
2469  */
2470 void webkit_web_view_paste_clipboard(WebKitWebView* webView)
2471 {
2472     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2473
2474     if (webkit_web_view_can_paste_clipboard(webView))
2475         g_signal_emit(webView, webkit_web_view_signals[PASTE_CLIPBOARD], 0);
2476 }
2477
2478 /**
2479  * webkit_web_view_delete_selection:
2480  * @web_view: a #WebKitWebView
2481  *
2482  * Deletes the current selection inside the @web_view.
2483  */
2484 void webkit_web_view_delete_selection(WebKitWebView* webView)
2485 {
2486     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2487
2488     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2489     frame->editor()->performDelete();
2490 }
2491
2492 /**
2493  * webkit_web_view_has_selection:
2494  * @web_view: a #WebKitWebView
2495  *
2496  * Determines whether text was selected.
2497  *
2498  * Return value: %TRUE if there is selected text, %FALSE if not
2499  */
2500 gboolean webkit_web_view_has_selection(WebKitWebView* webView)
2501 {
2502     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2503
2504     return !core(webView)->selection().isNone();
2505 }
2506
2507 /**
2508  * webkit_web_view_get_selected_text:
2509  * @web_view: a #WebKitWebView
2510  *
2511  * Retrieves the selected text if any.
2512  *
2513  * Return value: a newly allocated string with the selection or %NULL
2514  */
2515 gchar* webkit_web_view_get_selected_text(WebKitWebView* webView)
2516 {
2517     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
2518
2519     Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
2520     return g_strdup(frame->selectedText().utf8().data());
2521 }
2522
2523 /**
2524  * webkit_web_view_select_all:
2525  * @web_view: a #WebKitWebView
2526  *
2527  * Attempts to select everything inside the @web_view.
2528  */
2529 void webkit_web_view_select_all(WebKitWebView* webView)
2530 {
2531     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2532
2533     g_signal_emit(webView, webkit_web_view_signals[SELECT_ALL], 0);
2534 }
2535
2536 /**
2537  * webkit_web_view_get_editable:
2538  * @web_view: a #WebKitWebView
2539  *
2540  * Returns whether the user is allowed to edit the document.
2541  *
2542  * Returns %TRUE if @web_view allows the user to edit the HTML document, %FALSE if
2543  * it doesn't. You can change @web_view's document programmatically regardless of
2544  * this setting.
2545  *
2546  * Return value: a #gboolean indicating the editable state
2547  */
2548 gboolean webkit_web_view_get_editable(WebKitWebView* webView)
2549 {
2550     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2551
2552     WebKitWebViewPrivate* priv = webView->priv;
2553
2554     return priv->editable;
2555 }
2556
2557 /**
2558  * webkit_web_view_set_editable:
2559  * @web_view: a #WebKitWebView
2560  * @flag: a #gboolean indicating the editable state
2561  *
2562  * Sets whether @web_view allows the user to edit its HTML document.
2563  *
2564  * If @flag is %TRUE, @web_view allows the user to edit the document. If @flag is
2565  * %FALSE, an element in @web_view's document can only be edited if the
2566  * CONTENTEDITABLE attribute has been set on the element or one of its parent
2567  * elements. You can change @web_view's document programmatically regardless of
2568  * this setting. By default a #WebKitWebView is not editable.
2569
2570  * Normally, an HTML document is not editable unless the elements within the
2571  * document are editable. This function provides a low-level way to make the
2572  * contents of a #WebKitWebView editable without altering the document or DOM
2573  * structure.
2574  */
2575 void webkit_web_view_set_editable(WebKitWebView* webView, gboolean flag)
2576 {
2577     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2578
2579     WebKitWebViewPrivate* priv = webView->priv;
2580
2581     Frame* frame = core(webView)->mainFrame();
2582     g_return_if_fail(frame);
2583
2584     // TODO: What happens when the frame is replaced?
2585     flag = flag != FALSE;
2586     if (flag == priv->editable)
2587         return;
2588
2589     priv->editable = flag;
2590
2591     if (flag) {
2592         frame->applyEditingStyleToBodyElement();
2593         // TODO: If the WebKitWebView is made editable and the selection is empty, set it to something.
2594         //if (!webkit_web_view_get_selected_dom_range(webView))
2595         //    mainFrame->setSelectionFromNone();
2596     } else
2597         frame->removeEditingStyleFromBodyElement();
2598     g_object_notify(G_OBJECT(webView), "editable");
2599 }
2600
2601 /**
2602  * webkit_web_view_get_copy_target_list:
2603  * @web_view: a #WebKitWebView
2604  *
2605  * This function returns the list of targets this #WebKitWebView can
2606  * provide for clipboard copying and as DND source. The targets in the list are
2607  * added with %info values from the #WebKitWebViewTargetInfo enum,
2608  * using gtk_target_list_add() and
2609  * gtk_target_list_add_text_targets().
2610  *
2611  * Return value: the #GtkTargetList
2612  **/
2613 GtkTargetList* webkit_web_view_get_copy_target_list(WebKitWebView* webView)
2614 {
2615     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2616
2617     WebKitWebViewPrivate* priv = webView->priv;
2618     return priv->copy_target_list;
2619 }
2620
2621 /**
2622  * webkit_web_view_get_paste_target_list:
2623  * @web_view: a #WebKitWebView
2624  *
2625  * This function returns the list of targets this #WebKitWebView can
2626  * provide for clipboard pasting and as DND destination. The targets in the list are
2627  * added with %info values from the #WebKitWebViewTargetInfo enum,
2628  * using gtk_target_list_add() and
2629  * gtk_target_list_add_text_targets().
2630  *
2631  * Return value: the #GtkTargetList
2632  **/
2633 GtkTargetList* webkit_web_view_get_paste_target_list(WebKitWebView* webView)
2634 {
2635     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2636
2637     WebKitWebViewPrivate* priv = webView->priv;
2638     return priv->paste_target_list;
2639 }
2640
2641 /**
2642  * webkit_web_view_can_show_mime_type:
2643  * @web_view: a #WebKitWebView
2644  * @mime_type: a MIME type
2645  *
2646  * This functions returns whether or not a MIME type can be displayed using this view.
2647  *
2648  * Return value: a #gboolean indicating if the MIME type can be displayed
2649  *
2650  * Since: 1.0.3
2651  **/
2652
2653 gboolean webkit_web_view_can_show_mime_type(WebKitWebView* webView, const gchar* mimeType)
2654 {
2655     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2656
2657     Frame* frame = core(webkit_web_view_get_main_frame(webView));
2658     if (FrameLoader* loader = frame->loader())
2659         return loader->canShowMIMEType(String::fromUTF8(mimeType));
2660     else
2661         return FALSE;
2662 }
2663
2664 /**
2665  * webkit_web_view_get_transparent:
2666  * @web_view: a #WebKitWebView
2667  *
2668  * Returns whether the #WebKitWebView has a transparent background.
2669  *
2670  * Return value: %FALSE when the #WebKitWebView draws a solid background
2671  * (the default), otherwise %TRUE.
2672  */
2673 gboolean webkit_web_view_get_transparent(WebKitWebView* webView)
2674 {
2675     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2676
2677     WebKitWebViewPrivate* priv = webView->priv;
2678     return priv->transparent;
2679 }
2680
2681 /**
2682  * webkit_web_view_set_transparent:
2683  * @web_view: a #WebKitWebView
2684  *
2685  * Sets whether the #WebKitWebView has a transparent background.
2686  *
2687  * Pass %FALSE to have the #WebKitWebView draw a solid background
2688  * (the default), otherwise %TRUE.
2689  */
2690 void webkit_web_view_set_transparent(WebKitWebView* webView, gboolean flag)
2691 {
2692     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2693
2694     WebKitWebViewPrivate* priv = webView->priv;
2695     priv->transparent = flag;
2696
2697     // TODO: This needs to be made persistent or it could become a problem when
2698     // the main frame is replaced.
2699     Frame* frame = core(webView)->mainFrame();
2700     g_return_if_fail(frame);
2701     frame->view()->setTransparent(flag);
2702     g_object_notify(G_OBJECT(webView), "transparent");
2703 }
2704
2705 /**
2706  * webkit_web_view_get_zoom_level:
2707  * @web_view: a #WebKitWebView
2708  *
2709  * Returns the zoom level of @web_view, i.e. the factor by which elements in
2710  * the page are scaled with respect to their original size.
2711  * If the "full-content-zoom" property is set to %FALSE (the default)
2712  * the zoom level changes the text size, or if %TRUE, scales all
2713  * elements in the page.
2714  *
2715  * Return value: the zoom level of @web_view
2716  *
2717  * Since: 1.0.1
2718  */
2719 gfloat webkit_web_view_get_zoom_level(WebKitWebView* webView)
2720 {
2721     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 1.0f);
2722
2723     Frame* frame = core(webView)->mainFrame();
2724     if (!frame)
2725         return 1.0f;
2726
2727     return frame->zoomFactor();
2728 }
2729
2730 static void webkit_web_view_apply_zoom_level(WebKitWebView* webView, gfloat zoomLevel)
2731 {
2732     Frame* frame = core(webView)->mainFrame();
2733     if (!frame)
2734         return;
2735
2736     WebKitWebViewPrivate* priv = webView->priv;
2737     frame->setZoomFactor(zoomLevel, !priv->zoomFullContent);
2738 }
2739
2740 /**
2741  * webkit_web_view_set_zoom_level:
2742  * @web_view: a #WebKitWebView
2743  * @zoom_level: the new zoom level
2744  *
2745  * Sets the zoom level of @web_view, i.e. the factor by which elements in
2746  * the page are scaled with respect to their original size.
2747  * If the "full-content-zoom" property is set to %FALSE (the default)
2748  * the zoom level changes the text size, or if %TRUE, scales all
2749  * elements in the page.
2750  *
2751  * Since: 1.0.1
2752  */
2753 void webkit_web_view_set_zoom_level(WebKitWebView* webView, gfloat zoomLevel)
2754 {
2755     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2756
2757     webkit_web_view_apply_zoom_level(webView, zoomLevel);
2758     g_object_notify(G_OBJECT(webView), "zoom-level");
2759 }
2760
2761 /**
2762  * webkit_web_view_zoom_in:
2763  * @web_view: a #WebKitWebView
2764  *
2765  * Increases the zoom level of @web_view. The current zoom
2766  * level is incremented by the value of the "zoom-step"
2767  * property of the #WebKitWebSettings associated with @web_view.
2768  *
2769  * Since: 1.0.1
2770  */
2771 void webkit_web_view_zoom_in(WebKitWebView* webView)
2772 {
2773     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2774
2775     WebKitWebViewPrivate* priv = webView->priv;
2776     gfloat zoomMultiplierRatio;
2777     g_object_get(priv->webSettings, "zoom-step", &zoomMultiplierRatio, NULL);
2778
2779     webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) + zoomMultiplierRatio);
2780 }
2781
2782 /**
2783  * webkit_web_view_zoom_out:
2784  * @web_view: a #WebKitWebView
2785  *
2786  * Decreases the zoom level of @web_view. The current zoom
2787  * level is decremented by the value of the "zoom-step"
2788  * property of the #WebKitWebSettings associated with @web_view.
2789  *
2790  * Since: 1.0.1
2791  */
2792 void webkit_web_view_zoom_out(WebKitWebView* webView)
2793 {
2794     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2795
2796     WebKitWebViewPrivate* priv = webView->priv;
2797     gfloat zoomMultiplierRatio;
2798     g_object_get(priv->webSettings, "zoom-step", &zoomMultiplierRatio, NULL);
2799
2800     webkit_web_view_set_zoom_level(webView, webkit_web_view_get_zoom_level(webView) - zoomMultiplierRatio);
2801 }
2802
2803 /**
2804  * webkit_web_view_get_full_content_zoom:
2805  * @web_view: a #WebKitWebView
2806  *
2807  * Returns whether the zoom level affects only text or all elements.
2808  *
2809  * Return value: %FALSE if only text should be scaled (the default),
2810  * %TRUE if the full content of the view should be scaled.
2811  *
2812  * Since: 1.0.1
2813  */
2814 gboolean webkit_web_view_get_full_content_zoom(WebKitWebView* webView)
2815 {
2816     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
2817
2818     WebKitWebViewPrivate* priv = webView->priv;
2819     return priv->zoomFullContent;
2820 }
2821
2822 /**
2823  * webkit_web_view_set_full_content_zoom:
2824  * @web_view: a #WebKitWebView
2825  * @full_content_zoom: %FALSE if only text should be scaled (the default),
2826  * %TRUE if the full content of the view should be scaled.
2827  *
2828  * Sets whether the zoom level affects only text or all elements.
2829  *
2830  * Since: 1.0.1
2831  */
2832 void webkit_web_view_set_full_content_zoom(WebKitWebView* webView, gboolean zoomFullContent)
2833 {
2834     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2835
2836     WebKitWebViewPrivate* priv = webView->priv;
2837     if (priv->zoomFullContent == zoomFullContent)
2838       return;
2839
2840     priv->zoomFullContent = zoomFullContent;
2841     webkit_web_view_apply_zoom_level(webView, webkit_web_view_get_zoom_level(webView));
2842
2843     g_object_notify(G_OBJECT(webView), "full-content-zoom");
2844 }
2845
2846 /**
2847  * webkit_get_default_session:
2848  *
2849  * Retrieves the default #SoupSession used by all web views.
2850  * Note that the session features are added by WebKit on demand,
2851  * so if you insert your own #SoupCookieJar before any network
2852  * traffic occurs, WebKit will use it instead of the default.
2853  *
2854  * Return value: the default #SoupSession
2855  *
2856  * Since: 1.1.1
2857  */
2858 SoupSession* webkit_get_default_session ()
2859 {
2860     return ResourceHandle::defaultSession();
2861 }
2862
2863 }
2864
2865 /**
2866  * webkit_web_view_get_encoding:
2867  * @web_view: a #WebKitWebView
2868  *
2869  * Returns the default encoding of the #WebKitWebView.
2870  *
2871  * Return value: the default encoding
2872  *
2873  * Since: 1.1.1
2874  */
2875 const gchar* webkit_web_view_get_encoding(WebKitWebView* webView)
2876 {
2877     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2878
2879     String encoding = core(webView)->mainFrame()->loader()->encoding();
2880
2881     if (!encoding.isEmpty()) {
2882         WebKitWebViewPrivate* priv = webView->priv;
2883         g_free(priv->encoding);
2884         priv->encoding = g_strdup(encoding.utf8().data());
2885         return priv->encoding;
2886     } else
2887       return NULL;
2888 }
2889
2890 /**
2891  * webkit_web_view_set_custom_encoding:
2892  * @web_view: a #WebKitWebView
2893  * @encoding: the new encoding, or %NULL to restore the default encoding
2894  *
2895  * Sets the current #WebKitWebView encoding, without modifying the default one,
2896  * and reloads the page.
2897  *
2898  * Since: 1.1.1
2899  */
2900 void webkit_web_view_set_custom_encoding(WebKitWebView* webView, const char* encoding)
2901 {
2902     g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
2903
2904     core(webView)->mainFrame()->loader()->reloadWithOverrideEncoding(String::fromUTF8(encoding));
2905 }
2906
2907 /**
2908  * webkit_web_view_get_custom_encoding:
2909  * @web_view: a #WebKitWebView
2910  *
2911  * Returns the current encoding of the #WebKitWebView, not the default-encoding
2912  * of WebKitWebSettings.
2913  *
2914  * Return value: a string containing the current custom encoding for @web_view, or %NULL if there's none set.
2915  *
2916  * Since: 1.1.1
2917  */
2918 const char* webkit_web_view_get_custom_encoding(WebKitWebView* webView)
2919 {
2920     g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
2921
2922     String overrideEncoding = core(webView)->mainFrame()->loader()->documentLoader()->overrideEncoding();
2923
2924     if (!overrideEncoding.isEmpty()) {
2925         WebKitWebViewPrivate* priv = webView->priv;
2926         g_free (priv->customEncoding);
2927         priv->customEncoding = g_strdup(overrideEncoding.utf8().data());
2928         return priv->customEncoding;
2929     } else
2930       return NULL;
2931 }