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 CSSStyleSheet::CSSStyleSheet() : StyleSheet() 00126 { 00127 } 00128 00129 CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet &other) : StyleSheet(other) 00130 { 00131 } 00132 00133 CSSStyleSheet::CSSStyleSheet(const StyleSheet &other) 00134 { 00135 if (!other.isCSSStyleSheet()) 00136 impl = 0; 00137 else 00138 operator=(other); 00139 } 00140 00141 CSSStyleSheet::CSSStyleSheet(CSSStyleSheetImpl *impl) : StyleSheet(impl) 00142 { 00143 } 00144 00145 CSSStyleSheet &CSSStyleSheet::operator = (const CSSStyleSheet &other) 00146 { 00147 StyleSheet::operator = (other); 00148 return *this; 00149 } 00150 00151 CSSStyleSheet &CSSStyleSheet::operator = (const StyleSheet &other) 00152 { 00153 if(!other.handle()->isCSSStyleSheet()) 00154 { 00155 if(impl) impl->deref(); 00156 impl = 0; 00157 } else { 00158 StyleSheet::operator = (other); 00159 } 00160 return *this; 00161 } 00162 00163 CSSStyleSheet::~CSSStyleSheet() 00164 { 00165 } 00166 00167 CSSRule CSSStyleSheet::ownerRule() const 00168 { 00169 if(!impl) return 0; 00170 return ((CSSStyleSheetImpl *)impl)->ownerRule(); 00171 } 00172 00173 CSSRuleList CSSStyleSheet::cssRules() const 00174 { 00175 if(!impl) return (CSSRuleListImpl*)0; 00176 return ((CSSStyleSheetImpl *)impl)->cssRules(); 00177 } 00178 00179 unsigned long CSSStyleSheet::insertRule( const DOMString &rule, unsigned long index ) 00180 { 00181 int exceptioncode = 0; 00182 if(!impl) return 0; 00183 unsigned long retval = ((CSSStyleSheetImpl *)impl)->insertRule( rule, index, exceptioncode ); 00184 if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET ) 00185 throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET ); 00186 if ( exceptioncode ) 00187 throw DOMException( exceptioncode ); 00188 return retval; 00189 } 00190 00191 void CSSStyleSheet::deleteRule( unsigned long index ) 00192 { 00193 int exceptioncode = 0; 00194 if(impl) 00195 ((CSSStyleSheetImpl *)impl)->deleteRule( index, exceptioncode ); 00196 if ( exceptioncode >= CSSException::_EXCEPTION_OFFSET ) 00197 throw CSSException( exceptioncode - CSSException::_EXCEPTION_OFFSET ); 00198 if ( exceptioncode ) 00199 throw DOMException( exceptioncode ); 00200 } 00201 00202 00203 00204 StyleSheetList::StyleSheetList() 00205 { 00206 impl = 0; 00207 } 00208 00209 StyleSheetList::StyleSheetList(const StyleSheetList &other) 00210 { 00211 impl = other.impl; 00212 if(impl) impl->ref(); 00213 } 00214 00215 StyleSheetList::StyleSheetList(StyleSheetListImpl *i) 00216 { 00217 impl = i; 00218 if(impl) impl->ref(); 00219 } 00220 00221 StyleSheetList &StyleSheetList::operator = (const StyleSheetList &other) 00222 { 00223 if ( impl != other.impl ) { 00224 if(impl) impl->deref(); 00225 impl = other.impl; 00226 if(impl) impl->ref(); 00227 } 00228 return *this; 00229 } 00230 00231 StyleSheetList::~StyleSheetList() 00232 { 00233 if(impl) impl->deref(); 00234 } 00235 00236 unsigned long StyleSheetList::length() const 00237 { 00238 if(!impl) return 0; 00239 return ((StyleSheetListImpl *)impl)->length(); 00240 } 00241 00242 StyleSheet StyleSheetList::item( unsigned long index ) 00243 { 00244 if(!impl) return StyleSheet(); 00245 return ((StyleSheetListImpl *)impl)->item( index ); 00246 } 00247 00248 StyleSheetListImpl *StyleSheetList::handle() const 00249 { 00250 return impl; 00251 } 00252 00253 bool StyleSheetList::isNull() const 00254 { 00255 return (impl == 0); 00256 } 00257 00258 // ---------------------------------------------------------- 00259 00260 MediaList::MediaList() 00261 { 00262 impl = 0; 00263 } 00264 00265 MediaList::MediaList(const MediaList &other) 00266 { 00267 impl = other.impl; 00268 if(impl) impl->ref(); 00269 } 00270 00271 MediaList::MediaList(MediaListImpl *i) 00272 { 00273 impl = i; 00274 if(impl) impl->ref(); 00275 } 00276 00277 MediaList &MediaList::operator = (const MediaList &other) 00278 { 00279 if ( impl != other.impl ) { 00280 if(impl) impl->deref(); 00281 impl = other.impl; 00282 if(impl) impl->ref(); 00283 } 00284 return *this; 00285 } 00286 00287 MediaList::~MediaList() 00288 { 00289 if(impl) impl->deref(); 00290 } 00291 00292 DOM::DOMString MediaList::mediaText() const 00293 { 00294 if(!impl) return DOMString(); 00295 return static_cast<MediaListImpl *>(impl)->mediaText(); 00296 } 00297 00298 void MediaList::setMediaText(const DOM::DOMString &value ) 00299 { 00300 if(impl) 00301 static_cast<MediaListImpl *>(impl)->setMediaText( value ); 00302 } 00303 00304 unsigned long MediaList::length() const 00305 { 00306 if(!impl) return 0; 00307 return ((MediaListImpl *)impl)->length(); 00308 } 00309 00310 DOM::DOMString MediaList::item(unsigned long index) const 00311 { 00312 if(!impl) return DOMString(); 00313 return ((MediaListImpl *)impl)->item( index ); 00314 } 00315 00316 void MediaList::deleteMedium(const DOM::DOMString &oldMedium) 00317 { 00318 if(impl) 00319 ((MediaListImpl *)impl)->deleteMedium( oldMedium ); 00320 } 00321 00322 void MediaList::appendMedium(const DOM::DOMString &newMedium) 00323 { 00324 if(impl) 00325 ((MediaListImpl *)impl)->appendMedium( newMedium ); 00326 } 00327 00328 MediaListImpl *MediaList::handle() const 00329 { 00330 return impl; 00331 } 00332 00333 bool MediaList::isNull() const 00334 { 00335 return (impl == 0); 00336 } 00337 00338 // ---------------------------------------------------------- 00339 00340 LinkStyle::LinkStyle() 00341 { 00342 node = 0; 00343 } 00344 00345 LinkStyle::LinkStyle(const LinkStyle &other) 00346 { 00347 node = other.node; 00348 if(node) node->ref(); 00349 } 00350 00351 LinkStyle & LinkStyle::operator = (const LinkStyle &other) 00352 { 00353 if ( node != other.node ) { 00354 if(node) node->deref(); 00355 node = other.node; 00356 if(node) node->ref(); 00357 } 00358 return *this; 00359 } 00360 00361 LinkStyle & LinkStyle::operator = (const Node &other) 00362 { 00363 if(node) node->deref(); 00364 node = 0; 00365 // ### add processing instructions 00366 NodeImpl *n = other.handle(); 00367 00368 // ### check link is really linking a style sheet 00369 if( n && n->isElementNode() && 00370 (n->id() == ID_STYLE || n->id() == ID_LINK) ) { 00371 node = n; 00372 if(node) node->ref(); 00373 } 00374 return *this; 00375 } 00376 00377 LinkStyle::~LinkStyle() 00378 { 00379 if(node) node->deref(); 00380 } 00381 00382 StyleSheet LinkStyle::sheet() 00383 { 00384 int id = node ? node->id() : 0; 00385 // ### add PI 00386 return 00387 ( id == ID_STYLE) ? 00388 static_cast<HTMLStyleElementImpl *>(node)->sheet() 00389 : ( (id == ID_LINK) ? 00390 static_cast<HTMLLinkElementImpl *>(node)->sheet() 00391 : StyleSheet() ); 00392 } 00393 00394 bool LinkStyle::isNull() const 00395 { 00396 return (node == 0); 00397 } 00398 00399 00400 // ---------------------------------------------------------- 00401 00402 DocumentStyle::DocumentStyle() 00403 { 00404 doc = 0; 00405 } 00406 00407 DocumentStyle::DocumentStyle(const DocumentStyle &other) 00408 { 00409 doc = other.doc; 00410 if(doc) doc->ref(); 00411 } 00412 00413 DocumentStyle & DocumentStyle::operator = (const DocumentStyle &other) 00414 { 00415 if ( doc != other.doc ) { 00416 if(doc) doc->deref(); 00417 doc = other.doc; 00418 if(doc) doc->ref(); 00419 } 00420 return *this; 00421 } 00422 00423 DocumentStyle & DocumentStyle::operator = (const Document &other) 00424 { 00425 DocumentImpl *odoc = static_cast<DocumentImpl *>(other.handle()); 00426 if ( doc != odoc ) { 00427 if(doc) doc->deref(); 00428 doc = odoc; 00429 if(doc) doc->ref(); 00430 } 00431 return *this; 00432 } 00433 00434 DocumentStyle::~DocumentStyle() 00435 { 00436 if(doc) doc->deref(); 00437 } 00438 00439 StyleSheetList DocumentStyle::styleSheets() 00440 { 00441 return doc->styleSheets(); 00442 } 00443 00444 DOMString DocumentStyle::preferredStylesheetSet() const 00445 { 00446 return doc->preferredStylesheetSet(); 00447 } 00448 00449 void DocumentStyle::setSelectedStylesheetSet(const DOMString& aStr) 00450 { 00451 return doc->setSelectedStylesheetSet(aStr); 00452 } 00453 00454 DOMString DocumentStyle::selectedStylesheetSet() const 00455 { 00456 return doc->selectedStylesheetSet(); 00457 }