mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: Fix container query evaluation on unsupported axis
We were falling back to viewport size, which is not what the spec says. Differential Revision: https://phabricator.services.mozilla.com/D161132
This commit is contained in:
parent
aba0a4bce0
commit
81ae588ec9
3 changed files with 47 additions and 35 deletions
|
@ -261,51 +261,44 @@ pub struct ContainerInfo {
|
|||
wm: WritingMode,
|
||||
}
|
||||
|
||||
fn get_container(context: &Context) -> ContainerInfo {
|
||||
if let Some(ref info) = context.container_info {
|
||||
return info.clone();
|
||||
}
|
||||
ContainerInfo {
|
||||
size: context.device().au_viewport_size(),
|
||||
wm: WritingMode::horizontal_tb(),
|
||||
}
|
||||
fn eval_width(context: &Context) -> Option<CSSPixelLength> {
|
||||
let info = context.container_info.as_ref()?;
|
||||
Some(CSSPixelLength::new(info.size.width.to_f32_px()))
|
||||
}
|
||||
|
||||
fn eval_width(context: &Context) -> CSSPixelLength {
|
||||
let info = get_container(context);
|
||||
CSSPixelLength::new(info.size.width.to_f32_px())
|
||||
fn eval_height(context: &Context) -> Option<CSSPixelLength> {
|
||||
let info = context.container_info.as_ref()?;
|
||||
Some(CSSPixelLength::new(info.size.height.to_f32_px()))
|
||||
}
|
||||
|
||||
fn eval_height(context: &Context) -> CSSPixelLength {
|
||||
let info = get_container(context);
|
||||
CSSPixelLength::new(info.size.height.to_f32_px())
|
||||
}
|
||||
|
||||
fn eval_inline_size(context: &Context) -> CSSPixelLength {
|
||||
let info = get_container(context);
|
||||
CSSPixelLength::new(
|
||||
fn eval_inline_size(context: &Context) -> Option<CSSPixelLength> {
|
||||
let info = context.container_info.as_ref()?;
|
||||
Some(CSSPixelLength::new(
|
||||
LogicalSize::from_physical(info.wm, info.size)
|
||||
.inline
|
||||
.to_f32_px(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn eval_block_size(context: &Context) -> CSSPixelLength {
|
||||
let info = get_container(context);
|
||||
CSSPixelLength::new(
|
||||
fn eval_block_size(context: &Context) -> Option<CSSPixelLength> {
|
||||
let info = context.container_info.as_ref()?;
|
||||
Some(CSSPixelLength::new(
|
||||
LogicalSize::from_physical(info.wm, info.size)
|
||||
.block
|
||||
.to_f32_px(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn eval_aspect_ratio(context: &Context) -> Ratio {
|
||||
let info = get_container(context);
|
||||
Ratio::new(info.size.width.0 as f32, info.size.height.0 as f32)
|
||||
fn eval_aspect_ratio(context: &Context) -> Option<Ratio> {
|
||||
let info = context.container_info.as_ref()?;
|
||||
Some(Ratio::new(info.size.width.0 as f32, info.size.height.0 as f32))
|
||||
}
|
||||
|
||||
fn eval_orientation(context: &Context, value: Option<Orientation>) -> bool {
|
||||
let info = get_container(context);
|
||||
let info = match context.container_info.as_ref() {
|
||||
Some(info) => info,
|
||||
None => return false,
|
||||
};
|
||||
Orientation::eval(info.size, value)
|
||||
}
|
||||
|
||||
|
@ -316,31 +309,31 @@ pub static CONTAINER_FEATURES: [QueryFeatureDescription; 6] = [
|
|||
feature!(
|
||||
atom!("width"),
|
||||
AllowsRanges::Yes,
|
||||
Evaluator::Length(eval_width),
|
||||
Evaluator::OptionalLength(eval_width),
|
||||
FeatureFlags::CONTAINER_REQUIRES_WIDTH_AXIS,
|
||||
),
|
||||
feature!(
|
||||
atom!("height"),
|
||||
AllowsRanges::Yes,
|
||||
Evaluator::Length(eval_height),
|
||||
Evaluator::OptionalLength(eval_height),
|
||||
FeatureFlags::CONTAINER_REQUIRES_HEIGHT_AXIS,
|
||||
),
|
||||
feature!(
|
||||
atom!("inline-size"),
|
||||
AllowsRanges::Yes,
|
||||
Evaluator::Length(eval_inline_size),
|
||||
Evaluator::OptionalLength(eval_inline_size),
|
||||
FeatureFlags::CONTAINER_REQUIRES_INLINE_AXIS,
|
||||
),
|
||||
feature!(
|
||||
atom!("block-size"),
|
||||
AllowsRanges::Yes,
|
||||
Evaluator::Length(eval_block_size),
|
||||
Evaluator::OptionalLength(eval_block_size),
|
||||
FeatureFlags::CONTAINER_REQUIRES_BLOCK_AXIS,
|
||||
),
|
||||
feature!(
|
||||
atom!("aspect-ratio"),
|
||||
AllowsRanges::Yes,
|
||||
Evaluator::NumberRatio(eval_aspect_ratio),
|
||||
Evaluator::OptionalNumberRatio(eval_aspect_ratio),
|
||||
// XXX from_bits_truncate is const, but the pipe operator isn't, so this
|
||||
// works around it.
|
||||
FeatureFlags::from_bits_truncate(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue