mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Implement max-width, min-width for BlockFlow.
This commit is contained in:
parent
d73fc68209
commit
ce6a3ec4bd
2 changed files with 45 additions and 8 deletions
|
@ -9,7 +9,7 @@ use layout::context::LayoutContext;
|
||||||
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData};
|
use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData};
|
||||||
use layout::flow::{BlockFlowClass, FlowClass, FlowContext, FlowData, ImmutableFlowUtils};
|
use layout::flow::{BlockFlowClass, FlowClass, FlowContext, FlowData, ImmutableFlowUtils};
|
||||||
use layout::flow;
|
use layout::flow;
|
||||||
use layout::model::{MaybeAuto, Specified, Auto};
|
use layout::model::{MaybeAuto, Specified, Auto, specified_or_none, specified};
|
||||||
use layout::float_context::{FloatContext, Invalid};
|
use layout::float_context::{FloatContext, Invalid};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -391,16 +391,41 @@ impl FlowContext for BlockFlow {
|
||||||
let margin_bottom = MaybeAuto::from_style(style.Margin.margin_bottom,
|
let margin_bottom = MaybeAuto::from_style(style.Margin.margin_bottom,
|
||||||
remaining_width).specified_or_zero();
|
remaining_width).specified_or_zero();
|
||||||
|
|
||||||
let (width, margin_left, margin_right) =
|
let (width, maybe_margin_left, maybe_margin_right) =
|
||||||
(MaybeAuto::from_style(style.Box.width, remaining_width),
|
(MaybeAuto::from_style(style.Box.width, remaining_width),
|
||||||
MaybeAuto::from_style(style.Margin.margin_left, remaining_width),
|
MaybeAuto::from_style(style.Margin.margin_left, remaining_width),
|
||||||
MaybeAuto::from_style(style.Margin.margin_right, remaining_width));
|
MaybeAuto::from_style(style.Margin.margin_right, remaining_width));
|
||||||
|
|
||||||
let (width, margin_left, margin_right) = self.compute_horiz(width,
|
let (width, margin_left, margin_right) = self.compute_horiz(width,
|
||||||
margin_left,
|
maybe_margin_left,
|
||||||
margin_right,
|
maybe_margin_right,
|
||||||
available_width);
|
available_width);
|
||||||
|
|
||||||
|
// If the tentative used width is greater than 'max-width', width should be recalculated,
|
||||||
|
// but this time using the computed value of 'max-width' as the computed value for 'width'.
|
||||||
|
let (width, margin_left, margin_right) = {
|
||||||
|
match specified_or_none(style.Box.max_width, remaining_width) {
|
||||||
|
Some(value) if value < width => self.compute_horiz(Specified(value),
|
||||||
|
maybe_margin_left,
|
||||||
|
maybe_margin_right,
|
||||||
|
available_width),
|
||||||
|
_ => (width, margin_left, margin_right)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// If the resulting width is smaller than 'min-width', width should be recalculated,
|
||||||
|
// but this time using the value of 'min-width' as the computed value for 'width'.
|
||||||
|
let (width, margin_left, margin_right) = {
|
||||||
|
let computed_min_width = specified(style.Box.min_width, remaining_width);
|
||||||
|
if computed_min_width > width {
|
||||||
|
self.compute_horiz(Specified(computed_min_width),
|
||||||
|
maybe_margin_left,
|
||||||
|
maybe_margin_right,
|
||||||
|
available_width)
|
||||||
|
} else {
|
||||||
|
(width, margin_left, margin_right)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
model.margin.top = margin_top;
|
model.margin.top = margin_top;
|
||||||
model.margin.right = margin_right;
|
model.margin.right = margin_right;
|
||||||
model.margin.bottom = margin_bottom;
|
model.margin.bottom = margin_bottom;
|
||||||
|
|
|
@ -104,9 +104,21 @@ impl BoxModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_padding_length(&self, padding: computed::LengthOrPercentage, content_box_width: Au) -> Au {
|
pub fn compute_padding_length(&self, padding: computed::LengthOrPercentage, content_box_width: Au) -> Au {
|
||||||
match padding {
|
specified(padding, content_box_width)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn specified_or_none(length: computed::LengthOrPercentageOrNone, containing_length: Au) -> Option<Au> {
|
||||||
|
match length {
|
||||||
|
computed::LPN_None => None,
|
||||||
|
computed::LPN_Percentage(percent) => Some(containing_length.scale_by(percent)),
|
||||||
|
computed::LPN_Length(length) => Some(length),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn specified(length: computed::LengthOrPercentage, containing_length: Au) -> Au {
|
||||||
|
match length {
|
||||||
computed::LP_Length(length) => length,
|
computed::LP_Length(length) => length,
|
||||||
computed::LP_Percentage(p) => content_box_width.scale_by(p)
|
computed::LP_Percentage(p) => containing_length.scale_by(p)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue