Skip to content

Commit

Permalink
chore(innate): prep layout nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 7, 2023
1 parent 8b6270a commit 7d9c75b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 104 deletions.
2 changes: 1 addition & 1 deletion kayle_innate/kayle_innate/src/engine/audit/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'a> Auditor<'a> {
console_log!("StyleSheets Build Time {:?}", now() - tt);

let t = now();
let tree = parse_accessibility_tree(&document);
let tree = parse_accessibility_tree(&document, &author);
console_log!("Tree Build Time {:?}", now() - t);

Auditor {
Expand Down
12 changes: 7 additions & 5 deletions kayle_innate/kayle_innate/src/engine/audit/tree.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use scraper_forky::{ElementRef, Selector};
use scraper_forky::ElementRef;
use victor_tree::style::StyleSet;
use scraper_forky::Html;
use std::collections::BTreeMap;

/// try to fix all possible issues using a spec against the tree.
pub fn parse_accessibility_tree(
html: &scraper_forky::Html,
// css_rules: &str,
pub fn parse_accessibility_tree<'a, 'b>(
html: &'a Html,
_author: &StyleSet,
// todo: return the nodes with a tuple of the layout node and the element node
) -> std::collections::BTreeMap<&str, Vec<ElementRef<'_>>> {
) -> std::collections::BTreeMap<&'a str, Vec<ElementRef<'a>>> {
// use taffy::prelude::*;
// // todo: use optional variable for clips or layout creation
// let mut taffy = Taffy::new();
Expand Down
89 changes: 1 addition & 88 deletions kayle_innate/kayle_innate/src/engine/styles/mod.rs
Original file line number Diff line number Diff line change
@@ -1,90 +1,3 @@
pub mod css_cache;
pub mod errors;
pub mod rules;

use crate::console_log;
use cssparser::{Parser, ParserInput};
use markup5ever::local_name;
use markup5ever::namespace_url;
use markup5ever::ns;
use scraper_forky::selector::Simple;
use scraper_forky::{ElementRef, Html};
use selectors::matching::MatchingContext;
use std::sync::Arc;
use victor_tree::style::cascade::USER_AGENT_STYLESHEET;
use victor_tree::style::declaration_block::DeclarationBlock;
use victor_tree::style::values::{Direction, WritingMode};
use victor_tree::style::{ComputedValues, StyleSet};

/// get the style for an element
pub fn style_for_element<'a>(
author: &StyleSet,
_document: &Html,
node: ElementRef<'a>,
parent_style: Option<&ComputedValues>,
match_context: &mut MatchingContext<'_, Simple>,
) -> Arc<ComputedValues> {
use smallvec::SmallVec;
let style_attr_block;
let mut matching = victor_tree::style::cascade::MatchingDeclarations {
ua: SmallVec::new(),
author: SmallVec::new(),
};

// let mut nth_index_cache = selectors::NthIndexCache::from(Default::default());
// let mut match_context = selectors::matching::MatchingContext::new(
// selectors::matching::MatchingMode::Normal,
// None,
// Some(&mut nth_index_cache),
// selectors::matching::QuirksMode::NoQuirks,
// // selectors::matching::NeedsSelectorFlags::No,
// // selectors::matching::IgnoreNthChildForInvalidation::No,
// );

for &(ref selector, ref block) in &USER_AGENT_STYLESHEET.rules {
if selectors::matching::matches_selector(
selector,
0,
None,
&node,
match_context,
&mut |_, _| {},
) {
matching.ua.push(block)
}
}

// push author style sheet
for &(ref selector, ref block) in &author.rules {
if selectors::matching::matches_selector(
selector,
0,
None,
&node,
match_context,
&mut |_, _| {},
) {
matching.author.push(block)
}
}

if let ns!(html) | ns!(svg) | ns!(mathml) = node.value().name.ns {
if let Some(style_attr) = node.value().attr(&local_name!("style")) {
let mut input = ParserInput::new(style_attr);
let mut parser = Parser::new(&mut input);
style_attr_block = DeclarationBlock::parse(&mut parser);
matching.author.push(&style_attr_block);
}
}

let styles = ComputedValues::new(parent_style, Some(&matching));

console_log!(
"{:?}",
styles
.box_size()
.size_to_physical((WritingMode::SidewaysLr, Direction::Ltr))
);

styles
}
pub mod rules;
10 changes: 0 additions & 10 deletions kayle_innate/kayle_victor/victor/src/main.rs

This file was deleted.

0 comments on commit 7d9c75b

Please sign in to comment.