Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MouseTouchEventHandler において button の値が一部 PointerEventHandler と異なってしまう問題を修正 #295

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 2.8.3
* `MouseTouchEventHandler` において `button` の値が一部 `PointerEventHandler` と異なってしまう問題を修正

## 2.8.2
* `Platform#getTabindex()` を `Platform#getTabIndex()` に変更
* `Platform#setTabindex()` を `Platform#setTabIndex()` に変更
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akashic/pdi-browser",
"version": "2.8.2",
"version": "2.8.3",
"description": "An akashic-pdi implementation for Web browsers",
"main": "index.js",
"typings": "lib/full/index.d.ts",
Expand Down
32 changes: 23 additions & 9 deletions src/handler/MouseTouchEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ export class MouseTouchEventHandler extends InputEventHandler {
this.inputView.removeEventListener("contextmenu", preventEventDefault);
}

private getPlatformButtonType(e: MouseEvent): PlatformButtonType {
private getPlatformButtonType(e: MouseEvent, defaultValue: number): PlatformButtonType {
switch (e.button) {
case -1:
// 変化なし
return PlatformButtonType.Unchanged;
case 0:
// 左クリック
// 主ボタン(通常は左ボタン)
return PlatformButtonType.Primary;
case 1:
// ミドルクリック
// 予備ボタン(通常は中ボタン)
return PlatformButtonType.Auxiliary;
case 2:
// 右クリック
// 副ボタン(通常は右ボタン)
return PlatformButtonType.Secondary;
default:
// 上記以外のボタンは左クリックとして扱う
return PlatformButtonType.Primary;
return defaultValue;
}
}

Expand All @@ -54,22 +56,34 @@ export class MouseTouchEventHandler extends InputEventHandler {
if (this.pressingMouseButton != null) return;
this.pressingMouseButton = e.button;

this.pointDown(MouseTouchEventHandler.MOUSE_IDENTIFIER, this.getOffsetPositionFromInputView(e), this.getPlatformButtonType(e));
this.pointDown(
MouseTouchEventHandler.MOUSE_IDENTIFIER,
this.getOffsetPositionFromInputView(e),
this.getPlatformButtonType(e, PlatformButtonType.Primary)
);
window.addEventListener("mousemove", this.onWindowMouseMove, false);
window.addEventListener("mouseup", this.onWindowMouseUp, false);
// NOTE ここで e.preventDefault() してはならない。
// preventDefault() すると、iframe 内で動作していて iframe 外にドラッグした時に mousemove が途切れるようになる。
};

private onWindowMouseMove: (e: MouseEvent) => void = e => {
this.pointMove(MouseTouchEventHandler.MOUSE_IDENTIFIER, this.getOffsetPositionFromInputView(e), this.getPlatformButtonType(e));
this.pointMove(
MouseTouchEventHandler.MOUSE_IDENTIFIER,
this.getOffsetPositionFromInputView(e),
PlatformButtonType.Unchanged // NOTE: 簡易的だが pointermove と挙動を揃えるために常に Unchanged を指定する
);
};

private onWindowMouseUp: (e: MouseEvent) => void = e => {
if (this.pressingMouseButton !== e.button) return;
this.pressingMouseButton = null;

this.pointUp(MouseTouchEventHandler.MOUSE_IDENTIFIER, this.getOffsetPositionFromInputView(e), this.getPlatformButtonType(e));
this.pointUp(
MouseTouchEventHandler.MOUSE_IDENTIFIER,
this.getOffsetPositionFromInputView(e),
this.getPlatformButtonType(e, PlatformButtonType.Primary)
);
window.removeEventListener("mousemove", this.onWindowMouseMove, false);
window.removeEventListener("mouseup", this.onWindowMouseUp, false);
};
Expand Down