mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
This implements a simple tab system for servoshell: - The egui part uses the built-in SelectableLabels components and display the full tab title on hover. - WebView structs now hold all the state for each WebView. When we need "global" state, we return the focused WebView state, eg. for the load status since it's still global in the UI. - New keyboard shortcut: [Cmd-or-Ctrl]+[W] to close the current tab. - New keyboard shortcut: [Cmd-or-Ctrl]+[T] to create a new tab. - The new tab content is loaded from the 'servo:newtab' url using a couple of custom protocol handlers. Signed-off-by: webbeef <me@webbeef.org>
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
//! Loads resources using a mapping from well-known shortcuts to resource: urls.
|
|
//! Recognized shorcuts:
|
|
//! - servo:newtab
|
|
|
|
use std::future::Future;
|
|
use std::pin::Pin;
|
|
|
|
use net::fetch::methods::{DoneChannel, FetchContext};
|
|
use net::protocols::ProtocolHandler;
|
|
use net_traits::request::Request;
|
|
use net_traits::response::Response;
|
|
|
|
use crate::desktop::protocols::resource::ResourceProtocolHander;
|
|
|
|
#[derive(Default)]
|
|
pub struct ServoProtocolHander {}
|
|
|
|
impl ProtocolHandler for ServoProtocolHander {
|
|
fn load(
|
|
&self,
|
|
request: &mut Request,
|
|
done_chan: &mut DoneChannel,
|
|
context: &FetchContext,
|
|
) -> Pin<Box<dyn Future<Output = Response> + Send>> {
|
|
let url = request.current_url();
|
|
|
|
match url.path() {
|
|
"newtab" => ResourceProtocolHander::response_for_path(
|
|
request,
|
|
done_chan,
|
|
context,
|
|
"/newtab.html",
|
|
),
|
|
_ => Box::pin(std::future::ready(Response::network_internal_error(
|
|
"Invalid shortcut",
|
|
))),
|
|
}
|
|
}
|
|
}
|