Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Window.open and related infrastructure #20678

Merged
merged 7 commits into from Aug 11, 2018

rudimentary handling of tabs

  • Loading branch information
gterzian committed Aug 10, 2018
commit 96f75465cfddc616721ea24cbc2e011611e432f9
@@ -26,6 +26,12 @@ pub struct Browser {
/// 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>,

title: Option<String>,
status: Option<String>,
favicon: Option<ServoUrl>,
@@ -47,6 +53,7 @@ impl Browser {
title: None,
current_url: None,
browser_id: None,
browsers: Vec::new(),
status: None,
favicon: None,
loading_state: None,
@@ -62,6 +69,7 @@ impl Browser {

pub fn set_browser_id(&mut self, browser_id: BrowserId) {
self.browser_id = Some(browser_id);
self.browsers.push(browser_id);
}

pub fn handle_window_events(&mut self, events: Vec<WindowEvent>) {
@@ -293,7 +301,7 @@ impl Browser {
}
EmbedderMsg::BrowserCreated(new_browser_id) => {
// TODO: properly handle a new "tab"
self.browser_id = Some(new_browser_id);
self.browsers.push(new_browser_id);
self.event_queue.push(WindowEvent::SelectBrowser(new_browser_id));
}
EmbedderMsg::KeyEvent(ch, key, state, modified) => {
@@ -321,10 +329,13 @@ impl Browser {
self.loading_state = Some(LoadingState::Loaded);
}
EmbedderMsg::CloseBrowser => {
self.browser_id = None;
// Nothing left to do for now,
// but could hide a tab, and show another one, instead of quitting.
self.event_queue.push(WindowEvent::Quit);
// TODO: close the appropriate "tab".

This comment has been minimized.

Copy link
@nox

nox Jul 13, 2018

Member

I'm not sure what this todo is about.

This comment has been minimized.

Copy link
@gterzian

gterzian Jul 13, 2018

Author Member

Currently we just pop from the list of browsers(and quit constellation when the list is empty). To properly implement tabs one day, we probably should close the browser from which the CloseBrowser message originated.

let _ = self.browsers.pop();
if let Some(prev_browser_id) = self.browsers.last() {
self.event_queue.push(WindowEvent::SelectBrowser(*prev_browser_id));
} else {
self.event_queue.push(WindowEvent::Quit);
}
},
EmbedderMsg::Shutdown => {
self.shutdown_requested = true;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.