Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
| 7 * rights reserved. | 7 * rights reserved. |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "core/html/HTMLIFrameElement.h" | 51 #include "core/html/HTMLIFrameElement.h" |
| 52 #include "core/html/HTMLLinkElement.h" | 52 #include "core/html/HTMLLinkElement.h" |
| 53 #include "core/html/HTMLSlotElement.h" | 53 #include "core/html/HTMLSlotElement.h" |
| 54 #include "core/html/imports/HTMLImportsController.h" | 54 #include "core/html/imports/HTMLImportsController.h" |
| 55 #include "core/layout/api/LayoutViewItem.h" | 55 #include "core/layout/api/LayoutViewItem.h" |
| 56 #include "core/page/Page.h" | 56 #include "core/page/Page.h" |
| 57 #include "core/probe/CoreProbes.h" | 57 #include "core/probe/CoreProbes.h" |
| 58 #include "core/svg/SVGStyleElement.h" | 58 #include "core/svg/SVGStyleElement.h" |
| 59 #include "platform/fonts/FontCache.h" | 59 #include "platform/fonts/FontCache.h" |
| 60 #include "platform/instrumentation/tracing/TraceEvent.h" | 60 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 61 #include "platform/wtf/Atomics.h" | |
| 61 | 62 |
| 62 namespace blink { | 63 namespace blink { |
| 63 | 64 |
| 64 using namespace HTMLNames; | 65 using namespace HTMLNames; |
| 65 | 66 |
| 66 StyleEngine::StyleEngine(Document& document) | 67 StyleEngine::StyleEngine(Document& document) |
| 67 : document_(&document), | 68 : document_(&document), |
| 68 is_master_(!document.ImportsController() || | 69 is_master_(!document.ImportsController() || |
| 69 document.ImportsController()->Master() == &document), | 70 document.ImportsController()->Master() == &document), |
| 70 document_style_sheet_collection_( | 71 document_style_sheet_collection_( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 Master()->GetStyleEngine().UpdateActiveStyle(); | 130 Master()->GetStyleEngine().UpdateActiveStyle(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 if (tree_scope == document_) | 133 if (tree_scope == document_) |
| 133 return GetDocumentStyleSheetCollection().StyleSheetsForStyleSheetList(); | 134 return GetDocumentStyleSheetCollection().StyleSheetsForStyleSheetList(); |
| 134 | 135 |
| 135 return EnsureStyleSheetCollectionFor(tree_scope) | 136 return EnsureStyleSheetCollectionFor(tree_scope) |
| 136 ->StyleSheetsForStyleSheetList(); | 137 ->StyleSheetsForStyleSheetList(); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void StyleEngine::InjectAuthorSheet(StyleSheetContents* author_sheet) { | 140 int StyleEngine::InjectAuthorSheet(StyleSheetContents* author_sheet) { |
| 140 injected_author_style_sheets_.push_back(TraceWrapperMember<CSSStyleSheet>( | 141 AtomicIncrement(&injected_author_sheets_id_count_); |
|
rune
2017/05/16 09:00:58
StyleEngine is not made to be thread-safe. Why not
limasdf
2017/05/18 12:32:53
Done.
| |
| 141 this, CSSStyleSheet::Create(author_sheet, *document_))); | 142 injected_author_style_sheets_.push_back(std::make_pair( |
| 143 injected_author_sheets_id_count_, | |
| 144 TraceWrapperMember<CSSStyleSheet>( | |
| 145 this, CSSStyleSheet::Create(author_sheet, *document_)))); | |
| 146 | |
| 142 MarkDocumentDirty(); | 147 MarkDocumentDirty(); |
| 148 return injected_author_sheets_id_count_; | |
| 149 } | |
| 150 | |
| 151 bool StyleEngine::RemoveInjectedAuthorSheet(int id) { | |
| 152 for (size_t i = 0; i < injected_author_style_sheets_.size(); ++i) { | |
|
rune
2017/05/16 09:00:58
I suppose we can assume the number of injected she
| |
| 153 if (injected_author_style_sheets_[i].first == id) { | |
| 154 injected_author_style_sheets_.erase(i); | |
| 155 MarkDocumentDirty(); | |
| 156 return true; | |
| 157 } | |
| 158 } | |
| 159 return false; | |
| 143 } | 160 } |
| 144 | 161 |
| 145 CSSStyleSheet& StyleEngine::EnsureInspectorStyleSheet() { | 162 CSSStyleSheet& StyleEngine::EnsureInspectorStyleSheet() { |
| 146 if (inspector_style_sheet_) | 163 if (inspector_style_sheet_) |
| 147 return *inspector_style_sheet_; | 164 return *inspector_style_sheet_; |
| 148 | 165 |
| 149 StyleSheetContents* contents = | 166 StyleSheetContents* contents = |
| 150 StyleSheetContents::Create(CSSParserContext::Create(*document_)); | 167 StyleSheetContents::Create(CSSParserContext::Create(*document_)); |
| 151 inspector_style_sheet_ = CSSStyleSheet::Create(contents, *document_); | 168 inspector_style_sheet_ = CSSStyleSheet::Create(contents, *document_); |
| 152 MarkDocumentDirty(); | 169 MarkDocumentDirty(); |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 visitor->Trace(media_query_evaluator_); | 1185 visitor->Trace(media_query_evaluator_); |
| 1169 visitor->Trace(style_invalidator_); | 1186 visitor->Trace(style_invalidator_); |
| 1170 visitor->Trace(font_selector_); | 1187 visitor->Trace(font_selector_); |
| 1171 visitor->Trace(text_to_sheet_cache_); | 1188 visitor->Trace(text_to_sheet_cache_); |
| 1172 visitor->Trace(sheet_to_text_cache_); | 1189 visitor->Trace(sheet_to_text_cache_); |
| 1173 visitor->Trace(tracker_); | 1190 visitor->Trace(tracker_); |
| 1174 CSSFontSelectorClient::Trace(visitor); | 1191 CSSFontSelectorClient::Trace(visitor); |
| 1175 } | 1192 } |
| 1176 | 1193 |
| 1177 DEFINE_TRACE_WRAPPERS(StyleEngine) { | 1194 DEFINE_TRACE_WRAPPERS(StyleEngine) { |
| 1178 for (auto sheet : injected_author_style_sheets_) { | 1195 for (const auto& sheet : injected_author_style_sheets_) { |
| 1179 visitor->TraceWrappers(sheet); | 1196 visitor->TraceWrappers(sheet.second); |
| 1180 } | 1197 } |
| 1181 visitor->TraceWrappers(document_style_sheet_collection_); | 1198 visitor->TraceWrappers(document_style_sheet_collection_); |
| 1182 } | 1199 } |
| 1183 | 1200 |
| 1184 } // namespace blink | 1201 } // namespace blink |
| OLD | NEW |