Commit 86665bcc authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Chromium LUCI CQ

Use TreeScope instead of Document for CSSFontSelector

Prepare for supporting @font-face support in shadow trees by allowing
font selectors to be associated with TreeScope instead of Document.

Bug: 336876
Change-Id: I90ce9064e3c57c28c06ef02bb7e11c711ba1e4ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2562379Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832320}
parent 20fd08f9
......@@ -46,18 +46,18 @@
namespace blink {
CSSFontSelector::CSSFontSelector(Document* document)
: document_(document),
generic_font_family_settings_(
document->GetFrame()->GetSettings()->GetGenericFontFamilySettings()) {
// FIXME: An old comment used to say there was no need to hold a reference to
// document_ because "we are guaranteed to be destroyed before the document".
// But there does not seem to be any such guarantee.
DCHECK(document_);
DCHECK(document_->GetFrame());
CSSFontSelector::CSSFontSelector(const TreeScope& tree_scope)
: tree_scope_(&tree_scope),
generic_font_family_settings_(tree_scope.GetDocument()
.GetFrame()
->GetSettings()
->GetGenericFontFamilySettings()) {
DCHECK(tree_scope.GetDocument().GetFrame());
FontCache::GetFontCache()->AddClient(this);
FontFaceSetDocument::From(*document)->AddFontFacesToFontFaceCache(
&font_face_cache_);
if (tree_scope.RootNode().IsDocumentNode()) {
FontFaceSetDocument::From(tree_scope.GetDocument())
->AddFontFacesToFontFaceCache(&font_face_cache_);
}
}
CSSFontSelector::~CSSFontSelector() = default;
......@@ -97,13 +97,14 @@ void CSSFontSelector::FontCacheInvalidated() {
scoped_refptr<FontData> CSSFontSelector::GetFontData(
const FontDescription& font_description,
const AtomicString& family_name) {
Document& document = GetTreeScope()->GetDocument();
if (CSSSegmentedFontFace* face =
font_face_cache_.Get(font_description, family_name)) {
document_->GetFontMatchingMetrics()->ReportWebFontFamily(family_name);
document.GetFontMatchingMetrics()->ReportWebFontFamily(family_name);
return face->GetFontData(font_description);
}
document_->GetFontMatchingMetrics()->ReportSystemFontFamily(family_name);
document.GetFontMatchingMetrics()->ReportSystemFontFamily(family_name);
// Try to return the correct font based off our settings, in case we were
// handed the generic font family name.
......@@ -112,7 +113,7 @@ scoped_refptr<FontData> CSSFontSelector::GetFontData(
if (settings_family_name.IsEmpty())
return nullptr;
document_->GetFontMatchingMetrics()->ReportFontFamilyLookupByGenericFamily(
document.GetFontMatchingMetrics()->ReportFontFamilyLookupByGenericFamily(
family_name, font_description.GetScript(),
font_description.GenericFamily(), settings_family_name);
......@@ -120,7 +121,7 @@ scoped_refptr<FontData> CSSFontSelector::GetFontData(
FontCache::GetFontCache()->GetFontData(font_description,
settings_family_name);
document_->GetFontMatchingMetrics()->ReportFontLookupByUniqueOrFamilyName(
document.GetFontMatchingMetrics()->ReportFontLookupByUniqueOrFamilyName(
settings_family_name, font_description, font_data.get());
return font_data;
......@@ -162,43 +163,37 @@ void CSSFontSelector::UpdateGenericFontFamilySettings(Document& document) {
}
void CSSFontSelector::ReportNotDefGlyph() const {
DCHECK(document_);
UseCounter::Count(document_, WebFeature::kFontShapingNotDefGlyphObserved);
UseCounter::Count(GetDocument(), WebFeature::kFontShapingNotDefGlyphObserved);
}
void CSSFontSelector::ReportSuccessfulFontFamilyMatch(
const AtomicString& font_family_name) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportSuccessfulFontFamilyMatch(
GetDocument().GetFontMatchingMetrics()->ReportSuccessfulFontFamilyMatch(
font_family_name);
}
void CSSFontSelector::ReportFailedFontFamilyMatch(
const AtomicString& font_family_name) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportFailedFontFamilyMatch(
GetDocument().GetFontMatchingMetrics()->ReportFailedFontFamilyMatch(
font_family_name);
}
void CSSFontSelector::ReportSuccessfulLocalFontMatch(
const AtomicString& font_name) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportSuccessfulLocalFontMatch(
GetDocument().GetFontMatchingMetrics()->ReportSuccessfulLocalFontMatch(
font_name);
}
void CSSFontSelector::ReportFailedLocalFontMatch(
const AtomicString& font_name) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportFailedLocalFontMatch(font_name);
GetDocument().GetFontMatchingMetrics()->ReportFailedLocalFontMatch(font_name);
}
void CSSFontSelector::ReportFontLookupByUniqueOrFamilyName(
const AtomicString& name,
const FontDescription& font_description,
SimpleFontData* resulting_font_data) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportFontLookupByUniqueOrFamilyName(
GetDocument().GetFontMatchingMetrics()->ReportFontLookupByUniqueOrFamilyName(
name, font_description, resulting_font_data);
}
......@@ -207,8 +202,7 @@ void CSSFontSelector::ReportFontLookupByUniqueNameOnly(
const FontDescription& font_description,
SimpleFontData* resulting_font_data,
bool is_loading_fallback) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportFontLookupByUniqueNameOnly(
GetDocument().GetFontMatchingMetrics()->ReportFontLookupByUniqueNameOnly(
name, font_description, resulting_font_data, is_loading_fallback);
}
......@@ -217,8 +211,7 @@ void CSSFontSelector::ReportFontLookupByFallbackCharacter(
FontFallbackPriority fallback_priority,
const FontDescription& font_description,
SimpleFontData* resulting_font_data) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportFontLookupByFallbackCharacter(
GetDocument().GetFontMatchingMetrics()->ReportFontLookupByFallbackCharacter(
fallback_character, fallback_priority, font_description,
resulting_font_data);
}
......@@ -226,13 +219,12 @@ void CSSFontSelector::ReportFontLookupByFallbackCharacter(
void CSSFontSelector::ReportLastResortFallbackFontLookup(
const FontDescription& font_description,
SimpleFontData* resulting_font_data) {
DCHECK(document_);
document_->GetFontMatchingMetrics()->ReportLastResortFallbackFontLookup(
GetDocument().GetFontMatchingMetrics()->ReportLastResortFallbackFontLookup(
font_description, resulting_font_data);
}
void CSSFontSelector::Trace(Visitor* visitor) const {
visitor->Trace(document_);
visitor->Trace(tree_scope_);
visitor->Trace(font_face_cache_);
visitor->Trace(clients_);
FontSelector::Trace(visitor);
......
......@@ -42,7 +42,7 @@ class FontDescription;
class CORE_EXPORT CSSFontSelector : public FontSelector {
public:
explicit CSSFontSelector(Document*);
explicit CSSFontSelector(const TreeScope&);
~CSSFontSelector() override;
unsigned Version() const override { return font_face_cache_.Version(); }
......@@ -100,7 +100,7 @@ class CORE_EXPORT CSSFontSelector : public FontSelector {
void UnregisterForInvalidationCallbacks(FontSelectorClient*) override;
ExecutionContext* GetExecutionContext() const override {
return document_ ? document_->GetExecutionContext() : nullptr;
return tree_scope_ ? GetDocument().GetExecutionContext() : nullptr;
}
FontFaceCache* GetFontFaceCache() override { return &font_face_cache_; }
......@@ -109,7 +109,11 @@ class CORE_EXPORT CSSFontSelector : public FontSelector {
}
void UpdateGenericFontFamilySettings(Document&);
const TreeScope* GetTreeScope() const { return document_; }
const TreeScope* GetTreeScope() const { return tree_scope_; }
Document& GetDocument() const {
DCHECK(tree_scope_);
return tree_scope_->GetDocument();
}
void Trace(Visitor*) const override;
......@@ -120,7 +124,7 @@ class CORE_EXPORT CSSFontSelector : public FontSelector {
// TODO(Oilpan): Ideally this should just be a traced Member but that will
// currently leak because ComputedStyle and its data are not on the heap.
// See crbug.com/383860 for details.
WeakMember<Document> document_;
WeakMember<const TreeScope> tree_scope_;
// TODO(futhark): Make this a Member which can be shared between scopes
// sharing the same set of @font-faces.
FontFaceCache font_face_cache_;
......
......@@ -100,10 +100,9 @@ namespace {
CSSFontSelector* CreateCSSFontSelectorFor(Document& document) {
DCHECK(document.GetFrame());
if (UNLIKELY(document.GetFrame()->PagePopupOwner())) {
if (UNLIKELY(document.GetFrame()->PagePopupOwner()))
return PagePopupController::CreateCSSFontSelector(document);
}
return MakeGarbageCollected<CSSFontSelector>(&document);
return MakeGarbageCollected<CSSFontSelector>(document);
}
} // namespace
......
......@@ -99,7 +99,7 @@ scoped_refptr<const ComputedStyle> StyleForHoveredScrollbarPart(
class PopupMenuCSSFontSelector : public CSSFontSelector,
private FontSelectorClient {
public:
PopupMenuCSSFontSelector(Document*, CSSFontSelector*);
PopupMenuCSSFontSelector(Document&, CSSFontSelector*);
~PopupMenuCSSFontSelector() override;
// We don't override willUseFontData() for now because the old PopupListBox
......@@ -116,7 +116,7 @@ class PopupMenuCSSFontSelector : public CSSFontSelector,
};
PopupMenuCSSFontSelector::PopupMenuCSSFontSelector(
Document* document,
Document& document,
CSSFontSelector* owner_font_selector)
: CSSFontSelector(document), owner_font_selector_(owner_font_selector) {
owner_font_selector_->RegisterForInvalidationCallbacks(this);
......@@ -510,7 +510,7 @@ CSSFontSelector* InternalPopupMenu::CreateCSSFontSelector(
Document& popup_document) {
Document& owner_document = OwnerElement().GetDocument();
return MakeGarbageCollected<PopupMenuCSSFontSelector>(
&popup_document, owner_document.GetStyleEngine().GetFontSelector());
popup_document, owner_document.GetStyleEngine().GetFontSelector());
}
void InternalPopupMenu::SetValueAndClosePopup(int num_value,
......
......@@ -166,7 +166,7 @@ void PagePopupClient::AddLocalizedProperty(const char* name,
CSSFontSelector* PagePopupClient::CreateCSSFontSelector(
Document& popup_document) {
return MakeGarbageCollected<CSSFontSelector>(&popup_document);
return MakeGarbageCollected<CSSFontSelector>(popup_document);
}
PagePopupController* PagePopupClient::CreatePagePopupController(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment