@@ -6,7 +6,9 @@ use crate::node::{ImageData, NodeFlags, RasterImageData, SpecialElementData, Sta
6
6
use crate :: stylo_to_cursor_icon:: stylo_to_cursor_icon;
7
7
use crate :: traversal:: TreeTraverser ;
8
8
use crate :: util:: { ImageType , resolve_url} ;
9
- use crate :: { DocumentMutator , ElementData , Node , NodeData , TextNodeData } ;
9
+ use crate :: {
10
+ DEFAULT_CSS , DocumentConfig , DocumentMutator , ElementData , Node , NodeData , TextNodeData ,
11
+ } ;
10
12
use app_units:: Au ;
11
13
use blitz_traits:: devtools:: DevtoolSettings ;
12
14
use blitz_traits:: events:: { DomEvent , HitResult , UiEvent } ;
@@ -187,14 +189,11 @@ impl BaseDocument {
187
189
}
188
190
189
191
impl BaseDocument {
190
- pub fn new ( viewport : Viewport ) -> Self {
191
- Self :: with_font_ctx ( viewport, parley:: FontContext :: default ( ) )
192
- }
193
-
194
- pub fn with_font_ctx ( viewport : Viewport , mut font_ctx : FontContext ) -> Self {
192
+ pub fn new ( config : DocumentConfig ) -> Self {
195
193
static ID_GENERATOR : AtomicUsize = AtomicUsize :: new ( 1 ) ;
196
194
197
195
let id = ID_GENERATOR . fetch_add ( 1 , Ordering :: SeqCst ) ;
196
+ let viewport = config. viewport . unwrap_or_default ( ) ;
198
197
let device = make_device ( & viewport) ;
199
198
let stylist = Stylist :: new ( device, QuirksMode :: NoQuirks ) ;
200
199
let snapshots = SnapshotMap :: new ( ) ;
@@ -209,9 +208,23 @@ impl BaseDocument {
209
208
style_config:: set_bool ( "layout.unimplemented" , true ) ;
210
209
style_config:: set_bool ( "layout.columns.enabled" , true ) ;
211
210
212
- font_ctx
213
- . collection
214
- . register_fonts ( Blob :: new ( Arc :: new ( crate :: BULLET_FONT ) as _ ) , None ) ;
211
+ let font_ctx = config. font_ctx . unwrap_or_else ( || {
212
+ let mut font_ctx = FontContext :: default ( ) ;
213
+ font_ctx
214
+ . collection
215
+ . register_fonts ( Blob :: new ( Arc :: new ( crate :: BULLET_FONT ) as _ ) , None ) ;
216
+ font_ctx
217
+ } ) ;
218
+
219
+ let net_provider = config
220
+ . net_provider
221
+ . unwrap_or_else ( || Arc :: new ( DummyNetProvider ) ) ;
222
+ let navigation_provider = config
223
+ . navigation_provider
224
+ . unwrap_or_else ( || Arc :: new ( DummyNavigationProvider ) ) ;
225
+ let shell_provider = config
226
+ . shell_provider
227
+ . unwrap_or_else ( || Arc :: new ( DummyShellProvider ) ) ;
215
228
216
229
let mut doc = Self {
217
230
id,
@@ -236,15 +249,24 @@ impl BaseDocument {
236
249
is_animating : false ,
237
250
changed_nodes : HashSet :: new ( ) ,
238
251
controls_to_form : HashMap :: new ( ) ,
239
- net_provider : Arc :: new ( DummyNetProvider ) ,
240
- navigation_provider : Arc :: new ( DummyNavigationProvider ) ,
241
- shell_provider : Arc :: new ( DummyShellProvider ) ,
252
+ net_provider,
253
+ navigation_provider,
254
+ shell_provider,
242
255
} ;
243
256
244
257
// Initialise document with root Document node
245
258
doc. create_node ( NodeData :: Document ) ;
246
259
doc. root_node_mut ( ) . flags . insert ( NodeFlags :: IS_IN_DOCUMENT ) ;
247
260
261
+ match config. ua_stylesheets {
262
+ Some ( stylesheets) => {
263
+ for ss in & stylesheets {
264
+ doc. add_user_agent_stylesheet ( ss) ;
265
+ }
266
+ }
267
+ None => doc. add_user_agent_stylesheet ( DEFAULT_CSS ) ,
268
+ }
269
+
248
270
// Stylo data on the root node container is needed to render the node
249
271
let stylo_element_data = StyloElementData {
250
272
styles : ElementStyles {
0 commit comments