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

Commit

Permalink
Fix zoom level on browser restore
Browse files Browse the repository at this point in the history
and remove deprecated zoom level site setting.

fix #7832

Test Plan:
1. launch clean instance of brave
2. go to example.com and change the zoom level
3. close brave
4. reopen brave
5. example.com should load with the previous zoom setting
  • Loading branch information
diracdeltas committed Mar 23, 2017
1 parent 0cb879a commit 642c0dc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ AppStore
savePasswords: boolean, // only false or undefined/null
shieldsUp: boolean,
widevine: (number|boolean), // false = block widevine, 0 = allow once, 1 = allow always
zoomLevel: number
zoomLevel: number // deprecated
}
},
sync: {
Expand Down
18 changes: 12 additions & 6 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const cx = require('../lib/classSet')
const siteUtil = require('../state/siteUtil')
const FrameStateUtil = require('../state/frameStateUtil')
const UrlUtil = require('../lib/urlutil')
const {getZoomLevel} = require('../lib/zoom')
const messages = require('../constants/messages')
const contextMenus = require('../contextMenus')
const ipc = require('electron').ipcRenderer
Expand Down Expand Up @@ -336,7 +337,18 @@ class Frame extends ImmutableComponent {
this.runOnDomReady()
delete this.runOnDomReady
}
let zoomCallback = (e) => {
if (!e.isMainFrame) {
return
}
this.webview.removeEventListener(e.type, zoomCallback)
const zoomPercentage = this.frame && this.frame.get('lastZoomPercentage')
if (zoomPercentage !== this.webview.getZoomPercent()) {
this.webview.setZoomLevel(getZoomLevel(zoomPercentage))
}
}
this.webview.addEventListener('did-attach', eventCallback)
this.webview.addEventListener('load-commit', zoomCallback)
}

webviewAdded = true
Expand Down Expand Up @@ -368,12 +380,6 @@ class Frame extends ImmutableComponent {
this.updateWebview(this.onPropsChanged)
}

get zoomLevel () {
const zoom = this.props.frameSiteSettings && this.props.frameSiteSettings.get('zoomLevel')
appActions.removeSiteSetting(this.origin, 'zoomLevel', this.props.isPrivate)
return zoom
}

zoomIn () {
if (this.webview) {
this.webview.zoomIn()
Expand Down
5 changes: 5 additions & 0 deletions js/lib/zoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const {zoom} = require('../constants/config')
module.exports.getZoomValuePercentage = (zoomLevel) =>
100 + (20 * zoomLevel)

// Convert zoom percentage to zoom level
module.exports.getZoomLevel = (percentage) => {
return (percentage - 100) / 20
}

module.exports.getNextZoomLevel = (currentZoom, zoomIn) => {
const zoomLevels = zoom.zoomLevels
// First find the closet value to what we allow
Expand Down
1 change: 0 additions & 1 deletion js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ function addFrame (windowState, tabs, frameOpts, newKey, partitionNumber, active
}

const frame = Immutable.fromJS(Object.assign({
zoomLevel: config.zoom.defaultValue,
audioMuted: false, // frame is muted
location,
aboutDetails: undefined,
Expand Down
2 changes: 1 addition & 1 deletion js/state/syncUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports.CATEGORY_MAP = CATEGORY_MAP

const siteSettingDefaults = {
hostPattern: '',
zoomLevel: 0,
zoomLevel: 0, // deprecated
shieldsUp: true,
adControl: 1,
cookieControl: 0,
Expand Down
13 changes: 12 additions & 1 deletion test/unit/lib/zoomTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global describe, it */

const {getZoomValuePercentage, getNextZoomLevel} = require('../../../js/lib/zoom')
const {getZoomValuePercentage, getZoomLevel, getNextZoomLevel} = require('../../../js/lib/zoom')
const {zoom} = require('../../../js/constants/config')
const assert = require('assert')

Expand All @@ -16,6 +16,17 @@ describe('zoom', function () {
assert.equal(getZoomValuePercentage(-3.75), 25)
})
})
describe('getZoomLevel', function () {
it('formats 100 to 0', function * () {
assert.equal(getZoomLevel(100), 0)
})
it('formats positive value', function * () {
assert.equal(getZoomLevel(120), 1)
})
it('formats negative value', function * () {
assert.equal(getZoomLevel(25), -3.75)
})
})
describe('getNextZoomLevel', function () {
it('zoomOut respects minimum', function * () {
assert.equal(getNextZoomLevel(-200, false), zoom.zoomLevels[0])
Expand Down

0 comments on commit 642c0dc

Please sign in to comment.