diff options
Diffstat (limited to 'WebKit/gtk/webkit/webkitwebframe.cpp')
-rw-r--r-- | WebKit/gtk/webkit/webkitwebframe.cpp | 119 |
1 files changed, 96 insertions, 23 deletions
diff --git a/WebKit/gtk/webkit/webkitwebframe.cpp b/WebKit/gtk/webkit/webkitwebframe.cpp index 6a4c4d5..38e23a4 100644 --- a/WebKit/gtk/webkit/webkitwebframe.cpp +++ b/WebKit/gtk/webkit/webkitwebframe.cpp @@ -29,6 +29,7 @@ #include "webkitmarshal.h" #include "webkitprivate.h" +#include "AnimationController.h" #include "CString.h" #include "FrameLoader.h" #include "FrameLoaderClientGtk.h" @@ -45,6 +46,24 @@ #include <JavaScriptCore/APICast.h> +/** + * SECTION:webkitwebframe + * @short_description: The content of a #WebKitWebView + * + * A #WebKitWebView contains a main #WebKitWebFrame. A #WebKitWebFrame + * contains the content of one URI. The URI and name of the frame can + * be retrieved, the load status and progress can be observed using the + * signals and can be controlled using the methods of the #WebKitWebFrame. + * A #WebKitWebFrame can have any number of children and one child can + * be found by using #webkit_web_frame_find_frame. + * + * <informalexample><programlisting> + * /<!-- -->* Get the frame from the #WebKitWebView *<!-- -->/ + * WebKitWebFrame *frame = webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW(my_view)); + * g_print("The URI of this frame is '%s'", webkit_web_frame_get_uri (frame)); + * </programlisting></informalexample> + */ + using namespace WebKit; using namespace WebCore; using namespace std; @@ -92,13 +111,24 @@ static void webkit_web_frame_get_property(GObject* object, guint prop_id, GValue } } +// Called from the FrameLoaderClient when it is destroyed. Normally +// the unref in the FrameLoaderClient is destroying this object as +// well but due reference counting a user might have added a reference... +void webkit_web_frame_core_frame_gone(WebKitWebFrame* frame) +{ + ASSERT(WEBKIT_IS_WEB_FRAME(frame)); + frame->priv->coreFrame = 0; +} + static void webkit_web_frame_finalize(GObject* object) { WebKitWebFrame* frame = WEBKIT_WEB_FRAME(object); WebKitWebFramePrivate* priv = frame->priv; - priv->coreFrame->loader()->cancelAndClear(); - priv->coreFrame = 0; + if (priv->coreFrame) { + priv->coreFrame->loader()->cancelAndClear(); + priv->coreFrame = 0; + } g_free(priv->name); g_free(priv->title); @@ -224,25 +254,26 @@ WebKitWebFrame* webkit_web_frame_new(WebKitWebView* webView) WebKitWebViewPrivate* viewPriv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView); priv->webView = webView; - priv->client = new WebKit::FrameLoaderClient(frame); - priv->coreFrame = Frame::create(viewPriv->corePage, 0, priv->client).get(); + WebKit::FrameLoaderClient* client = new WebKit::FrameLoaderClient(frame); + priv->coreFrame = Frame::create(viewPriv->corePage, 0, client).get(); priv->coreFrame->init(); return frame; } -WebKitWebFrame* webkit_web_frame_init_with_web_view(WebKitWebView* webView, HTMLFrameOwnerElement* element) +PassRefPtr<Frame> webkit_web_frame_init_with_web_view(WebKitWebView* webView, HTMLFrameOwnerElement* element) { WebKitWebFrame* frame = WEBKIT_WEB_FRAME(g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL)); WebKitWebFramePrivate* priv = frame->priv; WebKitWebViewPrivate* viewPriv = WEBKIT_WEB_VIEW_GET_PRIVATE(webView); priv->webView = webView; - priv->client = new WebKit::FrameLoaderClient(frame); - priv->coreFrame = Frame::create(viewPriv->corePage, element, priv->client).releaseRef(); - priv->coreFrame->init(); + WebKit::FrameLoaderClient* client = new WebKit::FrameLoaderClient(frame); - return frame; + RefPtr<Frame> coreFrame = Frame::create(viewPriv->corePage, element, client); + priv->coreFrame = coreFrame.get(); + + return coreFrame.release(); } /** @@ -314,7 +345,8 @@ G_CONST_RETURN gchar* webkit_web_frame_get_name(WebKitWebFrame* frame) return priv->name; Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return ""; String string = coreFrame->tree()->name(); priv->name = g_strdup(string.utf8().data()); @@ -334,7 +366,8 @@ WebKitWebFrame* webkit_web_frame_get_parent(WebKitWebFrame* frame) g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return NULL; return kit(coreFrame->tree()->parent()); } @@ -356,7 +389,8 @@ void webkit_web_frame_load_request(WebKitWebFrame* frame, WebKitNetworkRequest* g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request)); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return; // TODO: Use the ResourceRequest carried by WebKitNetworkRequest when it is implemented. String string = String::fromUTF8(webkit_network_request_get_uri(request)); @@ -374,7 +408,8 @@ void webkit_web_frame_stop_loading(WebKitWebFrame* frame) g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return; coreFrame->loader()->stopAllLoaders(); } @@ -390,7 +425,8 @@ void webkit_web_frame_reload(WebKitWebFrame* frame) g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return; coreFrame->loader()->reload(); } @@ -418,7 +454,8 @@ WebKitWebFrame* webkit_web_frame_find_frame(WebKitWebFrame* frame, const gchar* g_return_val_if_fail(name, NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return NULL; String nameString = String::fromUTF8(name); return kit(coreFrame->tree()->find(AtomicString(nameString))); @@ -438,7 +475,8 @@ JSGlobalContextRef webkit_web_frame_get_global_context(WebKitWebFrame* frame) g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return NULL; return toGlobalRef(coreFrame->script()->globalObject()->globalExec()); } @@ -454,7 +492,8 @@ GSList* webkit_web_frame_get_children(WebKitWebFrame* frame) g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return NULL; GSList* children = NULL; for (Frame* child = coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { @@ -478,7 +517,8 @@ gchar* webkit_web_frame_get_inner_text(WebKitWebFrame* frame) g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return g_strdup(""); FrameView* view = coreFrame->view(); @@ -501,7 +541,8 @@ gchar* webkit_web_frame_dump_render_tree(WebKitWebFrame* frame) g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return g_strdup(""); FrameView* view = coreFrame->view(); @@ -555,14 +596,15 @@ void webkit_web_frame_print(WebKitWebFrame* frame) topLevel = NULL; Frame* coreFrame = core(frame); - ASSERT(coreFrame); + if (!coreFrame) + return; PrintContext printContext(coreFrame); GtkPrintOperation* op = gtk_print_operation_new(); - g_signal_connect(G_OBJECT(op), "begin-print", G_CALLBACK(begin_print), &printContext); - g_signal_connect(G_OBJECT(op), "draw-page", G_CALLBACK(draw_page), &printContext); - g_signal_connect(G_OBJECT(op), "end-print", G_CALLBACK(end_print), &printContext); + g_signal_connect(op, "begin-print", G_CALLBACK(begin_print), &printContext); + g_signal_connect(op, "draw-page", G_CALLBACK(draw_page), &printContext); + g_signal_connect(op, "end-print", G_CALLBACK(end_print), &printContext); GError *error = NULL; gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(topLevel), &error); g_object_unref(op); @@ -589,4 +631,35 @@ void webkit_web_frame_print(WebKitWebFrame*) #endif +bool webkit_web_frame_pause_animation(WebKitWebFrame* frame, const gchar* name, double time, const gchar* element) +{ + ASSERT(core(frame)); + Element* coreElement = core(frame)->document()->getElementById(AtomicString(element)); + if (!coreElement || !coreElement->renderer()) + return false; + return core(frame)->animation()->pauseAnimationAtTime(coreElement->renderer(), AtomicString(name), time); +} + +bool webkit_web_frame_pause_transition(WebKitWebFrame* frame, const gchar* name, double time, const gchar* element) +{ + ASSERT(core(frame)); + Element* coreElement = core(frame)->document()->getElementById(AtomicString(element)); + if (!coreElement || !coreElement->renderer()) + return false; + return core(frame)->animation()->pauseTransitionAtTime(coreElement->renderer(), AtomicString(name), time); +} + +unsigned int webkit_web_frame_number_of_active_animations(WebKitWebFrame* frame) +{ + Frame* coreFrame = core(frame); + if (!coreFrame) + return 0; + + AnimationController* controller = coreFrame->animation(); + if (!controller) + return 0; + + return controller->numberOfActiveAnimations(); +} + } |