Skip to content
Permalink
Browse files

Added implementation to exit from fullscreen mode by pressing ESC button

  • Loading branch information...
kamal-umudlu committed Mar 8, 2019
1 parent af6b598 commit 14ebd5bbb055d436a01756fd8fc0a5595e41332e
@@ -73,6 +73,8 @@ pub enum WindowEvent {
Navigation(TopLevelBrowsingContextId, TraversalDirection),
/// Sent when the user quits the application
Quit,
/// Sent when the user exits from fullscreen mode
ExitFullScreen(TopLevelBrowsingContextId),
/// Sent when a key input state changes
Keyboard(KeyboardEvent),
/// Sent when Ctr+R/Apple+R is called to reload the current page.
@@ -117,6 +119,7 @@ impl Debug for WindowEvent {
WindowEvent::SelectBrowser(..) => write!(f, "SelectBrowser"),
WindowEvent::ToggleWebRenderDebug(..) => write!(f, "ToggleWebRenderDebug"),
WindowEvent::CaptureWebRender => write!(f, "CaptureWebRender"),
WindowEvent::ExitFullScreen(..) => write!(f, "ExitFullScreen"),
}
}
}
@@ -1187,6 +1187,9 @@ where
self.forward_event(destination_pipeline_id, event);
},
FromCompositorMsg::SetCursor(cursor) => self.handle_set_cursor_msg(cursor),
FromCompositorMsg::ExitFullScreen(top_level_browsing_context_id) => {
self.handle_exit_fullscreen_msg(top_level_browsing_context_id);
},
}
}

@@ -3615,6 +3618,17 @@ where
self.window_size = new_size;
}

/// Called when the window exits from fullscreen mode
fn handle_exit_fullscreen_msg(
&mut self,
top_level_browsing_context_id: Option<TopLevelBrowsingContextId>,
) {
if let Some(top_level_browsing_context_id) = top_level_browsing_context_id {
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
self.switch_fullscreen_mode(browsing_context_id);
}
}

/// Handle updating actual viewport / zoom due to @viewport rules
fn handle_viewport_constrained_msg(
&mut self,
@@ -3851,6 +3865,41 @@ where
}
}

// Handle switching from fullscreen mode
fn switch_fullscreen_mode(&mut self, browsing_context_id: BrowsingContextId) {
if let Some(browsing_context) = self.browsing_contexts.get_mut(&browsing_context_id) {
let pipeline_id = browsing_context.pipeline_id;
let pipeline = match self.pipelines.get(&pipeline_id) {
None => {
return warn!(
"Pipeline {:?} switched from fullscreen mode after closing.",
pipeline_id
)
},
Some(pipeline) => pipeline,
};
let _ = pipeline
.event_loop
.send(ConstellationControlMsg::ExitFullScreen(pipeline.id));
}
// Send exit fullscreen message to any pending pipelines that aren't loaded yet
for change in &self.pending_changes {
let pipeline_id = change.new_pipeline_id;
let pipeline = match self.pipelines.get(&pipeline_id) {
None => {
warn!("Pending pipelone {:?} is closed", pipeline_id);
continue;
},
Some(pipeline) => pipeline,
};
if pipeline.browsing_context_id == browsing_context_id {
let _ = pipeline
.event_loop
.send(ConstellationControlMsg::ExitFullScreen(pipeline_id));
}
}
}

