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

📄 html_baseimpl.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
字号:
/** * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) *           (C) 1999 Antti Koivisto (koivisto@kde.org)) *	     (C) 2000 Simon Hausmann <hausmann@kde.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: html_baseimpl.cpp,v 1.3 2003/04/22 08:41:09 weiym Exp $ */// -------------------------------------------------------------------------#include "render_interface.h"#include "html_baseimpl.h"#include "html_documentimpl.h"#include "mghtmlview.h"#include "mghtml_part.h"#include "render_frames.h"#include "render_html.h"#include "render_body.h"#include "cssstyleselector.h"#include "css_stylesheetimpl.h"#include "cssproperties.h"//#include "loader.h"#include "htmlhashes.h"#include "dom_string.h"#include "kurl.h"#include "kdebug.h"using namespace DOM;using namespace khtml;HTMLBodyElementImpl::HTMLBodyElementImpl(DocumentImpl *doc)    : HTMLElementImpl(doc){    m_styleSheet = 0;}HTMLBodyElementImpl::~HTMLBodyElementImpl(){    if(m_styleSheet) m_styleSheet->deref();}const DOMString HTMLBodyElementImpl::nodeName() const{    return "BODY";}ushort HTMLBodyElementImpl::id() const{    return ID_BODY;}void HTMLBodyElementImpl::parseAttribute(AttrImpl *attr){    switch(attr->attrId)    {    case ATTR_BACKGROUND:    {#if 0	KURL u = khtml::Cache::completeURL(attr->value(), static_cast<HTMLDocumentImpl *>(document)->baseURL());#else	KURL u = KURL::completeURL(attr->value(), static_cast<HTMLDocumentImpl *>(document)->baseURL());#endif	bgImage = u.url();	addCSSProperty(CSS_PROP_BACKGROUND_IMAGE, u.url(), false);	break;    }    case ATTR_MARGINWIDTH:    {	QString str;	str += attr->value().string() + "px";        addCSSProperty(CSS_PROP_PADDING_LEFT, str, false);        addCSSProperty(CSS_PROP_PADDING_RIGHT, str, false);	break;    }    case ATTR_MARGINHEIGHT:    {	QString str;	str += attr->value().string() + "px";        addCSSProperty(CSS_PROP_PADDING_TOP, str, false);        addCSSProperty(CSS_PROP_PADDING_BOTTOM, str, false);	break;    }    case ATTR_BGCOLOR:	bgColor = attr->value();	addCSSProperty(CSS_PROP_BACKGROUND_COLOR, attr->value(), false);	break;    case ATTR_TEXT:	addCSSProperty(CSS_PROP_COLOR, attr->value(), false);	break;    case ATTR_LINK:    {	//kdDebug(0) << "HTMLBodyElementImpl::parseAttribute" << endl;	if(!m_styleSheet) {	    m_styleSheet = new CSSStyleSheetImpl(this);	    m_styleSheet->ref();	}	QString aStr = "a:link { color: " + attr->value().string() + "; }";	m_styleSheet->parseString(aStr);	m_styleSheet->setNonCSSHints();	break;    }    case ATTR_VLINK:    {	if(!m_styleSheet) {	    m_styleSheet = new CSSStyleSheetImpl(this);	    m_styleSheet->ref();	}	QString aStr = "a:vlink { color: " + attr->value().string() + "; }";	m_styleSheet->parseString(aStr);	m_styleSheet->setNonCSSHints();	break;    }     case ATTR_ALINK:      break;    default:	HTMLElementImpl::parseAttribute(attr);    }}void HTMLBodyElementImpl::attach(MGHTMLView *w){    if(w->marginWidth() != -1) {	QString str;	str.sprintf("%dpx",w->marginWidth());	addCSSProperty(CSS_PROP_PADDING_LEFT, str, false);        addCSSProperty(CSS_PROP_PADDING_RIGHT, str, false);    }    if(w->marginHeight() != -1) {	QString str;	str.sprintf("%dpx",w->marginHeight());	addCSSProperty(CSS_PROP_PADDING_TOP, str, false);        addCSSProperty(CSS_PROP_PADDING_BOTTOM, str, false);    }    m_style = document->styleSelector()->styleForElement( this, w->part() );    khtml::RenderObject *r = _parent->renderer();    if ( !r )      return;    m_render = new khtml::RenderBody();    m_render->setPart (w->part());    m_render->setStyle(m_style);    r->addChild( m_render, _next ? _next->renderer() : 0 );    NodeBaseImpl::attach( w );}// -------------------------------------------------------------------------// TODOHTMLFrameElementImpl::HTMLFrameElementImpl(DocumentImpl *doc)    : HTMLElementImpl(doc){    view = 0;    parentWidget = 0;    frameBorder = true;    frameBorderSet = false;    marginWidth = -1;    marginHeight = -1;//    scrolling = QScrollView::Auto;    noresize = false;}HTMLFrameElementImpl::~HTMLFrameElementImpl(){}const DOMString HTMLFrameElementImpl::nodeName() const{    return "FRAME";}ushort HTMLFrameElementImpl::id() const{    return ID_FRAME;}void HTMLFrameElementImpl::parseAttribute(AttrImpl *attr){    //kdDebug( 6031 ) << "parsing attribute " << attr->attrId << "=" << attr->value().string() << endl;    switch(attr->attrId)    {    case ATTR_SRC:	url = attr->value();	break;    case ATTR_NAME:	name = attr->value();	break;    case ATTR_FRAMEBORDER:	if(attr->value() == "0" || strcasecmp( attr->value(), "no" ) == 0 )	    frameBorder = false;        frameBorderSet = true;	break;    case ATTR_MARGINWIDTH:	marginWidth = attr->val()->toInt();	break;    case ATTR_MARGINHEIGHT:	marginHeight = attr->val()->toInt();	break;    case ATTR_NORESIZE:	noresize = true;	break;    case ATTR_SCROLLING:	//kdDebug( 6031 ) << "set scroll mode" << endl;#if 0	if( strcasecmp( attr->value(), "auto" ) == 0 )	    scrolling = QScrollView::Auto;	else if( strcasecmp( attr->value(), "yes" ) == 0 )	    scrolling = QScrollView::AlwaysOn;	else if( strcasecmp( attr->value(), "no" ) == 0 )	    scrolling = QScrollView::AlwaysOff;#endif    default:	HTMLElementImpl::parseAttribute(attr);    }}void HTMLFrameElementImpl::attach(MGHTMLView *w){    // inherit default settings from parent frameset    HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode());    while(node)    {        if(node->id() == ID_FRAMESET)        {            HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node);            if(!frameBorderSet)  frameBorder = frameset->frameBorder();            if(!noresize)  noresize = frameset->noResize();            break;        }        node = static_cast<HTMLElementImpl*>(node->parentNode());    }    m_style = document->styleSelector()->styleForElement( this, w->part() );    khtml::RenderObject *r = _parent->renderer();    if ( !r )      return;    khtml::RenderFrame *renderFrame = new khtml::RenderFrame( w, this );    m_render = renderFrame;    m_render->setPart (w->part());    m_render->setStyle(m_style);    r->addChild( m_render, _next ? _next->renderer() : 0 );    // we need a unique name for every frame in the frameset. Hope that's unique enough.    if(name.isEmpty() || w->part()->frameExists( name.string() ) )    {      name = DOMString(w->part()->requestFrameName());      //kdDebug( 6030 ) << "creating frame name: " << name.string() << endl;    }    w->part()->requestFrame( renderFrame, url.string(), name.string() );    NodeBaseImpl::attach( w );    return;}void HTMLFrameElementImpl::detach(){    delete view;    parentWidget = 0;    HTMLElementImpl::detach();}// -------------------------------------------------------------------------HTMLFrameSetElementImpl::HTMLFrameSetElementImpl(DocumentImpl *doc)    : HTMLElementImpl(doc){    // default value for rows and cols...    m_totalRows = 1;    m_totalCols = 1;    m_rows = m_cols = 0;    frameborder = true;    frameBorderSet = false;    m_border = 4;    noresize = false;    m_resizing = false;    view = 0;}HTMLFrameSetElementImpl::~HTMLFrameSetElementImpl(){    delete m_rows;    delete m_cols;}const DOMString HTMLFrameSetElementImpl::nodeName() const{    return "FRAMESET";}ushort HTMLFrameSetElementImpl::id() const{    return ID_FRAMESET;}void HTMLFrameSetElementImpl::parseAttribute(AttrImpl *attr){    switch(attr->attrId)    {    case ATTR_ROWS:	m_rows = attr->val()->toLengthList();	m_totalRows = m_rows->count();	break;    case ATTR_COLS:	m_cols = attr->val()->toLengthList();	m_totalCols = m_cols->count();	break;    case ATTR_FRAMEBORDER:	if(attr->value() == "0" || strcasecmp( attr->value(), "no" ) == 0 ) {	    frameborder = false;	    m_border = 0;	}        frameBorderSet = true;	break;    case ATTR_NORESIZE:	noresize = true;	break;    case ATTR_BORDER:	m_border = attr->val()->toInt();	if(!m_border)	    frameborder = false;	break;    default:	HTMLElementImpl::parseAttribute(attr);    }}void HTMLFrameSetElementImpl::attach(MGHTMLView *w){    // inherit default settings from parent frameset    HTMLElementImpl* node = static_cast<HTMLElementImpl*>(parentNode());    while(node)    {        if(node->id() == ID_FRAMESET)        {            HTMLFrameSetElementImpl* frameset = static_cast<HTMLFrameSetElementImpl*>(node);            if(!frameBorderSet)  frameborder = frameset->frameBorder();            if(!noresize)  noresize = frameset->noResize();            break;        }        node = static_cast<HTMLElementImpl*>(node->parentNode());    }    m_style = document->styleSelector()->styleForElement( this, w->part() );    view = w;    khtml::RenderObject *r = _parent->renderer();    if ( !r )      return;    khtml::RenderFrameSet *renderFrameSet = new khtml::RenderFrameSet( this, w, m_rows, m_cols );    m_render = renderFrameSet;    m_render->setPart (w->part());    m_render->setStyle(m_style);    r->addChild( m_render, _next ? _next->renderer() : 0 );    NodeBaseImpl::attach( w );}NodeImpl *HTMLFrameSetElementImpl::addChild(NodeImpl *child){#ifdef DEBUG_LAYOUT    //kdDebug( 6030 ) << nodeName().string() << "(FrameSet)::addChild( " << child->nodeName().string() << " )" << endl;#endif    return NodeBaseImpl::addChild(child);}bool HTMLFrameSetElementImpl::mouseEvent( int _x, int _y, int button, MouseEventType type,				  int _tx, int _ty, DOMString &url,                                          NodeImpl *&innerNode, long &offset){    _x-=_tx;    _y-=_ty;    //kdDebug( 6030 ) << "mouseEvent" << endl;    NodeImpl *child = _first;    while(child)    {	if(child->id() == ID_FRAMESET)	    if(child->mouseEvent( _x, _y, button, type, _tx, _ty, url, innerNode, offset)) return true;	child = child->nextSibling();    }    //kdDebug( 6030 ) << "children done.." << endl;    if(noresize) return true;    if ( !m_render || !m_render->layouted() )    {      //kdDebug( 6030 ) << "ugh, not layouted or not attached?!" << endl;      return true;    }    return static_cast<khtml::RenderFrameSet *>(m_render)->userResize( _x, _y, type );}// -------------------------------------------------------------------------HTMLHeadElementImpl::HTMLHeadElementImpl(DocumentImpl *doc)    : HTMLElementImpl(doc){}HTMLHeadElementImpl::~HTMLHeadElementImpl(){}const DOMString HTMLHeadElementImpl::nodeName() const{    return "HEAD";}ushort HTMLHeadElementImpl::id() const{    return ID_HEAD;}void HTMLHtmlElementImpl::attach(MGHTMLView *w){    m_style = document->styleSelector()->styleForElement( this, w->part() );    khtml::RenderObject *r = _parent->renderer();    if ( !r )      return;    m_render = new khtml::RenderHtml();    m_render->setPart (w->part());    m_render->setStyle(m_style);    r->addChild( m_render, _next ? _next->renderer() : 0 );    NodeBaseImpl::attach( w );}// -------------------------------------------------------------------------HTMLHtmlElementImpl::HTMLHtmlElementImpl(DocumentImpl *doc)    : HTMLElementImpl(doc){}HTMLHtmlElementImpl::~HTMLHtmlElementImpl(){}const DOMString HTMLHtmlElementImpl::nodeName() const{    return "HTML";}ushort HTMLHtmlElementImpl::id() const{    return ID_HTML;}// -------------------------------------------------------------------------HTMLIFrameElementImpl::HTMLIFrameElementImpl(DocumentImpl *doc) : HTMLFrameElementImpl(doc){}HTMLIFrameElementImpl::~HTMLIFrameElementImpl(){}const DOMString HTMLIFrameElementImpl::nodeName() const{    return "IFRAME";}ushort HTMLIFrameElementImpl::id() const{    return ID_IFRAME;}void HTMLIFrameElementImpl::parseAttribute(AttrImpl *attr ){  DOM::DOMStringImpl *stringImpl = attr->value().implementation();  QString val = QConstString( stringImpl->s, stringImpl->l ).string();  switch (  attr->attrId )  {    case ATTR_WIDTH:      addCSSLength( CSS_PROP_WIDTH, attr->value(), false );      break;    case ATTR_HEIGHT:      addCSSLength( CSS_PROP_HEIGHT, attr->value(), false );      break;    default:      HTMLFrameElementImpl::parseAttribute( attr );  }}void HTMLIFrameElementImpl::attach(MGHTMLView *w){  m_style = document->styleSelector()->styleForElement( this, w->part() );  khtml::RenderObject *r = _parent->renderer();  if ( !r )    return;  // we need a unique name for every frame in the frameset. Hope that's unique enough.  if(name.isEmpty())  {    name = DOMString(w->part()->requestFrameName());    //kdDebug( 6030 ) << "creating frame name: " << name.string() << endl;  }  khtml::RenderPartObject *renderFrame = new khtml::RenderPartObject( w, this );  m_render = renderFrame;  m_render->setPart (w->part());  m_render->setStyle(m_style);  r->addChild( m_render, _next ? _next->renderer() : 0 );  NodeBaseImpl::attach( w );}

⌨️ 快捷键说明

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