mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #16541 - sbwtw:fix_calc_behavior, r=stshine
Add calc method for CalcLengthOrPercentage * Add calc method to calculate formula value with parent size * Add unit test case <!-- Please describe your changes on the following line: --> Please see this issue: https://github.com/servo/servo/issues/15986 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #15986 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16541) <!-- Reviewable:end -->
This commit is contained in:
commit
418c3e8cc7
8 changed files with 47 additions and 32 deletions
|
@ -76,6 +76,16 @@ impl CalcLengthOrPercentage {
|
|||
pub fn percentage(&self) -> CSSFloat {
|
||||
self.percentage.unwrap_or(0.)
|
||||
}
|
||||
|
||||
/// If there are special rules for computing percentages in a value (e.g. the height property),
|
||||
/// they apply whenever a calc() expression contains percentages.
|
||||
pub fn to_computed(&self, container_len: Option<Au>) -> Option<Au> {
|
||||
match (container_len, self.percentage) {
|
||||
(Some(len), Some(percent)) => Some(self.length + len.scale_by(percent)),
|
||||
(_, None) => Some(self.length),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LengthOrPercentage> for CalcLengthOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue