mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Replace percent_resolved_*
functions with methods
This commit is contained in:
parent
a2c2b294d5
commit
ce7e84be72
3 changed files with 61 additions and 44 deletions
|
@ -21,8 +21,7 @@ use rayon_croissant::ParallelIteratorExt;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use style::computed_values::position::T as Position;
|
use style::computed_values::position::T as Position;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
use style::values::computed::{Length, LengthOrAuto};
|
||||||
use style::values::generics::length::MaxSize;
|
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
|
|
||||||
mod construct;
|
mod construct;
|
||||||
|
@ -365,10 +364,14 @@ fn layout_in_flow_non_replaced_block_level<'a>(
|
||||||
let pb = &padding + &border;
|
let pb = &padding + &border;
|
||||||
let pb_inline_sum = pb.inline_sum();
|
let pb_inline_sum = pb.inline_sum();
|
||||||
|
|
||||||
let box_size = percent_resolved_box_size(style.box_size(), containing_block);
|
let box_size = style.box_size().percentages_relative_to(containing_block);
|
||||||
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
|
let max_box_size = style
|
||||||
let min_box_size =
|
.max_box_size()
|
||||||
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
|
.percentages_relative_to(containing_block);
|
||||||
|
let min_box_size = style
|
||||||
|
.min_box_size()
|
||||||
|
.percentages_relative_to(containing_block)
|
||||||
|
.auto_is(Length::zero);
|
||||||
|
|
||||||
// https://drafts.csswg.org/css2/visudet.html#min-max-widths
|
// https://drafts.csswg.org/css2/visudet.html#min-max-widths
|
||||||
let solve_inline_margins = |inline_size| {
|
let solve_inline_margins = |inline_size| {
|
||||||
|
@ -529,10 +532,14 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
// FIXME(nox): This can divide by zero.
|
// FIXME(nox): This can divide by zero.
|
||||||
let intrinsic_ratio = intrinsic_size.inline.px() / intrinsic_size.block.px();
|
let intrinsic_ratio = intrinsic_size.inline.px() / intrinsic_size.block.px();
|
||||||
|
|
||||||
let box_size = percent_resolved_box_size(style.box_size(), containing_block);
|
let box_size = style.box_size().percentages_relative_to(containing_block);
|
||||||
let min_box_size =
|
let min_box_size = style
|
||||||
percent_resolved_box_size(style.min_box_size(), containing_block).auto_is(Length::zero);
|
.min_box_size()
|
||||||
let max_box_size = percent_resolved_max_box_size(style.max_box_size(), containing_block);
|
.percentages_relative_to(containing_block)
|
||||||
|
.auto_is(Length::zero);
|
||||||
|
let max_box_size = style
|
||||||
|
.max_box_size()
|
||||||
|
.percentages_relative_to(containing_block);
|
||||||
|
|
||||||
let clamp = |inline_size: Length, block_size: Length| {
|
let clamp = |inline_size: Length, block_size: Length| {
|
||||||
(
|
(
|
||||||
|
@ -701,37 +708,3 @@ fn solve_inline_margins_for_in_flow_block_level(
|
||||||
(LengthOrAuto::LengthPercentage(start), _) => (start, inline_margins - start),
|
(LengthOrAuto::LengthPercentage(start), _) => (start, inline_margins - start),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn percent_resolved_box_size(
|
|
||||||
box_size: Vec2<LengthPercentageOrAuto>,
|
|
||||||
containing_block: &ContainingBlock,
|
|
||||||
) -> Vec2<LengthOrAuto> {
|
|
||||||
Vec2 {
|
|
||||||
inline: box_size
|
|
||||||
.inline
|
|
||||||
.percentage_relative_to(containing_block.inline_size),
|
|
||||||
block: box_size
|
|
||||||
.block
|
|
||||||
.maybe_percentage_relative_to(containing_block.block_size.non_auto()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn percent_resolved_max_box_size(
|
|
||||||
max_box_size: Vec2<MaxSize<LengthPercentage>>,
|
|
||||||
containing_block: &ContainingBlock,
|
|
||||||
) -> Vec2<Option<Length>> {
|
|
||||||
Vec2 {
|
|
||||||
inline: match max_box_size.inline {
|
|
||||||
MaxSize::LengthPercentage(max_inline_size) => {
|
|
||||||
Some(max_inline_size.percentage_relative_to(containing_block.inline_size))
|
|
||||||
},
|
|
||||||
MaxSize::None => None,
|
|
||||||
},
|
|
||||||
block: match max_box_size.block {
|
|
||||||
MaxSize::LengthPercentage(max_block_size) => {
|
|
||||||
max_block_size.maybe_percentage_relative_to(containing_block.block_size.non_auto())
|
|
||||||
},
|
|
||||||
MaxSize::None => None,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use crate::ContainingBlock;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::{Add, AddAssign, Sub};
|
use std::ops::{Add, AddAssign, Sub};
|
||||||
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection};
|
use style::logical_geometry::{BlockFlowDirection, InlineBaseDirection};
|
||||||
use style::logical_geometry::{PhysicalCorner, WritingMode};
|
use style::logical_geometry::{PhysicalCorner, WritingMode};
|
||||||
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
use style::values::computed::{Length, LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
||||||
|
use style::values::generics::length::MaxSize;
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
|
|
||||||
|
@ -151,6 +153,39 @@ impl flow_relative::Vec2<LengthOrAuto> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl flow_relative::Vec2<LengthPercentageOrAuto> {
|
||||||
|
pub fn percentages_relative_to(
|
||||||
|
&self,
|
||||||
|
containing_block: &ContainingBlock,
|
||||||
|
) -> flow_relative::Vec2<LengthOrAuto> {
|
||||||
|
flow_relative::Vec2 {
|
||||||
|
inline: self
|
||||||
|
.inline
|
||||||
|
.percentage_relative_to(containing_block.inline_size),
|
||||||
|
block: self
|
||||||
|
.block
|
||||||
|
.maybe_percentage_relative_to(containing_block.block_size.non_auto()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl flow_relative::Vec2<MaxSize<LengthPercentage>> {
|
||||||
|
pub fn percentages_relative_to(
|
||||||
|
&self,
|
||||||
|
containing_block: &ContainingBlock,
|
||||||
|
) -> flow_relative::Vec2<Option<Length>> {
|
||||||
|
flow_relative::Vec2 {
|
||||||
|
inline: self
|
||||||
|
.inline
|
||||||
|
.to_option()
|
||||||
|
.map(|lp| lp.percentage_relative_to(containing_block.inline_size)),
|
||||||
|
block: self.block.to_option().and_then(|olp| {
|
||||||
|
olp.maybe_percentage_relative_to(containing_block.block_size.non_auto())
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl flow_relative::Rect<Length> {
|
impl flow_relative::Rect<Length> {
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
@ -207,6 +207,15 @@ impl<LengthPercentage> MaxSize<LengthPercentage> {
|
||||||
pub fn none() -> Self {
|
pub fn none() -> Self {
|
||||||
MaxSize::None
|
MaxSize::None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert
|
||||||
|
#[cfg(not(feature = "gecko"))]
|
||||||
|
pub fn to_option(self) -> Option<LengthPercentage> {
|
||||||
|
match self {
|
||||||
|
Self::LengthPercentage(lp) => Some(lp),
|
||||||
|
Self::None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic `<length>` | `<number>` value for the `-moz-tab-size` property.
|
/// A generic `<length>` | `<number>` value for the `-moz-tab-size` property.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue