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