2006-05-15  Eric Seidel  <eseidel@apple.com>

        Reviewed by mjs.

        Split css_stylesheetimpl.* into separate files (one per class).
        http://bugzilla.opendarwin.org/show_bug.cgi?id=8933

        * WebCore.vcproj/WebCore/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * css/CSSStyleSheet.cpp: Added.
        (WebCore::CSSStyleSheet::CSSStyleSheet):
        (WebCore::CSSStyleSheet::addRule):
        (WebCore::CSSStyleSheet::deleteRule):
        (WebCore::CSSStyleSheet::parseString):
        (WebCore::CSSStyleSheet::docLoader):
        * css/CSSStyleSheet.h: Added.
        * css/MediaList.cpp: Added.
        (WebCore::MediaList::MediaList):
        (WebCore::MediaList::contains):
        (WebCore::MediaList::parentStyleSheet):
        (WebCore::MediaList::parentRule):
        (WebCore::MediaList::deleteMedium):
        (WebCore::MediaList::setMediaText):
        * css/MediaList.h: Added.
        * css/StyleSheet.cpp: Added.
        (WebCore::StyleSheet::StyleSheet):
        (WebCore::StyleSheet::parentStyleSheet):
        (WebCore::StyleSheet::setMedia):
        * css/StyleSheet.h: Added.
        (WebCore::StyleSheet::ownerNode):
        * css/StyleSheetList.cpp: Added.
        (WebCore::StyleSheetList::~StyleSheetList):
        (WebCore::StyleSheetList::add):
        (WebCore::StyleSheetList::remove):
        (WebCore::StyleSheetList::item):
        * css/StyleSheetList.h: Added.
        * css/css_stylesheetimpl.cpp: Removed.
        * css/css_stylesheetimpl.h: Removed.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@14401 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/css/CSSStyleSheet.cpp b/WebCore/css/CSSStyleSheet.cpp
new file mode 100644
index 0000000..0a3318d
--- /dev/null
+++ b/WebCore/css/CSSStyleSheet.cpp
@@ -0,0 +1,186 @@
+/**
+ * This file is part of the DOM implementation for KDE.
+ *
+ * (C) 1999-2003 Lars Knoll (knoll@kde.org)
+ * Copyright (C) 2004, 2006 Apple Computer, Inc.
+ *
+ * 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.
+ */
+#include "config.h"
+#include "CSSStyleSheet.h"
+
+#include "css_ruleimpl.h"
+#include "CSSParser.h"
+#include "Document.h"
+#include "ExceptionCode.h"
+#include "Node.h"
+
+namespace WebCore {
+
+CSSStyleSheet::CSSStyleSheet(CSSStyleSheet* parentSheet, String href)
+    : StyleSheet(parentSheet, href)
+    , m_doc(parentSheet ? parentSheet->doc() : 0)
+    , m_implicit(false)
+    , m_namespaces(0)
+{
+}
+
+CSSStyleSheet::CSSStyleSheet(Node *parentNode, String href, bool _implicit)
+    : StyleSheet(parentNode, href)
+    , m_doc(parentNode->document())
+    , m_implicit(_implicit) 
+    , m_namespaces(0)
+{
+}
+
+CSSStyleSheet::CSSStyleSheet(CSSRule *ownerRule, String href)
+    : StyleSheet(ownerRule, href)
+    , m_doc(0)
+    , m_implicit(false)
+    , m_namespaces(0)
+{
+}
+
+CSSRule *CSSStyleSheet::ownerRule() const
+{
+    return (parent() && parent()->isRule()) ? static_cast<CSSRule *>(parent()) : 0;
+}
+
+unsigned CSSStyleSheet::insertRule(const String& rule, unsigned index, ExceptionCode& ec)
+{
+    ec = 0;
+    if (index > length()) {
+        ec = INDEX_SIZE_ERR;
+        return 0;
+    }
+    CSSParser p(useStrictParsing());
+    RefPtr<CSSRule> r = p.parseRule(this, rule);
+
+    if (!r) {
+        ec = SYNTAX_ERR;
+        return 0;
+    }
+
+    // ###
+    // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified index e.g. if an
+    //@import rule is inserted after a standard rule set or other at-rule.
+    insert(index, r.release());
+    
+    styleSheetChanged();
+    
+    return index;
+}
+
+unsigned CSSStyleSheet::addRule(const String &selector, const String &style, int index, ExceptionCode& ec)
+{
+    if (index == -1)
+        index = length();
+    return insertRule(selector + " { " + style + " }", index, ec);
+}
+
+CSSRuleList *CSSStyleSheet::cssRules()
+{
+    return new CSSRuleList(this);
+}
+
+void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
+{
+    if (index >= length()) {
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+
+    ec = 0;
+    remove(index);
+    styleSheetChanged();
+}
+
+void CSSStyleSheet::addNamespace(CSSParser* p, const AtomicString& prefix, const AtomicString& uri)
+{
+    if (uri.isEmpty())
+        return;
+
+    m_namespaces = new CSSNamespace(prefix, uri, m_namespaces);
+    
+    if (prefix.isEmpty())
+        // Set the default namespace on the parser so that selectors that omit namespace info will
+        // be able to pick it up easily.
+        p->defaultNamespace = uri;
+}
+
+const AtomicString& CSSStyleSheet::determineNamespace(const AtomicString& prefix)
+{
+    if (prefix.isEmpty())
+        return nullAtom; // No namespace. If an element/attribute has a namespace, we won't match it.
+    else if (prefix == starAtom)
+        return starAtom; // We'll match any namespace.
+    else if (m_namespaces) {
+        CSSNamespace* ns = m_namespaces->namespaceForPrefix(prefix);
+        if (ns)
+            return ns->uri();
+    }
+    return nullAtom; // Assume we wont match any namespaces.
+}
+
+bool CSSStyleSheet::parseString(const String &string, bool strict)
+{
+    setStrictParsing(strict);
+    CSSParser p(strict);
+    p.parseSheet(this, string);
+    return true;
+}
+
+bool CSSStyleSheet::isLoading()
+{
+    unsigned len = length();
+    for (unsigned i = 0; i < len; ++i) {
+        StyleBase* rule = item(i);
+        if (rule->isImportRule() && static_cast<CSSImportRule*>(rule)->isLoading())
+            return true;
+    }
+    return false;
+}
+
+void CSSStyleSheet::checkLoaded()
+{
+    if (isLoading())
+        return;
+    if (parent())
+        parent()->checkLoaded();
+    if (m_parentNode)
+        m_parentNode->sheetLoaded();
+}
+
+DocLoader *CSSStyleSheet::docLoader()
+{
+    if (!m_doc) // doc is 0 for the user- and default-sheet!
+        return 0;
+
+    // ### remove? (clients just use sheet->doc()->docLoader())
+    return m_doc->docLoader();
+}
+
+void CSSStyleSheet::styleSheetChanged()
+{
+    /* FIXME: We don't need to do everything updateStyleSelector does,
+     * basically we just need to recreate the document's selector with the
+     * already existing style sheets.
+     */
+    if (m_doc)
+        m_doc->updateStyleSelector();
+}
+
+}