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

📄 render_frames.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      xPos += child->width() + element()->border();
      child = child->nextSibling();
    }
    if (xPos>widest)
        widest = xPos;
    yPos += highest + element()->border();
  }

  m_height = yPos - element()->border();
  m_width = QMAX(m_width,widest - element()->border());

  // ensure the rows and columns are filled
  out = false;
  child = firstChild();
  for(r = 0; r < element()->totalRows() && !out; r++)
  {
    int highest = 0;
    int xPos = 0;
    for(c = 0; c < element()->totalCols(); c++)
    {
      if ( !child ) {
        out = true;
        break;
      }
      if (r == element()->totalRows()-1)
        child->setHeight( m_height - child->yPos());
      if (c == element()->totalCols()-1)
        child->setWidth( m_width - child->xPos());

      child = child->nextSibling();
    }
  }


//  kdDebug(6040) << "pf m_height=" << m_height << endl;

#else // NOKIA_CHANGES

  for(r = 0; r < element()->totalRows(); r++)
  {
    int xPos = 0;
    for(c = 0; c < element()->totalCols(); c++)
    {
      child->setPos( xPos, yPos );
#ifdef DEBUG_LAYOUT
      kdDebug(6040) << "child frame at (" << xPos << "/" << yPos << ") size (" << m_gridLayout[1][c] << "/" << m_gridLayout[0][r] << ")" << endl;
#endif
      // has to be resized and itself resize its contents
      if ((m_gridLayout[1][c] != child->width()) || (m_gridLayout[0][r] != child->height())) {
          child->setWidth( m_gridLayout[1][c] );
          child->setHeight( m_gridLayout[0][r] );
          child->setNeedsLayout(true);
          child->layout();
      }

      xPos += m_gridLayout[1][c] + element()->border();
      child = child->nextSibling();

      if ( !child )
        return;

    }

    yPos += m_gridLayout[0][r] + element()->border();
  }

#endif // NOKIA_CHANGES
  // all the remaining frames are hidden to avoid ugly
  // spurious unflowed frames
  while ( child ) {
      child->setWidth( 0 );
      child->setHeight( 0 );
      child->setNeedsLayout(false);

      child = child->nextSibling();
  }
}

