1 | /*
|
---|
2 | * (C) 1999-2003 Lars Knoll ([email protected])
|
---|
3 | * (C) 2002-2003 Dirk Mueller ([email protected])
|
---|
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>&&, std::optional<CascadeLayerName>&&);
|
---|
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 | void cancelLoad();
|
---|
46 |
|
---|
47 | String href() const { return m_strHref; }
|
---|
48 | StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
|
---|
49 |
|
---|
50 | bool isLoading() const;
|
---|
51 | MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
|
---|
52 |
|
---|
53 | void requestStyleSheet();
|
---|
54 | const CachedCSSStyleSheet* cachedCSSStyleSheet() const { return m_cachedSheet.get(); }
|
---|
55 |
|
---|
56 | const std::optional<CascadeLayerName>& cascadeLayerName() const { return m_cascadeLayerName; }
|
---|
57 |
|
---|
58 | private:
|
---|
59 | // NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it
|
---|
60 | // to avoid adding a vptr to StyleRuleImport.
|
---|
61 | class ImportedStyleSheetClient final : public CachedStyleSheetClient {
|
---|
62 | public:
|
---|
63 | ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { }
|
---|
64 | virtual ~ImportedStyleSheetClient() = default;
|
---|
65 | void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet) final
|
---|
66 | {
|
---|
67 | m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet);
|
---|
68 | }
|
---|
69 | private:
|
---|
70 | StyleRuleImport* m_ownerRule;
|
---|
71 | };
|
---|
72 |
|
---|
73 | void setCSSStyleSheet(const String& href, const URL& baseURL, const String& charset, const CachedCSSStyleSheet*);
|
---|
74 | friend class ImportedStyleSheetClient;
|
---|
75 |
|
---|
76 | StyleRuleImport(const String& href, Ref<MediaQuerySet>&&, std::optional<CascadeLayerName>&&);
|
---|
77 |
|
---|
78 | StyleSheetContents* m_parentStyleSheet { nullptr };
|
---|
79 |
|
---|
80 | ImportedStyleSheetClient m_styleSheetClient;
|
---|
81 | String m_strHref;
|
---|
82 | RefPtr<MediaQuerySet> m_mediaQueries;
|
---|
83 | RefPtr<StyleSheetContents> m_styleSheet;
|
---|
84 | std::optional<CascadeLayerName> m_cascadeLayerName;
|
---|
85 | CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
|
---|
86 | bool m_loading { false };
|
---|
87 | };
|
---|
88 |
|
---|
89 | } // namespace WebCore
|
---|
90 |
|
---|
91 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleImport)
|
---|
92 | static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isImportRule(); }
|
---|
93 | SPECIALIZE_TYPE_TRAITS_END()
|
---|