feat(reload): reload the active tab with Cmd/Ctrl+R
This commit is contained in:
@@ -297,6 +297,13 @@ fn handle_request(
|
||||
drop((webview_id, ready_surface_ids, pending_surface_ids));
|
||||
Ok(outcome)
|
||||
}
|
||||
LiveRequest::Reload { tab_id } => {
|
||||
if let Some(session) = sessions.get_mut(&tab_id) {
|
||||
session.clear_presented_frame();
|
||||
host.reload(&session.webview_id)?;
|
||||
}
|
||||
Ok(LiveOutcome::empty())
|
||||
}
|
||||
LiveRequest::Close { tab_id } => {
|
||||
if let Some(session) = sessions.remove(&tab_id) {
|
||||
host.close_webview(&session.webview_id);
|
||||
|
||||
@@ -68,6 +68,9 @@ pub(super) enum LiveRequest {
|
||||
#[serde(default)]
|
||||
pending_surface_ids: Vec<u64>,
|
||||
},
|
||||
Reload {
|
||||
tab_id: String,
|
||||
},
|
||||
Close {
|
||||
tab_id: String,
|
||||
},
|
||||
|
||||
@@ -372,6 +372,11 @@ pub trait ServoHost {
|
||||
|
||||
fn navigate(&mut self, request: NavigationRequest) -> Result<(), ServoHostError>;
|
||||
|
||||
/// Reload the current document in place (the URL is unchanged). Servo's
|
||||
/// load-status transitions drive the loading indicator, so no navigation
|
||||
/// hold is armed.
|
||||
fn reload(&mut self, webview_id: &WebViewId) -> Result<(), ServoHostError>;
|
||||
|
||||
fn scroll(&mut self, request: ScrollRequest) -> Result<(), ServoHostError>;
|
||||
|
||||
fn resize(&mut self, request: ResizeRequest) -> Result<(), ServoHostError>;
|
||||
|
||||
@@ -227,6 +227,17 @@ impl ServoHost for SoftwareServoHost {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn reload(&mut self, webview_id: &WebViewId) -> Result<(), ServoHostError> {
|
||||
self.servo.spin_event_loop();
|
||||
let webview = self
|
||||
.webviews
|
||||
.get_mut(webview_id)
|
||||
.ok_or_else(|| ServoHostError::WebViewNotFound { id: webview_id.clone() })?;
|
||||
webview.delegate.set_state(WebViewState::Loading);
|
||||
webview.webview.reload();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn scroll(&mut self, request: ScrollRequest) -> Result<(), ServoHostError> {
|
||||
if request.delta_x == 0 && request.delta_y == 0 {
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user