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

📄 render_frames.cpp

📁 最新Nokia手机浏览器全套源代码完美版。
💻 CPP
📖 第 1 页 / 共 4 页
字号:

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;
}

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();

            if (!root->minMaxKnown())
                root->calcMinMaxWidth();

            // if no scrolling for this frame, minwidth is set to zero
            if (element()->scrollingMode() != QScrollView::AlwaysOff
                || (body && body->id()==ID_FRAMESET) )
                m_minWidth = QMAX(root->minWidth(),root->docWidth());
            m_maxWidth = QMAX(root->maxWidth(),m_minWidth);
        }
    }

    setMinMaxKnown();

#ifdef DEBUG_LAYOUT
    kdDebug( 6040 ) << "RenderFrame::calcMinMaxWidth(" << this << "): min = " << m_minWidth << " max = " << m_maxWidth << endl;
#endif
}

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

    m_width = QMAX(m_width,m_minWidth);

    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();
            if (root->needsLayout())
                root->layout();
            if (element()->scrollingMode() != QScrollView::AlwaysOff
                || (body && body->id()==ID_FRAMESET) )
                m_height = QMAX(m_height,root->docHeight());
        }
    }

//    kdDebug( 0 ) << "m_height =" << m_height << endl;

    setNeedsLayout(false);

}
#endif

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

RenderPartObject::RenderPartObject( DOM::HTMLElementImpl* element )
    : RenderPart( element )
{
    // init RenderObject attributes
    setInline(true);
    m_hasFallbackContent = false;
}

static bool isURLAllowed(DOM::DocumentImpl *doc, const QString &url)
{
    KURL newURL(doc->completeURL(url));
    newURL.setRef(QString::null);
    
    if (doc->part()->topLevelFrameCount() >= 200)
    return false;

    // We allow one level of self-reference because some sites depend on that.
    // But we don't allow more than one.
    bool foundSelfReference = false;
    for (KHTMLPart *part = doc->part(); part; part = part->parentPart()) {
        KURL partURL = part->url();
        partURL.setRef(QString::null);
        if (partURL == newURL) {
            if (foundSelfReference)
                return false;
            foundSelfReference = true;
        }
    }
    return true;
}

static inline void mapClassIdToServiceType(const QString &classId, QString &serviceType)
{
    // It is ActiveX, but the nsplugin system handling
    // should also work, that's why we don't override the
    // serviceType with application/x-activex-handler
    // but let the KTrader in khtmlpart::createPart() detect
    // the user's preference: launch with activex viewer or
    // with nspluginviewer (Niko)
    if (classId.contains("D27CDB6E-AE6D-11cf-96B8-444553540000"))
        serviceType = "application/x-shockwave-flash";
    else if (classId.contains("CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"))
        serviceType = "audio/x-pn-realaudio-plugin";
    else if (classId.contains("02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"))
        serviceType = "video/quicktime";
    else if (classId.contains("166B1BCA-3F9C-11CF-8075-444553540000"))
        serviceType = "application/x-director";
    else if (classId.contains("6BF52A52-394A-11d3-B153-00C04F79FAA6"))
        serviceType = "application/x-mplayer2";
    else if (!classId.isEmpty())
        // We have a clsid, means this is activex (Niko)
        serviceType = "application/x-activex-handler";
    // TODO: add more plugins here
}

void RenderPartObject::updateWidget()
{
  QString url;
  QString serviceType;
  QStringList paramNames;
  QStringList paramValues;
  KHTMLPart *part = m_view->part();

  setNeedsLayoutAndMinMaxRecalc();

  if (element()->id() == ID_OBJECT) {

      HTMLObjectElementImpl *o = static_cast<HTMLObjectElementImpl *>(element());

      if (!o->isComplete())
        return;
      // Check for a child EMBED tag.
      HTMLEmbedElementImpl *embed = 0;
      for (NodeImpl *child = o->firstChild(); child; ) {
          if (child->id() == ID_EMBED) {
              embed = static_cast<HTMLEmbedElementImpl *>( child );
              break;
          } else if (child->id() == ID_OBJECT) {
              child = child->nextSibling();         // Don't descend into nested OBJECT tags
          } else {
              child = child->traverseNextNode(o);   // Otherwise descend (EMBEDs may be inside COMMENT tags)
          }
      }
      
      // Use the attributes from the EMBED tag instead of the OBJECT tag including WIDTH and HEIGHT.
      HTMLElementImpl *embedOrObject;
      if (embed) {
          embedOrObject = (HTMLElementImpl *)embed;
          DOMString attribute = embedOrObject->getAttribute(ATTR_WIDTH);
          if (!attribute.isEmpty()) {
              o->setAttribute(ATTR_WIDTH, attribute);
          }
          attribute = embedOrObject->getAttribute(ATTR_HEIGHT);
          if (!attribute.isEmpty()) {
              o->setAttribute(ATTR_HEIGHT, attribute);
          }
          url = embed->url;
          serviceType = embed->serviceType;
      } else {
          embedOrObject = (HTMLElementImpl *)o;
      }
      
      // If there was no URL or type defined in EMBED, try the OBJECT tag.
      if (url.isEmpty()) {
          url = o->url;
      }
      if (serviceType.isEmpty()) {
          serviceType = o->serviceType;
      }
      
      QDict<bool> uniqueParamNames(5, false);
      
      // Scan the PARAM children.
      // Get the URL and type from the params if we don't already have them.
      // Get the attributes from the params if there is no EMBED tag.
      NodeImpl *child = o->firstChild();
      while (child && (url.isEmpty() || serviceType.isEmpty() || !embed)) {
          if (child->id() == ID_PARAM) {
              HTMLParamElementImpl *p = static_cast<HTMLParamElementImpl *>( child );
              QString name = p->name().lower();
              if (url.isEmpty() && (name == "src" || name == "movie" || name == "code" || name == "url")) {
                  url = p->value();
              }
              if (serviceType.isEmpty() && name == "type") {
                  serviceType = p->value();
                  int pos = serviceType.find( ";" );
                  if (pos != -1) {
                      serviceType = serviceType.left(pos);
                  }
              }
              if (!embed) {
                  bool dummyValue = true;
                  uniqueParamNames.insert(p->name(), &dummyValue);
                  paramNames.append(p->name());
                  paramValues.append(p->value());
              }
          }
          child = child->nextSibling();
      }
      
      // When OBJECT is used for an applet via Sun's Java plugin, the CODEBASE attribute in the tag
      // points to the Java plugin itself (an ActiveX component) while the actual applet CODEBASE is
      // in a PARAM tag. See <http://java.sun.com/products/plugin/1.2/docs/tags.html>. This means
      // we have to explicitly suppress the tag's CODEBASE attribute if there is none in a PARAM,
      // else our Java plugin will misinterpret it. [4004531]
      if (!embed && serviceType.lower() == "application/x-java-applet") {
          bool dummyValue = true;
          uniqueParamNames.insert("codebase", &dummyValue); // pretend we found it in a PARAM already

⌨️ 快捷键说明

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