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

📄 css_valueimpl.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/** * This file is part of the DOM implementation for KDE. * * (C) 1999 Lars Knoll (knoll@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: css_valueimpl.cpp,v 1.49 2001/07/29 16:12:45 knoll Exp $ */#include "css_valueimpl.h"#include "css_value.h"#include "css_ruleimpl.h"#include "css_stylesheetimpl.h"#include "cssparser.h"#include "dom_exception.h"#include "dom_string.h"#include "dom_stringimpl.h"#include "dom_nodeimpl.h"#include "xml/dom_docimpl.h"#include "rendering/render_style.h"#include "misc/loader.h"#include "misc/helper.h"#include "khtmlview.h"#include "khtml_part.h"#include "khtml_settings.h"#include <qpaintdevicemetrics.h>#include <kdebug.h>#include "cssvalues.h"// Hack for debugging purposesextern DOM::DOMString getPropertyName(unsigned short id);using namespace DOM;CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent)    : StyleBaseImpl(parent){    m_lstValues = 0;    m_node = 0;}CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent, QList<CSSProperty> *lstValues)    : StyleBaseImpl(parent){    m_lstValues = lstValues;    m_node = 0;}CSSStyleDeclarationImpl::~CSSStyleDeclarationImpl(){    delete m_lstValues;    // we don't use refcounting for m_node, to avoid cyclic references (see ElementImpl)}DOMString CSSStyleDeclarationImpl::getPropertyValue( const DOMString &propertyName ){    CSSValueImpl *val = getPropertyCSSValue( propertyName );    if ( !val )	return 0;    return val->cssText();}DOMString CSSStyleDeclarationImpl::getPropertyValue( int id ){    CSSValueImpl *val = getPropertyCSSValue( id );    if ( !val )	return 0;    return val->cssText();}CSSValueImpl *CSSStyleDeclarationImpl::getPropertyCSSValue( const DOMString &propertyName ){    int id = getPropertyID(propertyName.string().ascii(), propertyName.length());    return getPropertyCSSValue(id);}CSSValueImpl *CSSStyleDeclarationImpl::getPropertyCSSValue( int propertyID ){    if(!m_lstValues) return 0;    unsigned int i = 0;    while(i < m_lstValues->count())    {	if(propertyID == m_lstValues->at(i)->m_id) return m_lstValues->at(i)->value();	i++;    }    return 0;}bool CSSStyleDeclarationImpl::removeProperty( int propertyID, bool onlyNonCSSHints ){    QListIterator<CSSProperty> lstValuesIt(*m_lstValues);    lstValuesIt.toLast();    while (lstValuesIt.current() && lstValuesIt.current()->m_id != propertyID)        --lstValuesIt;    if (lstValuesIt.current()) {	if ( onlyNonCSSHints && !lstValuesIt.current()->nonCSSHint )	    return false;	m_lstValues->removeRef(lstValuesIt.current());	return true;	if (m_node)	    m_node->setChanged(true);    }    return true;}        DOMString CSSStyleDeclarationImpl::removeProperty( const DOMString &propertyName ){    int id = getPropertyID(propertyName.string().lower().ascii(), propertyName.length());    return removeProperty(id);}DOMString CSSStyleDeclarationImpl::removeProperty(int id){    if(!m_lstValues) return 0;    DOMString value;    QListIterator<CSSProperty> lstValuesIt(*m_lstValues);    lstValuesIt.toLast();    while (lstValuesIt.current() && lstValuesIt.current()->m_id != id)        --lstValuesIt;    if (lstValuesIt.current()) {	value = lstValuesIt.current()->value()->cssText();        m_lstValues->removeRef(lstValuesIt.current());	if (m_node)	    m_node->setChanged(true);    }    return value;}DOMString CSSStyleDeclarationImpl::getPropertyPriority( const DOMString &propertyName ){    int id = getPropertyID(propertyName.string().ascii(), propertyName.length());    if(getPropertyPriority(id))	return DOMString("important");    return DOMString();}bool CSSStyleDeclarationImpl::getPropertyPriority( int propertyID ){    if(!m_lstValues) return false;    unsigned int i = 0;    while(i < m_lstValues->count())    {	if(propertyID == m_lstValues->at(i)->m_id ) return m_lstValues->at(i)->m_bImportant;	i++;    }    return false;}void CSSStyleDeclarationImpl::setProperty( const DOMString &propName, const DOMString &value, const DOMString &priority ){    int id = getPropertyID(propName.string().lower().ascii(), propName.length());    if (!id) return;    bool important = false;    QString str = priority.string().lower();    if(str.contains("important"))	important = true;    setProperty(id, value, important);}void CSSStyleDeclarationImpl::setProperty(const DOMString &propName, const DOMString &value, bool important, bool nonCSSHint){    int id = getPropertyID(propName.string().lower().ascii(), propName.length());    if (!id) return;    setProperty(id, value, important, nonCSSHint);}void CSSStyleDeclarationImpl::setProperty(int id, const DOMString &value, bool important, bool nonCSSHint){    if(!m_lstValues) {	m_lstValues = new QList<CSSProperty>;	m_lstValues->setAutoDelete(true);    }    if ( !removeProperty(id, nonCSSHint ) )	return;    int pos = m_lstValues->count();    DOMString ppValue = preprocess(value.string(),true);    parseValue(ppValue.unicode(), ppValue.unicode()+ppValue.length(), id, important, m_lstValues);    if( nonCSSHint && pos < (int)m_lstValues->count() ) {	CSSProperty *p = m_lstValues->at(pos);	while ( p ) {	    p->nonCSSHint = true;	    p = m_lstValues->next();	}    } else if((unsigned) pos == m_lstValues->count() )	{	kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()					<< "] value: [" << value.string() << "]"<< endl;	}    if (m_node)	m_node->setChanged(true);}void CSSStyleDeclarationImpl::setProperty(int id, int value, bool important, bool nonCSSHint){    if(!m_lstValues) {	m_lstValues = new QList<CSSProperty>;	m_lstValues->setAutoDelete(true);    }    if ( !removeProperty(id, nonCSSHint ) )	return;    int pos = m_lstValues->count();    CSSValueImpl * cssValue = new CSSPrimitiveValueImpl(value);    setParsedValue(id, cssValue, important, m_lstValues);    if( nonCSSHint && pos < (int)m_lstValues->count() ) {	CSSProperty *p = m_lstValues->at(pos);	while ( p ) {	    p->nonCSSHint = true;	    p = m_lstValues->next();	}    } else if((unsigned) pos == m_lstValues->count() )	{	kdDebug( 6080 ) << "CSSStyleDeclarationImpl::setProperty invalid property: [" << getPropertyName(id).string()					<< "] value: [" << value << "]" << endl;	}    if (m_node)	m_node->setChanged(true);}void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString){    DOMString ppPropertyString = preprocess(propertyString.string(),true);    QList<CSSProperty> *props = parseProperties(ppPropertyString.unicode(),						ppPropertyString.unicode()+ppPropertyString.length());    if(!props || !props->count())    {	kdDebug( 6080 ) << "no properties returned!" << endl;	return;    }    props->setAutoDelete(false);    unsigned int i = 0;    if(!m_lstValues) {	m_lstValues = new QList<CSSProperty>;	m_lstValues->setAutoDelete( true );    }    while(i < props->count())    {	//kdDebug( 6080 ) << "setting property" << endl;	CSSProperty *prop = props->at(i);	removeProperty(prop->m_id, false);	m_lstValues->append(prop);	i++;    }    delete props;    if (m_node)	m_node->setChanged(true);}void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOMString &value,						bool important, bool nonCSSHint){    bool parseMode = strictParsing;    strictParsing = false;    setProperty( id, value, important, nonCSSHint);    strictParsing = parseMode;#if 0 // ### FIXME after 2.0    if(!value.unicode() || value.length() == 0)	return;    if(!m_lstValues)    {	m_lstValues = new QList<CSSProperty>;	m_lstValues->setAutoDelete(true);    }    CSSValueImpl *v = parseUnit(value.unicode(), value.unicode()+value.length(),				INTEGER | PERCENT | LENGTH, );    if(!v)    {	kdDebug( 6080 ) << "invalid length" << endl;	return;    }    CSSPrimitiveValueImpl *p = static_cast<CSSPrimitiveValueImpl *>(v);    if(p->primitiveType() == CSSPrimitiveValue::CSS_NUMBER)    {	// set the parsed number in pixels	p->setPrimitiveType(CSSPrimitiveValue::CSS_PX);    }    CSSProperty *prop = new CSSProperty();    prop->m_id = id;    prop->setValue(v);    prop->m_bImportant = important;    prop->nonCSSHint = nonCSSHint;    m_lstValues->append(prop);#endif}unsigned long CSSStyleDeclarationImpl::length() const{    if(!m_lstValues) return 0;    return m_lstValues->count();}DOMString CSSStyleDeclarationImpl::item( unsigned long /*index*/ ){    // ###    //return m_lstValues->at(index);    return 0;}CSSRuleImpl *CSSStyleDeclarationImpl::parentRule() const{    if( !m_parent ) return 0;    if( m_parent->isRule() ) return static_cast<CSSRuleImpl *>(m_parent);    return 0;}DOM::DOMString CSSStyleDeclarationImpl::cssText() const{    return DOM::DOMString();    // ###}void CSSStyleDeclarationImpl::setCssText(DOM::DOMString /*str*/){    // ###}bool CSSStyleDeclarationImpl::parseString( const DOMString &/*string*/, bool ){    return false;    // ###}// --------------------------------------------------------------------------------------CSSValueImpl::CSSValueImpl()    : StyleBaseImpl(){}CSSValueImpl::~CSSValueImpl(){}DOM::DOMString CSSValueImpl::cssText() const{    return DOM::DOMString();}void CSSValueImpl::setCssText(DOM::DOMString /*str*/){    // ###}DOM::DOMString CSSInheritedValueImpl::cssText() const{    return DOMString("inherited");}// ----------------------------------------------------------------------------------------CSSValueListImpl::CSSValueListImpl()    : CSSValueImpl(){}CSSValueListImpl::~CSSValueListImpl(){    CSSValueImpl *val = m_values.first();    while( val ) {	val->deref();	val = m_values.next();    }}unsigned short CSSValueListImpl::valueType() const{    return CSSValue::CSS_VALUE_LIST;}

⌨️ 快捷键说明

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