1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4  * All rights reserved.
5  * Copyright (C) 2013 Google Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_DEFAULT_STYLE_SHEETS_H_
25 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_DEFAULT_STYLE_SHEETS_H_
26 
27 #include "third_party/blink/renderer/core/core_export.h"
28 #include "third_party/blink/renderer/core/style/computed_style_constants.h"
29 #include "third_party/blink/renderer/platform/heap/handle.h"
30 #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
31 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
32 
33 namespace blink {
34 
35 class Element;
36 class RuleSet;
37 class StyleSheetContents;
38 
39 class CSSDefaultStyleSheets final
40     : public GarbageCollected<CSSDefaultStyleSheets> {
41  public:
42   CORE_EXPORT static CSSDefaultStyleSheets& Instance();
43 
44   CSSDefaultStyleSheets();
45   CSSDefaultStyleSheets(const CSSDefaultStyleSheets&) = delete;
46   CSSDefaultStyleSheets& operator=(const CSSDefaultStyleSheets&) = delete;
47 
48   bool EnsureDefaultStyleSheetsForElement(const Element&);
49   bool EnsureDefaultStyleSheetsForPseudoElement(PseudoId);
50   bool EnsureDefaultStyleSheetForXrOverlay();
51   void EnsureDefaultStyleSheetForFullscreen();
52 
DefaultStyle()53   RuleSet* DefaultStyle() { return default_style_.Get(); }
DefaultMathMLStyle()54   RuleSet* DefaultMathMLStyle() { return default_mathml_style_.Get(); }
DefaultSVGStyle()55   RuleSet* DefaultSVGStyle() { return default_svg_style_.Get(); }
DefaultQuirksStyle()56   RuleSet* DefaultQuirksStyle() { return default_quirks_style_.Get(); }
DefaultPrintStyle()57   RuleSet* DefaultPrintStyle() { return default_print_style_.Get(); }
58   RuleSet* DefaultViewSourceStyle();
DefaultForcedColorStyle()59   RuleSet* DefaultForcedColorStyle() {
60     return default_forced_color_style_.Get();
61   }
DefaultPseudoElementStyleOrNull()62   RuleSet* DefaultPseudoElementStyleOrNull() {
63     return default_pseudo_element_style_.Get();
64   }
65 
66   StyleSheetContents* EnsureMobileViewportStyleSheet();
67   StyleSheetContents* EnsureTelevisionViewportStyleSheet();
68   StyleSheetContents* EnsureXHTMLMobileProfileStyleSheet();
69 
DefaultStyleSheet()70   StyleSheetContents* DefaultStyleSheet() { return default_style_sheet_.Get(); }
QuirksStyleSheet()71   StyleSheetContents* QuirksStyleSheet() { return quirks_style_sheet_.Get(); }
SvgStyleSheet()72   StyleSheetContents* SvgStyleSheet() { return svg_style_sheet_.Get(); }
MathmlStyleSheet()73   StyleSheetContents* MathmlStyleSheet() { return mathml_style_sheet_.Get(); }
MediaControlsStyleSheet()74   StyleSheetContents* MediaControlsStyleSheet() {
75     return media_controls_style_sheet_.Get();
76   }
FullscreenStyleSheet()77   StyleSheetContents* FullscreenStyleSheet() {
78     return fullscreen_style_sheet_.Get();
79   }
MarkerStyleSheet()80   StyleSheetContents* MarkerStyleSheet() { return marker_style_sheet_.Get(); }
81 
82   CORE_EXPORT void PrepareForLeakDetection();
83 
84   // Media Controls UA stylesheet loading is handled by the media_controls
85   // module.
86   class CORE_EXPORT UAStyleSheetLoader {
87    public:
88     UAStyleSheetLoader() = default;
89     UAStyleSheetLoader(const UAStyleSheetLoader&) = delete;
90     UAStyleSheetLoader& operator=(const UAStyleSheetLoader&) = delete;
91     virtual ~UAStyleSheetLoader() = default;
92     virtual String GetUAStyleSheet() = 0;
93   };
94   CORE_EXPORT void SetMediaControlsStyleSheetLoader(
95       std::unique_ptr<UAStyleSheetLoader>);
HasMediaControlsStyleSheetLoader()96   CORE_EXPORT bool HasMediaControlsStyleSheetLoader() {
97     return media_controls_style_sheet_loader_.get();
98   }
99 
100   void Trace(Visitor*) const;
101 
102  private:
103   void InitializeDefaultStyles();
104 
105   Member<RuleSet> default_style_;
106   Member<RuleSet> default_mathml_style_;
107   Member<RuleSet> default_svg_style_;
108   Member<RuleSet> default_quirks_style_;
109   Member<RuleSet> default_print_style_;
110   Member<RuleSet> default_view_source_style_;
111   Member<RuleSet> default_forced_color_style_;
112   Member<RuleSet> default_pseudo_element_style_;
113 
114   Member<StyleSheetContents> default_style_sheet_;
115   Member<StyleSheetContents> mobile_viewport_style_sheet_;
116   Member<StyleSheetContents> television_viewport_style_sheet_;
117   Member<StyleSheetContents> xhtml_mobile_profile_style_sheet_;
118   Member<StyleSheetContents> quirks_style_sheet_;
119   Member<StyleSheetContents> svg_style_sheet_;
120   Member<StyleSheetContents> mathml_style_sheet_;
121   Member<StyleSheetContents> media_controls_style_sheet_;
122   Member<StyleSheetContents> text_track_style_sheet_;
123   Member<StyleSheetContents> fullscreen_style_sheet_;
124   Member<StyleSheetContents> webxr_overlay_style_sheet_;
125   Member<StyleSheetContents> marker_style_sheet_;
126 
127   std::unique_ptr<UAStyleSheetLoader> media_controls_style_sheet_loader_;
128 };
129 
130 }  // namespace blink
131 
132 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_DEFAULT_STYLE_SHEETS_H_
133