mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Fix some clippy issues on the Android build (#35147)
This fixes a variety of clippy issues that show up on the Android build. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
5e5379d3bf
commit
f5f5a3f79e
5 changed files with 43 additions and 66 deletions
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
LocalFontIdentifier, LowercaseFontFamilyName,
|
LocalFontIdentifier, LowercaseFontFamilyName,
|
||||||
};
|
};
|
||||||
|
|
||||||
static FONT_LIST: LazyLock<FontList> = LazyLock::new(|| FontList::new());
|
static FONT_LIST: LazyLock<FontList> = LazyLock::new(FontList::new);
|
||||||
|
|
||||||
// Android doesn't provide an API to query system fonts until Android O:
|
// Android doesn't provide an API to query system fonts until Android O:
|
||||||
// https://developer.android.com/reference/android/text/FontConfig.html
|
// https://developer.android.com/reference/android/text/FontConfig.html
|
||||||
|
@ -141,7 +141,7 @@ impl FontList {
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
paths.iter().all(|path| {
|
paths.iter().all(|path| {
|
||||||
result = Self::from_path(path);
|
result = Self::from_path(path);
|
||||||
!result.is_some()
|
result.is_none()
|
||||||
});
|
});
|
||||||
|
|
||||||
if result.is_none() {
|
if result.is_none() {
|
||||||
|
@ -194,10 +194,7 @@ impl FontList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(FontList {
|
Some(FontList { families, aliases })
|
||||||
families: families,
|
|
||||||
aliases: aliases,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fonts expected to exist in Android devices.
|
// Fonts expected to exist in Android devices.
|
||||||
|
@ -277,24 +274,19 @@ impl FontList {
|
||||||
let mut fonts = Vec::new();
|
let mut fonts = Vec::new();
|
||||||
// Parse font variants
|
// Parse font variants
|
||||||
for node in familyset {
|
for node in familyset {
|
||||||
match node {
|
if let Node::Element {
|
||||||
Node::Element {
|
name,
|
||||||
name,
|
attributes,
|
||||||
attributes,
|
children,
|
||||||
children,
|
} = node
|
||||||
} => {
|
{
|
||||||
if name.local_name == "font" {
|
if name.local_name == "font" {
|
||||||
FontList::parse_font(&children, attributes, &mut fonts);
|
FontList::parse_font(children, attributes, &mut fonts);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
_ => {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out.push(FontFamily {
|
out.push(FontFamily { name, fonts });
|
||||||
name: name,
|
|
||||||
fonts: fonts,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse family and font file names for Androi API < 21
|
// Parse family and font file names for Androi API < 21
|
||||||
|
@ -339,10 +331,7 @@ impl FontList {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !fonts.is_empty() {
|
if !fonts.is_empty() {
|
||||||
out.push(FontFamily {
|
out.push(FontFamily { name, fonts })
|
||||||
name: name,
|
|
||||||
fonts: fonts,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -393,11 +382,7 @@ impl FontList {
|
||||||
// Parse optional weight filter
|
// Parse optional weight filter
|
||||||
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());
|
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());
|
||||||
|
|
||||||
out.push(FontAlias {
|
out.push(FontAlias { from, to, weight })
|
||||||
from: from,
|
|
||||||
to: to,
|
|
||||||
weight: weight,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_attrib(name: &str, attrs: &[Attribute]) -> Option<String> {
|
fn find_attrib(name: &str, attrs: &[Attribute]) -> Option<String> {
|
||||||
|
@ -408,7 +393,7 @@ impl FontList {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_content(nodes: &[Node]) -> Option<String> {
|
fn text_content(nodes: &[Node]) -> Option<String> {
|
||||||
nodes.get(0).and_then(|child| match child {
|
nodes.first().and_then(|child| match child {
|
||||||
Node::Text(contents) => Some(contents.trim().into()),
|
Node::Text(contents) => Some(contents.trim().into()),
|
||||||
Node::Element { .. } => None,
|
Node::Element { .. } => None,
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub(super) enum Node {
|
||||||
pub(super) fn parse(bytes: &[u8]) -> xml::reader::Result<Vec<Node>> {
|
pub(super) fn parse(bytes: &[u8]) -> xml::reader::Result<Vec<Node>> {
|
||||||
let mut stack = Vec::new();
|
let mut stack = Vec::new();
|
||||||
let mut nodes = Vec::new();
|
let mut nodes = Vec::new();
|
||||||
for result in xml::EventReader::new(&*bytes) {
|
for result in xml::EventReader::new(bytes) {
|
||||||
match result? {
|
match result? {
|
||||||
StartElement {
|
StartElement {
|
||||||
name, attributes, ..
|
name, attributes, ..
|
||||||
|
|
|
@ -273,9 +273,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scrollStart<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("scrollStart");
|
debug!("scrollStart");
|
||||||
call(&mut env, |s| {
|
call(&mut env, |s| s.scroll_start(dx as f32, dy as f32, x, y));
|
||||||
s.scroll_start(dx as f32, dy as f32, x as i32, y as i32)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -288,9 +286,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scrollEnd<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("scrollEnd");
|
debug!("scrollEnd");
|
||||||
call(&mut env, |s| {
|
call(&mut env, |s| s.scroll_end(dx as f32, dy as f32, x, y));
|
||||||
s.scroll_end(dx as f32, dy as f32, x as i32, y as i32)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -303,9 +299,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scroll<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("scroll");
|
debug!("scroll");
|
||||||
call(&mut env, |s| {
|
call(&mut env, |s| s.scroll(dx as f32, dy as f32, x, y));
|
||||||
s.scroll(dx as f32, dy as f32, x as i32, y as i32)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -317,7 +311,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchDown<'local>(
|
||||||
pointer_id: jint,
|
pointer_id: jint,
|
||||||
) {
|
) {
|
||||||
debug!("touchDown");
|
debug!("touchDown");
|
||||||
call(&mut env, |s| s.touch_down(x, y, pointer_id as i32));
|
call(&mut env, |s| s.touch_down(x, y, pointer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -329,7 +323,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchUp<'local>(
|
||||||
pointer_id: jint,
|
pointer_id: jint,
|
||||||
) {
|
) {
|
||||||
debug!("touchUp");
|
debug!("touchUp");
|
||||||
call(&mut env, |s| s.touch_up(x, y, pointer_id as i32));
|
call(&mut env, |s| s.touch_up(x, y, pointer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -341,7 +335,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchMove<'local>(
|
||||||
pointer_id: jint,
|
pointer_id: jint,
|
||||||
) {
|
) {
|
||||||
debug!("touchMove");
|
debug!("touchMove");
|
||||||
call(&mut env, |s| s.touch_move(x, y, pointer_id as i32));
|
call(&mut env, |s| s.touch_move(x, y, pointer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -353,7 +347,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchCancel<'local>(
|
||||||
pointer_id: jint,
|
pointer_id: jint,
|
||||||
) {
|
) {
|
||||||
debug!("touchCancel");
|
debug!("touchCancel");
|
||||||
call(&mut env, |s| s.touch_cancel(x, y, pointer_id as i32));
|
call(&mut env, |s| s.touch_cancel(x, y, pointer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -365,9 +359,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoomStart<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("pinchZoomStart");
|
debug!("pinchZoomStart");
|
||||||
call(&mut env, |s| {
|
call(&mut env, |s| s.pinchzoom_start(factor, x as u32, y as u32));
|
||||||
s.pinchzoom_start(factor as f32, x as u32, y as u32)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -379,7 +371,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoom<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("pinchZoom");
|
debug!("pinchZoom");
|
||||||
call(&mut env, |s| s.pinchzoom(factor as f32, x as u32, y as u32));
|
call(&mut env, |s| s.pinchzoom(factor, x as u32, y as u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -391,26 +383,24 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoomEnd<'local>(
|
||||||
y: jint,
|
y: jint,
|
||||||
) {
|
) {
|
||||||
debug!("pinchZoomEnd");
|
debug!("pinchZoomEnd");
|
||||||
call(&mut env, |s| {
|
call(&mut env, |s| s.pinchzoom_end(factor, x as u32, y as u32));
|
||||||
s.pinchzoom_end(factor as f32, x as u32, y as u32)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Java_org_servo_servoview_JNIServo_click<'local>(
|
pub extern "C" fn Java_org_servo_servoview_JNIServo_click(
|
||||||
mut env: JNIEnv<'local>,
|
mut env: JNIEnv,
|
||||||
_: JClass<'local>,
|
_: JClass,
|
||||||
x: jfloat,
|
x: jfloat,
|
||||||
y: jfloat,
|
y: jfloat,
|
||||||
) {
|
) {
|
||||||
debug!("click");
|
debug!("click");
|
||||||
call(&mut env, |s| s.click(x as f32, y as f32));
|
call(&mut env, |s| s.click(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn Java_org_servo_servoview_JNIServo_pauseCompositor<'local>(
|
pub extern "C" fn Java_org_servo_servoview_JNIServo_pauseCompositor(
|
||||||
mut env: JNIEnv,
|
mut env: JNIEnv,
|
||||||
_: JClass<'local>,
|
_: JClass<'_>,
|
||||||
) {
|
) {
|
||||||
debug!("pauseCompositor");
|
debug!("pauseCompositor");
|
||||||
call(&mut env, |s| s.pause_compositor());
|
call(&mut env, |s| s.pause_compositor());
|
||||||
|
@ -439,7 +429,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_mediaSessionAction<'local>(
|
||||||
action: jint,
|
action: jint,
|
||||||
) {
|
) {
|
||||||
debug!("mediaSessionAction");
|
debug!("mediaSessionAction");
|
||||||
call(&mut env, |s| s.media_session_action((action as i32).into()));
|
call(&mut env, |s| s.media_session_action((action).into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WakeupCallback {
|
pub struct WakeupCallback {
|
||||||
|
@ -531,7 +521,7 @@ impl HostTrait for HostCallbacks {
|
||||||
fn on_title_changed(&self, title: Option<String>) {
|
fn on_title_changed(&self, title: Option<String>) {
|
||||||
debug!("on_title_changed");
|
debug!("on_title_changed");
|
||||||
let mut env = self.jvm.get_env().unwrap();
|
let mut env = self.jvm.get_env().unwrap();
|
||||||
let title = title.unwrap_or_else(String::new);
|
let title = title.unwrap_or_default();
|
||||||
let Ok(title_string) = new_string_as_jvalue(&mut env, &title) else {
|
let Ok(title_string) = new_string_as_jvalue(&mut env, &title) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -557,8 +547,8 @@ impl HostTrait for HostCallbacks {
|
||||||
&[(&url_string).into()],
|
&[(&url_string).into()],
|
||||||
);
|
);
|
||||||
match allow {
|
match allow {
|
||||||
Ok(allow) => return allow.z().unwrap(),
|
Ok(allow) => allow.z().unwrap(),
|
||||||
Err(_) => return true,
|
Err(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,8 +751,8 @@ fn get_field<'local>(
|
||||||
}
|
}
|
||||||
|
|
||||||
env.get_field(obj, field, type_)
|
env.get_field(obj, field, type_)
|
||||||
.map(|value| Some(value))
|
.map(Some)
|
||||||
.or_else(|_| Err(format!("Can't find `{}` field", field)))
|
.map_err(|_| format!("Can't find `{}` field", field))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_non_null_field<'local>(
|
fn get_non_null_field<'local>(
|
||||||
|
|
|
@ -30,7 +30,7 @@ use crate::egl::servo_glue::{
|
||||||
use crate::prefs::{parse_command_line_arguments, ArgumentParsingResult};
|
use crate::prefs::{parse_command_line_arguments, ArgumentParsingResult};
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
pub static SERVO: RefCell<Option<ServoGlue>> = RefCell::new(None);
|
pub static SERVO: RefCell<Option<ServoGlue>> = const { RefCell::new(None) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InitOptions {
|
pub struct InitOptions {
|
||||||
|
@ -61,7 +61,7 @@ pub fn init(
|
||||||
resources::set(Box::new(ResourceReaderInstance::new()));
|
resources::set(Box::new(ResourceReaderInstance::new()));
|
||||||
|
|
||||||
// `parse_command_line_arguments` expects the first argument to be the binary name.
|
// `parse_command_line_arguments` expects the first argument to be the binary name.
|
||||||
let mut args = mem::replace(&mut init_opts.args, vec![]);
|
let mut args = mem::take(&mut init_opts.args);
|
||||||
args.insert(0, "servo".to_string());
|
args.insert(0, "servo".to_string());
|
||||||
|
|
||||||
let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) {
|
let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ use servo::config::prefs::{PrefValue, Preferences};
|
||||||
use servo::url::ServoUrl;
|
use servo::url::ServoUrl;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
|
||||||
pub(crate) struct ServoShellPreferences {
|
pub(crate) struct ServoShellPreferences {
|
||||||
/// The user agent to use for servoshell.
|
/// The user agent to use for servoshell.
|
||||||
pub user_agent: Option<String>,
|
pub user_agent: Option<String>,
|
||||||
|
@ -138,6 +139,7 @@ pub fn read_prefs_map(txt: &str) -> HashMap<String, PrefValue> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
|
||||||
pub(crate) enum ArgumentParsingResult {
|
pub(crate) enum ArgumentParsingResult {
|
||||||
ChromeProcess(Opts, Preferences, ServoShellPreferences),
|
ChromeProcess(Opts, Preferences, ServoShellPreferences),
|
||||||
ContentProcess(String),
|
ContentProcess(String),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue