1 | /* |
2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 | * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
4 | * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
5 | * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. |
6 | * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
7 | * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
8 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
9 | * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
10 | * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
11 | * Copyright (C) 2012 Google Inc. All rights reserved. |
12 | * |
13 | * This library is free software; you can redistribute it and/or |
14 | * modify it under the terms of the GNU Library General Public |
15 | * License as published by the Free Software Foundation; either |
16 | * version 2 of the License, or (at your option) any later version. |
17 | * |
18 | * This library is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 | * Library General Public License for more details. |
22 | * |
23 | * You should have received a copy of the GNU Library General Public License |
24 | * along with this library; see the file COPYING.LIB. If not, write to |
25 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 | * Boston, MA 02110-1301, USA. |
27 | */ |
28 | |
29 | #include "config.h" |
30 | #include "InspectorCSSOMWrappers.h" |
31 | |
32 | #include "CSSDefaultStyleSheets.h" |
33 | #include "CSSImportRule.h" |
34 | #include "CSSMediaRule.h" |
35 | #include "CSSRule.h" |
36 | #include "CSSStyleRule.h" |
37 | #include "CSSStyleSheet.h" |
38 | #include "CSSSupportsRule.h" |
39 | #include "ExtensionStyleSheets.h" |
40 | #include "StyleScope.h" |
41 | #include "StyleSheetContents.h" |
42 | |
43 | namespace WebCore { |
44 | |
45 | void InspectorCSSOMWrappers::collectFromStyleSheetIfNeeded(CSSStyleSheet* styleSheet) |
46 | { |
47 | if (!m_styleRuleToCSSOMWrapperMap.isEmpty()) |
48 | collect(styleSheet); |
49 | } |
50 | |
51 | template <class ListType> |
52 | void InspectorCSSOMWrappers::collect(ListType* listType) |
53 | { |
54 | if (!listType) |
55 | return; |
56 | unsigned size = listType->length(); |
57 | for (unsigned i = 0; i < size; ++i) { |
58 | CSSRule* cssRule = listType->item(i); |
59 | switch (cssRule->type()) { |
60 | case CSSRule::IMPORT_RULE: |
61 | collect(downcast<CSSImportRule>(*cssRule).styleSheet()); |
62 | break; |
63 | case CSSRule::MEDIA_RULE: |
64 | collect(downcast<CSSMediaRule>(cssRule)); |
65 | break; |
66 | case CSSRule::SUPPORTS_RULE: |
67 | collect(downcast<CSSSupportsRule>(cssRule)); |
68 | break; |
69 | case CSSRule::STYLE_RULE: |
70 | m_styleRuleToCSSOMWrapperMap.add(&downcast<CSSStyleRule>(*cssRule).styleRule(), downcast<CSSStyleRule>(cssRule)); |
71 | break; |
72 | default: |
73 | break; |
74 | } |
75 | } |
76 | } |
77 | |
78 | void InspectorCSSOMWrappers::collectFromStyleSheetContents(StyleSheetContents* styleSheet) |
79 | { |
80 | if (!styleSheet) |
81 | return; |
82 | auto styleSheetWrapper = CSSStyleSheet::create(*styleSheet); |
83 | m_styleSheetCSSOMWrapperSet.add(styleSheetWrapper.copyRef()); |
84 | collect(styleSheetWrapper.ptr()); |
85 | } |
86 | |
87 | void InspectorCSSOMWrappers::collectFromStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& sheets) |
88 | { |
89 | for (auto& sheet : sheets) |
90 | collect(sheet.get()); |
91 | } |
92 | |
93 | void InspectorCSSOMWrappers::maybeCollectFromStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& sheets) |
94 | { |
95 | for (auto& sheet : sheets) { |
96 | if (!m_styleSheetCSSOMWrapperSet.contains(sheet.get())) { |
97 | m_styleSheetCSSOMWrapperSet.add(sheet); |
98 | collect(sheet.get()); |
99 | } |
100 | } |
101 | } |
102 | |
103 | void InspectorCSSOMWrappers::collectDocumentWrappers(ExtensionStyleSheets& extensionStyleSheets) |
104 | { |
105 | if (m_styleRuleToCSSOMWrapperMap.isEmpty()) { |
106 | collectFromStyleSheetContents(CSSDefaultStyleSheets::simpleDefaultStyleSheet); |
107 | collectFromStyleSheetContents(CSSDefaultStyleSheets::defaultStyleSheet); |
108 | collectFromStyleSheetContents(CSSDefaultStyleSheets::quirksStyleSheet); |
109 | collectFromStyleSheetContents(CSSDefaultStyleSheets::svgStyleSheet); |
110 | collectFromStyleSheetContents(CSSDefaultStyleSheets::mathMLStyleSheet); |
111 | collectFromStyleSheetContents(CSSDefaultStyleSheets::mediaControlsStyleSheet); |
112 | collectFromStyleSheetContents(CSSDefaultStyleSheets::fullscreenStyleSheet); |
113 | #if ENABLE(DATALIST_ELEMENT) |
114 | collectFromStyleSheetContents(CSSDefaultStyleSheets::dataListStyleSheet); |
115 | #endif |
116 | #if ENABLE(INPUT_TYPE_COLOR) |
117 | collectFromStyleSheetContents(CSSDefaultStyleSheets::colorInputStyleSheet); |
118 | #endif |
119 | collectFromStyleSheetContents(CSSDefaultStyleSheets::plugInsStyleSheet); |
120 | collectFromStyleSheetContents(CSSDefaultStyleSheets::mediaQueryStyleSheet); |
121 | |
122 | collect(extensionStyleSheets.pageUserSheet()); |
123 | collectFromStyleSheets(extensionStyleSheets.injectedUserStyleSheets()); |
124 | collectFromStyleSheets(extensionStyleSheets.documentUserStyleSheets()); |
125 | } |
126 | } |
127 | |
128 | void InspectorCSSOMWrappers::collectScopeWrappers(Style::Scope& styleScope) |
129 | { |
130 | maybeCollectFromStyleSheets(styleScope.activeStyleSheets()); |
131 | } |
132 | |
133 | CSSStyleRule* InspectorCSSOMWrappers::getWrapperForRuleInSheets(StyleRule* rule) |
134 | { |
135 | return m_styleRuleToCSSOMWrapperMap.get(rule); |
136 | } |
137 | |
138 | } // namespace WebCore |
139 | |