servo/components/style/values/computed/resolution.rs
Emilio Cobos Álvarez 67f2185f54
style: Make webkit device-pixel-ratio media queries a proper alias to resolution.
According to the spec:

  https://compat.spec.whatwg.org/#css-media-queries-webkit-device-pixel-ratio

And to the Chromium implementation:

  https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/css/media_query_evaluator.cc?l=366&rcl=1d7328865bcf06a687aafc18ff95d55317030672

They're no different than resolution.

In our implementation `resolution` does slightly different stuff. Given we
still haven't shipped -webkit-device-pixel-ratio, making this match resolution
looks better than the opposite.

Differential Revision: https://phabricator.services.mozilla.com/D3588
2018-08-18 17:54:54 +02:00

54 lines
1.3 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! Resolution values:
//!
//! https://drafts.csswg.org/css-values/#resolution
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
use values::CSSFloat;
use values::computed::{Context, ToComputedValue};
use values::specified;
/// A computed `<resolution>`.
pub struct Resolution(CSSFloat);
impl Resolution {
/// Returns this resolution value as dppx.
#[inline]
pub fn dppx(&self) -> CSSFloat {
self.0
}
/// Return a computed `resolution` value from a dppx float value.
#[inline]
pub fn from_dppx(dppx: CSSFloat) -> Self {
Resolution(dppx)
}
}
impl ToComputedValue for specified::Resolution {
type ComputedValue = Resolution;
#[inline]
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
Resolution(self.to_dppx())
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
specified::Resolution::Dppx(computed.dppx())
}
}
impl ToCss for Resolution {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
self.dppx().to_css(dest)?;
dest.write_str("dppx")
}
}