11use cef:: rc:: { Rc , RcImpl } ;
22use cef:: sys:: { _cef_display_handler_t, cef_base_ref_counted_t, cef_cursor_type_t:: * , cef_log_severity_t:: * } ;
3- use cef:: { CefString , ImplDisplayHandler , WrapDisplayHandler } ;
3+ use cef:: { CefString , ImplDisplayHandler , Point , Size , WrapDisplayHandler } ;
44use winit:: cursor:: CursorIcon ;
55
66use crate :: cef:: CefEventHandler ;
@@ -25,7 +25,21 @@ type CefCursorHandle = cef::CursorHandle;
2525type CefCursorHandle = * mut u8 ;
2626
2727impl < H : CefEventHandler > ImplDisplayHandler for DisplayHandlerImpl < H > {
28- fn on_cursor_change ( & self , _browser : Option < & mut cef:: Browser > , _cursor : CefCursorHandle , cursor_type : cef:: CursorType , _custom_cursor_info : Option < & cef:: CursorInfo > ) -> std:: ffi:: c_int {
28+ fn on_cursor_change ( & self , _browser : Option < & mut cef:: Browser > , _cursor : CefCursorHandle , cursor_type : cef:: CursorType , custom_cursor_info : Option < & cef:: CursorInfo > ) -> std:: ffi:: c_int {
29+ if let Some ( custom_cursor_info) = custom_cursor_info {
30+ let Size { width, height } = custom_cursor_info. size ;
31+ let Point { x : hotspot_x, y : hotspot_y } = custom_cursor_info. hotspot ;
32+ let buffer_size = ( width * height * 4 ) as usize ;
33+ let buffer_ptr = custom_cursor_info. buffer as * const u8 ;
34+
35+ if !buffer_ptr. is_null ( ) && buffer_ptr. align_offset ( std:: mem:: align_of :: < u8 > ( ) ) == 0 {
36+ let buffer = unsafe { std:: slice:: from_raw_parts ( buffer_ptr, buffer_size) } . to_vec ( ) ;
37+ let cursor = winit:: cursor:: CustomCursorSource :: from_rgba ( buffer, width as u16 , height as u16 , hotspot_x as u16 , hotspot_y as u16 ) . unwrap ( ) ;
38+ self . event_handler . cursor_change ( cursor. into ( ) ) ;
39+ return 1 ; // We handled the cursor change.
40+ }
41+ }
42+
2943 let cursor = match cursor_type. into ( ) {
3044 CT_POINTER => CursorIcon :: Default ,
3145 CT_CROSS => CursorIcon :: Crosshair ,
@@ -72,7 +86,6 @@ impl<H: CefEventHandler> ImplDisplayHandler for DisplayHandlerImpl<H> {
7286 CT_GRABBING => CursorIcon :: Grabbing ,
7387 CT_MIDDLE_PANNING_VERTICAL => CursorIcon :: AllScroll ,
7488 CT_MIDDLE_PANNING_HORIZONTAL => CursorIcon :: AllScroll ,
75- CT_CUSTOM => CursorIcon :: Default ,
7689 CT_DND_NONE => CursorIcon :: Default ,
7790 CT_DND_MOVE => CursorIcon :: Move ,
7891 CT_DND_COPY => CursorIcon :: Copy ,
0 commit comments