mirror of
https://github.com/servo/servo.git
synced 2025-08-11 08:25:32 +01:00
style: Allow calc in media queries.
This commit is contained in:
parent
b318e61d5d
commit
be7a44315d
5 changed files with 72 additions and 30 deletions
|
@ -164,26 +164,9 @@ impl ToComputedValue for specified::CalcLengthOrPercentage {
|
|||
type ComputedValue = CalcLengthOrPercentage;
|
||||
|
||||
fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage {
|
||||
let mut length = None;
|
||||
|
||||
if let Some(absolute) = self.absolute {
|
||||
length = Some(length.unwrap_or(Au(0)) + absolute);
|
||||
}
|
||||
|
||||
for val in &[self.vw, self.vh, self.vmin, self.vmax] {
|
||||
if let Some(val) = *val {
|
||||
length = Some(length.unwrap_or(Au(0)) +
|
||||
val.to_computed_value(context.viewport_size()));
|
||||
}
|
||||
}
|
||||
for val in &[self.ch, self.em, self.ex, self.rem] {
|
||||
if let Some(val) = *val {
|
||||
length = Some(length.unwrap_or(Au(0)) + val.to_computed_value(
|
||||
context.style().get_font().clone_font_size(), context.style().root_font_size()));
|
||||
}
|
||||
}
|
||||
|
||||
CalcLengthOrPercentage { length: length, percentage: self.percentage.map(|p| p.0) }
|
||||
self.compute_from_viewport_and_font_size(context.viewport_size(),
|
||||
context.style().get_font().clone_font_size(),
|
||||
context.style().root_font_size())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::f32::consts::PI;
|
|||
use std::fmt;
|
||||
use std::ops::Mul;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::computed::{Context, ToComputedValue};
|
||||
use super::computed::{self, Context, ToComputedValue};
|
||||
use super::{CSSFloat, FONT_MEDIUM_PX, HasViewportPercentage, LocalToCss, NoViewportPercentage};
|
||||
use url::Url;
|
||||
|
||||
|
@ -751,6 +751,37 @@ impl CalcLengthOrPercentage {
|
|||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_from_viewport_and_font_size(&self,
|
||||
viewport_size: Size2D<Au>,
|
||||
font_size: Au,
|
||||
root_font_size: Au)
|
||||
-> computed::CalcLengthOrPercentage
|
||||
{
|
||||
let mut length = None;
|
||||
|
||||
if let Some(absolute) = self.absolute {
|
||||
length = Some(length.unwrap_or(Au(0)) + absolute);
|
||||
}
|
||||
|
||||
for val in &[self.vw, self.vh, self.vmin, self.vmax] {
|
||||
if let Some(val) = *val {
|
||||
length = Some(length.unwrap_or(Au(0)) +
|
||||
val.to_computed_value(viewport_size));
|
||||
}
|
||||
}
|
||||
for val in &[self.ch, self.em, self.ex, self.rem] {
|
||||
if let Some(val) = *val {
|
||||
length = Some(length.unwrap_or(Au(0)) + val.to_computed_value(
|
||||
font_size, root_font_size));
|
||||
}
|
||||
}
|
||||
|
||||
computed::CalcLengthOrPercentage {
|
||||
length: length,
|
||||
percentage: self.percentage.map(|p| p.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasViewportPercentage for CalcLengthOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue