Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2021 from brave/fullscreen
Browse files Browse the repository at this point in the history
enable escape for exit of webview fullscreen
  • Loading branch information
bbondy committed Jun 2, 2016
2 parents 3f2d039 + cd06d77 commit 4126235
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ class Frame extends ImmutableComponent {
if (this.props.isActive && !prevProps.isActive) {
this.webview.focus()
}

// make sure the webview content updates to
// match the fullscreen state of the frame
if (prevProps.frame.get('isFullScreen') !==
this.props.frame.get('isFullScreen')) {
if (this.props.frame.get('isFullScreen')) {
this.webview.executeJavaScript('document.webkitRequestFullscreen()')
} else {
this.webview.executeJavaScript('document.webkitExitFullscreen()')
}
}
this.webview.setAudioMuted(this.props.frame.get('audioMuted') || false)
this.updateAboutDetails()
}
Expand Down Expand Up @@ -526,6 +537,7 @@ class Frame extends ImmutableComponent {
})
this.webview.addEventListener('enter-html-full-screen', () => {
windowActions.setFullScreen(this.props.frame, true, true)
// disable the fullscreen warning after 5 seconds
setTimeout(windowActions.setFullScreen.bind(this, this.props.frame, undefined, false), 5000)
})
this.webview.addEventListener('leave-html-full-screen', () => {
Expand Down
18 changes: 12 additions & 6 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class Main extends ImmutableComponent {
const isDarwin = process.platform === 'darwin'
document.addEventListener('keydown', (e) => {
switch (e.which) {
case keyCodes.ESC:
this.exitFullScreen()
break
case keyCodes.F12:
if (!isDarwin) {
ipc.emit(messages.SHORTCUT_ACTIVE_FRAME_TOGGLE_DEV_TOOLS)
Expand All @@ -96,6 +99,14 @@ class Main extends ImmutableComponent {
}
})
}

exitFullScreen () {
const activeFrame = FrameStateUtil.getActiveFrame(this.props.windowState)
if (activeFrame && activeFrame.get('isFullScreen')) {
windowActions.setFullScreen(activeFrame, false)
}
}

registerSwipeListener () {
// Navigates back/forward on OS X two-finger swipe
var trackingFingers = false
Expand Down Expand Up @@ -129,12 +140,7 @@ class Main extends ImmutableComponent {
deltaY = 0
startTime = 0
})
ipc.on(messages.LEAVE_FULL_SCREEN, () => {
const activeFrame = FrameStateUtil.getActiveFrame(this.props.windowState)
if (activeFrame && activeFrame.get('isFullScreen')) {
windowActions.setFullScreen(activeFrame, false)
}
})
ipc.on(messages.LEAVE_FULL_SCREEN, this.exitFullScreen.bind(this))
}

loadOpenSearch () {
Expand Down

0 comments on commit 4126235

Please sign in to comment.