diff --git a/components/fonts/platform/freetype/ohos/font_list.rs b/components/fonts/platform/freetype/ohos/font_list.rs index 649966d4545..5abe20339df 100644 --- a/components/fonts/platform/freetype/ohos/font_list.rs +++ b/components/fonts/platform/freetype/ohos/font_list.rs @@ -22,16 +22,16 @@ use crate::{ FontTemplateDescriptor, LocalFontIdentifier, LowercaseFontFamilyName, }; -static FONT_LIST: LazyLock = LazyLock::new(|| FontList::new()); +static FONT_LIST: LazyLock = LazyLock::new(FontList::new); /// When testing the ohos font code on linux, we can pass the fonts directory of the SDK /// via an environment variable. #[cfg(ohos_mock)] -static OHOS_FONTS_DIR: &'static str = env!("OHOS_SDK_FONTS_DIR"); +static OHOS_FONTS_DIR: &str = env!("OHOS_SDK_FONTS_DIR"); /// On OpenHarmony devices the fonts are always located here. #[cfg(not(ohos_mock))] -static OHOS_FONTS_DIR: &'static str = "/system/fonts"; +static OHOS_FONTS_DIR: &str = "/system/fonts"; #[allow(unused)] #[derive(Clone, Copy, Debug, Default)] @@ -80,15 +80,13 @@ struct FontList { fn enumerate_font_files() -> io::Result> { let mut font_list = vec![]; - for elem in fs::read_dir(OHOS_FONTS_DIR)? { - if let Ok(e) = elem { - if e.file_type().unwrap().is_file() { - let name = e.file_name(); - let raw_name = name.as_bytes(); - if raw_name.ends_with(b".ttf".as_ref()) || raw_name.ends_with(b".ttc".as_ref()) { - debug!("Found font {}", e.file_name().to_str().unwrap()); - font_list.push(e.path()) - } + for elem in fs::read_dir(OHOS_FONTS_DIR)?.flatten() { + if elem.file_type().unwrap().is_file() { + let name = elem.file_name(); + let raw_name = name.as_bytes(); + if raw_name.ends_with(b".ttf".as_ref()) || raw_name.ends_with(b".ttc".as_ref()) { + debug!("Found font {}", elem.file_name().to_str().unwrap()); + font_list.push(elem.path()) } } } @@ -176,7 +174,7 @@ fn split_noto_font_name(name: &str) -> Vec { } } } - if current_word.len() > 0 { + if !current_word.is_empty() { name_components.push(current_word); } name_components @@ -291,11 +289,10 @@ fn parse_font_filenames(font_files: Vec) -> Vec { } } - let families = families + families .into_iter() .map(|(name, fonts)| FontFamily { name, fonts }) - .collect(); - families + .collect() } impl FontList { @@ -310,7 +307,7 @@ impl FontList { fn detect_installed_font_families() -> Vec { let mut families = enumerate_font_files() .inspect_err(|e| error!("Failed to enumerate font files due to `{e:?}`")) - .and_then(|font_files| Ok(parse_font_filenames(font_files))) + .map(|font_files| parse_font_filenames(font_files)) .unwrap_or_else(|_| FontList::fallback_font_families()); families.extend(Self::hardcoded_font_families()); families @@ -325,14 +322,14 @@ impl FontList { FontFamily { name: "HMOS Color Emoji".to_string(), fonts: vec![Font { - filepath: FontList::font_absolute_path("HMOSColorEmojiCompat.ttf".into()), + filepath: FontList::font_absolute_path("HMOSColorEmojiCompat.ttf"), ..Default::default() }], }, FontFamily { name: "HMOS Color Emoji Flags".to_string(), fonts: vec![Font { - filepath: FontList::font_absolute_path("HMOSColorEmojiFlags.ttf".into()), + filepath: FontList::font_absolute_path("HMOSColorEmojiFlags.ttf"), ..Default::default() }], }, diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index f944b988ae2..c207ba1762b 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -128,7 +128,7 @@ winit = "0.30.5" [target.'cfg(any(all(target_os = "linux", not(target_env = "ohos")), target_os = "windows"))'.dependencies] image = { workspace = true } -[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] +[target.'cfg(any(all(target_os = "linux", not(target_env = "ohos")), target_os = "macos"))'.dependencies] sig = "1.0" [target.'cfg(target_os = "windows")'.dependencies] diff --git a/ports/servoshell/crash_handler.rs b/ports/servoshell/crash_handler.rs index 94c0b10f992..c7f084f7e42 100644 --- a/ports/servoshell/crash_handler.rs +++ b/ports/servoshell/crash_handler.rs @@ -11,6 +11,8 @@ pub fn install() { use std::sync::atomic; use std::thread; + use sig::signal; + use crate::backtrace; extern "C" fn handler(sig: i32) { diff --git a/ports/servoshell/egl/ohos.rs b/ports/servoshell/egl/ohos.rs index e4586c90f8f..e005eb0114c 100644 --- a/ports/servoshell/egl/ohos.rs +++ b/ports/servoshell/egl/ohos.rs @@ -30,7 +30,6 @@ use ohos_sys::xcomponent::{ use servo::compositing::windowing::EmbedderEvent; use servo::embedder_traits; use servo::embedder_traits::{InputMethodType, PromptResult}; -use servo::euclid::Point2D; use servo::style::Zero; use simpleservo::EventLoopWaker; use xcomponent_sys::{ @@ -82,7 +81,7 @@ unsafe impl Send for XComponentWrapper {} unsafe impl Send for WindowWrapper {} #[derive(Clone, Copy, Debug)] -enum TouchEventType { +pub(super) enum TouchEventType { Down, Up, Move, @@ -91,7 +90,7 @@ enum TouchEventType { } #[derive(Debug)] -enum ServoAction { +pub(super) enum ServoAction { WakeUp, LoadUrl(String), GoBack, @@ -206,11 +205,9 @@ unsafe extern "C" fn on_vsync_cb( data: *mut ::core::ffi::c_void, ) { trace!("Vsync callback at time {timestamp}"); - // SAFETY: We require the function registering us as a callback - let (native_vsync, data) = unsafe { - let native = ohos_vsync::NativeVsync::from_raw(data.cast()); - (native, 0) - }; + // SAFETY: We require the function registering us as a callback provides a valid + // `OH_NativeVSync` object. We do not use `data` after this point. + let native_vsync = unsafe { ohos_vsync::NativeVsync::from_raw(data.cast()) }; call(ServoAction::Vsync).unwrap(); // Todo: Do we have a callback for when the frame finished rendering? unsafe { @@ -507,7 +504,7 @@ pub fn go_forward() { #[napi(js_name = "registerURLcallback")] pub fn register_url_callback(callback: Function) -> napi_ohos::Result<()> { debug!("register_url_callback called!"); - let mut tsfn_builder = callback.build_threadsafe_function(); + let tsfn_builder = callback.build_threadsafe_function(); let function = tsfn_builder .max_queue_size::() .build()?; @@ -522,7 +519,7 @@ pub fn register_url_callback(callback: Function) -> napi_ohos::Resul #[napi] pub fn register_prompt_toast_callback(callback: Function) -> napi_ohos::Result<()> { debug!("register_prompt_toast_callback called!"); - let mut tsfn_builder = callback.build_threadsafe_function(); + let tsfn_builder = callback.build_threadsafe_function(); let function = tsfn_builder.max_queue_size::().build()?; PROMPT_TOAST diff --git a/ports/servoshell/egl/ohos/simpleservo.rs b/ports/servoshell/egl/ohos/simpleservo.rs index 76796e06c7d..a29c9fa44fb 100644 --- a/ports/servoshell/egl/ohos/simpleservo.rs +++ b/ports/servoshell/egl/ohos/simpleservo.rs @@ -82,18 +82,12 @@ pub fn init( "--prefs-file /path/to/prefs.json", ); - let opts_matches; - let content_process_token; - match opts::from_cmdline_args(opts, &args) { - ArgumentParsingResult::ContentProcess(matches, token) => { + let opts_matches = match opts::from_cmdline_args(opts, &args) { + ArgumentParsingResult::ContentProcess(matches, _token) => { error!("Content Process mode not supported / tested yet on OpenHarmony!"); - opts_matches = matches; - content_process_token = Some(token); - }, - ArgumentParsingResult::ChromeProcess(matches) => { - opts_matches = matches; - content_process_token = None; + matches }, + ArgumentParsingResult::ChromeProcess(matches) => matches, }; crate::prefs::register_user_prefs(&opts_matches); diff --git a/ports/servoshell/egl/servo_glue.rs b/ports/servoshell/egl/servo_glue.rs index ab16a04277b..56e39c03564 100644 --- a/ports/servoshell/egl/servo_glue.rs +++ b/ports/servoshell/egl/servo_glue.rs @@ -26,7 +26,6 @@ use servo::script_traits::{ }; use servo::servo_geometry::DeviceIndependentPixel; use servo::style_traits::DevicePixel; -use servo::webrender_api::units::DeviceIntRect; use servo::webrender_api::ScrollLocation; use servo::webrender_traits::RenderingContext; use servo::{gl, Servo, TopLevelBrowsingContextId}; @@ -501,7 +500,8 @@ impl ServoGlue { let trusted = origin == PromptOrigin::Trusted; let res = match definition { PromptDefinition::Alert(message, sender) => { - sender.send(cb.prompt_alert(message, trusted)) + cb.prompt_alert(message, trusted); + sender.send(()) }, PromptDefinition::OkCancel(message, sender) => { sender.send(cb.prompt_ok_cancel(message, trusted)) diff --git a/ports/servoshell/lib.rs b/ports/servoshell/lib.rs index ed29f6284e3..8e19e055265 100644 --- a/ports/servoshell/lib.rs +++ b/ports/servoshell/lib.rs @@ -4,21 +4,18 @@ use cfg_if::cfg_if; -#[cfg(any(target_os = "macos", target_os = "linux"))] -#[macro_use] -extern crate sig; - #[cfg(test)] mod test; #[cfg(not(target_os = "android"))] mod backtrace; +#[cfg(not(target_env = "ohos"))] mod crash_handler; #[cfg(not(any(target_os = "android", target_env = "ohos")))] pub(crate) mod desktop; #[cfg(any(target_os = "android", target_env = "ohos"))] mod egl; -#[cfg(not(target_os = "android"))] +#[cfg(not(any(target_os = "android", target_env = "ohos")))] mod panic_hook; mod parser; mod prefs; diff --git a/ports/servoshell/parser.rs b/ports/servoshell/parser.rs index 3ebe259d1cc..aba9818093f 100644 --- a/ports/servoshell/parser.rs +++ b/ports/servoshell/parser.rs @@ -2,20 +2,19 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#[cfg(not(any(target_os = "android", target_env = "ohos")))] use std::path::{Path, PathBuf}; -use log::warn; use servo::net_traits::pub_domains::is_reg_domain; use servo::servo_config::pref; use servo::servo_url::ServoUrl; -use url::{self, Url}; #[cfg(not(any(target_os = "android", target_env = "ohos")))] pub fn parse_url_or_filename(cwd: &Path, input: &str) -> Result { match ServoUrl::parse(input) { Ok(url) => Ok(url), Err(url::ParseError::RelativeUrlWithoutBase) => { - Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url) + url::Url::from_file_path(&*cwd.join(input)).map(ServoUrl::from_url) }, Err(_) => Err(()), } @@ -33,7 +32,7 @@ pub fn get_default_url( let cmdline_url = url_opt.map(|s| s.to_string()).and_then(|url_string| { parse_url_or_filename(cwd.as_ref(), &url_string) .map_err(|error| { - warn!("URL parsing failed ({:?}).", error); + log::warn!("URL parsing failed ({:?}).", error); error }) .ok()