mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
style: Document style_traits and deny missing docs on it.
This commit is contained in:
parent
40a6a1f971
commit
82b6825a86
4 changed files with 37 additions and 7 deletions
|
@ -8,14 +8,17 @@ use super::ToCss;
|
||||||
|
|
||||||
macro_rules! define_cursor {
|
macro_rules! define_cursor {
|
||||||
($( $css: expr => $variant: ident = $value: expr, )+) => {
|
($( $css: expr => $variant: ident = $value: expr, )+) => {
|
||||||
|
/// https://drafts.csswg.org/css-ui/#cursor
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, HeapSizeOf))]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
pub enum Cursor {
|
pub enum Cursor {
|
||||||
$( $variant = $value ),+
|
$( $variant = $value ),+
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cursor {
|
impl Cursor {
|
||||||
|
/// Given a CSS keyword, get the corresponding cursor enum.
|
||||||
pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
|
pub fn from_css_keyword(keyword: &str) -> Result<Cursor, ()> {
|
||||||
match_ignore_ascii_case! { keyword,
|
match_ignore_ascii_case! { keyword,
|
||||||
$( concat!($css) => Ok(Cursor::$variant), )+
|
$( concat!($css) => Ok(Cursor::$variant), )+
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#![crate_name = "style_traits"]
|
#![crate_name = "style_traits"]
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code, missing_docs)]
|
||||||
|
|
||||||
#![cfg_attr(feature = "servo", feature(plugin))]
|
#![cfg_attr(feature = "servo", feature(plugin))]
|
||||||
#![cfg_attr(feature = "servo", feature(proc_macro))]
|
#![cfg_attr(feature = "servo", feature(proc_macro))]
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Helper types and traits for the handling of CSS values.
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
@ -78,13 +80,14 @@ macro_rules! __define_css_keyword_enum__add_optional_traits {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! __define_css_keyword_enum__actual {
|
macro_rules! __define_css_keyword_enum__actual {
|
||||||
($name: ident [ $( $derived_trait: ident),* ] [ $( $css: expr => $variant: ident ),+ ]) => {
|
($name: ident [ $( $derived_trait: ident),* ] [ $( $css: expr => $variant: ident ),+ ]) => {
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types, missing_docs)]
|
||||||
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug $(, $derived_trait )* )]
|
#[derive(Clone, Eq, PartialEq, Copy, Hash, RustcEncodable, Debug $(, $derived_trait )* )]
|
||||||
pub enum $name {
|
pub enum $name {
|
||||||
$( $variant ),+
|
$( $variant ),+
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $name {
|
impl $name {
|
||||||
|
/// Parse this property from a CSS input stream.
|
||||||
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
pub fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
|
||||||
match_ignore_ascii_case! { try!(input.expect_ident()),
|
match_ignore_ascii_case! { try!(input.expect_ident()),
|
||||||
$( $css => Ok($name::$variant), )+
|
$( $css => Ok($name::$variant), )+
|
||||||
|
@ -105,18 +108,23 @@ macro_rules! __define_css_keyword_enum__actual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Helper types for the handling of specified values.
|
||||||
pub mod specified {
|
pub mod specified {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
|
||||||
|
/// Whether to allow negative values or not.
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum AllowedNumericType {
|
pub enum AllowedNumericType {
|
||||||
|
/// Allow all kind of numeric values.
|
||||||
All,
|
All,
|
||||||
|
/// Allow only non-negative values.
|
||||||
NonNegative
|
NonNegative
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllowedNumericType {
|
impl AllowedNumericType {
|
||||||
|
/// Whether value is valid for this allowed numeric type.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_ok(&self, value: f32) -> bool {
|
pub fn is_ok(&self, value: f32) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -125,6 +133,7 @@ pub mod specified {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clamp the value following the rules of this numeric type.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn clamp(&self, val: Au) -> Au {
|
pub fn clamp(&self, val: Au) -> Au {
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! Helper types for the `@viewport` rule.
|
||||||
|
|
||||||
use {PagePx, ViewportPx};
|
use {PagePx, ViewportPx};
|
||||||
use cssparser::{Parser, ToCss};
|
use cssparser::{Parser, ToCss};
|
||||||
use euclid::scale_factor::ScaleFactor;
|
use euclid::scale_factor::ScaleFactor;
|
||||||
|
@ -20,16 +22,25 @@ define_css_keyword_enum!(Orientation:
|
||||||
"landscape" => Landscape);
|
"landscape" => Landscape);
|
||||||
|
|
||||||
|
|
||||||
|
/// A set of viewport descriptors:
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#viewport-desc
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, HeapSizeOf))]
|
||||||
pub struct ViewportConstraints {
|
pub struct ViewportConstraints {
|
||||||
|
/// Width and height:
|
||||||
|
/// * https://drafts.csswg.org/css-device-adapt/#width-desc
|
||||||
|
/// * https://drafts.csswg.org/css-device-adapt/#height-desc
|
||||||
pub size: TypedSize2D<f32, ViewportPx>,
|
pub size: TypedSize2D<f32, ViewportPx>,
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#zoom-desc
|
||||||
pub initial_zoom: ScaleFactor<f32, PagePx, ViewportPx>,
|
pub initial_zoom: ScaleFactor<f32, PagePx, ViewportPx>,
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#min-max-width-desc
|
||||||
pub min_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
pub min_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#min-max-width-desc
|
||||||
pub max_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
pub max_zoom: Option<ScaleFactor<f32, PagePx, ViewportPx>>,
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#user-zoom-desc
|
||||||
pub user_zoom: UserZoom,
|
pub user_zoom: UserZoom,
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#orientation-desc
|
||||||
pub orientation: Orientation
|
pub orientation: Orientation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,19 +64,21 @@ impl ToCss for ViewportConstraints {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Zoom is a number | percentage | auto
|
/// https://drafts.csswg.org/css-device-adapt/#descdef-viewport-zoom
|
||||||
/// See http://dev.w3.org/csswg/css-device-adapt/#descdef-viewport-zoom
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub enum Zoom {
|
pub enum Zoom {
|
||||||
|
/// A number value.
|
||||||
Number(f32),
|
Number(f32),
|
||||||
|
/// A percentage value.
|
||||||
Percentage(f32),
|
Percentage(f32),
|
||||||
|
/// The `auto` keyword.
|
||||||
Auto,
|
Auto,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for Zoom {
|
impl ToCss for Zoom {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
where W: fmt::Write
|
where W: fmt::Write,
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
Zoom::Number(number) => write!(dest, "{}", number),
|
Zoom::Number(number) => write!(dest, "{}", number),
|
||||||
|
@ -76,6 +89,9 @@ impl ToCss for Zoom {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Zoom {
|
impl Zoom {
|
||||||
|
/// Parse a zoom value per:
|
||||||
|
///
|
||||||
|
/// https://drafts.csswg.org/css-device-adapt/#descdef-viewport-zoom
|
||||||
pub fn parse(input: &mut Parser) -> Result<Zoom, ()> {
|
pub fn parse(input: &mut Parser) -> Result<Zoom, ()> {
|
||||||
use cssparser::Token;
|
use cssparser::Token;
|
||||||
|
|
||||||
|
@ -90,6 +106,8 @@ impl Zoom {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get this zoom value as a float value. Returns `None` if the value is the
|
||||||
|
/// `auto` keyword.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_f32(&self) -> Option<f32> {
|
pub fn to_f32(&self) -> Option<f32> {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue