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

📄 webcorebridge.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (aMarginWidth >= 0)
        kview->setMarginWidth(aMarginWidth);
    if (aMarginHeight >= 0)
        kview->setMarginHeight(aMarginHeight);

}

EXPORT_C
void CWebCoreBridge::ScrollToAnchor(const TDesC& aUrl)
{
	KURL url( aUrl );
    iPart->scrollToAnchor(url);
}


// ### NOT IMPLEMENTED editing
/*
- (BOOL)isSelectionEditable
{
    // EDIT FIXME: This needs to consider the entire selected range
    NodeImpl *startNode = iPart->selection().start().node();
    return startNode ? startNode->isContentEditable() : NO;
}
*/

/*EXPORT_C
TBool CWebCoreBridge::HaveSelection() const
{
    return iPart->selection().state() == Selection::RANGE;
}*/

// ### NOT IMPLEMENTED dom interface
/*
- (NSString *)_documentTypeString
{
    NSString *documentTypeString = nil;
    DOM::DocumentImpl *doc = iPart->xmlDocImpl();
    if (doc) {
        DocumentTypeImpl *doctype = doc->doctype();
        if (doctype) {
            documentTypeString = doctype->toString().string().getNSString();
        }
    }
    return documentTypeString;
}

- (NSString *)_stringWithDocumentTypeStringAndMarkupString:(NSString *)markupString
{
    NSString *documentTypeString = [self _documentTypeString];
    if (documentTypeString && markupString) {
        return [NSString stringWithFormat:@"%@%@", documentTypeString, markupString];
    } else if (documentTypeString) {
        return documentTypeString;
    } else if (markupString) {
        return markupString;
    } else {
        return @"";
    }
}

- (NSArray *)nodesFromList:(QPtrList<NodeImpl> *)nodeList
{
    NSMutableArray *nodes = [NSMutableArray array];
    unsigned int count = nodeList->count();
    for (unsigned int i = 0; i < count; i++) {
        [nodes addObject:[DOMNode _nodeWithImpl:nodeList->at(i)]];
    }
    return nodes;
}

- (NSString *)markupStringFromNode:(DOMNode *)node nodes:(NSArray **)nodes
{
    QPtrList<NodeImpl> *nodeList = NULL;
    if (nodes) {
        nodeList = new QPtrList<NodeImpl>;
    }
    NSString *markupString = [node _nodeImpl]->recursive_toHTMLWithOptions(false, NULL, nodeList).getNSString();
    if (nodes) {
        *nodes = [self nodesFromList:nodeList];
        delete nodeList;
    }
    return [self _stringWithDocumentTypeStringAndMarkupString:markupString];
}

- (NSString *)markupStringFromRange:(DOMRange *)range nodes:(NSArray **)nodes
{
    QPtrList<NodeImpl> *nodeList = NULL;
    if (nodes) {
        nodeList = new QPtrList<NodeImpl>;
    }
    NSString *markupString = [range _rangeImpl]->toHTMLWithOptions(nodeList).string().getNSString();
    if (nodes) {
        *nodes = [self nodesFromList:nodeList];
        delete nodeList;
    }
    return [self _stringWithDocumentTypeStringAndMarkupString:markupString];
}
*/

/*EXPORT_C
HBufC* CWebCoreBridge::SelectedString() const
{
    QString text = iPart->selectedText();
    text.replace('\\', iPart->backslashAsCurrencySymbol());

    return text.Des().Alloc();
}*/

// ### NOT IMPLEMENTED dom interface
/*
- (NSString *)stringForRange:(DOMRange *)range
{
    QString text = iPart->text([range _rangeImpl]);
    text.replace('\\', iPart->backslashAsCurrencySymbol());
    return [[text.getNSString() copy] autorelease];
}
*/

/*EXPORT_C
void CWebCoreBridge::SelectAll()
{
    iPart->selectAll();
}

EXPORT_C
void CWebCoreBridge::DeselectAll()
{
    DeselectText();
    DocumentImpl *doc = iPart->xmlDocImpl();
    if (doc) {
        doc->setFocusNode(0);
    }
}

EXPORT_C
void CWebCoreBridge::DeselectText()
{
    iPart->slotClearSelection();
}*/

EXPORT_C
TBool CWebCoreBridge::IsFrameSet() const
{
    return iPart->isFrameSet();
}

EXPORT_C
void CWebCoreBridge::ScalingFactorChanged(TInt aFactor)
{
    if((aFactor == 0) || (!iPart) ||(!iPart->xmlDocImpl())) {
        return;
    }

    if(iPart) {
        iPart->view()->setScalingFactor(aFactor);
    }

    NodeImpl* node = iPart->xmlDocImpl();
    while (node) {
        if (node->renderer()) {
            // Invalidate the current render tree
            node->renderer()->setNeedsLayoutAndMinMaxRecalc();
            RenderStyle* style = node->renderer()->style();
            if (style) {
                RenderStyle* newstyle = new (node->renderer()->renderArena()) RenderStyle(*style);
                newstyle->htmlFont().update(iPart->xmlDocImpl()->paintDeviceMetrics());
                node->renderer()->setStyle(newstyle);
            }
        }
		node = node->traverseNextNode();
    }
    iPart->xmlDocImpl()->recalcStyle( NodeImpl::Force );
}

