Skip to content

Commit

Permalink
fix compile (except tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharktheone committed Sep 16, 2024
1 parent d30ccd6 commit 4e962cd
Show file tree
Hide file tree
Showing 18 changed files with 494 additions and 248 deletions.
7 changes: 4 additions & 3 deletions crates/gosub_css3/src/matcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod functions;
mod property_definitions;
mod shorthands;
mod styling;
mod syntax;
mod syntax_matcher;
mod shorthands;
mod property_definitions;
mod walker;
mod styling;
14 changes: 10 additions & 4 deletions crates/gosub_css3/src/matcher/functions/attr.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use gosub_css3::stylesheet::CssValue;
use gosub_html5::node::Node;
use crate::stylesheet::CssValue;
use gosub_shared::traits::css3::CssSystem;
use gosub_shared::traits::node::{ElementDataType, Node};

pub fn resolve_attr(values: &[CssValue], node: &Node) -> Vec<CssValue> {
// Probably this shouldn't quite be in gosub_css3
pub fn resolve_attr<N: Node<C>, C: CssSystem>(values: &[CssValue], node: &N) -> Vec<CssValue> {
let Some(attr_name) = values.first().map(|v| v.to_string()) else {
return vec![];
};

let ty = values.get(1).cloned();

let Some(attr_value) = node.get_attribute(&attr_name) else {
let Some(data) = node.get_element_data() else {
return vec![];
};

let Some(attr_value) = data.attribute(&attr_name) else {
let _default_value = values.get(2).cloned();

if let Some(ty) = ty {
Expand Down
2 changes: 1 addition & 1 deletion crates/gosub_css3/src/matcher/functions/calc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gosub_css3::stylesheet::CssValue;
use crate::stylesheet::CssValue;

pub fn resolve_calc(_values: &[CssValue]) -> Vec<CssValue> {
todo!()
Expand Down
19 changes: 14 additions & 5 deletions crates/gosub_css3/src/matcher/functions/var.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
use std::collections::HashMap;

use gosub_css3::stylesheet::CssValue;
use gosub_html5::node::Node;
use gosub_html5::parser::document::Document;
use crate::stylesheet::CssValue;
use gosub_shared::traits::css3::CssSystem;
use gosub_shared::traits::document::Document;

#[derive(Clone, Debug, Default)]
pub struct VariableEnvironment {
pub values: HashMap<String, CssValue>,
}

impl VariableEnvironment {
pub fn get(&self, name: &str, _doc: &Document, _node: &Node) -> Option<CssValue> {
pub fn get<D: Document<C>, C: CssSystem>(
&self,
name: &str,
_doc: &D,
_node: &D::Node,
) -> Option<CssValue> {
let mut current = Some(self);

while let Some(env) = current {
Expand All @@ -29,7 +34,11 @@ impl VariableEnvironment {
}
}

pub fn resolve_var(values: &[CssValue], doc: &Document, node: &Node) -> Vec<CssValue> {
pub fn resolve_var<D: Document<C>, C: CssSystem>(
values: &[CssValue],
doc: &D,
node: &D::Node,
) -> Vec<CssValue> {
let Some(name) = values.first().map(|v| {
let mut str = v.to_string();

Expand Down
30 changes: 19 additions & 11 deletions crates/gosub_html5/src/document/builder.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
use std::collections::HashMap;

use url::Url;
use gosub_shared::traits::css3::CssSystem;
use url::Url;

use gosub_shared::traits::document::{Document, DocumentType};
use gosub_shared::traits::node::{Node, QuirksMode};
use crate::document::document::DocumentImpl;
use crate::DocumentHandle;
use crate::node::HTML_NAMESPACE;
use crate::DocumentHandle;
use gosub_shared::traits::document::{Document, DocumentType};
use gosub_shared::traits::node::{Node, QuirksMode};

/// This struct will be used to create a fully initialized document or document fragment
pub struct DocumentBuilder {}

impl<C: CssSystem> gosub_shared::traits::document::DocumentBuilder<C> for DocumentBuilder {

type Document = DocumentImpl<C>;


/// Creates a new document with a document root node
fn new_document(url: Option<Url>) -> DocumentHandle<Self::Document, C> {
let doc = <Self::Document as Document<C>>::new(DocumentType::HTML, url, None);
DocumentHandle::create(doc)
}

/// Creates a new document fragment with the context as the root node
fn new_document_fragment(context_node: &<Self::Document as Document<C>>::Node) -> DocumentHandle<Self::Document, C> {
fn new_document_fragment(
context_node: &<Self::Document as Document<C>>::Node,
) -> DocumentHandle<Self::Document, C> {
let handle = context_node.handle();

// Create a new document with an HTML node as the root node
Expand All @@ -35,20 +35,28 @@ impl<C: CssSystem> gosub_shared::traits::document::DocumentBuilder<C> for Docume
HashMap::new(),
context_node.location().clone(),
);
let fragment_doc = <Self::Document as Document<C>>::new(DocumentType::HTML, None, Some(&fragment_root_node));
let fragment_doc = <Self::Document as Document<C>>::new(
DocumentType::HTML,
None,
Some(fragment_root_node),
);
let mut fragment_handle = DocumentHandle::create(fragment_doc);

let context_doc_handle = context_node.handle();
match context_doc_handle.get().quirks_mode() {
QuirksMode::Quirks => {
fragment_handle.get_mut().set_quirks_mode(QuirksMode::Quirks);
fragment_handle
.get_mut()
.set_quirks_mode(QuirksMode::Quirks);
}
QuirksMode::LimitedQuirks => {
fragment_handle.get_mut().set_quirks_mode(QuirksMode::LimitedQuirks);
fragment_handle
.get_mut()
.set_quirks_mode(QuirksMode::LimitedQuirks);
}
_ => {}
}

fragment_handle
}
}
}
Loading

0 comments on commit 4e962cd

Please sign in to comment.