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

📄 webcorebridge.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    [fragment appendChild:node];
    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
}

- (void)replaceSelectionWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString selectReplacement:(BOOL)selectReplacement
{
    DOMDocumentFragment *fragment = [self documentFragmentWithMarkupString:markupString baseURLString:baseURLString];
    [self replaceSelectionWithFragment:fragment selectReplacement:selectReplacement];
}

- (void)replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement
{
    [self replaceSelectionWithFragment:[self documentFragmentWithText:text] selectReplacement:selectReplacement];
}

- (void)insertNewline
{
    if (!iPart || !iPart->xmlDocImpl())
        return;

    TypingCommand::insertNewline(iPart->xmlDocImpl());
    [self ensureCaretVisible];
}

- (void)insertText:(NSString *)text
{
    if (!iPart || !iPart->xmlDocImpl())
        return;

    TypingCommand::insertText(iPart->xmlDocImpl(), text);
    [self ensureCaretVisible];
}

- (void)setSelectionToDragCaret
{
    iPart->setSelection(iPart->dragCaret());
}

- (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment
{
    Position base = iPart->dragCaret().base();
    MoveSelectionCommand cmd(iPart->xmlDocImpl(), [selectionFragment _fragmentImpl], base);
    cmd.apply();
}

- (Position)_positionForPoint:(NSPoint)point
{
    RenderObject *renderer = iPart->renderer();
    if (!renderer) {
        return Position();
    }

    RenderObject::NodeInfo nodeInfo(true, true);
    renderer->layer()->nodeAtPoint(nodeInfo, (int)point.x, (int)point.y);
    NodeImpl *node = nodeInfo.innerNode();
    return node->positionForCoordinates((int)point.x, (int)point.y);
}

- (void)moveDragCaretToPoint:(NSPoint)point
{
    Selection dragCaret([self _positionForPoint:point]);
    iPart->setDragCaret(dragCaret);
}

- (void)removeDragCaret
{
    iPart->setDragCaret(Selection());
}

- (DOMRange *)dragCaretDOMRange
{
    return [DOMRange _rangeWithImpl:iPart->dragCaret().toRange().handle()];
}

- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
{
    Position position = [self _positionForPoint:point];
    return position.isEmpty() ? nil : [DOMRange _rangeWithImpl:Selection(position).toRange().handle()];
}

- (void)deleteSelection
{
    if (!iPart || !iPart->xmlDocImpl())
        return;

    Selection selection(iPart->selection());
    if (selection.state() != Selection::RANGE)
        return;

    DeleteSelectionCommand cmd(iPart->xmlDocImpl());
    cmd.apply();
}

- (void)deleteKeyPressed
{
    if (!iPart || !iPart->xmlDocImpl())
        return;

    TypingCommand::deleteKeyPressed(iPart->xmlDocImpl());
    [self ensureCaretVisible];
}

- (void)applyStyle:(DOMCSSStyleDeclaration *)style
{
    if (!iPart)
        return;
    iPart->applyStyle([style _styleDeclarationImpl]);
}

- (NSFont *)fontForCurrentPosition
{
    return iPart ? iPart->fontForCurrentPosition() : nil;
}

- (void)ensureCaretVisible
{
    if (!iPart)
        return;

    KHTMLView *v = iPart->view();
    if (!v)
        return;

    QRect r(iPart->selection().getRepaintRect());
    v->ensureVisible(r.right(), r.bottom());
    v->ensureVisible(r.left(), r.top());
}

// [info draggingLocation] is in window coords

- (NSDragOperation)dragOperationForDraggingInfo:(id <NSDraggingInfo>)info
{
    NSDragOperation op = NSDragOperationNone;
    if (iPart) {
        KHTMLView *v = iPart->view();
        if (v) {
            // Sending an event can result in the destruction of the view and part.
            v->ref();

            KWQClipboard::AccessPolicy policy = iPart->baseURL().isLocalFile() ? KWQClipboard::Readable : KWQClipboard::TypesReadable;
            KWQClipboard *clipboard = new KWQClipboard(true, [info draggingPasteboard], policy);
            clipboard->ref();
            NSDragOperation srcOp = [info draggingSourceOperationMask];
            clipboard->setSourceOperation(srcOp);

            if (v->updateDragAndDrop(QPoint([info draggingLocation]), clipboard)) {
                // *op unchanged if no source op was set
                if (!clipboard->destinationOperation(&op)) {
                    // The element accepted but they didn't pick an operation, so we pick one for them
                    // (as does WinIE).
                    if (srcOp & NSDragOperationCopy) {
                        op = NSDragOperationCopy;
                    } else if (srcOp & NSDragOperationMove || srcOp & NSDragOperationGeneric) {
                        op = NSDragOperationMove;
                    } else if (srcOp & NSDragOperationLink) {
                        op = NSDragOperationLink;
                    } else {
                        op = NSDragOperationGeneric;
                    }
                } else if (!(op & srcOp)) {
                    // make sure WC picked an op that was offered.  Cocoa doesn't seem to enforce this,
                    // but IE does.
                    op = NSDragOperationNone;
                }
            }
            clipboard->setAccessPolicy(KWQClipboard::Numb);    // invalidate clipboard here for security

            clipboard->deref();
            v->deref();
            return op;
        }
    }
    return op;
}

- (void)dragExitedWithDraggingInfo:(id <NSDraggingInfo>)info
{
    if (iPart) {
        KHTMLView *v = iPart->view();
        if (v) {
            // Sending an event can result in the destruction of the view and part.
            v->ref();

            KWQClipboard::AccessPolicy policy = iPart->baseURL().isLocalFile() ? KWQClipboard::Readable : KWQClipboard::TypesReadable;
            KWQClipboard *clipboard = new KWQClipboard(true, [info draggingPasteboard], policy);
            clipboard->ref();

            v->cancelDragAndDrop(QPoint([info draggingLocation]), clipboard);
            clipboard->setAccessPolicy(KWQClipboard::Numb);    // invalidate clipboard here for security

            clipboard->deref();
            v->deref();
        }
    }
}

- (BOOL)concludeDragForDraggingInfo:(id <NSDraggingInfo>)info
{
    if (iPart) {
        KHTMLView *v = iPart->view();
        if (v) {
            // Sending an event can result in the destruction of the view and part.
            v->ref();

            KWQClipboard *clipboard = new KWQClipboard(true, [info draggingPasteboard], KWQClipboard::Readable);
            clipboard->ref();

            BOOL result = v->performDragAndDrop(QPoint([info draggingLocation]), clipboard);
            clipboard->setAccessPolicy(KWQClipboard::Numb);    // invalidate clipboard here for security

            clipboard->deref();
            v->deref();

            return result;
        }
    }
    return NO;
}

- (void)dragSourceMovedTo:(NSPoint)windowLoc
{
    if (iPart) {
        iPart->dragSourceMovedTo(QPoint(windowLoc));
    }
}

- (void)dragSourceEndedAt:(NSPoint)windowLoc operation:(NSDragOperation)operation
{
    if (iPart) {
        // FIXME must handle operation
        iPart->dragSourceEndedAt(QPoint(windowLoc));
    }
}

- (BOOL)tryDHTMLCut
{
    return iPart->tryCut();
}

- (BOOL)tryDHTMLCopy
{
    return iPart->tryCopy();
}

- (BOOL)tryDHTMLPaste
{
    return iPart->tryPaste();
}

*/


EXPORT_C
TBool CWebCoreBridge::HasPendingLayout() const
{
    if (iPart && iPart->view())
        return iPart->view()->isLayoutPending();
    return EFalse;
}


EXPORT_C
void CWebCoreBridge::SetFastFirstDisplayMode(TBool aFastMode)
    {
    iPart->setFastFirstDisplayMode(aFastMode);
    }

EXPORT_C
TBool CWebCoreBridge::FastFirstDisplayMode() const
    {
    return iPart->fastFirstDisplayMode();
    }

EXPORT_C
TBool CWebCoreBridge::ShowingFastPreview() const
    {
    DocumentImpl *doc = iPart->xmlDocImpl();
    return doc?doc->fastDisplayMode():false;
    }

EXPORT_C
void CWebCoreBridge::FindLinksOfType(const TDesC& aType, RArray<TWebCoreLinkItem>& aResult)
{
    NodeImpl* node = 0;

    if(iPart) {
        QString searchType = QString::FromDes(aType);
        node = iPart->xmlDocImpl();

        while (node && node->id()!=ID_BODY) {
            if (node->isElementNode()) {
                ElementImpl* el = static_cast<ElementImpl*>(node);
                DOMString type = el->getAttribute("type");
                if (el->id()==ID_LINK && (searchType.isEmpty() || type==searchType)) {
                    DOMString href = el->getAttribute("href");
                    DOMString title = el->getAttribute("title");
                    DOMString charset = el->getAttribute("charset");
                    TWebCoreLinkItem item;
                    item.iType.Set((unsigned short*)type.unicode(),type.length());
                    if (!href.isEmpty())
                        item.iHref.Set((unsigned short*)href.unicode(),href.length());
                    if (!title.isEmpty())
                        item.iTitle.Set((unsigned short*)title.unicode(),title.length());
                    if (!charset.isEmpty())
                        item.iCharset.Set((unsigned short*)charset.unicode(),charset.length());
                    aResult.Append(item);
                }
            }
            node = node->traverseNextNode();
        }
    }


}

EXPORT_C
TBool CWebCoreBridge::NavigableNodeUnderCursor(TPoint &aPoint, TWebCoreFocusedElementType &aElType, TRect& aFocusRect) const
{
	TRect nr;

    RenderObject *renderer = iPart->renderer();
    if (!renderer) {
        return EFalse;
    }

    /*
    // fire the mousemove event
    TPointerEvent ev;
    ev.iType = TPointerEvent::EMove;
    ev.iPosition = aCursor.Position();

    KHTMLView *v = iPart->view();
    v->ref();
    QMouseEvent kEvent(QEvent::MouseMove, ev);
    NodeImpl* node = v->ifMouseMoveTo(&kEvent);
    v->deref();

    while (node && !node->renderer()) {
        node = node->parent();
    }
    */
    RenderObject::NodeInfo renderInfo(true, false);
    iPart->renderer()->layer()->hitTest(renderInfo, aPoint.iX, aPoint.iY);

    NodeImpl *node = renderInfo.innerNode();

    /*
    We shouldnt go up the tree and locate the node that has a renderer
    Image maps are represented by areas nodes and they dont have render objects
    */
    /*while (node && !node->renderer()) {
        node = node->parent();
    }*/

    if (node) {
        // get the navigable node at this point
        for (NodeImpl *navNode = node; navNode; navNode = navNode->parentNode()) {
            if (navNode->isElementNode()) {
                if( navNode->isFocusable() )
                    {
				    switch(navNode->id())
				        {
                        case ID_LINK:
                        case ID_A:
                            aElType = EWebCoreElementAnchor;
                            break;
						case ID_INPUT:
						    {
                            HTMLInputElementImpl* inputElement = static_cast<HTMLInputElementImpl *>(navNode);
                            TInt type = inputElement->inputType();
                            switch(inputElement->inputType())
                                   {
                                   case HTMLInputElementImpl::TEXT:
                                   case HTMLInputElementImpl::PASSWORD:
                                       aElType = EWebCoreElementInputBox;
                                       break;
                                   case HTMLInputElementImpl::CHECKBOX:
                                       // if the checkbox is selected
                                       if(inputElement->checked())
                                          {
                                          aElType = EWebCoreElementCheckBoxChecked;
                                          }
                                       else
                                          {
                                          aElType = EWebCoreElementCheckBoxUnChecked;
                                          }
                                       break;
                                   case HTMLInputElementImpl::RADIO:
                                       if(inputElement->checked())
                                          {
                                          aElType = EWebCoreElementRadioButtonSelected;
                                          }
                                          else
                                          {
                                          aElType = EWebCoreElementRadioButtonUnSelected;
                                          }
                                       break;
                                   case HTMLInputElementImpl::SUBMIT:
                                   case HTMLInputElementImpl::BUTTON:
                                       {
                                       aElType = EWebCoreElementButton;
                                       break;
                                       }
                                   case HTMLInputElementImpl::FILE:
                                       {
                                       if(inputElement->value().length())
                                          {
                                          aElType = EWebCoreElementFileSelectionBoxWithContent;
                                          }
                                          else
                                          {
                                          aElType = EWebCoreElementFileSelectionBoxNoContent;
                                          }
                                       }
                                       break;
						           }
                            }
                            break;
						case ID_TEXTAREA:
							{
                            aElType = EWebCoreElementInputBox;
						    break;
						    }
                        case ID_SELECT:
       

⌨️ 快捷键说明

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