• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef StyleRuleImport_h
23 #define StyleRuleImport_h
24 
25 #include "core/css/StyleRule.h"
26 #include "core/fetch/ResourcePtr.h"
27 #include "core/fetch/StyleSheetResourceClient.h"
28 #include "platform/heap/Handle.h"
29 
30 namespace blink {
31 
32 class CSSStyleSheetResource;
33 class MediaQuerySet;
34 class StyleSheetContents;
35 
36 class StyleRuleImport : public StyleRuleBase {
37     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
38 public:
39     static PassRefPtrWillBeRawPtr<StyleRuleImport> create(const String& href, PassRefPtrWillBeRawPtr<MediaQuerySet>);
40 
41     ~StyleRuleImport();
42 
parentStyleSheet()43     StyleSheetContents* parentStyleSheet() const { return m_parentStyleSheet; }
setParentStyleSheet(StyleSheetContents * sheet)44     void setParentStyleSheet(StyleSheetContents* sheet) { ASSERT(sheet); m_parentStyleSheet = sheet; }
clearParentStyleSheet()45     void clearParentStyleSheet() { m_parentStyleSheet = nullptr; }
46 
href()47     String href() const { return m_strHref; }
styleSheet()48     StyleSheetContents* styleSheet() const { return m_styleSheet.get(); }
49 
50     bool isLoading() const;
mediaQueries()51     MediaQuerySet* mediaQueries() { return m_mediaQueries.get(); }
52 
53     void requestStyleSheet();
54 
55     void traceAfterDispatch(Visitor*);
56 
57 private:
58     // FIXME: inherit from StyleSheetResourceClient directly to eliminate raw back pointer, as there are no space savings in this.
59     // NOTE: We put the StyleSheetResourceClient in a member instead of inheriting from it
60     // to avoid adding a vptr to StyleRuleImport.
61     class ImportedStyleSheetClient FINAL : public StyleSheetResourceClient {
62     public:
ImportedStyleSheetClient(StyleRuleImport * ownerRule)63         ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { }
~ImportedStyleSheetClient()64         virtual ~ImportedStyleSheetClient() { }
setCSSStyleSheet(const String & href,const KURL & baseURL,const String & charset,const CSSStyleSheetResource * sheet)65         virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CSSStyleSheetResource* sheet) OVERRIDE
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 KURL& baseURL, const String& charset, const CSSStyleSheetResource*);
74     friend class ImportedStyleSheetClient;
75 
76     StyleRuleImport(const String& href, PassRefPtrWillBeRawPtr<MediaQuerySet>);
77 
78     RawPtrWillBeMember<StyleSheetContents> m_parentStyleSheet;
79 
80     ImportedStyleSheetClient m_styleSheetClient;
81     String m_strHref;
82     RefPtrWillBeMember<MediaQuerySet> m_mediaQueries;
83     RefPtrWillBeMember<StyleSheetContents> m_styleSheet;
84     ResourcePtr<CSSStyleSheetResource> m_resource;
85     bool m_loading;
86 };
87 
88 DEFINE_STYLE_RULE_TYPE_CASTS(Import);
89 
90 } // namespace blink
91 
92 #endif
93