@@ -17,7 +17,7 @@ pub enum PixelFormat {
17
17
}
18
18
19
19
pub trait Engine {
20
- type Info : TabInfo ;
20
+ type Info : ViewInfo ;
21
21
22
22
fn do_work ( & self ) ;
23
23
fn need_render ( & self ) -> bool ;
@@ -32,9 +32,9 @@ pub trait Engine {
32
32
fn goto_url ( & self , url : & Url ) ;
33
33
fn goto_html ( & self , html : & str ) ;
34
34
fn has_loaded ( & self ) -> Option < bool > ;
35
- fn new_tab ( & mut self , page_type : PageType , size : Size < u32 > ) -> Tab < Self :: Info > ;
36
- fn get_tabs ( & self ) -> & Tabs < Self :: Info > ;
37
- fn get_tabs_mut ( & mut self ) -> & mut Tabs < Self :: Info > ;
35
+ fn new_view ( & mut self , page_type : PageType , size : Size < u32 > ) -> View < Self :: Info > ;
36
+ fn get_views ( & self ) -> & Views < Self :: Info > ;
37
+ fn get_views_mut ( & mut self ) -> & mut Views < Self :: Info > ;
38
38
39
39
fn refresh ( & self ) ;
40
40
fn go_forward ( & self ) ;
@@ -47,38 +47,38 @@ pub trait Engine {
47
47
fn handle_mouse_event ( & mut self , point : Point , event : mouse:: Event ) ;
48
48
}
49
49
50
- /// Engine specific tab information
51
- pub trait TabInfo {
50
+ /// Engine specific view information
51
+ pub trait ViewInfo {
52
52
fn url ( & self ) -> String ;
53
53
fn title ( & self ) -> String ;
54
54
}
55
55
56
- /// Can be converted from Tab to hold information for ResultType
56
+ /// Can be converted from View to hold information for ResultType
57
57
#[ derive( Clone , Debug , PartialEq ) ]
58
- pub struct DisplayTab {
59
- pub id : u32 ,
58
+ pub struct DisplayView {
59
+ pub id : usize ,
60
60
pub url : String ,
61
61
pub title : String ,
62
62
}
63
63
64
- impl < Info : TabInfo > From < Tab < Info > > for DisplayTab {
65
- fn from ( tab : Tab < Info > ) -> Self {
66
- DisplayTab {
67
- id : tab . id ,
68
- url : tab . url ( ) ,
69
- title : tab . title ( ) ,
64
+ impl < Info : ViewInfo > From < View < Info > > for DisplayView {
65
+ fn from ( view : View < Info > ) -> Self {
66
+ DisplayView {
67
+ id : view . id ,
68
+ url : view . url ( ) ,
69
+ title : view . title ( ) ,
70
70
}
71
71
}
72
72
}
73
73
74
- /// Stores Tab info like url & title
75
- pub struct Tab < Info : TabInfo > {
76
- id : u32 ,
74
+ /// Stores view info like url & title
75
+ pub struct View < Info : ViewInfo > {
76
+ id : usize ,
77
77
view : ImageInfo ,
78
78
info : Info ,
79
79
}
80
80
81
- impl < Info : TabInfo > Tab < Info > {
81
+ impl < Info : ViewInfo > View < Info > {
82
82
pub fn new ( info : Info ) -> Self {
83
83
let id = rand:: thread_rng ( ) . gen ( ) ;
84
84
Self {
@@ -88,8 +88,8 @@ impl<Info: TabInfo> Tab<Info> {
88
88
}
89
89
}
90
90
91
- pub fn to_display_tab ( & self ) -> DisplayTab {
92
- DisplayTab {
91
+ pub fn to_display_view ( & self ) -> DisplayView {
92
+ DisplayView {
93
93
id : self . id ,
94
94
url : self . url ( ) ,
95
95
title : self . title ( ) ,
@@ -104,7 +104,7 @@ impl<Info: TabInfo> Tab<Info> {
104
104
self . view = view;
105
105
}
106
106
107
- pub fn id ( & self ) -> u32 {
107
+ pub fn id ( & self ) -> usize {
108
108
self . id
109
109
}
110
110
@@ -117,94 +117,97 @@ impl<Info: TabInfo> Tab<Info> {
117
117
}
118
118
}
119
119
120
- pub struct Tabs < Info : TabInfo > {
121
- tabs : Vec < Tab < Info > > ,
122
- history : Vec < u32 > ,
120
+ pub struct Views < Info : ViewInfo > {
121
+ views : Vec < View < Info > > ,
122
+ history : Vec < usize > ,
123
123
}
124
124
125
- impl < Info : TabInfo > Default for Tabs < Info > {
125
+ impl < Info : ViewInfo > Default for Views < Info > {
126
126
fn default ( ) -> Self {
127
127
Self :: new ( )
128
128
}
129
129
}
130
130
131
- impl < Info : TabInfo > Tabs < Info > {
131
+ impl < Info : ViewInfo > Views < Info > {
132
132
pub fn new ( ) -> Self {
133
133
Self {
134
- tabs : Vec :: new ( ) ,
134
+ views : Vec :: new ( ) ,
135
135
history : Vec :: new ( ) ,
136
136
}
137
137
}
138
138
139
- pub fn id_to_index ( & self , id : u32 ) -> usize {
140
- for ( idx, tab ) in self . tabs . iter ( ) . enumerate ( ) {
141
- if tab . id == id {
139
+ pub fn id_to_index ( & self , id : usize ) -> usize {
140
+ for ( idx, view ) in self . views . iter ( ) . enumerate ( ) {
141
+ if view . id == id {
142
142
return idx;
143
143
}
144
144
}
145
145
panic ! ( "Id: {} was not found" , id) ;
146
146
}
147
147
148
- pub fn index_to_id ( & self , index : usize ) -> u32 {
149
- self . tabs
148
+ pub fn index_to_id ( & self , index : usize ) -> usize {
149
+ self . views
150
150
. get ( index)
151
151
. unwrap_or_else ( || panic ! ( "Index {} was not found" , index) )
152
152
. id
153
153
}
154
154
155
- pub fn get_current_id ( & self ) -> Option < u32 > {
155
+ pub fn get_current_id ( & self ) -> Option < usize > {
156
156
Some ( self . history . last ( ) ?. to_owned ( ) )
157
157
}
158
158
159
- pub fn set_current_id ( & mut self , id : u32 ) {
159
+ pub fn set_current_id ( & mut self , id : usize ) {
160
160
self . history . push ( id)
161
161
}
162
162
163
- pub fn tabs ( & self ) -> & Vec < Tab < Info > > {
164
- & self . tabs
163
+ pub fn views ( & self ) -> & Vec < View < Info > > {
164
+ & self . views
165
165
}
166
166
167
- pub fn display_tabs ( & self ) -> Vec < DisplayTab > {
168
- self . tabs . iter ( ) . map ( |tab| tab. to_display_tab ( ) ) . collect ( )
167
+ pub fn display_views ( & self ) -> Vec < DisplayView > {
168
+ self . views
169
+ . iter ( )
170
+ . map ( |view| view. to_display_view ( ) )
171
+ . collect ( )
169
172
}
170
173
171
- pub fn insert ( & mut self , tab : Tab < Info > ) -> u32 {
172
- let id = tab . id ;
173
- self . tabs . push ( tab ) ;
174
+ pub fn insert ( & mut self , view : View < Info > ) -> usize {
175
+ let id = view . id ;
176
+ self . views . push ( view ) ;
174
177
id
175
178
}
176
179
177
- /// Returns the newly active tab
178
- pub fn remove ( & mut self , id : u32 ) -> Option < u32 > {
179
- self . history . retain ( |tab_id | * tab_id != id) ;
180
+ /// Returns the newly active view
181
+ pub fn remove ( & mut self , id : usize ) -> Option < usize > {
182
+ self . history . retain ( |view_id | * view_id != id) ;
180
183
181
- self . tabs . retain ( |tab| tab . id != id) ;
184
+ self . views . retain ( |view| view . id != id) ;
182
185
self . get_current_id ( )
183
186
}
184
187
185
- pub fn get_current ( & self ) -> Option < & Tab < Info > > {
188
+ pub fn get_current ( & self ) -> Option < & View < Info > > {
186
189
self . get ( self . get_current_id ( ) ?)
187
190
}
188
191
189
- pub fn get_current_mut ( & mut self ) -> Option < & mut Tab < Info > > {
192
+ pub fn get_current_mut ( & mut self ) -> Option < & mut View < Info > > {
190
193
Some ( self . get_mut ( self . get_current_id ( ) ?) )
191
194
}
192
195
193
- pub fn get ( & self , id : u32 ) -> Option < & Tab < Info > > {
194
- self . tabs . iter ( ) . find ( |& tab| tab . id == id)
196
+ pub fn get ( & self , id : usize ) -> Option < & View < Info > > {
197
+ self . views . iter ( ) . find ( |& view| view . id == id)
195
198
}
196
199
197
- pub fn get_mut ( & mut self , id : u32 ) -> & mut Tab < Info > {
198
- for tab in self . tabs . iter_mut ( ) {
199
- if tab . id == id {
200
- return tab ;
200
+ pub fn get_mut ( & mut self , id : usize ) -> & mut View < Info > {
201
+ for view in self . views . iter_mut ( ) {
202
+ if view . id == id {
203
+ return view ;
201
204
}
202
205
}
203
- panic ! ( "Unable to find Tab with id: {}" , id) ;
206
+ panic ! ( "Unable to find view with id: {}" , id) ;
204
207
}
205
208
}
206
209
207
- /// Allows users to create new tabs with url or custom html
210
+ /// Allows users to create new views with url or custom html
208
211
#[ derive( Clone ) ]
209
212
pub enum PageType {
210
213
Url ( & ' static str ) ,
0 commit comments