// ### NOT IMPLEMENTED printing
/*
- (NSString *)styleSheetForPrinting
{
    if (!iPart->settings()->shouldPrintBackgrounds()) {
        return @"* { background-image: none !important; background-color: white !important;}";
    }
    return nil;
}
*/

EXPORT_C
void CWebCoreBridge::ReapplyStylesForDeviceType( TWebCoreDeviceType aDeviceType )
{
// ### NOT IMPLEMENTED
/*
    iPart->setMediaType(deviceType == WebCoreDeviceScreen ? "screen" : "print");
    DocumentImpl *doc = iPart->xmlDocImpl();
    if (doc) {
        static QPaintDevice screen;
        static QPrinter printer;
        doc->setPaintDevice(deviceType == WebCoreDeviceScreen ? &screen : &printer);
        if (deviceType != WebCoreDeviceScreen) {
            doc->setPrintStyleSheet(QString::fromNSString([self styleSheetForPrinting]));
        }
    }
    return iPart->reparseConfiguration();*/
}

static bool nowPrinting(CWebCoreBridge *self)
{
    DocumentImpl *doc = self->Part()->xmlDocImpl();
    return doc && doc->paintDevice() && doc->paintDevice()->devType() == QInternal::Printer;
}
/*
// Set or unset the printing mode in the view.  We only toy with this if we're printing.
- (void)_setupRootForPrinting:(BOOL)onOrOff
{
    if (nowPrinting(self)) {
        RenderCanvas *root = static_cast<khtml::RenderCanvas *>(iPart->xmlDocImpl()->renderer());
        if (root) {
            root->setPrintingMode(onOrOff);
        }
    }
}
*/

EXPORT_C
void CWebCoreBridge::ForceLayoutAdjustingViewSize(TBool aAdjustSizeFlag)
{
    iPart->forceLayout();
    if (aAdjustSizeFlag) {
        AdjustViewSize();
    }
}

/*
- (void)forceLayoutWithMinimumPageWidth:(float)minPageWidth maximumPageWidth:(float)maxPageWidth adjustingViewSize:(BOOL)flag
{
    [self _setupRootForPrinting:YES];
    iPart->forceLayoutWithPageWidthRange(minPageWidth, maxPageWidth);
    if (flag) {
        [self adjustViewSize];
    }
    [self _setupRootForPrinting:NO];
}
*/

EXPORT_C
void CWebCoreBridge::SendResizeEvent()
{
    iPart->sendResizeEvent();
}

EXPORT_C
void CWebCoreBridge::SendScrollEvent()
{
    iPart->sendScrollEvent();
}

/*
- (void)drawRect:(NSRect)rect withPainter:(QPainter *)p
{
    [self _setupRootForPrinting:YES];
    iPart->paint(p, QRect(rect));
    [self _setupRootForPrinting:NO];
}
*/

/*EXPORT_C
void DrawRect(const TRect& rect)
{
    QPainter painter(nowPrinting(self));
    painter.setUsesInactiveTextBackgroundColor(iPart->usesInactiveTextBackgroundColor());
    painter.setDrawsFocusRing(iPart->showsFirstResponder());
    [self drawRect:rect withPainter:&painter];
}*/


