mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Implement Calc for LengthOrPercentage
This commit is contained in:
parent
fa5ad1c6b4
commit
9556141e57
6 changed files with 165 additions and 13 deletions
|
@ -331,9 +331,8 @@ impl CandidateBSizeIterator {
|
|||
(LengthOrPercentageOrAuto::Length(length), _) => MaybeAuto::Specified(length),
|
||||
};
|
||||
let max_block_size = match (fragment.style.max_block_size(), block_container_block_size) {
|
||||
(LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) => {
|
||||
Some(block_container_block_size.scale_by(percent))
|
||||
}
|
||||
(LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) =>
|
||||
Some(block_container_block_size.scale_by(percent)),
|
||||
(LengthOrPercentageOrNone::Percentage(_), None) |
|
||||
(LengthOrPercentageOrNone::None, _) => None,
|
||||
(LengthOrPercentageOrNone::Length(length), _) => Some(length),
|
||||
|
@ -342,6 +341,10 @@ impl CandidateBSizeIterator {
|
|||
(LengthOrPercentage::Percentage(percent), Some(block_container_block_size)) => {
|
||||
block_container_block_size.scale_by(percent)
|
||||
}
|
||||
(LengthOrPercentage::Calc(calc), Some(block_container_block_size)) => {
|
||||
calc.length() + block_container_block_size.scale_by(calc.percentage())
|
||||
}
|
||||
(LengthOrPercentage::Calc(calc), None) => calc.length(),
|
||||
(LengthOrPercentage::Percentage(_), None) => Au(0),
|
||||
(LengthOrPercentage::Length(length), _) => length,
|
||||
};
|
||||
|
|
|
@ -1955,6 +1955,8 @@ fn position_to_offset(position: LengthOrPercentage, Au(total_length): Au) -> f32
|
|||
fmin(1.0, (length as f32) / (total_length as f32))
|
||||
}
|
||||
LengthOrPercentage::Percentage(percentage) => percentage as f32,
|
||||
LengthOrPercentage::Calc(calc) =>
|
||||
fmin(1.0, calc.percentage() + (calc.length().0 as f32) / (total_length as f32)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -988,7 +988,12 @@ impl InlineFlow {
|
|||
let percent_offset = line_height.scale_by(p);
|
||||
offset_from_baseline = offset_from_baseline - percent_offset
|
||||
}
|
||||
}
|
||||
vertical_align::T::Calc(calc) => {
|
||||
let line_height = fragment.calculate_line_height(layout_context);
|
||||
let percent_offset = line_height.scale_by(calc.percentage());
|
||||
offset_from_baseline = offset_from_baseline - percent_offset - calc.length()
|
||||
}
|
||||
}
|
||||
}
|
||||
(offset_from_baseline - ascent, largest_size_updated)
|
||||
}
|
||||
|
|
|
@ -416,7 +416,9 @@ pub fn specified_or_none(length: LengthOrPercentageOrNone, containing_length: Au
|
|||
pub fn specified(length: LengthOrPercentage, containing_length: Au) -> Au {
|
||||
match length {
|
||||
LengthOrPercentage::Length(length) => length,
|
||||
LengthOrPercentage::Percentage(p) => containing_length.scale_by(p)
|
||||
LengthOrPercentage::Percentage(p) => containing_length.scale_by(p),
|
||||
LengthOrPercentage::Calc(calc) =>
|
||||
containing_length.scale_by(calc.percentage()) + calc.length(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue