📄 css_valueimpl.cpp
字号:
/** * 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.2 2002/01/28 04:31:02 leon Exp $ */#include "render_interface.h"#include "mgcolor.h"#include "mgrect.h"#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 "cssvalues.h"#include "kdebug.h"#define DEBUG_BY_XHTANG 1using namespace DOM;CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent) : StyleBaseImpl(parent){ m_lstValues = 0;}CSSStyleDeclarationImpl::CSSStyleDeclarationImpl(CSSRuleImpl *parent, QList<CSSProperty> *lstValues) : StyleBaseImpl(parent){ m_lstValues = lstValues;}CSSStyleDeclarationImpl::~CSSStyleDeclarationImpl(){ if(m_lstValues) delete m_lstValues;}DOMString CSSStyleDeclarationImpl::getPropertyValue( const DOMString &propertyName ){ CSSValueImpl *val = getPropertyCSSValue( propertyName ); 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;}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; unsigned int i = 0; while(i < m_lstValues->count()) { if(id == m_lstValues->at(i)->m_id) { m_lstValues->remove(i); // ### return 0; } i++; } return 0;}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); } int pos = m_lstValues->count(); parseValue(value.unicode(), value.unicode()+value.length(), id, important, m_lstValues); if(nonCSSHint) { CSSProperty *p = m_lstValues->at(pos); while ( p ) { p->nonCSSHint = true; p = m_lstValues->next(); } }}void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString){ QList<CSSProperty> *props = parseProperties(propertyString.unicode(), propertyString.unicode()+propertyString.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); m_lstValues->append(prop); i++; } delete props;}void CSSStyleDeclarationImpl::setLengthProperty(int id, const DOMString &value, bool important, bool nonCSSHint){ setProperty( id, value, important, nonCSSHint);#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*/ ){ 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()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -