@@ -9,77 +9,55 @@ use crate::ImageInfo;
9
9
#[ cfg( feature = "ultralight" ) ]
10
10
pub mod ultralight;
11
11
12
+ /// Creation of new pages to be of a html type or a url
13
+ #[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord ) ]
14
+ pub enum PageType {
15
+ Url ( String ) ,
16
+ Html ( String ) ,
17
+ }
18
+
12
19
pub enum PixelFormat {
13
20
Rgba ,
14
21
Bgra ,
15
22
}
16
23
17
- /// Result type for get_url, get_title, get_view, and get_cursor
18
- /// This is because they can fail by the wrong id, and the requested view, may not be loaded yet
19
- #[ derive( Debug , Clone ) ]
20
- pub enum EngineResult < T > {
21
- IdDoesNotExist ,
22
- NotLoaded ,
23
- Success ( T ) ,
24
- }
25
-
26
24
/// Alias of usize used for controlling specific views
27
25
/// Only used by advanced to get views, basic simply uses u32
28
26
pub type ViewId = usize ;
29
27
30
28
/// Trait to handle multiple browser engines
31
29
/// Currently only supports cpu renders via pixel_buffer
30
+ /// Passing a View id that does not exist will cause a panic
32
31
pub trait Engine {
33
32
/// Used to do work in the actual browser engine
34
33
fn update ( & mut self ) ;
35
34
/// Has Ultralight perform a new render
36
35
fn render ( & mut self , size : Size < u32 > ) ;
37
36
/// Request that the browser engine rerender a specific view that may have been updated
38
- /// Can fail if requested id does not exist
39
- fn request_render ( & mut self , id : ViewId , size : Size < u32 > ) -> Option < ( ) > ;
40
- /// Creates new a new blank view and returns the ViewId to interact with it
41
- /// Can fail if underlying engine fails to create view
42
- fn new_view ( & mut self , size : Size < u32 > ) -> Option < ViewId > ;
37
+ fn request_render ( & mut self , id : ViewId , size : Size < u32 > ) ;
38
+ /// Creates new a new (possibly blank) view and returns the ViewId to interact with it
39
+ fn new_view ( & mut self , size : Size < u32 > , content : Option < PageType > ) -> ViewId ;
43
40
/// Removes desired view
44
- /// Can fail if requested id does not exist
45
- fn remove_view ( & mut self , id : ViewId ) -> Option < ( ) > ;
41
+ fn remove_view ( & mut self , id : ViewId ) ;
46
42
47
43
// window changes - no id needed they work for all views(gloabally)
48
44
fn focus ( & mut self ) ;
49
45
fn unfocus ( & self ) ;
50
46
fn resize ( & mut self , size : Size < u32 > ) ;
51
47
52
48
// handle events per engine
53
- /// Can fail if requested id does not exist
54
- fn handle_keyboard_event ( & mut self , id : ViewId , event : keyboard:: Event ) -> Option < ( ) > ;
55
- /// Can fail if requested id does not exist
56
- fn handle_mouse_event ( & mut self , id : ViewId , point : Point , event : mouse:: Event ) -> Option < ( ) > ;
49
+ fn handle_keyboard_event ( & mut self , id : ViewId , event : keyboard:: Event ) ;
50
+ fn handle_mouse_event ( & mut self , id : ViewId , point : Point , event : mouse:: Event ) ;
57
51
58
52
/// Allows navigating to html or Url on a specific view
59
- /// Can fail if requested id does not exist
60
- fn goto ( & mut self , id : ViewId , page_type : PageType ) -> Option < ( ) > ;
61
- /// Can fail if requested id does not exist
62
- fn refresh ( & mut self , id : ViewId ) -> Option < ( ) > ;
63
- /// Can fail if requested id does not exist
64
- fn go_forward ( & mut self , id : ViewId ) -> Option < ( ) > ;
65
- /// Can fail if requested id does not exist
66
- fn go_back ( & mut self , id : ViewId ) -> Option < ( ) > ;
67
- /// Can fail if requested id does not exist
68
- fn scroll ( & mut self , id : ViewId , delta : mouse:: ScrollDelta ) -> Option < ( ) > ;
69
-
70
- /// Can fail if requested id does not exist or page has not loaded and therfore has no url
71
- fn get_url ( & self , id : ViewId ) -> EngineResult < String > ;
72
- /// Can fail if requested id does not exist or page has not loaded and therfore has no title
73
- fn get_title ( & self , id : ViewId ) -> EngineResult < String > ;
74
- /// Can fail if requested id does not exist
75
- fn get_cursor ( & self , id : ViewId ) -> EngineResult < Interaction > ;
76
- /// Can fail if requested id does not exist
77
- fn get_view ( & self , id : ViewId ) -> EngineResult < & ImageInfo > ;
78
- }
79
-
80
- /// Allows users to create new views with url or custom html
81
- #[ derive( Clone , Debug , Eq , PartialEq , PartialOrd , Ord ) ]
82
- pub enum PageType {
83
- Url ( String ) ,
84
- Html ( String ) ,
53
+ fn goto ( & mut self , id : ViewId , page_type : PageType ) ;
54
+ fn refresh ( & mut self , id : ViewId ) ;
55
+ fn go_forward ( & mut self , id : ViewId ) ;
56
+ fn go_back ( & mut self , id : ViewId ) ;
57
+ fn scroll ( & mut self , id : ViewId , delta : mouse:: ScrollDelta ) ;
58
+
59
+ fn get_url ( & self , id : ViewId ) -> String ;
60
+ fn get_title ( & self , id : ViewId ) -> String ;
61
+ fn get_cursor ( & self , id : ViewId ) -> Interaction ;
62
+ fn get_view ( & self , id : ViewId ) -> & ImageInfo ;
85
63
}
0 commit comments