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

📄 webcorebridge.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*
 * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
 * Portions Copyright (c) 2005 Nokia Corporation, 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 "WebCoreBridge.h"

#include "csshelper.h"
#include "dom_node.h"
#include "dom_docimpl.h"
#include "dom_nodeimpl.h"
#include "dom_position.h"
#include "dom2_eventsimpl.h"
#include "dom2_rangeimpl.h"
#include "dom2_viewsimpl.h"
#include "dom2_eventsimpl.h"
#include "htmlediting.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 "render_layer.h"

//#import <JavaScriptCore/jni_jsobject.h>
//#import <JavaScriptCore/object.h>
//#import <JavaScriptCore/runtime_root.h>
//#import <JavaScriptCore/property_map.h>

#include "KWQAssertions.h"
#include "KWQCharsets.h"
#include "KWQClipboard.h"
#include "KWQDOMNode.h"
#include "KWQFileButton.h"
//#include "KWQEditCommand.h"
#include "KWQFont.h"
//#include "KWQFoundationExtras.h"
#include "KWQFrame.h"
#include "KWQKHTMLPart.h"
#include "KWQLoader.h"
//#include "KWQPageState.h"
//#include "KWQRenderTreeDebug.h"
//#include "KWQView.h"
//#include "KWQPrinter.h"
#include "KWQAccObjectCache.h"
#include "KWQGlobalServices.h"

#include "WebCoreImageRenderer.h"
//#include "WebCoreTextRendererFactory.h"
//#include "WebCoreViewFactory.h"
#include "WebCoreSettings.h"

using DOM::AtomicString;
using DOM::DocumentFragmentImpl;
using DOM::DocumentImpl;
using DOM::DocumentTypeImpl;
using DOM::DOMString;
using DOM::Element;
using DOM::ElementImpl;
using DOM::HTMLElementImpl;
using DOM::HTMLFormElementImpl;
using DOM::HTMLGenericFormElementImpl;
using DOM::HTMLImageElementImpl;
using DOM::HTMLInputElementImpl;
using DOM::Node;
using DOM::NodeImpl;
using DOM::Position;
using DOM::Range;

using khtml::Decoder;
using khtml::DeleteSelectionCommand;
using khtml::EditCommand;
using khtml::MoveSelectionCommand;
using khtml::ReplaceSelectionCommand;
using khtml::parseURL;
using khtml::ApplyStyleCommand;
using khtml::RenderCanvas;
using khtml::RenderImage;
using khtml::RenderObject;
using khtml::RenderPart;
using khtml::RenderStyle;
using khtml::RenderWidget;
//using khtml::TypingCommand;

//using KJS::SavedProperties;
//using KJS::SavedBuiltins;

using KParts::URLArgs;

//using KJS::Bindings::RootObject;


static TBool initializedObjectCacheSize = EFalse;
static TBool initializedKJS = EFalse;

EXPORT_C CWebCoreBridge* CWebCoreBridge::NewL(MWebClientBridge& aClient)
    {
    CWebCoreBridge* self = new (ELeave) CWebCoreBridge(aClient);
    CleanupStack::PushL(self);
    self->ConstructL();
    CleanupStack::Pop();
    return self;
    }


CWebCoreBridge::CWebCoreBridge(MWebClientBridge& aClient)
    :iClientBridge(&aClient)
    {
    }

CWebCoreBridge::~CWebCoreBridge()
    {
    RemoveFromFrame();

    if (iRenderPart) {
        iRenderPart->deref(iRenderPartArena);
    }
    iPart->setBridge(0);
    iPart->deref();
    }


void CWebCoreBridge::ConstructL()
    {

    iPart = new KWQKHTMLPart();
    iPart->setBridge(this);

    if (!initializedObjectCacheSize){
        khtml::Cache::setSize(Client().GetObjectCacheSize());
        initializedObjectCacheSize = ETrue;
    }

    if (!initializedKJS) {

// ### NOT IMPLEMENTED scripting
        /*mainThread = pthread_self();

        KJS::Bindings::RootObject::setFindRootObjectForNativeHandleFunction (rootForView);

        KJS::Bindings::Instance::setDidExecuteFunction(updateRenderingForBindings);

        initializedKJS = TRUE;*/
    }

    iShouldCreateRenderers = ETrue;

    }

EXPORT_C
MWebClientBridge& CWebCoreBridge::Client()
    {
    return *iClientBridge;
    }


/*
+ (WebCoreBridge *)bridgeForDOMDocument:(DOMDocument *)document
{
    return ((KWQKHTMLPart *)[document _documentImpl]->part())->bridge();
}*/

EXPORT_C
void CWebCoreBridge::InitializeSettings(const CWebCoreSettings &settings)
{
    iPart->setSettings(settings.Settings());
}


KWQKHTMLPart *CWebCoreBridge::Part() const
{
    return iPart;
}

EXPORT_C
void CWebCoreBridge::SetRenderPart(KHTMLRenderPart *aNewPart)
{
    RenderArena *arena = aNewPart->ref();
    if (iRenderPart) {
        iRenderPart->deref(iRenderPartArena);
    }
    iRenderPart = aNewPart;
    iRenderPartArena = arena;
}

EXPORT_C
KHTMLRenderPart *CWebCoreBridge::RenderPart() const
{
    return iRenderPart;
}

EXPORT_C
void CWebCoreBridge::SetParent(CWebCoreBridge *aParent)
{
    iPart->setParent(aParent->Part());
}

EXPORT_C
void CWebCoreBridge::ProvisionalLoadStarted()
{
    iPart->provisionalLoadStarted();
}

