@@ -54,9 +54,7 @@ function Browser(props: { app: AppState }) {
54
54
} ) ;
55
55
56
56
connection . events . on ( "Cursor" , ( cursor ) => InputHandler . setCursor ( canvas , cursor ) ) ;
57
-
58
- InputHandler . setupEventListeners ( canvas , connection ) ;
59
-
57
+ InputHandler . setupEventListeners ( props . app , canvas , connection ) ;
60
58
} ) ;
61
59
62
60
return (
@@ -71,7 +69,6 @@ function Browser(props: { app: AppState }) {
71
69
72
70
export default Browser ;
73
71
74
-
75
72
class Renderer {
76
73
private canvas : HTMLCanvasElement ;
77
74
private canvasCtx : CanvasRenderingContext2D ;
@@ -119,52 +116,50 @@ class InputHandler {
119
116
[ Cursor . Crosshair ] : "crosshair" ,
120
117
} ;
121
118
122
- static setupEventListeners ( canvas : HTMLCanvasElement , connection : TabConnection ) {
123
- canvas . onmousemove = ( e ) => this . handleMouseMove ( e , connection ) ;
124
- canvas . onmousedown = ( e ) => this . handleMouseDown ( e , connection ) ;
125
- canvas . onmouseup = ( e ) => this . handleMouseUp ( e , connection ) ;
126
- canvas . onwheel = ( e ) => this . handleWheel ( e , connection ) ;
119
+ static setupEventListeners ( app : AppState , canvas : HTMLCanvasElement , connection : TabConnection ) {
120
+ canvas . onmousemove = ( e ) => connection . page . mouseMove ( e . offsetX , e . offsetY ) ;
121
+ canvas . onmousedown = ( e ) => connection . page . click ( e . offsetX , e . offsetY , e . button , true ) ;
122
+ canvas . onmouseup = ( e ) => connection . page . click ( e . offsetX , e . offsetY , e . button , false ) ;
123
+ canvas . onwheel = ( e ) => connection . page . scroll ( e . offsetX , e . offsetY , e . deltaX , e . deltaY ) ;
127
124
128
- canvas . onkeydown = ( e ) => this . handleKeyDown ( e , connection ) ;
129
- canvas . onkeyup = ( e ) => this . handleKeyUp ( e , connection ) ;
130
-
131
- canvas . onfocus = ( ) => connection . page . focus ( true ) ;
132
- canvas . onblur = ( ) => connection . page . focus ( false ) ;
133
- }
134
-
135
- private static handleMouseMove ( e : MouseEvent , connection : TabConnection ) {
136
- connection . page . mouseMove ( e . offsetX , e . offsetY ) ;
137
- }
138
-
139
- private static handleMouseDown ( e : MouseEvent , connection : TabConnection ) {
140
- connection . page . click ( e . offsetX , e . offsetY , e . button , true ) ;
141
- }
125
+ canvas . onkeydown = ( e ) => {
126
+ if ( app . shortcuts . checkShortcutConflict ( e ) ) return ;
142
127
143
- private static handleMouseUp ( e : MouseEvent , connection : TabConnection ) {
144
- connection . page . click ( e . offsetX , e . offsetY , e . button , false ) ;
145
- }
128
+ if ( e . key === "Tab" ) {
129
+ e . preventDefault ( ) ;
130
+ }
146
131
147
- private static handleWheel ( e : WheelEvent , connection : TabConnection ) {
148
- connection . page . scroll ( e . offsetX , e . offsetY , e . deltaX , e . deltaY ) ;
149
- }
132
+ const keyCode = domCodeToKeyCode ( e . code ) ;
133
+ if ( keyCode !== undefined ) {
134
+ let unicode = 0 ;
135
+ if ( e . key . length === 1 ) {
136
+ unicode = e . key . charCodeAt ( 0 ) ;
137
+ }
138
+ connection . page . key ( keyCode , unicode , true , e . ctrlKey , e . shiftKey ) ;
139
+ }
140
+ }
141
+ canvas . onkeyup = ( e ) => {
142
+ if ( app . shortcuts . checkShortcutConflict ( e ) ) return ;
150
143
151
- private static handleKeyDown ( e : KeyboardEvent , connection : TabConnection ) {
152
- const keyCode = domCodeToKeyCode ( e . code ) ;
153
- if ( keyCode !== undefined ) {
154
- let unicode = 0 ;
155
- if ( e . key . length === 1 ) {
156
- unicode = e . key . charCodeAt ( 0 ) ;
144
+ if ( e . key === "Tab" ) {
145
+ e . preventDefault ( ) ;
157
146
}
158
- connection . page . key ( keyCode , unicode , true , e . ctrlKey , e . shiftKey ) ;
159
147
148
+ const keyCode = domCodeToKeyCode ( e . code ) ;
149
+ if ( keyCode !== undefined ) {
150
+ connection . page . key ( keyCode , 0 , false , e . ctrlKey , e . shiftKey ) ;
151
+ }
160
152
}
161
- }
162
153
163
- private static handleKeyUp ( e : KeyboardEvent , connection : TabConnection ) {
164
- const keyCode = domCodeToKeyCode ( e . code ) ;
165
- if ( keyCode !== undefined ) {
166
- connection . page . key ( keyCode , 0 , false , e . ctrlKey , e . shiftKey ) ;
167
- }
154
+ canvas . onfocus = ( ) => {
155
+ app . setBrowserFocused ( true ) ;
156
+ connection . page . focus ( true ) ;
157
+ } ;
158
+ canvas . onblur = ( ) => {
159
+ console . log ( "canvas blurred" ) ;
160
+ app . setBrowserFocused ( false ) ;
161
+ connection . page . focus ( false ) ;
162
+ } ;
168
163
}
169
164
170
165
static setCursor ( canvas : HTMLCanvasElement , cursor : Cursor ) {
0 commit comments