Skip to content

Commit f217333

Browse files
committed
fix: text-slot bug in testing framework
1 parent 45d8f43 commit f217333

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

float-pigment-css/src/property.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ property_list! (PropertyValueWithGlobal, {
166166
0xa3 TextDecorationThickness: TextDecorationThicknessType as Initial default TextDecorationThickness::Auto;
167167
0xa4 FontFeatureSettings: FontFeatureSettingsType as Inherit default FontFeatureSettings::Normal;
168168

169+
// grid
170+
0xa5 GridTemplateRows: GridTemplateRowsType as Initial default GridTemplateRows::None;
171+
169172
0xd0 ListStyleType: ListStyleTypeType as Inherit default ListStyleType::Disc;
170173
0xd1 ListStyleImage: ListStyleImageType as Inherit default ListStyleImage::None;
171174
0xd2 ListStylePosition: ListStylePositionType as Inherit default ListStylePosition::Outside;
@@ -1657,6 +1660,12 @@ property_value_format! (PropertyValueWithGlobal, {
16571660
)
16581661
};
16591662
}};
1663+
1664+
// grid_template_rows: {{ GridTemplateRows
1665+
// = "none" => GridTemplateRows::None
1666+
// | <track_list>
1667+
// | <auto_track_list>
1668+
// }};
16601669
});
16611670

16621671
pub(crate) fn split_hv<T: Clone>(x: Vec<T>) -> (T, T) {

float-pigment-css/src/typing.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub enum Color {
134134
Specified(u8, u8, u8, u8),
135135
}
136136

137-
/// A length value or an expression that evaluates to a langth value.
137+
/// A length value or an expression that evaluates to a length value.
138138
#[allow(missing_docs)]
139139
#[repr(C)]
140140
#[property_value_type(PropertyValueWithGlobal for LengthType)]
@@ -1796,3 +1796,14 @@ pub enum Gap {
17961796
#[resolve_font_size(Length::resolve_em)]
17971797
Length(Length),
17981798
}
1799+
1800+
/// The `grid-template-rows` property defines the line names and track sizing functions of the grid rows.
1801+
#[allow(missing_docs)]
1802+
#[repr(C)]
1803+
#[property_value_type(PropertyValueWithGlobal for GridTemplateRowsType)]
1804+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ResolveFontSize)]
1805+
#[cfg_attr(debug_assertions, derive(CompatibilityEnumCheck))]
1806+
pub enum GridTemplateRows {
1807+
/// A keyword meaning that there is no explicit grid
1808+
None,
1809+
}

float-pigment-css/src/typing_stringify.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,3 +2336,11 @@ impl fmt::Display for Gap {
23362336
}
23372337
}
23382338
}
2339+
2340+
impl fmt::Display for GridTemplateRows {
2341+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2342+
match self {
2343+
GridTemplateRows::None => write!(f, "none"),
2344+
}
2345+
}
2346+
}

float-pigment-forest/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ impl Node {
315315
pub(crate) unsafe fn baseline_func(&self) -> Option<&BaselineFn<Len>> {
316316
(*self.baseline_func.get()).as_deref()
317317
}
318-
pub unsafe fn set_baseline_func(&self, baseline_func: Option<Box<BaselineFn<Len>>>) {
318+
pub fn set_baseline_func(&self, baseline_func: Option<Box<BaselineFn<Len>>>) {
319319
drop(std::mem::replace(
320-
&mut *self.baseline_func.get(),
320+
unsafe { &mut *self.baseline_func.get() },
321321
baseline_func,
322322
));
323323
}

float-pigment-forest/tests/custom/css_margin.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,20 @@ fn margin_collapse_between_sibling_and_empty_block_4() {
365365
)
366366
}
367367

368+
#[test]
369+
fn margin_collapse_between_sibling_and_empty_block_5() {
370+
assert_xml!(
371+
r#"
372+
<div style="height: 300px;">
373+
<div style="height: 30px; margin-bottom: 50px" expect_height="30" expect_top="0"></div>
374+
<text-slot len="0"></text-slot>
375+
<div style="height: 30px; margin-top: 100px" expect_height="30" expect_top="130"></div>
376+
</div>
377+
"#,
378+
true
379+
)
380+
}
381+
368382
#[test]
369383
fn margin_collapse_between_parent_and_empty_block_1() {
370384
assert_xml!(

float-pigment-forest/tests/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ impl TextInfo {
125125
max_content_height: Len,
126126
) -> Size<Len> {
127127
let text_len = self.text_len;
128+
if text_len == 0 {
129+
println!(
130+
"text_info: {self:?}, width: {min_width:?} ~ {max_width:?}, height: {min_height:?} ~ {max_height:?}, max_content_width: {max_content_width:?}, max_content_height: {max_content_height:?}, measured_width: 0, measured_height: 0",
131+
);
132+
return Size::new(Len::zero(), Len::zero());
133+
}
128134
let text_width = self.font_size * text_len as f32;
129135
let max_w = max_width.min(max_content_width);
130136
let max_h = max_height.min(max_content_height);
@@ -188,6 +194,11 @@ fn convert_font_size_to_px(font_size: float_pigment_css::typing::Length) -> f32
188194
#[inline(always)]
189195
fn prepare_measure_node(node: *mut Node, text_info: TextInfo) {
190196
let node = unsafe { &mut *node };
197+
unsafe {
198+
node.set_display(Display::Inline);
199+
node.set_node_type(float_pigment_forest::NodeType::Text);
200+
}
201+
node.set_baseline_func(Some(Box::new(|_, _, _| Len::from_f32(16.))));
191202
node.set_measure_func(Some(Box::new(
192203
move |_,
193204
max_width,
@@ -208,11 +219,6 @@ fn prepare_measure_node(node: *mut Node, text_info: TextInfo) {
208219
)
209220
},
210221
)));
211-
unsafe {
212-
node.set_display(Display::Inline);
213-
node.set_baseline_func(Some(Box::new(|_, _, _| Len::from_f32(16.))));
214-
node.set_node_type(float_pigment_forest::NodeType::Text);
215-
}
216222
}
217223

218224
impl TestCtx {
@@ -385,7 +391,6 @@ impl TestCtx {
385391
self.set_expect_layout_pos(node, e.attributes());
386392

387393
if is_measure_text_slot(e.tag()) {
388-
let node = Node::new_ptr();
389394
let text_len = e
390395
.attributes()
391396
.get("len")

0 commit comments

Comments
 (0)