css 0.0.22

A crate that uses the cssparser and selectors crates to provide a domain model for CSS Stylesheets. Intended to allow effective minification of CSS and CSS transformations such as autoprefixing and removal by other crates
// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.


pub(crate) struct ViewportAtRuleParser<'a>
{
	pub(crate) context: &'a ParserContext
}

impl<'a, 'i> AtRuleParser<'i> for ViewportAtRuleParser<'a>
{
	type PreludeNoBlock = ();
	
	type PreludeBlock = ();
	
	type AtRule = ViewportDescriptorDeclaration;
	
	type Error = CustomParseError<'i>;
}

impl<'a, 'i> DeclarationParser<'i> for ViewportAtRuleParser<'a>
{
	type Declaration = ViewportDescriptorDeclaration;
	
	type Error = CustomParseError<'i>;
	
	fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>) -> Result<Self::Declaration, ParseError<'i, CustomParseError<'i>>>
	{
		use self::ViewportDescriptor::*;
		
		#[inline(always)]
		fn parse_property<'i, 't, Parse: FnOnce(&mut Parser<'i, 't>) -> Result<Intermediate, ParseError<'i, CustomParseError<'i>>>, Intermediate, Constructor: FnOnce(Intermediate) -> ViewportDescriptor>(input: &mut Parser<'i, 't>, constructor: Constructor, parse: Parse) -> Result<ViewportDescriptorDeclaration, ParseError<'i, CustomParseError<'i>>>
		{
			ViewportDescriptorDeclaration::parse_important(constructor((parse(input))?), input)
		}
		
		#[inline(always)]
		fn parse_shorthand_property<'a, 'i, 't, Constructor: FnOnce(ViewportLength, Option<ViewportLength>) -> ViewportDescriptor>(input: &mut Parser<'i, 't>, this: &ViewportAtRuleParser<'a>, constructor: Constructor) -> Result<ViewportDescriptorDeclaration, ParseError<'i, CustomParseError<'i>>>
		{
			let minimum = this.parseViewportLength(input)?;
			let maximum = match input.try(|input| this.parseViewportLength(input))
			{
				Err(_) => None,
				Ok(maximum) => Some(maximum),
			};
			ViewportDescriptorDeclaration::parse_important(constructor(minimum, maximum), input)
		}
		
		match_ignore_ascii_case!
		{
			&*name,
		
            "min-width" => parse_property(input, MinWidth, |input| self.parseViewportLength(input)),
            
            "max-width" => parse_property(input, MaxWidth, |input| self.parseViewportLength(input)),
            
            "width" => parse_shorthand_property(input, self, |minimum, maximum| Width { minimum, maximum }),
			
            "min-height" => parse_property(input, MinHeight, |input| self.parseViewportLength(input)),
            
            "max-height" => parse_property(input, MaxHeight, |input| self.parseViewportLength(input)),
            
            "height" => parse_shorthand_property(input, self, |minimum, maximum| Height { minimum, maximum }),
            
            "zoom" => parse_property(input, Zoom, |input| self.parseZoom(input)),
            
            "min-zoom" => parse_property(input, MinZoom, |input| self.parseZoom(input)),
            
            "max-zoom" => parse_property(input, MaxZoom, |input| self.parseZoom(input)),
            
            "user-zoom" => parse_property(input, UserZoom, ViewportUserZoom::parse),
            
            "orientation" => parse_property(input, Orientation, ViewportOrientation::parse),
            
            _ => Err(ParseError::Custom(CustomParseError::UnexpectedViewportProperty(name.clone()))),
        }
	}
}

impl<'a> ViewportAtRuleParser<'a>
{
	#[inline(always)]
	fn parseViewportLength<'i, 't>(&self, input: &mut Parser<'i, 't>) -> Result<ViewportLength, ParseError<'i, CustomParseError<'i>>>
	{
		ViewportLength::parse(self.context, input)
	}
	
	#[inline(always)]
	fn parseZoom<'i, 't>(&self, input: &mut Parser<'i, 't>) -> Result<ViewportZoom, ParseError<'i, CustomParseError<'i>>>
	{
		ViewportZoom::parse(self.context, input)
	}
}