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

📄 kwqkhtmlpart.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    setWidget(view);    // Only one form submission is allowed per view of a part.    // Since this part may be getting reused as a result of being    // pulled from the back/forward cache, reset this flag.    _submittedFormURL = KURL();}KHTMLView *KWQKHTMLPart::view() const{    return d->m_view;}void KWQKHTMLPart::setTitle(const DOM::DOMString &title){    QString text = title.string();    text.replace('\\', backslashAsCurrencySymbol());    // FIXME: utf8? -- psalmi    _bridge->setTitle(text.utf8());};void KWQKHTMLPart::setStatusBarText(const QString &status){    QString text = status;    text.replace('\\', backslashAsCurrencySymbol());    // FIXME: utf8? -- psalmi    _bridge->setStatusText(text.utf8());}void KWQKHTMLPart::scheduleClose(){    _bridge->closeWindowSoon();}void KWQKHTMLPart::unfocusWindow(){    _bridge->unfocusWindow();}void KWQKHTMLPart::jumpToSelection(){    const DOM::Selection &s = selection();         // Assumes that selection will only ever be text nodes. This is currently    // true, but will it always be so?    if (!s.start().node()) {	#if KWIQ         RenderText *rt = 0;	if (s.start().node()->renderer() && s.start().node()->renderer()->isText())	    rt = static_cast<RenderText *>(s.start().node()->renderer());#else	        RenderText *rt = dynamic_cast<RenderText *>(s.start().node()->renderer());#endif	        if (rt) {            int x = 0, y = 0;            rt->posOfChar(s.start().offset(), x, y);            // The -50 offset is copied from KHTMLPart::findTextNext, which sets the contents position            // after finding a matched text string.           d->m_view->setContentsPos(x - 50, y - 50);        }/*        I think this would be a better way to do this, to avoid needless horizontal scrolling,        but it is not feasible until selectionRect() returns a tighter rect around the        selected text.  Right now it works at element granularity.         NSView *docView = d->m_view->getDocumentView();        NSRect selRect = NSRect(selectionRect());        NSRect visRect = [docView visibleRect];        if (!NSContainsRect(visRect, selRect)) {            // pad a bit so we overscroll slightly            selRect = NSInsetRect(selRect, -10.0, -10.0);            selRect = NSIntersectionRect(selRect, [docView bounds]);            [docView scrollRectToVisible:selRect];        }*/    }}void KWQKHTMLPart::redirectionTimerStartedOrStopped(){    // Don't report history navigations, just actual redirection.    if (d->m_scheduledRedirection == historyNavigationScheduled) {        return;    }    // FIXME: utf8? -- psalmi    GTime time = 0;    if (d->m_redirectionTimer.isActive()) {	_bridge->reportClientRedirectToURL(d->m_redirectURL.utf8(),					   d->m_delayRedirect,					   //fireDate:[d->m_redirectionTimer.getNSTimer() fireDate],					   time,					   d->m_redirectLockHistory,					   d->m_executingJavaScriptFormAction);    } else {        _bridge->reportClientRedirectCancelled(d->m_cancelWithLoadInProgress);    }}void KWQKHTMLPart::paint(QPainter *p, const QRect &rect){#ifndef NDEBUG    bool fillWithRed;    if (p->device()->devType() == QInternal::Printer)        fillWithRed = false; // Printing, don't fill with red (can't remember why).    else if (!xmlDocImpl() || xmlDocImpl()->ownerElement())        fillWithRed = false; // Subframe, don't fill with red.    else if (view() && view()->isTransparent())        fillWithRed = false; // Transparent, don't fill with red.    else if (_drawSelectionOnly)        fillWithRed = false; // Selections are transparent, don't fill with red.    else if (_elementToDraw != 0)        fillWithRed = false; // Element images are transparent, don't fill with red.    else        fillWithRed = true;    if (fillWithRed) {        p->fillRect(rect.x(), rect.y(), rect.width(), rect.height(), QColor(0xFF, 0, 0));    }#endif    if (renderer()) {        // _elementToDraw is used to draw only one element        RenderObject *eltRenderer = (_elementToDraw != 0) ? _elementToDraw.handle()->renderer() : 0;        renderer()->layer()->paint(p, rect, _drawSelectionOnly, eltRenderer);    } else {        ERROR("called KWQKHTMLPart::paint with nil renderer");    }}void KWQKHTMLPart::adjustPageHeight(float *newBottom, float oldTop, float oldBottom, float bottomLimit){    RenderCanvas *root = static_cast<RenderCanvas *>(xmlDocImpl()->renderer());    if (root) {        // Use a printer device, with painting disabled for the pagination phase        QPainter painter(true);        painter.setPaintingDisabled(true);        root->setTruncatedAt((int)floor(oldBottom));        QRect dirtyRect(0, (int)floor(oldTop),                        root->docWidth(), (int)ceil(oldBottom-oldTop));        root->layer()->paint(&painter, dirtyRect);        *newBottom = root->bestTruncatedAt();        if (*newBottom == 0) {            *newBottom = oldBottom;        }    } else {        *newBottom = oldBottom;    }}RenderObject *KWQKHTMLPart::renderer(){    DocumentImpl *doc = xmlDocImpl();    return doc ? doc->renderer() : 0;}QString KWQKHTMLPart::userAgent() const{    // FIXME: utf8? -- psalmi    return QString(_bridge->userAgentForURL(m_url.url().utf8()));}QString KWQKHTMLPart::mimeTypeForFileName(const QString &fileName) const{    // FIXME: utf8? -- psalmi    return _bridge->MIMETypeForPath(fileName.utf8());}GtkWidget *KWQKHTMLPart::nextKeyViewInFrame(DOM::NodeImpl *node, KWQSelectionDirection direction){    DocumentImpl *doc = xmlDocImpl();    if (!doc) {        return 0;    }    for (;;) {        node = direction == KWQSelectingNext            ? doc->nextFocusNode(node) : doc->previousFocusNode(node);        if (!node) {            return 0;        }        RenderWidget *renderWidget = 0;	if (node->renderer() && node->renderer()->isWidget()) 	    renderWidget = static_cast<RenderWidget *>(node->renderer());        if (renderWidget) {            QWidget *widget = renderWidget->widget();            KHTMLView *childFrameWidget = 0;	    if (widget && QOBJECT_IS_A(widget, KHTMLView)) childFrameWidget = static_cast<KHTMLView*>(widget);            if (childFrameWidget) {                GtkWidget *view = KWQ(childFrameWidget->part())->nextKeyViewInFrame(0, direction);                if (view) {                    return view;                }            } else if (widget) {                GtkWidget *view = widget->getGtkWidget();                // AppKit won't be able to handle scrolling and making us the first responder                // well unless we are actually installed in the correct place. KHTML only does                // that for visible widgets, so we need to do it explicitly here.                int x, y;                if (view && renderWidget->absolutePosition(x, y)) {                    renderWidget->view()->addChild(widget, x, y);                    return view;                }            }        }        else {            doc->setFocusNode(node);            if (view()) {                view()->ensureRectVisibleCentered(node->getRect());            }            _bridge->makeFirstResponder(_bridge->documentView());            return _bridge->documentView();        }    }}GtkWidget *KWQKHTMLPart::nextKeyViewInFrameHierarchy(DOM::NodeImpl *node, KWQSelectionDirection direction){    GtkWidget *next = nextKeyViewInFrame(node, direction);    if (next) {        return next;    }    // remove focus from currently focused node    DocumentImpl *doc = xmlDocImpl();    if (doc) {        doc->setFocusNode(0);    }        KWQKHTMLPart *parent = KWQ(parentPart());    if (parent) {        next = parent->nextKeyView(parent->childFrame(this)->m_frame->element(), direction);        if (next) {            return next;        }    }        return 0;}GtkWidget *KWQKHTMLPart::nextKeyView(DOM::NodeImpl *node, KWQSelectionDirection direction){    GtkWidget * next = nextKeyViewInFrameHierarchy(node, direction);    if (next) {        return next;    }    // Look at views from the top level part up, looking for a next key view that we can use.    next = direction == KWQSelectingNext        ? _bridge->nextKeyViewOutsideWebFrameViews()        : _bridge->previousKeyViewOutsideWebFrameViews();    if (next) {        return next;    }    // If all else fails, make a loop by starting from 0.    return nextKeyViewInFrameHierarchy(0, direction);}GtkWidget *KWQKHTMLPart::nextKeyViewForWidget(QWidget *startingWidget, KWQSelectionDirection direction){    // Use the event filter object to figure out which RenderWidget owns this QWidget and get to the DOM.    // Then get the next key view in the order determined by the DOM.    DOM::NodeImpl *node = nodeForWidget(startingWidget);    ASSERT(node);    return partForNode(node)->nextKeyView(node, direction);}#if 0bool KWQKHTMLPart::currentEventIsMouseDownInWidget(QWidget *candidate){    KWQ_BLOCK_EXCEPTIONS;    switch ([[NSApp currentEvent] type]) {        case NSLeftMouseDown:        case NSRightMouseDown:        case NSOtherMouseDown:            break;        default:            return NO;    }    KWQ_UNBLOCK_EXCEPTIONS;        NodeImpl *node = nodeForWidget(candidate);    ASSERT(node);    return partForNode(node)->nodeUnderMouse() == node;}#endifbool KWQKHTMLPart::currentEventIsKeyboardOptionTab(){#if 0    KWQ_BLOCK_EXCEPTIONS;    NSEvent *evt = [NSApp currentEvent];    if ([evt type] != NSKeyDown) {        return NO;    }    if (([evt modifierFlags] & NSAlternateKeyMask) == 0) {        return NO;    }        NSString *chars = [evt charactersIgnoringModifiers];    if ([chars length] != 1)        return NO;        const unichar tabKey = 0x0009;    const unichar shiftTabKey = 0x0019;    unichar c = [chars characterAtIndex:0];    if (c != tabKey && c != shiftTabKey)        return NO;        KWQ_UNBLOCK_EXCEPTIONS;    return YES;#endif    return true;}#if 0bool KWQKHTMLPart::handleKeyboardOptionTabInView(NSView *view){    if (KWQKHTMLPart::currentEventIsKeyboardOptionTab()) {        if (([[NSApp currentEvent] modifierFlags] & NSShiftKeyMask) != 0) {            [[view window] selectKeyViewPrecedingView:view];        } else {            [[view window] selectKeyViewFollowingView:view];        }        return YES;    }        return NO;}#endifbool KWQKHTMLPart::tabsToLinks() const{    if (_bridge->keyboardUIMode() & WebCoreKeyboardAccessTabsToLinks)        return !KWQKHTMLPart::currentEventIsKeyboardOptionTab();    else        return KWQKHTMLPart::currentEventIsKeyboardOptionTab();}bool KWQKHTMLPart::tabsToAllControls() const{    return _bridge->keyboardUIMode() & WebCoreKeyboardAccessFull;}#if 0KJS::Bindings::RootObject *KWQKHTMLPart::bindingRootObject(){    if (!_bindingRoot) {        _bindingRoot = new KJS::Bindings::RootObject(0);    // The root gets deleted by JavaScriptCore.        KJS::ObjectImp *win = static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(this));        _bindingRoot->setRootObjectImp (win);        _bindingRoot->setInterpreter (KJSProxy::proxy(this)->interpreter());        addPluginRootObject (_bindingRoot);    }    return _bindingRoot;}WebScriptObject *KWQKHTMLPart::windowScriptObject(){    if (!_windowScriptObject) {        KJS::ObjectImp *win = static_cast<KJS::ObjectImp *>(KJS::Window::retrieveWindow(this));        _windowScriptObject = KWQRetainNSRelease([[WebScriptObject alloc] _initWithObjectImp:win root:bindingRootObject()]);    }    return _windowScriptObject;}#endifvoid KWQKHTMLPart::partClearedInBegin(){    _bridge->windowObjectCleared();}QMap<int, ScheduledAction*> *KWQKHTMLPart::pauseActions(const void *key){    if (d->m_doc && d->m_jscript) {        Window *w = Window::retrieveWindow(this);        if (w && w->hasTimeouts()) {            return w->pauseTimeouts(key);        }    }    return 0;}void KWQKHTMLPart::resumeActions(QMap<int, ScheduledAction*> *actions, const void *key){    if (d->m_doc && d->m_jscript && d->m_bJScriptEnabled) {        Window *w = Window::retrieveWindow(this);        if (w) {            w->resumeTimeouts(actions, key);        }    }}bool KWQKHTMLPart::canCachePage(){    // Only save page state if:    // 1.  We're not a frame or frameset.    // 2.  The page has no unload handler.    // 3.  The page has no password fields.    // 4.  The URL for the page is not https.    // 5.  The page has no applets.    if (d->m_frames.count() ||        parentPart() ||        m_url.protocol().startsWith("https") || 

⌨️ 快捷键说明

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