KHTML
css_stylesheet.cpp
Go to the documentation of this file.00001 00024 #include "dom/dom_exception.h" 00025 #include "dom/css_rule.h" 00026 #include "dom/dom_doc.h" 00027 00028 #include "xml/dom_docimpl.h" 00029 00030 #include "html/html_headimpl.h" 00031 00032 #include "css/css_stylesheetimpl.h" 00033 #include "misc/htmlhashes.h" 00034 00035 #include <stdio.h> 00036 00037 using namespace DOM; 00038 00039 StyleSheet::StyleSheet() 00040 { 00041 impl = 0; 00042 } 00043 00044 StyleSheet::StyleSheet(const StyleSheet &other) 00045 { 00046 impl = other.impl; 00047 if(impl) impl->ref(); 00048 } 00049 00050 StyleSheet::StyleSheet(StyleSheetImpl *i) 00051 { 00052 impl = i; 00053 if(impl) impl->ref(); 00054 } 00055 00056 StyleSheet &StyleSheet::operator = (const StyleSheet &other) 00057 { 00058 if ( impl != other.impl ) { 00059 if(impl) impl->deref(); 00060 impl = other.impl; 00061 if(impl) impl->ref(); 00062 } 00063 return *this; 00064 } 00065 00066 StyleSheet::~StyleSheet() 00067 { 00068 if(impl) impl->deref(); 00069 } 00070 00071 DOMString StyleSheet::type() const 00072 { 00073 if(!impl) return DOMString(); 00074 return ((StyleSheetImpl *)impl)->type(); 00075 } 00076 00077 bool StyleSheet::disabled() const 00078 { 00079 if(!impl) return 0; 00080 return ((StyleSheetImpl *)impl)->disabled(); 00081 } 00082 00083 void StyleSheet::setDisabled( bool _disabled ) 00084 { 00085 if(impl) 00086 ((StyleSheetImpl *)impl)->setDisabled( _disabled ); 00087 } 00088 00089 DOM::Node StyleSheet::ownerNode() const 00090 { 00091 if(!impl) return Node(); 00092 return ((StyleSheetImpl *)impl)->ownerNode(); 00093 } 00094 00095 StyleSheet StyleSheet::parentStyleSheet() const 00096 { 00097 if(!impl) return 0; 00098 return ((StyleSheetImpl *)impl)->parentStyleSheet(); 00099 } 00100 00101 DOMString StyleSheet::href() const 00102 { 00103 if(!impl) return DOMString(); 00104 return ((StyleSheetImpl *)impl)->href(); 00105 } 00106 00107 DOMString StyleSheet::title() const 00108 { 00109 if(!impl) return DOMString(); 00110 return ((StyleSheetImpl *)impl)->title(); 00111 } 00112 00113 MediaList StyleSheet::media() const 00114 { 00115 if(!impl) return 0; 00116 return ((StyleSheetImpl *)impl)->media(); 00117 } 00118 00119 bool StyleSheet::isCSSStyleSheet() const 00120 { 00121 if(!impl) return false; 00122 return ((StyleSheetImpl *)impl)->isCSSStyleSheet(); 00123 } 00124 00125 KUrl StyleSheet::baseUrl() { 00126 if(!impl) return KUrl(); 00127 return ((StyleSheetImpl *)impl)->baseURL(); 00128 } 00129 00130 00131 CSSStyleSheet::CSSStyleSheet() : StyleSheet() 00132 { 00133 } 00134 00135 CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet &other) : StyleSheet(other) 00136 { 00137 } 00138 00139 CSSStyleSheet::CSSStyleSheet(const StyleSheet &other) 00140 { 00141 if (!other.isCSSStyleSheet()) 00142 impl = 0; 00143 else 00144 operator=(other); 00145 } 00146 00147 CSSStyleSheet::CSSStyleSheet(CSSStyleSheetImpl *impl) : StyleSheet(impl) 00148 { 00149 } 00150 00151 CSSStyleSheet &CSSStyleSheet::operator = (const CSSStyleSheet &other) 00152 { 00153 StyleSheet::operator = (other); 00154 return *this; 00155 } 00156 00157 CSSStyleSheet &CSSStyleSheet::operator = (const StyleSheet &other) 00158 { 00159 if(!other.handle()->isCSSStyleSheet()) 00160 { 00161 if(impl) impl->deref(); 00162 impl = 0; 00163 } else { 00164 StyleSheet::operator = (other); 00165 } 00166 return *this; 00167 } 00168 00169 CSSStyleSheet::~CSSStyleSheet() 00170 { 00171 } 00172 00173 CSSRule CSSStyleSheet::ownerRule() const 00174 { 00175 if(!impl) return 0; 00176 return ((CSSStyleSheetImpl *)impl)->ownerRule(); 00177 } 00178 00179 CSSRuleList CSSStyleSheet::cssRules() const 00180 { 00181 if(!impl) return (CSSRuleListImpl*)0; 00182 return ((CSSStyleSheetImpl *)impl)->cssRules(); 00183 } 00184 00185 unsigned long CSSStyleSheet::insertRule( const DOMString &rule, unsigned long index ) 00186 { 00187 int exceptioncode = 0; 00188 if(!impl) return 0; 00189 unsigned long retval = ((CSSStyleSheetImpl *)impl)->insertRule( rule, index, exceptioncode ); 00190 if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET ) 00191 throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET ); 00192 if ( exceptioncode ) 00193 throw DOMException( exceptioncode ); 00194 return retval; 00195 } 00196 00197 void CSSStyleSheet::deleteRule( unsigned long index ) 00198 { 00199 int exceptioncode = 0; 00200 if(impl) 00201 ((CSSStyleSheetImpl *)impl)->deleteRule( index, exceptioncode ); 00202 if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET ) 00203 throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET ); 00204 if ( exceptioncode ) 00205 throw DOMException( exceptioncode ); 00206 } 00207 00208 DOM::DOMString CSSStyleSheet::charset() const { 00209 if(!impl) return DOMString(); 00210 return static_cast<CSSStyleSheetImpl *>(impl)->charset(); 00211 } 00212 00213 00214 StyleSheetList::StyleSheetList() 00215 { 00216 impl = 0; 00217 } 00218 00219 StyleSheetList::StyleSheetList(const StyleSheetList &other) 00220 { 00221 impl = other.impl; 00222 if(impl) impl->ref(); 00223 } 00224 00225 StyleSheetList::StyleSheetList(StyleSheetListImpl *i) 00226 { 00227 impl = i; 00228 if(impl) impl->ref(); 00229 } 00230 00231 StyleSheetList &StyleSheetList::operator = (const StyleSheetList &other) 00232 { 00233 if ( impl != other.impl ) { 00234 if(impl) impl->deref(); 00235 impl = other.impl; 00236 if(impl) impl->ref(); 00237 } 00238 return *this; 00239 } 00240 00241 StyleSheetList::~StyleSheetList() 00242 { 00243 if(impl) impl->deref(); 00244 } 00245 00246 unsigned long StyleSheetList::length() const 00247 { 00248 if(!impl) return 0; 00249 return ((StyleSheetListImpl *)impl)->length(); 00250 } 00251 00252 StyleSheet StyleSheetList::item( unsigned long index ) 00253 { 00254 if(!impl) return StyleSheet(); 00255 return ((StyleSheetListImpl *)impl)->item( index ); 00256 } 00257 00258 StyleSheetListImpl *StyleSheetList::handle() const 00259 { 00260 return impl; 00261 } 00262 00263 bool StyleSheetList::isNull() const 00264 { 00265 return (impl == 0); 00266 } 00267 00268 // ---------------------------------------------------------- 00269 00270 MediaList::MediaList() 00271 { 00272 impl = 0; 00273 } 00274 00275 MediaList::MediaList(const MediaList &other) 00276 { 00277 impl = other.impl; 00278 if(impl) impl->ref(); 00279 } 00280 00281 MediaList::MediaList(MediaListImpl *i) 00282 { 00283 impl = i; 00284 if(impl) impl->ref(); 00285 } 00286 00287 MediaList &MediaList::operator = (const MediaList &other) 00288 { 00289 if ( impl != other.impl ) { 00290 if(impl) impl->deref(); 00291 impl = other.impl; 00292 if(impl) impl->ref(); 00293 } 00294 return *this; 00295 } 00296 00297 MediaList::~MediaList() 00298 { 00299 if(impl) impl->deref(); 00300 } 00301 00302 DOM::DOMString MediaList::mediaText() const 00303 { 00304 if(!impl) return DOMString(); 00305 return static_cast<MediaListImpl *>(impl)->mediaText(); 00306 } 00307 00308 void MediaList::setMediaText(const DOM::DOMString &value ) 00309 { 00310 if(!impl) 00311 return; 00312 int exceptioncode = 0; 00313 static_cast<MediaListImpl *>(impl)->setMediaText( value, exceptioncode ); 00314 if ( exceptioncode ) 00315 throw DOMException( exceptioncode ); 00316 } 00317 00318 unsigned long MediaList::length() const 00319 { 00320 if(!impl) return 0; 00321 return ((MediaListImpl *)impl)->length(); 00322 } 00323 00324 DOM::DOMString MediaList::item(unsigned long index) const 00325 { 00326 if(!impl) return DOMString(); 00327 return ((MediaListImpl *)impl)->item( index ); 00328 } 00329 00330 void MediaList::deleteMedium(const DOM::DOMString &oldMedium) 00331 { 00332 if(!impl) 00333 return; 00334 int exceptioncode = 0; 00335 ((MediaListImpl *)impl)->deleteMedium( oldMedium, exceptioncode ); 00336 if ( exceptioncode ) 00337 throw DOMException( exceptioncode ); 00338 } 00339 00340 void MediaList::appendMedium(const DOM::DOMString &newMedium) 00341 { 00342 if(!impl) 00343 return; 00344 int exceptioncode = 0; 00345 ((MediaListImpl *)impl)->appendMedium( newMedium, exceptioncode ); 00346 if ( exceptioncode ) 00347 throw DOMException( exceptioncode ); 00348 } 00349 00350 MediaListImpl *MediaList::handle() const 00351 { 00352 return impl; 00353 } 00354 00355 bool MediaList::isNull() const 00356 { 00357 return (impl == 0); 00358 } 00359 00360 // ---------------------------------------------------------- 00361 00362 LinkStyle::LinkStyle() 00363 { 00364 node = 0; 00365 } 00366 00367 LinkStyle::LinkStyle(const LinkStyle &other) 00368 { 00369 node = other.node; 00370 if(node) node->ref(); 00371 } 00372 00373 LinkStyle & LinkStyle::operator = (const LinkStyle &other) 00374 { 00375 if ( node != other.node ) { 00376 if(node) node->deref(); 00377 node = other.node; 00378 if(node) node->ref(); 00379 } 00380 return *this; 00381 } 00382 00383 LinkStyle & LinkStyle::operator = (const Node &other) 00384 { 00385 if(node) node->deref(); 00386 node = 0; 00387 // ### add processing instructions 00388 NodeImpl *n = other.handle(); 00389 00390 // ### check link is really linking a style sheet 00391 if( n && n->isElementNode() && 00392 (n->id() == ID_STYLE || n->id() == ID_LINK) ) { 00393 node = n; 00394 if(node) node->ref(); 00395 } 00396 return *this; 00397 } 00398 00399 LinkStyle::~LinkStyle() 00400 { 00401 if(node) node->deref(); 00402 } 00403 00404 StyleSheet LinkStyle::sheet() 00405 { 00406 int id = node ? node->id() : 0; 00407 // ### add PI 00408 return 00409 ( id == ID_STYLE) ? 00410 static_cast<HTMLStyleElementImpl *>(node)->sheet() 00411 : ( (id == ID_LINK) ? 00412 static_cast<HTMLLinkElementImpl *>(node)->sheet() 00413 : StyleSheet() ); 00414 } 00415 00416 bool LinkStyle::isNull() const 00417 { 00418 return (node == 0); 00419 } 00420 00421 00422 // ---------------------------------------------------------- 00423 00424 DocumentStyle::DocumentStyle() 00425 { 00426 doc = 0; 00427 } 00428 00429 DocumentStyle::DocumentStyle(const DocumentStyle &other) 00430 { 00431 doc = other.doc; 00432 if(doc) doc->ref(); 00433 } 00434 00435 DocumentStyle & DocumentStyle::operator = (const DocumentStyle &other) 00436 { 00437 if ( doc != other.doc ) { 00438 if(doc) doc->deref(); 00439 doc = other.doc; 00440 if(doc) doc->ref(); 00441 } 00442 return *this; 00443 } 00444 00445 DocumentStyle & DocumentStyle::operator = (const Document &other) 00446 { 00447 DocumentImpl *odoc = static_cast<DocumentImpl *>(other.handle()); 00448 if ( doc != odoc ) { 00449 if(doc) doc->deref(); 00450 doc = odoc; 00451 if(doc) doc->ref(); 00452 } 00453 return *this; 00454 } 00455 00456 DocumentStyle::~DocumentStyle() 00457 { 00458 if(doc) doc->deref(); 00459 } 00460 00461 StyleSheetList DocumentStyle::styleSheets() const 00462 { 00463 return doc->styleSheets(); 00464 } 00465 00466 DOMString DocumentStyle::preferredStylesheetSet() const 00467 { 00468 return doc->preferredStylesheetSet(); 00469 } 00470 00471 void DocumentStyle::setSelectedStylesheetSet(const DOMString& aStr) 00472 { 00473 return doc->setSelectedStylesheetSet(aStr); 00474 } 00475 00476 DOMString DocumentStyle::selectedStylesheetSet() const 00477 { 00478 return doc->selectedStylesheetSet(); 00479 }