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 #6 from brave/zoom
Browse files Browse the repository at this point in the history
Add zoom shortcut support.
  • Loading branch information
bbondy committed Dec 4, 2015
2 parents 6568fda + 66829d0 commit 5c818fc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
25 changes: 25 additions & 0 deletions app/content/webviewPreload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var webFrame = require('electron').webFrame
var ipc = require('electron').ipcRenderer

var browserZoomLevel = 0
var browserMaxZoom = 9
var browserMinZoom = -8

ipc.on('zoom-in', function () {
if (browserMaxZoom > browserZoomLevel) {
browserZoomLevel += 1
}
webFrame.setZoomLevel(browserZoomLevel)
})

ipc.on('zoom-out', function () {
if (browserMinZoom < browserZoomLevel) {
browserZoomLevel -= 1
}
webFrame.setZoomLevel(browserZoomLevel)
})

ipc.on('zoom-reset', function () {
browserZoomLevel = 0
webFrame.setZoomLevel(browserZoomLevel)
})
5 changes: 4 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ app.on('ready', function () {
['Escape', 'shortcut-stop'],
['Ctrl+Tab', 'shortcut-next-tab'],
['Ctrl+Shift+Tab', 'shortcut-prev-tab'],
['CmdOrCtrl+R', 'shortcut-reload']
['CmdOrCtrl+R', 'shortcut-reload'],
['CmdOrCtrl+=', 'shortcut-zoom-in'],
['CmdOrCtrl+-', 'shortcut-zoom-out'],
['CmdOrCtrl+0', 'shortcut-zoom-reset']
]

simpleWebContentEvents.forEach((shortcutEventName) =>
Expand Down
23 changes: 22 additions & 1 deletion js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ class Frame extends ImmutableComponent {
webview.reload()
}
})
ipc.on('shortcut-zoom-in', () => {
let webview = ReactDOM.findDOMNode(this.refs.webview)
if (webview) {
webview.send('zoom-in')
}
})
ipc.on('shortcut-zoom-out', () => {
let webview = ReactDOM.findDOMNode(this.refs.webview)
if (webview) {
webview.send('zoom-out')
}
})
ipc.on('shortcut-zoom-reset', () => {
let webview = ReactDOM.findDOMNode(this.refs.webview)
if (webview) {
webview.send('zoom-reset')
}
})
process.on('reload-active-frame', () => {
if (this.props.isActive) {
let webview = ReactDOM.findDOMNode(this.refs.webview)
Expand Down Expand Up @@ -105,7 +123,10 @@ class Frame extends ImmutableComponent {
frameWrapper: true,
isActive: this.props.isActive
})}>
<webview ref='webview' src={this.props.frame.get('location')} />
<webview
ref='webview'
src={this.props.frame.get('location')}
preload='content/webviewPreload.js'/>
</div>
}
}
Expand Down

0 comments on commit 5c818fc

Please sign in to comment.