Format remaining files

This commit is contained in:
Pyfisch 2018-11-06 13:01:35 +01:00
parent bf47f90da6
commit cb07debcb6
252 changed files with 5944 additions and 3744 deletions

View file

@ -112,9 +112,8 @@ pub fn init(
resources::set(Box::new(ResourceReader(readfile)));
if let Some(args) = init_opts.args {
let mut args: Vec<String> = serde_json::from_str(&args).map_err(|_| {
"Invalid arguments. Servo arguments must be formatted as a JSON array"
})?;
let mut args: Vec<String> = serde_json::from_str(&args)
.map_err(|_| "Invalid arguments. Servo arguments must be formatted as a JSON array")?;
// opts::from_cmdline_args expects the first argument to be the binary name.
args.insert(0, "servo".to_string());
@ -123,19 +122,19 @@ pub fn init(
opts::from_cmdline_args(&args);
}
let embedder_url = init_opts.url.as_ref().and_then(|s| {
ServoUrl::parse(s).ok()
});
let embedder_url = init_opts.url.as_ref().and_then(|s| ServoUrl::parse(s).ok());
let cmdline_url = opts::get().url.clone();
let pref_url = PREFS.get("shell.homepage").as_string().and_then(|s| {
ServoUrl::parse(s).ok()
});
let pref_url = PREFS
.get("shell.homepage")
.as_string()
.and_then(|s| ServoUrl::parse(s).ok());
let blank_url = ServoUrl::parse("about:blank").ok();
let url = embedder_url
.or(cmdline_url)
.or(pref_url)
.or(blank_url).unwrap();
.or(blank_url)
.unwrap();
gl.clear_color(1.0, 1.0, 1.0, 1.0);
gl.clear(gl::COLOR_BUFFER_BIT);
@ -171,16 +170,14 @@ pub fn init(
}
pub fn deinit() {
SERVO.with(|s| {
s.replace(None).unwrap().deinit()
});
SERVO.with(|s| s.replace(None).unwrap().deinit());
}
impl ServoGlue {
fn get_browser_id(&self) -> Result<BrowserId, &'static str> {
let browser_id = match self.browser_id {
Some(id) => id,
None => return Err("No BrowserId set yet.")
None => return Err("No BrowserId set yet."),
};
Ok(browser_id)
}
@ -417,7 +414,8 @@ impl ServoGlue {
let _ = self.browsers.pop();
if let Some(prev_browser_id) = self.browsers.last() {
self.browser_id = Some(*prev_browser_id);
self.events.push(WindowEvent::SelectBrowser(*prev_browser_id));
self.events
.push(WindowEvent::SelectBrowser(*prev_browser_id));
} else {
self.events.push(WindowEvent::Quit);
}
@ -476,7 +474,8 @@ impl WindowMethods for ServoCallbacks {
fn set_animation_state(&self, state: AnimationState) {
debug!("WindowMethods::set_animation_state");
self.host_callbacks.on_animating_changed(state == AnimationState::Animating);
self.host_callbacks
.on_animating_changed(state == AnimationState::Animating);
}
fn get_coordinates(&self) -> EmbedderCoordinates {

View file

@ -10,7 +10,10 @@ use std::mem;
use std::os::raw::c_char;
use std::rc::Rc;
fn call<F>(f: F) where F: Fn(&mut ServoGlue) -> Result<(), &'static str> {
fn call<F>(f: F)
where
F: Fn(&mut ServoGlue) -> Result<(), &'static str>,
{
SERVO.with(|s| {
if let Err(error) = match s.borrow_mut().as_mut() {
Some(ref mut s) => (f)(s),
@ -27,15 +30,15 @@ fn call<F>(f: F) where F: Fn(&mut ServoGlue) -> Result<(), &'static str> {
/// Callback used by Servo internals
#[repr(C)]
pub struct CHostCallbacks {
pub flush: extern fn(),
pub make_current: extern fn(),
pub on_load_started: extern fn(),
pub on_load_ended: extern fn(),
pub on_title_changed: extern fn(title: *const c_char),
pub on_url_changed: extern fn(url: *const c_char),
pub on_history_changed: extern fn(can_go_back: bool, can_go_forward: bool),
pub on_animating_changed: extern fn(animating: bool),
pub on_shutdown_complete: extern fn(),
pub flush: extern "C" fn(),
pub make_current: extern "C" fn(),
pub on_load_started: extern "C" fn(),
pub on_load_ended: extern "C" fn(),
pub on_title_changed: extern "C" fn(title: *const c_char),
pub on_url_changed: extern "C" fn(url: *const c_char),
pub on_history_changed: extern "C" fn(can_go_back: bool, can_go_forward: bool),
pub on_animating_changed: extern "C" fn(animating: bool),
pub on_shutdown_complete: extern "C" fn(),
}
/// Servo options
@ -62,9 +65,10 @@ pub extern "C" fn servo_version() -> *const c_char {
fn init(
opts: CInitOptions,
gl: Rc<gl::Gl>,
wakeup: extern fn(),
readfile: extern fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks) {
wakeup: extern "C" fn(),
readfile: extern "C" fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks,
) {
let args = unsafe { CStr::from_ptr(opts.args) };
let args = args.to_str().map(|s| s.to_string()).ok();
@ -91,20 +95,26 @@ fn init(
#[no_mangle]
pub extern "C" fn init_with_egl(
opts: CInitOptions,
wakeup: extern fn(),
readfile: extern fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks) {
wakeup: extern "C" fn(),
readfile: extern "C" fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks,
) {
let gl = gl_glue::egl::init().unwrap();
init(opts, gl, wakeup, readfile, callbacks)
}
#[cfg(any(target_os = "linux", target_os = "windows", target_os = "macos"))]
#[cfg(any(
target_os = "linux",
target_os = "windows",
target_os = "macos"
))]
#[no_mangle]
pub extern "C" fn init_with_gl(
opts: CInitOptions,
wakeup: extern fn(),
readfile: extern fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks) {
wakeup: extern "C" fn(),
readfile: extern "C" fn(*const c_char) -> *const c_char,
callbacks: CHostCallbacks,
) {
let gl = gl_glue::gl::init().unwrap();
init(opts, gl, wakeup, readfile, callbacks)
}
@ -219,10 +229,10 @@ pub extern "C" fn click(x: i32, y: i32) {
call(|s| s.click(x as u32, y as u32));
}
pub struct WakeupCallback(extern fn());
pub struct WakeupCallback(extern "C" fn());
impl WakeupCallback {
fn new(callback: extern fn()) -> WakeupCallback {
fn new(callback: extern "C" fn()) -> WakeupCallback {
WakeupCallback(callback)
}
}
@ -236,10 +246,10 @@ impl EventLoopWaker for WakeupCallback {
}
}
pub struct ReadFileCallback(extern fn(*const c_char) -> *const c_char);
pub struct ReadFileCallback(extern "C" fn(*const c_char) -> *const c_char);
impl ReadFileCallback {
fn new(callback: extern fn(*const c_char) -> *const c_char) -> ReadFileCallback {
fn new(callback: extern "C" fn(*const c_char) -> *const c_char) -> ReadFileCallback {
ReadFileCallback(callback)
}
}

View file

@ -22,7 +22,11 @@ pub mod egl {
pub type EGLNativeWindowType = *const libc::c_void;
#[cfg(target_os = "android")]
pub type EGLNativeWindowType = *const libc::c_void;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
#[cfg(any(
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd"
))]
pub type EGLNativeWindowType = *const libc::c_void;
pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
@ -77,7 +81,11 @@ pub mod egl {
}
}
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(any(
target_os = "windows",
target_os = "linux",
target_os = "macos"
))]
pub mod gl {
use servo::gl::Gl;
use std::rc::Rc;

View file

@ -55,7 +55,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
Err(err) => {
throw(&env, &err);
return;
}
},
};
if log {
@ -95,7 +95,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
Err(_) => {
throw(&env, "Failed to get global reference of callback argument");
return;
}
},
};
let wakeup = Box::new(WakeupCallback::new(callbacks_ref.clone(), &env));
@ -110,11 +110,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_init(
}
#[no_mangle]
pub fn Java_org_mozilla_servoview_JNIServo_setBatchMode(
env: JNIEnv,
_: JClass,
batch: jboolean,
) {
pub fn Java_org_mozilla_servoview_JNIServo_setBatchMode(env: JNIEnv, _: JClass, batch: jboolean) {
debug!("setBatchMode");
call(&env, |s| s.set_batch_mode(batch == JNI_TRUE));
}
@ -158,7 +154,7 @@ pub fn Java_org_mozilla_servoview_JNIServo_loadUri(env: JNIEnv, _class: JClass,
},
Err(_) => {
throw(&env, "Failed to convert Java string");
}
},
};
}
@ -202,7 +198,9 @@ pub fn Java_org_mozilla_servoview_JNIServo_scrollStart(
y: jint,
) {
debug!("scrollStart");
call(&env, |s| s.scroll_start(dx as i32, dy as i32, x as u32, y as u32));
call(&env, |s| {
s.scroll_start(dx as i32, dy as i32, x as u32, y as u32)
});
}
#[no_mangle]
@ -215,10 +213,11 @@ pub fn Java_org_mozilla_servoview_JNIServo_scrollEnd(
y: jint,
) {
debug!("scrollEnd");
call(&env, |s| s.scroll_end(dx as i32, dy as i32, x as u32, y as u32));
call(&env, |s| {
s.scroll_end(dx as i32, dy as i32, x as u32, y as u32)
});
}
#[no_mangle]
pub fn Java_org_mozilla_servoview_JNIServo_scroll(
env: JNIEnv,
@ -241,7 +240,9 @@ pub fn Java_org_mozilla_servoview_JNIServo_pinchZoomStart(
y: jint,
) {
debug!("pinchZoomStart");
call(&env, |s| s.pinchzoom_start(factor as f32, x as u32, y as u32));
call(&env, |s| {
s.pinchzoom_start(factor as f32, x as u32, y as u32)
});
}
#[no_mangle]
@ -268,7 +269,6 @@ pub fn Java_org_mozilla_servoview_JNIServo_pinchZoomEnd(
call(&env, |s| s.pinchzoom_end(factor as f32, x as u32, y as u32));
}
#[no_mangle]
pub fn Java_org_mozilla_servoview_JNIServo_click(env: JNIEnv, _: JClass, x: jint, y: jint) {
debug!("click");
@ -391,7 +391,8 @@ impl HostTrait for HostCallbacks {
"onTitleChanged",
"(Ljava/lang/String;)V",
&[s],
).unwrap();
)
.unwrap();
}
fn on_url_changed(&self, url: String) {
@ -407,7 +408,8 @@ impl HostTrait for HostCallbacks {
"onUrlChanged",
"(Ljava/lang/String;)V",
&[s],
).unwrap();
)
.unwrap();
}
fn on_history_changed(&self, can_go_back: bool, can_go_forward: bool) {
@ -420,7 +422,8 @@ impl HostTrait for HostCallbacks {
"onHistoryChanged",
"(ZZ)V",
&[can_go_back, can_go_forward],
).unwrap();
)
.unwrap();
}
fn on_animating_changed(&self, animating: bool) {
@ -432,7 +435,8 @@ impl HostTrait for HostCallbacks {
"onAnimatingChanged",
"(Z)V",
&[animating],
).unwrap();
)
.unwrap();
}
}
@ -441,17 +445,11 @@ fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
// From jni-rs to android_injected_glue
let mut app: ffi::android_app = unsafe {
std::mem::zeroed()
};
let mut native_activity: ffi::ANativeActivity = unsafe {
std::mem::zeroed()
};
let mut app: ffi::android_app = unsafe { std::mem::zeroed() };
let mut native_activity: ffi::ANativeActivity = unsafe { std::mem::zeroed() };
let clazz = Box::into_raw(Box::new(env.new_global_ref(activity).unwrap()));
native_activity.clazz = unsafe {
(*clazz).as_obj().into_inner() as *mut c_void
};
native_activity.clazz = unsafe { (*clazz).as_obj().into_inner() as *mut c_void };
let vm = env.get_java_vm().unwrap().get_java_vm_pointer();
native_activity.vm = vm as *mut ffi::_JavaVM;
@ -463,7 +461,7 @@ fn initialize_android_glue(env: &JNIEnv, activity: JObject) {
}
}
extern {
extern "C" {
pub fn __android_log_write(prio: c_int, tag: *const c_char, text: *const c_char) -> c_int;
}
@ -497,7 +495,11 @@ fn redirect_stdout_to_logcat() {
let result = {
let read_into = &mut buf[cursor..];
unsafe {
read(descriptor, read_into.as_mut_ptr() as *mut _, read_into.len())
read(
descriptor,
read_into.as_mut_ptr() as *mut _,
read_into.len(),
)
}
};
@ -505,7 +507,11 @@ fn redirect_stdout_to_logcat() {
return;
} else if result < 0 {
unsafe {
__android_log_write(3, tag, b"error in log thread; closing\0".as_ptr() as *const _);
__android_log_write(
3,
tag,
b"error in log thread; closing\0".as_ptr() as *const _,
);
}
return;
} else {
@ -546,7 +552,10 @@ fn redirect_stdout_to_logcat() {
fn throw(env: &JNIEnv, err: &str) {
if let Err(e) = env.throw(("java/lang/Exception", err)) {
warn!("Failed to throw Java exception: `{}`. Exception was: `{}`", e, err);
warn!(
"Failed to throw Java exception: `{}`. Exception was: `{}`",
e, err
);
}
}