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

📄 render_image.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                              (float)(cHeight)/intrinsicHeight() );                resizeCache = pix.xForm( matrix );                scaledrect.setWidth( ( cWidth*scaledrect.width() ) / intrinsicWidth() );                scaledrect.setHeight( ( cHeight*scaledrect.height() ) / intrinsicHeight() );//                   qDebug("resizeCache size: %d/%d", resizeCache.width(), resizeCache.height());//                   qDebug("valid: %d/%d, scaled: %d/%d",//                          i->valid_rect().width(), i->valid_rect().height(),//                          scaledrect.width(), scaledrect.height());                // sometimes scaledrect.width/height are off by one because                // of rounding errors. if the i is fully loaded, we                // make sure that we don't do unnecessary resizes during painting                QSize s(scaledrect.size());                if(i->valid_rect().size() == QSize( intrinsicWidth(), intrinsicHeight() )) // fully loaded                    s = QSize(cWidth, cHeight);                if(kAbs(s.width() - cWidth) < 2) // rounding errors                    s.setWidth(cWidth);                if(resizeCache.size() != s)                    resizeCache.resize(s);                paintInfo.p->drawPixmap( QPoint( _tx + leftBorder + leftPad, _ty + topBorder + topPad),                               resizeCache, scaledrect );            }            else                paintInfo.p->drawPixmap( QPoint( _tx + leftBorder + leftPad, _ty + topBorder + topPad), resizeCache );        }        else        {            // we might be just about switching images            QRect rect(i->valid_rect().isValid() ? i->valid_rect()                       : QRect(0, 0, intrinsicWidth(), intrinsicHeight()));            QPoint offs( _tx + leftBorder + leftPad, _ty + topBorder + topPad);//             qDebug("normal paint rect %d/%d/%d/%d", rect.x(), rect.y(), rect.width(), rect.height());//             rect = rect & QRect( 0 , y - offs.y() - 10, w, 10 + y + h  - offs.y());//             qDebug("normal paint rect after %d/%d/%d/%d", rect.x(), rect.y(), rect.width(), rect.height());//             qDebug("normal paint: offs.y(): %d, y: %d, diff: %d", offs.y(), y, y - offs.y());//             qDebug("");//           p->setClipRect(QRect(x,y,w,h));//             p->drawPixmap( offs.x(), y, pix, rect.x(), rect.y(), rect.width(), rect.height() );             paintInfo.p->drawPixmap(offs, pix, rect);        }    }    if (m_selectionState != SelectionNone) {//    kdDebug(6040) << "_tx " << _tx << " _ty " << _ty << " _x " << _x << " _y " << _y << endl;        // Draw in any case if inside selection. For selection borders, the	// offset will decide whether to draw selection or not	bool draw = true;	if (m_selectionState != SelectionInside) {	    int startPos, endPos;            selectionStartEnd(startPos, endPos);            if(selectionState() == SelectionStart)                endPos = 1;            else if(selectionState() == SelectionEnd)                startPos = 0;	    draw = endPos - startPos > 0;	}	if (draw) {    	    // setting the brush origin is important for compatibility,	    // don't touch it unless you know what you're doing    	    paintInfo.p->setBrushOrigin(_tx, _ty - paintInfo.r.y());            paintInfo.p->fillRect(_tx, _ty, width(), height(),		    QBrush(style()->palette().active().highlight(),		    Qt::Dense4Pattern));	}    }}void RenderImage::layout(){    KHTMLAssert( needsLayout());    KHTMLAssert( minMaxKnown() );    short oldwidth = m_width;    int oldheight = m_height;    // minimum height    m_height = image && image->isErrorImage() ? intrinsicHeight() : 0;    calcWidth();    calcHeight();    // if they are variable width and we calculate a huge height or width, we assume they    // actually wanted the intrinsic width.    if ( m_width > 4096 && !style()->width().isFixed() )	m_width = intrinsicWidth() + paddingLeft() + paddingRight() + borderLeft() + borderRight();    if ( m_height > 2048 && !style()->height().isFixed() )	m_height = intrinsicHeight() + paddingTop() + paddingBottom() + borderTop() + borderBottom();    // limit total size to not run out of memory when doing the xform call.    if ( ( m_width * m_height > 4096*2048 ) &&         ( contentWidth() > intrinsicWidth() || contentHeight() > intrinsicHeight() ) ) {	float scale = sqrt( m_width*m_height / ( 4096.*2048. ) );	m_width = (int) (m_width/scale);	m_height = (int) (m_height/scale);    }    if ( m_width != oldwidth || m_height != oldheight )        resizeCache = QPixmap();    setNeedsLayout(false);}void RenderImage::notifyFinished(CachedObject *finishedObj){    if ( ( image == finishedObj || oimage == finishedObj ) && oimage ) {        oimage->deref( this );        oimage = 0;        repaint();    }    RenderReplaced::notifyFinished(finishedObj);}bool RenderImage::nodeAtPoint(NodeInfo& info, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction, bool inside){    inside |= RenderReplaced::nodeAtPoint(info, _x, _y, _tx, _ty, hitTestAction, inside);    if (inside && element()) {        int tx = _tx + m_x;        int ty = _ty + m_y;        if (isRelPositioned())            relativePositionOffset(tx, ty);        HTMLImageElementImpl* i = element()->id() == ID_IMG ? static_cast<HTMLImageElementImpl*>(element()) : 0;        HTMLMapElementImpl* map;        if (i && i->getDocument()->isHTMLDocument() &&            (map = static_cast<HTMLDocumentImpl*>(i->getDocument())->getMap(i->imageMap()))) {            // we're a client side image map            inside = map->mapMouseEvent(_x - tx, _y - ty, contentWidth(), contentHeight(), info);            info.setInnerNonSharedNode(element());        }    }    return inside;}void RenderImage::updateImage(CachedImage* new_image){    CachedImage* tempimage = oimage;    oimage = image;    image = new_image;    assert( image != oimage );    if ( image != tempimage && image != oimage )        image->ref(this);    if (tempimage && image != tempimage && oimage != tempimage )        tempimage->deref(this);    // if the loading finishes we might get an error and then the image is deleted    if ( image )        berrorPic = image->isErrorImage();    else        berrorPic = true;}void RenderImage::updateFromElement(){    if (element()->id() == ID_INPUT)        alt = static_cast<HTMLInputElementImpl*>(element())->altText();    else if (element()->id() == ID_IMG)        alt = static_cast<HTMLImageElementImpl*>(element())->altText();    DOMString u = element()->id() == ID_OBJECT ?                  element()->getAttribute(ATTR_DATA) : element()->getAttribute(ATTR_SRC);    if (!u.isEmpty() &&        ( !image || image->url() != u ) ) {        CachedImage *new_image = element()->getDocument()->docLoader()->                                 requestImage(khtml::parseURL(u));        if(new_image && new_image != image           // check appears redundant, as we only care about this when we're anonymous           // which can never happen here.           /*&& (!style() || !style()->contentObject())*/            ) {            updateImage( new_image );        }    }}bool RenderImage::complete() const{     // "complete" means that the image has been loaded     // but also that its width/height (contentWidth(),contentHeight()) have been calculated.     return image && image->valid_rect().size() == image->pixmap_size() && !needsLayout();}bool RenderImage::isWidthSpecified() const{    switch (style()->width().type()) {        case Fixed:        case Percent:            return true;        default:            return false;    }    assert(false);    return false;}bool RenderImage::isHeightSpecified() const{    switch (style()->height().type()) {        case Fixed:        case Percent:            return true;        default:            return false;    }    assert(false);    return false;}short RenderImage::calcAspectRatioWidth() const{    if (intrinsicHeight() == 0)        return 0;    if (!image || image->isErrorImage())        return intrinsicWidth(); // Don't bother scaling.    return RenderReplaced::calcReplacedHeight() * intrinsicWidth() / intrinsicHeight();}int RenderImage::calcAspectRatioHeight() const{    if (intrinsicWidth() == 0)        return 0;    if (!image || image->isErrorImage())        return intrinsicHeight(); // Don't bother scaling.    return RenderReplaced::calcReplacedWidth() * intrinsicHeight() / intrinsicWidth();}short RenderImage::calcReplacedWidth() const{    int width;    if (isWidthSpecified())        width = calcReplacedWidthUsing(Width);    else        width = calcAspectRatioWidth();    int minW = calcReplacedWidthUsing(MinWidth);    int maxW = style()->maxWidth().value() == UNDEFINED ? width : calcReplacedWidthUsing(MaxWidth);    if (width > maxW)        width = maxW;    if (width < minW)        width = minW;    return width;}int RenderImage::calcReplacedHeight() const{    int height;    if (isHeightSpecified())        height = calcReplacedHeightUsing(Height);    else        height = calcAspectRatioHeight();    int minH = calcReplacedHeightUsing(MinHeight);    int maxH = style()->maxHeight().value() == UNDEFINED ? height : calcReplacedHeightUsing(MaxHeight);    if (height > maxH)        height = maxH;    if (height < minH)        height = minH;    return height;}#if 0void RenderImage::caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height){    RenderReplaced::caretPos(offset, flags, _x, _y, width, height);#if 0	// doesn't work reliably    height = intrinsicHeight();    width = override && offset == 0 ? intrinsicWidth() : 0;    _x = xPos();    _y = yPos();    if (offset > 0) _x += intrinsicWidth();    RenderObject *cb = containingBlock();    int absx, absy;    if (cb && cb != this && cb->absolutePosition(absx,absy))    {        _x += absx;        _y += absy;    } else {        // we don't know our absolute position, and there is no point returning        // just a relative one        _x = _y = -1;    }#endif}#endif

⌨️ 快捷键说明

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