mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
constellation: focusing and closing webviews (#30842)
* constellation: focusing, closing, and native window visibility * rename “browser” to “webview”, “unfocus” to “blur” * remove native window visibility from constellation * rename more “browser” to “webview” * guard clauses * don’t automatically focus when no webviews are focused * comment spec steps for window.close() * use format interpolation Co-authored-by: Martin Robinson <mrobinson@igalia.com> * fix formatting * rename “Webview” to “WebView” in types and type parameters * remove unused method * fix libsimpleservo --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
6baaa82826
commit
eb95703325
16 changed files with 533 additions and 285 deletions
|
@ -31,7 +31,7 @@ use servo::embedder_traits::{
|
|||
use servo::euclid::{Point2D, Rect, Scale, Size2D, Vector2D};
|
||||
use servo::keyboard_types::{Key, KeyState, KeyboardEvent};
|
||||
pub use servo::msg::constellation_msg::InputMethodType;
|
||||
use servo::msg::constellation_msg::TraversalDirection;
|
||||
use servo::msg::constellation_msg::{TraversalDirection, WebViewId};
|
||||
pub use servo::script_traits::{MediaSessionActionType, MouseButton};
|
||||
use servo::script_traits::{TouchEventType, TouchId};
|
||||
use servo::servo_config::{opts, pref};
|
||||
|
@ -168,19 +168,25 @@ pub struct ServoGlue {
|
|||
servo: Servo<ServoWindowCallbacks>,
|
||||
batch_mode: bool,
|
||||
callbacks: Rc<ServoWindowCallbacks>,
|
||||
/// id of the top level browsing context. It is unique as tabs
|
||||
/// are not supported yet. None until created.
|
||||
browser_id: Option<BrowserId>,
|
||||
// A rudimentary stack of "tabs".
|
||||
// EmbedderMsg::BrowserCreated will push onto it.
|
||||
// EmbedderMsg::CloseBrowser will pop from it,
|
||||
// and exit if it is empty afterwards.
|
||||
browsers: Vec<BrowserId>,
|
||||
events: Vec<EmbedderEvent>,
|
||||
|
||||
context_menu_sender: Option<IpcSender<ContextMenuResult>>,
|
||||
|
||||
/// List of top-level browsing contexts.
|
||||
/// Modified by EmbedderMsg::WebViewOpened and EmbedderMsg::WebViewClosed,
|
||||
/// and we exit if it ever becomes empty.
|
||||
webviews: HashMap<WebViewId, WebView>,
|
||||
|
||||
/// The order in which the webviews were created.
|
||||
creation_order: Vec<WebViewId>,
|
||||
|
||||
/// The webview that is currently focused.
|
||||
/// Modified by EmbedderMsg::WebViewFocused and EmbedderMsg::WebViewBlurred.
|
||||
focused_webview_id: Option<WebViewId>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WebView {}
|
||||
|
||||
pub fn servo_version() -> String {
|
||||
format!(
|
||||
"Servo {}-{}",
|
||||
|
@ -312,12 +318,13 @@ pub fn init(
|
|||
servo: servo.servo,
|
||||
batch_mode: false,
|
||||
callbacks: window_callbacks,
|
||||
browser_id: None,
|
||||
browsers: vec![],
|
||||
events: vec![],
|
||||
context_menu_sender: None,
|
||||
webviews: HashMap::default(),
|
||||
creation_order: vec![],
|
||||
focused_webview_id: None,
|
||||
};
|
||||
let _ = servo_glue.process_event(EmbedderEvent::NewBrowser(url, servo.browser_id));
|
||||
let _ = servo_glue.process_event(EmbedderEvent::NewWebView(url, servo.browser_id));
|
||||
*s.borrow_mut() = Some(servo_glue);
|
||||
});
|
||||
|
||||
|
@ -330,11 +337,11 @@ pub fn deinit() {
|
|||
|
||||
impl ServoGlue {
|
||||
fn get_browser_id(&self) -> Result<BrowserId, &'static str> {
|
||||
let browser_id = match self.browser_id {
|
||||
let webview_id = match self.focused_webview_id {
|
||||
Some(id) => id,
|
||||
None => return Err("No BrowserId set yet."),
|
||||
None => return Err("No focused WebViewId yet."),
|
||||
};
|
||||
Ok(browser_id)
|
||||
Ok(webview_id)
|
||||
}
|
||||
|
||||
/// Request shutdown. Will call on_shutdown_complete.
|
||||
|
@ -604,7 +611,7 @@ impl ServoGlue {
|
|||
pub fn change_visibility(&mut self, visible: bool) -> Result<(), &'static str> {
|
||||
info!("change_visibility");
|
||||
if let Ok(id) = self.get_browser_id() {
|
||||
let event = EmbedderEvent::ChangeBrowserVisibility(id, visible);
|
||||
let event = EmbedderEvent::WebViewVisibilityChanged(id, visible);
|
||||
self.process_event(event)
|
||||
} else {
|
||||
// Ignore visibility change if no browser has been created yet.
|
||||
|
@ -714,21 +721,35 @@ impl ServoGlue {
|
|||
.push(EmbedderEvent::SendError(browser_id, reason));
|
||||
}
|
||||
},
|
||||
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
||||
EmbedderMsg::AllowOpeningWebView(response_chan) => {
|
||||
// Note: would be a place to handle pop-ups config.
|
||||
// see Step 7 of #the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
|
||||
if let Err(e) = response_chan.send(true) {
|
||||
warn!("Failed to send AllowOpeningBrowser response: {}", e);
|
||||
};
|
||||
},
|
||||
EmbedderMsg::BrowserCreated(new_browser_id) => {
|
||||
// TODO: properly handle a new "tab"
|
||||
self.browsers.push(new_browser_id);
|
||||
if self.browser_id.is_none() {
|
||||
self.browser_id = Some(new_browser_id);
|
||||
}
|
||||
EmbedderMsg::WebViewOpened(new_webview_id) => {
|
||||
self.webviews.insert(new_webview_id, WebView {});
|
||||
self.creation_order.push(new_webview_id);
|
||||
self.events
|
||||
.push(EmbedderEvent::SelectBrowser(new_browser_id));
|
||||
.push(EmbedderEvent::FocusWebView(new_webview_id));
|
||||
},
|
||||
EmbedderMsg::WebViewClosed(webview_id) => {
|
||||
self.webviews.retain(|&id, _| id != webview_id);
|
||||
self.creation_order.retain(|&id| id != webview_id);
|
||||
self.focused_webview_id = None;
|
||||
if let Some(&newest_webview_id) = self.creation_order.last() {
|
||||
self.events
|
||||
.push(EmbedderEvent::FocusWebView(newest_webview_id));
|
||||
} else {
|
||||
self.events.push(EmbedderEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::WebViewFocused(webview_id) => {
|
||||
self.focused_webview_id = Some(webview_id);
|
||||
},
|
||||
EmbedderMsg::WebViewBlurred => {
|
||||
self.focused_webview_id = None;
|
||||
},
|
||||
EmbedderMsg::GetClipboardContents(sender) => {
|
||||
let contents = self.callbacks.host_callbacks.get_clipboard_contents();
|
||||
|
@ -737,17 +758,6 @@ impl ServoGlue {
|
|||
EmbedderMsg::SetClipboardContents(text) => {
|
||||
self.callbacks.host_callbacks.set_clipboard_contents(text);
|
||||
},
|
||||
EmbedderMsg::CloseBrowser => {
|
||||
// TODO: close the appropriate "tab".
|
||||
let _ = self.browsers.pop();
|
||||
if let Some(prev_browser_id) = self.browsers.last() {
|
||||
self.browser_id = Some(*prev_browser_id);
|
||||
self.events
|
||||
.push(EmbedderEvent::SelectBrowser(*prev_browser_id));
|
||||
} else {
|
||||
self.events.push(EmbedderEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::Shutdown => {
|
||||
self.callbacks.host_callbacks.on_shutdown_complete();
|
||||
},
|
||||
|
|
|
@ -23,17 +23,17 @@ use winit::event::WindowEvent;
|
|||
use winit::event_loop::EventLoopWindowTarget;
|
||||
use winit::window::WindowId;
|
||||
|
||||
use crate::browser::Browser;
|
||||
use crate::embedder::EmbedderCallbacks;
|
||||
use crate::events_loop::{EventsLoop, WakerEvent};
|
||||
use crate::minibrowser::Minibrowser;
|
||||
use crate::parser::get_default_url;
|
||||
use crate::webview::WebViewManager;
|
||||
use crate::window_trait::WindowPortsMethods;
|
||||
use crate::{headed_window, headless_window};
|
||||
|
||||
pub struct App {
|
||||
servo: Option<Servo<dyn WindowPortsMethods>>,
|
||||
browser: RefCell<Browser<dyn WindowPortsMethods>>,
|
||||
webviews: RefCell<WebViewManager<dyn WindowPortsMethods>>,
|
||||
event_queue: RefCell<Vec<EmbedderEvent>>,
|
||||
suspended: Cell<bool>,
|
||||
windows: HashMap<WindowId, Rc<dyn WindowPortsMethods>>,
|
||||
|
@ -81,7 +81,7 @@ impl App {
|
|||
};
|
||||
|
||||
// Handle browser state.
|
||||
let browser = Browser::new(window.clone());
|
||||
let webviews = WebViewManager::new(window.clone());
|
||||
let initial_url = get_default_url(
|
||||
url.as_ref().map(String::as_str),
|
||||
env::current_dir().unwrap(),
|
||||
|
@ -90,7 +90,7 @@ impl App {
|
|||
|
||||
let mut app = App {
|
||||
event_queue: RefCell::new(vec![]),
|
||||
browser: RefCell::new(browser),
|
||||
webviews: RefCell::new(webviews),
|
||||
servo: None,
|
||||
suspended: Cell::new(false),
|
||||
windows: HashMap::new(),
|
||||
|
@ -200,7 +200,7 @@ impl App {
|
|||
);
|
||||
let mut servo = servo_data.servo;
|
||||
|
||||
servo.handle_events(vec![EmbedderEvent::NewBrowser(
|
||||
servo.handle_events(vec![EmbedderEvent::NewWebView(
|
||||
initial_url.to_owned(),
|
||||
servo_data.browser_id,
|
||||
)]);
|
||||
|
@ -297,9 +297,9 @@ impl App {
|
|||
|
||||
// Consume and handle any events from the Minibrowser.
|
||||
if let Some(minibrowser) = app.minibrowser() {
|
||||
let browser = &mut app.browser.borrow_mut();
|
||||
let webviews = &mut app.webviews.borrow_mut();
|
||||
let app_event_queue = &mut app.event_queue.borrow_mut();
|
||||
minibrowser.queue_embedder_events_for_minibrowser_events(browser, app_event_queue);
|
||||
minibrowser.queue_embedder_events_for_minibrowser_events(webviews, app_event_queue);
|
||||
}
|
||||
|
||||
match app.handle_events() {
|
||||
|
@ -316,8 +316,8 @@ impl App {
|
|||
} => {
|
||||
if history_changed {
|
||||
if let Some(mut minibrowser) = app.minibrowser() {
|
||||
let browser = &mut app.browser.borrow_mut();
|
||||
if minibrowser.update_location_in_toolbar(browser) {
|
||||
let webviews = &mut app.webviews.borrow_mut();
|
||||
if minibrowser.update_location_in_toolbar(webviews) {
|
||||
// Update the minibrowser immediately. While we could update by requesting a
|
||||
// redraw, doing so would delay the location update by two frames.
|
||||
minibrowser.update(
|
||||
|
@ -422,18 +422,11 @@ impl App {
|
|||
/// towards Servo and embedder messages flow away from Servo, and also runs the compositor.
|
||||
///
|
||||
/// As the embedder, we push embedder events through our event queues, from the App queue and
|
||||
/// Window queues to the Browser queue, and from the Browser queue to Servo. We receive and
|
||||
/// collect embedder messages from the various Servo components, then take them out of the
|
||||
/// Servo interface so that the Browser can handle them.
|
||||
/// Window queues to the WebViewManager queue, and from the WebViewManager queue to Servo. We
|
||||
/// receive and collect embedder messages from the various Servo components, then take them out
|
||||
/// of the Servo interface so that the WebViewManager can handle them.
|
||||
fn handle_events(&mut self) -> PumpResult {
|
||||
let mut browser = self.browser.borrow_mut();
|
||||
|
||||
// FIXME:
|
||||
// As of now, we support only one browser (self.browser)
|
||||
// but have multiple windows (dom.webxr.glwindow). We forward
|
||||
// the events of all the windows combined to that single
|
||||
// browser instance. Pressing the "a" key on the glwindow
|
||||
// will send a key event to the servo window.
|
||||
let mut webviews = self.webviews.borrow_mut();
|
||||
|
||||
// Take any outstanding embedder events from the App and its Windows.
|
||||
let mut embedder_events = self.get_events();
|
||||
|
@ -441,8 +434,8 @@ impl App {
|
|||
embedder_events.extend(window.get_events());
|
||||
}
|
||||
|
||||
// Catch some keyboard events, and push the rest onto the Browser event queue.
|
||||
browser.handle_window_events(embedder_events);
|
||||
// Catch some keyboard events, and push the rest onto the WebViewManager event queue.
|
||||
webviews.handle_window_events(embedder_events);
|
||||
|
||||
// Take any new embedder messages from Servo itself.
|
||||
let mut embedder_messages = self.servo.as_mut().unwrap().get_events();
|
||||
|
@ -451,19 +444,19 @@ impl App {
|
|||
let mut history_changed = false;
|
||||
loop {
|
||||
// Consume and handle those embedder messages.
|
||||
let servo_event_response = browser.handle_servo_events(embedder_messages);
|
||||
let servo_event_response = webviews.handle_servo_events(embedder_messages);
|
||||
need_present |= servo_event_response.need_present;
|
||||
history_changed |= servo_event_response.history_changed;
|
||||
|
||||
// Route embedder events from the Browser to the relevant Servo components,
|
||||
// Route embedder events from the WebViewManager to the relevant Servo components,
|
||||
// receives and collects embedder messages from various Servo components,
|
||||
// and runs the compositor.
|
||||
need_resize |= self
|
||||
.servo
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.handle_events(browser.get_events());
|
||||
if browser.shutdown_requested() {
|
||||
.handle_events(webviews.get_events());
|
||||
if webviews.shutdown_requested() {
|
||||
return PumpResult::Shutdown;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ cfg_if::cfg_if! {
|
|||
|
||||
mod app;
|
||||
mod backtrace;
|
||||
mod browser;
|
||||
mod crash_handler;
|
||||
mod egui_glue;
|
||||
mod embedder;
|
||||
|
@ -45,6 +44,7 @@ cfg_if::cfg_if! {
|
|||
mod parser;
|
||||
mod prefs;
|
||||
mod resources;
|
||||
mod webview;
|
||||
mod window_trait;
|
||||
|
||||
pub mod platform {
|
||||
|
|
|
@ -20,11 +20,11 @@ use servo::servo_geometry::DeviceIndependentPixel;
|
|||
use servo::servo_url::ServoUrl;
|
||||
use servo::webrender_surfman::WebrenderSurfman;
|
||||
|
||||
use crate::browser::Browser;
|
||||
use crate::egui_glue::EguiGlow;
|
||||
use crate::events_loop::EventsLoop;
|
||||
use crate::geometry::winit_position_to_euclid_point;
|
||||
use crate::parser::location_bar_input_to_url;
|
||||
use crate::webview::WebViewManager;
|
||||
use crate::window_trait::WindowPortsMethods;
|
||||
|
||||
pub struct Minibrowser {
|
||||
|
@ -260,13 +260,13 @@ impl Minibrowser {
|
|||
/// routing those to the App event queue.
|
||||
pub fn queue_embedder_events_for_minibrowser_events(
|
||||
&self,
|
||||
browser: &Browser<dyn WindowPortsMethods>,
|
||||
browser: &WebViewManager<dyn WindowPortsMethods>,
|
||||
app_event_queue: &mut Vec<EmbedderEvent>,
|
||||
) {
|
||||
for event in self.event_queue.borrow_mut().drain(..) {
|
||||
match event {
|
||||
MinibrowserEvent::Go => {
|
||||
let browser_id = browser.browser_id().unwrap();
|
||||
let browser_id = browser.webview_id().unwrap();
|
||||
let location = self.location.borrow();
|
||||
if let Some(url) = location_bar_input_to_url(&location.clone()) {
|
||||
app_event_queue.push(EmbedderEvent::LoadUrl(browser_id, url));
|
||||
|
@ -276,14 +276,14 @@ impl Minibrowser {
|
|||
}
|
||||
},
|
||||
MinibrowserEvent::Back => {
|
||||
let browser_id = browser.browser_id().unwrap();
|
||||
let browser_id = browser.webview_id().unwrap();
|
||||
app_event_queue.push(EmbedderEvent::Navigation(
|
||||
browser_id,
|
||||
TraversalDirection::Back(1),
|
||||
));
|
||||
},
|
||||
MinibrowserEvent::Forward => {
|
||||
let browser_id = browser.browser_id().unwrap();
|
||||
let browser_id = browser.webview_id().unwrap();
|
||||
app_event_queue.push(EmbedderEvent::Navigation(
|
||||
browser_id,
|
||||
TraversalDirection::Forward(1),
|
||||
|
@ -293,11 +293,11 @@ impl Minibrowser {
|
|||
}
|
||||
}
|
||||
|
||||
/// Updates the location field from the given [Browser], unless the user has started editing it
|
||||
/// without clicking Go, returning true iff the location has changed (needing an egui update).
|
||||
/// Updates the location field from the given [BrowserManager], unless the user has started
|
||||
/// editing it without clicking Go, returning true iff it has changed (needing an egui update).
|
||||
pub fn update_location_in_toolbar(
|
||||
&mut self,
|
||||
browser: &mut Browser<dyn WindowPortsMethods>,
|
||||
browser: &mut WebViewManager<dyn WindowPortsMethods>,
|
||||
) -> bool {
|
||||
// User edited without clicking Go?
|
||||
if self.location_dirty.get() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::rc::Rc;
|
||||
|
@ -17,7 +18,7 @@ use servo::embedder_traits::{
|
|||
CompositorEventVariant, ContextMenuResult, EmbedderMsg, FilterPattern, PermissionPrompt,
|
||||
PermissionRequest, PromptDefinition, PromptOrigin, PromptResult,
|
||||
};
|
||||
use servo::msg::constellation_msg::{TopLevelBrowsingContextId as BrowserId, TraversalDirection};
|
||||
use servo::msg::constellation_msg::{TopLevelBrowsingContextId as WebViewId, TraversalDirection};
|
||||
use servo::script_traits::TouchEventType;
|
||||
use servo::servo_config::opts;
|
||||
use servo::servo_url::ServoUrl;
|
||||
|
@ -28,19 +29,21 @@ use crate::keyutils::{CMD_OR_ALT, CMD_OR_CONTROL};
|
|||
use crate::parser::location_bar_input_to_url;
|
||||
use crate::window_trait::{WindowPortsMethods, LINE_HEIGHT};
|
||||
|
||||
pub struct Browser<Window: WindowPortsMethods + ?Sized> {
|
||||
pub struct WebViewManager<Window: WindowPortsMethods + ?Sized> {
|
||||
current_url: Option<ServoUrl>,
|
||||
current_url_string: Option<String>,
|
||||
|
||||
/// id of the top level browsing context. It is unique as tabs
|
||||
/// are not supported yet. None until created.
|
||||
browser_id: Option<BrowserId>,
|
||||
/// List of top-level browsing contexts.
|
||||
/// Modified by EmbedderMsg::WebViewOpened and EmbedderMsg::WebViewClosed,
|
||||
/// and we exit if it ever becomes empty.
|
||||
webviews: HashMap<WebViewId, WebView>,
|
||||
|
||||
// A rudimentary stack of "tabs".
|
||||
// EmbedderMsg::BrowserCreated will push onto it.
|
||||
// EmbedderMsg::CloseBrowser will pop from it,
|
||||
// and exit if it is empty afterwards.
|
||||
browsers: Vec<BrowserId>,
|
||||
/// The order in which the webviews were created.
|
||||
creation_order: Vec<WebViewId>,
|
||||
|
||||
/// The webview that is currently focused.
|
||||
/// Modified by EmbedderMsg::WebViewFocused and EmbedderMsg::WebViewBlurred.
|
||||
focused_webview_id: Option<WebViewId>,
|
||||
|
||||
title: Option<String>,
|
||||
|
||||
|
@ -50,22 +53,26 @@ pub struct Browser<Window: WindowPortsMethods + ?Sized> {
|
|||
shutdown_requested: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WebView {}
|
||||
|
||||
pub struct ServoEventResponse {
|
||||
pub need_present: bool,
|
||||
pub history_changed: bool,
|
||||
}
|
||||
|
||||
impl<Window> Browser<Window>
|
||||
impl<Window> WebViewManager<Window>
|
||||
where
|
||||
Window: WindowPortsMethods + ?Sized,
|
||||
{
|
||||
pub fn new(window: Rc<Window>) -> Browser<Window> {
|
||||
Browser {
|
||||
pub fn new(window: Rc<Window>) -> WebViewManager<Window> {
|
||||
WebViewManager {
|
||||
title: None,
|
||||
current_url: None,
|
||||
current_url_string: None,
|
||||
browser_id: None,
|
||||
browsers: Vec::new(),
|
||||
webviews: HashMap::default(),
|
||||
creation_order: vec![],
|
||||
focused_webview_id: None,
|
||||
window,
|
||||
clipboard: match Clipboard::new() {
|
||||
Ok(c) => Some(c),
|
||||
|
@ -79,8 +86,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub fn browser_id(&self) -> Option<BrowserId> {
|
||||
self.browser_id
|
||||
pub fn webview_id(&self) -> Option<WebViewId> {
|
||||
self.focused_webview_id
|
||||
}
|
||||
|
||||
pub fn current_url_string(&self) -> Option<&str> {
|
||||
|
@ -113,7 +120,7 @@ where
|
|||
fn handle_key_from_window(&mut self, key_event: KeyboardEvent) {
|
||||
ShortcutMatcher::from_event(key_event.clone())
|
||||
.shortcut(CMD_OR_CONTROL, 'R', || {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
self.event_queue.push(EmbedderEvent::Reload(id));
|
||||
}
|
||||
})
|
||||
|
@ -128,7 +135,7 @@ where
|
|||
let input = tinyfiledialogs::input_box(title, title, &tiny_dialog_escape(&url));
|
||||
if let Some(input) = input {
|
||||
if let Some(url) = location_bar_input_to_url(&input) {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
self.event_queue.push(EmbedderEvent::LoadUrl(id, url));
|
||||
}
|
||||
}
|
||||
|
@ -171,13 +178,13 @@ where
|
|||
));
|
||||
})
|
||||
.shortcut(CMD_OR_ALT, Key::ArrowRight, || {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
let event = EmbedderEvent::Navigation(id, TraversalDirection::Forward(1));
|
||||
self.event_queue.push(event);
|
||||
}
|
||||
})
|
||||
.shortcut(CMD_OR_ALT, Key::ArrowLeft, || {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
let event = EmbedderEvent::Navigation(id, TraversalDirection::Back(1));
|
||||
self.event_queue.push(event);
|
||||
}
|
||||
|
@ -185,7 +192,7 @@ where
|
|||
.shortcut(Modifiers::empty(), Key::Escape, || {
|
||||
let state = self.window.get_fullscreen();
|
||||
if state {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
let event = EmbedderEvent::ExitFullScreen(id);
|
||||
self.event_queue.push(event);
|
||||
}
|
||||
|
@ -198,7 +205,7 @@ where
|
|||
|
||||
#[cfg(not(target_os = "win"))]
|
||||
fn platform_handle_key(&mut self, key_event: KeyboardEvent) {
|
||||
if let Some(id) = self.browser_id {
|
||||
if let Some(id) = self.focused_webview_id {
|
||||
if let Some(event) = ShortcutMatcher::from_event(key_event.clone())
|
||||
.shortcut(CMD_OR_CONTROL, '[', || {
|
||||
EmbedderEvent::Navigation(id, TraversalDirection::Back(1))
|
||||
|
@ -217,7 +224,7 @@ where
|
|||
fn platform_handle_key(&mut self, _key_event: KeyboardEvent) {}
|
||||
|
||||
/// Handle key events after they have been handled by Servo.
|
||||
fn handle_key_from_servo(&mut self, _: Option<BrowserId>, event: KeyboardEvent) {
|
||||
fn handle_key_from_servo(&mut self, _: Option<WebViewId>, event: KeyboardEvent) {
|
||||
ShortcutMatcher::from_event(event)
|
||||
.shortcut(CMD_OR_CONTROL, '=', || {
|
||||
self.event_queue.push(EmbedderEvent::Zoom(1.1))
|
||||
|
@ -285,14 +292,14 @@ where
|
|||
/// Returns true if the caller needs to manually present a new frame.
|
||||
pub fn handle_servo_events(
|
||||
&mut self,
|
||||
events: Vec<(Option<BrowserId>, EmbedderMsg)>,
|
||||
events: Vec<(Option<WebViewId>, EmbedderMsg)>,
|
||||
) -> ServoEventResponse {
|
||||
let mut need_present = false;
|
||||
let mut history_changed = false;
|
||||
for (browser_id, msg) in events {
|
||||
for (webview_id, msg) in events {
|
||||
trace!(
|
||||
"embedder <- servo EmbedderMsg ({:?}, {:?})",
|
||||
browser_id.map(|x| format!("{}", x)),
|
||||
webview_id.map(|x| format!("{}", x)),
|
||||
msg
|
||||
);
|
||||
match msg {
|
||||
|
@ -395,7 +402,7 @@ where
|
|||
if let Err(e) = res {
|
||||
let reason = format!("Failed to send Prompt response: {}", e);
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::SendError(browser_id, reason));
|
||||
.push(EmbedderEvent::SendError(webview_id, reason));
|
||||
}
|
||||
},
|
||||
EmbedderMsg::AllowUnload(sender) => {
|
||||
|
@ -403,35 +410,47 @@ where
|
|||
if let Err(e) = sender.send(true) {
|
||||
let reason = format!("Failed to send AllowUnload response: {}", e);
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::SendError(browser_id, reason));
|
||||
.push(EmbedderEvent::SendError(webview_id, reason));
|
||||
}
|
||||
},
|
||||
EmbedderMsg::AllowNavigationRequest(pipeline_id, _url) => {
|
||||
if let Some(_browser_id) = browser_id {
|
||||
if let Some(_webview_id) = webview_id {
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::AllowNavigationResponse(pipeline_id, true));
|
||||
}
|
||||
},
|
||||
EmbedderMsg::AllowOpeningBrowser(response_chan) => {
|
||||
EmbedderMsg::AllowOpeningWebView(response_chan) => {
|
||||
// Note: would be a place to handle pop-ups config.
|
||||
// see Step 7 of #the-rules-for-choosing-a-browsing-context-given-a-browsing-context-name
|
||||
if let Err(e) = response_chan.send(true) {
|
||||
warn!("Failed to send AllowOpeningBrowser response: {}", e);
|
||||
warn!("Failed to send AllowOpeningWebView response: {}", e);
|
||||
};
|
||||
},
|
||||
EmbedderMsg::BrowserCreated(new_browser_id) => {
|
||||
// TODO: properly handle a new "tab"
|
||||
self.browsers.push(new_browser_id);
|
||||
if self.browser_id.is_none() {
|
||||
self.browser_id = Some(new_browser_id);
|
||||
} else {
|
||||
error!("Multiple top level browsing contexts not supported yet.");
|
||||
}
|
||||
EmbedderMsg::WebViewOpened(new_webview_id) => {
|
||||
self.webviews.insert(new_webview_id, WebView {});
|
||||
self.creation_order.push(new_webview_id);
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::SelectBrowser(new_browser_id));
|
||||
.push(EmbedderEvent::FocusWebView(new_webview_id));
|
||||
},
|
||||
EmbedderMsg::WebViewClosed(webview_id) => {
|
||||
self.webviews.retain(|&id, _| id != webview_id);
|
||||
self.creation_order.retain(|&id| id != webview_id);
|
||||
self.focused_webview_id = None;
|
||||
if let Some(&newest_webview_id) = self.creation_order.last() {
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::FocusWebView(newest_webview_id));
|
||||
} else {
|
||||
self.event_queue.push(EmbedderEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::WebViewFocused(webview_id) => {
|
||||
self.focused_webview_id = Some(webview_id);
|
||||
},
|
||||
EmbedderMsg::WebViewBlurred => {
|
||||
self.focused_webview_id = None;
|
||||
},
|
||||
EmbedderMsg::Keyboard(key_event) => {
|
||||
self.handle_key_from_servo(browser_id, key_event);
|
||||
self.handle_key_from_servo(webview_id, key_event);
|
||||
},
|
||||
EmbedderMsg::GetClipboardContents(sender) => {
|
||||
let contents = self
|
||||
|
@ -476,17 +495,6 @@ where
|
|||
EmbedderMsg::LoadComplete => {
|
||||
// FIXME: surface the loading state in the UI somehow
|
||||
},
|
||||
EmbedderMsg::CloseBrowser => {
|
||||
// TODO: close the appropriate "tab".
|
||||
let _ = self.browsers.pop();
|
||||
if let Some(prev_browser_id) = self.browsers.last() {
|
||||
self.browser_id = Some(*prev_browser_id);
|
||||
self.event_queue
|
||||
.push(EmbedderEvent::SelectBrowser(*prev_browser_id));
|
||||
} else {
|
||||
self.event_queue.push(EmbedderEvent::Quit);
|
||||
}
|
||||
},
|
||||
EmbedderMsg::Shutdown => {
|
||||
self.shutdown_requested = true;
|
||||
},
|
||||
|
@ -545,10 +553,10 @@ where
|
|||
EmbedderMsg::ReadyToPresent => {
|
||||
need_present = true;
|
||||
},
|
||||
EmbedderMsg::EventDelivered(event) => match (browser_id, event) {
|
||||
(Some(browser_id), CompositorEventVariant::MouseButtonEvent) => {
|
||||
// TODO Focus browser and/or raise to top if needed.
|
||||
trace!("{}: Got a mouse button event", browser_id);
|
||||
EmbedderMsg::EventDelivered(event) => match (webview_id, event) {
|
||||
(Some(webview_id), CompositorEventVariant::MouseButtonEvent) => {
|
||||
// TODO Focus webview and/or raise to top if needed.
|
||||
trace!("{}: Got a mouse button event", webview_id);
|
||||
},
|
||||
(_, _) => {},
|
||||
},
|
Loading…
Add table
Add a link
Reference in a new issue