// Close a browsing context (and all children)
fn close_browsing_context(
&mut self,
@@ -1252,6 +1252,10 @@ impl ScriptThread {
Some(index) => sequential[index] = event,
}
},
FromConstellation(ConstellationControlMsg::ExitFullScreen(id)) => self
.profile_event(ScriptThreadEventCategory::ExitFullscreen, Some(id), || {
self.handle_exit_fullscreen(id);
}),
_ => {
sequential.push(event);
},
@@ -1448,6 +1452,7 @@ impl ScriptThread {
Reload(id, ..) => Some(id),
WebVREvents(id, ..) => Some(id),
PaintMetric(..) => None,
ExitFullScreen(id, ..) => Some(id),
}
},
MixedMessage::FromDevtools(_) => None,
@@ -1676,6 +1681,7 @@ impl ScriptThread {
msg @ ConstellationControlMsg::Viewport(..) |
msg @ ConstellationControlMsg::SetScrollState(..) |
msg @ ConstellationControlMsg::Resize(..) |
msg @ ConstellationControlMsg::ExitFullScreen(..) |
msg @ ConstellationControlMsg::ExitScriptThread => {
panic!("should have handled {:?} already", msg)
},
@@ -1888,6 +1894,18 @@ impl ScriptThread {
warn!("resize sent to nonexistent pipeline");
}

fn handle_exit_fullscreen(&self, id: PipelineId) {
let document = self.documents.borrow().find_document(id);
if let Some(document) = document {
let _ac = JSAutoCompartment::new(
document.global().get_cx(),
document.reflector().get_jsobject().get(),
);
document.exit_fullscreen();
return;
}
}

fn handle_viewport(&self, id: PipelineId, rect: Rect<f32>) {
let document = self.documents.borrow().find_document(id);
if let Some(document) = document {
@@ -261,6 +261,8 @@ pub enum ConstellationControlMsg {
Resize(PipelineId, WindowSizeData, WindowSizeType),
/// Notifies script that window has been resized but to not take immediate action.
ResizeInactive(PipelineId, WindowSizeData),
/// Window switched from fullscreen mode.
ExitFullScreen(PipelineId),
/// Notifies the script that the document associated with this pipeline should 'unload'.
UnloadDocument(PipelineId),
/// Notifies the script that a pipeline should be closed.
@@ -386,6 +388,7 @@ impl fmt::Debug for ConstellationControlMsg {
Reload(..) => "Reload",
WebVREvents(..) => "WebVREvents",
PaintMetric(..) => "PaintMetric",
ExitFullScreen(..) => "ExitFullScreen",
};
write!(formatter, "ConstellationControlMsg::{}", variant)
}
@@ -776,6 +779,8 @@ pub enum ConstellationMsg {
ForwardEvent(PipelineId, CompositorEvent),
/// Requesting a change to the onscreen cursor.
SetCursor(Cursor),
/// Request to exit from fullscreen mode
ExitFullScreen(Option<TopLevelBrowsingContextId>),
}

impl fmt::Debug for ConstellationMsg {
@@ -803,6 +808,7 @@ impl fmt::Debug for ConstellationMsg {
SelectBrowser(..) => "SelectBrowser",
ForwardEvent(..) => "ForwardEvent",
SetCursor(..) => "SetCursor",
ExitFullScreen(..) => "ExitFullScreen",
};
write!(formatter, "ConstellationMsg::{}", variant)
}
@@ -397,6 +397,13 @@ where
self.compositor.maybe_start_shutting_down();
},

WindowEvent::ExitFullScreen(top_level_browsing_context_id) => {
let msg = ConstellationMsg::ExitFullScreen(Some(top_level_browsing_context_id));
if let Err(e) = self.constellation_chan.send(msg) {
warn!("Sending exit fullscreen to constellation failed ({:?}).", e);
}
},

WindowEvent::Reload(top_level_browsing_context_id) => {
let msg = ConstellationMsg::Reload(top_level_browsing_context_id);
if let Err(e) = self.constellation_chan.send(msg) {
@@ -143,7 +143,15 @@ impl Browser {
}
})
.shortcut(Modifiers::empty(), Key::Escape, || {
self.event_queue.push(WindowEvent::Quit);
let state = self.window.get_fullscreen();
if state {
if let Some(id) = self.browser_id {
let event = WindowEvent::ExitFullScreen(id);
self.event_queue.push(event);
}
} else {
self.event_queue.push(WindowEvent::Quit);
}
})
.otherwise(|| self.platform_handle_key(key_event));
}
@@ -331,6 +331,10 @@ impl Window {
self.fullscreen.set(state);
}

pub fn get_fullscreen(&self) -> bool {
return self.fullscreen.get();
}

fn is_animating(&self) -> bool {
self.animation_state.get() == AnimationState::Animating && !self.suspended.get()
}

0 comments on commit 14ebd5b

Please sign in to comment.
You can’t perform that action at this time.