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 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 "core/css/CSSImportRule.h"
24
25 #include "core/css/CSSStyleSheet.h"
26 #include "core/css/MediaList.h"
27 #include "core/css/StyleRuleImport.h"
28 #include "core/css/StyleSheetContents.h"
29 #include "wtf/text/StringBuilder.h"
30
31 namespace blink {
32
CSSImportRule(StyleRuleImport * importRule,CSSStyleSheet * parent)33 CSSImportRule::CSSImportRule(StyleRuleImport* importRule, CSSStyleSheet* parent)
34 : CSSRule(parent)
35 , m_importRule(importRule)
36 {
37 }
38
~CSSImportRule()39 CSSImportRule::~CSSImportRule()
40 {
41 #if !ENABLE(OILPAN)
42 if (m_styleSheetCSSOMWrapper)
43 m_styleSheetCSSOMWrapper->clearOwnerRule();
44
45 if (m_mediaCSSOMWrapper)
46 m_mediaCSSOMWrapper->clearParentRule();
47 #endif // ENABLE(OILPAN)
48 }
49
href() const50 String CSSImportRule::href() const
51 {
52 return m_importRule->href();
53 }
54
media() const55 MediaList* CSSImportRule::media() const
56 {
57 if (!m_mediaCSSOMWrapper)
58 m_mediaCSSOMWrapper = MediaList::create(m_importRule->mediaQueries(), const_cast<CSSImportRule*>(this));
59 return m_mediaCSSOMWrapper.get();
60 }
61
cssText() const62 String CSSImportRule::cssText() const
63 {
64 StringBuilder result;
65 result.appendLiteral("@import url(\"");
66 result.append(m_importRule->href());
67 result.appendLiteral("\")");
68
69 if (m_importRule->mediaQueries()) {
70 String mediaText = m_importRule->mediaQueries()->mediaText();
71 if (!mediaText.isEmpty()) {
72 result.append(' ');
73 result.append(mediaText);
74 }
75 }
76 result.append(';');
77
78 return result.toString();
79 }
80
styleSheet() const81 CSSStyleSheet* CSSImportRule::styleSheet() const
82 {
83 if (!m_importRule->styleSheet())
84 return 0;
85
86 if (!m_styleSheetCSSOMWrapper)
87 m_styleSheetCSSOMWrapper = CSSStyleSheet::create(m_importRule->styleSheet(), const_cast<CSSImportRule*>(this));
88 return m_styleSheetCSSOMWrapper.get();
89 }
90
reattach(StyleRuleBase *)91 void CSSImportRule::reattach(StyleRuleBase*)
92 {
93 // FIXME: Implement when enabling caching for stylesheets with import rules.
94 ASSERT_NOT_REACHED();
95 }
96
trace(Visitor * visitor)97 void CSSImportRule::trace(Visitor* visitor)
98 {
99 visitor->trace(m_importRule);
100 visitor->trace(m_mediaCSSOMWrapper);
101 visitor->trace(m_styleSheetCSSOMWrapper);
102 CSSRule::trace(visitor);
103 }
104
105 } // namespace blink
106