|
1 | 1 | use cef::rc::{Rc, RcImpl};
|
2 |
| -use cef::sys::{_cef_display_handler_t, cef_base_ref_counted_t, cef_log_severity_t::*}; |
| 2 | +use cef::sys::{_cef_display_handler_t, cef_base_ref_counted_t, cef_cursor_type_t::*, cef_log_severity_t::*}; |
3 | 3 | use cef::{CefString, ImplDisplayHandler, WrapDisplayHandler};
|
| 4 | +use winit::cursor::CursorIcon; |
4 | 5 |
|
5 |
| -pub(crate) struct DisplayHandlerImpl { |
| 6 | +use crate::cef::CefEventHandler; |
| 7 | + |
| 8 | +pub(crate) struct DisplayHandlerImpl<H: CefEventHandler> { |
6 | 9 | object: *mut RcImpl<_cef_display_handler_t, Self>,
|
| 10 | + event_handler: H, |
7 | 11 | }
|
8 | 12 |
|
9 |
| -impl DisplayHandlerImpl { |
10 |
| - pub fn new() -> Self { |
11 |
| - Self { object: std::ptr::null_mut() } |
| 13 | +impl<H: CefEventHandler> DisplayHandlerImpl<H> { |
| 14 | + pub fn new(event_handler: H) -> Self { |
| 15 | + Self { |
| 16 | + object: std::ptr::null_mut(), |
| 17 | + event_handler, |
| 18 | + } |
12 | 19 | }
|
13 | 20 | }
|
14 | 21 |
|
15 |
| -impl ImplDisplayHandler for DisplayHandlerImpl { |
| 22 | +impl<H: CefEventHandler> ImplDisplayHandler for DisplayHandlerImpl<H> { |
| 23 | + fn on_cursor_change(&self, _browser: Option<&mut cef::Browser>, _cursor: cef::CursorHandle, cursor_type: cef::CursorType, _custom_cursor_info: Option<&cef::CursorInfo>) -> ::std::os::raw::c_int { |
| 24 | + let cursor = match cursor_type.into() { |
| 25 | + CT_POINTER => CursorIcon::Default, |
| 26 | + CT_CROSS => CursorIcon::Crosshair, |
| 27 | + CT_HAND => CursorIcon::Pointer, |
| 28 | + CT_IBEAM => CursorIcon::Text, |
| 29 | + CT_WAIT => CursorIcon::Wait, |
| 30 | + CT_HELP => CursorIcon::Help, |
| 31 | + CT_EASTRESIZE => CursorIcon::EResize, |
| 32 | + CT_NORTHRESIZE => CursorIcon::NResize, |
| 33 | + CT_NORTHEASTRESIZE => CursorIcon::NeResize, |
| 34 | + CT_NORTHWESTRESIZE => CursorIcon::NwResize, |
| 35 | + CT_SOUTHRESIZE => CursorIcon::SResize, |
| 36 | + CT_SOUTHEASTRESIZE => CursorIcon::SeResize, |
| 37 | + CT_SOUTHWESTRESIZE => CursorIcon::SwResize, |
| 38 | + CT_WESTRESIZE => CursorIcon::WResize, |
| 39 | + CT_NORTHSOUTHRESIZE => CursorIcon::NsResize, |
| 40 | + CT_EASTWESTRESIZE => CursorIcon::EwResize, |
| 41 | + CT_NORTHEASTSOUTHWESTRESIZE => CursorIcon::NeswResize, |
| 42 | + CT_NORTHWESTSOUTHEASTRESIZE => CursorIcon::NwseResize, |
| 43 | + CT_COLUMNRESIZE => CursorIcon::ColResize, |
| 44 | + CT_ROWRESIZE => CursorIcon::RowResize, |
| 45 | + CT_MIDDLEPANNING => CursorIcon::AllScroll, |
| 46 | + CT_EASTPANNING => CursorIcon::AllScroll, |
| 47 | + CT_NORTHPANNING => CursorIcon::AllScroll, |
| 48 | + CT_NORTHEASTPANNING => CursorIcon::AllScroll, |
| 49 | + CT_NORTHWESTPANNING => CursorIcon::AllScroll, |
| 50 | + CT_SOUTHPANNING => CursorIcon::AllScroll, |
| 51 | + CT_SOUTHEASTPANNING => CursorIcon::AllScroll, |
| 52 | + CT_SOUTHWESTPANNING => CursorIcon::AllScroll, |
| 53 | + CT_WESTPANNING => CursorIcon::AllScroll, |
| 54 | + CT_MOVE => CursorIcon::Move, |
| 55 | + CT_VERTICALTEXT => CursorIcon::VerticalText, |
| 56 | + CT_CELL => CursorIcon::Cell, |
| 57 | + CT_CONTEXTMENU => CursorIcon::ContextMenu, |
| 58 | + CT_ALIAS => CursorIcon::Alias, |
| 59 | + CT_PROGRESS => CursorIcon::Progress, |
| 60 | + CT_NODROP => CursorIcon::NoDrop, |
| 61 | + CT_COPY => CursorIcon::Copy, |
| 62 | + CT_NONE => CursorIcon::Default, |
| 63 | + CT_NOTALLOWED => CursorIcon::NotAllowed, |
| 64 | + CT_ZOOMIN => CursorIcon::ZoomIn, |
| 65 | + CT_ZOOMOUT => CursorIcon::ZoomOut, |
| 66 | + CT_GRAB => CursorIcon::Grab, |
| 67 | + CT_GRABBING => CursorIcon::Grabbing, |
| 68 | + CT_MIDDLE_PANNING_VERTICAL => CursorIcon::AllScroll, |
| 69 | + CT_MIDDLE_PANNING_HORIZONTAL => CursorIcon::AllScroll, |
| 70 | + CT_CUSTOM => CursorIcon::Default, |
| 71 | + CT_DND_NONE => CursorIcon::Default, |
| 72 | + CT_DND_MOVE => CursorIcon::Move, |
| 73 | + CT_DND_COPY => CursorIcon::Copy, |
| 74 | + CT_DND_LINK => CursorIcon::Alias, |
| 75 | + CT_NUM_VALUES => CursorIcon::Default, |
| 76 | + _ => CursorIcon::Default, |
| 77 | + }; |
| 78 | + |
| 79 | + self.event_handler.cursor_change(cursor.into()); |
| 80 | + |
| 81 | + 1 // We handled the cursor change. |
| 82 | + } |
| 83 | + |
16 | 84 | fn on_console_message(
|
17 | 85 | &self,
|
18 | 86 | _browser: Option<&mut cef::Browser>,
|
@@ -41,24 +109,27 @@ impl ImplDisplayHandler for DisplayHandlerImpl {
|
41 | 109 | }
|
42 | 110 | }
|
43 | 111 |
|
44 |
| -impl Clone for DisplayHandlerImpl { |
| 112 | +impl<H: CefEventHandler> Clone for DisplayHandlerImpl<H> { |
45 | 113 | fn clone(&self) -> Self {
|
46 | 114 | unsafe {
|
47 | 115 | let rc_impl = &mut *self.object;
|
48 | 116 | rc_impl.interface.add_ref();
|
49 | 117 | }
|
50 |
| - Self { object: self.object } |
| 118 | + Self { |
| 119 | + object: self.object, |
| 120 | + event_handler: self.event_handler.clone(), |
| 121 | + } |
51 | 122 | }
|
52 | 123 | }
|
53 |
| -impl Rc for DisplayHandlerImpl { |
| 124 | +impl<H: CefEventHandler> Rc for DisplayHandlerImpl<H> { |
54 | 125 | fn as_base(&self) -> &cef_base_ref_counted_t {
|
55 | 126 | unsafe {
|
56 | 127 | let base = &*self.object;
|
57 | 128 | std::mem::transmute(&base.cef_object)
|
58 | 129 | }
|
59 | 130 | }
|
60 | 131 | }
|
61 |
| -impl WrapDisplayHandler for DisplayHandlerImpl { |
| 132 | +impl<H: CefEventHandler> WrapDisplayHandler for DisplayHandlerImpl<H> { |
62 | 133 | fn wrap_rc(&mut self, object: *mut RcImpl<_cef_display_handler_t, Self>) {
|
63 | 134 | self.object = object;
|
64 | 135 | }
|
|
0 commit comments