EXPORT_C
void CWebCoreBridge::DrawRect(const TRect& rect, CWebCoreGraphicsContext& aGc)
{
    QPainter painter(nowPrinting(this));
    painter.SetGc(aGc);
    painter.setUsesInactiveTextBackgroundColor(iPart->usesInactiveTextBackgroundColor());
    painter.setDrawsFocusRing(iPart->showsFirstResponder());
    iPart->paint(&painter,QRect(rect));
}
/*
// Used by pagination code called from AppKit when a standalone web page is printed.
- (NSArray*)computePageRectsWithPrintWidthScaleFactor:(float)printWidthScaleFactor printHeight:(float)printHeight
{
    [self _setupRootForPrinting:YES];
    NSMutableArray* pages = [NSMutableArray arrayWithCapacity:5];
    if (printWidthScaleFactor == 0 || printHeight == 0)
        return pages;

    if (!iPart || !iPart->xmlDocImpl() || !iPart->view()) return pages;
    RenderCanvas* root = static_cast<khtml::RenderCanvas *>(iPart->xmlDocImpl()->renderer());
    if (!root) return pages;

    KHTMLView* view = iPart->view();
    NSView* documentView = view->getDocumentView();
    if (!documentView)
        return pages;

    float currPageHeight = printHeight;
    float docHeight = root->layer()->height();
    float docWidth = root->layer()->width();
    float printWidth = docWidth/printWidthScaleFactor;

    // We need to give the part the opportunity to adjust the page height at each step.
    for (float i = 0; i < docHeight; i += currPageHeight) {
        float proposedBottom = kMin(docHeight, i + printHeight);
        iPart->adjustPageHeight(&proposedBottom, i, proposedBottom, i);
        currPageHeight = kMax(1.0f, proposedBottom - i);
        for (float j = 0; j < docWidth; j += printWidth) {
            NSValue* val = [NSValue valueWithRect: NSMakeRect(j, i, printWidth, currPageHeight)];
            [pages addObject: val];
        }
    }
    [self _setupRootForPrinting:NO];

    return pages;
}

// This is to support the case where a webview is embedded in the view that's being printed
- (void)adjustPageHeightNew:(float *)newBottom top:(float)oldTop bottom:(float)oldBottom limit:(float)bottomLimit
{
    [self _setupRootForPrinting:YES];
    iPart->adjustPageHeight(newBottom, oldTop, oldBottom, bottomLimit);
    [self _setupRootForPrinting:NO];
}
*/

// ### NOT IMPLEMENTED dom interface
/*
- (NSObject *)copyDOMNode:(NodeImpl *)node copier:(id <WebCoreDOMTreeCopier>)copier
{
    NSMutableArray *children = [[NSMutableArray alloc] init];
    for (NodeImpl *child = node->firstChild(); child; child = child->nextSibling()) {
        [children addObject:[self copyDOMNode:child copier:copier]];
    }
    NSObject *copiedNode = [copier nodeWithName:node->nodeName().string().getNSString()
                                          value:node->nodeValue().string().getNSString()
                                         source:node->recursive_toHTML(true).getNSString()
                                       children:children];
    [children release];
    return copiedNode;
}

- (NSObject *)copyDOMTree:(id <WebCoreDOMTreeCopier>)copier
{
    DocumentImpl *doc = iPart->xmlDocImpl();
    if (!doc) {
        return nil;
    }
    return [self copyDOMNode:doc copier:copier];
}

- (NSObject *)copyRenderNode:(RenderObject *)node copier:(id <WebCoreRenderTreeCopier>)copier
{
    NSMutableArray *children = [[NSMutableArray alloc] init];
    for (RenderObject *child = node->firstChild(); child; child = child->nextSibling()) {
        [children addObject:[self copyRenderNode:child copier:copier]];
    }

    NSString *name = [[NSString alloc] initWithUTF8String:node->renderName()];

    RenderPart *nodeRenderPart = dynamic_cast<RenderPart *>(node);
    QWidget *widget = nodeRenderPart ? nodeRenderPart->widget() : 0;
    NSView *view = widget ? widget->getView() : nil;

    int nx, ny;
    node->absolutePosition(nx,ny);
    NSObject *copiedNode = [copier nodeWithName:name
                                       position:NSMakePoint(nx,ny)
                                           rect:NSMakeRect(node->xPos(), node->yPos(), node->width(), node->height())
                                           view:view
                                       children:children];

    [name release];
    [children release];

    return copiedNode;
}

- (NSObject *)copyRenderTree:(id <WebCoreRenderTreeCopier>)copier
{
    RenderObject *renderer = iPart->renderer();
    if (!renderer) {
        return nil;
    }
    return [self copyRenderNode:renderer copier:copier];
}
*/

EXPORT_C
void CWebCoreBridge::RemoveFromFrame()
{
    if (iPart->view())
        iPart->view()->setView(0);
    iPart->setView(0);

    // tell image renderers this frame does not exist any more
    MWebCoreScrollView* view = &Client().DocumentView();
    QDictIterator<khtml::CachedObject> it( *khtml::Cache::cache );
    khtml::CachedObject* o = 0;
    while( ( o = it.current() ) != NULL ) {
        if( o->type() == khtml::CachedObject::Image ) {
            const QPixmap& pm = static_cast<khtml::CachedImage *>(o)->pixmap();
            if (pm.image())
                pm.image()->RemoveFromScrollView(view);
        }
        ++it;
    }
}

EXPORT_C
void CWebCoreBridge::InstallInFrame(MWebCoreScrollView& aView)
{
    // If this isn't the main frame, it must have a render iPart set, or it
    // won't ever get installed in the view hierarchy.
    ASSERT(this == Client().MainFrame() || iRenderPart != 0);

    iPart->view()->setView(&aView);
    if (iRenderPart) {
        iRenderPart->setWidget(iPart->view());
        // Now the render part owns the view, so we don't any more.
    }

    iPart->view()->initScrollBars();
    iPart->view()->setScalingFactor(aView.ScalingFactor());
}

⌨️ 快捷键说明

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