mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +01:00
parent
8d21a79246
commit
4a305d1e62
21 changed files with 274 additions and 156 deletions
|
@ -2,19 +2,20 @@
|
|||
* 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/. */
|
||||
|
||||
use cssparser::{Parser, DeclarationListParser, AtRuleParser, DeclarationParser, ToCss, parse_important};
|
||||
use cssparser::{Parser, DeclarationListParser, AtRuleParser, DeclarationParser, parse_important};
|
||||
use euclid::scale_factor::ScaleFactor;
|
||||
use euclid::size::{Size2D, TypedSize2D};
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use properties::longhands;
|
||||
use style_traits::viewport::{UserZoom, Zoom, Orientation, ViewportConstraints};
|
||||
use stylesheets::Origin;
|
||||
use util::geometry::{Au, PagePx, ViewportPx};
|
||||
use util::geometry::{Au, ViewportPx};
|
||||
use values::computed::{Context, ToComputedValue};
|
||||
use values::specified::{AllowedNumericType, LengthOrPercentageOrAuto};
|
||||
use values::specified::LengthOrPercentageOrAuto;
|
||||
|
||||
|
||||
use std::ascii::AsciiExt;
|
||||
use std::collections::hash_map::{Entry, HashMap};
|
||||
use std::fmt;
|
||||
use std::intrinsics;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
@ -33,61 +34,6 @@ pub enum ViewportDescriptor {
|
|||
Orientation(Orientation)
|
||||
}
|
||||
|
||||
/// Zoom is a number | percentage | auto
|
||||
/// See http://dev.w3.org/csswg/css-device-adapt/#descdef-viewport-zoom
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum Zoom {
|
||||
Number(f32),
|
||||
Percentage(f32),
|
||||
Auto,
|
||||
}
|
||||
|
||||
impl ToCss for Zoom {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write
|
||||
{
|
||||
match *self {
|
||||
Zoom::Number(number) => write!(dest, "{}", number),
|
||||
Zoom::Percentage(percentage) => write!(dest, "{}%", percentage * 100.),
|
||||
Zoom::Auto => write!(dest, "auto")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Zoom {
|
||||
pub fn parse(input: &mut Parser) -> Result<Zoom, ()> {
|
||||
use cssparser::Token;
|
||||
|
||||
match try!(input.next()) {
|
||||
Token::Percentage(ref value) if AllowedNumericType::NonNegative.is_ok(value.unit_value) =>
|
||||
Ok(Zoom::Percentage(value.unit_value)),
|
||||
Token::Number(ref value) if AllowedNumericType::NonNegative.is_ok(value.value) =>
|
||||
Ok(Zoom::Number(value.value)),
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") =>
|
||||
Ok(Zoom::Auto),
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_f32(&self) -> Option<f32> {
|
||||
match *self {
|
||||
Zoom::Number(number) => Some(number as f32),
|
||||
Zoom::Percentage(percentage) => Some(percentage as f32),
|
||||
Zoom::Auto => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_css_keyword_enum!(UserZoom:
|
||||
"zoom" => Zoom,
|
||||
"fixed" => Fixed);
|
||||
|
||||
define_css_keyword_enum!(Orientation:
|
||||
"auto" => Auto,
|
||||
"portrait" => Portrait,
|
||||
"landscape" => Landscape);
|
||||
|
||||
struct ViewportRuleParser<'a, 'b: 'a> {
|
||||
context: &'a ParserContext<'b>
|
||||
}
|
||||
|
@ -306,40 +252,14 @@ impl<'a, I> ViewportDescriptorDeclarationCascade for I
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize, Serialize)]
|
||||
pub struct ViewportConstraints {
|
||||
pub size: TypedSize2D<ViewportPx, f32>,
|
||||
|
||||
pub initial_zoom: ScaleFactor<PagePx, ViewportPx, f32>,
|
||||
pub min_zoom: Option<ScaleFactor<PagePx, ViewportPx, f32>>,
|
||||
pub max_zoom: Option<ScaleFactor<PagePx, ViewportPx, f32>>,
|
||||
|
||||
pub user_zoom: UserZoom,
|
||||
pub orientation: Orientation
|
||||
pub trait MaybeNew {
|
||||
fn maybe_new(initial_viewport: TypedSize2D<ViewportPx, f32>,
|
||||
rule: &ViewportRule)
|
||||
-> Option<ViewportConstraints>;
|
||||
}
|
||||
|
||||
impl ToCss for ViewportConstraints {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write
|
||||
{
|
||||
try!(write!(dest, "@viewport {{"));
|
||||
try!(write!(dest, " width: {}px;", self.size.width.get()));
|
||||
try!(write!(dest, " height: {}px;", self.size.height.get()));
|
||||
try!(write!(dest, " zoom: {};", self.initial_zoom.get()));
|
||||
if let Some(min_zoom) = self.min_zoom {
|
||||
try!(write!(dest, " min-zoom: {};", min_zoom.get()));
|
||||
}
|
||||
if let Some(max_zoom) = self.max_zoom {
|
||||
try!(write!(dest, " max-zoom: {};", max_zoom.get()));
|
||||
}
|
||||
try!(write!(dest, " user-zoom: ")); try!(self.user_zoom.to_css(dest));
|
||||
try!(write!(dest, "; orientation: ")); try!(self.orientation.to_css(dest));
|
||||
write!(dest, "; }}")
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewportConstraints {
|
||||
pub fn maybe_new(initial_viewport: TypedSize2D<ViewportPx, f32>,
|
||||
impl MaybeNew for ViewportConstraints {
|
||||
fn maybe_new(initial_viewport: TypedSize2D<ViewportPx, f32>,
|
||||
rule: &ViewportRule)
|
||||
-> Option<ViewportConstraints>
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue