StyleSheetList.cpp [plain text]
#include "config.h"
#include "StyleSheetList.h"
#include "CSSStyleSheet.h"
#include "Document.h"
#include "DocumentStyleSheetCollection.h"
#include "HTMLNames.h"
#include "HTMLStyleElement.h"
#include <wtf/text/WTFString.h>
namespace WebCore {
using namespace HTMLNames;
StyleSheetList::StyleSheetList(Document* document)
: m_document(document)
{
}
StyleSheetList::~StyleSheetList()
{
}
inline const Vector<RefPtr<StyleSheet>>& StyleSheetList::styleSheets() const
{
if (!m_document)
return m_detachedStyleSheets;
return m_document->styleSheetCollection().styleSheetsForStyleSheetList();
}
void StyleSheetList::detachFromDocument()
{
m_detachedStyleSheets = m_document->styleSheetCollection().styleSheetsForStyleSheetList();
m_document = 0;
}
unsigned StyleSheetList::length() const
{
return styleSheets().size();
}
StyleSheet* StyleSheetList::item(unsigned index)
{
const Vector<RefPtr<StyleSheet>>& sheets = styleSheets();
return index < sheets.size() ? sheets[index].get() : 0;
}
HTMLStyleElement* StyleSheetList::getNamedItem(const String& name) const
{
if (!m_document)
return 0;
Element* element = m_document->getElementById(name);
if (element && isHTMLStyleElement(element))
return toHTMLStyleElement(element);
return 0;
}
}