📄 webkitwebframe.cpp
字号:
WebKitWebFrame* webkit_web_frame_get_parent(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); if (!coreFrame) return NULL; return kit(coreFrame->tree()->parent());}/** * webkit_web_frame_load_uri: * @frame: a #WebKitWebFrame * @uri: an URI string * * Requests loading of the specified URI string. * * Since: 1.1.1 */void webkit_web_frame_load_uri(WebKitWebFrame* frame, const gchar* uri){ g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); g_return_if_fail(uri); Frame* coreFrame = core(frame); if (!coreFrame) return; coreFrame->loader()->load(ResourceRequest(KURL(KURL(), String::fromUTF8(uri))), false);}/** * webkit_web_frame_load_string: * @frame: a #WebKitWebFrame * @content: an URI string * @mime_type: the MIME type, or %NULL * @encoding: the encoding, or %NULL * @base_uri: the base URI for relative locations * * Requests loading of the given @content with the specified @mime_type, * @encoding and @base_uri. * * If @mime_type is %NULL, "text/html" is assumed. * * If @encoding is %NULL, "UTF-8" is assumed. * * Since: 1.1.1 */void webkit_web_frame_load_string(WebKitWebFrame* frame, const gchar* content, const gchar* contentMimeType, const gchar* contentEncoding, const gchar* baseUri){ g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); g_return_if_fail(content); Frame* coreFrame = core(frame); if (!coreFrame) return; KURL url(KURL(), baseUri ? String::fromUTF8(baseUri) : ""); RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create(content, strlen(content)); SubstituteData substituteData(sharedBuffer.release(), contentMimeType ? String(contentMimeType) : "text/html", contentEncoding ? String(contentEncoding) : "UTF-8", blankURL(), url); coreFrame->loader()->load(ResourceRequest(url), substituteData, false);}/** * webkit_web_frame_load_request: * @frame: a #WebKitWebFrame * @request: a #WebKitNetworkRequest * * Connects to a given URI by initiating an asynchronous client request. * * Creates a provisional data source that will transition to a committed data * source once any data has been received. Use webkit_web_frame_stop_loading() to * stop the load. This function is typically invoked on the main frame. */void webkit_web_frame_load_request(WebKitWebFrame* frame, WebKitNetworkRequest* request){ g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); g_return_if_fail(WEBKIT_IS_NETWORK_REQUEST(request)); Frame* coreFrame = core(frame); if (!coreFrame) return; // TODO: Use the ResourceRequest carried by WebKitNetworkRequest when it is implemented. String string = String::fromUTF8(webkit_network_request_get_uri(request)); coreFrame->loader()->load(ResourceRequest(KURL(KURL(), string)), false);}/** * webkit_web_frame_stop_loading: * @frame: a #WebKitWebFrame * * Stops any pending loads on @frame's data source, and those of its children. */void webkit_web_frame_stop_loading(WebKitWebFrame* frame){ g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); Frame* coreFrame = core(frame); if (!coreFrame) return; coreFrame->loader()->stopAllLoaders();}/** * webkit_web_frame_reload: * @frame: a #WebKitWebFrame * * Reloads the initial request. */void webkit_web_frame_reload(WebKitWebFrame* frame){ g_return_if_fail(WEBKIT_IS_WEB_FRAME(frame)); Frame* coreFrame = core(frame); if (!coreFrame) return; coreFrame->loader()->reload();}/** * webkit_web_frame_find_frame: * @frame: a #WebKitWebFrame * @name: the name of the frame to be found * * For pre-defined names, returns @frame if @name is "_self" or "_current", * returns @frame's parent frame if @name is "_parent", and returns the main * frame if @name is "_top". Also returns @frame if it is the main frame and * @name is either "_parent" or "_top". For other names, this function returns * the first frame that matches @name. This function searches @frame and its * descendents first, then @frame's parent and its children moving up the * hierarchy until a match is found. If no match is found in @frame's * hierarchy, this function will search for a matching frame in other main * frame hierarchies. Returns %NULL if no match is found. * * Return value: the found #WebKitWebFrame or %NULL in case none is found */WebKitWebFrame* webkit_web_frame_find_frame(WebKitWebFrame* frame, const gchar* name){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); g_return_val_if_fail(name, NULL); Frame* coreFrame = core(frame); if (!coreFrame) return NULL; String nameString = String::fromUTF8(name); return kit(coreFrame->tree()->find(AtomicString(nameString)));}/** * webkit_web_frame_get_global_context: * @frame: a #WebKitWebFrame * * Gets the global JavaScript execution context. Use this function to bridge * between the WebKit and JavaScriptCore APIs. * * Return value: the global JavaScript context */JSGlobalContextRef webkit_web_frame_get_global_context(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); if (!coreFrame) return NULL; return toGlobalRef(coreFrame->script()->globalObject()->globalExec());}/** * webkit_web_frame_get_children: * @frame: a #WebKitWebFrame * * Return value: child frames of @frame */GSList* webkit_web_frame_get_children(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); if (!coreFrame) return NULL; GSList* children = NULL; for (Frame* child = coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling()) { FrameLoader* loader = child->loader(); WebKit::FrameLoaderClient* client = static_cast<WebKit::FrameLoaderClient*>(loader->client()); if (client) children = g_slist_append(children, client->webFrame()); } return children;}/** * webkit_web_frame_get_inner_text: * @frame: a #WebKitWebFrame * * Return value: inner text of @frame */gchar* webkit_web_frame_get_inner_text(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); if (!coreFrame) return g_strdup(""); FrameView* view = coreFrame->view(); if (view && view->layoutPending()) view->layout(); Element* documentElement = coreFrame->document()->documentElement(); String string = documentElement->innerText(); return g_strdup(string.utf8().data());}/** * webkit_web_frame_dump_render_tree: * @frame: a #WebKitWebFrame * * Return value: Non-recursive render tree dump of @frame */gchar* webkit_web_frame_dump_render_tree(WebKitWebFrame* frame){ g_return_val_if_fail(WEBKIT_IS_WEB_FRAME(frame), NULL); Frame* coreFrame = core(frame); if (!coreFrame) return g_strdup(""); FrameView* view = coreFrame->view(); if (view && view->layoutPending()) view->layout(); String string = externalRepresentation(coreFrame->contentRenderer()); return g_strdup(string.utf8().data());}#if GTK_CHECK_VERSION(2,10,0)static void begin_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data){ PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); float width = gtk_print_context_get_width(context); float height = gtk_print_context_get_height(context); FloatRect printRect = FloatRect(0, 0, width, height); printContext->begin(width); // TODO: Margin adjustments and header/footer support float headerHeight = 0; float footerHeight = 0; float pageHeight; // height of the page adjusted by margins printContext->computePageRects(printRect, headerHeight, footerHeight, 1.0, pageHeight); gtk_print_operation_set_n_pages(op, printContext->pageCount());}static void draw_page(GtkPrintOperation* op, GtkPrintContext* context, gint page_nr, gpointer user_data){ PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); cairo_t* cr = gtk_print_context_get_cairo_context(context); GraphicsContext ctx(cr); float width = gtk_print_context_get_width(context); printContext->spoolPage(ctx, page_nr, width);}static void end_print(GtkPrintOperation* op, GtkPrintContext* context, gpointer user_data){ PrintContext* printContext = reinterpret_cast<PrintContext*>(user_data); printContext->end();}void webkit_web_frame_print(WebKitWebFrame* frame){ GtkWidget* topLevel = gtk_widget_get_toplevel(GTK_WIDGET(webkit_web_frame_get_web_view(frame))); if (!GTK_WIDGET_TOPLEVEL(topLevel)) topLevel = NULL; Frame* coreFrame = core(frame); if (!coreFrame) return; PrintContext printContext(coreFrame); GtkPrintOperation* op = gtk_print_operation_new(); 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); if (error) { GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(topLevel), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", error->message); g_error_free(error); g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), NULL); gtk_widget_show(dialog); }}#elsevoid webkit_web_frame_print(WebKitWebFrame*){ g_warning("Printing support is not available in older versions of GTK+");}#endifbool 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();}gchar* webkit_web_frame_get_response_mime_type(WebKitWebFrame* frame){ Frame* coreFrame = core(frame); DocumentLoader* docLoader = coreFrame->loader()->documentLoader(); String mimeType = docLoader->responseMIMEType(); return g_strdup(mimeType.utf8().data());}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -