1 /**
2 * This file is part of the DOM implementation for KDE.
3 *
4 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24 #include "StyleSheetList.h"
25
26 #include "CSSStyleSheet.h"
27 #include "Document.h"
28 #include "HTMLNames.h"
29 #include "HTMLStyleElement.h"
30 #include "PlatformString.h"
31
32 namespace WebCore {
33
34 using namespace HTMLNames;
35
StyleSheetList(Document * doc)36 StyleSheetList::StyleSheetList(Document* doc)
37 : m_doc(doc)
38 {
39 }
40
~StyleSheetList()41 StyleSheetList::~StyleSheetList()
42 {
43 }
44
documentDestroyed()45 void StyleSheetList::documentDestroyed()
46 {
47 m_doc = 0;
48 }
49
length() const50 unsigned StyleSheetList::length() const
51 {
52 return m_sheets.size();
53 }
54
item(unsigned index)55 StyleSheet* StyleSheetList::item(unsigned index)
56 {
57 return index < length() ? m_sheets[index].get() : 0;
58 }
59
getNamedItem(const String & name) const60 HTMLStyleElement* StyleSheetList::getNamedItem(const String& name) const
61 {
62 if (!m_doc)
63 return 0;
64
65 // IE also supports retrieving a stylesheet by name, using the name/id of the <style> tag
66 // (this is consistent with all the other collections)
67 // ### Bad implementation because returns a single element (are IDs always unique?)
68 // and doesn't look for name attribute.
69 // But unicity of stylesheet ids is good practice anyway ;)
70
71 Element* element = m_doc->getElementById(name);
72 if (element && element->hasTagName(styleTag))
73 return static_cast<HTMLStyleElement*>(element);
74 return 0;
75 }
76
77 } // namespace WebCore
78