mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
parent
8d21a79246
commit
4a305d1e62
21 changed files with 274 additions and 156 deletions
|
@ -19,6 +19,9 @@ path = "../layout_traits"
|
|||
[dependencies.script_traits]
|
||||
path = "../script_traits"
|
||||
|
||||
[dependencies.style_traits]
|
||||
path = "../style_traits"
|
||||
|
||||
[dependencies.msg]
|
||||
path = "../msg"
|
||||
|
||||
|
@ -28,9 +31,6 @@ path = "../profile_traits"
|
|||
[dependencies.net_traits]
|
||||
path = "../net_traits"
|
||||
|
||||
[dependencies.style]
|
||||
path = "../style"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
|
@ -79,4 +79,3 @@ core-graphics = "0.1"
|
|||
|
||||
[target.x86_64-apple-darwin.dependencies.core-text]
|
||||
git = "https://github.com/servo/core-text-rs"
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ use std::mem as std_mem;
|
|||
use std::rc::Rc;
|
||||
use std::slice::bytes::copy_memory;
|
||||
use std::sync::mpsc::Sender;
|
||||
use style::viewport::ViewportConstraints;
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use time::{precise_time_ns, precise_time_s};
|
||||
use url::Url;
|
||||
use util::geometry::{Au, PagePx, ScreenPx, ViewportPx};
|
||||
|
|
|
@ -25,7 +25,7 @@ use profile_traits::time;
|
|||
use std::fmt::{Error, Formatter, Debug};
|
||||
use std::rc::Rc;
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use style::viewport::ViewportConstraints;
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use url::Url;
|
||||
use util::cursor::Cursor;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ use std::marker::PhantomData;
|
|||
use std::mem::replace;
|
||||
use std::process;
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
use style::viewport::ViewportConstraints;
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use url::Url;
|
||||
use util::cursor::Cursor;
|
||||
use util::geometry::PagePx;
|
||||
|
|
|
@ -30,7 +30,7 @@ extern crate num;
|
|||
extern crate profile_traits;
|
||||
extern crate net_traits;
|
||||
extern crate gfx_traits;
|
||||
extern crate style;
|
||||
extern crate style_traits;
|
||||
#[macro_use]
|
||||
extern crate util;
|
||||
extern crate gleam;
|
||||
|
@ -58,4 +58,3 @@ mod scrolling;
|
|||
pub mod pipeline;
|
||||
pub mod constellation;
|
||||
pub mod windowing;
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ authors = ["The Servo Project Developers"]
|
|||
name = "msg"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies.style]
|
||||
path = "../style"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
[dependencies.canvas_traits]
|
||||
path = "../canvas_traits"
|
||||
|
||||
[dependencies.style_traits]
|
||||
path = "../style_traits"
|
||||
|
||||
[dependencies.azure]
|
||||
git = "https://github.com/servo/rust-azure"
|
||||
|
||||
|
@ -56,4 +56,3 @@ core-foundation = "0.1"
|
|||
|
||||
[target.x86_64-apple-darwin.dependencies.io-surface]
|
||||
git = "https://github.com/servo/io-surface-rs"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ use offscreen_gl_context::GLContextAttributes;
|
|||
use png::Image;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||
use style::viewport::ViewportConstraints;
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use url::Url;
|
||||
use util::cursor::Cursor;
|
||||
use util::geometry::{PagePx, ViewportPx};
|
||||
|
|
|
@ -18,7 +18,7 @@ extern crate rustc_serialize;
|
|||
extern crate serde;
|
||||
extern crate util;
|
||||
extern crate url;
|
||||
extern crate style;
|
||||
extern crate style_traits;
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
extern crate core_foundation;
|
||||
|
|
24
components/servo/Cargo.lock
generated
24
components/servo/Cargo.lock
generated
|
@ -242,7 +242,7 @@ dependencies = [
|
|||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"profile_traits 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"time 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
@ -1036,7 +1036,7 @@ dependencies = [
|
|||
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
@ -1589,6 +1589,7 @@ dependencies = [
|
|||
"smallvec 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style_traits 0.0.1",
|
||||
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
@ -1603,6 +1604,25 @@ dependencies = [
|
|||
"string_cache 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"string_cache_plugin 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"style 0.0.1",
|
||||
"style_traits 0.0.1",
|
||||
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "style_traits"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"cssparser 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"plugins 0.0.1",
|
||||
"rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"selectors 0.1.0 (git+https://github.com/servo/rust-selectors)",
|
||||
"serde 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_macros 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.37 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
]
|
||||
|
|
|
@ -15,6 +15,9 @@ path = "../plugins"
|
|||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
[dependencies.style_traits]
|
||||
path = "../style_traits"
|
||||
|
||||
[dependencies.selectors]
|
||||
git = "https://github.com/servo/rust-selectors"
|
||||
features = ["unstable"]
|
||||
|
@ -42,4 +45,3 @@ string_cache_plugin = "0.1"
|
|||
euclid = "0.1"
|
||||
serde = "0.5"
|
||||
serde_macros = "0.5"
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ extern crate lazy_static;
|
|||
extern crate num;
|
||||
extern crate util;
|
||||
|
||||
#[macro_use]
|
||||
extern crate style_traits;
|
||||
|
||||
mod custom_properties;
|
||||
pub mod stylesheets;
|
||||
|
|
|
@ -18,8 +18,9 @@ use legacy::PresentationalHintSynthesis;
|
|||
use media_queries::Device;
|
||||
use node::TElementAttributes;
|
||||
use properties::{PropertyDeclaration, PropertyDeclarationBlock};
|
||||
use style_traits::viewport::ViewportConstraints;
|
||||
use stylesheets::{Stylesheet, CSSRuleIteratorExt, Origin};
|
||||
use viewport::{ViewportConstraints, ViewportRuleCascade};
|
||||
use viewport::{MaybeNew, ViewportRuleCascade};
|
||||
|
||||
|
||||
pub type DeclarationBlock = GenericDeclarationBlock<Vec<PropertyDeclaration>>;
|
||||
|
|
|
@ -6,37 +6,6 @@
|
|||
|
||||
pub use cssparser::RGBA;
|
||||
|
||||
macro_rules! define_css_keyword_enum {
|
||||
($name: ident: $( $css: expr => $variant: ident ),+,) => {
|
||||
define_css_keyword_enum!($name: $( $css => $variant ),+);
|
||||
};
|
||||
($name: ident: $( $css: expr => $variant: ident ),+) => {
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug, HeapSizeOf)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum $name {
|
||||
$( $variant ),+
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
$( $css => Ok($name::$variant) ),+
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for $name {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write {
|
||||
match *self {
|
||||
$( $name::$variant => dest.write_str($css) ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! define_numbered_css_keyword_enum {
|
||||
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
||||
|
@ -83,25 +52,11 @@ pub mod specified {
|
|||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
use std::ops::Mul;
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::CSSFloat;
|
||||
use url::Url;
|
||||
use util::geometry::Au;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum AllowedNumericType {
|
||||
All,
|
||||
NonNegative
|
||||
}
|
||||
|
||||
impl AllowedNumericType {
|
||||
#[inline]
|
||||
pub fn is_ok(&self, value: f32) -> bool {
|
||||
match *self {
|
||||
AllowedNumericType::All => true,
|
||||
AllowedNumericType::NonNegative => value >= 0.,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug, HeapSizeOf)]
|
||||
pub struct CSSColor {
|
||||
|
|
|
@ -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>
|
||||
{
|
||||
|
|
35
components/style_traits/Cargo.toml
Normal file
35
components/style_traits/Cargo.toml
Normal file
|
@ -0,0 +1,35 @@
|
|||
[package]
|
||||
name = "style_traits"
|
||||
version = "0.0.1"
|
||||
authors = ["The Servo Project Developers"]
|
||||
|
||||
[lib]
|
||||
name = "style_traits"
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../util"
|
||||
|
||||
[dependencies.cssparser]
|
||||
version = "0.3"
|
||||
features = [ "serde-serialization" ]
|
||||
|
||||
[dependencies.plugins]
|
||||
path = "../plugins"
|
||||
|
||||
[dependencies.selectors]
|
||||
git = "https://github.com/servo/rust-selectors"
|
||||
features = ["unstable"]
|
||||
|
||||
[dependencies.url]
|
||||
version = "0.2"
|
||||
features = [ "serde_serialization" ]
|
||||
|
||||
[dependencies]
|
||||
euclid = "0.1"
|
||||
log = "0.3"
|
||||
lazy_static = "0.1.10"
|
||||
num = "0.1.24"
|
||||
rustc-serialize = "0.3"
|
||||
serde = "0.5"
|
||||
serde_macros = "0.5"
|
27
components/style_traits/lib.rs
Normal file
27
components/style_traits/lib.rs
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* 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/. */
|
||||
|
||||
//! This module contains shared types and messages for use by devtools/script.
|
||||
//! The traits are here instead of in script so that the devtools crate can be
|
||||
//! modified independently of the rest of Servo.
|
||||
|
||||
#![crate_name = "style_traits"]
|
||||
#![crate_type = "rlib"]
|
||||
#![feature(custom_derive)]
|
||||
#![feature(plugin)]
|
||||
#![plugin(serde_macros)]
|
||||
#![deny(unsafe_code)]
|
||||
|
||||
extern crate euclid;
|
||||
extern crate rustc_serialize;
|
||||
extern crate serde;
|
||||
extern crate util;
|
||||
|
||||
#[macro_use]
|
||||
extern crate cssparser;
|
||||
|
||||
#[macro_use]
|
||||
pub mod values;
|
||||
|
||||
pub mod viewport;
|
55
components/style_traits/values.rs
Normal file
55
components/style_traits/values.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
/* 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/. */
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! define_css_keyword_enum {
|
||||
($name: ident: $( $css: expr => $variant: ident ),+,) => {
|
||||
define_css_keyword_enum!($name: $( $css => $variant ),+);
|
||||
};
|
||||
($name: ident: $( $css: expr => $variant: ident ),+) => {
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug, HeapSizeOf)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub enum $name {
|
||||
$( $variant ),+
|
||||
}
|
||||
|
||||
impl $name {
|
||||
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||
$( $css => Ok($name::$variant) ),+
|
||||
_ => Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::cssparser::ToCss for $name {
|
||||
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result
|
||||
where W: ::std::fmt::Write {
|
||||
match *self {
|
||||
$( $name::$variant => dest.write_str($css) ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub mod specified {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum AllowedNumericType {
|
||||
All,
|
||||
NonNegative
|
||||
}
|
||||
|
||||
impl AllowedNumericType {
|
||||
#[inline]
|
||||
pub fn is_ok(&self, value: f32) -> bool {
|
||||
match *self {
|
||||
AllowedNumericType::All => true,
|
||||
AllowedNumericType::NonNegative => value >= 0.,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
components/style_traits/viewport.rs
Normal file
99
components/style_traits/viewport.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
/* 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/. */
|
||||
|
||||
use cssparser::{Parser, ToCss};
|
||||
use euclid::scale_factor::ScaleFactor;
|
||||
use euclid::size::TypedSize2D;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::fmt;
|
||||
use util::geometry::{PagePx, ViewportPx};
|
||||
use values::specified::AllowedNumericType;
|
||||
|
||||
define_css_keyword_enum!(UserZoom:
|
||||
"zoom" => Zoom,
|
||||
"fixed" => Fixed);
|
||||
|
||||
define_css_keyword_enum!(Orientation:
|
||||
"auto" => Auto,
|
||||
"portrait" => Portrait,
|
||||
"landscape" => Landscape);
|
||||
|
||||
|
||||
#[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
|
||||
}
|
||||
|
||||
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, "; }}")
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,9 @@ doctest = false
|
|||
[dependencies.style]
|
||||
path = "../../../components/style"
|
||||
|
||||
[dependencies.style_traits]
|
||||
path = "../../../components/style_traits"
|
||||
|
||||
[dependencies.util]
|
||||
path = "../../../components/util"
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ extern crate euclid;
|
|||
extern crate selectors;
|
||||
extern crate string_cache;
|
||||
extern crate style;
|
||||
extern crate style_traits;
|
||||
extern crate url;
|
||||
extern crate util;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use style::parser::ParserContext;
|
|||
use style::stylesheets::{Origin, Stylesheet, CSSRuleIteratorExt};
|
||||
use style::values::specified::{Length, LengthOrPercentageOrAuto};
|
||||
use style::viewport::*;
|
||||
use style_traits::viewport::*;
|
||||
use url::Url;
|
||||
|
||||
macro_rules! stylesheet {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue