1 /** 2 * (C) 1999-2003 Lars Knoll (knoll (at) kde.org) 3 * Copyright (C) 2004, 2006 Apple Computer, Inc. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 #include "config.h" 21 #include "StyleSheet.h" 22 23 #include "MediaList.h" 24 #include "Node.h" 25 26 namespace WebCore { 27 28 StyleSheet::StyleSheet(StyleSheet* parentSheet, const String& originalURL, const KURL& finalURL) 29 : StyleList(parentSheet) 30 , m_parentNode(0) 31 , m_originalURL(originalURL) 32 , m_finalURL(finalURL) 33 , m_disabled(false) 34 { 35 } 36 37 StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL) 38 : StyleList(0) 39 , m_parentNode(parentNode) 40 , m_originalURL(originalURL) 41 , m_finalURL(finalURL) 42 , m_disabled(false) 43 { 44 } 45 46 StyleSheet::StyleSheet(StyleBase* owner, const String& originalURL, const KURL& finalURL) 47 : StyleList(owner) 48 , m_parentNode(0) 49 , m_originalURL(originalURL) 50 , m_finalURL(finalURL) 51 , m_disabled(false) 52 { 53 } 54 55 StyleSheet::~StyleSheet() 56 { 57 if (m_media) 58 m_media->setParent(0); 59 60 // For style rules outside the document, .parentStyleSheet can become null even if the style rule 61 // is still observable from JavaScript. This matches the behavior of .parentNode for nodes, but 62 // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection. 63 for (unsigned i = 0; i < length(); ++i) { 64 ASSERT(item(i)->parent() == this); 65 item(i)->setParent(0); 66 } 67 } 68 69 StyleSheet* StyleSheet::parentStyleSheet() const 70 { 71 return (parent() && parent()->isStyleSheet()) ? static_cast<StyleSheet*>(parent()) : 0; 72 } 73 74 void StyleSheet::setMedia(PassRefPtr<MediaList> media) 75 { 76 if (m_media) 77 m_media->setParent(0); 78 79 m_media = media; 80 m_media->setParent(this); 81 } 82 83 KURL StyleSheet::completeURL(const String& url) const 84 { 85 // Always return a null URL when passed a null string. 86 // FIXME: Should we change the KURL constructor to have this behavior? 87 // See also Document::completeURL(const String&) 88 if (url.isNull()) 89 return KURL(); 90 return KURL(baseURL(), url); 91 } 92 93 } 94