EXPORT_C
void CWebCoreBridge::OpenURL(const TDesC& aURL, TBool aReload,
            const TDesC& aContentType, const TDesC& aRefresh, const TDateTime& aLastModified)
{
// ### NOT IMPLEMENTED page cache
/*
    if (pageCache) {
        KWQPageState *state = [pageCache objectForKey:WebCorePageCacheStateKey];
        iPart->openURLFromPageCache(state);
        [state invalidate];
        return;
    }
*/

    // arguments
    URLArgs args(iPart->browserExtension()->urlArgs());
    args.reload = aReload;
    if (aContentType!=KNullDesC) {
        args.serviceType = QString::FromDes(aContentType);
    }
    iPart->browserExtension()->setURLArgs(args);

    // opening the URL
    if (iPart->didOpenURL(aURL)) {
        // things we have to set up after calling didOpenURL
        if (aRefresh!=KNullDesC) {
            iPart->addMetaData("http-refresh", QString::FromDes(aRefresh));
        }
// ### NOT IMPLEMENTED url metadata "modified"
/*
        if (lastModified) {
            NSString *modifiedString = [lastModified descriptionWithCalendarFormat:@"%a %b %d %Y %H:%M:%S" timeZone:nil locale:nil];
            iPart->addMetaData("modified", QString::fromNSString(modifiedString));
        }
*/
    }
}

EXPORT_C
void CWebCoreBridge::CreateDocumentWithEncoding(const TDesC& aEncoding, TBool aUserChosen)
{
    iPart->setEncoding(QString::FromDes(aEncoding), aUserChosen);
    Client().DocumentStarted();
}

EXPORT_C
void CWebCoreBridge::AddData(const TDesC8& aData)
{
    DocumentImpl *doc = iPart->xmlDocImpl();

    // Document may be nil 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());
        iPart->addData((const char *)aData.Ptr(), aData.Length());
    }
}

EXPORT_C
void CWebCoreBridge::CloseURL()
{
    iPart->closeURL();
}

EXPORT_C
void CWebCoreBridge::DidNotOpenURL(const TDesC& aURL)
{
    iPart->didNotOpenURL(KURL(aURL).url());

/*
// We might have made a page cache item, but now we're bailing out due to an error before we ever
    // transitioned to the new page (before WebFrameState==commit).  The goal here is to restore any state
    // so that the existing view (that wenever got far enough to replace) can continue being used.
    DocumentImpl *doc = _part->xmlDocImpl();
    if (doc) {
        doc->setInPageCache(NO);
    }
    KWQPageState *state = [pageCache objectForKey:WebCorePageCacheStateKey];
    [state invalidate];    */
}


EXPORT_C
void CWebCoreBridge::SaveDocumentState()
{
// ### NOT IMPLEMENTED document state save/restore
/*
    DocumentImpl *doc = iPart->xmlDocImpl();
    if (doc != 0){
        QStringList list = doc->docState();
        NSMutableArray *documentState = [[[NSMutableArray alloc] init] autorelease];

        for (uint i = 0; i < list.count(); i++){
            QString s = list[i];
            [documentState addObject: [NSString stringWithCharacters: (const unichar *)s.unicode() length: s.length()]];
        }
        [self saveDocumentState: documentState];
    }
*/
}

EXPORT_C
void CWebCoreBridge::RestoreDocumentState()
{
// ### NOT IMPLEMENTED document state save/restore
/*
    DocumentImpl *doc = iPart->xmlDocImpl();

    if (doc != 0){
        NSArray *documentState = [self documentState];

        QStringList s;
        for (uint i = 0; i < [documentState count]; i++){
            NSString *string = [documentState objectAtIndex: i];
            s.append(QString::fromNSString(string));
        }

        doc->setRestoreState(s);
    }
*/
}

EXPORT_C
void CWebCoreBridge::ScrollToAnchorWithURL(const TDesC& aURL)
{
    iPart->scrollToAnchor(KURL(aURL).url().latin1());
}


/*EXPORT_C
TBool CWebCoreBridge::SaveDocumentToPageCache()
{
// ### NOT IMPLEMENTED page cache

    DocumentImpl *doc = iPart->xmlDocImpl();
    if (!doc) {
        return NO;
    }

    if (!doc->view()) {
        return NO;
    }
    iPart->clearTimers();

    SavedProperties *windowProperties = new SavedProperties;
    iPart->saveWindowProperties(windowProperties);

    SavedProperties *locationProperties = new SavedProperties;
    iPart->saveLocationProperties(locationProperties);

    SavedBuiltins *interpreterBuiltins = new SavedBuiltins;
    iPart->saveInterpreterBuiltins(*interpreterBuiltins);

    KWQPageState *pageState = [[[KWQPageState alloc] initWithDocument:doc
                                                                  URL:iPart->m_url
                                                     windowProperties:windowProperties
                                                   locationProperties:locationProperties
                                  interpreterBuiltins:interpreterBuiltins] autorelease];
    [pageState setPausedActions: iPart->pauseActions((const void *)pageState)];

    return [self saveDocumentToPageCache:pageState];

    return EFalse;
}*/

EXPORT_C
TBool CWebCoreBridge::CanCachePage() const
{
    return iPart->canCachePage();
}

EXPORT_C
void CWebCoreBridge::End()
{
    iPart->end();
}

EXPORT_C
void CWebCoreBridge::CreateKHTMLView(MWebCoreScrollView& aView, TInt aMarginWidth, TInt aMarginHeight)
{
    // If we own the view, delete the old one - otherwise the render iPart will take care of deleting the view.

// NOT IMPLEMENTED views

    RemoveFromFrame();

    KHTMLView *kview = new KHTMLView(iPart, 0);
    iPart->setView(kview);
    kview->deref();

    kview->setView(&aView);

⌨️ 快捷键说明

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