bool RenderFrameSet::userResize( MouseEventImpl *evt )
{
    if (needsLayout()) return false;

    bool res = false;
    int _x = evt->clientX();
    int _y = evt->clientY();

    if ( !m_resizing && evt->id() == EventImpl::MOUSEMOVE_EVENT || evt->id() == EventImpl::MOUSEDOWN_EVENT )
    {
#ifdef DEBUG_LAYOUT
        kdDebug( 6031 ) << "mouseEvent:check" << endl;
#endif

        m_hSplit = -1;
        m_vSplit = -1;
        //bool resizePossible = true;

        // check if we're over a horizontal or vertical boundary
        int pos = m_gridLayout[1][0] + xPos();
        for(int c = 1; c < element()->totalCols(); c++)
        {
            if(_x >= pos && _x <= pos+element()->border())
            {
            if(m_vSplitVar && m_vSplitVar[c-1] == true) m_vSplit = c-1;
#ifdef DEBUG_LAYOUT
            kdDebug( 6031 ) << "vsplit!" << endl;
#endif
            res = true;
            break;
            }
            pos += m_gridLayout[1][c] + element()->border();
        }

        pos = m_gridLayout[0][0] + yPos();
        for(int r = 1; r < element()->totalRows(); r++)
        {
            if( _y >= pos && _y <= pos+element()->border())
            {
            if(m_hSplitVar && m_hSplitVar[r-1] == true) m_hSplit = r-1;
#ifdef DEBUG_LAYOUT
            kdDebug( 6031 ) << "hsplitvar = " << m_hSplitVar << endl;
            kdDebug( 6031 ) << "hsplit!" << endl;
#endif
            res = true;
            break;
            }
            pos += m_gridLayout[0][r] + element()->border();
        }
#ifdef DEBUG_LAYOUT
        kdDebug( 6031 ) << m_hSplit << "/" << m_vSplit << endl;
#endif

        QCursor cursor;
        if(m_hSplit != -1 && m_vSplit != -1)
        {
            cursor = KCursor::sizeAllCursor();
        }
        else if( m_vSplit != -1 )
        {
            cursor = KCursor::sizeHorCursor();
        }
        else if( m_hSplit != -1 )
        {
            cursor = KCursor::sizeVerCursor();
        }

        if(evt->id() == EventImpl::MOUSEDOWN_EVENT)
        {
            setResizing(true);
            KApplication::setOverrideCursor(cursor);
            m_vSplitPos = _x;
            m_hSplitPos = _y;
            m_oldpos = -1;
        }
        else
            canvas()->view()->viewport()->setCursor(cursor);

    }

    // ### check the resize is not going out of bounds.
    if(m_resizing && evt->id() == EventImpl::MOUSEUP_EVENT)
    {
        setResizing(false);
        KApplication::restoreOverrideCursor();

        if(m_vSplit != -1 )
        {
        #ifdef DEBUG_LAYOUT
            kdDebug( 6031 ) << "split xpos=" << _x << endl;
#endif
            int delta = m_vSplitPos - _x;
            m_gridDelta[1][m_vSplit] -= delta;
            m_gridDelta[1][m_vSplit+1] += delta;
        }
        if(m_hSplit != -1 )
        {
#ifdef DEBUG_LAYOUT
            kdDebug( 6031 ) << "split ypos=" << _y << endl;
#endif
            int delta = m_hSplitPos - _y;
            m_gridDelta[0][m_hSplit] -= delta;
            m_gridDelta[0][m_hSplit+1] += delta;
        }

        // this just schedules the relayout
        // important, otherwise the moving indicator is not correctly erased
        setNeedsLayout(true);
    }

    else if (m_resizing || evt->id() == EventImpl::MOUSEUP_EVENT) {
#if APPLE_CHANGES
        KHTMLView *v = canvas()->view();
        QPainter paint;

        v->disableFlushDrawing();
        v->lockDrawingFocus();
#else
        QPainter paint( canvas()->view() );
#endif
        paint.setPen( Qt::gray );
        paint.setBrush( Qt::gray );

#if !APPLE_CHANGES
        paint.setRasterOp( Qt::XorROP );
#endif
        QRect r(xPos(), yPos(), width(), height());
        const int rBord = 3;
        int sw = element()->border();
        int p = m_resizing ? (m_vSplit > -1 ? _x : _y) : -1;
        if (m_vSplit > -1) {
            if ( m_oldpos >= 0 )
#if APPLE_CHANGES
                v->updateContents( m_oldpos + sw/2 - rBord , r.y(), 2*rBord, r.height(), true );
#else
                paint.drawRect( m_oldpos + sw/2 - rBord , r.y(),
                                2*rBord, r.height() );
#endif
            if ( p >= 0 ){
#if APPLE_CHANGES
                paint.setPen( Qt::NoPen );
                paint.setBrush( Qt::gray );
                v->setDrawingAlpha((float)0.25);
                paint.drawRect( p  + sw/2 - rBord, r.y(), 2*rBord, r.height() );
                v->setDrawingAlpha((float)1.0);
#else
                paint.drawRect( p  + sw/2 - rBord, r.y(), 2*rBord, r.height() );
#endif
            }
        } else {
            if ( m_oldpos >= 0 )
#if APPLE_CHANGES
                v->updateContents( r.x(), m_oldpos + sw/2 - rBord, r.width(), 2*rBord, true );
#else
                paint.drawRect( r.x(), m_oldpos + sw/2 - rBord,
                                r.width(), 2*rBord );
#endif
            if ( p >= 0 ){
#if APPLE_CHANGES
                paint.setPen( Qt::NoPen );
                paint.setBrush( Qt::gray );
                v->setDrawingAlpha((float)0.25);
                paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
                v->setDrawingAlpha((float)1.0);
#else
                paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
#endif
            }
        }
        m_oldpos = p;

#if APPLE_CHANGES
        v->unlockDrawingFocus();
        v->enableFlushDrawing();
#endif
    }

    return res;
}

void RenderFrameSet::setResizing(bool e)
{
      m_resizing = e;
      for (RenderObject* p = parent(); p; p = p->parent())
          if (p->isFrameSet()) static_cast<RenderFrameSet*>(p)->m_clientresizing = m_resizing;
}

bool RenderFrameSet::canResize( int _x, int _y )
{
    // if we haven't received a layout, then the gridLayout doesn't contain useful data yet
    if (needsLayout() || !m_gridLayout[0] || !m_gridLayout[1] ) return false;

    // check if we're over a horizontal or vertical boundary
    int pos = m_gridLayout[1][0];
    for(int c = 1; c < element()->totalCols(); c++)
        if(_x >= pos && _x <= pos+element()->border())
            return true;

    pos = m_gridLayout[0][0];
    for(int r = 1; r < element()->totalRows(); r++)
        if( _y >= pos && _y <= pos+element()->border())
            return true;

    return false;
}

