This commit is contained in:
gellert 2016-07-31 17:10:53 +02:00
Родитель 5525ac36b8
Коммит 35ee99265e
7 изменённых файлов: 177 добавлений и 8 удалений

Просмотреть файл

@ -1516,7 +1516,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
&WebContents::ShowDefinitionForSelection)
.SetMethod("capturePage", &WebContents::CapturePage)
.SetMethod("isFocused", &WebContents::IsFocused)
.SetMethod("isOffScreen", &WebContents::IsOffScreen)
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
.SetMethod("startPainting", &WebContents::StartPainting)
.SetMethod("stopPainting", &WebContents::StopPainting)
.SetMethod("isPainting", &WebContents::IsPainting)

Просмотреть файл

@ -17,7 +17,8 @@ OffScreenOutputDevice::OffScreenOutputDevice(bool transparent,
DCHECK(!callback_.is_null());
}
OffScreenOutputDevice::~OffScreenOutputDevice() { }
OffScreenOutputDevice::~OffScreenOutputDevice() {
}
void OffScreenOutputDevice::Resize(
const gfx::Size& pixel_size, float scale_factor) {

Просмотреть файл

@ -32,7 +32,7 @@ exports.load = (appUrl) => {
backgroundColor: '#FFFFFF',
useContentSize: true,
webPreferences: {
offscreen: true,
// offscreen: true,
nodeIntegration: false
}
})
@ -81,7 +81,7 @@ exports.load = (appUrl) => {
console.log(`browser #2: ${d < 10 ? ` ${d}` : d} ms`)
start2 = end2
})*/
})
mainWindow3 = new BrowserWindow({
width: 800,

Просмотреть файл

@ -1059,6 +1059,10 @@ win.webContents.on('did-finish-load', () => {
Shows pop-up dictionary that searches the selected word on the page.
#### `contents.isOffscreen()`
Indicates whether *offscreen rendering* is enabled.
#### `contents.startPainting()`
If *offscreen rendering* is enabled and not painting, start painting.

Просмотреть файл

@ -1167,4 +1167,156 @@ describe('browser-window module', function () {
w.loadURL(server.url)
})
})
describe('offscreen rendering', function () {
it('creates offscreen window', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.once('paint', function (event, rect, data, size) {
assert.notEqual(data.length, 0)
done()
})
})
describe('window.webContents.isOffscreen', function () {
it('has offscreen type', function () {
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
assert.equal(w_.webContents.isOffscreen(), true)
})
it('is a regular window', function () {
assert.equal(w.webContents.isOffscreen(), false)
})
})
describe('window.webContents.isPainting', function () {
it('is currently painting', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.isPainting(), true)
done()
})
})
})
describe('window.webContents.stopPainting', function () {
it('stops painting', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.stopPainting()
assert.equal(w_.webContents.isPainting(), false)
done()
})
})
})
describe('window.webContents.startPainting', function () {
it('starts painting', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.stopPainting()
w_.webContents.startPainting()
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.isPainting(), true)
done()
})
})
})
})
describe('window.webContents.getFrameRate', function () {
it('has default frame rate', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.getFrameRate(), 60)
done()
})
})
})
describe('window.webContents.setFrameRate', function () {
it('has custom frame rate', function (done) {
this.timeout(10000)
let w_ = new BrowserWindow({
show: false,
width: 400,
height: 400,
webPreferences: {
backgroundThrottling: false,
offscreen: true
}
})
w_.loadURL('file://' + fixtures + '/api/offscreen-rendering.html')
w_.webContents.on('dom-ready', function () {
w_.webContents.setFrameRate(30)
w_.webContents.once('paint', function (event, rect, data, size) {
assert.equal(w_.webContents.getFrameRate(), 30)
done()
})
})
})
})
})
})

Просмотреть файл

@ -40,11 +40,12 @@ describe('webContents module', function () {
return a.getId() - b.getId()
})
assert.equal(all.length, 4)
assert.equal(all.length, 5)
assert.equal(all[0].getType(), 'window')
assert.equal(all[1].getType(), 'window')
assert.equal(all[2].getType(), 'remote')
assert.equal(all[3].getType(), 'webview')
assert.equal(all[1].getType(), 'offscreen')
assert.equal(all[2].getType(), 'window')
assert.equal(all[3].getType(), 'remote')
assert.equal(all[4].getType(), 'webview')
done()
})

11
spec/fixtures/api/offscreen-rendering.html поставляемый Normal file
Просмотреть файл

@ -0,0 +1,11 @@
<html>
<body>
<div style="width: 10px; height: 10px;" id="dirty"></div>
</body>
<script type="text/javascript" charset="utf-8">
setInterval(function(){
document.getElementById('dirty').style.backgroundColor =
'#'+(Math.random()*0xFFFFFF<<0).toString(16)
}, 10)
</script>
</html>