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

📄 render_canvas.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        }        r = n;        if (r) {            selectionRect = selectionRect.unite(enclosingPositionedRect(r));        }    }    return selectionRect;}void RenderCanvas::setSelection(RenderObject *s, int sp, RenderObject *e, int ep){    // Check we got valid renderobjects. www.msnbc.com and clicking around, to find the case where this happened.    if ( !s || !e )    {        kdWarning(6040) << "RenderCanvas::setSelection() called with start=" << s << " end=" << e << endl;        return;    }    //kdDebug( 6040 ) << "RenderCanvas::setSelection(" << s << "," << sp << "," << e << "," << ep << ")" << endl;#if APPLE_CHANGES    // Cut out early if the selection hasn't changed.    if (m_selectionStart == s && m_selectionStartPos == sp &&        m_selectionEnd == e && m_selectionEndPos == ep){        return;    }    // Record the old selected objects.  Will be used later    // to delta again the selected objects.        RenderObject *oldStart = m_selectionStart;    int oldStartPos = m_selectionStartPos;    RenderObject *oldEnd = m_selectionEnd;    int oldEndPos = m_selectionEndPos;    QPtrList<RenderObject> oldSelectedInside;    QPtrList<RenderObject> newSelectedInside;    RenderObject *os = oldStart;    while (os && os != oldEnd)    {        RenderObject* no;        if (!(no = os->firstChild())) {            if ( !(no = os->nextSibling()) )            {                no = os->parent();                while (no && !no->nextSibling())                    no = no->parent();                if (no)                    no = no->nextSibling();            }        }        if (os->selectionState() == SelectionInside && !oldSelectedInside.containsRef(os))            oldSelectedInside.append(os);                    os = no;    }    clearSelection(false);#else    clearSelection();#endif    while (s->firstChild())        s = s->firstChild();    while (e->lastChild())        e = e->lastChild();    // set selection start    if (m_selectionStart)        m_selectionStart->setIsSelectionBorder(false);    m_selectionStart = s;    if (m_selectionStart)        m_selectionStart->setIsSelectionBorder(true);    m_selectionStartPos = sp;    // set selection end    if (m_selectionEnd)        m_selectionEnd->setIsSelectionBorder(false);    m_selectionEnd = e;    if (m_selectionEnd)        m_selectionEnd->setIsSelectionBorder(true);    m_selectionEndPos = ep;    // update selection status of all objects between m_selectionStart and m_selectionEnd    RenderObject* o = s;        while (o && o!=e)    {        if (o->style()->userSelect() != SELECT_NONE)            o->setSelectionState(SelectionInside);//      kdDebug( 6040 ) << "setting selected " << o << ", " << o->isText() << endl;        RenderObject* no = 0;        if (!(no = o->firstChild()))            if ( !(no = o->nextSibling()) )            {                no = o->parent();                while (no && !no->nextSibling())                    no = no->parent();                if (no)                    no = no->nextSibling();            }#if APPLE_CHANGES        if (o->selectionState() == SelectionInside && !newSelectedInside.containsRef(o))            newSelectedInside.append(o);#endif                    o=no;    }        if (s->style()->userSelect() != SELECT_NONE)        s->setSelectionState(SelectionStart);    if (e->style()->userSelect() != SELECT_NONE)        e->setSelectionState(SelectionEnd);    if (s == e && s->style()->userSelect() != SELECT_NONE)        s->setSelectionState(SelectionBoth);#if APPLE_CHANGES    if (!m_view)        return;    newSelectedInside.remove (s);    newSelectedInside.remove (e);        QRect updateRect;    // Don't use repaint() because it will cause all rects to    // be united (see khtmlview::scheduleRepaint()).  Instead    // just draw damage rects for objects that have a change    // in selection state.        // Are any of the old fully selected objects not in the new selection?    // If so we have to draw them.    // Could be faster by building list of non-intersecting rectangles rather    // than unioning rectangles.    QPtrListIterator<RenderObject> oldIterator(oldSelectedInside);    bool firstRect = true;    for (; oldIterator.current(); ++oldIterator){        if (!newSelectedInside.containsRef(oldIterator.current())){            if (firstRect){                updateRect = enclosingPositionedRect(oldIterator.current());                firstRect = false;            }            else                updateRect = updateRect.unite(enclosingPositionedRect(oldIterator.current()));        }    }    if (!firstRect){        m_view->updateContents( updateRect );    }    // Are any of the new fully selected objects not in the previous selection?    // If so we have to draw them.    // Could be faster by building list of non-intersecting rectangles rather    // than unioning rectangles.    QPtrListIterator<RenderObject> newIterator(newSelectedInside);    firstRect = true;    for (; newIterator.current(); ++newIterator){        if (!oldSelectedInside.containsRef(newIterator.current())){            if (firstRect){                updateRect = enclosingPositionedRect(newIterator.current());                firstRect = false;            }            else                updateRect = updateRect.unite(enclosingPositionedRect(newIterator.current()));        }    }    if (!firstRect) {        m_view->updateContents( updateRect );    }        // Is the new starting object different, or did the position in the starting    // element change?  If so we have to draw it.    if (oldStart != m_selectionStart ||         (oldStart == oldEnd && (oldStartPos != m_selectionStartPos || oldEndPos != m_selectionEndPos)) ||        (oldStart == m_selectionStart && oldStartPos != m_selectionStartPos)){        m_view->updateContents( enclosingPositionedRect(m_selectionStart) );    }    // Draw the old selection start object if it's different than the new selection    // start object.    if (oldStart && oldStart != m_selectionStart){        m_view->updateContents( enclosingPositionedRect(oldStart) );    }        // Does the selection span objects and is the new end object different, or did the position    // in the end element change?  If so we have to draw it.    if (oldStart != oldEnd &&         (oldEnd != m_selectionEnd ||        (oldEnd == m_selectionEnd && oldEndPos != m_selectionEndPos))){        m_view->updateContents( enclosingPositionedRect(m_selectionEnd) );    }        // Draw the old selection end object if it's different than the new selection    // end object.    if (oldEnd && oldEnd != m_selectionEnd){        m_view->updateContents( enclosingPositionedRect(oldEnd) );    }#else    repaint();#endif}#if APPLE_CHANGESvoid RenderCanvas::clearSelection(bool doRepaint)#elsevoid RenderCanvas::clearSelection()#endif{    // update selection status of all objects between m_selectionStart and m_selectionEnd    RenderObject* o = m_selectionStart;    while (o && o!=m_selectionEnd)    {        if (o->selectionState()!=SelectionNone)#if APPLE_CHANGES            if (doRepaint)#endif                o->repaint();        o->setSelectionState(SelectionNone);        RenderObject* no;        if ( !(no = o->firstChild()) )            if ( !(no = o->nextSibling()) )            {                no = o->parent();                while (no && !no->nextSibling())                    no = no->parent();                if (no)                    no = no->nextSibling();            }        o=no;    }    if (m_selectionEnd)    {        m_selectionEnd->setSelectionState(SelectionNone);        // check if selection is collapsed        if (m_selectionStart != m_selectionEnd || m_selectionStartPos != m_selectionEndPos)#if APPLE_CHANGES            if (doRepaint)#endif                m_selectionEnd->repaint();    }    // set selection start & end to 0    if (m_selectionStart)        m_selectionStart->setIsSelectionBorder(false);    m_selectionStart = 0;    m_selectionStartPos = -1;    if (m_selectionEnd)        m_selectionEnd->setIsSelectionBorder(false);    m_selectionEnd = 0;    m_selectionEndPos = -1;}void RenderCanvas::selectionStartEnd(int& spos, int& epos){    spos = m_selectionStartPos;    epos = m_selectionEndPos;}QRect RenderCanvas::viewRect() const{    if (m_printingMode)        return QRect(0,0, m_width, m_height);    else if (m_view)        return QRect(m_view->contentsX(),            m_view->contentsY(),            m_view->visibleWidth(),            m_view->visibleHeight());    else return QRect(0,0,m_rootWidth,m_rootHeight);}int RenderCanvas::docHeight() const{    int h;    if (m_printingMode || !m_view)        h = m_height;    else        h = m_view->visibleHeight();    int lowestPos = lowestPosition();    if( lowestPos > h )        h = lowestPos;    // FIXME: This doesn't do any margin collapsing.    // Instead of this dh computation we should keep the result    // when we call RenderBlock::layout.    int dh = 0;    for (RenderObject *c = firstChild(); c; c = c->nextSibling()) {        dh += c->height() + c->marginTop() + c->marginBottom();    }    if( dh > h )        h = dh;    return h;}int RenderCanvas::docWidth() const{    int w;    if (m_printingMode || !m_view)        w = m_width;    else        w = m_view->visibleWidth();    int rightmostPos = rightmostPosition();    if( rightmostPos > w )        w = rightmostPos;    for (RenderObject *c = firstChild(); c; c = c->nextSibling()) {        int dw = c->width() + c->marginLeft() + c->marginRight();        if( dw > w )            w = dw;    }    return w;}#if APPLE_CHANGES// The idea here is to take into account what object is moving the pagination point, and// thus choose the best place to chop it.void RenderCanvas::setBestTruncatedAt(int y, RenderObject *forRenderer, bool forcedBreak){    // Nobody else can set a page break once we have a forced break.    if (m_forcedPageBreak) return;        // Forced breaks always win over unforced breaks.    if (forcedBreak) {        m_forcedPageBreak = true;        m_bestTruncatedAt = y;        return;    }        // prefer the widest object who tries to move the pagination point    int width = forRenderer->width();    if (width > m_truncatorWidth) {        m_truncatorWidth = width;        m_bestTruncatedAt = y;    }}#endif

⌨️ 快捷键说明

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