Skip to content

Commit

Permalink
Fixed background color on _override_native stylesheets
Browse files Browse the repository at this point in the history
* { } should be used carefully, since it literally does what it
needs to now: The background color gets set on everything. The
problem was that the * { background-color: white } sets the background
color on literally everything, even on items that are supposed to be
transparent.

More or less the "bug" was that * { } didn't work correctly before
(and now it does).
  • Loading branch information
fschutt committed Nov 18, 2018
1 parent f65fa2c commit 3553358
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
52 changes: 29 additions & 23 deletions src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,31 +762,37 @@ pub(crate) fn match_dom_css_selectors<T: Layout>(
parent_rules.css_constraints.list.extend(applying_rule.declarations.clone());
}

let inheritable_rules = CssConstraintList {
list: parent_rules.css_constraints.list.iter().filter(|prop| prop.is_inheritable()).cloned().collect(),
};

// For children: inherit from parents - filter children that themselves are parents!
for (child_idx, child_id) in parent_id.children(arena_borrow).enumerate().filter(|(_, child_id)| arena_borrow[*child_id].first_child().is_none()) {

// Style children that themselves aren't parents
let child_html_matcher = HtmlCascadeInfo {
node_data: &arena_borrow[child_id].data,
index_in_parent: child_idx, // necessary for nth-child
is_mouse_over: false, // TODO
is_mouse_pressed: false, // TODO
};

let mut child_rules = inheritable_rules.clone();
let inheritable_rules: Vec<CssDeclaration> = parent_rules.css_constraints.list.iter().filter(|prop| prop.is_inheritable()).cloned().collect();

// For children: inherit from parents - filter children that themselves are not parents!
for (child_idx, child_id) in parent_id.children(arena_borrow).enumerate() {
let child_node = &arena_borrow[child_id];
match child_node.first_child() {
None => {
// Style children that themselves aren't parents
let mut child_rules = inheritable_rules.clone();

let child_html_matcher = HtmlCascadeInfo {
node_data: &child_node.data,
index_in_parent: child_idx + 1, // necessary for nth-child
is_mouse_over: false, // TODO
is_mouse_pressed: false, // TODO
};

// Iterate through all rules in the CSS style sheet, test if the
// This is technically O(n ^ 2), however, there are usually not that many CSS blocks,
// so the cost of this should be insignificant.
for applying_rule in css.rules.iter().filter(|rule| rule.path.matches_html_element(&child_html_matcher)) {
child_rules.extend(applying_rule.declarations.clone());
}

// Iterate through all rules in the CSS style sheet, test if the
// This is technically O(n ^ 2), however, there are usually not that many CSS blocks,
// so the cost of this should be insignificant.
for applying_rule in css.rules.iter().filter(|rule| rule.path.matches_html_element(&child_html_matcher)) {
child_rules.list.extend(applying_rule.declarations.clone());
styled_nodes.insert(child_id, StyledNode { css_constraints: CssConstraintList { list: child_rules }});
},
Some(_) => {
// For all children that themselves are parents, simply copy the inheritable rules
styled_nodes.insert(child_id, StyledNode { css_constraints: CssConstraintList { list: inheritable_rules.clone() } });
},
}

styled_nodes.insert(child_id, StyledNode { css_constraints: child_rules });
}

styled_nodes.insert(parent_id, parent_rules);
Expand Down
1 change: 1 addition & 0 deletions src/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ fn displaylist_handle_rect<'a,'b,'c,'d,'e,'f, T: Layout>(
referenced_mutable_content.builder.push_clip_id(id);
}


// If the rect is hit-testing relevant, we need to push a rect anyway. Otherwise the hit-testing gets confused
if let Some(bg_col) = &rect.style.background_color {
// The background color won't be seen anyway, so don't push a
Expand Down
2 changes: 2 additions & 0 deletions src/styles/native_linux.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
* {
font-size: 12px;
font-family: sans-serif;
/*
color: #4c4c4c;
background-color: #e7e7e7;
*/
}

.__azul-native-button {
Expand Down
6 changes: 4 additions & 2 deletions src/styles/native_macos.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
* {
font-size: 12px;
font-family: sans-serif;
color: #4c4c4c;
background-color: #e7e7e7;
}

.__azul-native-button {
/*
color: #4c4c4c;
background-color: #e7e7e7;
*/
border: 1px solid #b7b7b7;
border-radius: 4px;
box-shadow: 0px 0px 3px #c5c5c5ad;
Expand Down
3 changes: 2 additions & 1 deletion src/styles/native_windows.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
* {
font-size: 14.66px;
font-family: sans-serif;
/*
color: #000;
background-color: #f0f0f0; /* Windows Background color, rgb(240, 240, 240) */
background-color: #f0f0f0; Windows Background color, rgb(240, 240, 240) */
}

.__azul-native-button {
Expand Down

0 comments on commit 3553358

Please sign in to comment.