Skip to content

Commit

Permalink
Applied clippy suggestions (#156)
Browse files Browse the repository at this point in the history
* Applied clippy suggestions

I ran "cargo clippy" on the codebase and applied it's suggestions. I also implemented the Default trait for the TouchHandler inside touch.rs and moved the new() function over to the default() function.

* Reversed to cfg-aliases for target_os annotations and removed unnecessary comments
  • Loading branch information
levipalait authored Aug 17, 2024
1 parent f2e1531 commit 7b61d8c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 29 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ harness = false

[profile.release-lto]
inherits = "release"
lto = true
lto = true

# Tell clippy to allow e.g. #[cfg(macos)]
[lints.clippy]
mismatched_target_os = "allow"
10 changes: 3 additions & 7 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1746,9 +1746,9 @@ impl IOCompositor {
if previous_pipeline_id.replace(pipeline_id) != Some(pipeline_id) {
let scroll_result = self
.pipeline_details
.get_mut(&pipeline_id)?
.get_mut(pipeline_id)?
.scroll_tree
.scroll_node_or_ancestor(&scroll_tree_node, scroll_location);
.scroll_node_or_ancestor(scroll_tree_node, scroll_location);
if let Some((external_id, offset)) = scroll_result {
return Some((*pipeline_id, external_id, offset));
}
Expand Down Expand Up @@ -1778,11 +1778,7 @@ impl IOCompositor {
pipeline_ids.push(*pipeline_id);
}
}
if pipeline_ids.is_empty() && !self.webxr_main_thread.running() {
self.is_animating = false;
} else {
self.is_animating = true;
};
self.is_animating = !pipeline_ids.is_empty() || self.webxr_main_thread.running();
for pipeline_id in &pipeline_ids {
self.tick_animations_for_pipeline(*pipeline_id)
}
Expand Down
2 changes: 1 addition & 1 deletion src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn get_servo_key_from_winit_key(key: &LogicalKey) -> Key {
// TODO: figure out how to map NavigateForward, NavigateBackward
// TODO: map the remaining keys if possible
match key {
LogicalKey::Character(c) => return Key::Character(c.to_string()),
LogicalKey::Character(c) => Key::Character(c.to_string()),
// printable: Key1 to Key0
// printable: A to Z
LogicalKey::Named(NamedKey::Escape) => Key::Escape,
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ impl ApplicationHandler for App {
window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
self.verso.as_mut().map(|v| {
if let Some(v) = self.verso.as_mut() {
v.handle_winit_window_event(window_id, event);
v.handle_servo_messages(event_loop);
});
}
}

fn user_event(&mut self, event_loop: &event_loop::ActiveEventLoop, _: ()) {
self.verso.as_mut().map(|v| {
if let Some(v) = self.verso.as_mut() {
v.handle_servo_messages(event_loop);
});
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ pub enum TouchAction {
NoAction,
}

impl TouchHandler {
/// Create a touch handler.
pub fn new() -> Self {
TouchHandler {
impl Default for TouchHandler {
fn default() -> Self {
Self {
state: Nothing,
active_touch_points: Vec::new(),
}
}
}

impl TouchHandler {
/// Create a touch handler.
pub fn new() -> Self {
Self::default()
}

/// Handle touch down input.
pub fn on_touch_down(&mut self, id: TouchId, point: Point2D<f32, DevicePixel>) {
Expand Down
4 changes: 3 additions & 1 deletion src/verso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,9 @@ impl Verso {
// Check compositor status and set control flow.
if shutdown {
// If Compositor has shut down, deinit and remove it.
self.compositor.take().map(IOCompositor::deinit);
if let Some(compositor) = self.compositor.take() {
IOCompositor::deinit(compositor)
}
evl.exit();
} else if self.is_animating() {
evl.set_control_flow(ControlFlow::Poll);
Expand Down
19 changes: 11 additions & 8 deletions src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ impl Window {
}
}
EmbedderMsg::SetClipboardContents(text) => {
clipboard.map(|c| {
if let Some(c) = clipboard {
if let Err(e) = c.set_text(text) {
log::warn!(
"Verso WebView {webview_id:?} failed to set clipboard contents: {}",
e
);
}
});
}
}
EmbedderMsg::EventDelivered(event) => {
if let CompositorEventVariant::MouseButtonEvent = event {
Expand Down Expand Up @@ -178,16 +178,19 @@ impl Window {
let url = match Url::parse(unparsed_url) {
Ok(url_parsed) => url_parsed,
Err(e) => {
if e == url::ParseError::RelativeUrlWithoutBase
{
Url::parse(&format!("https://{}", unparsed_url)).unwrap()
if e == url::ParseError::RelativeUrlWithoutBase {
Url::parse(&format!("https://{}", unparsed_url))
.unwrap()
} else {
panic!("Verso Panel failed to parse URL: {}", e);
}
}
};

send_to_constellation(sender, ConstellationMsg::LoadUrl(id, ServoUrl::from_url(url)));
send_to_constellation(
sender,
ConstellationMsg::LoadUrl(id, ServoUrl::from_url(url)),
);
} else {
match msg.as_str() {
"PREV" => {
Expand Down Expand Up @@ -245,11 +248,11 @@ impl Window {
}
}
EmbedderMsg::SetClipboardContents(text) => {
clipboard.map(|c| {
if let Some(c) = clipboard {
if let Err(e) = c.set_text(text) {
log::warn!("Verso Panel failed to set clipboard contents: {}", e);
}
});
}
}
e => {
log::trace!("Verso Panel isn't supporting this message yet: {e:?}")
Expand Down
6 changes: 3 additions & 3 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl Window {
}
WindowEvent::ModifiersChanged(modifier) => self.modifiers_state.set(modifier.state()),
WindowEvent::KeyboardInput { event, .. } => {
let event = keyboard_event_from_winit(&event, self.modifiers_state.get());
let event = keyboard_event_from_winit(event, self.modifiers_state.get());
log::trace!("Verso is handling {:?}", event);
let msg = ConstellationMsg::Keyboard(event);
send_to_constellation(sender, msg);
Expand Down Expand Up @@ -312,12 +312,12 @@ impl Window {
compositor: &mut IOCompositor,
) -> (Option<WebView>, bool) {
if self.panel.as_ref().filter(|w| w.webview_id == id).is_some() {
self.webview.as_ref().map(|w| {
if let Some(w) = self.webview.as_ref() {
send_to_constellation(
&compositor.constellation_chan,
ConstellationMsg::CloseWebView(w.webview_id),
)
});
}
(self.panel.take(), false)
} else if self
.webview
Expand Down

0 comments on commit 7b61d8c

Please sign in to comment.