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 ;
57
68use crate :: cef:: consts:: { MULTICLICK_ALLOWED_TRAVEL , MULTICLICK_TIMEOUT } ;
79
@@ -31,26 +33,57 @@ 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 {
35- CefModifiers :: new ( self , location, is_repeat)
36+ pub ( crate ) fn cef_modifiers ( & self , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> cef_event_flags_t {
37+ let mut flags = cef_event_flags_t:: EVENTFLAG_NONE ;
38+
39+ if self . modifiers . shift_key ( ) {
40+ flags |= cef_event_flags_t:: EVENTFLAG_SHIFT_DOWN ;
41+ }
42+ if self . modifiers . control_key ( ) {
43+ flags |= cef_event_flags_t:: EVENTFLAG_CONTROL_DOWN ;
44+ }
45+ if self . modifiers . alt_key ( ) {
46+ flags |= cef_event_flags_t:: EVENTFLAG_ALT_DOWN ;
47+ }
48+ if self . modifiers . meta_key ( ) {
49+ flags |= cef_event_flags_t:: EVENTFLAG_COMMAND_DOWN ;
50+ }
51+
52+ if self . mouse_state . left {
53+ flags |= cef_event_flags_t:: EVENTFLAG_LEFT_MOUSE_BUTTON ;
54+ }
55+ if self . mouse_state . right {
56+ flags |= cef_event_flags_t:: EVENTFLAG_RIGHT_MOUSE_BUTTON ;
57+ }
58+ if self . mouse_state . middle {
59+ flags |= cef_event_flags_t:: EVENTFLAG_MIDDLE_MOUSE_BUTTON ;
60+ }
61+
62+ if is_repeat {
63+ flags |= cef_event_flags_t:: EVENTFLAG_IS_REPEAT ;
64+ }
65+
66+ flags |= match location {
67+ KeyLocation :: Left => cef_event_flags_t:: EVENTFLAG_IS_LEFT ,
68+ KeyLocation :: Right => cef_event_flags_t:: EVENTFLAG_IS_RIGHT ,
69+ KeyLocation :: Numpad => cef_event_flags_t:: EVENTFLAG_IS_KEY_PAD ,
70+ KeyLocation :: Standard => cef_event_flags_t:: EVENTFLAG_NONE ,
71+ } ;
72+
73+ flags
3674 }
3775
38- pub ( crate ) fn cef_mouse_modifiers ( & self ) -> CefModifiers {
76+ pub ( crate ) fn cef_mouse_modifiers ( & self ) -> cef_event_flags_t {
3977 self . cef_modifiers ( & winit:: keyboard:: KeyLocation :: Standard , false )
4078 }
4179}
4280
43- impl From < InputState > for CefModifiers {
44- fn from ( val : InputState ) -> Self {
45- CefModifiers :: new ( & val, & winit:: keyboard:: KeyLocation :: Standard , false )
46- }
47- }
4881impl From < & InputState > for MouseEvent {
4982 fn from ( val : & InputState ) -> Self {
5083 MouseEvent {
5184 x : val. mouse_position . x as i32 ,
5285 y : val. mouse_position . y as i32 ,
53- modifiers : val. cef_mouse_modifiers ( ) . raw ( ) ,
86+ modifiers : val. cef_mouse_modifiers ( ) . 0 ,
5487 }
5588 }
5689}
@@ -59,7 +92,7 @@ impl From<&mut InputState> for MouseEvent {
5992 MouseEvent {
6093 x : val. mouse_position . x as i32 ,
6194 y : val. mouse_position . y as i32 ,
62- modifiers : val. cef_mouse_modifiers ( ) . raw ( ) ,
95+ modifiers : val. cef_mouse_modifiers ( ) . 0 ,
6396 }
6497 }
6598}
@@ -196,52 +229,3 @@ impl Default for ClickRecord {
196229 }
197230 }
198231}
199-
200- pub ( crate ) struct CefModifiers ( u32 ) ;
201- impl 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 ;
206-
207- if input_state. modifiers . shift_key ( ) {
208- inner |= cef_event_flags_t:: EVENTFLAG_SHIFT_DOWN as u32 ;
209- }
210- if input_state. modifiers . control_key ( ) {
211- inner |= cef_event_flags_t:: EVENTFLAG_CONTROL_DOWN as u32 ;
212- }
213- if input_state. modifiers . alt_key ( ) {
214- inner |= cef_event_flags_t:: EVENTFLAG_ALT_DOWN as u32 ;
215- }
216- if input_state. modifiers . meta_key ( ) {
217- inner |= cef_event_flags_t:: EVENTFLAG_COMMAND_DOWN as u32 ;
218- }
219-
220- if input_state. mouse_state . left {
221- inner |= cef_event_flags_t:: EVENTFLAG_LEFT_MOUSE_BUTTON as u32 ;
222- }
223- if input_state. mouse_state . right {
224- inner |= cef_event_flags_t:: EVENTFLAG_RIGHT_MOUSE_BUTTON as u32 ;
225- }
226- if input_state. mouse_state . middle {
227- inner |= cef_event_flags_t:: EVENTFLAG_MIDDLE_MOUSE_BUTTON as u32 ;
228- }
229-
230- if is_repeat {
231- inner |= cef_event_flags_t:: EVENTFLAG_IS_REPEAT as u32 ;
232- }
233-
234- 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 ,
239- } ;
240-
241- Self ( inner)
242- }
243-
244- pub ( crate ) fn raw ( & self ) -> u32 {
245- self . 0
246- }
247- }
0 commit comments