Skip to content

Commit 958e7d6

Browse files
committed
feat: Support for the picture element
1 parent fe26a23 commit 958e7d6

7 files changed

Lines changed: 456 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ style_traits = { version = "0.3", package = "stylo_traits" }
3030
style_config = { version = "0.3", package = "stylo_config" }
3131
style_dom = { version = "0.3", package = "stylo_dom" }
3232
selectors = { version = "0.28", package = "selectors" }
33+
cssparser = "0.35"
34+
mime = "0.3"
3335

3436
markup5ever = "0.16.1" # needs to match stylo web_atoms version
3537
html5ever = "0.31" # needs to match stylo web_atoms version

packages/blitz-dom/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ atomic_refcell = { workspace = true, features = ["serde"] }
4040
string_cache = { workspace = true }
4141
markup5ever = { workspace = true }
4242
smallvec = { workspace = true }
43+
cssparser = { workspace = true }
44+
mime = { workspace = true }
4345

4446
# DioxusLabs dependencies
4547
taffy = { workspace = true }

packages/blitz-dom/src/document.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use style::properties::ComputedValues;
2121
use style::properties::style_structs::Font;
2222
use style::values::GenericAtomIdent;
2323
use style::values::computed::Overflow;
24+
use style_traits::ParsingMode;
2425
// use quadtree_rs::Quadtree;
2526
use crate::net::{Resource, StylesheetLoader};
2627
use selectors::{Element, matching::QuirksMode};
@@ -38,9 +39,12 @@ use style::servo_arc::Arc as ServoArc;
3839
use style::{
3940
dom::{TDocument, TNode},
4041
media_queries::{Device, MediaList},
42+
parser::ParserContext,
4143
selector_parser::SnapshotMap,
4244
shared_lock::{SharedRwLock, StylesheetGuards},
43-
stylesheets::{AllowImportRules, DocumentStyleSheet, Origin, Stylesheet, UrlExtraData},
45+
stylesheets::{
46+
AllowImportRules, CssRuleType, DocumentStyleSheet, Origin, Stylesheet, UrlExtraData,
47+
},
4448
stylist::Stylist,
4549
};
4650
use taffy::AvailableSpace;
@@ -1221,6 +1225,46 @@ impl BaseDocument {
12211225
);
12221226
chain
12231227
}
1228+
1229+
pub fn maybe_load_node_resource(&self, target_id: usize) {
1230+
let Some(node) = self.get_node(target_id) else {
1231+
return;
1232+
};
1233+
1234+
let NodeData::Element(el) = &node.data else {
1235+
return;
1236+
};
1237+
1238+
if el.name.local.as_ref() == "img" {
1239+
self.load_image(target_id);
1240+
}
1241+
}
1242+
1243+
/// https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia
1244+
pub fn match_media(&self, media_query_string: &str) -> bool {
1245+
let mut input = cssparser::ParserInput::new(media_query_string);
1246+
let mut parser = cssparser::Parser::new(&mut input);
1247+
1248+
let url_data = UrlExtraData::from(
1249+
self.base_url
1250+
.clone()
1251+
.unwrap_or_else(|| "about:blank".parse::<Url>().unwrap()),
1252+
);
1253+
let quirks_mode = self.stylist.quirks_mode();
1254+
let context = ParserContext::new(
1255+
Origin::Author,
1256+
&url_data,
1257+
Some(CssRuleType::Style),
1258+
ParsingMode::all(),
1259+
quirks_mode,
1260+
Default::default(),
1261+
None,
1262+
None,
1263+
);
1264+
1265+
let media_list = MediaList::parse(&context, &mut parser);
1266+
media_list.evaluate(self.stylist.device(), quirks_mode)
1267+
}
12241268
}
12251269

12261270
impl AsRef<BaseDocument> for BaseDocument {

packages/blitz-dom/src/node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ use url::Url;
3737
use crate::layout::table::TableContext;
3838
use blitz_traits::{BlitzMouseButtonEvent, DomEventData, HitResult};
3939

40+
pub mod image;
41+
4042
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
4143
pub enum DisplayOuter {
4244
Block,

0 commit comments

Comments
 (0)