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