Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 22 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ browser-persistence = { path = "./apps/browser/persistence" }
blitz-test-harness = { path = "./packages/blitz-test-harness" }

# Servo dependencies
style = { version = "0.20.0", package = "stylo" }
style_traits = { version = "0.20.0", package = "stylo_traits" }
style_atoms = { version = "0.20.0", package = "stylo_atoms" }
style_config = { version = "0.20.0", package = "stylo_static_prefs" }
style_dom = { version = "0.20.0", package = "stylo_dom" }
selectors = { version = "0.40.0", package = "selectors" }
style = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "stylo" }
style_traits = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "stylo_traits" }
style_atoms = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "stylo_atoms" }
style_config = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "stylo_static_prefs" }
style_dom = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "stylo_dom" }
selectors = { git = "https://github.com/DioxusLabs/stylo", rev = "d14e3b8f32ad5eaea1c54bb7855dbf63ac0d8b0f", package = "selectors" }
cssparser = { version = "0.37.0" }

# HTML5ever dependencies
Expand Down
49 changes: 49 additions & 0 deletions examples/assets/line_clamp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: sans-serif;
font-size: 16px;
line-height: 24px;
margin: 16px;
}
div {
width: 300px;
background: #cfe8ff;
margin-bottom: 16px;
}
.clamp-2 {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.clamp-3-visible {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
}
</style>
</head>
<body>
<div class="clamp-2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</div>
<div class="clamp-3-visible">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat.
</div>
</body>
</html>
27 changes: 27 additions & 0 deletions packages/blitz-dom/src/layout/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,33 @@ impl BaseDocument {
#[allow(unused_mut)]
let mut height = inline_layout.layout.height();

// Legacy `-webkit-line-clamp`: clamp the content height to the bottom of the
// Nth line box. Lines after the Nth do not contribute to the content height
// (they are clipped by `overflow: hidden` in the classic recipe).
//
// The clamp only applies when the full legacy recipe is present:
// `display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: N`.
// Stylo's style adjuster detects that combination and adjusts the computed
// display to `flow-root` (or `inline-block`), leaving `original_display` as
// `-webkit-box`. So the clamp applies iff the original display was
// `-webkit-box` and the adjustment fired (computed display differs).
let line_clamp = self.nodes[node_id].primary_styles().and_then(|styles| {
use style::values::specified::box_::DisplayInside;
let box_style = styles.get_box();
let clamp = box_style.clone__webkit_line_clamp();
let is_legacy_webkit_box = box_style.original_display.inside()
== DisplayInside::WebkitBox
&& box_style.display.inside() != DisplayInside::WebkitBox;
(!clamp.is_none() && is_legacy_webkit_box).then(|| clamp.0.max(0) as usize)
});
if let Some(max_lines) = line_clamp {
if inline_layout.layout.len() > max_lines {
if let Some(line) = inline_layout.layout.get(max_lines.saturating_sub(1)) {
height = height.min(line.metrics().block_max_coord);
}
}
}

// HACK. TODO: fix in Parley.
//
// A forced line break (e.g. `<br>` or a preserved newline) at the end of the
Expand Down
3 changes: 2 additions & 1 deletion packages/blitz-dom/src/layout/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ pub(crate) fn collect_table_cells(
DisplayInside::Flow
| DisplayInside::FlowRoot
| DisplayInside::Flex
| DisplayInside::Grid => {
| DisplayInside::Grid
| DisplayInside::WebkitBox => {
node.remove_damage(CONSTRUCT_DESCENDENT | CONSTRUCT_FC | CONSTRUCT_BOX);
// Probably a table caption: ignore
// println!(
Expand Down
5 changes: 4 additions & 1 deletion packages/blitz-dom/src/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ impl Node {
let prefer_layout_children = match self.display_constructed_as().inside() {
DisplayInside::None => return false,
DisplayInside::Contents => false,
DisplayInside::Flow | DisplayInside::FlowRoot | DisplayInside::TableCell => {
DisplayInside::Flow
| DisplayInside::FlowRoot
| DisplayInside::TableCell
| DisplayInside::WebkitBox => {
// Prefer layout children for "block" but not "inline" contexts
self.element_data()
.is_none_or(|el| el.inline_layout_data.is_none())
Expand Down
Loading