mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Rename the MinMaxConstraint to SizeConstraint and enhancement
Renamed to `SizeConstraint`, add an optional `border` parameter to deal with `box-sizing: border-box`, and fix its bug when involving with `calc`.
This commit is contained in:
parent
b9a8ccd775
commit
39780e894b
3 changed files with 66 additions and 49 deletions
|
@ -23,7 +23,7 @@ use inline::{InlineMetrics, LAST_FRAGMENT_OF_ELEMENT, LineMetrics};
|
|||
use ipc_channel::ipc::IpcSender;
|
||||
#[cfg(debug_assertions)]
|
||||
use layout_debug;
|
||||
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto};
|
||||
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, SizeConstraint};
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::image::base::{Image, ImageMetadata};
|
||||
use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
|
||||
|
@ -1202,6 +1202,27 @@ impl Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Return a size constraint that can be used the clamp size in given direction.
|
||||
/// To take `box-sizing: border-box` into account, the `border_padding` field
|
||||
/// must be initialized first.
|
||||
///
|
||||
/// TODO(stshine): Maybe there is a more convenient way.
|
||||
pub fn size_constraint(&self, containing_size: Option<Au>, direction: Direction) -> SizeConstraint {
|
||||
let (style_min_size, style_max_size) = match direction {
|
||||
Direction::Inline => (self.style.min_inline_size(), self.style.max_inline_size()),
|
||||
Direction::Block => (self.style.min_block_size(), self.style.max_block_size())
|
||||
};
|
||||
|
||||
let border = if self.style().get_position().box_sizing == box_sizing::T::border_box {
|
||||
Some(self.border_padding.start_end(direction))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
SizeConstraint::new(containing_size, style_min_size, style_max_size, border)
|
||||
}
|
||||
|
||||
/// Returns a guess as to the distances from the margin edge of this fragment to its content
|
||||
/// in the inline direction. This will generally be correct unless percentages are involved.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue