Skip to content
Permalink
Browse files

feat: add webContents 'zoom-changed' event (#17747)

  • Loading branch information...
miniak authored and alexeykuzmin committed May 14, 2019
1 parent 23b0487 commit 6609138959826a4be0e1a340975e981bf72aaefc
@@ -636,6 +636,10 @@ content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
return content::KeyboardEventProcessingResult::NOT_HANDLED;
}

void WebContents::ContentsZoomChange(bool zoom_in) {
Emit("zoom-changed", zoom_in ? "in" : "out");
}

void WebContents::EnterFullscreenModeForTab(
content::WebContents* source,
const GURL& origin,
@@ -369,6 +369,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override;
void ContentsZoomChange(bool zoom_in) override;
void EnterFullscreenModeForTab(
content::WebContents* source,
const GURL& origin,
@@ -374,6 +374,14 @@ Emitted when the window enters a full-screen state triggered by HTML API.

Emitted when the window leaves a full-screen state triggered by HTML API.

#### Event: 'zoom-changed'

Returns:
* `event` Event
* `zoomDirection` String - Can be `in` or `out`.

Emitted when the user is requesting to change the zoom level using the mouse wheel.

#### Event: 'devtools-opened'

Emitted when DevTools is opened.
@@ -345,6 +345,45 @@ describe('webContents module', () => {
})
})

describe('zoom-changed', () => {
beforeEach(function () {
// On Mac, zooming isn't done with the mouse wheel.
if (process.platform === 'darwin') {
return closeWindow(w).then(() => {
w = null
this.skip()
})
}
})

it('is emitted with the correct zooming info', async () => {
w.loadFile(path.join(fixtures, 'pages', 'base-page.html'))
await emittedOnce(w.webContents, 'did-finish-load')

const testZoomChanged = async ({ zoomingIn }) => {
const promise = emittedOnce(w.webContents, 'zoom-changed')

w.webContents.sendInputEvent({
type: 'mousewheel',
x: 300,
y: 300,
deltaX: 0,
deltaY: zoomingIn ? 1 : -1,
wheelTicksX: 0,
wheelTicksY: zoomingIn ? 1 : -1,
phase: 'began',
modifiers: ['control', 'meta']
})

const [, zoomDirection] = await promise
expect(zoomDirection).to.equal(zoomingIn ? 'in' : 'out')
}

await testZoomChanged({ zoomingIn: true })
await testZoomChanged({ zoomingIn: false })
})
})

describe('devtools window', () => {
let testFn = it
if (process.platform === 'darwin' && isCi) {

0 comments on commit 6609138

Please sign in to comment.
You can’t perform that action at this time.