00001
00024
00025
00026
#include "dom/dom_string.h"
00027
#include "dom/dom_exception.h"
00028
#include "dom/css_stylesheet.h"
00029
#include "dom/css_rule.h"
00030
00031
#include "css/css_ruleimpl.h"
00032
#include "css/css_valueimpl.h"
00033
#include "css/cssparser.h"
00034
#include "css/css_stylesheetimpl.h"
00035
00036
#include "xml/dom_nodeimpl.h"
00037
#include "html/html_documentimpl.h"
00038
#include "misc/loader.h"
00039
00040
#include <kdebug.h>
00041
00042
using namespace DOM;
00043
using namespace khtml;
00044
00045
00046 StyleSheetImpl::StyleSheetImpl(StyleSheetImpl *parentSheet,
DOMString href)
00047 : StyleListImpl(parentSheet)
00048 {
00049 m_disabled =
false;
00050 m_media = 0;
00051 m_parentNode = 0;
00052 m_strHref = href;
00053 }
00054
00055
00056 StyleSheetImpl::StyleSheetImpl(DOM::NodeImpl *parentNode,
DOMString href)
00057 : StyleListImpl()
00058 {
00059 m_parentNode = parentNode;
00060 m_disabled =
false;
00061 m_media = 0;
00062 m_strHref = href;
00063 }
00064
00065 StyleSheetImpl::StyleSheetImpl(StyleBaseImpl *owner,
DOMString href)
00066 : StyleListImpl(owner)
00067 {
00068 m_disabled =
false;
00069 m_media = 0;
00070 m_parentNode = 0;
00071 m_strHref = href;
00072 }
00073
00074 StyleSheetImpl::~StyleSheetImpl()
00075 {
00076
if(m_media) {
00077 m_media->setParent( 0 );
00078 m_media->deref();
00079 }
00080 }
00081
00082 StyleSheetImpl *StyleSheetImpl::parentStyleSheet()
const
00083
{
00084
if( !m_parent )
return 0;
00085
if( m_parent->isStyleSheet() )
return static_cast<StyleSheetImpl *>(m_parent);
00086
return 0;
00087 }
00088
00089
void StyleSheetImpl::setMedia( MediaListImpl *media )
00090 {
00091
if( media )
00092 media->ref();
00093
if( m_media )
00094 m_media->deref();
00095 m_media = media;
00096 }
00097
00098
00099
00100
00101 CSSStyleSheetImpl::CSSStyleSheetImpl(CSSStyleSheetImpl *parentSheet,
DOMString href)
00102 : StyleSheetImpl(parentSheet, href)
00103 {
00104 m_lstChildren =
new QPtrList<StyleBaseImpl>;
00105 m_doc = 0;
00106 m_implicit =
false;
00107 }
00108
00109 CSSStyleSheetImpl::CSSStyleSheetImpl(DOM::NodeImpl *parentNode,
DOMString href,
bool _implicit)
00110 : StyleSheetImpl(parentNode, href)
00111 {
00112 m_lstChildren =
new QPtrList<StyleBaseImpl>;
00113 m_doc = parentNode->getDocument();
00114 m_implicit = _implicit;
00115 }
00116
00117 CSSStyleSheetImpl::CSSStyleSheetImpl(CSSRuleImpl *ownerRule,
DOMString href)
00118 : StyleSheetImpl(ownerRule, href)
00119 {
00120 m_lstChildren =
new QPtrList<StyleBaseImpl>;
00121 m_doc = 0;
00122 m_implicit =
false;
00123 }
00124
00125 CSSStyleSheetImpl::CSSStyleSheetImpl(DOM::NodeImpl *parentNode, CSSStyleSheetImpl *orig)
00126 : StyleSheetImpl(parentNode, orig->m_strHref)
00127 {
00128 m_lstChildren =
new QPtrList<StyleBaseImpl>;
00129 StyleBaseImpl *rule;
00130
for ( rule = orig->m_lstChildren->first(); rule != 0; rule = orig->m_lstChildren->next() )
00131 {
00132 m_lstChildren->append(rule);
00133 rule->setParent(
this);
00134 }
00135 m_doc = parentNode->getDocument();
00136 m_implicit =
false;
00137 }
00138
00139 CSSStyleSheetImpl::CSSStyleSheetImpl(CSSRuleImpl *ownerRule, CSSStyleSheetImpl *orig)
00140 : StyleSheetImpl(ownerRule, orig->m_strHref)
00141 {
00142
00143 m_lstChildren =
new QPtrList<StyleBaseImpl>;
00144 StyleBaseImpl *rule;
00145
for ( rule = orig->m_lstChildren->first(); rule != 0; rule = orig->m_lstChildren->next() )
00146 {
00147 m_lstChildren->append(rule);
00148 rule->setParent(
this);
00149 }
00150 m_doc = 0;
00151 m_implicit =
false;
00152 }
00153
00154 CSSRuleImpl *CSSStyleSheetImpl::ownerRule()
const
00155
{
00156
if( !m_parent )
return 0;
00157
if( m_parent->isRule() )
return static_cast<CSSRuleImpl *>(m_parent);
00158
return 0;
00159 }
00160
00161
unsigned long CSSStyleSheetImpl::insertRule(
const DOMString &rule,
unsigned long index,
int &exceptioncode )
00162 {
00163 exceptioncode = 0;
00164
if(index > m_lstChildren->count()) {
00165 exceptioncode = DOMException::INDEX_SIZE_ERR;
00166
return 0;
00167 }
00168 CSSParser p( strictParsing );
00169 CSSRuleImpl *r = p.parseRule(
this, rule );
00170
00171
if(!r) {
00172 exceptioncode = CSSException::SYNTAX_ERR + CSSException::_EXCEPTION_OFFSET;
00173
return 0;
00174 }
00175
00176
00177
00178 m_lstChildren->insert(index, r);
00179
return index;
00180 }
00181
00182
CSSRuleList CSSStyleSheetImpl::cssRules()
00183 {
00184
return this;
00185 }
00186
00187
void CSSStyleSheetImpl::deleteRule(
unsigned long index,
int &exceptioncode )
00188 {
00189 exceptioncode = 0;
00190 StyleBaseImpl *b = m_lstChildren->take(index);
00191
if(!b) {
00192 exceptioncode = DOMException::INDEX_SIZE_ERR;
00193
return;
00194 }
00195 b->deref();
00196 }
00197
00198
bool CSSStyleSheetImpl::parseString(
const DOMString &string,
bool strict)
00199 {
00200
#ifdef CSS_STYLESHEET_DEBUG
00201
kdDebug( 6080 ) <<
"parsing sheet, len=" << string.
length() <<
", sheet is " << string.
string() <<
endl;
00202
#endif
00203
00204 strictParsing = strict;
00205 CSSParser p( strict );
00206 p.parseSheet(
this, string );
00207
return true;
00208 }
00209
00210
bool CSSStyleSheetImpl::isLoading()
const
00211
{
00212 StyleBaseImpl *rule;
00213
for ( rule = m_lstChildren->first(); rule != 0; rule = m_lstChildren->next() )
00214 {
00215
if(rule->isImportRule())
00216 {
00217 CSSImportRuleImpl *
import = static_cast<CSSImportRuleImpl *>(rule);
00218
#ifdef CSS_STYLESHEET_DEBUG
00219
kdDebug( 6080 ) <<
"found import" <<
endl;
00220
#endif
00221
if(
import->isLoading())
00222 {
00223
#ifdef CSS_STYLESHEET_DEBUG
00224
kdDebug( 6080 ) <<
"--> not loaded" <<
endl;
00225
#endif
00226
return true;
00227 }
00228 }
00229 }
00230
return false;
00231 }
00232
00233
void CSSStyleSheetImpl::checkLoaded()
const
00234
{
00235
if(isLoading())
return;
00236
if(m_parent) m_parent->checkLoaded();
00237
if(m_parentNode) m_parentNode->sheetLoaded();
00238 }
00239
00240
void CSSStyleSheetImpl::setNonCSSHints()
00241 {
00242 StyleBaseImpl *rule = m_lstChildren->first();
00243
while(rule) {
00244
if(rule->isStyleRule()) {
00245 static_cast<CSSStyleRuleImpl *>(rule)->setNonCSSHints();
00246 }
00247 rule = m_lstChildren->next();
00248 }
00249 }
00250
00251
00252
00253
00254
00255 StyleSheetListImpl::~StyleSheetListImpl()
00256 {
00257
for (
QPtrListIterator<StyleSheetImpl> it ( styleSheets ); it.current(); ++it )
00258 it.current()->deref();
00259 }
00260
00261
void StyleSheetListImpl::add( StyleSheetImpl* s )
00262 {
00263
if ( !styleSheets.containsRef( s ) ) {
00264 s->ref();
00265 styleSheets.append( s );
00266 }
00267 }
00268
00269
void StyleSheetListImpl::remove( StyleSheetImpl* s )
00270 {
00271
if ( styleSheets.removeRef( s ) )
00272 s->deref();
00273 }
00274
00275
unsigned long StyleSheetListImpl::length()
const
00276
{
00277
00278
unsigned long l = 0;
00279
QPtrListIterator<StyleSheetImpl> it(styleSheets);
00280
for (; it.current(); ++it) {
00281
if (!it.current()->isCSSStyleSheet() || !static_cast<CSSStyleSheetImpl*>(it.current())->implicit())
00282 l++;
00283 }
00284
return l;
00285 }
00286
00287 StyleSheetImpl *StyleSheetListImpl::item (
unsigned long index )
00288 {
00289
unsigned long l = 0;
00290
QPtrListIterator<StyleSheetImpl> it(styleSheets);
00291
for (; it.current(); ++it) {
00292
if (!it.current()->isCSSStyleSheet() || !static_cast<CSSStyleSheetImpl*>(it.current())->implicit()) {
00293
if (l == index)
00294
return it.current();
00295 l++;
00296 }
00297 }
00298
return 0;
00299 }
00300
00301
00302
00303 MediaListImpl::MediaListImpl( CSSStyleSheetImpl *parentSheet,
00304
const DOMString &media )
00305 : StyleBaseImpl( parentSheet )
00306 {
00307
setMediaText( media );
00308 }
00309
00310 MediaListImpl::MediaListImpl( CSSRuleImpl *parentRule,
const DOMString &media )
00311 : StyleBaseImpl(parentRule)
00312 {
00313
setMediaText( media );
00314 }
00315
00316
bool MediaListImpl::contains(
const DOMString &medium )
const
00317
{
00318
return m_lstMedia.count() == 0 || m_lstMedia.contains( medium ) ||
00319 m_lstMedia.contains(
"all" );
00320 }
00321
00322 CSSStyleSheetImpl *MediaListImpl::parentStyleSheet()
const
00323
{
00324
if( m_parent->isCSSStyleSheet() )
return static_cast<CSSStyleSheetImpl *>(m_parent);
00325
return 0;
00326 }
00327
00328 CSSRuleImpl *MediaListImpl::parentRule()
const
00329
{
00330
if( m_parent->isRule() )
return static_cast<CSSRuleImpl *>(m_parent);
00331
return 0;
00332 }
00333
00334
void MediaListImpl::deleteMedium(
const DOMString &oldMedium )
00335 {
00336
for (
QValueList<DOMString>::Iterator it = m_lstMedia.begin(); it != m_lstMedia.
end(); ++it ) {
00337
if( (*it) == oldMedium ) {
00338 m_lstMedia.
remove( it );
00339
return;
00340 }
00341 }
00342 }
00343
00344
DOM::DOMString MediaListImpl::mediaText()
const
00345
{
00346
DOMString text;
00347
for (
QValueList<DOMString>::ConstIterator it = m_lstMedia.begin(); it != m_lstMedia.
end(); ++it ) {
00348 text += *it;
00349 text +=
", ";
00350 }
00351
return text;
00352 }
00353
00354
void MediaListImpl::setMediaText(
const DOM::DOMString &value)
00355 {
00356 m_lstMedia.clear();
00357
QString val = value.
string();
00358
QStringList list =
QStringList::split(
',', value.
string() );
00359
for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it )
00360 {
00361
DOMString medium = (*it).stripWhiteSpace();
00362
if( !medium.
isEmpty() )
00363 m_lstMedia.append( medium );
00364 }
00365 }