#ifndef NDEBUG
void RenderFrameSet::dump(QTextStream *stream, QString ind) const
{
  *stream << " totalrows=" << element()->totalRows();
  *stream << " totalcols=" << element()->totalCols();

  uint i;
  for (i = 0; i < (uint)element()->totalRows(); i++)
    *stream << " hSplitvar(" << i << ")=" << m_hSplitVar[i];

  for (i = 0; i < (uint)element()->totalCols(); i++)
    *stream << " vSplitvar(" << i << ")=" << m_vSplitVar[i];

  RenderContainer::dump(stream,ind);
}
#endif

/**************************************************************************************/

RenderPart::RenderPart(DOM::HTMLElementImpl* node)
    : RenderWidget(node)
{
    // init RenderObject attributes
    setInline(false);
}

RenderPart::~RenderPart()
{
    if (m_widget && m_widget->inherits("KHTMLView")) {
    static_cast<KHTMLView *>(m_widget)->deref();
    }
}

void RenderPart::setWidget( QWidget *widget )
{
#ifdef DEBUG_LAYOUT
    kdDebug(6031) << "RenderPart::setWidget()" << endl;
#endif

    if (widget == m_widget) {
    return;
    }

    if (m_widget && m_widget->inherits("KHTMLView")) {
    static_cast<KHTMLView *>(m_widget)->deref();
    }

    if (widget && widget->inherits("KHTMLView")) {
    static_cast<KHTMLView *>(widget)->ref();
    setQWidget( widget, false );
    connect( widget, SIGNAL( cleared() ), this, SLOT( slotViewCleared() ) );
    } else {
    setQWidget( widget );
    }
    setNeedsLayoutAndMinMaxRecalc();

    // make sure the scrollbars are set correctly for restore
    // ### find better fix
    slotViewCleared();
}

bool RenderPart::partLoadingErrorNotify(khtml::ChildFrame *, const KURL& , const QString& )
{
    return false;
}

int RenderPart::intrinsicWidth() const
{
  // KDE may need a non-zero width here, although this will mess up pages (e.g., thinker.org).
#if APPLE_CHANGES
    return 0;
#else
    return 300;
#endif
}

int RenderPart::intrinsicHeight() const
{
  // KDE may need a non-zero height here, although this will mess up pages (e.g., thinker.org).
#if APPLE_CHANGES
    return 0;
#else
    return 200;
#endif
}

void RenderPart::slotViewCleared()
{
}

/***************************************************************************************/

RenderFrame::RenderFrame( DOM::HTMLFrameElementImpl *frame )
    : RenderPart(frame)
{
    setInline( false );
}

void RenderFrame::slotViewCleared()
{
    if (element() && m_widget && m_widget->inherits("QScrollView")) {
#ifdef DEBUG_LAYOUT
        kdDebug(6031) << "frame is a scrollview!" << endl;
#endif
        QScrollView *view = static_cast<QScrollView *>(m_widget);
        if(!element()->frameBorder || !((static_cast<HTMLFrameSetElementImpl *>(element()->parentNode()))->frameBorder()))
            view->setFrameStyle(QFrame::NoFrame);
#if APPLE_CHANGES
        // Qt creates QScrollView w/ a default style of QFrame::StyledPanel | QFrame::Sunken.
        else
            view->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );

#else
        view->setHScrollBarMode(element()->scrolling );
        view->setVScrollBarMode(element()->scrolling );
#endif

        if(view->inherits("KHTMLView")) {
#ifdef DEBUG_LAYOUT
            kdDebug(6031) << "frame is a KHTMLview!" << endl;
#endif
            KHTMLView *htmlView = static_cast<KHTMLView *>(view);
            if(element()->marginWidth != -1) htmlView->setMarginWidth(element()->marginWidth);
            if(element()->marginHeight != -1) htmlView->setMarginHeight(element()->marginHeight);
        }
    }
}

#if NOKIA_CHANGES
void RenderFrame::calcMinMaxWidth()
{
    // expand the frame by setting frame minwidth = content minwidth
#ifdef DEBUG_LAYOUT
    kdDebug( 6040 ) << renderName() << "(RenderFrame)::calcMinMaxWidth() this=" << this << endl;
#endif

    m_minWidth = 0;
    m_maxWidth = 0;

    QScrollView* sview = static_cast<QScrollView *>(m_widget);
    if (sview && sview->inherits("KHTMLView")) {
        KHTMLView* view = static_cast<KHTMLView *>(sview);
        RenderCanvas* root = static_cast<RenderCanvas*>(view->part()?(view->part()->xmlDocImpl()?view->part()->xmlDocImpl()->renderer():0):0);
        if (root) {
            NodeImpl *body = 0;
            if (view->part()->xmlDocImpl()->isHTMLDocument())
                body = static_cast<HTMLDocumentImpl *>(view->part()->xmlDocImpl())->body();

⌨️ 快捷键说明

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