mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
[NFC] winit: document event handling and improve naming (#30016)
* compositing: rename WindowEvent to EmbedderEvent * winit: rename winit_event_to_{servo → embedder}_event * winit: rename ServoEvent::Awakened to WakerEvent * winit: document App::handle_events and rename locals * servo: rename Servo.embedder_events to messages_for_embedder * winit: rustdoc link to EmbedderEvent * winit: use new name queue_embedder_events_for_winit_event
This commit is contained in:
parent
605bf52334
commit
dfeced5a8e
10 changed files with 228 additions and 202 deletions
|
@ -18,7 +18,7 @@ pub use servo::webrender_api::units::DeviceIntRect;
|
|||
use getopts::Options;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use servo::compositing::windowing::{
|
||||
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
||||
AnimationState, EmbedderCoordinates, EmbedderEvent, EmbedderMethods, MouseWindowEvent,
|
||||
WindowMethods,
|
||||
};
|
||||
use servo::config::prefs::pref_map;
|
||||
|
@ -179,7 +179,7 @@ pub struct ServoGlue {
|
|||
// EmbedderMsg::CloseBrowser will pop from it,
|
||||
// and exit if it is empty afterwards.
|
||||
browsers: Vec<BrowserId>,
|
||||
events: Vec<WindowEvent>,
|
||||
events: Vec<EmbedderEvent>,
|
||||
|
||||
context_menu_sender: Option<IpcSender<ContextMenuResult>>,
|
||||
}
|
||||
|
@ -316,7 +316,7 @@ pub fn init(
|
|||
events: vec![],
|
||||
context_menu_sender: None,
|
||||
};
|
||||
let _ = servo_glue.process_event(WindowEvent::NewBrowser(url, servo.browser_id));
|
||||
let _ = servo_glue.process_event(EmbedderEvent::NewBrowser(url, servo.browser_id));
|
||||
*s.borrow_mut() = Some(servo_glue);
|
||||
});
|
||||
|
||||
|
@ -338,7 +338,7 @@ impl ServoGlue {
|
|||
|
||||
/// Request shutdown. Will call on_shutdown_complete.
|
||||
pub fn request_shutdown(&mut self) -> Result<(), &'static str> {
|
||||
self.process_event(WindowEvent::Quit)
|
||||
self.process_event(EmbedderEvent::Quit)
|
||||
}
|
||||
|
||||
/// Call after on_shutdown_complete
|
||||
|
@ -382,7 +382,7 @@ impl ServoGlue {
|
|||
.map_err(|_| "Can't parse URL")
|
||||
.and_then(|url| {
|
||||
let browser_id = self.get_browser_id()?;
|
||||
let event = WindowEvent::LoadUrl(browser_id, url);
|
||||
let event = EmbedderEvent::LoadUrl(browser_id, url);
|
||||
self.process_event(event)
|
||||
})
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ impl ServoGlue {
|
|||
/// Reload the page.
|
||||
pub fn clear_cache(&mut self) -> Result<(), &'static str> {
|
||||
info!("clear_cache");
|
||||
let event = WindowEvent::ClearCache;
|
||||
let event = EmbedderEvent::ClearCache;
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -398,14 +398,14 @@ impl ServoGlue {
|
|||
pub fn reload(&mut self) -> Result<(), &'static str> {
|
||||
info!("reload");
|
||||
let browser_id = self.get_browser_id()?;
|
||||
let event = WindowEvent::Reload(browser_id);
|
||||
let event = EmbedderEvent::Reload(browser_id);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Redraw the page.
|
||||
pub fn refresh(&mut self) -> Result<(), &'static str> {
|
||||
info!("refresh");
|
||||
self.process_event(WindowEvent::Refresh)
|
||||
self.process_event(EmbedderEvent::Refresh)
|
||||
}
|
||||
|
||||
/// Stop loading the page.
|
||||
|
@ -418,7 +418,7 @@ impl ServoGlue {
|
|||
pub fn go_back(&mut self) -> Result<(), &'static str> {
|
||||
info!("go_back");
|
||||
let browser_id = self.get_browser_id()?;
|
||||
let event = WindowEvent::Navigation(browser_id, TraversalDirection::Back(1));
|
||||
let event = EmbedderEvent::Navigation(browser_id, TraversalDirection::Back(1));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -426,7 +426,7 @@ impl ServoGlue {
|
|||
pub fn go_forward(&mut self) -> Result<(), &'static str> {
|
||||
info!("go_forward");
|
||||
let browser_id = self.get_browser_id()?;
|
||||
let event = WindowEvent::Navigation(browser_id, TraversalDirection::Forward(1));
|
||||
let event = EmbedderEvent::Navigation(browser_id, TraversalDirection::Forward(1));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -434,7 +434,7 @@ impl ServoGlue {
|
|||
pub fn resize(&mut self, coordinates: Coordinates) -> Result<(), &'static str> {
|
||||
info!("resize");
|
||||
*self.callbacks.coordinates.borrow_mut() = coordinates;
|
||||
self.process_event(WindowEvent::Resize)
|
||||
self.process_event(EmbedderEvent::Resize)
|
||||
}
|
||||
|
||||
/// Start scrolling.
|
||||
|
@ -443,7 +443,8 @@ impl ServoGlue {
|
|||
pub fn scroll_start(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = Vector2D::new(dx, dy);
|
||||
let scroll_location = ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Down);
|
||||
let event =
|
||||
EmbedderEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Down);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -453,7 +454,8 @@ impl ServoGlue {
|
|||
pub fn scroll(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = Vector2D::new(dx, dy);
|
||||
let scroll_location = ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Move);
|
||||
let event =
|
||||
EmbedderEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Move);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -463,13 +465,13 @@ impl ServoGlue {
|
|||
pub fn scroll_end(&mut self, dx: f32, dy: f32, x: i32, y: i32) -> Result<(), &'static str> {
|
||||
let delta = Vector2D::new(dx, dy);
|
||||
let scroll_location = ScrollLocation::Delta(delta);
|
||||
let event = WindowEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Up);
|
||||
let event = EmbedderEvent::Scroll(scroll_location, Point2D::new(x, y), TouchEventType::Up);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Touch event: press down
|
||||
pub fn touch_down(&mut self, x: f32, y: f32, pointer_id: i32) -> Result<(), &'static str> {
|
||||
let event = WindowEvent::Touch(
|
||||
let event = EmbedderEvent::Touch(
|
||||
TouchEventType::Down,
|
||||
TouchId(pointer_id),
|
||||
Point2D::new(x as f32, y as f32),
|
||||
|
@ -479,7 +481,7 @@ impl ServoGlue {
|
|||
|
||||
/// Touch event: move touching finger
|
||||
pub fn touch_move(&mut self, x: f32, y: f32, pointer_id: i32) -> Result<(), &'static str> {
|
||||
let event = WindowEvent::Touch(
|
||||
let event = EmbedderEvent::Touch(
|
||||
TouchEventType::Move,
|
||||
TouchId(pointer_id),
|
||||
Point2D::new(x as f32, y as f32),
|
||||
|
@ -489,7 +491,7 @@ impl ServoGlue {
|
|||
|
||||
/// Touch event: Lift touching finger
|
||||
pub fn touch_up(&mut self, x: f32, y: f32, pointer_id: i32) -> Result<(), &'static str> {
|
||||
let event = WindowEvent::Touch(
|
||||
let event = EmbedderEvent::Touch(
|
||||
TouchEventType::Up,
|
||||
TouchId(pointer_id),
|
||||
Point2D::new(x as f32, y as f32),
|
||||
|
@ -499,7 +501,7 @@ impl ServoGlue {
|
|||
|
||||
/// Cancel touch event
|
||||
pub fn touch_cancel(&mut self, x: f32, y: f32, pointer_id: i32) -> Result<(), &'static str> {
|
||||
let event = WindowEvent::Touch(
|
||||
let event = EmbedderEvent::Touch(
|
||||
TouchEventType::Cancel,
|
||||
TouchId(pointer_id),
|
||||
Point2D::new(x as f32, y as f32),
|
||||
|
@ -510,46 +512,47 @@ impl ServoGlue {
|
|||
/// Register a mouse movement.
|
||||
pub fn mouse_move(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
|
||||
let point = Point2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowMoveEventClass(point);
|
||||
let event = EmbedderEvent::MouseWindowMoveEventClass(point);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Register a mouse button press.
|
||||
pub fn mouse_down(&mut self, x: f32, y: f32, button: MouseButton) -> Result<(), &'static str> {
|
||||
let point = Point2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseDown(button, point));
|
||||
let event =
|
||||
EmbedderEvent::MouseWindowEventClass(MouseWindowEvent::MouseDown(button, point));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Register a mouse button release.
|
||||
pub fn mouse_up(&mut self, x: f32, y: f32, button: MouseButton) -> Result<(), &'static str> {
|
||||
let point = Point2D::new(x, y);
|
||||
let event = WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseUp(button, point));
|
||||
let event = EmbedderEvent::MouseWindowEventClass(MouseWindowEvent::MouseUp(button, point));
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
/// Start pinchzoom.
|
||||
/// x/y are pinch origin coordinates.
|
||||
pub fn pinchzoom_start(&mut self, factor: f32, _x: u32, _y: u32) -> Result<(), &'static str> {
|
||||
self.process_event(WindowEvent::PinchZoom(factor))
|
||||
self.process_event(EmbedderEvent::PinchZoom(factor))
|
||||
}
|
||||
|
||||
/// Pinchzoom.
|
||||
/// x/y are pinch origin coordinates.
|
||||
pub fn pinchzoom(&mut self, factor: f32, _x: u32, _y: u32) -> Result<(), &'static str> {
|
||||
self.process_event(WindowEvent::PinchZoom(factor))
|
||||
self.process_event(EmbedderEvent::PinchZoom(factor))
|
||||
}
|
||||
|
||||
/// End pinchzoom.
|
||||
/// x/y are pinch origin coordinates.
|
||||
pub fn pinchzoom_end(&mut self, factor: f32, _x: u32, _y: u32) -> Result<(), &'static str> {
|
||||
self.process_event(WindowEvent::PinchZoom(factor))
|
||||
self.process_event(EmbedderEvent::PinchZoom(factor))
|
||||
}
|
||||
|
||||
/// Perform a click.
|
||||
pub fn click(&mut self, x: f32, y: f32) -> Result<(), &'static str> {
|
||||
let mouse_event = MouseWindowEvent::Click(MouseButton::Left, Point2D::new(x, y));
|
||||
let event = WindowEvent::MouseWindowEventClass(mouse_event);
|
||||
let event = EmbedderEvent::MouseWindowEventClass(mouse_event);
|
||||
self.process_event(event)
|
||||
}
|
||||
|
||||
|
@ -559,7 +562,7 @@ impl ServoGlue {
|
|||
key,
|
||||
..KeyboardEvent::default()
|
||||
};
|
||||
self.process_event(WindowEvent::Keyboard(key_event))
|
||||
self.process_event(EmbedderEvent::Keyboard(key_event))
|
||||
}
|
||||
|
||||
pub fn key_up(&mut self, key: Key) -> Result<(), &'static str> {
|
||||
|
@ -568,7 +571,7 @@ impl ServoGlue {
|
|||
key,
|
||||
..KeyboardEvent::default()
|
||||
};
|
||||
self.process_event(WindowEvent::Keyboard(key_event))
|
||||
self.process_event(EmbedderEvent::Keyboard(key_event))
|
||||
}
|
||||
|
||||
pub fn media_session_action(
|
||||
|
@ -576,13 +579,13 @@ impl ServoGlue {
|
|||
action: MediaSessionActionType,
|
||||
) -> Result<(), &'static str> {
|
||||
info!("Media session action {:?}", action);
|
||||
self.process_event(WindowEvent::MediaSessionAction(action))
|
||||
self.process_event(EmbedderEvent::MediaSessionAction(action))
|
||||
}
|
||||
|
||||
pub fn change_visibility(&mut self, visible: bool) -> Result<(), &'static str> {
|
||||
info!("change_visibility");
|
||||
if let Ok(id) = self.get_browser_id() {
|
||||
let event = WindowEvent::ChangeBrowserVisibility(id, visible);
|
||||
let event = EmbedderEvent::ChangeBrowserVisibility(id, visible);
|
||||
self.process_event(event)
|
||||
} else {
|
||||
// Ignore visibility change if no browser has been created yet.
|
||||
|
@ -592,7 +595,7 @@ impl ServoGlue {
|
|||
|
||||
pub fn ime_dismissed(&mut self) -> Result<(), &'static str> {
|
||||
info!("ime_dismissed");
|
||||
self.process_event(WindowEvent::IMEDismissed)
|
||||
self.process_event(EmbedderEvent::IMEDismissed)
|
||||
}
|
||||
|
||||
pub fn on_context_menu_closed(
|
||||
|
@ -607,7 +610,7 @@ impl ServoGlue {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn process_event(&mut self, event: WindowEvent) -> Result<(), &'static str> {
|
||||
fn process_event(&mut self, event: EmbedderEvent) -> Result<(), &'static str> {
|
||||
self.events.push(event);
|
||||
if !self.batch_mode {
|
||||
self.perform_updates()
|
||||
|
@ -628,7 +631,8 @@ impl ServoGlue {
|
|||
.callbacks
|
||||
.host_callbacks
|
||||
.on_allow_navigation(url.to_string());
|
||||
let window_event = WindowEvent::AllowNavigationResponse(pipeline_id, data);
|
||||
let window_event =
|
||||
EmbedderEvent::AllowNavigationResponse(pipeline_id, data);
|
||||
self.events.push(window_event);
|
||||
let _ = self.perform_updates();
|
||||
}
|
||||
|
@ -687,7 +691,8 @@ impl ServoGlue {
|
|||
};
|
||||
if let Err(e) = res {
|
||||
let reason = format!("Failed to send Prompt response: {}", e);
|
||||
self.events.push(WindowEvent::SendError(browser_id, reason));
|
||||
self.events
|
||||
.push(EmbedderEvent::SendError(browser_id, reason));
|
||||
}
|
||||
},
|
||||
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
||||
|
@ -703,7 +708,8 @@ impl ServoGlue {
|
|||
if self.browser_id.is_none() {
|
||||
self.browser_id = Some(new_browser_id);
|
||||
}
|
||||
self.events.push(WindowEvent::SelectBrowser(new_browser_id));
|
||||
self.events
|
||||
.push(EmbedderEvent::SelectBrowser(new_browser_id));
|
||||
},
|
||||
EmbedderMsg::GetClipboardContents(sender) => {
|
||||
let contents = self.callbacks.host_callbacks.get_clipboard_contents();
|
||||
|
@ -718,9 +724,9 @@ impl ServoGlue {
|
|||
if let Some(prev_browser_id) = self.browsers.last() {
|
||||
self.browser_id = Some(*prev_browser_id);
|
||||
self.events
|
||||
.push(WindowEvent::SelectBrowser(*prev_browser_id));
|
||||
.push(EmbedderEvent::SelectBrowser(*prev_browser_id));
|
||||
} else {
|
||||
self.events.push(WindowEvent::Quit);
|
||||
self.events.push(EmbedderEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::Shutdown => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue