1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// 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.


/// No Charset here, CSSCharsetRule has been removed from CSSOM (https://drafts.csswg.org/cssom/#changes-from-5-december-2013) and Edge doesn't support it
#[derive(Debug, Clone)]
pub enum CssRule
{
	/// @counter-style
	CounterStyle(CounterStyleAtRule),
	
	/// @document
	Document(DocumentAtRule),
	
	/// @font-face
	FontFace(FontFaceAtRule),
	
	/// @font-feature-values
	FontFeatureValues(FontFeatureValuesAtRule),
	
	/// @import
	Import(ImportAtRule),
	
	/// @keyframes
	Keyframes(KeyframesAtRule),
	
	/// @media
	Media(MediaAtRule),
	
	/// @namespace
	Namespace(NamespaceAtRule),
	
	/// @page
	Page(PageAtRule),
	
	/// Style rules, eg `div { width: 10%; }`
	Style(StyleRule),
	
	/// @supports
	Supports(SupportsAtRule),
	
	/// @viewport
	Viewport(ViewportAtRule),
}

impl ToCss for CssRule
{
	/// https://drafts.csswg.org/cssom/#serialize-a-css-rule
	fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result
	{
		use self::CssRule::*;
		
		match *self
		{
			CounterStyle(ref rule) => rule.to_css(dest),
			
			Document(ref rule) => rule.to_css(dest),
			
			FontFace(ref rule) => rule.to_css(dest),
			
			FontFeatureValues(ref rule) => rule.to_css(dest),
			
			Import(ref rule) => rule.to_css(dest),
			
			Keyframes(ref rule) => rule.to_css(dest),
			
			Media(ref rule) => rule.to_css(dest),
			
			Namespace(ref rule) => rule.to_css(dest),
			
			Page(ref rule) => rule.to_css(dest),
			
			Style(ref rule) => rule.to_css(dest),
			
			Supports(ref rule) => rule.to_css(dest),
			
			Viewport(ref rule) => rule.to_css(dest),
		}
	}
}

impl CssRule
{
	/// Returns the CSSOM rule type of this rule.
	#[inline(always)]
	pub fn rule_type(&self) -> CssRuleType
	{
		use self::CssRule::*;
		
		match *self
		{
			CounterStyle(_) => CssRuleType::CounterStyle,
			
			Document(_)  => CssRuleType::Document,
			
			FontFace(_) => CssRuleType::FontFace,
			
			FontFeatureValues(_) => CssRuleType::FontFeatureValues,
			
			Import(_) => CssRuleType::Import,
			
			Keyframes(_) => CssRuleType::Keyframes,
			
			Media(_) => CssRuleType::Media,
			
			Namespace(_) => CssRuleType::Namespace,
			
			Page(_) => CssRuleType::Page,
			
			Style(_) => CssRuleType::Style,
			
			Supports(_) => CssRuleType::Supports,
			
			Viewport(_) => CssRuleType::Viewport,
		}
	}
}