⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcorebridge.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include <gtk/gtk.h>#if 0 // no jni support#include <JavaScriptCore/jni_jsobject.h>#endif#include <JavaScriptCore/object.h>#include <JavaScriptCore/property_map.h>#include <JavaScriptCore/interpreter.h> // SavedBuiltins#include "WebCoreBridge.h"#include "GLibHelpers.h"#include "csshelper.h"#include "dom_node.h"#include "dom_docimpl.h"#include "dom_nodeimpl.h"#include "html_documentimpl.h"#include "html_formimpl.h"#include "html_imageimpl.h"#include "htmlattrs.h"#include "htmltags.h"#include "khtml_part.h"#include "khtmlview.h"#include "kjs_proxy.h"#include "kjs_window.h"#include "loader.h"#include "render_frames.h"#include "render_image.h"#include "render_object.h"#include "render_canvas.h"#include "render_style.h"#include "render_replaced.h"#include "KWQLogging.h"#include "KWQCharsets.h"#include "KWQDOMNode.h"#include "KWQFont.h"#include "KWQFrame.h"#include "KWQLoader.h"#include "KWQPageState.h"#include "KWQRenderTreeDebug.h"//#include "KWQView.h"#include "KWQPrinter.h"//#include "WebCoreDOMPrivate.h"//#include "WebCoreImageRenderer.h"//#include "WebCoreTextRendererFactory.h"#include "WebCoreViewFactory.h"#include "WebCoreSettings.h"//#include <AppKit/NSView.h>#include "KWQKJob.h"#include "KWQKHTMLSettings.h"#include "KWQKHTMLFactory.h"#include "WebCoreHistory.h"#include "WebCoreUnicode.h"using DOM::DocumentImpl;using DOM::Node;using DOM::NodeImpl;using khtml::Decoder;using khtml::parseURL;using khtml::RenderImage;using khtml::RenderObject;using khtml::RenderPart;using khtml::RenderStyle;using khtml::RenderCanvas;using KJS::SavedProperties;using KJS::SavedBuiltins;using KParts::URLArgs;#if 0 // KWIQ: no jni supportusing KJS::Bindings::RootObject;#endifgchar* WebCoreElementFrameKey = "WebElementFrame";gchar* WebCoreElementImageAltStringKey = "WebElementImageAltString";gchar* WebCoreElementImageKey = "WebElementImage";gchar* WebCoreElementImageRectKey = "WebElementImageRect";gchar* WebCoreElementImageURLKey = "WebElementImageURL";gchar* WebCoreElementIsSelectedKey = "WebElementIsSelected";gchar* WebCoreElementLinkURLKey = "webelementlinkurl";gchar* WebCoreElementLinkTargetFrameKey = "WebElementTargetFrame";gchar* WebCoreElementLinkLabelKey = "WebElementLinkLabel";gchar* WebCoreElementLinkTitleKey = "WebElementLinkTitle";gchar* WebCoreElementNameKey = "WebElementName";gchar* WebCoreElementTitleKey = "WebCoreElementTitle"; // not in WebKit API for now, could be in API some daygchar * KWIQPageCacheStateKey = "KWIQPageCacheState";#if 0static RootObject *rootForGtkWidget(void *v){    GtkWidget *widget = GTK_WIDGET (v);    WebCoreBridge *aBridge = WebCoreViewFactory::sharedFactory().bridgeForGtkWidget(widget);    if (aBridge) {        KWQKHTMLPart *part = aBridge->part();        RootObject *root = new RootObject(v);    // The root gets deleted by JavaScriptCore.                root->setRootObjectImp (static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(part)));        root->setInterpreter (KJSProxy::proxy(part)->interpreter());        part->addPluginRootObject (root);                    return root;    }    return 0;}#endifstatic bool initializedObjectCacheSize = false;static bool initializedKJS = false;WebCoreBridge::WebCoreBridge()    :_part(0)    ,_renderPart(0)    ,_renderPartArena(0)        ,_drawSelectionOnly(false)    ,_url(0)    ,_name(0)    ,_referrer(0)    ,_renderTree(0)    ,_jsEvalString(0)    ,_encoding(0){    _part = new KWQKHTMLPart;    _part->setBridge(this);    // getObjectCacheSize cannot be called from constructor         if (!initializedKJS) {#if 0 //no jni support        KJS::Bindings::RootObject::setFindRootObjectForNativeHandleFunction (rootForGtkWidget);#endif         initializedKJS = true;    }        _shouldCreateRenderers = true;}void WebCoreBridge::init(){    if (!initializedObjectCacheSize) {	// getObjectCacheSize cannot be called from constructor, call it here (a bit dangerous)        khtml::Cache::setSize(getObjectCacheSize());        initializedObjectCacheSize = true;    }}void WebCoreBridge::initializeSettings(WebCoreSettings *settings){    _part->setSettings(settings->settings());}WebCoreBridge::~WebCoreBridge(){    LOG(KwiqLog, " this:%x, part():%x framename %s", this, part(), name() );    removeFromFrame();        if (_renderPart) {        _renderPart->deref(_renderPartArena);    }    // free temporary strings    freeString(_url);    freeString(_name);    freeString(_referrer);    freeString(_renderTree);    freeString(_jsEvalString);    freeString(_encoding);        _part->setBridge(0);    _part->deref();}KWQKHTMLPart* WebCoreBridge::part(){    return _part;}void WebCoreBridge::setRenderPart(KHTMLRenderPart *newPart){    RenderArena *arena = newPart->ref();    if (_renderPart) {        _renderPart->deref(_renderPartArena);    }    _renderPart = newPart;    _renderPartArena = arena;}KHTMLRenderPart * WebCoreBridge::renderPart(){    return _renderPart;}void WebCoreBridge::setParent(WebCoreBridge *parent){    _part->setParent(parent->part());}void WebCoreBridge::provisionalLoadStarted(){    _part->provisionalLoadStarted();}void WebCoreBridge::openURL(const gchar *_URL, 			 bool reload, 			 const gchar *_contentType,			 const gchar *refresh, 			 GTime _lastModified, 			 KWIQPageCache* pageCache){    KURL URL(_URL);    QString contentType(_contentType);    QDateTime lastModified(_lastModified);    if (pageCache) {	KWQPageState* state = static_cast<KWQPageState*>(pageCache->state());	_part->openURLFromPageCache(state);        state->invalidate();        return;    }          // arguments    URLArgs args(_part->browserExtension()->urlArgs());    args.reload = reload;    if (!contentType.isEmpty()) {        args.serviceType = QString::fromUtf8(_contentType);    }    _part->browserExtension()->setURLArgs(args);    // opening the URL    if (_part->didOpenURL(URL)) {        // things we have to set up after calling didOpenURL        if (refresh) {            _part->addMetaData("http-refresh", QString::fromUtf8(refresh));        }	if (lastModified.isValid()) {	    QString modifiedString = lastModified.toString("%a %b %d %Y %H:%M:%S");	    _part->addMetaData("modified", modifiedString);	}    }}void WebCoreBridge::setEncoding(const gchar *encoding, bool userChosen){    _part->setEncoding(QString::fromUtf8(encoding), userChosen);}void WebCoreBridge::addData(const char* data, int length){    DocumentImpl *doc = _part->xmlDocImpl();        // Document may be NULL if the part is about to redirect    // as a result of JS executing during load, i.e. one frame    // changing another's location before the frame's document    // has been created.     if (doc){        doc->setShouldCreateRenderers(shouldCreateRenderers());        _part->addData(data, length);    }}void WebCoreBridge::closeURL(){    _part->closeURL();}void WebCoreBridge::didNotOpenURL(const gchar *URL){    _part->didNotOpenURL(KURL(URL));}void WebCoreBridge::saveDocumentState(){    DocumentImpl *doc = _part->xmlDocImpl();    if (doc != 0){        QStringList list = doc->docState();	GList* documentState = 0;                for (uint i = 0; i < list.count(); i++){            QString s = list[i];            documentState = g_list_append(documentState, g_strdup(s.utf8()));        }        saveDocumentState(documentState); 	GList* iter = documentState;	while (iter) {	    g_free(iter->data);	    iter = g_list_next(iter);	}	g_list_free(documentState);    }}void WebCoreBridge::restoreDocumentState(){    DocumentImpl *doc = _part->xmlDocImpl();        if (doc != 0){        GList *docState = documentState();  	GList *iter = docState;        QStringList s;	while (iter) {	    ASSERT(iter->data);	    gchar *string = static_cast<gchar*>(iter->data);	    s.append(QString::fromUtf8(string));	    iter = g_list_next(iter);        }                    doc->setRestoreState(s);    }}void WebCoreBridge::scrollToAnchorWithURL(const gchar *URL){    _part->scrollToAnchor(QString::fromUtf8(URL));}bool WebCoreBridge::saveDocumentToPageCache(){    DocumentImpl *doc = _part->xmlDocImpl();    if (!doc) {        return false;    }        _part->clearTimers();    SavedProperties *windowProperties = new SavedProperties;    _part->saveWindowProperties(windowProperties);    SavedProperties *locationProperties = new SavedProperties;    _part->saveLocationProperties(locationProperties);    SavedBuiltins *interpreterBuiltins = new SavedBuiltins;    _part->saveInterpreterBuiltins(*interpreterBuiltins);        KWQPageState *pageState = new KWQPageState(doc,					       _part->m_url,					       windowProperties, 					       locationProperties,					       interpreterBuiltins);    pageState->setPausedActions(_part->pauseActions((const void *)pageState));    return saveDocumentToPageCache(pageState);}bool WebCoreBridge::canCachePage(){    return _part->canCachePage();}void WebCoreBridge::end(){    _part->end();}void WebCoreBridge::createKHTMLViewWithGtkWidget(GtkWidget* widget, int marginWidth, int marginHeight){    // If we own the view, delete the old one - otherwise the render _part will take care of deleting the view.    removeFromFrame();    KHTMLView *kview = new KHTMLView(_part, 0);    _part->setView(kview);    kview->deref();        kview->setGtkWidget(widget);    if (marginWidth >= 0)        kview->setMarginWidth(marginWidth);    if (marginHeight >= 0)        kview->setMarginHeight(marginHeight);}void WebCoreBridge::scrollToAnchor(const gchar *a){    _part->gotoAnchor(QString::fromUtf8(a));}#if 0QString WebCoreBridge::selectedString(){    QString text = _part->selectedText();    text.replace('\\', _part->backslashAsCurrencySymbol());    return text;}void WebCoreBridge::selectAll(){    _part->selectAll();}void WebCoreBridge::deselectAll(){    _part->slotClearSelection();}void deselectText(){    _part->slotClearSelection();}#endifbool WebCoreBridge::isFrameSet(){    return _part->isFrameSet();}QString styleSheetForPrinting(KWQKHTMLPart* _part){    if (!_part->settings()->shouldPrintBackgrounds()) {        return QString::fromLatin1("* { background-image: none !important; background-color: white !important;}");    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -