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

📄 khtml_part.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  QString url, protocol, datetime;  url = reqUrl.prettyURL();  protocol = reqUrl.protocol();  datetime = KGlobal::locale()->formatDateTime( QDateTime::currentDateTime(),                                                false );  QString doc = QString::fromLatin1( "<html><head><title>" );  doc += i18n( "Error: " );  doc += errorName;  doc += QString::fromLatin1( " - %1</title></head><body><h1>" ).arg( url );  doc += i18n( "The requested operation could not be completed" );  doc += QString::fromLatin1( "</h1><h2>" );  doc += errorName;  doc += QString::fromLatin1( "</h2>" );  if ( techName != QString::null ) {    doc += QString::fromLatin1( "<h2>" );    doc += i18n( "Technical Reason: " );    doc += techName;    doc += QString::fromLatin1( "</h2>" );  }  doc += QString::fromLatin1( "<h3>" );  doc += i18n( "Details of the Request:" );  doc += QString::fromLatin1( "</h3><ul><li>" );  doc += i18n( "URL: %1" ).arg( url );  doc += QString::fromLatin1( "</li><li>" );  if ( protocol != QString::null ) {    // uncomment for 3.1... i18n change    // doc += i18n( "Protocol: %1" ).arg( protocol ).arg( protocol );    doc += QString::fromLatin1( "</li><li>" );  }  doc += i18n( "Date and Time: %1" ).arg( datetime );  doc += QString::fromLatin1( "</li><li>" );  doc += i18n( "Additional Information: %1" ).arg( text );  doc += QString::fromLatin1( "</li></ul><h3>" );  doc += i18n( "Description:" );  doc += QString::fromLatin1( "</h3><p>" );  doc += description;  doc += QString::fromLatin1( "</p>" );  if ( causes.count() ) {    doc += QString::fromLatin1( "<h3>" );    doc += i18n( "Possible Causes:" );    doc += QString::fromLatin1( "</h3><ul><li>" );    doc += causes.join( "</li><li>" );    doc += QString::fromLatin1( "</li></ul>" );  }  if ( solutions.count() ) {    doc += QString::fromLatin1( "<h3>" );    doc += i18n( "Possible Solutions:" );    doc += QString::fromLatin1( "</h3><ul><li>" );    doc += solutions.join( "</li><li>" );    doc += QString::fromLatin1( "</li></ul>" );  }  doc += QString::fromLatin1( "</body></html>" );  write( doc );  end();}#endifvoid KHTMLPart::slotFinished( KIO::Job * job ){  if (job->error())  {    KHTMLPageCache::self()->cancelEntry(d->m_cacheId);    d->m_job = 0L;#if !APPLE_CHANGES    emit canceled( job->errorString() );#endif    // TODO: what else ?    checkCompleted();#if !APPLE_CHANGES    showError( job );#endif    return;  }  //kdDebug( 6050 ) << "slotFinished" << endl;  KHTMLPageCache::self()->endData(d->m_cacheId);  if ( d->m_doc && d->m_doc->docLoader()->expireDate() && m_url.protocol().lower().startsWith("http"))      KIO::http_update_cache(m_url, false, d->m_doc->docLoader()->expireDate());  d->m_workingURL = KURL();  d->m_job = 0L;  if (d->m_doc->parsing())    end(); //will emit completed()}void KHTMLPart::begin( const KURL &url, int xOffset, int yOffset ){#if APPLE_CHANGES  // If we aren't loading an actual URL, then we need to make sure  // that we have at least an empty document. createEmptyDocument will  // do that if we don't have a document already.  if (d->m_workingURL.isEmpty()) {    KWQ(this)->createEmptyDocument();  }#endif  clear();#if APPLE_CHANGES  KWQ(this)->partClearedInBegin();#endif  // Only do this after clearing the part, so that JavaScript can  // clean up properly if it was on for the last load.#if !APPLE_CHANGES  d->m_bJScriptEnabled = KHTMLFactory::defaultHTMLSettings()->isJavaScriptEnabled(url.host());#else  d->m_bJScriptEnabled = d->m_settings->isJavaScriptEnabled(url.host());#endif  d->m_bCleared = false;  d->m_cacheId = 0;  d->m_bComplete = false;  d->m_bLoadEventEmitted = false;  if(url.isValid()) {#if APPLE_CHANGES      KHTMLFactory::vLinks()->insert( KWQ(this)->requestedURLString() );#else      QString urlString = url.url();      KHTMLFactory::vLinks()->insert( urlString );      QString urlString2 = url.prettyURL();      if ( urlString != urlString2 ) {          KHTMLFactory::vLinks()->insert( urlString2 );      }#endif  }  // ###  //stopParser();  KParts::URLArgs args( d->m_extension->urlArgs() );  args.xOffset = xOffset;  args.yOffset = yOffset;  d->m_extension->setURLArgs( args );  KURL ref(url);  ref.setUser(QSTRING_NULL);  ref.setPass(QSTRING_NULL);  ref.setRef(QSTRING_NULL);  d->m_referrer = ref.protocol().startsWith("http") ? ref.url() : "";  m_url = url;  KURL baseurl;#if APPLE_CHANGES  // We don't need KDE chained URI handling or window caption setting  if ( !m_url.isEmpty() )  {    baseurl = m_url;  }#else  if ( !m_url.isEmpty() )  {    KURL::List lst = KURL::split( m_url );    if ( !lst.isEmpty() )      baseurl = *lst.begin();    KURL title( baseurl );    title.setRef( QString::null );    title.setQuery( QString::null );    emit setWindowCaption( title.url() );  }  else    emit setWindowCaption( i18n( "no title", "* Unknown *" ) );#endif  // ### not sure if XHTML documents served as text/xml should use DocumentImpl or HTMLDocumentImpl  if (args.serviceType == "text/xml" || args.serviceType == "application/xml" || args.serviceType == "application/xhtml+xml")    d->m_doc = DOMImplementationImpl::instance()->createDocument( d->m_view );  else    d->m_doc = DOMImplementationImpl::instance()->createHTMLDocument( d->m_view );  d->m_doc->ref();  if (!d->m_doc->attached())    d->m_doc->attach( );  d->m_doc->setURL( m_url.url() );  // We prefer m_baseURL over m_url because m_url changes when we are  // about to load a new page.  d->m_doc->setBaseURL( baseurl.url() );#if APPLE_CHANGES  if (d->m_decoder)    d->m_doc->setDecoder(d->m_decoder);#endif#if !APPLE_CHANGES  d->m_doc->docLoader()->setShowAnimations( KHTMLFactory::defaultHTMLSettings()->showAnimations() );#else  d->m_doc->docLoader()->setShowAnimations( d->m_settings->showAnimations() );#endif#if APPLE_CHANGES  KWQ(this)->updatePolicyBaseURL();#endif#if !APPLE_CHANGES  d->m_paUseStylesheet->setItems(QStringList());  d->m_paUseStylesheet->setEnabled( false );#endif#if !APPLE_CHANGES  setAutoloadImages( KHTMLFactory::defaultHTMLSettings()->autoLoadImages() );  QString userStyleSheet = KHTMLFactory::defaultHTMLSettings()->userStyleSheet();#else  setAutoloadImages( d->m_settings->autoLoadImages() );  QString userStyleSheet = d->m_settings->userStyleSheet();#endif  if ( !userStyleSheet.isEmpty() )    setUserStyleSheet( KURL( userStyleSheet ) );#if APPLE_CHANGES  KWQ(this)->restoreDocumentState();#else  d->m_doc->setRestoreState(args.docState);#endif  d->m_doc->open();  // clear widget  if (d->m_view)    d->m_view->resizeContents( 0, 0 );  connect(d->m_doc,SIGNAL(finishedParsing()),this,SLOT(slotFinishedParsing()));#if !APPLE_CHANGES  emit d->m_extension->enableAction( "print", true );#endif  d->m_doc->setParsing(true);}void KHTMLPart::write( const char *str, int len ){    if ( !d->m_decoder ) {        d->m_decoder = new Decoder;        if (!d->m_encoding.isNull())            d->m_decoder->setEncoding(d->m_encoding.latin1(),                d->m_haveEncoding ? Decoder::UserChosenEncoding : Decoder::EncodingFromHTTPHeader);        else {            // Inherit the default encoding from the parent frame if there is one.            const char *defaultEncoding = (parentPart() && parentPart()->d->m_decoder)                ? parentPart()->d->m_decoder->encoding() : settings()->encoding().latin1();            d->m_decoder->setEncoding(defaultEncoding, Decoder::DefaultEncoding);        }#if APPLE_CHANGES        if (d->m_doc)            d->m_doc->setDecoder(d->m_decoder);#endif    }  if ( len == 0 )    return;  if ( len == -1 )    len = strlen( str );  QString decoded = d->m_decoder->decode( str, len );  if(decoded.isEmpty()) return;  if(d->m_bFirstData) {      // determine the parse mode      d->m_doc->determineParseMode( decoded );      d->m_bFirstData = false;  //kdDebug(6050) << "KHTMLPart::write haveEnc = " << d->m_haveEncoding << endl;      // ### this is still quite hacky, but should work a lot better than the old solution      if(d->m_decoder->visuallyOrdered()) d->m_doc->setVisuallyOrdered();      d->m_doc->recalcStyle( NodeImpl::Force );  }  if (jScript())    jScript()->appendSourceFile(m_url.url(),decoded);  Tokenizer* t = d->m_doc->tokenizer();  // parsing some of the page can result in running a script which  // could possibly destroy the part. To avoid this, ref it temporarily.  ref();  if(t)    t->write( decoded, true );  deref();}void KHTMLPart::write( const QString &str ){  if ( str.isNull() )    return;  if(d->m_bFirstData) {      // determine the parse mode      d->m_doc->setParseMode( DocumentImpl::Strict );      d->m_bFirstData = false;  }  if (jScript())    jScript()->appendSourceFile(m_url.url(),str);  Tokenizer* t = d->m_doc->tokenizer();  if(t)    t->write( str, true );}void KHTMLPart::end(){    // make sure nothing's left in there...    if(d->m_decoder)        write(d->m_decoder->flush());    if (d->m_doc)	d->m_doc->finishParsing();}#if !APPLE_CHANGESvoid KHTMLPart::paint(QPainter *p, const QRect &rc, int yOff, bool *more){    if (!d->m_view) return;    d->m_view->paint(p, rc, yOff, more);}#endifvoid KHTMLPart::stopAnimations(){  if ( d->m_doc )    d->m_doc->docLoader()->setShowAnimations( KHTMLSettings::KAnimationDisabled );  ConstFrameIt it = d->m_frames.begin();  ConstFrameIt end = d->m_frames.end();  for (; it != end; ++it )    if ( !( *it ).m_part.isNull() && ( *it ).m_part->inherits( "KHTMLPart" ) ) {      KParts::ReadOnlyPart* p = ( *it ).m_part;      static_cast<KHTMLPart*>( p )->stopAnimations();    }}void KHTMLPart::gotoAnchor(){    if (m_url.hasRef()) {        QString ref = m_url.encodedHtmlRef();        if (!gotoAnchor(ref)) {            // Can't use htmlRef() here because it doesn't know which encoding to use to decode.            // Decoding here has to match encoding in completeURL, which means it has to use the            // page's encoding rather than UTF-8.            if (d->m_decoder)#if !APPLE_CHANGES                gotoAnchor(KURL::decode_string(ref, d->m_decoder->codec()->mibEnum()));#else                gotoAnchor(KURL::decode_string(ref, d->m_decoder->codec()));#endif        }    }}void KHTMLPart::slotFinishedParsing(){  d->m_doc->setParsing(false);  disconnect(d->m_doc,SIGNAL(finishedParsing()),this,SLOT(slotFinishedParsing()));  if (!d->m_view)    return; // We are probably being destructed.      checkCompleted();  // check if the scrollbars are really needed for the content  // if not, remove them, relayout, and repaint  d->m_view->restoreScrollBar();  gotoAnchor();}void KHTMLPart::slotLoaderRequestStarted( khtml::DocLoader* dl, khtml::CachedObject *obj ){#if !APPLE_CHANGES  if ( obj && obj->type() == khtml::CachedObject::Image && d->m_doc && d->m_doc->docLoader() == dl ) {    KHTMLPart* p = this;    while ( p ) {      KHTMLPart* op = p;      p->d->m_totalObjectCount++;      p = p->parentPart();      if ( !p && d->m_loadedObjects <= d->m_totalObjectCount )        QTimer::singleShot( 200, op, SLOT( slotProgressUpdate() ) );    }  }#endif}void KHTMLPart::slotLoaderRequestDone( khtml::DocLoader* dl, khtml::CachedObject *obj ){#if !APPLE_CHANGES  if ( obj && obj->type() == khtml::CachedObject::Image && d->m_doc && d->m_doc->docLoader() == dl ) {    KHTMLPart* p = this;    while ( p ) {      KHTMLPart* op = p;      p->d->m_loadedObjects++;      p = p->parentPart();      if ( !p && d->m_loadedObjects <= d->m_totalObjectCount && d->m_jobPercent >= 100 )        QTimer::singleShot( 200, op, SLOT( slotProgressUpdate() ) );    }  }#endif  checkCompleted();}#if !APPLE_CHANGESvoid KHTMLPart::slotProgressUpdate(){  int percent;  if ( d->m_loadedObjects < d->m_totalObjectCount )    percent = d->m_jobPercent / 4 + ( d->m_loadedObjects*300 ) / ( 4*d->m_totalObjectCount );  else    percent = d->m_jobPercent;  if ( d->m_loadedObjects < d->m_totalObjectCount && percent >= 75 )    emit d->m_extension->infoMessage( i18n( "%1 of 1 Image loaded", "%1 of %n Images loaded", d->m_totalObjectCount ).arg( d->m_loadedObjects ) );  emit d->m_extension->loadingProgress( percent );}void KHTMLPart::slotJobSpeed( KIO::Job* /*job*/, unsigned long speed ){  emit d->m_extension->speedProgress( speed );}void KHTMLPart::slotJobPercent( KIO::Job* /*job*/, unsigned long percent ){  d->m_jobPercent = percent;  if ( !parentPart() )    QTimer::singleShot( 0, this, SLOT( slotProgressUpdate() ) );}#endifvoid KHTMLPart::checkCompleted(){//   kdDebug( 6050 ) << "KHTMLPart::checkCompleted() parsing: " << d->m_doc->parsing() << endl;//   kdDebug( 6050 ) << "                           complete: " << d->m_bComplete << endl;#if !APPLE_CHANGES  // restore the cursor position

⌨️ 快捷键说明

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