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