1 | /* |
2 | * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 | * (C) 2002-2003 Dirk Mueller (mueller@kde.org) |
4 | * Copyright (C) 2002, 2006, 2008, 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 | #pragma once |
23 | |
24 | #include "CachedResourceHandle.h" |
25 | #include "CachedStyleSheetClient.h" |
26 | #include "StyleRule.h" |
27 | #include <wtf/TypeCasts.h> |
28 | |
29 | namespace WebCore { |
30 | |
31 | class CachedCSSStyleSheet; |
32 | class MediaQuerySet; |
33 | class StyleSheetContents; |
34 | |
35 | class StyleRuleImport final : public StyleRuleBase { |
36 | WTF_MAKE_FAST_ALLOCATED; |
37 | public: |
38 | static Ref<StyleRuleImport> create(const String& href, Ref<MediaQuerySet>&&); |
39 | |
40 | ~StyleRuleImport(); |
41 | |
42 | StyleSheetContents* parentStyleSheet() const { return m_parentStyleSheet; } |
43 | void setParentStyleSheet(StyleSheetContents* sheet) { ASSERT(sheet); m_parentStyleSheet = sheet; } |
44 | void clearParentStyleSheet() { m_parentStyleSheet = 0; } |
45 | |
46 | String href() const { return m_strHref; } |
47 | StyleSheetContents* styleSheet() const { return m_styleSheet.get(); } |
48 | |
49 | bool isLoading() const; |
50 | MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); } |
51 | |
52 | void requestStyleSheet(); |
53 | const CachedCSSStyleSheet* cachedCSSStyleSheet() const { return m_cachedSheet.get(); } |
54 | |
55 | private: |
56 | // NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it |
57 | // to avoid adding a vptr to StyleRuleImport. |
58 | class ImportedStyleSheetClient final : public CachedStyleSheetClient { |
59 | public: |
60 | ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { } |
61 | virtual ~ImportedStyleSheetClient() = default; |
62 | void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet) final |
63 | { |
64 | m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet); |
65 | } |
66 | private: |
67 | StyleRuleImport* m_ownerRule; |
68 | }; |
69 | |
70 | void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet*); |
71 | friend class ImportedStyleSheetClient; |
72 | |
73 | StyleRuleImport(const String& href, Ref<MediaQuerySet>&&); |
74 | |
75 | StyleSheetContents* m_parentStyleSheet; |
76 | |
77 | ImportedStyleSheetClient m_styleSheetClient; |
78 | String m_strHref; |
79 | RefPtr<MediaQuerySet> m_mediaQueries; |
80 | RefPtr<StyleSheetContents> m_styleSheet; |
81 | CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; |
82 | bool m_loading; |
83 | }; |
84 | |
85 | } // namespace WebCore |
86 | |
87 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleImport) |
88 | static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isImportRule(); } |
89 | SPECIALIZE_TYPE_TRAITS_END() |
90 | |