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:
Martin Robinson 2025-01-23 16:18:58 +01:00 committed by GitHub
parent 5e5379d3bf
commit f5f5a3f79e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 43 additions and 66 deletions

View file

@ -19,7 +19,7 @@ use crate::{
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:
// https://developer.android.com/reference/android/text/FontConfig.html
@ -141,7 +141,7 @@ impl FontList {
let mut result = None;
paths.iter().all(|path| {
result = Self::from_path(path);
!result.is_some()
result.is_none()
});
if result.is_none() {
@ -194,10 +194,7 @@ impl FontList {
}
}
Some(FontList {
families: families,
aliases: aliases,
})
Some(FontList { families, aliases })
}
// Fonts expected to exist in Android devices.
@ -277,24 +274,19 @@ impl FontList {
let mut fonts = Vec::new();
// Parse font variants
for node in familyset {
match node {
Node::Element {
name,
attributes,
children,
} => {
if name.local_name == "font" {
FontList::parse_font(&children, attributes, &mut fonts);
}
},
_ => {},
if let Node::Element {
name,
attributes,
children,
} = node
{
if name.local_name == "font" {
FontList::parse_font(children, attributes, &mut fonts);
}
}
}
out.push(FontFamily {
name: name,
fonts: fonts,
});
out.push(FontFamily { name, fonts });
}
// Parse family and font file names for Androi API < 21
@ -339,10 +331,7 @@ impl FontList {
.collect();
if !fonts.is_empty() {
out.push(FontFamily {
name: name,
fonts: fonts,
})
out.push(FontFamily { name, fonts })
}
}
}
@ -393,11 +382,7 @@ impl FontList {
// Parse optional weight filter
let weight = Self::find_attrib("weight", attrs).and_then(|w| w.parse().ok());
out.push(FontAlias {
from: from,
to: to,
weight: weight,
})
out.push(FontAlias { from, to, weight })
}
fn find_attrib(name: &str, attrs: &[Attribute]) -> Option<String> {
@ -408,7 +393,7 @@ impl FontList {
}
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::Element { .. } => None,
})

View file

@ -17,7 +17,7 @@ pub(super) enum Node {
pub(super) fn parse(bytes: &[u8]) -> xml::reader::Result<Vec<Node>> {
let mut stack = Vec::new();
let mut nodes = Vec::new();
for result in xml::EventReader::new(&*bytes) {
for result in xml::EventReader::new(bytes) {
match result? {
StartElement {
name, attributes, ..

View file

@ -273,9 +273,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scrollStart<'local>(
y: jint,
) {
debug!("scrollStart");
call(&mut env, |s| {
s.scroll_start(dx as f32, dy as f32, x as i32, y as i32)
});
call(&mut env, |s| s.scroll_start(dx as f32, dy as f32, x, y));
}
#[no_mangle]
@ -288,9 +286,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scrollEnd<'local>(
y: jint,
) {
debug!("scrollEnd");
call(&mut env, |s| {
s.scroll_end(dx as f32, dy as f32, x as i32, y as i32)
});
call(&mut env, |s| s.scroll_end(dx as f32, dy as f32, x, y));
}
#[no_mangle]
@ -303,9 +299,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_scroll<'local>(
y: jint,
) {
debug!("scroll");
call(&mut env, |s| {
s.scroll(dx as f32, dy as f32, x as i32, y as i32)
});
call(&mut env, |s| s.scroll(dx as f32, dy as f32, x, y));
}
#[no_mangle]
@ -317,7 +311,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchDown<'local>(
pointer_id: jint,
) {
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]
@ -329,7 +323,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchUp<'local>(
pointer_id: jint,
) {
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]
@ -341,7 +335,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchMove<'local>(
pointer_id: jint,
) {
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]
@ -353,7 +347,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_touchCancel<'local>(
pointer_id: jint,
) {
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]
@ -365,9 +359,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoomStart<'local>(
y: jint,
) {
debug!("pinchZoomStart");
call(&mut env, |s| {
s.pinchzoom_start(factor as f32, x as u32, y as u32)
});
call(&mut env, |s| s.pinchzoom_start(factor, x as u32, y as u32));
}
#[no_mangle]
@ -379,7 +371,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoom<'local>(
y: jint,
) {
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]
@ -391,26 +383,24 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_pinchZoomEnd<'local>(
y: jint,
) {
debug!("pinchZoomEnd");
call(&mut env, |s| {
s.pinchzoom_end(factor as f32, x as u32, y as u32)
});
call(&mut env, |s| s.pinchzoom_end(factor, x as u32, y as u32));
}
#[no_mangle]
pub extern "C" fn Java_org_servo_servoview_JNIServo_click<'local>(
mut env: JNIEnv<'local>,
_: JClass<'local>,
pub extern "C" fn Java_org_servo_servoview_JNIServo_click(
mut env: JNIEnv,
_: JClass,
x: jfloat,
y: jfloat,
) {
debug!("click");
call(&mut env, |s| s.click(x as f32, y as f32));
call(&mut env, |s| s.click(x, y));
}
#[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,
_: JClass<'local>,
_: JClass<'_>,
) {
debug!("pauseCompositor");
call(&mut env, |s| s.pause_compositor());
@ -439,7 +429,7 @@ pub extern "C" fn Java_org_servo_servoview_JNIServo_mediaSessionAction<'local>(
action: jint,
) {
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 {
@ -531,7 +521,7 @@ impl HostTrait for HostCallbacks {
fn on_title_changed(&self, title: Option<String>) {
debug!("on_title_changed");
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 {
return;
};
@ -557,8 +547,8 @@ impl HostTrait for HostCallbacks {
&[(&url_string).into()],
);
match allow {
Ok(allow) => return allow.z().unwrap(),
Err(_) => return true,
Ok(allow) => allow.z().unwrap(),
Err(_) => true,
}
}
@ -761,8 +751,8 @@ fn get_field<'local>(
}
env.get_field(obj, field, type_)
.map(|value| Some(value))
.or_else(|_| Err(format!("Can't find `{}` field", field)))
.map(Some)
.map_err(|_| format!("Can't find `{}` field", field))
}
fn get_non_null_field<'local>(

View file

@ -30,7 +30,7 @@ use crate::egl::servo_glue::{
use crate::prefs::{parse_command_line_arguments, ArgumentParsingResult};
thread_local! {
pub static SERVO: RefCell<Option<ServoGlue>> = RefCell::new(None);
pub static SERVO: RefCell<Option<ServoGlue>> = const { RefCell::new(None) };
}
pub struct InitOptions {
@ -61,7 +61,7 @@ pub fn init(
resources::set(Box::new(ResourceReaderInstance::new()));
// `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());
let (opts, preferences, servoshell_preferences) = match parse_command_line_arguments(args) {

View file

@ -17,6 +17,7 @@ use servo::config::prefs::{PrefValue, Preferences};
use servo::url::ServoUrl;
use url::Url;
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
pub(crate) struct ServoShellPreferences {
/// The user agent to use for servoshell.
pub user_agent: Option<String>,
@ -138,6 +139,7 @@ pub fn read_prefs_map(txt: &str) -> HashMap<String, PrefValue> {
}
#[allow(clippy::large_enum_variant)]
#[cfg_attr(any(target_os = "android", target_env = "ohos"), allow(dead_code))]
pub(crate) enum ArgumentParsingResult {
ChromeProcess(Opts, Preferences, ServoShellPreferences),
ContentProcess(String),