mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Cleanup FontContext privacy (#33745)
* Remove unnecessary FontContext argument in FontContext method. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Make more parts of FontContext private. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
4d200a4348
commit
a6da1daa12
1 changed files with 54 additions and 55 deletions
|
@ -48,7 +48,7 @@ static SMALL_CAPS_SCALE_FACTOR: f32 = 0.8; // Matches FireFox (see gfxFont.h)
|
||||||
/// paint code. It talks directly to the system font service where
|
/// paint code. It talks directly to the system font service where
|
||||||
/// required.
|
/// required.
|
||||||
pub struct FontContext {
|
pub struct FontContext {
|
||||||
pub(crate) system_font_service_proxy: Arc<SystemFontServiceProxy>,
|
system_font_service_proxy: Arc<SystemFontServiceProxy>,
|
||||||
resource_threads: ReentrantMutex<CoreResourceThread>,
|
resource_threads: ReentrantMutex<CoreResourceThread>,
|
||||||
|
|
||||||
/// A sender that can send messages and receive replies from the compositor.
|
/// A sender that can send messages and receive replies from the compositor.
|
||||||
|
@ -121,7 +121,7 @@ impl FontContext {
|
||||||
self.web_fonts.read().number_of_fonts_still_loading()
|
self.web_fonts.read().number_of_fonts_still_loading()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_font_data(&self, identifier: &FontIdentifier) -> Arc<FontData> {
|
fn get_font_data(&self, identifier: &FontIdentifier) -> Arc<FontData> {
|
||||||
match identifier {
|
match identifier {
|
||||||
FontIdentifier::Web(_) => self.web_fonts.read().get_font_data(identifier),
|
FontIdentifier::Web(_) => self.web_fonts.read().get_font_data(identifier),
|
||||||
FontIdentifier::Local(_) | FontIdentifier::Mock(_) => {
|
FontIdentifier::Local(_) | FontIdentifier::Mock(_) => {
|
||||||
|
@ -300,7 +300,6 @@ impl FontContext {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
FontIdentifier::Web(_) => self.create_web_font_instance(
|
FontIdentifier::Web(_) => self.create_web_font_instance(
|
||||||
self,
|
|
||||||
font.template.clone(),
|
font.template.clone(),
|
||||||
font.descriptor.pt_size,
|
font.descriptor.pt_size,
|
||||||
font.webrender_font_instance_flags(),
|
font.webrender_font_instance_flags(),
|
||||||
|
@ -308,15 +307,14 @@ impl FontContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_web_font_instance(
|
fn create_web_font_instance(
|
||||||
&self,
|
&self,
|
||||||
font_context: &FontContext,
|
|
||||||
font_template: FontTemplateRef,
|
font_template: FontTemplateRef,
|
||||||
pt_size: Au,
|
pt_size: Au,
|
||||||
flags: FontInstanceFlags,
|
flags: FontInstanceFlags,
|
||||||
) -> FontInstanceKey {
|
) -> FontInstanceKey {
|
||||||
let identifier = font_template.identifier().clone();
|
let identifier = font_template.identifier().clone();
|
||||||
let font_data = font_context.get_font_data(&identifier);
|
let font_data = self.get_font_data(&identifier);
|
||||||
let font_key = *self
|
let font_key = *self
|
||||||
.webrender_font_keys
|
.webrender_font_keys
|
||||||
.write()
|
.write()
|
||||||
|
@ -360,13 +358,13 @@ impl FontContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WebFontDownloadState {
|
pub(crate) struct WebFontDownloadState {
|
||||||
pub css_font_face_descriptors: Arc<CSSFontFaceDescriptors>,
|
pub(crate) css_font_face_descriptors: Arc<CSSFontFaceDescriptors>,
|
||||||
remaining_sources: Vec<Source>,
|
remaining_sources: Vec<Source>,
|
||||||
finished_callback: WebFontLoadFinishedCallback,
|
finished_callback: WebFontLoadFinishedCallback,
|
||||||
core_resource_thread: CoreResourceThread,
|
core_resource_thread: CoreResourceThread,
|
||||||
local_fonts: Arc<HashMap<Atom, Option<FontTemplateRef>>>,
|
local_fonts: Arc<HashMap<Atom, Option<FontTemplateRef>>>,
|
||||||
pub stylesheet: DocumentStyleSheet,
|
pub(crate) stylesheet: DocumentStyleSheet,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FontContextWebFontMethods {
|
pub trait FontContextWebFontMethods {
|
||||||
|
@ -378,7 +376,6 @@ pub trait FontContextWebFontMethods {
|
||||||
finished_callback: WebFontLoadFinishedCallback,
|
finished_callback: WebFontLoadFinishedCallback,
|
||||||
synchronous: bool,
|
synchronous: bool,
|
||||||
) -> usize;
|
) -> usize;
|
||||||
fn process_next_web_font_source(&self, web_font_download_state: WebFontDownloadState);
|
|
||||||
fn remove_all_web_fonts_from_stylesheet(&self, stylesheet: &DocumentStyleSheet);
|
fn remove_all_web_fonts_from_stylesheet(&self, stylesheet: &DocumentStyleSheet);
|
||||||
fn collect_unused_webrender_resources(&self, all: bool)
|
fn collect_unused_webrender_resources(&self, all: bool)
|
||||||
-> (Vec<FontKey>, Vec<FontInstanceKey>);
|
-> (Vec<FontKey>, Vec<FontInstanceKey>);
|
||||||
|
@ -477,51 +474,6 @@ impl FontContextWebFontMethods for Arc<FontContext> {
|
||||||
number_loading
|
number_loading
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_next_web_font_source(&self, mut state: WebFontDownloadState) {
|
|
||||||
let Some(source) = state.remaining_sources.pop() else {
|
|
||||||
self.web_fonts
|
|
||||||
.write()
|
|
||||||
.handle_web_font_failed_to_load(&state);
|
|
||||||
self.handle_web_font_load_finished(&state.finished_callback, false);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let this = self.clone();
|
|
||||||
let web_font_family_name = state.css_font_face_descriptors.family_name.clone();
|
|
||||||
match source {
|
|
||||||
Source::Url(url_source) => {
|
|
||||||
RemoteWebFontDownloader::download(url_source, this, web_font_family_name, state)
|
|
||||||
},
|
|
||||||
Source::Local(ref local_family_name) => {
|
|
||||||
if let Some((new_template, font_data)) = state
|
|
||||||
.local_fonts
|
|
||||||
.get(&local_family_name.name)
|
|
||||||
.cloned()
|
|
||||||
.flatten()
|
|
||||||
.and_then(|local_template| {
|
|
||||||
let template = FontTemplate::new_for_local_web_font(
|
|
||||||
local_template.clone(),
|
|
||||||
&state.css_font_face_descriptors,
|
|
||||||
state.stylesheet.clone(),
|
|
||||||
)
|
|
||||||
.ok()?;
|
|
||||||
let font_data = self.get_font_data(&local_template.identifier());
|
|
||||||
Some((template, font_data))
|
|
||||||
})
|
|
||||||
{
|
|
||||||
let not_cancelled = self.web_fonts.write().handle_web_font_loaded(
|
|
||||||
&state,
|
|
||||||
new_template,
|
|
||||||
font_data,
|
|
||||||
);
|
|
||||||
self.handle_web_font_load_finished(&state.finished_callback, not_cancelled);
|
|
||||||
} else {
|
|
||||||
this.process_next_web_font_source(state);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_all_web_fonts_from_stylesheet(&self, stylesheet: &DocumentStyleSheet) {
|
fn remove_all_web_fonts_from_stylesheet(&self, stylesheet: &DocumentStyleSheet) {
|
||||||
let mut web_fonts = self.web_fonts.write();
|
let mut web_fonts = self.web_fonts.write();
|
||||||
let mut fonts = self.fonts.write();
|
let mut fonts = self.fonts.write();
|
||||||
|
@ -618,6 +570,53 @@ impl FontContextWebFontMethods for Arc<FontContext> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FontContext {
|
||||||
|
fn process_next_web_font_source(self: &Arc<FontContext>, mut state: WebFontDownloadState) {
|
||||||
|
let Some(source) = state.remaining_sources.pop() else {
|
||||||
|
self.web_fonts
|
||||||
|
.write()
|
||||||
|
.handle_web_font_failed_to_load(&state);
|
||||||
|
self.handle_web_font_load_finished(&state.finished_callback, false);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let this = self.clone();
|
||||||
|
let web_font_family_name = state.css_font_face_descriptors.family_name.clone();
|
||||||
|
match source {
|
||||||
|
Source::Url(url_source) => {
|
||||||
|
RemoteWebFontDownloader::download(url_source, this, web_font_family_name, state)
|
||||||
|
},
|
||||||
|
Source::Local(ref local_family_name) => {
|
||||||
|
if let Some((new_template, font_data)) = state
|
||||||
|
.local_fonts
|
||||||
|
.get(&local_family_name.name)
|
||||||
|
.cloned()
|
||||||
|
.flatten()
|
||||||
|
.and_then(|local_template| {
|
||||||
|
let template = FontTemplate::new_for_local_web_font(
|
||||||
|
local_template.clone(),
|
||||||
|
&state.css_font_face_descriptors,
|
||||||
|
state.stylesheet.clone(),
|
||||||
|
)
|
||||||
|
.ok()?;
|
||||||
|
let font_data = self.get_font_data(&local_template.identifier());
|
||||||
|
Some((template, font_data))
|
||||||
|
})
|
||||||
|
{
|
||||||
|
let not_cancelled = self.web_fonts.write().handle_web_font_loaded(
|
||||||
|
&state,
|
||||||
|
new_template,
|
||||||
|
font_data,
|
||||||
|
);
|
||||||
|
self.handle_web_font_load_finished(&state.finished_callback, not_cancelled);
|
||||||
|
} else {
|
||||||
|
this.process_next_web_font_source(state);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct RemoteWebFontDownloader {
|
struct RemoteWebFontDownloader {
|
||||||
font_context: Arc<FontContext>,
|
font_context: Arc<FontContext>,
|
||||||
url: ServoArc<Url>,
|
url: ServoArc<Url>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue