Skip to content

Commit c4046c7

Browse files
committed
fixing bugs
1 parent 3a8aabd commit c4046c7

File tree

5 files changed

+211
-288
lines changed

5 files changed

+211
-288
lines changed

examples/multi_webview.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl App {
8484

8585
fn subscription(&self) -> Subscription<Message> {
8686
time::every(Duration::from_millis(10))
87-
.map(|_| Action::Update)
87+
.map(|_| Action::UpdateAll)
8888
.map(Message::WebView)
8989
}
9090
}

src/engines.rs

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,55 @@ use crate::ImageInfo;
99
#[cfg(feature = "ultralight")]
1010
pub mod ultralight;
1111

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+
1219
pub enum PixelFormat {
1320
Rgba,
1421
Bgra,
1522
}
1623

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-
2624
/// Alias of usize used for controlling specific views
2725
/// Only used by advanced to get views, basic simply uses u32
2826
pub type ViewId = usize;
2927

3028
/// Trait to handle multiple browser engines
3129
/// Currently only supports cpu renders via pixel_buffer
30+
/// Passing a View id that does not exist will cause a panic
3231
pub trait Engine {
3332
/// Used to do work in the actual browser engine
3433
fn update(&mut self);
3534
/// Has Ultralight perform a new render
3635
fn render(&mut self, size: Size<u32>);
3736
/// 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;
4340
/// 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);
4642

4743
// window changes - no id needed they work for all views(gloabally)
4844
fn focus(&mut self);
4945
fn unfocus(&self);
5046
fn resize(&mut self, size: Size<u32>);
5147

5248
// 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);
5751

5852
/// 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;
8563
}

0 commit comments

Comments
 (0)