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

📄 dom_docimpl.cpp.orig

📁 将konqueror浏览器移植到ARM9 2410中
💻 ORIG
📖 第 1 页 / 共 3 页
字号:
void DocumentImpl::applyChanges(bool,bool force){    // ### move the following two lines to createSelector????    delete m_styleSelector;    m_styleSelector = 0;    m_styleSelector = new CSSStyleSelector(this);    if(!m_render) return;    recalcStyle();    // a style change can influence the children, so we just go    // through them and trigger an appplyChanges there too    NodeImpl *n = _first;    while(n) {        n->applyChanges(false,force || changed());        n = n->nextSibling();    }    // force a relayout of this part of the document    m_render->layout();    // force a repaint of this part.    // ### if updateSize() changes any size, it will already force a    // repaint, so we might do double work here...    m_render->repaint();    setChanged(false);}DocumentTypeImpl *DocumentImpl::doctype() const{    return m_doctype;}DOMImplementationImpl *DocumentImpl::implementation() const{    return m_implementation;}void DocumentImpl::setChanged(bool b){    if (b)        changedNodes.append(this);    NodeBaseImpl::setChanged(b);}void DocumentImpl::recalcStyle(){    QTime qt;    qt.start();    if( !m_render ) return;    setStyle(new RenderStyle());    m_style->setDisplay(BLOCK);    m_style->setVisuallyOrdered( visuallyOrdered );    // ### make the font stuff _really_ work!!!!    QFont f = KGlobalSettings::generalFont();    if (m_view)    {        const KHTMLSettings *settings = m_view->part()->settings();        f.setFamily(settings->stdFontName());        QValueList<int> fs = settings->fontSizes();        float dpiY = 72.; // fallback        if ( !khtml::printpainter )            dpiY = paintDeviceMetrics()->logicalDpiY();        if ( !khtml::printpainter && dpiY < 96 )            dpiY = 96.;        float size = fs[3] * dpiY / 72.;        if(size < settings->minFontSize())            size = settings->minFontSize();        khtml::setFontSize( f, int(size),  settings, paintDeviceMetrics() );        KGlobal::charsets()->setQFont(f, settings->charset());    }    //kdDebug() << "DocumentImpl::attach: setting to charset " << settings->charset() << endl;    m_style->setFont(f);    if ( parseMode() != Strict )        m_style->setHtmlHacks(true); // enable html specific rendering tricks    if(m_render)        m_render->setStyle(m_style);    NodeImpl *n;    for (n = _first; n; n = n->nextSibling())        n->recalcStyle();    //kdDebug( 6020 ) << "TIME: recalcStyle() dt=" << qt.elapsed() << endl;}// ------------------------------------------------------------------------DocumentFragmentImpl *DocumentImpl::createDocumentFragment(  ){    return new DocumentFragmentImpl( docPtr() );}TextImpl *DocumentImpl::createTextNode( const DOMString &data ){    return new TextImpl( docPtr(), data);}CommentImpl *DocumentImpl::createComment ( const DOMString &data ){    return new CommentImpl( docPtr(), data );}CDATASectionImpl *DocumentImpl::createCDATASection ( const DOMString &data ){    return new CDATASectionImpl( docPtr(), data );}ProcessingInstructionImpl *DocumentImpl::createProcessingInstruction ( const DOMString &target, const DOMString &data ){    return new ProcessingInstructionImpl( docPtr(),target,data);}AttrImpl *DocumentImpl::createAttribute( const DOMString &name ){    AttrImpl *attr = new AttrImpl( docPtr(), name );    attr->setValue("");    return attr;}AttrImpl *DocumentImpl::createAttributeNS( const DOMString &/*_namespaceURI*/, const DOMString &/*_qualifiedName*/ ){    // ###    return 0;}EntityReferenceImpl *DocumentImpl::createEntityReference ( const DOMString &name ){    return new EntityReferenceImpl(docPtr(), name.implementation());}NodeListImpl *DocumentImpl::getElementsByTagName( const DOMString &tagname ){    return new TagNodeListImpl( this, tagname );}void DocumentImpl::updateRendering(){//    int o=changedNodes.count();//    int a=0;    QListIterator<NodeImpl> it(changedNodes);    for (; it.current(); ) {        // applyChanges removes current from the list	    it.current()->applyChanges( true, true );//        a++;    }//    kdDebug() << "UpdateRendering orig="<<o<<" actual="<<a<<endl;    changedNodes.clear();}void DocumentImpl::attach(KHTMLView *w){    m_view = w;    if ( m_view ) {        m_docLoader->m_part = w->part();        setPaintDevice( m_view );    }    if(!m_styleSelector) createSelector();    m_render = new RenderRoot(w);    recalcStyle();    NodeBaseImpl::attach();}void DocumentImpl::detach(){    clearSelection();    RenderObject* render = m_render;    // start destruction mode    m_render = 0;    NodeBaseImpl::detach();    if ( render )        render->detach();    m_view = 0;}void DocumentImpl::setVisuallyOrdered(){    visuallyOrdered = true;    if(!m_style) return;    m_style->setVisuallyOrdered(true);}void DocumentImpl::setSelection(NodeImpl* s, int sp, NodeImpl* e, int ep){    if ( m_render )        static_cast<RenderRoot*>(m_render)->setSelection(s->renderer(),sp,e->renderer(),ep);}void DocumentImpl::clearSelection(){    if ( m_render )        static_cast<RenderRoot*>(m_render)->clearSelection();}Tokenizer *DocumentImpl::createTokenizer(){    return new XMLTokenizer(docPtr(),m_view);}void DocumentImpl::setPaintDevice( QPaintDevice *dev ){    m_paintDevice = dev;    delete m_paintDeviceMetrics;    m_paintDeviceMetrics = new QPaintDeviceMetrics( dev );}void DocumentImpl::open(  ){    clear();    m_tokenizer = createTokenizer();    connect(m_tokenizer,SIGNAL(finishedParsing()),this,SIGNAL(finishedParsing()));    m_tokenizer->begin();}void DocumentImpl::close(  ){    for ( RenderObject* o = m_render; o; o = o->lastChild() )        o->setParsing( false );    if ( m_render )        m_render->close();    delete m_tokenizer;    m_tokenizer = 0;}void DocumentImpl::write( const DOMString &text ){    if(m_tokenizer)        m_tokenizer->write(text.string(), false);}void DocumentImpl::write( const QString &text ){    if(m_tokenizer)        m_tokenizer->write(text, false);}void DocumentImpl::writeln( const DOMString &text ){    write(text);    write(DOMString("\n"));}void DocumentImpl::finishParsing (  ){    if(m_tokenizer)        m_tokenizer->finish();}void DocumentImpl::clear(){    delete m_tokenizer;    m_tokenizer = 0;    removeChildren();}ElementImpl *DocumentImpl::getElementById( const DOMString &elementId ){    QStack<NodeImpl> nodeStack;    NodeImpl *current = _first;    while(1)    {        if(!current)        {            if(nodeStack.isEmpty()) break;            current = nodeStack.pop();            current = current->nextSibling();        }        else        {            if(current->isElementNode())            {                ElementImpl *e = static_cast<ElementImpl *>(current);                if(e->getAttribute(ATTR_ID) == elementId)                    return e;            }            NodeImpl *child = current->firstChild();            if(child)            {                nodeStack.push(current);                current = child;            }            else            {                current = current->nextSibling();            }        }    }    return 0;}DOMString DocumentImpl::baseURL() const{    if(view() && !view()->part()->baseURL().isEmpty()) return view()->part()->baseURL().url();    return url;}void DocumentImpl::setStyleSheet(const DOM::DOMString &url, const DOM::DOMString &sheet){    kdDebug( 6030 ) << "HTMLDocument::setStyleSheet()" << endl;    m_sheet = new CSSStyleSheetImpl(this, url);    m_sheet->ref();    m_sheet->parseString(sheet);    m_loadingSheet = false;    createSelector();}void DocumentImpl::setUserStyleSheet( const QString& sheet ){    if ( m_usersheet != sheet ) {        m_usersheet = sheet;        applyChanges();    }}CSSStyleSheetImpl* DocumentImpl::elementSheet(){    if (!m_elemSheet) {        m_elemSheet = new CSSStyleSheetImpl(this, baseURL());        m_elemSheet->ref();    }    return m_elemSheet;}static bool isTransitional(const QString &spec, int start){    if((spec.find("TRANSITIONAL", start, false ) != -1 ) ||       (spec.find("LOOSE", start, false ) != -1 ) ||       (spec.find("FRAMESET", start, false ) != -1 ) ||       (spec.find("LATIN1", start, false ) != -1 ) ||       (spec.find("SYMBOLS", start, false ) != -1 ) ||       (spec.find("SPECIAL", start, false ) != -1 ) ) {        //kdDebug() << "isTransitional" << endl;        return true;    }    return false;}enum HTMLMode {    Html3 = 0,    Html4 = 1,    XHtml = 2};void DocumentImpl::determineParseMode( const QString &str ){    // determines the parse mode for HTML    // quite some hints here are inspired by the mozilla code.    // default parsing mode is Loose    pMode = Compat;    ParseMode systemId = Unknown;    ParseMode publicId = Unknown;    HTMLMode htmlMode = Html3;    int pos = 0;    int doctype = str.find("!doctype", 0, false);    if( doctype > 2 )        pos = doctype - 2;    // get the first tag (or the doctype tag    int start = str.find('<', pos);    int stop = str.find('>', pos);    if( start > -1 && stop > start ) {        QString spec = str.mid( start + 1, stop - start - 1 );        //kdDebug() << "DocumentImpl::determineParseMode dtd=" << spec<< endl;        start = 0;        int quote = -1;        if( doctype != -1 ) {            while( (quote = spec.find( "\"", start )) != -1 ) {                int quote2 = spec.find( "\"", quote+1 );                if(quote2 < 0) quote2 = spec.length();                QString val = spec.mid( quote+1, quote2 - quote-1 );                //kdDebug() << "DocumentImpl::determineParseMode val = " << val << endl;                // find system id                pos = val.find("http://www.w3.org/tr/", 0, false);                if ( pos != -1 ) {                    // loose or strict dtd?                    if ( val.find("strict.dtd", pos, false) != -1 )                        systemId = Strict;                    else if (isTransitional(val, pos))                        systemId = Transitional;                }                // find public id                pos = val.find("//dtd", 0, false );                if ( pos != -1 ) {                    if( val.find( "xhtml", pos+6, false ) != -1 ) {                        htmlMode = XHtml;                        if( isTransitional( val, pos ) )                            publicId = Transitional;                        else                            publicId = Strict;                    } else if ( val.find( "15445:1999", pos+6 ) != -1 ) {                        htmlMode = Html4;                        publicId = Strict;                    } else {                        int tagPos = val.find( "html", pos+6, false );                        if( tagPos == -1 )                            tagPos = val.find( "hypertext markup", pos+6, false );                        if ( tagPos != -1 ) {                            tagPos = val.find(QRegExp("[0-9]"), tagPos );                            int version = val.mid( tagPos, 1 ).toInt();                            //kdDebug() << "DocumentImpl::determineParseMode tagPos = " << tagPos << " version=" << version << endl;                            if( version > 3 ) {                                htmlMode = Html4;                                publicId = isTransitional( val, tagPos ) ? Transitional : Strict;                            }                        }                    }                }                start = quote2 + 1;            }        }        if( systemId == publicId )            pMode = publicId;        else if ( systemId == Unknown )            pMode = htmlMode == Html4 ? Compat : publicId;        else if ( publicId == Transitional && systemId == Strict ) {            if ( htmlMode == Html3 )                pMode = Compat;            else                pMode = Strict;        } else            pMode = Compat;        if ( htmlMode == XHtml )            pMode = Strict;    }    //kdDebug() << "DocumentImpl::determineParseMode: publicId =" << publicId << " systemId = " << systemId << endl;    //kdDebug() << "DocumentImpl::determineParseMode: htmlMode = " << htmlMode<< endl;    if( pMode == Strict )        kdDebug(6020) << " using strict parseMode" << endl;    else if (pMode == Compat )        kdDebug(6020) << " using compatibility parseMode" << endl;    else        kdDebug(6020) << " using transitional parseMode" << endl;}// Please see if there`s a possibility to merge that code// with the next function and getElementByID().NodeImpl *DocumentImpl::findElement( int id ){    QStack<NodeImpl> nodeStack;    NodeImpl *current = _first;    while(1)    {        if(!current)        {            if(nodeStack.isEmpty()) break;            current = nodeStack.pop();            current = current->nextSibling();        }        else        {            if(current->id() == id)                return current;            NodeImpl *child = current->firstChild();            if(child)            {                nodeStack.push(current);                current = child;            }            else            {                current = current->nextSibling();            }        }    }    return 0;}ElementImpl *DocumentImpl::findSelectableElement(NodeImpl *start, bool forward){    if (!start)        start = forward?_first:_last;    if (!start)        return 0;    if (forward)        while(1)        {            if (!start->isSelectable() && start->firstChild())                start = start->firstChild();            else if (start->nextSibling())                start = start->nextSibling();            else // find the next sibling of the first parent that has a nextSibling            {                NodeImpl *pa = start;                while (pa)                {                    pa = pa->parentNode();                    if (!pa)                        return 0;                    if (pa->nextSibling())                    {                        start = pa->nextSibling();                        pa = 0;                    }                }

⌨️ 快捷键说明

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