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

📄 html_documentimpl.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		return static_cast<HTMLElementImpl*>(start);	}    else	while (1)	{	    if (start->lastChild())		start = start->lastChild();	    else if (start->previousSibling())		start = start->previousSibling();	    else	    {		NodeImpl *pa = start;		while (pa)		{		  // find the previous sibling of the first parent that has a prevSibling		    pa = pa->parentNode();		    if (!pa)			return 0;		    if (pa->previousSibling())		    {			start = pa->previousSibling();			pa = 0;			break;		    }		}	    }	    if (start->isElementNode() && static_cast<HTMLElementImpl*>(start)->isSelectable())		return static_cast<HTMLElementImpl*>(start);	}//    kdFatal(6000) << "some error in findElement\n";}StyleSheetListImpl *HTMLDocumentImpl::styleSheets(){    // ### implement for html    return 0;}// --------------------------------------------------------------------------// not part of the DOM// --------------------------------------------------------------------------void HTMLDocumentImpl::clear(){    if(parser) delete parser;    if(tokenizer) delete tokenizer;    parser = 0;    tokenizer = 0;    // #### clear tree}bool HTMLDocumentImpl::mouseEvent( int _x, int _y, int button, MouseEventType type,                                  int, int, DOMString &url,                                   NodeImpl *&innerNode, long &offset){    bool inside = false;    NodeImpl *n = firstChild();    while ( n && n->id() != ID_HTML )        n = n->nextSibling();    if ( n )        inside = n->mouseEvent(_x, _y, button, type, 0, 0, url, innerNode, offset);    ////kdDebug(0) << "documentImpl::mouseEvent " << n->id() << " " << inside << endl;	    return inside;}void HTMLDocumentImpl::attach(MGHTMLView *w){    m_view = w;    if(!m_styleSelector) createSelector();    m_render = new RenderRoot(w);    recalcStyle();	m_docLoader->setHwnd(w->getHwnd());//	m_docLoader->setRenderRoot(m_render);    NodeBaseImpl::attach(w);}void HTMLDocumentImpl::detach(){#ifdef JAVASCRIPT_ENABLE    // onunload script...    if(m_view && m_view->part() && m_view->part()->jScriptEnabled() && body()) {        DOMString script = body()->getAttribute(ATTR_ONUNLOAD);        if(script.length()) {            ////kdDebug( 6030 ) << "emit executeScript( " << script.string() << " )" << endl;//            m_view->part()->executeScript( Node(this), script.string() );            m_view->part()->executeScript( (HTMLElementImpl*)0, script.string() );		}    }#endif    //kdDebug( 6090 ) << "HTMLDocumentImpl::detach()" << endl;    m_view = 0;    DocumentImpl::detach();}void HTMLDocumentImpl::setVisuallyOrdered(){    visuallyOrdered = true;    if(!m_style) return;    m_style->setVisuallyOrdered(true);}void HTMLDocumentImpl::createSelector(){    applyChanges();}// ### this function should not be needed in the long run. The one in// DocumentImpl should be enough.void HTMLDocumentImpl::applyChanges(bool,bool force){	    if(m_styleSelector) delete m_styleSelector;    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);}void HTMLDocumentImpl::recalcStyle(){    QTime qt;    qt.start();    if( !m_render ) return;    if( m_style ) delete m_style;    m_style = new RenderStyle();    m_style->setDisplay(BLOCK);    m_style->setVisuallyOrdered( visuallyOrdered );    // ### make the font stuff _really_ work!!!!	// TODO set proper font	/*    const MGHTMLSettings *settings = m_view->part()->settings();    QValueList<int> fs = settings->fontSizes();    int size = fs[3];    if(size < settings->minFontSize())        size = settings->minFontSize();    QFont f = KGlobalSettings::generalFont();    f.setFamily(settings->stdFontName());    f.setPointSize(size);    ////kdDebug() << "HTMLDocumentImpl::attach: setting to charset " << settings->charset() << endl;    KGlobal::charsets()->setQFont(f, settings->charset());    m_style->setFont(f);	*/	    m_style->setHtmlHacks(true); // enable html specific rendering tricks    if (m_render) {        m_render->setPart (m_view->part());	    m_render->setStyle(m_style);    }    NodeImpl *n;    for (n = _first; n; n = n->nextSibling())	n->recalcStyle();    //kdDebug( ) << "TIME: recalcStyle() dt=" << qt.elapsed() << endl;}void HTMLDocumentImpl::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();}CSSStyleSheetImpl* HTMLDocumentImpl::elementSheet(){    if (!m_elemSheet) {        m_elemSheet = new CSSStyleSheetImpl(this, baseURL());	m_elemSheet->ref();    }    return m_elemSheet;}void HTMLDocumentImpl::setSelection(NodeImpl* s, int sp, NodeImpl* e, int ep){    static_cast<RenderRoot*>(m_render)        ->setSelection(s->renderer(),sp,e->renderer(),ep);}void HTMLDocumentImpl::clearSelection(){    static_cast<RenderRoot*>(m_render)        ->clearSelection();}int HTMLDocumentImpl::findHighestTabIndex(){    NodeImpl *n=body();    NodeImpl *next=0;    HTMLAreaElementImpl *a;    int retval=-1;    int tmpval;    while(n)    {	//find out tabindex of current element, if availiable	if (n->id()==ID_A)        {	    a=static_cast<HTMLAreaElementImpl *>(n);	    tmpval=a->tabIndex();	    if (tmpval>retval)		retval=tmpval;        }	//iterate to next element.	if (n->firstChild())	    n=n->firstChild();	else if (n->nextSibling())	    n=n->nextSibling();	else        {	    next=0;	    while(!next)            {		n=n->parentNode();		if (!n)		    return retval;		next=n->nextSibling();            }	    n=next;        }    }    return retval;}HTMLElementImpl *HTMLDocumentImpl::findLink(HTMLElementImpl *n, bool forward, int tabIndexHint){    // tabIndexHint is the tabIndex that should be found.    // if it is not in the document, and direction is forward,    // tabIndexHint is incremented until maxTabIndex is reached.    // if direction is backward, tabIndexHint is reduced until -1    // is encountered.    // if tabIndex is -1, items containing tabIndex are skipped.  //kdDebug(6000)<<"HTMLDocumentImpl:findLink: Node: "<<n<<" forward: "<<(forward?"true":"false")<<" tabIndexHint: "<<tabIndexHint<<"\n";    int maxTabIndex;    if (forward) maxTabIndex = findHighestTabIndex();    else maxTabIndex = -1;    do    {	do	{	    n = findSelectableElement(n, forward);	    // this is alright even for non-tabindex-searches,	    // because DOM::NodeImpl::tabIndex() defaults to -1.	} while (n && (n->tabIndex()!=tabIndexHint));	if (n)	    break;	if (tabIndexHint!=-1)	{	    if (forward)	    {		tabIndexHint++;		if (tabIndexHint>maxTabIndex)		    tabIndexHint=-1;		n=0;	    }	    else	    {		tabIndexHint--;		n=0;	    }	    //kdDebug(6000)<<"trying next tabIndexHint:"<<tabIndexHint<<"\n";	}	// this is not the same as else ... ,	// since tabIndexHint may have been changed in the block above.	if (tabIndexHint==-1)	    break;    } while(1); // break.    return n;}void HTMLDocumentImpl::slotFinishedParsing(){#if DEBUG_BY_XHTANG	fprintf(stderr,"HTMLDocumentImpl::slotFinishedParsing\n");#endif#ifdef JAVASCRIPT_ENABLE		// onload script...    if(m_view && m_view->part()->jScriptEnabled() && body()) {        DOMString script = body()->getAttribute(ATTR_ONLOAD);        if(script.length()) {            //kdDebug( 6030 ) << "emit executeScript( " << script.string() << " )" << endl;				//            m_view->part()->executeScript( Node(this), script.string() );            m_view->part()->executeScript( (HTMLElementImpl*)0, script.string() );		}    }    if ( !onloadScript.isEmpty() )		//		m_view->part()->executeScript( Node(this), onloadScript );		m_view->part()->executeScript( (HTMLElementImpl*)0, onloadScript );#endif    emit finishedParsing();}bool HTMLDocumentImpl::childAllowed( NodeImpl *newChild ){    return (newChild->id() == ID_HTML || newChild->id() == ID_COMMENT);}void HTMLDocumentImpl::setReloading(){    m_docLoader->reloading = true;}void HTMLDocumentImpl::updateRendering(){    QListIterator<NodeImpl> it(changedNodes);    for (; it.current(); ++it) {	if( it.current()->changed() )	    it.current()->applyChanges( true, true );    }     changedNodes.clear();}#include "html_documentimpl.moc"

⌨️ 快捷键说明

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