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