11use cef:: MouseEvent ;
2+ use cef:: sys:: cef_event_flags_t;
23use std:: time:: Instant ;
34use winit:: dpi:: PhysicalPosition ;
45use winit:: event:: { ElementState , MouseButton } ;
6+ use winit:: keyboard:: { KeyLocation , ModifiersState } ;
57
68use crate :: cef:: consts:: { MULTICLICK_ALLOWED_TRAVEL , MULTICLICK_TIMEOUT } ;
79
810#[ derive( Default ) ]
911pub ( crate ) struct InputState {
10- modifiers : winit :: keyboard :: ModifiersState ,
12+ modifiers : ModifiersState ,
1113 mouse_position : MousePosition ,
1214 mouse_state : MouseState ,
1315 mouse_click_tracker : ClickTracker ,
1416}
1517impl InputState {
16- pub ( crate ) fn modifiers_changed ( & mut self , modifiers : & winit :: keyboard :: ModifiersState ) {
18+ pub ( crate ) fn modifiers_changed ( & mut self , modifiers : & ModifiersState ) {
1719 self . modifiers = * modifiers;
1820 }
1921
@@ -31,26 +33,26 @@ impl InputState {
3133 self . mouse_click_tracker . input ( button, state, self . mouse_position )
3234 }
3335
34- pub ( crate ) fn cef_modifiers ( & self , location : & winit :: keyboard :: KeyLocation , is_repeat : bool ) -> CefModifiers {
36+ pub ( crate ) fn cef_modifiers ( & self , location : & KeyLocation , is_repeat : bool ) -> CefModifiers {
3537 CefModifiers :: new ( self , location, is_repeat)
3638 }
3739
3840 pub ( crate ) fn cef_mouse_modifiers ( & self ) -> CefModifiers {
39- self . cef_modifiers ( & winit :: keyboard :: KeyLocation :: Standard , false )
41+ self . cef_modifiers ( & KeyLocation :: Standard , false )
4042 }
4143}
4244
4345impl From < InputState > for CefModifiers {
4446 fn from ( val : InputState ) -> Self {
45- CefModifiers :: new ( & val, & winit :: keyboard :: KeyLocation :: Standard , false )
47+ CefModifiers :: new ( & val, & KeyLocation :: Standard , false )
4648 }
4749}
4850impl From < & InputState > for MouseEvent {
4951 fn from ( val : & InputState ) -> Self {
5052 MouseEvent {
5153 x : val. mouse_position . x as i32 ,
5254 y : val. mouse_position . y as i32 ,
53- modifiers : val. cef_mouse_modifiers ( ) . raw ( ) ,
55+ modifiers : val. cef_mouse_modifiers ( ) . into ( ) ,
5456 }
5557 }
5658}
@@ -59,7 +61,7 @@ impl From<&mut InputState> for MouseEvent {
5961 MouseEvent {
6062 x : val. mouse_position . x as i32 ,
6163 y : val. mouse_position . y as i32 ,
62- modifiers : val. cef_mouse_modifiers ( ) . raw ( ) ,
64+ modifiers : val. cef_mouse_modifiers ( ) . into ( ) ,
6365 }
6466 }
6567}
@@ -197,51 +199,51 @@ impl Default for ClickRecord {
197199 }
198200}
199201
200- pub ( crate ) struct CefModifiers ( u32 ) ;
202+ pub ( crate ) struct CefModifiers ( cef_event_flags_t ) ;
201203impl CefModifiers {
202- fn new ( input_state : & InputState , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> Self {
203- use cef:: sys:: cef_event_flags_t;
204-
205- let mut inner = 0 ;
204+ fn new ( input_state : & InputState , location : & KeyLocation , is_repeat : bool ) -> Self {
205+ let mut inner = cef_event_flags_t:: EVENTFLAG_NONE ;
206206
207207 if input_state. modifiers . shift_key ( ) {
208- inner |= cef_event_flags_t:: EVENTFLAG_SHIFT_DOWN as u32 ;
208+ inner |= cef_event_flags_t:: EVENTFLAG_SHIFT_DOWN ;
209209 }
210210 if input_state. modifiers . control_key ( ) {
211- inner |= cef_event_flags_t:: EVENTFLAG_CONTROL_DOWN as u32 ;
211+ inner |= cef_event_flags_t:: EVENTFLAG_CONTROL_DOWN ;
212212 }
213213 if input_state. modifiers . alt_key ( ) {
214- inner |= cef_event_flags_t:: EVENTFLAG_ALT_DOWN as u32 ;
214+ inner |= cef_event_flags_t:: EVENTFLAG_ALT_DOWN ;
215215 }
216216 if input_state. modifiers . meta_key ( ) {
217- inner |= cef_event_flags_t:: EVENTFLAG_COMMAND_DOWN as u32 ;
217+ inner |= cef_event_flags_t:: EVENTFLAG_COMMAND_DOWN ;
218218 }
219219
220220 if input_state. mouse_state . left {
221- inner |= cef_event_flags_t:: EVENTFLAG_LEFT_MOUSE_BUTTON as u32 ;
221+ inner |= cef_event_flags_t:: EVENTFLAG_LEFT_MOUSE_BUTTON ;
222222 }
223223 if input_state. mouse_state . right {
224- inner |= cef_event_flags_t:: EVENTFLAG_RIGHT_MOUSE_BUTTON as u32 ;
224+ inner |= cef_event_flags_t:: EVENTFLAG_RIGHT_MOUSE_BUTTON ;
225225 }
226226 if input_state. mouse_state . middle {
227- inner |= cef_event_flags_t:: EVENTFLAG_MIDDLE_MOUSE_BUTTON as u32 ;
227+ inner |= cef_event_flags_t:: EVENTFLAG_MIDDLE_MOUSE_BUTTON ;
228228 }
229229
230230 if is_repeat {
231- inner |= cef_event_flags_t:: EVENTFLAG_IS_REPEAT as u32 ;
231+ inner |= cef_event_flags_t:: EVENTFLAG_IS_REPEAT ;
232232 }
233233
234234 inner |= match location {
235- winit :: keyboard :: KeyLocation :: Left => cef_event_flags_t:: EVENTFLAG_IS_LEFT as u32 ,
236- winit :: keyboard :: KeyLocation :: Right => cef_event_flags_t:: EVENTFLAG_IS_RIGHT as u32 ,
237- winit :: keyboard :: KeyLocation :: Numpad => cef_event_flags_t:: EVENTFLAG_IS_KEY_PAD as u32 ,
238- winit :: keyboard :: KeyLocation :: Standard => 0 ,
235+ KeyLocation :: Left => cef_event_flags_t:: EVENTFLAG_IS_LEFT ,
236+ KeyLocation :: Right => cef_event_flags_t:: EVENTFLAG_IS_RIGHT ,
237+ KeyLocation :: Numpad => cef_event_flags_t:: EVENTFLAG_IS_KEY_PAD ,
238+ KeyLocation :: Standard => cef_event_flags_t :: EVENTFLAG_NONE ,
239239 } ;
240240
241241 Self ( inner)
242242 }
243+ }
243244
244- pub ( crate ) fn raw ( & self ) -> u32 {
245- self . 0
245+ impl Into < u32 > for CefModifiers {
246+ fn into ( self ) -> u32 {
247+ self . 0 . 0 as u32
246248 }
247249}
0 commit comments