feat: replace scroll-touch* with generic input-event (#35531)
This commit is contained in:
parent
dfb8a2d804
commit
f82a863f65
20 changed files with 253 additions and 138 deletions
|
@ -652,18 +652,36 @@ The following app commands are explicitly supported on Linux:
|
||||||
* `browser-backward`
|
* `browser-backward`
|
||||||
* `browser-forward`
|
* `browser-forward`
|
||||||
|
|
||||||
#### Event: 'scroll-touch-begin' _macOS_
|
#### Event: 'scroll-touch-begin' _macOS_ _Deprecated_
|
||||||
|
|
||||||
Emitted when scroll wheel event phase has begun.
|
Emitted when scroll wheel event phase has begun.
|
||||||
|
|
||||||
#### Event: 'scroll-touch-end' _macOS_
|
> **Note**
|
||||||
|
> This event is deprecated beginning in Electron 22.0.0. See [Breaking
|
||||||
|
> Changes](breaking-changes.md#deprecated-browserwindow-scroll-touch--events)
|
||||||
|
> for details of how to migrate to using the [WebContents
|
||||||
|
> `input-event`](api/web-contents.md#event-input-event) event.
|
||||||
|
|
||||||
|
#### Event: 'scroll-touch-end' _macOS_ _Deprecated_
|
||||||
|
|
||||||
Emitted when scroll wheel event phase has ended.
|
Emitted when scroll wheel event phase has ended.
|
||||||
|
|
||||||
#### Event: 'scroll-touch-edge' _macOS_
|
> **Note**
|
||||||
|
> This event is deprecated beginning in Electron 22.0.0. See [Breaking
|
||||||
|
> Changes](breaking-changes.md#deprecated-browserwindow-scroll-touch--events)
|
||||||
|
> for details of how to migrate to using the [WebContents
|
||||||
|
> `input-event`](api/web-contents.md#event-input-event) event.
|
||||||
|
|
||||||
|
#### Event: 'scroll-touch-edge' _macOS_ _Deprecated_
|
||||||
|
|
||||||
Emitted when scroll wheel event phase filed upon reaching the edge of element.
|
Emitted when scroll wheel event phase filed upon reaching the edge of element.
|
||||||
|
|
||||||
|
> **Note**
|
||||||
|
> This event is deprecated beginning in Electron 22.0.0. See [Breaking
|
||||||
|
> Changes](breaking-changes.md#deprecated-browserwindow-scroll-touch--events)
|
||||||
|
> for details of how to migrate to using the [WebContents
|
||||||
|
> `input-event`](api/web-contents.md#event-input-event) event.
|
||||||
|
|
||||||
#### Event: 'swipe' _macOS_
|
#### Event: 'swipe' _macOS_
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
# InputEvent Object
|
# InputEvent Object
|
||||||
|
|
||||||
|
* `type` string - Can be `undefined`, `mouseDown`, `mouseUp`, `mouseMove`,
|
||||||
|
`mouseEnter`, `mouseLeave`, `contextMenu`, `mouseWheel`, `rawKeyDown`,
|
||||||
|
`keyDown`, `keyUp`, `char`, `gestureScrollBegin`, `gestureScrollEnd`,
|
||||||
|
`gestureScrollUpdate`, `gestureFlingStart`, `gestureFlingCancel`,
|
||||||
|
`gesturePinchBegin`, `gesturePinchEnd`, `gesturePinchUpdate`,
|
||||||
|
`gestureTapDown`, `gestureShowPress`, `gestureTap`, `gestureTapCancel`,
|
||||||
|
`gestureShortPress`, `gestureLongPress`, `gestureLongTap`,
|
||||||
|
`gestureTwoFingerTap`, `gestureTapUnconfirmed`, `gestureDoubleTap`,
|
||||||
|
`touchStart`, `touchMove`, `touchEnd`, `touchCancel`, `touchScrollStarted`,
|
||||||
|
`pointerDown`, `pointerUp`, `pointerMove`, `pointerRawUpdate`,
|
||||||
|
`pointerCancel` or `pointerCausedUaAction`.
|
||||||
* `modifiers` string[] (optional) - An array of modifiers of the event, can
|
* `modifiers` string[] (optional) - An array of modifiers of the event, can
|
||||||
be `shift`, `control`, `ctrl`, `alt`, `meta`, `command`, `cmd`, `isKeypad`,
|
be `shift`, `control`, `ctrl`, `alt`, `meta`, `command`, `cmd`, `isKeypad`,
|
||||||
`isAutoRepeat`, `leftButtonDown`, `middleButtonDown`, `rightButtonDown`,
|
`isAutoRepeat`, `leftButtonDown`, `middleButtonDown`, `rightButtonDown`,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# KeyboardInputEvent Object extends `InputEvent`
|
# KeyboardInputEvent Object extends `InputEvent`
|
||||||
|
|
||||||
* `type` string - The type of the event, can be `keyDown`, `keyUp` or `char`.
|
* `type` string - The type of the event, can be `rawKeyDown`, `keyDown`, `keyUp` or `char`.
|
||||||
* `keyCode` string - The character that will be sent
|
* `keyCode` string - The character that will be sent
|
||||||
as the keyboard event. Should only use the valid key codes in
|
as the keyboard event. Should only use the valid key codes in
|
||||||
[Accelerator](../accelerator.md).
|
[Accelerator](../accelerator.md).
|
||||||
|
|
|
@ -411,6 +411,16 @@ Emitted when a plugin process has crashed.
|
||||||
|
|
||||||
Emitted when `webContents` is destroyed.
|
Emitted when `webContents` is destroyed.
|
||||||
|
|
||||||
|
#### Event: 'input-event'
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `event` Event
|
||||||
|
* `inputEvent` [InputEvent](structures/input-event.md)
|
||||||
|
|
||||||
|
Emitted when an input event is sent to the WebContents. See
|
||||||
|
[InputEvent](structures/input-event.md) for details.
|
||||||
|
|
||||||
#### Event: 'before-input-event'
|
#### Event: 'before-input-event'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -12,6 +12,32 @@ This document uses the following convention to categorize breaking changes:
|
||||||
* **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
|
* **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
|
||||||
* **Removed:** An API or feature was removed, and is no longer supported by Electron.
|
* **Removed:** An API or feature was removed, and is no longer supported by Electron.
|
||||||
|
|
||||||
|
## Planned Breaking API Changes (23.0)
|
||||||
|
|
||||||
|
### Removed: BrowserWindow `scroll-touch-*` events
|
||||||
|
|
||||||
|
The deprecated `scroll-touch-begin`, `scroll-touch-end` and `scroll-touch-edge`
|
||||||
|
events on BrowserWindow have been removed. Instead, use the newly available
|
||||||
|
[`input-event` event](api/web-contents.md#event-input-event) on WebContents.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Removed in Electron 23.0
|
||||||
|
win.on('scroll-touch-begin', scrollTouchBegin)
|
||||||
|
win.on('scroll-touch-edge', scrollTouchEdge)
|
||||||
|
win.on('scroll-touch-end', scrollTouchEnd)
|
||||||
|
|
||||||
|
// Replace with
|
||||||
|
win.webContents.on('input-event', (_, event) => {
|
||||||
|
if (event.type === 'gestureScrollBegin') {
|
||||||
|
scrollTouchBegin()
|
||||||
|
} else if (event.type === 'gestureScrollUpdate') {
|
||||||
|
scrollTouchEdge()
|
||||||
|
} else if (event.type === 'gestureScrollEnd') {
|
||||||
|
scrollTouchEnd()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Planned Breaking API Changes (22.0)
|
## Planned Breaking API Changes (22.0)
|
||||||
|
|
||||||
### Removed: WebContents `new-window` event
|
### Removed: WebContents `new-window` event
|
||||||
|
@ -30,6 +56,30 @@ webContents.setWindowOpenHandler((details) => {
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Deprecated: BrowserWindow `scroll-touch-*` events
|
||||||
|
|
||||||
|
The `scroll-touch-begin`, `scroll-touch-end` and `scroll-touch-edge` events on
|
||||||
|
BrowserWindow are deprecated. Instead, use the newly available [`input-event`
|
||||||
|
event](api/web-contents.md#event-input-event) on WebContents.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Deprecated
|
||||||
|
win.on('scroll-touch-begin', scrollTouchBegin)
|
||||||
|
win.on('scroll-touch-edge', scrollTouchEdge)
|
||||||
|
win.on('scroll-touch-end', scrollTouchEnd)
|
||||||
|
|
||||||
|
// Replace with
|
||||||
|
win.webContents.on('input-event', (_, event) => {
|
||||||
|
if (event.type === 'gestureScrollBegin') {
|
||||||
|
scrollTouchBegin()
|
||||||
|
} else if (event.type === 'gestureScrollUpdate') {
|
||||||
|
scrollTouchEdge()
|
||||||
|
} else if (event.type === 'gestureScrollEnd') {
|
||||||
|
scrollTouchEnd()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Planned Breaking API Changes (20.0)
|
## Planned Breaking API Changes (20.0)
|
||||||
|
|
||||||
### Behavior Changed: V8 Memory Cage enabled
|
### Behavior Changed: V8 Memory Cage enabled
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron/main';
|
import { BaseWindow, WebContents, Event, BrowserView, TouchBar } from 'electron/main';
|
||||||
import type { BrowserWindow as BWT } from 'electron/main';
|
import type { BrowserWindow as BWT } from 'electron/main';
|
||||||
|
import * as deprecate from '@electron/internal/common/deprecate';
|
||||||
const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT };
|
const { BrowserWindow } = process._linkedBinding('electron_browser_window') as { BrowserWindow: typeof BWT };
|
||||||
|
|
||||||
Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype);
|
Object.setPrototypeOf(BrowserWindow.prototype, BaseWindow.prototype);
|
||||||
|
@ -44,6 +45,28 @@ BrowserWindow.prototype._init = function (this: BWT) {
|
||||||
this.on(event as any, visibilityChanged);
|
this.on(event as any, visibilityChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const warn = deprecate.warnOnceMessage('\'scroll-touch-{begin,end,edge}\' are deprecated and will be removed. Please use the WebContents \'input-event\' event instead.');
|
||||||
|
this.webContents.on('input-event', (_, e) => {
|
||||||
|
if (e.type === 'gestureScrollBegin') {
|
||||||
|
if (this.listenerCount('scroll-touch-begin') !== 0) {
|
||||||
|
warn();
|
||||||
|
this.emit('scroll-touch-edge');
|
||||||
|
this.emit('scroll-touch-begin');
|
||||||
|
}
|
||||||
|
} else if (e.type === 'gestureScrollUpdate') {
|
||||||
|
if (this.listenerCount('scroll-touch-edge') !== 0) {
|
||||||
|
warn();
|
||||||
|
this.emit('scroll-touch-edge');
|
||||||
|
}
|
||||||
|
} else if (e.type === 'gestureScrollEnd') {
|
||||||
|
if (this.listenerCount('scroll-touch-end') !== 0) {
|
||||||
|
warn();
|
||||||
|
this.emit('scroll-touch-edge');
|
||||||
|
this.emit('scroll-touch-end');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Notify the creation of the window.
|
// Notify the creation of the window.
|
||||||
const event = process._linkedBinding('electron_browser_event').createEmpty();
|
const event = process._linkedBinding('electron_browser_event').createEmpty();
|
||||||
app.emit('browser-window-created', event, this);
|
app.emit('browser-window-created', event, this);
|
||||||
|
|
|
@ -3,10 +3,13 @@ type DeprecationHandler = (message: string) => void;
|
||||||
let deprecationHandler: DeprecationHandler | null = null;
|
let deprecationHandler: DeprecationHandler | null = null;
|
||||||
|
|
||||||
export function warnOnce (oldName: string, newName?: string) {
|
export function warnOnce (oldName: string, newName?: string) {
|
||||||
let warned = false;
|
return warnOnceMessage(newName
|
||||||
const msg = newName
|
|
||||||
? `'${oldName}' is deprecated and will be removed. Please use '${newName}' instead.`
|
? `'${oldName}' is deprecated and will be removed. Please use '${newName}' instead.`
|
||||||
: `'${oldName}' is deprecated and will be removed.`;
|
: `'${oldName}' is deprecated and will be removed.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function warnOnceMessage (msg: string) {
|
||||||
|
let warned = false;
|
||||||
return () => {
|
return () => {
|
||||||
if (!warned && !process.noDeprecation) {
|
if (!warned && !process.noDeprecation) {
|
||||||
warned = true;
|
warned = true;
|
||||||
|
|
|
@ -247,14 +247,6 @@ void BaseWindow::OnWindowLeaveFullScreen() {
|
||||||
Emit("leave-full-screen");
|
Emit("leave-full-screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseWindow::OnWindowScrollTouchBegin() {
|
|
||||||
Emit("scroll-touch-begin");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseWindow::OnWindowScrollTouchEnd() {
|
|
||||||
Emit("scroll-touch-end");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseWindow::OnWindowSwipe(const std::string& direction) {
|
void BaseWindow::OnWindowSwipe(const std::string& direction) {
|
||||||
Emit("swipe", direction);
|
Emit("swipe", direction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,6 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
||||||
bool* prevent_default) override;
|
bool* prevent_default) override;
|
||||||
void OnWindowMove() override;
|
void OnWindowMove() override;
|
||||||
void OnWindowMoved() override;
|
void OnWindowMoved() override;
|
||||||
void OnWindowScrollTouchBegin() override;
|
|
||||||
void OnWindowScrollTouchEnd() override;
|
|
||||||
void OnWindowSwipe(const std::string& direction) override;
|
void OnWindowSwipe(const std::string& direction) override;
|
||||||
void OnWindowRotateGesture(float rotation) override;
|
void OnWindowRotateGesture(float rotation) override;
|
||||||
void OnWindowSheetBegin() override;
|
void OnWindowSheetBegin() override;
|
||||||
|
|
|
@ -106,10 +106,6 @@ BrowserWindow::BrowserWindow(gin::Arguments* args,
|
||||||
// Associate with BrowserWindow.
|
// Associate with BrowserWindow.
|
||||||
web_contents->SetOwnerWindow(window());
|
web_contents->SetOwnerWindow(window());
|
||||||
|
|
||||||
auto* host = web_contents->web_contents()->GetRenderViewHost();
|
|
||||||
if (host)
|
|
||||||
host->GetWidget()->AddInputEventObserver(this);
|
|
||||||
|
|
||||||
InitWithArgs(args);
|
InitWithArgs(args);
|
||||||
|
|
||||||
// Install the content view after BaseWindow's JS code is initialized.
|
// Install the content view after BaseWindow's JS code is initialized.
|
||||||
|
@ -128,9 +124,6 @@ BrowserWindow::~BrowserWindow() {
|
||||||
if (api_web_contents_) {
|
if (api_web_contents_) {
|
||||||
// Cleanup the observers if user destroyed this instance directly instead of
|
// Cleanup the observers if user destroyed this instance directly instead of
|
||||||
// gracefully closing content::WebContents.
|
// gracefully closing content::WebContents.
|
||||||
auto* host = web_contents()->GetRenderViewHost();
|
|
||||||
if (host)
|
|
||||||
host->GetWidget()->RemoveInputEventObserver(this);
|
|
||||||
api_web_contents_->RemoveObserver(this);
|
api_web_contents_->RemoveObserver(this);
|
||||||
// Destroy the WebContents.
|
// Destroy the WebContents.
|
||||||
OnCloseContents();
|
OnCloseContents();
|
||||||
|
@ -138,26 +131,6 @@ BrowserWindow::~BrowserWindow() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::OnInputEvent(const blink::WebInputEvent& event) {
|
|
||||||
switch (event.GetType()) {
|
|
||||||
case blink::WebInputEvent::Type::kGestureScrollBegin:
|
|
||||||
case blink::WebInputEvent::Type::kGestureScrollUpdate:
|
|
||||||
case blink::WebInputEvent::Type::kGestureScrollEnd:
|
|
||||||
Emit("scroll-touch-edge");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BrowserWindow::RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
||||||
content::RenderViewHost* new_host) {
|
|
||||||
if (old_host)
|
|
||||||
old_host->GetWidget()->RemoveInputEventObserver(this);
|
|
||||||
if (new_host)
|
|
||||||
new_host->GetWidget()->AddInputEventObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BrowserWindow::BeforeUnloadDialogCancelled() {
|
void BrowserWindow::BeforeUnloadDialogCancelled() {
|
||||||
WindowList::WindowCloseCancelled(window());
|
WindowList::WindowCloseCancelled(window());
|
||||||
// Cancel unresponsive event when window close is cancelled.
|
// Cancel unresponsive event when window close is cancelled.
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
namespace electron::api {
|
namespace electron::api {
|
||||||
|
|
||||||
class BrowserWindow : public BaseWindow,
|
class BrowserWindow : public BaseWindow,
|
||||||
public content::RenderWidgetHost::InputEventObserver,
|
|
||||||
public content::WebContentsObserver,
|
public content::WebContentsObserver,
|
||||||
public ExtendedWebContentsObserver {
|
public ExtendedWebContentsObserver {
|
||||||
public:
|
public:
|
||||||
|
@ -43,12 +42,7 @@ class BrowserWindow : public BaseWindow,
|
||||||
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
|
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
|
||||||
~BrowserWindow() override;
|
~BrowserWindow() override;
|
||||||
|
|
||||||
// content::RenderWidgetHost::InputEventObserver:
|
|
||||||
void OnInputEvent(const blink::WebInputEvent& event) override;
|
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
||||||
content::RenderViewHost* new_host) override;
|
|
||||||
void BeforeUnloadDialogCancelled() override;
|
void BeforeUnloadDialogCancelled() override;
|
||||||
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
||||||
void OnRendererResponsive(
|
void OnRendererResponsive(
|
||||||
|
|
|
@ -820,6 +820,12 @@ void WebContents::InitZoomController(content::WebContents* web_contents,
|
||||||
double zoom_factor;
|
double zoom_factor;
|
||||||
if (options.Get(options::kZoomFactor, &zoom_factor))
|
if (options.Get(options::kZoomFactor, &zoom_factor))
|
||||||
zoom_controller_->SetDefaultZoomFactor(zoom_factor);
|
zoom_controller_->SetDefaultZoomFactor(zoom_factor);
|
||||||
|
|
||||||
|
// Nothing to do with ZoomController, but this function gets called in all
|
||||||
|
// init cases!
|
||||||
|
content::RenderViewHost* host = web_contents->GetRenderViewHost();
|
||||||
|
if (host)
|
||||||
|
host->GetWidget()->AddInputEventObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::InitWithSessionAndOptions(
|
void WebContents::InitWithSessionAndOptions(
|
||||||
|
@ -957,6 +963,12 @@ void WebContents::InitWithWebContents(
|
||||||
}
|
}
|
||||||
|
|
||||||
WebContents::~WebContents() {
|
WebContents::~WebContents() {
|
||||||
|
if (web_contents()) {
|
||||||
|
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
|
||||||
|
if (host)
|
||||||
|
host->GetWidget()->RemoveInputEventObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (!inspectable_web_contents_) {
|
if (!inspectable_web_contents_) {
|
||||||
WebContentsDestroyed();
|
WebContentsDestroyed();
|
||||||
return;
|
return;
|
||||||
|
@ -1273,7 +1285,12 @@ content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
|
||||||
|
|
||||||
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
||||||
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
||||||
bool prevent_default = Emit("before-input-event", event);
|
// For backwards compatibility, pretend that `kRawKeyDown` events are
|
||||||
|
// actually `kKeyDown`.
|
||||||
|
content::NativeWebKeyboardEvent tweaked_event(event);
|
||||||
|
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
|
||||||
|
tweaked_event.SetType(blink::WebInputEvent::Type::kKeyDown);
|
||||||
|
bool prevent_default = Emit("before-input-event", tweaked_event);
|
||||||
if (prevent_default) {
|
if (prevent_default) {
|
||||||
return content::KeyboardEventProcessingResult::HANDLED;
|
return content::KeyboardEventProcessingResult::HANDLED;
|
||||||
}
|
}
|
||||||
|
@ -1684,6 +1701,14 @@ void WebContents::OnWebContentsLostFocus(
|
||||||
Emit("blur");
|
Emit("blur");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||||
|
content::RenderViewHost* new_host) {
|
||||||
|
if (old_host)
|
||||||
|
old_host->GetWidget()->RemoveInputEventObserver(this);
|
||||||
|
if (new_host)
|
||||||
|
new_host->GetWidget()->AddInputEventObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::DOMContentLoaded(
|
void WebContents::DOMContentLoaded(
|
||||||
content::RenderFrameHost* render_frame_host) {
|
content::RenderFrameHost* render_frame_host) {
|
||||||
auto* web_frame = WebFrameMain::FromRenderFrameHost(render_frame_host);
|
auto* web_frame = WebFrameMain::FromRenderFrameHost(render_frame_host);
|
||||||
|
@ -3060,6 +3085,9 @@ void WebContents::SendInputEvent(v8::Isolate* isolate,
|
||||||
blink::WebKeyboardEvent::Type::kRawKeyDown,
|
blink::WebKeyboardEvent::Type::kRawKeyDown,
|
||||||
blink::WebInputEvent::Modifiers::kNoModifiers, ui::EventTimeForNow());
|
blink::WebInputEvent::Modifiers::kNoModifiers, ui::EventTimeForNow());
|
||||||
if (gin::ConvertFromV8(isolate, input_event, &keyboard_event)) {
|
if (gin::ConvertFromV8(isolate, input_event, &keyboard_event)) {
|
||||||
|
// For backwards compatibility, convert `kKeyDown` to `kRawKeyDown`.
|
||||||
|
if (keyboard_event.GetType() == blink::WebKeyboardEvent::Type::kKeyDown)
|
||||||
|
keyboard_event.SetType(blink::WebKeyboardEvent::Type::kRawKeyDown);
|
||||||
rwh->ForwardKeyboardEvent(keyboard_event);
|
rwh->ForwardKeyboardEvent(keyboard_event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -3466,6 +3494,10 @@ void WebContents::SetImageAnimationPolicy(const std::string& new_policy) {
|
||||||
web_contents()->OnWebPreferencesChanged();
|
web_contents()->OnWebPreferencesChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::OnInputEvent(const blink::WebInputEvent& event) {
|
||||||
|
Emit("input-event", event);
|
||||||
|
}
|
||||||
|
|
||||||
v8::Local<v8::Promise> WebContents::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
v8::Local<v8::Promise> WebContents::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
||||||
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
|
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
|
||||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||||
|
|
|
@ -103,6 +103,7 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
public gin_helper::CleanedUpAtExit,
|
public gin_helper::CleanedUpAtExit,
|
||||||
public content::WebContentsObserver,
|
public content::WebContentsObserver,
|
||||||
public content::WebContentsDelegate,
|
public content::WebContentsDelegate,
|
||||||
|
public content::RenderWidgetHost::InputEventObserver,
|
||||||
public InspectableWebContentsDelegate,
|
public InspectableWebContentsDelegate,
|
||||||
public InspectableWebContentsViewDelegate {
|
public InspectableWebContentsViewDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -433,6 +434,9 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
|
|
||||||
void SetImageAnimationPolicy(const std::string& new_policy);
|
void SetImageAnimationPolicy(const std::string& new_policy);
|
||||||
|
|
||||||
|
// content::RenderWidgetHost::InputEventObserver:
|
||||||
|
void OnInputEvent(const blink::WebInputEvent& event) override;
|
||||||
|
|
||||||
// disable copy
|
// disable copy
|
||||||
WebContents(const WebContents&) = delete;
|
WebContents(const WebContents&) = delete;
|
||||||
WebContents& operator=(const WebContents&) = delete;
|
WebContents& operator=(const WebContents&) = delete;
|
||||||
|
@ -616,6 +620,8 @@ class WebContents : public ExclusiveAccessContext,
|
||||||
content::RenderWidgetHost* render_widget_host) override;
|
content::RenderWidgetHost* render_widget_host) override;
|
||||||
void OnWebContentsLostFocus(
|
void OnWebContentsLostFocus(
|
||||||
content::RenderWidgetHost* render_widget_host) override;
|
content::RenderWidgetHost* render_widget_host) override;
|
||||||
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||||
|
content::RenderViewHost* new_host) override;
|
||||||
|
|
||||||
// InspectableWebContentsDelegate:
|
// InspectableWebContentsDelegate:
|
||||||
void DevToolsReloadPage() override;
|
void DevToolsReloadPage() override;
|
||||||
|
|
|
@ -603,16 +603,6 @@ void NativeWindow::NotifyWindowEnterFullScreen() {
|
||||||
observer.OnWindowEnterFullScreen();
|
observer.OnWindowEnterFullScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowScrollTouchBegin() {
|
|
||||||
for (NativeWindowObserver& observer : observers_)
|
|
||||||
observer.OnWindowScrollTouchBegin();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowScrollTouchEnd() {
|
|
||||||
for (NativeWindowObserver& observer : observers_)
|
|
||||||
observer.OnWindowScrollTouchEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
|
void NativeWindow::NotifyWindowSwipe(const std::string& direction) {
|
||||||
for (NativeWindowObserver& observer : observers_)
|
for (NativeWindowObserver& observer : observers_)
|
||||||
observer.OnWindowSwipe(direction);
|
observer.OnWindowSwipe(direction);
|
||||||
|
|
|
@ -291,8 +291,6 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
void NotifyWindowResized();
|
void NotifyWindowResized();
|
||||||
void NotifyWindowWillMove(const gfx::Rect& new_bounds, bool* prevent_default);
|
void NotifyWindowWillMove(const gfx::Rect& new_bounds, bool* prevent_default);
|
||||||
void NotifyWindowMoved();
|
void NotifyWindowMoved();
|
||||||
void NotifyWindowScrollTouchBegin();
|
|
||||||
void NotifyWindowScrollTouchEnd();
|
|
||||||
void NotifyWindowSwipe(const std::string& direction);
|
void NotifyWindowSwipe(const std::string& direction);
|
||||||
void NotifyWindowRotateGesture(float rotation);
|
void NotifyWindowRotateGesture(float rotation);
|
||||||
void NotifyWindowSheetBegin();
|
void NotifyWindowSheetBegin();
|
||||||
|
|
|
@ -228,9 +228,6 @@ class NativeWindowMac : public NativeWindow,
|
||||||
base::scoped_nsobject<ElectronPreviewItem> preview_item_;
|
base::scoped_nsobject<ElectronPreviewItem> preview_item_;
|
||||||
base::scoped_nsobject<ElectronTouchBar> touch_bar_;
|
base::scoped_nsobject<ElectronTouchBar> touch_bar_;
|
||||||
|
|
||||||
// Event monitor for scroll wheel event.
|
|
||||||
id wheel_event_monitor_;
|
|
||||||
|
|
||||||
// The NSView that used as contentView of window.
|
// The NSView that used as contentView of window.
|
||||||
//
|
//
|
||||||
// For frameless window it would fill the whole window.
|
// For frameless window it would fill the whole window.
|
||||||
|
|
|
@ -418,32 +418,6 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
||||||
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
||||||
|
|
||||||
// Use an NSEvent monitor to listen for the wheel event.
|
|
||||||
BOOL __block began = NO;
|
|
||||||
wheel_event_monitor_ = [NSEvent
|
|
||||||
addLocalMonitorForEventsMatchingMask:NSEventMaskScrollWheel
|
|
||||||
handler:^(NSEvent* event) {
|
|
||||||
if ([[event window] windowNumber] !=
|
|
||||||
[window_ windowNumber])
|
|
||||||
return event;
|
|
||||||
|
|
||||||
if (!began && (([event phase] ==
|
|
||||||
NSEventPhaseMayBegin) ||
|
|
||||||
([event phase] ==
|
|
||||||
NSEventPhaseBegan))) {
|
|
||||||
this->NotifyWindowScrollTouchBegin();
|
|
||||||
began = YES;
|
|
||||||
} else if (began &&
|
|
||||||
(([event phase] ==
|
|
||||||
NSEventPhaseEnded) ||
|
|
||||||
([event phase] ==
|
|
||||||
NSEventPhaseCancelled))) {
|
|
||||||
this->NotifyWindowScrollTouchEnd();
|
|
||||||
began = NO;
|
|
||||||
}
|
|
||||||
return event;
|
|
||||||
}];
|
|
||||||
|
|
||||||
// Set maximizable state last to ensure zoom button does not get reset
|
// Set maximizable state last to ensure zoom button does not get reset
|
||||||
// by calls to other APIs.
|
// by calls to other APIs.
|
||||||
SetMaximizable(maximizable);
|
SetMaximizable(maximizable);
|
||||||
|
@ -1725,10 +1699,6 @@ void NativeWindowMac::Cleanup() {
|
||||||
DCHECK(!IsClosed());
|
DCHECK(!IsClosed());
|
||||||
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
||||||
display::Screen::GetScreen()->RemoveObserver(this);
|
display::Screen::GetScreen()->RemoveObserver(this);
|
||||||
if (wheel_event_monitor_) {
|
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
|
||||||
wheel_event_monitor_ = nil;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::OverrideNSWindowContentView() {
|
void NativeWindowMac::OverrideNSWindowContentView() {
|
||||||
|
|
|
@ -81,8 +81,6 @@ class NativeWindowObserver : public base::CheckedObserver {
|
||||||
bool* prevent_default) {}
|
bool* prevent_default) {}
|
||||||
virtual void OnWindowMove() {}
|
virtual void OnWindowMove() {}
|
||||||
virtual void OnWindowMoved() {}
|
virtual void OnWindowMoved() {}
|
||||||
virtual void OnWindowScrollTouchBegin() {}
|
|
||||||
virtual void OnWindowScrollTouchEnd() {}
|
|
||||||
virtual void OnWindowSwipe(const std::string& direction) {}
|
virtual void OnWindowSwipe(const std::string& direction) {}
|
||||||
virtual void OnWindowRotateGesture(float rotation) {}
|
virtual void OnWindowRotateGesture(float rotation) {}
|
||||||
virtual void OnWindowSheetBegin() {}
|
virtual void OnWindowSheetBegin() {}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "gin/converter.h"
|
#include "gin/converter.h"
|
||||||
|
#include "gin/data_object_builder.h"
|
||||||
#include "shell/common/gin_converters/gfx_converter.h"
|
#include "shell/common/gin_converters/gfx_converter.h"
|
||||||
#include "shell/common/gin_converters/gurl_converter.h"
|
#include "shell/common/gin_converters/gurl_converter.h"
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
|
@ -56,43 +57,73 @@ struct Converter<char16_t> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
#define BLINK_EVENT_TYPES() \
|
||||||
struct Converter<blink::WebInputEvent::Type> {
|
CASE_TYPE(kUndefined, "undefined") \
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
CASE_TYPE(kMouseDown, "mouseDown") \
|
||||||
v8::Handle<v8::Value> val,
|
CASE_TYPE(kMouseUp, "mouseUp") \
|
||||||
blink::WebInputEvent::Type* out) {
|
CASE_TYPE(kMouseMove, "mouseMove") \
|
||||||
std::string type = base::ToLowerASCII(gin::V8ToString(isolate, val));
|
CASE_TYPE(kMouseEnter, "mouseEnter") \
|
||||||
if (type == "mousedown")
|
CASE_TYPE(kMouseLeave, "mouseLeave") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseDown;
|
CASE_TYPE(kContextMenu, "contextMenu") \
|
||||||
else if (type == "mouseup")
|
CASE_TYPE(kMouseWheel, "mouseWheel") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseUp;
|
CASE_TYPE(kRawKeyDown, "rawKeyDown") \
|
||||||
else if (type == "mousemove")
|
CASE_TYPE(kKeyDown, "keyDown") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseMove;
|
CASE_TYPE(kKeyUp, "keyUp") \
|
||||||
else if (type == "mouseenter")
|
CASE_TYPE(kChar, "char") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseEnter;
|
CASE_TYPE(kGestureScrollBegin, "gestureScrollBegin") \
|
||||||
else if (type == "mouseleave")
|
CASE_TYPE(kGestureScrollEnd, "gestureScrollEnd") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseLeave;
|
CASE_TYPE(kGestureScrollUpdate, "gestureScrollUpdate") \
|
||||||
else if (type == "contextmenu")
|
CASE_TYPE(kGestureFlingStart, "gestureFlingStart") \
|
||||||
*out = blink::WebInputEvent::Type::kContextMenu;
|
CASE_TYPE(kGestureFlingCancel, "gestureFlingCancel") \
|
||||||
else if (type == "mousewheel")
|
CASE_TYPE(kGesturePinchBegin, "gesturePinchBegin") \
|
||||||
*out = blink::WebInputEvent::Type::kMouseWheel;
|
CASE_TYPE(kGesturePinchEnd, "gesturePinchEnd") \
|
||||||
else if (type == "keydown")
|
CASE_TYPE(kGesturePinchUpdate, "gesturePinchUpdate") \
|
||||||
*out = blink::WebInputEvent::Type::kRawKeyDown;
|
CASE_TYPE(kGestureTapDown, "gestureTapDown") \
|
||||||
else if (type == "keyup")
|
CASE_TYPE(kGestureShowPress, "gestureShowPress") \
|
||||||
*out = blink::WebInputEvent::Type::kKeyUp;
|
CASE_TYPE(kGestureTap, "gestureTap") \
|
||||||
else if (type == "char")
|
CASE_TYPE(kGestureTapCancel, "gestureTapCancel") \
|
||||||
*out = blink::WebInputEvent::Type::kChar;
|
CASE_TYPE(kGestureShortPress, "gestureShortPress") \
|
||||||
else if (type == "touchstart")
|
CASE_TYPE(kGestureLongPress, "gestureLongPress") \
|
||||||
*out = blink::WebInputEvent::Type::kTouchStart;
|
CASE_TYPE(kGestureLongTap, "gestureLongTap") \
|
||||||
else if (type == "touchmove")
|
CASE_TYPE(kGestureTwoFingerTap, "gestureTwoFingerTap") \
|
||||||
*out = blink::WebInputEvent::Type::kTouchMove;
|
CASE_TYPE(kGestureTapUnconfirmed, "gestureTapUnconfirmed") \
|
||||||
else if (type == "touchend")
|
CASE_TYPE(kGestureDoubleTap, "gestureDoubleTap") \
|
||||||
*out = blink::WebInputEvent::Type::kTouchEnd;
|
CASE_TYPE(kTouchStart, "touchStart") \
|
||||||
else if (type == "touchcancel")
|
CASE_TYPE(kTouchMove, "touchMove") \
|
||||||
*out = blink::WebInputEvent::Type::kTouchCancel;
|
CASE_TYPE(kTouchEnd, "touchEnd") \
|
||||||
return true;
|
CASE_TYPE(kTouchCancel, "touchCancel") \
|
||||||
|
CASE_TYPE(kTouchScrollStarted, "touchScrollStarted") \
|
||||||
|
CASE_TYPE(kPointerDown, "pointerDown") \
|
||||||
|
CASE_TYPE(kPointerUp, "pointerUp") \
|
||||||
|
CASE_TYPE(kPointerMove, "pointerMove") \
|
||||||
|
CASE_TYPE(kPointerRawUpdate, "pointerRawUpdate") \
|
||||||
|
CASE_TYPE(kPointerCancel, "pointerCancel") \
|
||||||
|
CASE_TYPE(kPointerCausedUaAction, "pointerCausedUaAction")
|
||||||
|
|
||||||
|
bool Converter<blink::WebInputEvent::Type>::FromV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
v8::Handle<v8::Value> val,
|
||||||
|
blink::WebInputEvent::Type* out) {
|
||||||
|
std::string type = gin::V8ToString(isolate, val);
|
||||||
|
#define CASE_TYPE(event_type, js_name) \
|
||||||
|
if (base::EqualsCaseInsensitiveASCII(type, js_name)) { \
|
||||||
|
*out = blink::WebInputEvent::Type::event_type; \
|
||||||
|
return true; \
|
||||||
}
|
}
|
||||||
};
|
BLINK_EVENT_TYPES()
|
||||||
|
#undef CASE_TYPE
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> Converter<blink::WebInputEvent::Type>::ToV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
const blink::WebInputEvent::Type& in) {
|
||||||
|
#define CASE_TYPE(event_type, js_name) \
|
||||||
|
case blink::WebInputEvent::Type::event_type: \
|
||||||
|
return StringToV8(isolate, js_name);
|
||||||
|
switch (in) { BLINK_EVENT_TYPES() }
|
||||||
|
#undef CASE_TYPE
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<blink::WebMouseEvent::Button> {
|
struct Converter<blink::WebMouseEvent::Button> {
|
||||||
|
@ -207,6 +238,19 @@ bool Converter<blink::WebInputEvent>::FromV8(v8::Isolate* isolate,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> Converter<blink::WebInputEvent>::ToV8(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
const blink::WebInputEvent& in) {
|
||||||
|
if (blink::WebInputEvent::IsKeyboardEventType(in.GetType()))
|
||||||
|
return gin::ConvertToV8(isolate,
|
||||||
|
*static_cast<const blink::WebKeyboardEvent*>(&in));
|
||||||
|
return gin::DataObjectBuilder(isolate)
|
||||||
|
.Set("type", in.GetType())
|
||||||
|
.Set("modifiers", ModifiersToArray(in.GetModifiers()))
|
||||||
|
.Set("_modifiers", in.GetModifiers())
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
|
bool Converter<blink::WebKeyboardEvent>::FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
blink::WebKeyboardEvent* out) {
|
blink::WebKeyboardEvent* out) {
|
||||||
|
@ -276,10 +320,7 @@ v8::Local<v8::Value> Converter<blink::WebKeyboardEvent>::ToV8(
|
||||||
const blink::WebKeyboardEvent& in) {
|
const blink::WebKeyboardEvent& in) {
|
||||||
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
gin_helper::Dictionary dict = gin::Dictionary::CreateEmpty(isolate);
|
||||||
|
|
||||||
if (in.GetType() == blink::WebInputEvent::Type::kRawKeyDown)
|
dict.Set("type", in.GetType());
|
||||||
dict.Set("type", "keyDown");
|
|
||||||
else if (in.GetType() == blink::WebInputEvent::Type::kKeyUp)
|
|
||||||
dict.Set("type", "keyUp");
|
|
||||||
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
|
dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.dom_key));
|
||||||
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
|
dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString(
|
||||||
static_cast<ui::DomCode>(in.dom_code)));
|
static_cast<ui::DomCode>(in.dom_code)));
|
||||||
|
|
|
@ -24,11 +24,22 @@ namespace gin {
|
||||||
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
|
blink::WebInputEvent::Type GetWebInputEventType(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val);
|
v8::Local<v8::Value> val);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct Converter<blink::WebInputEvent::Type> {
|
||||||
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
|
v8::Local<v8::Value> val,
|
||||||
|
blink::WebInputEvent::Type* out);
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const blink::WebInputEvent::Type& in);
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct Converter<blink::WebInputEvent> {
|
struct Converter<blink::WebInputEvent> {
|
||||||
static bool FromV8(v8::Isolate* isolate,
|
static bool FromV8(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Value> val,
|
v8::Local<v8::Value> val,
|
||||||
blink::WebInputEvent* out);
|
blink::WebInputEvent* out);
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const blink::WebInputEvent& in);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
|
Loading…
Add table
Reference in a new issue