1/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "config.h"
23#include "CSSImportRule.h"
24
25#include "CSSStyleSheet.h"
26#include "MediaList.h"
27#include "StyleRuleImport.h"
28#include "StyleSheetContents.h"
29#include <wtf/text/StringBuilder.h>
30
31namespace WebCore {
32
33CSSImportRule::CSSImportRule(StyleRuleImport& importRule, CSSStyleSheet* parent)
34 : CSSRule(parent)
35 , m_importRule(importRule)
36{
37}
38
39CSSImportRule::~CSSImportRule()
40{
41 if (m_styleSheetCSSOMWrapper)
42 m_styleSheetCSSOMWrapper->clearOwnerRule();
43 if (m_mediaCSSOMWrapper)
44 m_mediaCSSOMWrapper->clearParentRule();
45}
46
47String CSSImportRule::href() const
48{
49 return m_importRule.get().href();
50}
51
52MediaList& CSSImportRule::media() const
53{
54 if (!m_mediaCSSOMWrapper)
55 m_mediaCSSOMWrapper = MediaList::create(m_importRule.get().mediaQueries(), const_cast<CSSImportRule*>(this));
56 return *m_mediaCSSOMWrapper;
57}
58
59String CSSImportRule::cssText() const
60{
61 StringBuilder result;
62 result.appendLiteral("@import url(\"");
63 result.append(m_importRule.get().href());
64 result.appendLiteral("\")");
65
66 if (m_importRule.get().mediaQueries()) {
67 String mediaText = m_importRule.get().mediaQueries()->mediaText();
68 if (!mediaText.isEmpty()) {
69 result.append(' ');
70 result.append(mediaText);
71 }
72 }
73 result.append(';');
74
75 return result.toString();
76}
77
78CSSStyleSheet* CSSImportRule::styleSheet() const
79{
80 if (!m_importRule.get().styleSheet())
81 return 0;
82
83 if (!m_styleSheetCSSOMWrapper)
84 m_styleSheetCSSOMWrapper = CSSStyleSheet::create(*m_importRule.get().styleSheet(), const_cast<CSSImportRule*>(this));
85 return m_styleSheetCSSOMWrapper.get();
86}
87
88void CSSImportRule::reattach(StyleRuleBase&)
89{
90 // FIXME: Implement when enabling caching for stylesheets with import rules.
91 ASSERT_NOT_REACHED();
92}
93
94} // namespace WebCore
95