зеркало из https://github.com/electron/electron.git
add zoom specs based on standard protocols
This commit is contained in:
Родитель
0c022fdc36
Коммит
a57af31b99
|
@ -496,7 +496,7 @@ describe('webContents module', function () {
|
|||
})
|
||||
})
|
||||
ipcMain.once('temporary-zoom-set', (e, zoomLevel) => {
|
||||
w2.loadURL(`file://${fixtures}/pages/a.html`)
|
||||
w2.loadURL(`file://${fixtures}/pages/c.html`)
|
||||
finalZoomLevel = zoomLevel
|
||||
})
|
||||
w.loadURL(`file://${fixtures}/pages/webframe-zoom.html`)
|
||||
|
@ -521,10 +521,10 @@ describe('webContents module', function () {
|
|||
})
|
||||
ipcMain.once('zoom-level-set', (e, zoomLevel) => {
|
||||
assert.equal(zoomLevel, 0.6)
|
||||
w.loadURL(`file://${fixtures}/pages/b.html`)
|
||||
w.loadURL(`file://${fixtures}/pages/d.html`)
|
||||
initialNavigation = false
|
||||
})
|
||||
w.loadURL(`file://${fixtures}/pages/a.html`)
|
||||
w.loadURL(`file://${fixtures}/pages/c.html`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<html>
|
||||
<body>
|
||||
<webview nodeintegration src="a.html" id="view"/>
|
||||
<webview nodeintegration src="zoom://host1" id="view" partition="webview-temp"/>
|
||||
</body>
|
||||
<script>
|
||||
const {ipcRenderer, webFrame} = require('electron')
|
||||
const view = document.getElementById('view')
|
||||
let finalNavigation = false
|
||||
view.addEventListener('dom-ready', () => {
|
||||
if (!finalNavigation)
|
||||
if (!finalNavigation && !view.canGoBack()) {
|
||||
view.setZoomLevel(2.0)
|
||||
}
|
||||
view.getZoomLevel((zoomLevel) => {
|
||||
view.getZoomFactor((zoomFactor) => {
|
||||
ipcRenderer.send('webview-zoom-level', zoomLevel, zoomFactor, finalNavigation)
|
||||
if (!finalNavigation) {
|
||||
ipcRenderer.send('webview-zoom-level', zoomLevel, zoomFactor, view.canGoBack(), finalNavigation)
|
||||
if (!view.canGoBack() && !finalNavigation) {
|
||||
view.src = 'zoom://host2'
|
||||
} else if (!finalNavigation) {
|
||||
finalNavigation = true
|
||||
view.src = 'b.html'
|
||||
view.goBack()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<html>
|
||||
<body>
|
||||
<webview nodeintegration src="zoom://host1" id="view" partition="webview-temp"/>
|
||||
</body>
|
||||
<script>
|
||||
const {ipcRenderer, webFrame} = require('electron')
|
||||
const view = document.getElementById('view')
|
||||
let finalNavigation = false
|
||||
function SendZoomLevel() {
|
||||
return new Promise((resolve, reject) => {
|
||||
view.getZoomLevel((zoomLevel) => {
|
||||
view.getZoomFactor((zoomFactor) => {
|
||||
ipcRenderer.send('webview-zoom-in-page', zoomLevel, zoomFactor, finalNavigation)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
view.addEventListener('dom-ready', () => {
|
||||
view.setZoomLevel(2.0)
|
||||
SendZoomLevel().then(() => {
|
||||
if (!finalNavigation) {
|
||||
finalNavigation = true
|
||||
view.executeJavaScript('window.location.hash=123', () => {})
|
||||
}
|
||||
})
|
||||
})
|
||||
view.addEventListener('did-navigate-in-page', () => {
|
||||
SendZoomLevel()
|
||||
})
|
||||
</script>
|
||||
</html>
|
|
@ -2,7 +2,7 @@
|
|||
<body>
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
const {ipcRenderer, webFrame} = require('electron')
|
||||
ipcRenderer.send('webview-zoom-level', webFrame.getZoomFactor(), webFrame.getZoomLevel())
|
||||
ipcRenderer.send('webview-parent-zoom-level', webFrame.getZoomFactor(), webFrame.getZoomLevel())
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1527,6 +1527,21 @@ describe('<webview> tag', function () {
|
|||
})
|
||||
|
||||
describe('zoom behavior', () => {
|
||||
const zoomScheme = remote.getGlobal('zoomScheme')
|
||||
const webviewSession = session.fromPartition('webview-temp')
|
||||
|
||||
before((done) => {
|
||||
const protocol = webviewSession.protocol
|
||||
protocol.registerStringProtocol(zoomScheme, (request, callback) => {
|
||||
callback('hello')
|
||||
}, (error) => done(error))
|
||||
})
|
||||
|
||||
after((done) => {
|
||||
const protocol = webviewSession.protocol
|
||||
protocol.unregisterProtocol(zoomScheme, (error) => done(error))
|
||||
})
|
||||
|
||||
it('inherits the zoomFactor of the parent window', (done) => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
|
@ -1534,7 +1549,7 @@ describe('<webview> tag', function () {
|
|||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
ipcMain.once('webview-zoom-level', (event, zoomFactor, zoomLevel) => {
|
||||
ipcMain.once('webview-parent-zoom-level', (event, zoomFactor, zoomLevel) => {
|
||||
assert.equal(zoomFactor, 1.2)
|
||||
assert.equal(zoomLevel, 1)
|
||||
done()
|
||||
|
@ -1542,24 +1557,39 @@ describe('<webview> tag', function () {
|
|||
w.loadURL(`file://${fixtures}/pages/webview-zoom-factor.html`)
|
||||
})
|
||||
|
||||
it('inherits the zoomLevel of parent window on navigation', (done) => {
|
||||
it('maintains zoom level on navigation', (done) => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, final) => {
|
||||
if (!final) {
|
||||
ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, newHost, final) => {
|
||||
if (!newHost) {
|
||||
assert.equal(zoomFactor, 1.44)
|
||||
assert.equal(zoomLevel, 2.0)
|
||||
} else {
|
||||
assert.equal(zoomFactor, 1.2)
|
||||
assert.equal(zoomLevel, 1)
|
||||
done()
|
||||
}
|
||||
if (final) done()
|
||||
})
|
||||
w.loadURL(`file://${fixtures}/pages/webview-custom-zoom-level.html`)
|
||||
})
|
||||
|
||||
it('maintains zoom level when navigating within same page', (done) => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
zoomFactor: 1.2
|
||||
}
|
||||
})
|
||||
ipcMain.on('webview-zoom-in-page', (event, zoomLevel, zoomFactor, final) => {
|
||||
assert.equal(zoomFactor, 1.44)
|
||||
assert.equal(zoomLevel, 2.0)
|
||||
if (final) done()
|
||||
})
|
||||
w.loadURL(`file://${fixtures}/pages/webview-in-page-navigate.html`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Загрузка…
Ссылка в новой задаче