├── .nuget ├── Upload.cmd ├── css.png ├── Build.cmd └── NuGet.Config ├── Build ├── Alba.snk └── CommonTests.targets ├── .gitmodules ├── .gitignore ├── Alba.CsCss ├── Gfx │ ├── Side.cs │ ├── gfxFontFeature.cs │ ├── Original │ │ ├── gfxFontConstants.tt │ │ ├── nsColorNameList.ttinclude │ │ ├── nsFont.conv.cs │ │ ├── gfxFontConstants.h │ │ └── nsColorNameList.tt │ └── nscoord.cs ├── Common │ ├── BrowserCompatibility.cs │ ├── nsIPrincipal.cs │ ├── nsresultExts.cs │ ├── AlbaCsCssTraceSources.cs │ ├── nsresult.cs │ ├── Original │ │ ├── nsNameSpace.conv.cs │ │ ├── nsINameSpaceManager.tt │ │ └── nsINameSpaceManager.h │ ├── nsAtomList.cs │ ├── nsGkAtoms.cs │ ├── nsXMLNameSpaceMap.cs │ ├── nsNameSpaceManager.cs │ └── ErrorReporter.cs ├── Globalization │ ├── CssResources.tt │ ├── css.tt │ └── CssResources.g.cs ├── Style │ ├── Calc │ │ ├── ICalcOpsInput.cs │ │ ├── CssValueInputCalcOps.cs │ │ ├── NumbersAlreadyNormalizedOps.cs │ │ ├── ReduceNumberCalcOps.cs │ │ ├── ICalcOps.cs │ │ └── BasicFloatCalcOps.cs │ ├── nsCachedStyleData.cs │ ├── Media │ │ ├── nsMediaFeatures.cs │ │ ├── Original │ │ │ ├── CssMediaFeature.RangeType.conv.cs │ │ │ ├── nsMediaFeaturesH.tt │ │ │ ├── CssMediaFeature.ValueType.conv.cs │ │ │ ├── nsMediaFeatures.tt │ │ │ ├── nsMediaFeaturesH.h │ │ │ └── nsMediaFeatures.conv.cs │ │ ├── CssMediaExpression.cs │ │ ├── nsMediaList.cs │ │ ├── CssMediaQuery.cs │ │ └── CssMediaFeature.cs │ ├── nsCSSDataBlock.cs │ ├── nsCSSAnonBoxes.cs │ ├── Original │ │ ├── nsCSSFontDesc.g.cs │ │ ├── CssRuleKind.conv.cs │ │ ├── nsStyle.nsIWidget.conv.cs │ │ ├── CssAttrFunction.conv.cs │ │ ├── nsCSSFontDescList.h │ │ ├── nsCSSProps.CSSFontDescList.g.cs │ │ ├── StyleRule.tt │ │ ├── nsCSSFontDescList.ttinclude │ │ ├── nsCSSValue.tt │ │ ├── nsCSSKeywordList.ttinclude │ │ ├── nsCSSPseudoElementList.ttinclude │ │ ├── LookAndFeel.tt │ │ ├── nsCSSProps.CSSPropAliasList.g.cs │ │ ├── nsCSSPropAliasList.ttinclude │ │ ├── nsCSSPropAliasList.tt │ │ ├── nsIWidget.tt │ │ ├── nsStyleStructID.g.cs │ │ ├── nsCSSPropH.conv.cs │ │ ├── nsStyleStructList.ttinclude │ │ ├── Rule.tt │ │ ├── CssPseudoElement.g.cs │ │ ├── nsCSSProps.tt │ │ ├── nsCSSKeywordList.tt │ │ ├── nsStyleStructList.tt │ │ ├── nsCSSPseudoClassList.ttinclude │ │ ├── nsCSSPseudoClassList.tt │ │ ├── nsCSSPropsH.tt │ │ ├── nsCSSPseudoElementList.tt │ │ ├── nsCSSPseudoElements.g.cs │ │ ├── nsCSSPseudoElementList.h │ │ ├── CssFontFace.g.cs │ │ ├── CssStyleSheet.CssRuleKind.g.cs │ │ ├── nsCSSFontDescList.tt │ │ ├── nsCSSPropAliasList.h │ │ ├── nsStyleConsts.tt │ │ ├── Rule.h │ │ └── CssToken.conv.cs │ ├── Values │ │ ├── CssValueGradientStop.cs │ │ ├── CssValueList.cs │ │ ├── CssValuePair.cs │ │ ├── CssValuePairList.cs │ │ ├── CssValueTriplet.cs │ │ ├── CssUriValue.cs │ │ ├── CssRect.cs │ │ └── CssValueGradient.cs │ ├── CssPropertyValue.cs │ ├── Rules │ │ ├── CssKeyframesRule.cs │ │ ├── CssRule.cs │ │ ├── CssPageRule.cs │ │ ├── CssFontFaceRule.cs │ │ ├── CssCharsetRule.cs │ │ ├── CssImportRule.cs │ │ ├── CssKeyframeRule.cs │ │ ├── CssGroupRule.cs │ │ ├── CssSupportsRule.cs │ │ ├── CssMediaRule.cs │ │ ├── CssNamespaceRule.cs │ │ ├── CssDocumentRule.cs │ │ └── CssStyleRule.cs │ ├── nsCSSKeywords.cs │ ├── CssParserErrorEventArgs.cs │ ├── nsCSSPseudoElements.cs │ ├── CssPropertySet.cs │ ├── CssToken.cs │ ├── CssSelectorGroup.cs │ ├── CssStyle.cs │ ├── nsCSSPseudoClasses.cs │ ├── nsCSSCompressedDataBlock.cs │ ├── CssScanner.cs │ ├── CssLoader.cs │ ├── CssAttrSelector.cs │ ├── CssPseudoClassSelector.cs │ ├── nsCSSProps.cs │ ├── CssStyleSheet.cs │ └── CssTokenType.cs ├── T4 │ ├── Include.ttinclude │ └── ResX.ttinclude ├── Internal │ ├── Extensions │ │ ├── ObjectExts.cs │ │ ├── ArrayExts.cs │ │ ├── ListExts.cs │ │ ├── DictionaryExts.cs │ │ ├── StringExts.cs │ │ ├── EnumerableExts.cs │ │ └── StringBuilderExts.cs │ ├── ReferenceEqualityComparer.cs │ ├── CommonUtil.cs │ └── nsStyleUtil.cs ├── Alba.CsCss.nuspec ├── Properties │ └── AssemblyInfo.cs └── Alba.CsCss.csproj.DotSettings ├── Alba.CsCss.Tests ├── Files │ └── StackOverflow18262390.css ├── AssemblySetup.cs ├── Properties │ └── AssemblyInfo.cs ├── PublicInterface.cs └── Style │ └── CssScannerTests.cs └── Alba.CsCss.sln /.nuget/Upload.cmd: -------------------------------------------------------------------------------- 1 | NuGet Push Alba.CsCss.1.0.1.0.nupkg 2 | Pause 3 | -------------------------------------------------------------------------------- /.nuget/css.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Athari/CsCss/HEAD/.nuget/css.png -------------------------------------------------------------------------------- /Build/Alba.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Athari/CsCss/HEAD/Build/Alba.snk -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Alba.Framework"] 2 | path = Alba.Framework 3 | url = git@github.com:Athari/Alba.Framework.git 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.nuget/NuGet.exe 2 | /Packages 3 | /TestResults 4 | /Temp 5 | bin/ 6 | obj/ 7 | *.nupkg 8 | *.suo 9 | *.DotSettings.user 10 | *.csproj.user -------------------------------------------------------------------------------- /.nuget/Build.cmd: -------------------------------------------------------------------------------- 1 | Copy /Y ..\ReadMe.md ..\ReadMe.txt 2 | NuGet Pack ..\Alba.CsCss\Alba.CsCss.csproj -Symbols -Build -Properties Configuration=Release 3 | Del ..\ReadMe.txt 4 | Pause 5 | -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Side.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Gfx 2 | { 3 | public enum Side 4 | { 5 | Top, 6 | Right, 7 | Bottom, 8 | Left 9 | }; 10 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/BrowserCompatibility.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss 2 | { 3 | public enum BrowserCompatibility 4 | { 5 | FullStandards = 1, 6 | AlmostStandards = 2, 7 | Quirks = 3, 8 | }; 9 | } -------------------------------------------------------------------------------- /Alba.CsCss/Globalization/CssResources.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #><#@ output extension="/" #> 2 | <#@ include file="..\T4\ResX.ttinclude" #> 3 | <# GenerateResxDesigner(generateProps: false); #> 4 | -------------------------------------------------------------------------------- /Alba.CsCss/Globalization/css.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #><#@ output extension="/" #> 2 | <#@ include file="..\T4\ResX.ttinclude" #> 3 | <# GenerateResxFromProperties(fileName: "CssResources.resx"); #> 4 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/ICalcOpsInput.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable TypeParameterCanBeVariant 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | internal interface ICalcOpsInput 6 | { 7 | TInput[] GetArrayValue (); 8 | } 9 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCachedStyleData.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | internal class nsCachedStyleData 4 | { 5 | public static int GetBitForSID (nsStyleStructID aSID) 6 | { 7 | return 1 << (int)aSID; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Alba.CsCss/T4/Include.ttinclude: -------------------------------------------------------------------------------- 1 | <#@ assembly name="$(SolutionDir)\bin\Debug\Alba.Framework.dll" 2 | #><#@ import namespace="System.Collections.Generic" 3 | #><#@ import namespace="Alba.Framework.Text" 4 | #><#@ import namespace="Alba.Framework.Collections" 5 | #><#@ import namespace="Alba.Framework.Globalization" 6 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsIPrincipal.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss 2 | { 3 | // Unused. In Firefox code, used to check various URL permissions. 4 | internal class nsIPrincipal 5 | { 6 | public static nsIPrincipal Default = new nsIPrincipal(); 7 | 8 | private nsIPrincipal () 9 | {} 10 | } 11 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/nsMediaFeatures.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | internal partial class nsMediaFeatures 6 | { 7 | public static CssMediaFeature GetFeature (string aName) 8 | { 9 | return features.FirstOrDefault(f => f.mName == aName) ?? EmptyFeature; 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/CssValueInputCalcOps.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | internal class CssValueInputCalcOps 4 | { 5 | //typedef nsCSSValue input_type; 6 | //typedef nsCSSValue::Array input_array_type; 7 | 8 | public static CssUnit GetUnit (CssValue aValue) 9 | { 10 | return aValue.GetUnit(); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSDataBlock.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | internal class nsCSSDataBlock 4 | { 5 | protected static bool MoveValue (ref CssValue aSource, ref CssValue aDest) 6 | { 7 | bool changed = aSource != aDest; 8 | aDest = aSource; 9 | aSource.Reset(); 10 | return changed; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/ObjectExts.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Alba.CsCss.Internal.Extensions 4 | { 5 | internal static class ObjectExts 6 | { 7 | public static nsresult Equals (this T @this, T other, out bool equal) 8 | { 9 | equal = EqualityComparer.Default.Equals(@this, other); 10 | return nsresult.OK; 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsresultExts.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss 2 | { 3 | internal static class nsresultExts 4 | { 5 | public static bool Succeeded (this nsresult @this) 6 | { 7 | return ((uint)@this & 0x80000000) == 0; 8 | } 9 | 10 | public static bool Failed (this nsresult @this) 11 | { 12 | return ((uint)@this & 0x80000000) != 0; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/CssMediaFeature.RangeType.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | // ReSharper disable RedundantUsingDirective 5 | // ReSharper disable RedundantCast 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | public partial class CssMediaFeature 10 | { 11 | public enum RangeType { 12 | MinMaxAllowed, MinMaxNotAllowed 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/NumbersAlreadyNormalizedOps.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | internal class NumbersAlreadyNormalizedOps : CssValueInputCalcOps 6 | { 7 | public float ComputeNumber (CssValue aValue) 8 | { 9 | Debug.Assert(aValue.GetUnit() == CssUnit.Number, "unexpected unit"); 10 | return aValue.GetFloatValue(); 11 | } 12 | }; 13 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSAnonBoxes.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | // internal mozilla stuff no one cares about 4 | internal static class nsCSSAnonBoxes 5 | { 6 | public static bool IsAnonBox (string aAtom) 7 | { 8 | return false; 9 | } 10 | 11 | public static bool IsTreePseudoElement (string aAtom) 12 | { 13 | return false; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSFontDesc.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | internal enum nsCSSFontDesc 8 | { 9 | UNKNOWN, 10 | Family, 11 | Style, 12 | Weight, 13 | Stretch, 14 | Src, 15 | UnicodeRange, 16 | FontFeatureSettings, 17 | FontLanguageOverride, 18 | COUNT 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/gfxFontFeature.cs: -------------------------------------------------------------------------------- 1 | using uint32_t = System.UInt32; 2 | 3 | namespace Alba.CsCss.Gfx 4 | { 5 | internal struct gfxFontFeature 6 | { 7 | // see http://www.microsoft.com/typography/otspec/featuretags.htm 8 | public uint32_t mTag; 9 | // 0 = off, 1 = on, larger values may be used as parameters 10 | // to features that select among multiple alternatives 11 | public uint32_t mValue; 12 | } 13 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssRuleKind.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | public enum CssRuleKind 8 | { 9 | Unknown, 10 | Charset, 11 | Import, 12 | Namespace, 13 | Style, 14 | Media, 15 | FontFace, 16 | Page, 17 | Keyframe, 18 | Keyframes, 19 | Document, 20 | Supports, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsStyle.nsIWidget.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | public partial class CssStyle 8 | { 9 | public const int WindowShadowNone = 0; 10 | public const int WindowShadowDefault = 1; 11 | public const int WindowShadowMenu = 2; 12 | public const int WindowShadowTooltip = 3; 13 | public const int WindowShadowSheet = 4; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValueGradientStop.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | public class CssValueGradientStop 4 | { 5 | internal CssValue mColor; 6 | internal CssValue mLocation; 7 | 8 | // public interface 9 | 10 | public CssValue Color 11 | { 12 | get { return mColor; } 13 | } 14 | 15 | public CssValue Location 16 | { 17 | get { return mLocation; } 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssPropertyValue.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay ("{mProperty}: {mValue}")] 6 | public struct CssPropertyValue 7 | { 8 | internal CssProperty mProperty; 9 | internal CssValue mValue; 10 | 11 | public CssProperty Property 12 | { 13 | get { return mProperty; } 14 | } 15 | 16 | public CssValue Value 17 | { 18 | get { return mValue; } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Alba.CsCss.Tests/Files/StackOverflow18262390.css: -------------------------------------------------------------------------------- 1 | b { background: url(img0) } 2 | b { background: url("img1") } 3 | b { background: url('img2') } 4 | b { background: url( img3 ) } 5 | b { background: url( "img4" ) } 6 | b { background: url( 'img5' ) } 7 | b { background: url (noimg0) } 8 | b { background: url ("noimg1") } 9 | b { background: url ('noimg2') } 10 | /*b { background: url(noimg3) }*/ 11 | b { color: url(noimg4) } 12 | b { content: 'url(noimg5)' } 13 | @media screen and (max-width: 1280px) { b { background: url(img6) } } 14 | b { background: url(img7) } 15 | -------------------------------------------------------------------------------- /Alba.CsCss.Tests/AssemblySetup.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Alba.Framework.Testing; 3 | using Microsoft.VisualStudio.TestTools.UnitTesting; 4 | 5 | namespace Alba.CsCss.Tests 6 | { 7 | [TestClass] 8 | public class AssemblySetup 9 | { 10 | [AssemblyInitialize] 11 | public static void AssemblyInitialize (TestContext context) 12 | { 13 | AlbaCsCssTraceSources.CssParser.Switch.Level = SourceLevels.All; 14 | AlbaCsCssTraceSources.CssParser.Listeners.Add(new TraceRedirectTraceListener()); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/AlbaCsCssTraceSources.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss 4 | { 5 | public static class AlbaCsCssTraceSources 6 | { 7 | public const string BaseTraceSourceName = "Alba.CsCss."; 8 | public const string CssParserTraceSourceName = BaseTraceSourceName + "CssParser"; 9 | 10 | private static TraceSource _cssParser; 11 | 12 | public static TraceSource CssParser 13 | { 14 | get { return _cssParser ?? (_cssParser = new TraceSource(CssParserTraceSourceName)); } 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssAttrFunction.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | public enum CssAttrFunction 8 | { 9 | Set = 0,// [attr] 10 | Equals = 1,// [attr=value] 11 | Includes = 2,// [attr~=value] (space separated) 12 | DashMatch = 3,// [attr|=value] ('-' truncated) 13 | BeginsMatch = 4,// [attr^=value] (begins with) 14 | EndsMatch = 5,// [attr$=value] (ends with) 15 | ContainsMatch = 6,// [attr*=value] (contains substring) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValueList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using Alba.CsCss.Internal.Extensions; 5 | 6 | namespace Alba.CsCss.Style 7 | { 8 | [DebuggerDisplay ("{mValue} ...")] 9 | internal class CssValueList 10 | { 11 | internal CssValue mValue; 12 | internal CssValueList mNext; 13 | 14 | // Public interface 15 | 16 | internal static IEnumerable TraverseList (CssValueList @this) 17 | { 18 | return @this.TraverseList(i => i.mNext).Select(i => i.mValue); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValuePair.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay ("{mXValue}, {mYValue}")] 6 | public class CssValuePair 7 | { 8 | internal CssValue mXValue, mYValue; 9 | 10 | internal void SetBothValuesTo (CssValue aValue) 11 | { 12 | mXValue = mYValue = aValue; 13 | } 14 | 15 | // Public interface 16 | 17 | public CssValue X 18 | { 19 | get { return mXValue; } 20 | } 21 | 22 | public CssValue Y 23 | { 24 | get { return mYValue; } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/ArrayExts.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Internal.Extensions 2 | { 3 | internal static class ArrayExts 4 | { 5 | public static int Count (this T[] @this) 6 | { 7 | return @this.Length; 8 | } 9 | 10 | public static T Item (this T[] @this, int index) 11 | { 12 | return @this[index]; 13 | } 14 | 15 | public static int FindChar (this char[] @this, char ch) 16 | { 17 | for (int i = 0; i < @this.Length; i++) 18 | if (@this[i] == ch) 19 | return i; 20 | return -1; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsresult.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable RedundantCast 2 | 3 | // Too much hassle to convert the whole ErrorList.h (included from nsError.h) with hundreds of codes, considering we need only a few. 4 | // Besides, exact codes don't really matter; only 0x80000000 failure bit matters. 5 | 6 | namespace Alba.CsCss 7 | { 8 | internal enum nsresult 9 | { 10 | OK = unchecked ((int)0x00000000), 11 | ERROR_UNEXPECTED = unchecked ((int)0x8000ffff), 12 | ERROR_DOM_SYNTAX_ERR = unchecked ((int)0x8053000c), 13 | ERROR_MALFORMED_URI = unchecked((int)0x804b000a), 14 | ERROR_ILLEGAL_VALUE = unchecked((int)0x80070057), 15 | } 16 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssKeyframesRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay (@"@keyframes {mName} \{ ({mRules.Count}) \}")] 6 | public class CssKeyframesRule : CssGroupRule 7 | { 8 | private readonly string mName; 9 | 10 | internal CssKeyframesRule (string aName) 11 | { 12 | mName = aName; 13 | } 14 | 15 | internal override CssRuleKind GetKind () 16 | { 17 | return CssRuleKind.Keyframes; 18 | } 19 | 20 | // Public interface 21 | 22 | public string Name 23 | { 24 | get { return mName; } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSFontDescList.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | CSS_FONT_DESC(font-family, Family) 7 | CSS_FONT_DESC(font-style, Style) 8 | CSS_FONT_DESC(font-weight, Weight) 9 | CSS_FONT_DESC(font-stretch, Stretch) 10 | CSS_FONT_DESC(src, Src) 11 | CSS_FONT_DESC(unicode-range, UnicodeRange) 12 | CSS_FONT_DESC(-moz-font-feature-settings, FontFeatureSettings) 13 | CSS_FONT_DESC(-moz-font-language-override, FontLanguageOverride) 14 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSKeywords.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Alba.CsCss.Internal.Extensions; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | internal static partial class nsCSSKeywords 7 | { 8 | public static CssKeyword LookupKeyword (string aKeyword) 9 | { 10 | return (CssKeyword)gKeywordTable.GetOrDefault(aKeyword, -1); 11 | } 12 | 13 | public static CssKeyword LookupKeyword (StringBuilder aKeyword) 14 | { 15 | return LookupKeyword(aKeyword.ToString()); 16 | } 17 | 18 | public static string GetStringValue (CssKeyword aKeyword) 19 | { 20 | return kCSSRawKeywords[(int)aKeyword]; 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValuePairList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using Alba.CsCss.Internal.Extensions; 5 | 6 | namespace Alba.CsCss.Style 7 | { 8 | [DebuggerDisplay ("{mXValue}, {mYValue} ...")] 9 | internal class CssValuePairList 10 | { 11 | internal CssValue mXValue, mYValue; 12 | internal CssValuePairList mNext; 13 | 14 | // Public interface 15 | 16 | internal static IEnumerable TraverseList (CssValuePairList @this) 17 | { 18 | return @this.TraverseList(i => i.mNext).Select(i => new CssValuePair { mXValue = i.mXValue, mYValue = i.mYValue }); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssRule.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | public abstract class CssRule 4 | { 5 | private CssStyleSheet mSheet; 6 | 7 | internal virtual void SetStyleSheet (CssStyleSheet aSheet) 8 | { 9 | mSheet = aSheet; 10 | } 11 | 12 | internal CssStyleSheet GetStyleSheet () 13 | { 14 | return mSheet; 15 | } 16 | 17 | internal abstract CssRuleKind GetKind (); 18 | 19 | // My 20 | 21 | internal virtual void Fix () 22 | {} 23 | 24 | // Public interface 25 | 26 | public CssRuleKind Kind 27 | { 28 | get { return GetKind(); } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssPageRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay (@"@page \{ {mDeclaration.DebugDisplayCount,nq} \}")] 6 | public class CssPageRule : CssRule 7 | { 8 | private readonly CssDeclaration mDeclaration; 9 | 10 | internal CssPageRule (CssDeclaration aDeclaration) 11 | { 12 | mDeclaration = aDeclaration; 13 | } 14 | 15 | internal override CssRuleKind GetKind () 16 | { 17 | return CssRuleKind.Page; 18 | } 19 | 20 | // Public interface 21 | 22 | public CssDeclaration Declaration 23 | { 24 | get { return mDeclaration; } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/ReferenceEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | 4 | namespace Alba.CsCss.Internal 5 | { 6 | internal class ReferenceEqualityComparer : IEqualityComparer 7 | { 8 | private static ReferenceEqualityComparer _default; 9 | 10 | public static IEqualityComparer Default 11 | { 12 | get { return _default ?? (_default = new ReferenceEqualityComparer()); } 13 | } 14 | 15 | public bool Equals (T x, T y) 16 | { 17 | return ReferenceEquals(x, y); 18 | } 19 | 20 | public int GetHashCode (T obj) 21 | { 22 | return RuntimeHelpers.GetHashCode(obj); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/CssMediaExpression.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | public class CssMediaExpression 4 | { 5 | internal CssMediaFeature mFeature; 6 | internal RangeType mRange; 7 | internal CssValue mValue; 8 | 9 | // Public interface 10 | 11 | public CssMediaFeature Feature 12 | { 13 | get { return mFeature; } 14 | } 15 | 16 | public RangeType Range 17 | { 18 | get { return mRange; } 19 | } 20 | 21 | public CssValue Value 22 | { 23 | get { return mValue; } 24 | } 25 | 26 | public enum RangeType 27 | { 28 | Min, 29 | Max, 30 | Equal 31 | }; 32 | } 33 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/ReduceNumberCalcOps.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Alba.CsCss.Internal; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | internal class ReduceNumberCalcOps : BasicFloatCalcOps /*, CssValueInputCalcOps*/, ICalcOps 7 | { 8 | public float ComputeLeafValue (CssValue aValue) 9 | { 10 | Debug.Assert(aValue.GetUnit() == CssUnit.Number, "unexpected unit"); 11 | return aValue.GetFloatValue(); 12 | } 13 | 14 | public float ComputeNumber (CssValue aValue) 15 | { 16 | return CommonUtil.ComputeCalc(aValue, this); 17 | } 18 | 19 | public CssUnit GetUnit (CssValue aValue) 20 | { 21 | return aValue.GetUnit(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValueTriplet.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay ("{mXValue}, {mYValue}, {mZValue}")] 6 | public class CssValueTriplet 7 | { 8 | internal CssValue mXValue, mYValue, mZValue; 9 | 10 | internal void SetBothValuesTo (CssValue aValue) 11 | { 12 | mXValue = mYValue = mZValue = aValue; 13 | } 14 | 15 | // Public interface 16 | 17 | public CssValue X 18 | { 19 | get { return mXValue; } 20 | } 21 | 22 | public CssValue Y 23 | { 24 | get { return mYValue; } 25 | } 26 | 27 | public CssValue Z 28 | { 29 | get { return mZValue; } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSProps.CSSFontDescList.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.Collections.Generic; 6 | using Alba.CsCss.Internal.Extensions; 7 | 8 | namespace Alba.CsCss.Style 9 | { 10 | internal partial class nsCSSProps 11 | { 12 | private static readonly string[] kCSSRawFontDescs = { 13 | "font-family", 14 | "font-style", 15 | "font-weight", 16 | "font-stretch", 17 | "src", 18 | "unicode-range", 19 | "-moz-font-feature-settings", 20 | "-moz-font-language-override", 21 | }; 22 | 23 | private static readonly Dictionary gFontDescTable = kCSSRawFontDescs.ToCaseInsensitiveNameTable(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Alba.CsCss/Common/Original/nsNameSpace.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss 6 | { 7 | internal class nsNameSpace 8 | { 9 | public const int None = 0; 10 | public const int Unknown = -1; 11 | public const int XMLNS = 1; // not really a namespace, but it needs to play the game 12 | public const int XML = 2; 13 | public const int XHTML = 3; 14 | public const int XLink = 4; 15 | public const int XSLT = 5; 16 | public const int XBL = 6; 17 | public const int MathML = 7; 18 | public const int RDF = 8; 19 | public const int XUL = 9; 20 | public const int SVG = 10; 21 | public const int LastBuiltin = 10; // last 'built-in' namespace 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/ICalcOps.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable TypeParameterCanBeVariant 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | using TUnit = CssUnit; 6 | 7 | // Here TInput is CssValue and TResult is float, but original code contains more combinations. 8 | internal interface ICalcOps 9 | where TInput : ICalcOpsInput 10 | { 11 | TUnit GetUnit (TInput aValue); 12 | TResult MergeAdditive (TUnit aCalcFunction, TResult aValue1, TResult aValue2); 13 | TResult MergeMultiplicativeL (TUnit aCalcFunction, TResult aValue1, TResult aValue2); 14 | TResult MergeMultiplicativeR (TUnit aCalcFunction, TResult aValue1, TResult aValue2); 15 | TResult ComputeLeafValue (TInput aValue); 16 | TResult ComputeNumber (TInput aValue); 17 | } 18 | } -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Original/gfxFontConstants.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | var T4 = GetT4(); 7 | T4.GenerateFile("nsFont.conv.cs", () => GenerateFontConstants(source)); 8 | T4.Process(); 9 | #> 10 | 11 | <#+ void GenerateFontConstants (string source) { #> 12 | // 13 | // Generated file. Do not edit manually. 14 | // 15 | 16 | namespace Alba.CsCss.Gfx 17 | { 18 | internal partial class nsFont 19 | { 20 | <#+ foreach (Match m in source.ReMatches(@"#define NS_FONT_(?\w+) (?.*)")) { #> 21 | public const int <#=m.Get("Name")#> = <#=m.Get("Value")#>; 22 | <#+ } #> 23 | } 24 | } 25 | <#+ } /* void GenerateFontConstants */ #> 26 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssFontFaceRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay (@"@font-face \{ font-family: {mDecl.mFamily}; src: {mDecl.mSrc} \}")] 6 | public class CssFontFaceRule : CssRule 7 | { 8 | private readonly CssFontFace mDecl = new CssFontFace(); 9 | 10 | internal CssFontFaceRule () 11 | {} 12 | 13 | internal void SetDesc (nsCSSFontDesc aDescId, CssValue aValue) 14 | { 15 | mDecl.SetValue(aDescId, aValue); 16 | } 17 | 18 | internal override CssRuleKind GetKind () 19 | { 20 | return CssRuleKind.FontFace; 21 | } 22 | 23 | // Public interface 24 | 25 | public CssFontFace Font 26 | { 27 | get { return mDecl; } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Alba.CsCss/Alba.CsCss.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $id$ 5 | $version$ 6 | Alba.CsCss Stylesheet Parser 7 | $author$ 8 | $author$ 9 | https://github.com/Athari/CsCss/blob/master/License.md 10 | https://github.com/Athari/CsCss 11 | https://raw.github.com/Athari/CsCss/master/.nuget/css.png 12 | false 13 | $description$ 14 | 15 | CSS CSS3 Style Stylesheet Parser Lexer Scanner Parse Syntax LINQ 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssCharsetRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Text; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"@charset ""{mEncoding}\""")] 7 | public class CssCharsetRule : CssRule 8 | { 9 | private readonly string mEncoding; 10 | 11 | internal CssCharsetRule (string aEncoding) 12 | { 13 | mEncoding = aEncoding; 14 | } 15 | 16 | internal override CssRuleKind GetKind () 17 | { 18 | return CssRuleKind.Charset; 19 | } 20 | 21 | // Public interface 22 | 23 | public string EncodingName 24 | { 25 | get { return mEncoding; } 26 | } 27 | 28 | public Encoding Encoding 29 | { 30 | get { return Encoding.GetEncoding(mEncoding); } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/StyleRule.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | var T4 = GetT4(); 7 | T4.GenerateFile("CssAttrFunction.conv.cs", () => GenerateAttrFunc(source)); 8 | T4.Process(); 9 | #> 10 | 11 | <#+ void GenerateAttrFunc (string source) { #> 12 | // 13 | // Generated file. Do not edit manually. 14 | // 15 | 16 | namespace Alba.CsCss.Style 17 | { 18 | public enum CssAttrFunction 19 | { 20 | <#+ foreach (Match m in source.ReMatches(@"#define NS_ATTR_FUNC_(?\w+) +(?-?\d+)(? *// .*)?")) { #> 21 | <#=ToPascalId(m.Get("Name")).Replace("match", "Match")#> = <#=m.Get("Value")#>,<#=m.Get("Comment").Trim()#> 22 | <#+ } #> 23 | } 24 | } 25 | <#+ } /* void GenerateAttrFunc */ #> 26 | -------------------------------------------------------------------------------- /Build/CommonTests.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $(SolutionDir)\bin\DebugTests\ 10 | $(SolutionDir)\obj\DebugTests\$(AssemblyName)\ 11 | 12 | 13 | $(SolutionDir)\bin\ReleaseTests\ 14 | $(SolutionDir)\obj\ReleaseTests\$(AssemblyName)\ 15 | 16 | -------------------------------------------------------------------------------- /Alba.CsCss/Common/Original/nsINameSpaceManager.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | var T4 = GetT4(); 7 | T4.GenerateFile("nsNameSpace.conv.cs", () => GenerateNameSpace(source)); 8 | T4.Process(); 9 | #> 10 | 11 | <#+ void GenerateNameSpace (string source) { #> 12 | // 13 | // Generated file. Do not edit manually. 14 | // 15 | 16 | namespace Alba.CsCss 17 | { 18 | internal class nsNameSpace 19 | { 20 | public const int None = 0; 21 | <#+ foreach (Match m in source.ReMatches(@"#define kNameSpaceID_(?\w+) +(?-?\d+)(? *// .*)?")) { #> 22 | public const int <#=m.Get("Name")#> = <#=m.Get("Value")#>;<#=m.Get("Comment")#> 23 | <#+ } #> 24 | } 25 | } 26 | <#+ } /* void GenerateNameSpace */ #> 27 | -------------------------------------------------------------------------------- /Alba.CsCss/Globalization/CssResources.g.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Resources; 3 | 4 | namespace Alba.CsCss.Globalization 5 | { 6 | internal static class CssResources 7 | { 8 | private static ResourceManager _manager; 9 | 10 | public static CultureInfo Culture { get; set; } 11 | 12 | public static ResourceManager ResourceManager 13 | { 14 | get { return _manager ?? (_manager = new ResourceManager("Alba.CsCss.Globalization.CssResources", typeof(CssResources).Assembly)); } 15 | } 16 | 17 | public static string GetString (string name) 18 | { 19 | return ResourceManager.GetString(name, Culture); 20 | } 21 | 22 | public static string FormatString (string name, params object[] args) 23 | { 24 | return string.Format(Culture, GetString(name), args); 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/nsMediaList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | internal class nsMediaList 6 | { 7 | private readonly List mArray = new List(); 8 | private CssStyleSheet mStyleSheet; 9 | 10 | internal void AppendQuery (CssMediaQuery query) 11 | { 12 | mArray.Add(query); 13 | } 14 | 15 | internal void Clear () 16 | { 17 | mArray.Clear(); 18 | } 19 | 20 | internal int Count () 21 | { 22 | return mArray.Count; 23 | } 24 | 25 | internal void SetStyleSheet (CssStyleSheet aSheet) 26 | { 27 | mStyleSheet = aSheet; 28 | } 29 | 30 | // Public interface 31 | 32 | internal IList Queries 33 | { 34 | get { return mArray; } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsAtomList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Alba.CsCss.Internal.Extensions; 5 | 6 | namespace Alba.CsCss 7 | { 8 | internal class nsAtomList 9 | { 10 | public string mAtom; 11 | public nsAtomList mNext; 12 | 13 | public nsAtomList () 14 | {} 15 | 16 | public nsAtomList (string aAtom) 17 | { 18 | mAtom = String.Intern(aAtom); 19 | } 20 | 21 | internal static void AddItem (ref nsAtomList @this, nsAtomList item) 22 | { 23 | while (@this != null) 24 | @this = @this.mNext; 25 | @this = item; 26 | } 27 | 28 | // Public interface 29 | 30 | internal static IEnumerable TraverseList (nsAtomList @this) 31 | { 32 | return @this.TraverseList(i => i.mNext).Select(i => i.mAtom); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssImportRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"@import ""{mUrlSpec}""")] 7 | public class CssImportRule : CssRule 8 | { 9 | private readonly nsMediaList mMedia; 10 | private readonly string mUrlSpec; 11 | 12 | internal CssImportRule (nsMediaList aMedia, string aUrlSpec) 13 | { 14 | mMedia = aMedia; 15 | mUrlSpec = aUrlSpec; 16 | } 17 | 18 | internal override CssRuleKind GetKind () 19 | { 20 | return CssRuleKind.Import; 21 | } 22 | 23 | // Public interface 24 | 25 | public string Uri 26 | { 27 | get { return mUrlSpec; } 28 | } 29 | 30 | public IList MediaQueries 31 | { 32 | get { return mMedia.Queries; } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Original/nsColorNameList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _gfxColorNames; 3 | 4 | IEnumerable GetGfxColorNamesFromSource (string source) { 5 | 6 | foreach (Match m in source.ReMatches( 7 | @"(?x)GFX_COLOR\( 8 | (?\w+), (?$) 9 | \)".Replace(",", @",\ *").Replace("$", sArgs))) { 10 | var desc = new GfxColorName { 11 | Name = m.Get("Name").Trim(), 12 | Value = m.Get("Value").Trim(), 13 | }; 14 | yield return desc; 15 | } 16 | } 17 | 18 | IEnumerable GetGfxColorNames () { 19 | if (_gfxColorNames == null) 20 | _gfxColorNames = GetGfxColorNamesFromSource(LoadText("nsColorNameList.h")).ToList(); 21 | return _gfxColorNames; 22 | } 23 | 24 | class GfxColorName 25 | { 26 | public string Name, Value; 27 | } 28 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSFontDescList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _cssFontDescs; 3 | 4 | IEnumerable GetCssFontDescsFromSource (string source) { 5 | 6 | foreach (Match m in source.ReMatches( 7 | @"(?x)CSS_FONT_DESC\( 8 | (?$), (?$) 9 | \)".Replace(",", @",\ *").Replace("$", sArgs))) { 10 | var desc = new CssFontDesc { 11 | Name = m.Get("Name").Trim(), 12 | Method = m.Get("Method").Trim(), 13 | }; 14 | yield return desc; 15 | } 16 | } 17 | 18 | IEnumerable GetCssFontDescs () { 19 | if (_cssFontDescs == null) 20 | _cssFontDescs = GetCssFontDescsFromSource(LoadText("nsCSSFontDescList.h")).ToList(); 21 | return _cssFontDescs; 22 | } 23 | 24 | class CssFontDesc 25 | { 26 | public string Name, Method; 27 | } 28 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssParserErrorEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | public class CssParserErrorEventArgs : EventArgs 6 | { 7 | private readonly ErrorReporter mReporter; 8 | 9 | internal CssParserErrorEventArgs (ErrorReporter aReporter) 10 | { 11 | mReporter = aReporter; 12 | } 13 | 14 | public string Message 15 | { 16 | get { return mReporter.mError.ToString(); } 17 | } 18 | 19 | public Uri Uri 20 | { 21 | get { return mReporter.mUri; } 22 | } 23 | 24 | public string Line 25 | { 26 | get { return mReporter.mErrorLine; } 27 | } 28 | 29 | public int LineNumber 30 | { 31 | get { return mReporter.mErrorLineNumber - 1; } 32 | } 33 | 34 | public int ColumnNumber 35 | { 36 | get { return mReporter.mErrorColumnNumber; } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Alba.CsCss/T4/ResX.ttinclude: -------------------------------------------------------------------------------- 1 | <#@ include file="Include.ttinclude" 2 | #><#@ include file="$(SolutionDir)\Alba.Framework\Alba.Framework.CodeGeneration\T4\ResX.ttinclude" 3 | #><#+ 4 | void GenerateResxFromProperties (string fileName = null) 5 | { 6 | IEnumerable> lines = LoadText(ext: "properties") 7 | .ReSplit(@"\r?\n") 8 | .Select(s => s.Trim()) 9 | .Where(s => !string.IsNullOrEmpty(s) && !s.StartsWith("#")) 10 | .Select(s => { 11 | s = s.Contains("%1") ? s.Replace("}", "}}").Replace("{", "{{") : s; // { -> {{ & } -> }} for string.Format 12 | return s 13 | .ReReplace(@"%(\d+)\$.", m => string.Format("{{{0}}}", m.Get().ToInt32Inv() - 1)) // %2$S -> {1} 14 | .Split(new[] { '=' }, 2); 15 | }) 16 | .Select(ss => new KeyValuePair(ss[0], ss[1])); 17 | GenerateResx(lines, fileName); 18 | } 19 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSValue.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | source = source 7 | // whitespace 8 | .ReReplace(@"\r", "") 9 | // common preprocessor 10 | .ReReplace(@"\\\n", ""); 11 | 12 | var T4 = GetT4(); 13 | T4.GenerateFile("CssUnit.conv.cs", () => GenerateCssUnit(source)); 14 | T4.Process(); 15 | #> 16 | <#+ 17 | void GenerateCssUnit (string source) { 18 | #> 19 | // 20 | // Generated file. Do not edit manually. 21 | // 22 | 23 | // TODO Convert comments to doc-comments 24 | namespace Alba.CsCss.Style 25 | { 26 | public enum CssUnit 27 | { 28 | <#= source.ReMatchGet(@"(?s)enum nsCSSUnit {\n(.*?)\n}") 29 | .ReReplace(@"eCSSUnit_(\w+)", ToPascalId) 30 | .Indent(6).NormalizeWhitespace() #> 31 | } 32 | } 33 | <#+ 34 | } // GenerateCssUnit 35 | #> 36 | -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/ListExts.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Alba.CsCss.Internal.Extensions 4 | { 5 | internal static class ListExts 6 | { 7 | public static T AppendElement (this IList @this, T item) 8 | { 9 | @this.Add(item); 10 | return item; 11 | } 12 | 13 | public static T AppendElement (this IList @this) where T : new() 14 | { 15 | var item = new T(); 16 | @this.Add(item); 17 | return item; 18 | } 19 | 20 | public static T ElementAt (this IList @this, int index) 21 | { 22 | return @this[index]; 23 | } 24 | 25 | public static void RemoveElementAt (this IList @this, int index) 26 | { 27 | @this.RemoveAt(index); 28 | } 29 | 30 | public static int Length (this IList @this) 31 | { 32 | return @this.Count; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSKeywordList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _cssKeywords; 3 | 4 | IEnumerable GetCssKeywordsFromSource (string source) { 5 | 6 | foreach (Match m in source.ReMatches( 7 | @"(?mx)^CSS_KEY\( 8 | (?$), (?$) 9 | \)".Replace(",", @",\ *").Replace("$", sArgs))) { 10 | var desc = new CssKeyword { 11 | Name = m.Get("Name").Trim(), 12 | Id = m.Get("Id").Trim(), 13 | }; 14 | yield return desc; 15 | } 16 | } 17 | 18 | IEnumerable GetCssKeywords () { 19 | if (_cssKeywords == null) 20 | _cssKeywords = GetCssKeywordsFromSource(LoadText("nsCSSKeywordList.h")).ToList(); 21 | return _cssKeywords; 22 | } 23 | 24 | class CssKeyword 25 | { 26 | public string Name, Id; 27 | 28 | public bool IsExtension { get { return Name.StartsWith("-"); } } 29 | } 30 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssKeyframeRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"{mKeys[0]}% \{ {mDeclaration.DebugDisplayCount,nq} \}")] 7 | public class CssKeyframeRule : CssRule 8 | { 9 | private readonly List mKeys; 10 | private readonly CssDeclaration mDeclaration; 11 | 12 | internal CssKeyframeRule (List aKeys, CssDeclaration aDeclaration) 13 | { 14 | mKeys = aKeys; 15 | mDeclaration = aDeclaration; 16 | } 17 | 18 | internal override CssRuleKind GetKind () 19 | { 20 | return CssRuleKind.Keyframe; 21 | } 22 | 23 | // Public interface 24 | 25 | public IList Keys 26 | { 27 | get { return mKeys; } 28 | } 29 | 30 | public CssDeclaration Declaration 31 | { 32 | get { return mDeclaration; } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSPseudoElements.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | internal static partial class nsCSSPseudoElements 4 | { 5 | public static CssPseudoElement GetPseudoType (string aAtom) 6 | { 7 | CssPseudoElement res; 8 | if (sPseudoElements.TryGetValue(aAtom, out res)) 9 | return res; 10 | if (nsCSSAnonBoxes.IsAnonBox(aAtom)) { 11 | #if MOZ_XUL 12 | if (nsCSSAnonBoxes.IsTreePseudoElement(aAtom)) 13 | return CssPseudoElement.XULTree; 14 | #endif 15 | return CssPseudoElement.AnonBox; 16 | } 17 | return CssPseudoElement.NotPseudoElement; 18 | } 19 | 20 | public static bool IsCSS2PseudoElement (string aAtom) 21 | { 22 | bool result = aAtom == after || 23 | aAtom == before || 24 | aAtom == firstLetter || 25 | aAtom == firstLine; 26 | return result; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssPropertySet.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | internal class CssPropertySet 8 | { 9 | private readonly BitArray mProperties = new BitArray((int)CssProperty.PropertyCountNoShorthands); 10 | 11 | public void AddProperty (CssProperty aProperty) 12 | { 13 | mProperties[(int)aProperty] = true; 14 | } 15 | 16 | public void RemoveProperty (CssProperty aProperty) 17 | { 18 | mProperties[(int)aProperty] = false; 19 | } 20 | 21 | public bool HasProperty (CssProperty aProperty) 22 | { 23 | return mProperties[(int)aProperty]; 24 | } 25 | 26 | public void Empty () 27 | { 28 | mProperties.SetAll(false); 29 | } 30 | 31 | [Conditional ("DEBUG")] 32 | public void AssertIsEmpty (string message) 33 | { 34 | Debug.Assert(mProperties.Cast().All(v => !v), message); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssGroupRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | public abstract class CssGroupRule : CssRule 7 | { 8 | private readonly List mRules = new List(); 9 | 10 | internal void AppendStyleRule (CssRule aRule) 11 | { 12 | mRules.Add(aRule); 13 | } 14 | 15 | internal override void SetStyleSheet (CssStyleSheet aSheet) 16 | { 17 | if (aSheet == GetStyleSheet()) 18 | return; 19 | foreach (CssRule rule in mRules) 20 | if (rule != null) 21 | rule.SetStyleSheet(aSheet); 22 | base.SetStyleSheet(aSheet); 23 | } 24 | 25 | // Public interface 26 | 27 | public IList Rules 28 | { 29 | get { return mRules; } 30 | } 31 | 32 | public IEnumerable GetRules () where TRule : CssRule 33 | { 34 | return mRules.OfType(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssToken.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using Alba.CsCss.Internal.Extensions; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | internal partial class CssToken 8 | { 9 | internal readonly StringBuilder mIdent = new StringBuilder(); 10 | internal CssTokenType mType = CssTokenType.Whitespace; 11 | internal float mNumber; 12 | internal Int32 mInteger; 13 | internal Int32 mInteger2; 14 | internal char mSymbol; 15 | internal bool mIntegerValid; 16 | internal bool mHasSign; 17 | 18 | // TODO Avoid multiple calls to CssToken.ToString (cache string after calling Next[URL]?) 19 | internal string mIdentStr 20 | { 21 | get { return mIdent.ToString(); } 22 | set 23 | { 24 | mIdent.Clear(); 25 | mIdent.Append(value); 26 | } 27 | } 28 | 29 | internal bool IsSymbol (char aSymbol) 30 | { 31 | return mType == CssTokenType.Symbol && mSymbol == aSymbol; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/nsMediaFeaturesH.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | 7 | var T4 = GetT4(); 8 | foreach (Match m in source.ReMatches(@"(?ns)enum (?\w+) {(?.*?)};")) 9 | T4.GenerateFile("CssMediaFeature.{0}.conv.cs".Fmt(m.Get("Class")), () => GenerateMediaFeatureEnum(m.Get("Code"), m.Get("Class"))); 10 | T4.Process(); 11 | #> 12 | <#+ 13 | void GenerateMediaFeatureEnum (string source, string enumName) { 14 | #> 15 | // 16 | // Generated file. Do not edit manually. 17 | // 18 | // ReSharper disable RedundantUsingDirective 19 | // ReSharper disable RedundantCast 20 | 21 | namespace Alba.CsCss.Style 22 | { 23 | public partial class CssMediaFeature 24 | { 25 | public enum <#=enumName#> { 26 | <#= source.ReReplace(@"\be(\w+)\b", "$1").NormalizeWhitespace().Unindent(8).Trim().Indent(12) #> 27 | } 28 | } 29 | } 30 | <#+ 31 | } // GenerateMediaFeatureEnum 32 | #> 33 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssSupportsRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Text; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"@supports {mCondition} \{ ({mRules.Count}) \}")] 7 | public class CssSupportsRule : CssGroupRule 8 | { 9 | private readonly bool mUseGroup; 10 | private readonly string mCondition; 11 | 12 | internal CssSupportsRule (ref bool aConditionMet, StringBuilder aCondition) 13 | { 14 | mUseGroup = aConditionMet; 15 | mCondition = aCondition.ToString(); 16 | } 17 | 18 | internal static bool PrefEnabled () 19 | { 20 | return true; 21 | } 22 | 23 | internal override CssRuleKind GetKind () 24 | { 25 | return CssRuleKind.Supports; 26 | } 27 | 28 | // Public interface 29 | 30 | public bool IsSupported 31 | { 32 | get { return mUseGroup; } 33 | } 34 | 35 | public string Condition 36 | { 37 | get { return mCondition; } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssMediaRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"@media ... \{ ({mRules.Count}) \}")] 7 | public class CssMediaRule : CssGroupRule 8 | { 9 | private nsMediaList mMedia; 10 | 11 | internal CssMediaRule () 12 | {} 13 | 14 | internal void SetMedia (nsMediaList aMedia) 15 | { 16 | mMedia = aMedia; 17 | } 18 | 19 | internal override CssRuleKind GetKind () 20 | { 21 | return CssRuleKind.Media; 22 | } 23 | 24 | internal override void SetStyleSheet (CssStyleSheet aSheet) 25 | { 26 | if (mMedia != null) { 27 | mMedia.SetStyleSheet(null); 28 | mMedia.SetStyleSheet(aSheet); 29 | } 30 | base.SetStyleSheet(aSheet); 31 | } 32 | 33 | // Public interface 34 | 35 | public IList MediaQueries 36 | { 37 | get { return mMedia.Queries; } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssNamespaceRule.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay (@"@namespace {mPrefix} ""{mUrlSpec}""")] 6 | public class CssNamespaceRule : CssRule 7 | { 8 | private readonly string mPrefix; 9 | private readonly string mUrlSpec; 10 | 11 | internal CssNamespaceRule (string aPrefix, string aUrlSpec) 12 | { 13 | mPrefix = aPrefix; 14 | mUrlSpec = aUrlSpec; 15 | } 16 | 17 | internal string GetPrefix () 18 | { 19 | return mPrefix; 20 | } 21 | 22 | internal string GetURLSpec () 23 | { 24 | return mUrlSpec; 25 | } 26 | 27 | internal override CssRuleKind GetKind () 28 | { 29 | return CssRuleKind.Namespace; 30 | } 31 | 32 | // Public interface 33 | 34 | public string Prefix 35 | { 36 | get { return mPrefix; } 37 | } 38 | 39 | public string Uri 40 | { 41 | get { return mUrlSpec; } 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoElementList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _cssPseudoElements; 3 | 4 | IEnumerable GetCssPseudoElementsFromSource (string source) 5 | { 6 | foreach (Match m in source.ReMatches( 7 | @"(?x)CSS_PSEUDO_ELEMENT\( 8 | (?$), (?$), (?$) 9 | \)".Replace(",", @",\s*").Replace("$", sArgs))) { 10 | var el = new CssPseudoElement { 11 | Name = m.Get("Name").Trim(), 12 | Value = m.Get("Value").Trim(), 13 | Flags = m.Get("Flags").ReReplace(@"\s+", " ").Trim(), 14 | }; 15 | yield return el; 16 | } 17 | } 18 | 19 | IEnumerable GetCssPseudoElements () 20 | { 21 | if (_cssPseudoElements == null) 22 | _cssPseudoElements = GetCssPseudoElementsFromSource(LoadText("nsCSSPseudoElementList.h")).ToList(); 23 | return _cssPseudoElements; 24 | } 25 | 26 | class CssPseudoElement 27 | { 28 | public string Name, Value, Flags; 29 | } 30 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Calc/BasicFloatCalcOps.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | internal abstract class BasicFloatCalcOps 6 | { 7 | public float MergeAdditive (CssUnit aCalcFunction, float aValue1, float aValue2) 8 | { 9 | Debug.Assert(aCalcFunction == CssUnit.CalcPlus || aCalcFunction == CssUnit.CalcMinus, "unexpected unit"); 10 | return aCalcFunction == CssUnit.CalcPlus ? aValue1 + aValue2 : aValue1 - aValue2; 11 | } 12 | 13 | public float MergeMultiplicativeL (CssUnit aCalcFunction, float aValue1, float aValue2) 14 | { 15 | Debug.Assert(aCalcFunction == CssUnit.CalcTimesL, "unexpected unit"); 16 | return aValue1 * aValue2; 17 | } 18 | 19 | public float MergeMultiplicativeR (CssUnit aCalcFunction, float aValue1, float aValue2) 20 | { 21 | Debug.Assert(aCalcFunction == CssUnit.CalcTimesR || aCalcFunction == CssUnit.CalcDivided, "unexpected unit"); 22 | return aCalcFunction == CssUnit.CalcTimesR ? aValue1 * aValue2 : aValue1 / aValue2; 23 | } 24 | }; 25 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/LookAndFeel.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | 7 | var T4 = GetT4(); 8 | T4.GenerateFile("LookAndFeel.conv.cs", () => GenerateCssProps(source)); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateCssProps (string source) { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | namespace Alba.CsCss.Style 18 | { 19 | internal class LookAndFeel 20 | { 21 | <#+ foreach (string array in ConvertEnums(source)) { #> 22 | <#= array.Indent(8).NormalizeWhitespace() #> 23 | 24 | <#+ } #> 25 | } 26 | } 27 | <#+ } /* void GenerateCssProps */ #> 28 | 29 | <#+ 30 | IEnumerable ConvertEnums (string source) 31 | { 32 | foreach (Match m in source.ReMatches(@"(?ns)enum (?\w+) {(?.*?)};")) 33 | yield return m.Result("public enum ${Type} {${Code}};") 34 | .ReReplace(@"\be{0}(ID)?_".Fmt(m.Get("Type").RemovePostfixSafe("ID")), ""); // remove enum prefix 35 | } 36 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/DictionaryExts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Alba.CsCss.Internal.Extensions 5 | { 6 | /// Copied from Alba.Framework to avoid referencing. 7 | internal static class DictionaryExts 8 | { 9 | public static TValue GetOrDefault (this IDictionary @this, TKey key, TValue defaultValue = default(TValue)) 10 | { 11 | TValue value; 12 | return @this.TryGetValue(key, out value) ? value : defaultValue; 13 | } 14 | 15 | public static TValue GetOrDefault (this IDictionary @this, TKey key, Func getDefaultValue) 16 | { 17 | TValue value; 18 | return @this.TryGetValue(key, out value) ? value : getDefaultValue(); 19 | } 20 | 21 | public static TValue? GetNullableOrDefault (this IDictionary @this, TKey key, TValue? defaultValue = null) 22 | where TValue : struct 23 | { 24 | TValue value; 25 | return @this.TryGetValue(key, out value) ? value : defaultValue; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsGkAtoms.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss 2 | { 3 | // no point in converting all constants 4 | internal class nsGkAtoms 5 | { 6 | public const string all = "all"; 7 | public const string _not = "not"; 8 | public const string only = "only"; 9 | public const string width = "width"; 10 | public const string height = "height"; 11 | public const string deviceWidth = "device-width"; 12 | public const string deviceHeight = "device-height"; 13 | public const string orientation = "orientation"; 14 | public const string aspectRatio = "aspect-ratio"; 15 | public const string deviceAspectRatio = "device-aspect-ratio"; 16 | public const string color = "color"; 17 | public const string colorIndex = "color-index"; 18 | public const string monochrome = "monochrome"; 19 | public const string resolution = "resolution"; 20 | public const string scan = "scan"; 21 | public const string grid = "grid"; 22 | public const string _moz_device_pixel_ratio = "-moz-device-pixel-ratio"; 23 | public const string _moz_device_orientation = "-moz-device-orientation"; 24 | } 25 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSProps.CSSPropAliasList.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | internal partial class nsCSSProps 8 | { 9 | private static readonly CssProperty[] gAliases = { 10 | CssProperty.TransformOrigin, 11 | CssProperty.PerspectiveOrigin, 12 | CssProperty.Perspective, 13 | CssProperty.TransformStyle, 14 | CssProperty.BackfaceVisibility, 15 | CssProperty.BorderImage, 16 | CssProperty.Transition, 17 | CssProperty.TransitionDelay, 18 | CssProperty.TransitionDuration, 19 | CssProperty.TransitionProperty, 20 | CssProperty.TransitionTimingFunction, 21 | CssProperty.Animation, 22 | CssProperty.AnimationDelay, 23 | CssProperty.AnimationDirection, 24 | CssProperty.AnimationDuration, 25 | CssProperty.AnimationFillMode, 26 | CssProperty.AnimationIterationCount, 27 | CssProperty.AnimationName, 28 | CssProperty.AnimationPlayState, 29 | CssProperty.AnimationTimingFunction, 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssDocumentRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | using Alba.CsCss.Internal.Extensions; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | // TODO support for @document 8 | [DebuggerDisplay (@"@document {mURLs.url} \{ ({mRules.Count}) \}")] 9 | internal class CssDocumentRule : CssGroupRule 10 | { 11 | private URL mURLs; 12 | 13 | internal CssDocumentRule () 14 | {} 15 | 16 | internal void SetURLs (URL aURLs) 17 | { 18 | mURLs = aURLs; 19 | } 20 | 21 | internal override CssRuleKind GetKind () 22 | { 23 | return CssRuleKind.Document; 24 | } 25 | 26 | // Public interface 27 | 28 | public IEnumerable Uris 29 | { 30 | get { return mURLs.TraverseList(i => i.next); } 31 | } 32 | 33 | public enum Function 34 | { 35 | eURL, 36 | eURLPrefix, 37 | eDomain, 38 | eRegExp 39 | }; 40 | 41 | public class URL 42 | { 43 | public Function func; 44 | public string url; 45 | public URL next; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssSelectorGroup.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Alba.CsCss.Internal.Extensions; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | public class CssSelectorGroup 7 | { 8 | internal CssSelectorGroup mNext; 9 | internal CssSelector mSelectors; 10 | internal int mWeight; 11 | 12 | internal CssSelectorGroup () 13 | {} 14 | 15 | internal CssSelector AddSelector (char aOperator) 16 | { 17 | var newSel = new CssSelector(); 18 | if (mSelectors != null) 19 | mSelectors.SetOperator(aOperator); 20 | newSel.mNext = mSelectors; 21 | mSelectors = newSel; 22 | return newSel; 23 | } 24 | 25 | // Public interface 26 | 27 | public IEnumerable Selectors 28 | { 29 | get { return CssSelector.TraverseList(mSelectors); } 30 | } 31 | 32 | public int Weight 33 | { 34 | get { return mWeight; } 35 | } 36 | 37 | internal static IEnumerable TraverseList (CssSelectorGroup @this) 38 | { 39 | return @this.TraverseList(i => i.mNext); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPropAliasList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _cssPropAliases; 3 | 4 | void LoadCssPropAliases () { 5 | string source = LoadText("nsCSSPropAliasList.h"); 6 | _cssPropAliases = GetCssPropAliasesFromSource(source).ToList(); 7 | } 8 | 9 | IEnumerable GetCssPropAliasesFromSource (string source) { 10 | 11 | foreach (Match m in source.ReMatches( 12 | @"(?x)CSS_PROP_ALIAS\( 13 | (?$), (?$), (?$), (?$) 14 | \)".Replace(",", @",\ *").Replace("$", sArgs))) { 15 | var prop = new CssPropAlias { 16 | Name = m.Get("Name").Trim(), 17 | Id = m.Get("Id").Trim(), 18 | Method = m.Get("Method").Trim(), 19 | Pref = m.Get("Pref").Trim(), 20 | }; 21 | yield return prop; 22 | } 23 | //WriteLine(source); 24 | } 25 | 26 | IEnumerable GetCssPropAliases () { 27 | if (_cssPropAliases == null) 28 | LoadCssPropAliases(); 29 | return _cssPropAliases; 30 | } 31 | 32 | class CssPropAlias 33 | { 34 | public string Name, Id, Method, Pref; 35 | } 36 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssStyle.cs: -------------------------------------------------------------------------------- 1 | using Alba.CsCss.Gfx; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | public partial class CssStyle 6 | { 7 | public const Side SideTop = Side.Top; 8 | public const Side SideRight = Side.Right; 9 | public const Side SideBottom = Side.Bottom; 10 | public const Side SideLeft = Side.Left; 11 | 12 | internal bool HALF_CORNER_IS_X (int var) 13 | { 14 | return var % 2 == 0; 15 | } 16 | 17 | internal int HALF_TO_FULL_CORNER (int var) 18 | { 19 | return var / 2; 20 | } 21 | 22 | internal int FULL_TO_HALF_CORNER (int var, int vert) 23 | { 24 | return var * 2 + (vert != 0 ? 1 : 0); 25 | } 26 | 27 | internal bool SIDE_IS_VERTICAL (int side) 28 | { 29 | return side % 2 != 0; 30 | } 31 | 32 | internal int SIDE_TO_FULL_CORNER (int side, int second) 33 | { 34 | return (side + (second != 0 ? 1 : 0)) % 4; 35 | } 36 | 37 | internal int SIDE_TO_HALF_CORNER (int side, int second, bool parallel) 38 | { 39 | return ((side + (second != 0 ? 1 : 0)) * 2 + (side + (parallel ? 0 : 1)) % 2) % 8; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPropAliasList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsCSSPropAliasList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsCSSPropAliasList.g.txt", () => GenerateCssPropAliasListText()); 8 | T4.GenerateFile("nsCSSProps.CSSPropAliasList.g.cs", () => GenerateCssProps()); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateCssPropAliasListText () { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | <#+ foreach (CssPropAlias prop in GetCssPropAliases()) { #> 18 | // 19 | // Name: <#= prop.Name #> 20 | // Id: <#= prop.Id #> 21 | // Method: <#= prop.Method #> 22 | // Pref: <#= prop.Pref #> 23 | <#+ } #> 24 | <#+ } /* void GenerateCssPropAliasListText */ #> 25 | 26 | <#+ void GenerateCssProps () { #> 27 | // 28 | // Generated file. Do not edit manually. 29 | // 30 | 31 | namespace Alba.CsCss.Style 32 | { 33 | internal partial class nsCSSProps 34 | { 35 | private static readonly CssProperty[] gAliases = { 36 | <#+ foreach (CssPropAlias prop in GetCssPropAliases()) { #> 37 | CssProperty.<#=ToPascalId(prop.Id)#>, 38 | <#+ } #> 39 | }; 40 | } 41 | } 42 | <#+ } /* void GenerateCssProps */ #> 43 | -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/StringExts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Internal.Extensions 5 | { 6 | internal static class StringExts 7 | { 8 | public static bool EqualsLiteral (this string @this, string value) 9 | { 10 | return string.Equals(@this, value, StringComparison.Ordinal); 11 | } 12 | 13 | internal static int Length (this string @this) 14 | { 15 | return @this.Length; 16 | } 17 | 18 | public static char First (this string @this) 19 | { 20 | return @this.Length > 0 ? @this[0] : '\0'; 21 | } 22 | 23 | internal static bool LowerCaseEqualsLiteral (this string @this, string value) 24 | { 25 | return string.Equals(@this, value, StringComparison.OrdinalIgnoreCase); 26 | } 27 | 28 | internal static bool LowerCaseEqualsASCII (this string @this, string value, int length) 29 | { 30 | Debug.Assert(value.Length == length); 31 | return string.Equals(@this, value, StringComparison.OrdinalIgnoreCase); 32 | } 33 | 34 | public static bool LowerCaseEqualsASCII (this string @this, string value) 35 | { 36 | return string.Equals(@this, value, StringComparison.OrdinalIgnoreCase); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Original/nsFont.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Gfx 6 | { 7 | internal partial class nsFont 8 | { 9 | public const int STYLE_NORMAL = 0; 10 | public const int STYLE_ITALIC = 1; 11 | public const int STYLE_OBLIQUE = 2; 12 | public const int WEIGHT_NORMAL = 400; 13 | public const int WEIGHT_BOLD = 700; 14 | public const int STRETCH_ULTRA_CONDENSED = (-4); 15 | public const int STRETCH_EXTRA_CONDENSED = (-3); 16 | public const int STRETCH_CONDENSED = (-2); 17 | public const int STRETCH_SEMI_CONDENSED = (-1); 18 | public const int STRETCH_NORMAL = 0; 19 | public const int STRETCH_SEMI_EXPANDED = 1; 20 | public const int STRETCH_EXPANDED = 2; 21 | public const int STRETCH_EXTRA_EXPANDED = 3; 22 | public const int STRETCH_ULTRA_EXPANDED = 4; 23 | public const int VARIANT_NORMAL = 0; 24 | public const int VARIANT_SMALL_CAPS = 1; 25 | public const int DECORATION_NONE = 0x0; 26 | public const int DECORATION_UNDERLINE = 0x1; 27 | public const int DECORATION_OVERLINE = 0x2; 28 | public const int DECORATION_LINE_THROUGH = 0x4; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSPseudoClasses.cs: -------------------------------------------------------------------------------- 1 | using Alba.CsCss.Internal.Extensions; 2 | 3 | // TODO Convert sources from nsCSSPseudoClasses.cpp instead of copypasting 4 | namespace Alba.CsCss.Style 5 | { 6 | internal static partial class nsCSSPseudoClasses 7 | { 8 | public static CssPseudoClass GetPseudoType (string aAtom) 9 | { 10 | return sPseudoClasses.GetOrDefault(aAtom, CssPseudoClass.NotPseudoClass); 11 | } 12 | 13 | public static bool HasSelectorListArg (CssPseudoClass aType) 14 | { 15 | return aType == CssPseudoClass.Any; 16 | } 17 | 18 | public static bool HasStringArg (CssPseudoClass aType) 19 | { 20 | return aType == CssPseudoClass.Lang || 21 | aType == CssPseudoClass.MozEmptyExceptChildrenWithLocalname || 22 | aType == CssPseudoClass.MozSystemMetric || 23 | aType == CssPseudoClass.MozLocaleDir || 24 | aType == CssPseudoClass.Dir; 25 | } 26 | 27 | public static bool HasNthPairArg (CssPseudoClass aType) 28 | { 29 | return aType == CssPseudoClass.NthChild || 30 | aType == CssPseudoClass.NthLastChild || 31 | aType == CssPseudoClass.NthOfType || 32 | aType == CssPseudoClass.NthLastOfType; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssUriValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Alba.CsCss.Internal; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | [DebuggerDisplay ("{mString}")] 8 | public class CssUriValue 9 | { 10 | internal Uri mURI; 11 | internal readonly Uri mReferrer; 12 | internal readonly string mString; 13 | internal readonly nsIPrincipal mOriginPrincipal; 14 | internal bool mURIResolved; 15 | 16 | internal CssUriValue (string aString, Uri aBaseURI, Uri aReferrer, nsIPrincipal aOriginPrincipal) 17 | { 18 | mString = aString; 19 | mURI = aBaseURI; 20 | mReferrer = aReferrer; 21 | mOriginPrincipal = aOriginPrincipal; 22 | mURIResolved = false; 23 | } 24 | 25 | internal Uri GetURI () 26 | { 27 | if (!mURIResolved) { 28 | Uri uri; 29 | CommonUtil.NS_NewURI(out uri, mString, null, mURI); 30 | mURI = uri; 31 | mURIResolved = true; 32 | } 33 | return mURI; 34 | } 35 | 36 | // Public interface 37 | 38 | public string OriginalUri 39 | { 40 | get { return mString; } 41 | } 42 | 43 | public Uri Uri 44 | { 45 | get { return GetURI(); } 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsIWidget.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | 7 | var T4 = GetT4(); 8 | T4.GenerateFile("nsStyle.nsIWidget.conv.cs", () => GenerateStyle(source)); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateStyle (string source) { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | namespace Alba.CsCss.Style 18 | { 19 | public partial class CssStyle 20 | { 21 | <#+ foreach (string define in ConvertStyleDefines(source)) { #> 22 | <#= define #> 23 | <#+ } #> 24 | } 25 | } 26 | <#+ } /* void GenerateStyle */ #> 27 | 28 | <#+ 29 | IEnumerable ConvertStyleDefines (string source) 30 | { 31 | foreach (Match m in source.ReMatches( 32 | @"(?imnx)^ 33 | \#define \ + 34 | NS_STYLE_ (?\w+) \ + # constant name with NS_STYLE_ prefix 35 | (?\(? (-?\d+ | 0x[0-9a-f]+ | \d<<\d+) \)?) \ *? # NN or 0xHH or N<\ ? (//.* | /\*.*)? )$ # one-line or block comment")) 37 | yield return "public const int {0} = {1};{2}".Fmt(ToPascalId(m.Get("Name")), m.Get("IntValue"), m.Get("Remainder")); 38 | } 39 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsXMLNameSpaceMap.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Alba.CsCss 5 | { 6 | internal class nsXMLNameSpaceMap 7 | { 8 | private readonly Dictionary mNameSpaces = new Dictionary(); 9 | 10 | public nsXMLNameSpaceMap (bool aForXML) 11 | { 12 | if (aForXML) { 13 | AddPrefix("xmlns", nsNameSpace.XMLNS); 14 | AddPrefix("xml", nsNameSpace.XML); 15 | } 16 | } 17 | 18 | public nsresult AddPrefix (string aPrefix, int aNameSpaceID) 19 | { 20 | mNameSpaces[aPrefix] = aNameSpaceID; 21 | return nsresult.OK; 22 | } 23 | 24 | public nsresult AddPrefix (string aPrefix, string aURI) 25 | { 26 | int id; 27 | nsNameSpaceManager.Instance.RegisterNameSpace(aURI, out id); 28 | return AddPrefix(aPrefix, id); 29 | } 30 | 31 | public int FindNameSpaceID (string aPrefix) 32 | { 33 | int id; 34 | if (mNameSpaces.TryGetValue(aPrefix, out id)) 35 | return id; 36 | else 37 | return aPrefix != null ? nsNameSpace.Unknown : nsNameSpace.None; 38 | } 39 | 40 | public string FindPrefix (int aNameSpaceID) 41 | { 42 | return mNameSpaces.FirstOrDefault(ns => ns.Value == aNameSpaceID).Key; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/CssMediaFeature.ValueType.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | // ReSharper disable RedundantUsingDirective 5 | // ReSharper disable RedundantCast 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | public partial class CssMediaFeature 10 | { 11 | public enum ValueType { 12 | // All value types allow CSSUnit_Null to indicate that no value 13 | // was given (in addition to the types listed below). 14 | Length, // values are such that nsCSSValue::IsLengthUnit() is true 15 | Integer, // values are CSSUnit_Integer 16 | Float, // values are CSSUnit_Number 17 | BoolInteger,// values are CSSUnit_Integer (0, -0, or 1 only) 18 | IntRatio, // values are CSSUnit_Array of two CSSUnit_Integer 19 | Resolution, // values are in CSSUnit_Inch (for dpi), 20 | // CSSUnit_Pixel (for dppx), or 21 | // CSSUnit_Centimeter (for dpcm) 22 | Enumerated, // values are CSSUnit_Enumerated (uses keyword table) 23 | Ident // values are CSSUnit_Ident 24 | // Note that a number of pieces of code (both for parsing and 25 | // for matching of valueless xpressions) assume that all numeric 26 | // value types cannot be negative. The parsing code also does 27 | // not allow zeros in IntRatio types. 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Rules/CssStyleRule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay (@"{mSelector} \{ {mDeclaration.DebugDisplayCount,nq} \}")] 7 | public class CssStyleRule : CssRule 8 | { 9 | private readonly CssSelectorGroup mSelector; 10 | private readonly CssDeclaration mDeclaration; 11 | private int mLineNumber; 12 | 13 | internal CssStyleRule (CssSelectorGroup aSelector, CssDeclaration aDeclaration) 14 | { 15 | mSelector = aSelector; 16 | mDeclaration = aDeclaration; 17 | } 18 | 19 | internal void SetLineNumber (int aLineNumber) 20 | { 21 | mLineNumber = aLineNumber; 22 | } 23 | 24 | internal override CssRuleKind GetKind () 25 | { 26 | return CssRuleKind.Style; 27 | } 28 | 29 | // My 30 | 31 | internal override void Fix () 32 | { 33 | base.Fix(); 34 | mDeclaration.Fix(); 35 | } 36 | 37 | // Public interface 38 | 39 | public IEnumerable SelectorGroups 40 | { 41 | get { return CssSelectorGroup.TraverseList(mSelector); } 42 | } 43 | 44 | public CssDeclaration Declaration 45 | { 46 | get { return mDeclaration; } 47 | } 48 | 49 | public int LineNumber 50 | { 51 | get { return mLineNumber; } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsStyleStructID.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.ComponentModel; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | internal enum nsStyleStructID { 10 | [EditorBrowsable(EditorBrowsableState.Never)] 11 | Inherited_Start = 0, 12 | [EditorBrowsable(EditorBrowsableState.Never)] 13 | DUMMY1 = Inherited_Start - 1, 14 | 15 | // Inherited 16 | Font, 17 | Color, 18 | List, 19 | Text, 20 | Visibility, 21 | Quotes, 22 | UserInterface, 23 | TableBorder, 24 | SVG, 25 | 26 | [EditorBrowsable(EditorBrowsableState.Never)] 27 | Reset_Start, 28 | [EditorBrowsable(EditorBrowsableState.Never)] 29 | DUMMY2 = Reset_Start - 1, 30 | 31 | // Reset 32 | Background, 33 | Position, 34 | TextReset, 35 | Display, 36 | Content, 37 | UIReset, 38 | Table, 39 | Margin, 40 | Padding, 41 | Border, 42 | Outline, 43 | XUL, 44 | SVGReset, 45 | Column, 46 | 47 | [EditorBrowsable(EditorBrowsableState.Never)] 48 | Length, 49 | [EditorBrowsable(EditorBrowsableState.Never)] 50 | Inherited_Count = Reset_Start - Inherited_Start, 51 | [EditorBrowsable(EditorBrowsableState.Never)] 52 | Reset_Count = Length - Reset_Start, 53 | [EditorBrowsable(EditorBrowsableState.Never)] 54 | BackendOnly = Length, 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/nscoord.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Alba.CsCss.Gfx 4 | { 5 | /// 6 | /// Basic type used for the geometry classes. 7 | /// 8 | /// Normally all coordinates are maintained in an app unit coordinate 9 | /// space. An app unit is 1/60th of a CSS device pixel, which is, in turn 10 | /// an integer number of device pixels, such at the CSS DPI is as close to 11 | /// 96dpi as possible. 12 | /// 13 | internal struct nscoord : IEquatable 14 | { 15 | private readonly int _value; 16 | 17 | private nscoord (int value) 18 | { 19 | _value = value; 20 | } 21 | 22 | public static readonly nscoord MAX = new nscoord(1 << 30); 23 | public static readonly nscoord MIN = new nscoord(-MAX._value); 24 | 25 | public bool Equals (nscoord other) 26 | { 27 | return _value == other._value; 28 | } 29 | 30 | public override bool Equals (object obj) 31 | { 32 | return !ReferenceEquals(null, obj) && (obj is nscoord && Equals((nscoord)obj)); 33 | } 34 | 35 | public override int GetHashCode () 36 | { 37 | return _value; 38 | } 39 | 40 | public static bool operator == (nscoord left, nscoord right) 41 | { 42 | return left.Equals(right); 43 | } 44 | 45 | public static bool operator != (nscoord left, nscoord right) 46 | { 47 | return !left.Equals(right); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Alba.CsCss.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Alba.CsCss.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Alba.CsCss.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6844f7e0-1ad3-4bda-b1d6-d459f19cd264")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Original/gfxFontConstants.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | /* font constants shared by both thebes and layout */ 7 | 8 | #ifndef GFX_FONT_CONSTANTS_H 9 | #define GFX_FONT_CONSTANTS_H 10 | 11 | /* 12 | * This file is separate from gfxFont.h so that layout can include it 13 | * without bringing in gfxFont.h and everything it includes. 14 | */ 15 | 16 | #define NS_FONT_STYLE_NORMAL 0 17 | #define NS_FONT_STYLE_ITALIC 1 18 | #define NS_FONT_STYLE_OBLIQUE 2 19 | 20 | #define NS_FONT_WEIGHT_NORMAL 400 21 | #define NS_FONT_WEIGHT_BOLD 700 22 | 23 | #define NS_FONT_STRETCH_ULTRA_CONDENSED (-4) 24 | #define NS_FONT_STRETCH_EXTRA_CONDENSED (-3) 25 | #define NS_FONT_STRETCH_CONDENSED (-2) 26 | #define NS_FONT_STRETCH_SEMI_CONDENSED (-1) 27 | #define NS_FONT_STRETCH_NORMAL 0 28 | #define NS_FONT_STRETCH_SEMI_EXPANDED 1 29 | #define NS_FONT_STRETCH_EXPANDED 2 30 | #define NS_FONT_STRETCH_EXTRA_EXPANDED 3 31 | #define NS_FONT_STRETCH_ULTRA_EXPANDED 4 32 | 33 | #endif 34 | 35 | // from nsFont.h 36 | 37 | #define NS_FONT_VARIANT_NORMAL 0 38 | #define NS_FONT_VARIANT_SMALL_CAPS 1 39 | 40 | #define NS_FONT_DECORATION_NONE 0x0 41 | #define NS_FONT_DECORATION_UNDERLINE 0x1 42 | #define NS_FONT_DECORATION_OVERLINE 0x2 43 | #define NS_FONT_DECORATION_LINE_THROUGH 0x4 -------------------------------------------------------------------------------- /Alba.CsCss/Gfx/Original/nsColorNameList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsColorNameList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsColorNameList.g.txt", () => GenerateGfxColorNameListText()); 8 | T4.GenerateFile("CssColor.g.cs", () => GenerateGfxColor()); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateGfxColorNameListText () { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | <#+ foreach (GfxColorName color in GetGfxColorNames()) { #> 18 | // 19 | // Name: <#= color.Name #> 20 | // Value: <#= color.Value #> 21 | <#+ } #> 22 | <#+ } /* void GenerateGfxColorNameListText */ #> 23 | 24 | <#+ void GenerateGfxColor () { #> 25 | // 26 | // Generated file. Do not edit manually. 27 | // 28 | 29 | using System.Collections.Generic; 30 | using System.Linq; 31 | 32 | namespace Alba.CsCss.Gfx 33 | { 34 | public partial struct CssColor 35 | { 36 | private static readonly string[] kColorNames = { 37 | <#+ foreach (GfxColorName color in GetGfxColorNames()) { #> 38 | "<#= color.Name #>", 39 | <#+ } #> 40 | }; 41 | 42 | private static readonly CssColor[] kColors = { 43 | <#+ foreach (GfxColorName color in GetGfxColorNames()) { #> 44 | <#= color.Value.Replace("NS_", "") #>, 45 | <#+ } #> 46 | }; 47 | 48 | private static readonly Dictionary gColorTable = kColorNames.Select((n, i) => new { n, i }).ToDictionary(c => c.n, c => c.i); 49 | } 50 | } 51 | <#+ } /* void GenerateGfxColor */ #> 52 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPropH.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | internal partial class nsCSSProps 8 | { 9 | public const int DIRECTIONAL_SOURCE = (1<<0); 10 | public const int VALUE_LIST_USES_COMMAS = (1<<1); /* otherwise spaces */ 11 | public const int APPLIES_TO_FIRST_LETTER = (1<<2); 12 | public const int APPLIES_TO_FIRST_LINE = (1<<3); 13 | public const int IGNORED_WHEN_COLORS_DISABLED = (1<<4); 14 | public const int START_IMAGE_LOADS = (1<<5); 15 | public const int IMAGE_IS_IN_ARRAY_0 = (1<<6); 16 | public const int REPORT_OTHER_NAME = (1<<7); 17 | public const int STORES_CALC = (1<<8); 18 | public const int PARSE_PROPERTY_MASK = (7<<9); 19 | public const int PARSE_INACCESSIBLE = (1<<9); 20 | public const int PARSE_FUNCTION = (2<<9); 21 | public const int PARSE_VALUE = (3<<9); 22 | public const int PARSE_VALUE_LIST = (4<<9); 23 | public const int VALUE_PARSER_FUNCTION = (1<<12); 24 | public const int VALUE_RESTRICTION_MASK = (3<<13); 25 | public const int VALUE_NONNEGATIVE = (1<<13); 26 | public const int VALUE_AT_LEAST_ONE = (2<<13); 27 | public const int HASHLESS_COLOR_QUIRK = (1<<15); 28 | public const int UNITLESS_LENGTH_QUIRK = (1<<16); 29 | public const int IS_ALIAS = (1<<17); 30 | public const int APPLIES_TO_PLACEHOLDER = (1<<18); 31 | public const int APPLIES_TO_PAGE_RULE = (1<<19); 32 | public const int APPLIES_TO_FIRST_LETTER_AND_FIRST_LINE = APPLIES_TO_FIRST_LETTER | APPLIES_TO_FIRST_LINE; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/CssMediaQuery.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Alba.CsCss.Internal.Extensions; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | public class CssMediaQuery 7 | { 8 | private readonly List mExpressions = new List(); 9 | private bool mNegated; 10 | private bool mHasOnly; // only needed for serialization 11 | private bool mTypeOmitted; // only needed for serialization 12 | private bool mHadUnknownExpression; 13 | private string mMediaType; 14 | 15 | internal void SetNegated () 16 | { 17 | mNegated = true; 18 | } 19 | 20 | internal void SetHasOnly () 21 | { 22 | mHasOnly = true; 23 | } 24 | 25 | internal void SetTypeOmitted () 26 | { 27 | mTypeOmitted = true; 28 | } 29 | 30 | internal void SetHadUnknownExpression () 31 | { 32 | mHadUnknownExpression = true; 33 | } 34 | 35 | internal void SetType (string aMediaType) 36 | { 37 | mMediaType = aMediaType; 38 | } 39 | 40 | internal CssMediaExpression NewExpression () 41 | { 42 | return mExpressions.AppendElement(); 43 | } 44 | 45 | // Public interface 46 | 47 | public IList Expressions 48 | { 49 | get { return mExpressions; } 50 | } 51 | 52 | public bool IsNegated 53 | { 54 | get { return mNegated; } 55 | } 56 | 57 | public string MediaType 58 | { 59 | get { return mMediaType; } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Alba.CsCss.Tests/PublicInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using Alba.CsCss.Style; 5 | using Alba.Framework.Text; 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | 8 | namespace Alba.CsCss.Tests 9 | { 10 | [TestClass] 11 | public class PublicInterface 12 | { 13 | [TestMethod] 14 | public void ClassNamesTest () 15 | { 16 | bool success = true; 17 | foreach (Type type in typeof(CssLoader).Assembly.GetExportedTypes().OrderBy(t => t.FullName)) { 18 | int nCaps = 0; 19 | bool isuccess = true; 20 | 21 | if (char.IsLower(type.Name, 0)) { 22 | isuccess = false; 23 | Trace.WriteLine("{0} - failed: class name is not in PascalCase".Fmt(type.FullName)); 24 | } 25 | 26 | if (isuccess) { 27 | foreach (char c in type.Name) { 28 | if (char.IsUpper(c)) 29 | nCaps++; 30 | else 31 | nCaps = 0; 32 | if (nCaps > 2) { 33 | isuccess = false; 34 | Trace.WriteLine("{0} - failed: SCREAMING_CAPS in class name".Fmt(type.FullName)); 35 | break; 36 | } 37 | } 38 | } 39 | 40 | if (isuccess) 41 | Trace.WriteLine("{0} - no issues found".Fmt(type.FullName)); 42 | success &= isuccess; 43 | } 44 | Assert.IsTrue(success, "One or more public classes failed name check."); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSCompressedDataBlock.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace Alba.CsCss.Style 4 | { 5 | [DebuggerDisplay ("Count = {mData.Length}")] 6 | internal class nsCSSCompressedDataBlock : nsCSSDataBlock 7 | { 8 | internal CssPropertyValue[] mData; 9 | internal int mStyleBits; 10 | 11 | public nsCSSCompressedDataBlock (int aNumProps) 12 | { 13 | mData = new CssPropertyValue[aNumProps]; 14 | } 15 | 16 | internal int IndexFor (CssProperty aProperty) 17 | { 18 | Debug.Assert(!nsCSSProps.IsShorthand(aProperty), "Don't call for shorthands"); 19 | if ((nsCachedStyleData.GetBitForSID(nsCSSProps.kSIDTable[(int)aProperty]) & mStyleBits) == 0) 20 | return -1; 21 | for (int i = 0; i < mData.Length; i++) 22 | if (mData[i].mProperty == aProperty) 23 | return i; 24 | return -1; 25 | } 26 | 27 | internal CssValue ValueFor (CssProperty aProperty) 28 | { 29 | int index = IndexFor(aProperty); 30 | return index != -1 ? mData[index].mValue : CssValue.NullValue; 31 | } 32 | 33 | public bool TryReplaceValue (CssProperty aProperty, nsCSSExpandedDataBlock aFromBlock, ref bool aChanged) 34 | { 35 | CssValue newValue = aFromBlock.mValues[(int)aProperty]; 36 | 37 | int oldValue = IndexFor(aProperty); 38 | if (oldValue == -1) { 39 | aChanged = false; 40 | return false; 41 | } 42 | 43 | aChanged = MoveValue(ref newValue, ref mData[oldValue].mValue); 44 | aFromBlock.mPropertiesSet.RemoveProperty(aProperty); 45 | return true; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Alba.CsCss/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Alba.CsCss")] 9 | [assembly: AssemblyDescription(@"CSS Parser written in C#, based on Mozilla Firefox code. 10 | Supports parsing of all modern CSS expressions. Supports Quirks mode. Values are parsed into detailed structures. Detailed error logging. Debugging via SymbolSource.org.")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("Alba")] 13 | [assembly: AssemblyProduct("Alba.CsCss")] 14 | [assembly: AssemblyCopyright("Copyright © 2013 Athari")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | 18 | // Setting ComVisible to false makes the types in this assembly not visible 19 | // to COM components. If you need to access a type in this assembly from 20 | // COM, set the ComVisible attribute to true on that type. 21 | [assembly: ComVisible(false)] 22 | 23 | // The following GUID is for the ID of the typelib if this project is exposed to COM 24 | [assembly: Guid("ece5e321-78a4-4e02-bd3a-c91cd4a1bc06")] 25 | 26 | // Version information for an assembly consists of the following four values: 27 | // 28 | // Major Version 29 | // Minor Version 30 | // Build Number 31 | // Revision 32 | // 33 | // You can specify all the values or you can default the Build and Revision Numbers 34 | // by using the '*' as shown below: 35 | // [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyVersion("1.0.1.0")] 37 | [assembly: AssemblyFileVersion("1.0.1.0")] 38 | 39 | [assembly: InternalsVisibleTo("Alba.CsCss.Tests")] -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsStyleStructList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _styleStructs; 3 | 4 | IEnumerable GetStyleStructsFromSource (string source) 5 | { 6 | var kinds = new Dictionary { 7 | { "STYLE_STRUCT_INHERITED", StyleStructKind.Inherited }, 8 | { "STYLE_STRUCT_RESET", StyleStructKind.Reset }, 9 | }; 10 | foreach (Match m in source.ReMatches( 11 | @"(?mx)^( 12 | (? STYLE_STRUCT_INHERITED )\( 13 | (?$), (?$), (?$) 14 | \) 15 | | 16 | (? STYLE_STRUCT_RESET )\( 17 | (?$), (?$), (?$) 18 | \) 19 | )".Replace(",", @",\ *").Replace("$", sArgs))) { 20 | var cls = new StyleStruct { 21 | Kind = kinds[m.Get("Kind")], 22 | Name = m.Get("Name").Trim(), 23 | CheckDataCallback = m.Get("CheckDataCallback").Trim().Replace("nullptr", "null"), 24 | CtorArgs = m.Get("CtorArgs").Trim(), 25 | }; 26 | yield return cls; 27 | } 28 | } 29 | 30 | IEnumerable GetStyleStructs (StyleStructKind? kind = null) 31 | { 32 | if (_styleStructs == null) 33 | _styleStructs = GetStyleStructsFromSource(LoadText("nsStyleStructList.h")).ToList(); 34 | return kind == null ? _styleStructs : _styleStructs.Where(style => style.Kind == kind.Value); 35 | } 36 | 37 | enum StyleStructKind { Inherited, Reset }; 38 | 39 | class StyleStruct 40 | { 41 | public string Name, CheckDataCallback, CtorArgs; 42 | public StyleStructKind Kind; 43 | } 44 | #> 45 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/Rule.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | source = source.ReReplace(@"\r", ""); 7 | 8 | var T4 = GetT4(); 9 | T4.GenerateFile("CssRuleKind.conv.cs", () => GenerateCssRuleKind(source)); 10 | T4.GenerateFile("CssStyleSheet.CssRuleKind.g.cs", () => GenerateCssStyleSheet(source)); 11 | T4.Process(); 12 | #> 13 | <#+ 14 | void GenerateCssRuleKind (string source) { 15 | #> 16 | // 17 | // Generated file. Do not edit manually. 18 | // 19 | 20 | namespace Alba.CsCss.Style 21 | { 22 | public enum CssRuleKind 23 | { 24 | <#+ foreach (string val in GetRuleEnumValues(source)) { #> 25 | <#=val#>, 26 | <#+ } #> 27 | } 28 | } 29 | <#+ 30 | } // GenerateCssRuleKind 31 | 32 | void GenerateCssStyleSheet (string source) { 33 | #> 34 | // 35 | // Generated file. Do not edit manually. 36 | // 37 | 38 | using System.Collections.Generic; 39 | 40 | namespace Alba.CsCss.Style 41 | { 42 | public partial class CssStyleSheet 43 | { 44 | <#+ foreach (string val in GetRuleEnumValues(source).Where(v => v != "Unknown" && v != "Document")) { #> 45 | public IEnumerableRule> <#=val#>Rules 46 | { 47 | get { return GetRulesRule>(); } 48 | } 49 | 50 | public IEnumerableRule> All<#=val#>Rules 51 | { 52 | get { return GetAllRulesRule>(); } 53 | } 54 | 55 | <#+ } #> 56 | } 57 | } 58 | <#+ 59 | } // GenerateCssStyleSheet 60 | 61 | IEnumerable GetRuleEnumValues (string source) 62 | { 63 | foreach (Match m in source.ReMatchGet(@"(?s)enum {\n(.*?)\s*}").ReMatches(@"(\w+)_RULE")) 64 | yield return ToPascalId(m); 65 | } 66 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssPseudoElement.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.ComponentModel; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | public enum CssPseudoElement 10 | { 11 | After, 12 | Before, 13 | FirstLetter, 14 | FirstLine, 15 | [EditorBrowsable(EditorBrowsableState.Advanced)] 16 | MozSelection, 17 | [EditorBrowsable(EditorBrowsableState.Advanced)] 18 | MozFocusInner, 19 | [EditorBrowsable(EditorBrowsableState.Advanced)] 20 | MozFocusOuter, 21 | [EditorBrowsable(EditorBrowsableState.Advanced)] 22 | MozListBullet, 23 | [EditorBrowsable(EditorBrowsableState.Advanced)] 24 | MozListNumber, 25 | [EditorBrowsable(EditorBrowsableState.Advanced)] 26 | MozMathStretchy, 27 | [EditorBrowsable(EditorBrowsableState.Advanced)] 28 | MozMathAnonymous, 29 | [EditorBrowsable(EditorBrowsableState.Advanced)] 30 | MozProgressBar, 31 | [EditorBrowsable(EditorBrowsableState.Advanced)] 32 | MozRangeTrack, 33 | [EditorBrowsable(EditorBrowsableState.Advanced)] 34 | MozRangeProgress, 35 | [EditorBrowsable(EditorBrowsableState.Advanced)] 36 | MozRangeThumb, 37 | [EditorBrowsable(EditorBrowsableState.Advanced)] 38 | MozMeterBar, 39 | [EditorBrowsable(EditorBrowsableState.Advanced)] 40 | MozPlaceholder, 41 | [EditorBrowsable(EditorBrowsableState.Advanced)] 42 | PseudoElementCount, 43 | [EditorBrowsable(EditorBrowsableState.Advanced)] 44 | AnonBox = PseudoElementCount, 45 | #if MOZ_XUL 46 | XULTree, 47 | #endif 48 | [EditorBrowsable(EditorBrowsableState.Never)] 49 | NotPseudoElement, 50 | [EditorBrowsable(EditorBrowsableState.Never)] 51 | MAX, 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Alba.CsCss.Tests/Style/CssScannerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Alba.CsCss.Style; 3 | using Alba.Framework.Text; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace Alba.CsCss.Tests.Style 7 | { 8 | [TestClass] 9 | public class CssScannerTests 10 | { 11 | [TestMethod] 12 | public void Create () 13 | { 14 | // ReSharper disable once UnusedVariable 15 | var lex = new CssScanner("", 0); 16 | } 17 | 18 | [TestMethod] 19 | public void ParseSimple () 20 | { 21 | var lex = new CssScanner("h1 { color: #123; }", 0); 22 | AssertNextToken(lex, CssTokenType.Ident, t => t.mIdent.ToString() == "h1"); 23 | AssertNextToken(lex, CssTokenType.Symbol, t => t.mSymbol == '{'); 24 | AssertNextToken(lex, CssTokenType.Ident, t => t.mIdent.ToString() == "color"); 25 | AssertNextToken(lex, CssTokenType.Symbol, t => t.mSymbol == ':'); 26 | AssertNextToken(lex, CssTokenType.Hash, t => t.mIdent.ToString() == "123"); 27 | AssertNextToken(lex, CssTokenType.Symbol, t => t.mSymbol == ';'); 28 | AssertNextToken(lex, CssTokenType.Symbol, t => t.mSymbol == '}'); 29 | AssertNextTokenEnd(lex); 30 | } 31 | 32 | private static void AssertNextToken (CssScanner lex, CssTokenType type, Func condition) 33 | { 34 | var token = new CssToken(); 35 | Assert.IsTrue(lex.Next(token, true), "Unexpected EOF"); 36 | Assert.AreEqual(type, token.mType); 37 | Assert.IsTrue(condition(token), "Condition for token {0} failed".Fmt(token.mType)); 38 | } 39 | 40 | private static void AssertNextTokenEnd (CssScanner lex) 41 | { 42 | var token = new CssToken(); 43 | Assert.IsFalse(lex.Next(token, true), "Expected EOF"); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Alba.CsCss/Alba.CsCss.csproj.DotSettings: -------------------------------------------------------------------------------- 1 | 2 | True 3 | True 4 | True 5 | True 6 | True 7 | True 8 | True 9 | True 10 | True 11 | True 12 | True 13 | True -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSProps.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = ConvertSource(LoadText(ext: "cpp") + LoadText(@"..\Media\Original\nsMediaFeatures.cpp")); 6 | 7 | var T4 = GetT4(); 8 | T4.GenerateFile("nsCSSProps.conv.cs", () => GenerateCssProps(source)); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateCssProps (string source) { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | using int32_t = System.Int32; 18 | using uint32_t = System.Int32; 19 | 20 | namespace Alba.CsCss.Style 21 | { 22 | <#+ WriteTypeRenames("nsCSSProperty", "nsCSSKeyword", "nsStyle"); #> 23 | 24 | internal partial class nsCSSProps 25 | { 26 | <#+ foreach (string array in ConvertGlobalArrays(source)) { #> 27 | <#= array.Indent(8).NormalizeWhitespace() #> 28 | 29 | <#+ } #> 30 | } 31 | } 32 | <#+ } /* void GenerateCssProps */ #> 33 | 34 | <#+ 35 | string ConvertSource (string source) 36 | { 37 | return source 38 | // specific enums 39 | .ReReplace(@"eCSSKeyword_(\w+)", "(int)nsCSSKeyword.$1") 40 | .ReReplace(@"eCSSProperty_(\w+)", "nsCSSProperty.$1") 41 | .ReReplace(@"NS_STYLE_(\w+)", m => "nsStyle." + ToPascalId(m)) 42 | .ReReplace(@"NS_((?:BOXPROP|COLOR)_\w+)", m => "nsStyle." + ToPascalId(m)) 43 | .ReReplace(@"NS_THEME_(\w+)", "0/*unused*/") 44 | .ReReplace(@"LookAndFeel::e(\w+?)_(\w+)", "(int)LookAndFeel.$1.$2") 45 | 46 | // common preprocessor 47 | .ReReplace(@"#ifdef (\w+)", "#if $1") 48 | ; 49 | } 50 | 51 | IEnumerable ConvertGlobalArrays (string source) 52 | { 53 | foreach (Match m in source.ReMatches(@"(?ns)(static )?(const )?(?u?int\d+_t|nsCSSProperty) (nsCSSProps::)?(?\w+)\[\] = {(?.*?)};")) 54 | yield return "public static readonly {0}[] {1} = {{{2}}};" 55 | .Fmt(m.Get("Type"), m.Get("Var"), Refactor(m.Get("Code"))); 56 | } 57 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssScanner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | internal partial class CssScanner 7 | { 8 | private readonly string mBuffer; 9 | private Int32 mOffset; 10 | private readonly Int32 mCount; 11 | 12 | private Int32 mLineNumber; 13 | private Int32 mLineOffset; 14 | 15 | private Int32 mTokenLineNumber; 16 | private Int32 mTokenLineOffset; 17 | private Int32 mTokenOffset; 18 | 19 | private Int32 mRecordStartOffset; 20 | 21 | private ErrorReporter mReporter; 22 | 23 | private bool mSVGMode; 24 | private bool mRecording; 25 | 26 | internal CssScanner (string aBuffer, Int32 aLineNumber) 27 | { 28 | mBuffer = aBuffer; 29 | mCount = aBuffer.Length; 30 | mLineNumber = aLineNumber; 31 | mTokenLineNumber = aLineNumber; 32 | } 33 | 34 | internal void SetErrorReporter (ErrorReporter aReporter) 35 | { 36 | mReporter = aReporter; 37 | } 38 | 39 | internal bool IsSVGMode () 40 | { 41 | return mSVGMode; 42 | } 43 | 44 | internal void SetSVGMode (bool aSVGMode) 45 | { 46 | mSVGMode = aSVGMode; 47 | } 48 | 49 | internal Int32 GetLineNumber () 50 | { 51 | return mTokenLineNumber; 52 | } 53 | 54 | internal Int32 GetColumnLineNumber () 55 | { 56 | return mTokenOffset - mTokenLineOffset; 57 | } 58 | 59 | internal void StopRecording (StringBuilder aBuffer) 60 | { 61 | mRecording = false; 62 | aBuffer.Append(mBuffer, mRecordStartOffset, mOffset - mRecordStartOffset); 63 | } 64 | 65 | internal string GetCurrentLine () 66 | { 67 | Int32 end = mTokenOffset; 68 | while (end < mCount && !IsVertSpace(mBuffer[end])) { 69 | end++; 70 | } 71 | return mBuffer.Substring(mTokenLineOffset, end - mTokenLineOffset); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssRect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Alba.CsCss.Gfx; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | [DebuggerDisplay ("{mLeft}, {mTop}, {mRight}, {mBottom}")] 8 | public class CssRect 9 | { 10 | internal CssValue mTop, mRight, mBottom, mLeft; 11 | 12 | internal void SetAllSidesTo (CssValue aValue) 13 | { 14 | mTop = mRight = mBottom = mLeft = aValue; 15 | } 16 | 17 | // Public interface 18 | 19 | public CssValue Top 20 | { 21 | get { return mTop; } 22 | } 23 | 24 | public CssValue Right 25 | { 26 | get { return mRight; } 27 | } 28 | 29 | public CssValue Bottom 30 | { 31 | get { return mBottom; } 32 | } 33 | 34 | public CssValue Left 35 | { 36 | get { return mLeft; } 37 | } 38 | 39 | public CssValue GetSide (Side side) 40 | { 41 | switch (side) { 42 | case Side.Top: 43 | return mTop; 44 | case Side.Right: 45 | return mRight; 46 | case Side.Bottom: 47 | return mBottom; 48 | case Side.Left: 49 | return mLeft; 50 | default: 51 | throw new ArgumentOutOfRangeException("side"); 52 | } 53 | } 54 | 55 | public void SetSide (Side side, CssValue aValue) 56 | { 57 | switch (side) { 58 | case Side.Top: 59 | mTop = aValue; 60 | break; 61 | case Side.Right: 62 | mRight = aValue; 63 | break; 64 | case Side.Bottom: 65 | mBottom = aValue; 66 | break; 67 | case Side.Left: 68 | mLeft = aValue; 69 | break; 70 | default: 71 | throw new ArgumentOutOfRangeException("side"); 72 | } 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssLoader.cs: -------------------------------------------------------------------------------- 1 | // TODO Implement other CssLoader methods, support @charset etc. 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace Alba.CsCss.Style 7 | { 8 | public class CssLoader 9 | { 10 | public BrowserCompatibility Compatibility { get; set; } 11 | public event EventHandler ParseError; 12 | 13 | public CssLoader () 14 | { 15 | Compatibility = BrowserCompatibility.FullStandards; 16 | } 17 | 18 | public CssStyleSheet ParseSheet (string aInput, Uri sheetUrl, Uri baseUrl) 19 | { 20 | var sheet = new CssStyleSheet(); 21 | sheet.SetURIs(sheetUrl, baseUrl); 22 | var parser = new CssParser(); 23 | parser.SetChildLoader(this); 24 | parser.SetQuirkMode(Compatibility == BrowserCompatibility.Quirks); 25 | parser.SetStyleSheet(sheet); 26 | parser.ParseSheet(aInput, sheetUrl, baseUrl, nsIPrincipal.Default, 1, false); 27 | sheet.Fix(); // My 28 | return sheet; 29 | } 30 | 31 | public IEnumerable GetUris (string aInput) 32 | { 33 | var lexer = new CssScanner(aInput, 1); 34 | lexer.SetErrorReporter(new ErrorReporter(lexer, null, this, null)); 35 | var token = new CssToken(); 36 | while (lexer.Next(token, true)) 37 | if (token.mType == CssTokenType.URL) 38 | yield return token.mIdentStr; 39 | } 40 | 41 | public IEnumerable GetUris (string aInput, Uri baseUri) 42 | { 43 | return GetUris(aInput).Select(s => new Uri(baseUri, s)); 44 | } 45 | 46 | internal void LoadChildSheet (CssStyleSheet aParentSheet, Uri aUrl, nsMediaList aMedia, CssImportRule aRule) 47 | {} 48 | 49 | internal void FireParseError (ErrorReporter aErrorReporter) 50 | { 51 | var handler = ParseError; 52 | if (handler != null) 53 | handler(this, new CssParserErrorEventArgs(aErrorReporter)); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/EnumerableExts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace Alba.CsCss.Internal.Extensions 6 | { 7 | internal static class EnumerableExts 8 | { 9 | public static IEnumerable TraverseList (this T root, Func getNext) where T : class 10 | { 11 | for (T current = root; current != null; current = getNext(current)) 12 | yield return current; 13 | } 14 | 15 | public static IEnumerable TraverseTree (this T root, Func> getChildren) 16 | { 17 | return TraverseTreeDepth(root, getChildren); 18 | } 19 | 20 | public static IEnumerable TraverseTreeDepth (this T root, Func> getChildren) 21 | { 22 | var stack = new Stack(); 23 | stack.Push(root); 24 | 25 | while (stack.Count != 0) { 26 | T item = stack.Pop(); 27 | yield return item; 28 | foreach (var child in getChildren(item).Inverse()) 29 | stack.Push(child); 30 | } 31 | } 32 | 33 | public static IEnumerable Inverse (this IEnumerable @this) 34 | { 35 | var list = @this as IList; 36 | if (list != null) { 37 | for (int i = list.Count - 1; i >= 0; i--) 38 | yield return list[i]; 39 | } 40 | else { 41 | foreach (T item in @this.Reverse()) 42 | yield return item; 43 | } 44 | } 45 | 46 | public static Dictionary ToCaseInsensitiveNameTable (this IEnumerable @this) 47 | { 48 | var dic = new Dictionary(StringComparer.OrdinalIgnoreCase); 49 | int i = 0; 50 | foreach (string str in @this) 51 | dic.Add(str, i++); 52 | return dic; 53 | } 54 | 55 | public static bool IsEmpty (this IEnumerable @this) 56 | { 57 | return !@this.Any(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSKeywordList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsCSSKeywordList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsCSSKeywordList.g.txt", () => GenerateCssKeywordListText()); 8 | T4.GenerateFile("CssKeyword.g.cs", () => GenerateCssKeyword()); 9 | T4.GenerateFile("nsCSSKeywords.g.cs", () => GenerateCssKeywords()); 10 | T4.Process(); 11 | #> 12 | 13 | <#+ void GenerateCssKeywordListText () { #> 14 | // 15 | // Generated file. Do not edit manually. 16 | // 17 | 18 | <#+ foreach (CssKeyword key in GetCssKeywords()) { #> 19 | // 20 | // Name: <#= key.Name #> 21 | // Id: <#= key.Id #> 22 | <#+ } #> 23 | <#+ } /* void GenerateCssKeywordListText */ #> 24 | 25 | <#+ void GenerateCssKeyword () { #> 26 | // 27 | // Generated file. Do not edit manually. 28 | // 29 | 30 | using System.ComponentModel; 31 | 32 | namespace Alba.CsCss.Style 33 | { 34 | public enum CssKeyword 35 | { 36 | Unknown = -1, 37 | <#+ foreach (CssKeyword key in GetCssKeywords()) { #> 38 | /// Keyword "<#=key.Name#>" 39 | <#+ if (key.IsExtension) { #> 40 | [EditorBrowsable(EditorBrowsableState.Advanced)] 41 | <#+ } #> 42 | <#=ToPascalId(key.Id)#>, 43 | <#+ } #> 44 | [EditorBrowsable(EditorBrowsableState.Never)] 45 | KeywordCount 46 | } 47 | } 48 | <#+ } /* void GenerateCssKeyword */ #> 49 | 50 | <#+ void GenerateCssKeywords () { #> 51 | // 52 | // Generated file. Do not edit manually. 53 | // 54 | 55 | using System.Collections.Generic; 56 | using Alba.CsCss.Internal.Extensions; 57 | 58 | namespace Alba.CsCss.Style 59 | { 60 | internal partial class nsCSSKeywords 61 | { 62 | private static readonly string[] kCSSRawKeywords = { 63 | <#+ foreach (CssKeyword key in GetCssKeywords()) { #> 64 | "<#=key.Name#>", 65 | <#+ } #> 66 | }; 67 | 68 | private static readonly Dictionary gKeywordTable = kCSSRawKeywords.ToCaseInsensitiveNameTable(); 69 | } 70 | } 71 | <#+ } /* void GenerateCssKeywords */ #> 72 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsStyleStructList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsStyleStructList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsStyleStructList.g.txt", () => GenerateStyleStructListText()); 8 | T4.GenerateFile("nsStyleStructID.g.cs", () => GenerateStyleStructId()); 9 | T4.Process(); 10 | #> 11 | 12 | <#+ void GenerateStyleStructListText () { #> 13 | // 14 | // Generated file. Do not edit manually. 15 | // 16 | 17 | <#+ foreach (StyleStruct style in GetStyleStructs()) { #> 18 | // 19 | // Kind: <#=style.Kind#> 20 | // Name: <#=style.Name#> 21 | // CheckDataCallback: <#=style.CheckDataCallback#> 22 | // CtorArgs: <#=style.CtorArgs#> 23 | <#+ } #> 24 | <#+ } /* void GenerateStyleStructListText */ #> 25 | 26 | <#+ void GenerateStyleStructId () { #> 27 | // 28 | // Generated file. Do not edit manually. 29 | // 30 | 31 | using System.ComponentModel; 32 | 33 | namespace Alba.CsCss.Style 34 | { 35 | internal enum nsStyleStructID { 36 | [EditorBrowsable(EditorBrowsableState.Never)] 37 | Inherited_Start = 0, 38 | [EditorBrowsable(EditorBrowsableState.Never)] 39 | DUMMY1 = Inherited_Start - 1, 40 | 41 | // Inherited 42 | <#+ foreach (StyleStruct style in GetStyleStructs(StyleStructKind.Inherited)) { #> 43 | <#=style.Name#>, 44 | <#+ } #> 45 | 46 | [EditorBrowsable(EditorBrowsableState.Never)] 47 | Reset_Start, 48 | [EditorBrowsable(EditorBrowsableState.Never)] 49 | DUMMY2 = Reset_Start - 1, 50 | 51 | // Reset 52 | <#+ foreach (StyleStruct style in GetStyleStructs(StyleStructKind.Reset)) { #> 53 | <#=style.Name#>, 54 | <#+ } #> 55 | 56 | [EditorBrowsable(EditorBrowsableState.Never)] 57 | Length, 58 | [EditorBrowsable(EditorBrowsableState.Never)] 59 | Inherited_Count = Reset_Start - Inherited_Start, 60 | [EditorBrowsable(EditorBrowsableState.Never)] 61 | Reset_Count = Length - Reset_Start, 62 | [EditorBrowsable(EditorBrowsableState.Never)] 63 | BackendOnly = Length, 64 | } 65 | } 66 | <#+ } /* void GenerateStyleStructId */ #> 67 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/CssMediaFeature.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | public partial class CssMediaFeature 7 | { 8 | internal string mName; 9 | internal RangeType mRangeType; 10 | internal ValueType mValueType; 11 | 12 | internal int[] mKeywordTable; 13 | internal string mMetric; 14 | 15 | // union of mKeywordTable and mMetric 16 | internal CssMediaFeature mData 17 | { 18 | get { return this; } 19 | } 20 | 21 | private CssMediaFeature (string aName, RangeType aRangeType, ValueType aValueType, int[] aKeywordTable, string aMetric) 22 | { 23 | mName = aName; 24 | mRangeType = aRangeType; 25 | mValueType = aValueType; 26 | mKeywordTable = aKeywordTable; 27 | mMetric = aMetric; 28 | } 29 | 30 | internal CssMediaFeature (string aName, RangeType aRangeType, ValueType aValueType, string aMetric) 31 | : this(aName, aRangeType, aValueType, null, aMetric) 32 | {} 33 | 34 | internal CssMediaFeature (string aName, RangeType aRangeType, ValueType aValueType, int[] aKeywordTable) 35 | : this(aName, aRangeType, aValueType, aKeywordTable, null) 36 | {} 37 | 38 | internal CssMediaFeature (string aName, RangeType aRangeType, ValueType aValueType) 39 | : this(aName, aRangeType, aValueType, null, null) 40 | {} 41 | 42 | internal CssMediaFeature () 43 | : this(null, RangeType.MinMaxAllowed, ValueType.Integer, null, null) 44 | {} 45 | 46 | // Public interface 47 | 48 | public string Name 49 | { 50 | get { return mName; } 51 | } 52 | 53 | public RangeType Range 54 | { 55 | get { return mRangeType; } 56 | } 57 | 58 | public ValueType Value 59 | { 60 | get { return mValueType; } 61 | } 62 | 63 | public string Metric 64 | { 65 | get { return mMetric; } 66 | } 67 | 68 | public IEnumerable PossibleValues 69 | { 70 | get { return mKeywordTable.Where((k, i) => i % 2 == 1 && k != -1); } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoClassList.ttinclude: -------------------------------------------------------------------------------- 1 | <#+ 2 | IList _cssPseudoClasses; 3 | 4 | string ConvertCssPseudoClassesSource (string source) 5 | { 6 | return source 7 | // whitespace 8 | .ReReplace(@"\r", "") 9 | // common preprocessor 10 | .ReReplace(@"#(include|define|undef|pragma) .*", "") 11 | // whitespace 12 | .Trim() 13 | ; 14 | } 15 | 16 | IEnumerable GetCssPseudoClassesFromSource (string source) 17 | { 18 | var kinds = new Dictionary { 19 | { "CSS_PSEUDO_CLASS", CssPseudoClassKind.Normal }, 20 | { "CSS_STATE_PSEUDO_CLASS", CssPseudoClassKind.State }, 21 | { "CSS_STATE_DEPENDENT_PSEUDO_CLASS", CssPseudoClassKind.StateDependent }, 22 | }; 23 | foreach (Match m in source.ReMatches( 24 | @"(?mx)^( 25 | (? CSS_PSEUDO_CLASS )\( 26 | (?$), (?$), (?$) 27 | \) 28 | | 29 | (? CSS_STATE_PSEUDO_CLASS | CSS_STATE_DEPENDENT_PSEUDO_CLASS )\( 30 | (?$), (?$), (?$), (?$) 31 | \) 32 | )".Replace(",", @",\ *").Replace("$", sArgs))) { 33 | var cls = new CssPseudoClass { 34 | Kind = kinds[m.Get("Kind")], 35 | Name = m.Get("Name").Trim(), 36 | Value = m.Get("Value").Trim(), 37 | Pref = m.Get("Pref").Trim(), 38 | Bit = m.Get("Bit").Trim(), 39 | }; 40 | yield return cls; 41 | } 42 | } 43 | 44 | IEnumerable GetCssPseudoClasses () 45 | { 46 | if (_cssPseudoClasses == null) { 47 | string output = ConvertCssPseudoClassesSource(LoadText("nsCSSPseudoClassList.h")); 48 | _cssPseudoClasses = GetCssPseudoClassesFromSource(output).ToList(); 49 | } 50 | return _cssPseudoClasses; 51 | } 52 | 53 | enum CssPseudoClassKind { Normal, State, StateDependent }; 54 | 55 | class CssPseudoClass 56 | { 57 | public string Name, Value, Pref, Bit; 58 | public CssPseudoClassKind Kind; 59 | } 60 | #> 61 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssAttrSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Alba.CsCss.Internal.Extensions; 4 | 5 | namespace Alba.CsCss.Style 6 | { 7 | public class CssAttrSelector 8 | { 9 | internal string mLowercaseAttr, mCasedAttr; 10 | internal int mNameSpace; 11 | internal string mValue; 12 | internal bool mCaseSensitive; 13 | internal CssAttrFunction mFunction; 14 | internal CssAttrSelector mNext; 15 | 16 | internal CssAttrSelector (int aNameSpace, string aAttr, CssAttrFunction aFunction = CssAttrFunction.Set, string aValue = null, bool aCaseSensitive = true) 17 | { 18 | mNameSpace = aNameSpace; 19 | mCasedAttr = String.Intern(aAttr); 20 | mLowercaseAttr = String.Intern(aAttr.ToLower()); 21 | mFunction = aFunction; 22 | mValue = aValue; 23 | mCaseSensitive = aCaseSensitive; 24 | } 25 | 26 | internal static void AddItem (ref CssAttrSelector @this, CssAttrSelector item) 27 | { 28 | while (@this != null) 29 | @this = @this.mNext; 30 | @this = item; 31 | } 32 | 33 | // Public interface 34 | 35 | public string Attr 36 | { 37 | get { return mCasedAttr ?? mLowercaseAttr; } 38 | } 39 | 40 | public string AttrCased 41 | { 42 | get { return mCasedAttr; } 43 | } 44 | 45 | public string AttrLower 46 | { 47 | get { return mLowercaseAttr; } 48 | } 49 | 50 | public bool IsCaseSensitive 51 | { 52 | get { return mCaseSensitive; } 53 | } 54 | 55 | public int NamespaceId 56 | { 57 | get { return mNameSpace; } 58 | } 59 | 60 | public string NamespaceUri 61 | { 62 | get { return nsNameSpaceManager.Instance.GetNameSpaceURI(mNameSpace); } 63 | } 64 | 65 | public CssAttrFunction Function 66 | { 67 | get { return mFunction; } 68 | } 69 | 70 | public string Value 71 | { 72 | get { return mValue; } 73 | } 74 | 75 | internal static IEnumerable TraverseList (CssAttrSelector @this) 76 | { 77 | return @this.TraverseList(i => i.mNext); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoClassList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsCSSPseudoClassList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsCSSPseudoClassList.g.txt", () => GenerateCssPseudoClassListText()); 8 | T4.GenerateFile("CssPseudoClass.g.cs", () => GenerateCssPseudoClass()); 9 | T4.GenerateFile("nsCSSPseudoClasses.g.cs", () => GenerateCssPseudoClasses()); 10 | T4.Process(); 11 | #> 12 | 13 | <#+ void GenerateCssPseudoClassListText () { #> 14 | // 15 | // Generated file. Do not edit manually. 16 | // 17 | 18 | <#+ foreach (CssPseudoClass cls in GetCssPseudoClasses()) { #> 19 | // 20 | // Kind: <#=cls.Kind#> 21 | // Name: <#=cls.Name#> 22 | // Value: <#=cls.Value#> 23 | // Pref: <#=cls.Pref#> 24 | // Bit: <#=cls.Bit#> 25 | <#+ } #> 26 | <#+ } /* void GenerateCssPseudoClassListText */ #> 27 | 28 | <#+ void GenerateCssPseudoClass () { #> 29 | // 30 | // Generated file. Do not edit manually. 31 | // 32 | 33 | using System.ComponentModel; 34 | 35 | namespace Alba.CsCss.Style 36 | { 37 | public enum CssPseudoClass { 38 | <#+ foreach (string clsName in GetCssPseudoClasses().Select(cls => ToPascalId(cls.Name))) { #> 39 | <#+ if (clsName.StartsWith("Moz")) { #> 40 | [EditorBrowsable(EditorBrowsableState.Advanced)] 41 | <#+ } #> 42 | <#=clsName#>, 43 | <#+ } #> 44 | [EditorBrowsable(EditorBrowsableState.Advanced)] 45 | Count, 46 | [EditorBrowsable(EditorBrowsableState.Never)] 47 | NotPseudoClass, 48 | } 49 | } 50 | <#+ } /* void GenerateCssPseudoClass */ #> 51 | 52 | <#+ void GenerateCssPseudoClasses () { #> 53 | // 54 | // Generated file. Do not edit manually. 55 | // 56 | 57 | using System.Collections.Generic; 58 | using Alba.CsCss.Internal; 59 | 60 | namespace Alba.CsCss.Style 61 | { 62 | internal static partial class nsCSSPseudoClasses 63 | { 64 | private static readonly IDictionary sPseudoClasses = 65 | new Dictionary(ReferenceEqualityComparer.Default) { 66 | <#+ foreach (CssPseudoClass cls in GetCssPseudoClasses()) { #> 67 | { <#=cls.Value#>, CssPseudoClass.<#=ToPascalId(cls.Name)#> }, 68 | <#+ } #> 69 | }; 70 | } 71 | } 72 | <#+ } /* void GenerateCssPseudoClass */ #> 73 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPropsH.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | source = source 7 | // whitespace 8 | .ReReplace(@"\r", "") 9 | // common preprocessor 10 | .ReReplace(@"\\\n", ""); 11 | 12 | var T4 = GetT4(); 13 | T4.GenerateFile("nsCSSPropH.conv.cs", () => GenerateCssPropDefines(source)); 14 | T4.Process(); 15 | #> 16 | <#+ 17 | void GenerateCssPropDefines (string source) { 18 | #> 19 | // 20 | // Generated file. Do not edit manually. 21 | // 22 | 23 | namespace Alba.CsCss.Style 24 | { 25 | internal partial class nsCSSProps 26 | { 27 | <#+ foreach (string line in ConvertCssPropDefines(source)) { #> 28 | <#=line#> 29 | <#+ } #> 30 | } 31 | } 32 | <#+ 33 | } // GenerateCssPropDefines 34 | 35 | IEnumerable ConvertCssPropDefines (string source) 36 | { 37 | foreach (Match m in source.ReMatches( 38 | @"(?imnx)^ 39 | \#define \ + 40 | CSS_PROPERTY_ (?\w+) \ + # constant name with prefix removed 41 | (?\(? (-?\d+ | 0x[0-9a-f]+ | \d<<\d+) \)?) \ *? # NN or 0xHH or N<\ ? (//.* | /\*.*)? )$ # one-line or block comment")) 43 | yield return m.Result("public const int ${Name} = ${IntValue};${Remainder}"); 44 | 45 | foreach (Match m in source.ReMatches( 46 | @"(?mnx)^ 47 | \#define \ + 48 | CSS_PROPERTY_ (?\w+) \ + # constant name with prefix removed 49 | \(? ( # aliased constant name(s) 50 | CSS_PROPERTY_ (?\w+ (\ *\|\ *)? ) # aliased constant name ending with optional | operator 51 | )+ \)? \ *? 52 | (?\ ? (//.* | /\*.*)? )$ # one-line or block comment")) { 53 | string name = m.Get("Name"), namesValue = m.GetConcat("NamesValue"), remainder = m.Get("Remainder"); 54 | namesValue = namesValue.ReReplace(@"^FONT_", "nsFont."); 55 | yield return "public const int {0} = {1};{2}".Fmt(name, namesValue, remainder); 56 | } 57 | } 58 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssPseudoClassSelector.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Alba.CsCss.Internal.Extensions; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | public class CssPseudoClassSelector 7 | { 8 | internal CssPseudoClass mType; 9 | internal CssPseudoClassSelector mNext; 10 | private object mData; 11 | 12 | internal CssPseudoClassSelector (CssPseudoClass aType, string aString) 13 | { 14 | mType = aType; 15 | mString = aString; 16 | } 17 | 18 | internal CssPseudoClassSelector (CssPseudoClass aType, int[] aNumbers) 19 | { 20 | mType = aType; 21 | mNumbers = aNumbers; 22 | } 23 | 24 | internal CssPseudoClassSelector (CssPseudoClass aType, CssSelectorGroup aSelectors) 25 | { 26 | mType = aType; 27 | mSelectors = aSelectors; 28 | } 29 | 30 | internal CssPseudoClassSelector (CssPseudoClass aType) 31 | { 32 | mType = aType; 33 | mData = null; 34 | } 35 | 36 | internal string mString 37 | { 38 | get { return (string)mData; } 39 | set { mData = value; } 40 | } 41 | 42 | internal int[] mNumbers 43 | { 44 | get { return (int[])mData; } 45 | set { mData = value; } 46 | } 47 | 48 | internal CssSelectorGroup mSelectors 49 | { 50 | get { return (CssSelectorGroup)mData; } 51 | set { mData = value; } 52 | } 53 | 54 | internal static void AddItem (ref CssPseudoClassSelector @this, CssPseudoClassSelector item) 55 | { 56 | while (@this != null) 57 | @this = @this.mNext; 58 | @this = item; 59 | } 60 | 61 | // Public interface 62 | 63 | public CssPseudoClass Type 64 | { 65 | get { return mType; } 66 | } 67 | 68 | public string String 69 | { 70 | get { return mString; } 71 | } 72 | 73 | public IList Numbers 74 | { 75 | get { return mNumbers; } 76 | } 77 | 78 | public IEnumerable SelectorGroups 79 | { 80 | get { return CssSelectorGroup.TraverseList(mSelectors); } 81 | } 82 | 83 | internal static IEnumerable TraverseList (CssPseudoClassSelector @this) 84 | { 85 | return @this.TraverseList(i => i.mNext); 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/Extensions/StringBuilderExts.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Text; 4 | 5 | namespace Alba.CsCss.Internal.Extensions 6 | { 7 | internal static class StringBuilderExts 8 | { 9 | private static readonly CultureInfo Culture = CultureInfo.InvariantCulture; 10 | 11 | internal static bool IsEmpty (this StringBuilder @this) 12 | { 13 | return @this.Length == 0; 14 | } 15 | 16 | internal static void AppendLiteral (this StringBuilder @this, string value) 17 | { 18 | @this.Append(value); 19 | } 20 | 21 | internal static void AppendInt (this StringBuilder @this, int value, int toBase) 22 | { 23 | @this.Append(Convert.ToString(value, toBase)); 24 | } 25 | 26 | internal static void AppendFloat (this StringBuilder @this, float value) 27 | { 28 | @this.Append(Convert.ToString(value, Culture)); 29 | } 30 | 31 | internal static int Length (this StringBuilder @this) 32 | { 33 | return @this.Length; 34 | } 35 | 36 | internal static void SetLength (this StringBuilder @this, int value) 37 | { 38 | @this.Length = value; 39 | } 40 | 41 | internal static void Truncate (this StringBuilder @this, int length = 0) 42 | { 43 | @this.Length = length; 44 | } 45 | 46 | internal static bool LowerCaseEqualsLiteral (this StringBuilder @this, string value) 47 | { 48 | return @this.ToString().ToLowerInvariant() == value; 49 | } 50 | 51 | internal static void AssignLiteral (this StringBuilder @this, string value) 52 | { 53 | @this.Clear(); 54 | @this.Append(value); 55 | } 56 | 57 | internal static void Trim (this StringBuilder @this, string aSet, bool aLeading, bool aTrailing, bool unused) 58 | { 59 | if (!aLeading && !aTrailing) 60 | return; 61 | string val = @this.ToString(); 62 | if (aLeading && aTrailing) 63 | val = val.Trim(aSet.ToCharArray()); 64 | else if (aLeading) 65 | val = val.TrimStart(aSet.ToCharArray()); 66 | else if (aTrailing) 67 | val = val.TrimEnd(aSet.ToCharArray()); 68 | @this.Clear(); 69 | @this.Append(val); 70 | } 71 | 72 | internal static void Clear (this StringBuilder @this) // missing in .NET 3.5 73 | { 74 | @this.Length = 0; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/CommonUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Alba.CsCss.Internal.Extensions; 4 | using Alba.CsCss.Style; 5 | using int32_t = System.Int32; 6 | using uint32_t = System.UInt32; 7 | 8 | namespace Alba.CsCss.Internal 9 | { 10 | internal static class CommonUtil 11 | { 12 | public static int32_t NSToIntRound (float x) 13 | { 14 | return x >= 0.0f ? (int32_t)(x + 0.5f) : (int32_t)(x - 0.5f); 15 | } 16 | 17 | public static nsresult NS_NewURI (out Uri result, string spec, string charset, Uri baseUri) 18 | { 19 | return Uri.TryCreate(baseUri, spec, out result) ? nsresult.OK : nsresult.ERROR_MALFORMED_URI; 20 | } 21 | 22 | internal static TResult ComputeCalc (TInput aValue, ICalcOps aOps) 23 | where TInput : ICalcOpsInput 24 | { 25 | switch (aOps.GetUnit(aValue)) { 26 | case CssUnit.Calc: { 27 | TInput[] arr = aValue.GetArrayValue(); 28 | Debug.Assert(arr.Count() == 1, "unexpected length"); 29 | return ComputeCalc(arr.Item(0), aOps); 30 | } 31 | case CssUnit.CalcPlus: 32 | case CssUnit.CalcMinus: { 33 | TInput[] arr = aValue.GetArrayValue(); 34 | Debug.Assert(arr.Count() == 2, "unexpected length"); 35 | TResult lhs = ComputeCalc(arr.Item(0), aOps), rhs = ComputeCalc(arr.Item(1), aOps); 36 | return aOps.MergeAdditive(aOps.GetUnit(aValue), lhs, rhs); 37 | } 38 | case CssUnit.CalcTimesL: { 39 | TInput[] arr = aValue.GetArrayValue(); 40 | Debug.Assert(arr.Count() == 2, "unexpected length"); 41 | TResult lhs = aOps.ComputeNumber(arr.Item(0)), rhs = ComputeCalc(arr.Item(1), aOps); 42 | return aOps.MergeMultiplicativeL(aOps.GetUnit(aValue), lhs, rhs); 43 | } 44 | case CssUnit.CalcTimesR: 45 | case CssUnit.CalcDivided: { 46 | TInput[] arr = aValue.GetArrayValue(); 47 | Debug.Assert(arr.Count() == 2, "unexpected length"); 48 | TResult lhs = ComputeCalc(arr.Item(0), aOps), rhs = aOps.ComputeNumber(arr.Item(1)); 49 | return aOps.MergeMultiplicativeR(aOps.GetUnit(aValue), lhs, rhs); 50 | } 51 | default: { 52 | return aOps.ComputeLeafValue(aValue); 53 | } 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoElementList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsCSSPseudoElementList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsCSSPseudoElementList.g.txt", () => GenerateCssPseudoElementListText()); 8 | T4.GenerateFile("CssPseudoElement.g.cs", () => GenerateCssPseudoElement()); 9 | T4.GenerateFile("nsCSSPseudoElements.g.cs", () => GenerateCssPseudoElements()); 10 | T4.Process(); 11 | #> 12 | 13 | <#+ void GenerateCssPseudoElementListText () { #> 14 | // 15 | // Generated file. Do not edit manually. 16 | // 17 | 18 | <#+ foreach (CssPseudoElement el in GetCssPseudoElements()) { #> 19 | // 20 | // Name: <#=el.Name#> 21 | // Value: <#=el.Value#> 22 | // Flags: <#=el.Flags#> 23 | <#+ } #> 24 | <#+ } /* void GenerateCssPseudoElementListText */ #> 25 | 26 | <#+ void GenerateCssPseudoElement () { #> 27 | // 28 | // Generated file. Do not edit manually. 29 | // 30 | 31 | using System.ComponentModel; 32 | 33 | namespace Alba.CsCss.Style 34 | { 35 | public enum CssPseudoElement 36 | { 37 | <#+ foreach (string elName in GetCssPseudoElements().Select(el => ToPascalId(el.Name))) { #> 38 | <#+ if (elName.StartsWith("Moz")) { #> 39 | [EditorBrowsable(EditorBrowsableState.Advanced)] 40 | <#+ } #> 41 | <#=elName#>, 42 | <#+ } #> 43 | [EditorBrowsable(EditorBrowsableState.Advanced)] 44 | PseudoElementCount, 45 | [EditorBrowsable(EditorBrowsableState.Advanced)] 46 | AnonBox = PseudoElementCount, 47 | #if MOZ_XUL 48 | XULTree, 49 | #endif 50 | [EditorBrowsable(EditorBrowsableState.Never)] 51 | NotPseudoElement, 52 | [EditorBrowsable(EditorBrowsableState.Never)] 53 | MAX, 54 | } 55 | } 56 | <#+ } /* void GenerateCssPseudoElement */ #> 57 | 58 | <#+ void GenerateCssPseudoElements () { #> 59 | // 60 | // Generated file. Do not edit manually. 61 | // 62 | 63 | using System.Collections.Generic; 64 | using Alba.CsCss.Internal; 65 | 66 | namespace Alba.CsCss.Style 67 | { 68 | internal static partial class nsCSSPseudoElements 69 | { 70 | <#+ foreach (CssPseudoElement cls in GetCssPseudoElements()) { #> 71 | public static string <#=ToId(cls.Name)#> = <#=cls.Value#>; 72 | <#+ } #> 73 | 74 | private static readonly IDictionary sPseudoElements = 75 | new Dictionary(ReferenceEqualityComparer.Default) { 76 | <#+ foreach (CssPseudoElement cls in GetCssPseudoElements()) { #> 77 | { <#=cls.Value#>, CssPseudoElement.<#=ToPascalId(cls.Name)#> }, 78 | <#+ } #> 79 | }; 80 | } 81 | } 82 | <#+ } /* void GenerateCssPseudoElement */ #> 83 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoElements.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.Collections.Generic; 6 | using Alba.CsCss.Internal; 7 | 8 | namespace Alba.CsCss.Style 9 | { 10 | internal static partial class nsCSSPseudoElements 11 | { 12 | public static string after = ":after"; 13 | public static string before = ":before"; 14 | public static string firstLetter = ":first-letter"; 15 | public static string firstLine = ":first-line"; 16 | public static string mozSelection = ":-moz-selection"; 17 | public static string mozFocusInner = ":-moz-focus-inner"; 18 | public static string mozFocusOuter = ":-moz-focus-outer"; 19 | public static string mozListBullet = ":-moz-list-bullet"; 20 | public static string mozListNumber = ":-moz-list-number"; 21 | public static string mozMathStretchy = ":-moz-math-stretchy"; 22 | public static string mozMathAnonymous = ":-moz-math-anonymous"; 23 | public static string mozProgressBar = ":-moz-progress-bar"; 24 | public static string mozRangeTrack = ":-moz-range-track"; 25 | public static string mozRangeProgress = ":-moz-range-progress"; 26 | public static string mozRangeThumb = ":-moz-range-thumb"; 27 | public static string mozMeterBar = ":-moz-meter-bar"; 28 | public static string mozPlaceholder = ":-moz-placeholder"; 29 | 30 | private static readonly IDictionary sPseudoElements = 31 | new Dictionary(ReferenceEqualityComparer.Default) { 32 | { ":after", CssPseudoElement.After }, 33 | { ":before", CssPseudoElement.Before }, 34 | { ":first-letter", CssPseudoElement.FirstLetter }, 35 | { ":first-line", CssPseudoElement.FirstLine }, 36 | { ":-moz-selection", CssPseudoElement.MozSelection }, 37 | { ":-moz-focus-inner", CssPseudoElement.MozFocusInner }, 38 | { ":-moz-focus-outer", CssPseudoElement.MozFocusOuter }, 39 | { ":-moz-list-bullet", CssPseudoElement.MozListBullet }, 40 | { ":-moz-list-number", CssPseudoElement.MozListNumber }, 41 | { ":-moz-math-stretchy", CssPseudoElement.MozMathStretchy }, 42 | { ":-moz-math-anonymous", CssPseudoElement.MozMathAnonymous }, 43 | { ":-moz-progress-bar", CssPseudoElement.MozProgressBar }, 44 | { ":-moz-range-track", CssPseudoElement.MozRangeTrack }, 45 | { ":-moz-range-progress", CssPseudoElement.MozRangeProgress }, 46 | { ":-moz-range-thumb", CssPseudoElement.MozRangeThumb }, 47 | { ":-moz-meter-bar", CssPseudoElement.MozMeterBar }, 48 | { ":-moz-placeholder", CssPseudoElement.MozPlaceholder }, 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Alba.CsCss/Common/Original/nsINameSpaceManager.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | #ifndef nsINameSpaceManager_h___ 7 | #define nsINameSpaceManager_h___ 8 | 9 | #include "nsISupports.h" 10 | #include "nsStringGlue.h" 11 | 12 | class nsIAtom; 13 | class nsString; 14 | 15 | #define kNameSpaceID_Unknown -1 16 | // 0 is special at C++, so use a static const int32_t for 17 | // kNameSpaceID_None to keep if from being cast to pointers 18 | // Note that the XBL cache assumes (and asserts) that it can treat a 19 | // single-byte value higher than kNameSpaceID_LastBuiltin specially. 20 | static const int32_t kNameSpaceID_None = 0; 21 | #define kNameSpaceID_XMLNS 1 // not really a namespace, but it needs to play the game 22 | #define kNameSpaceID_XML 2 23 | #define kNameSpaceID_XHTML 3 24 | #define kNameSpaceID_XLink 4 25 | #define kNameSpaceID_XSLT 5 26 | #define kNameSpaceID_XBL 6 27 | #define kNameSpaceID_MathML 7 28 | #define kNameSpaceID_RDF 8 29 | #define kNameSpaceID_XUL 9 30 | #define kNameSpaceID_SVG 10 31 | #define kNameSpaceID_LastBuiltin 10 // last 'built-in' namespace 32 | 33 | #define NS_NAMESPACEMANAGER_CONTRACTID "@mozilla.org/content/namespacemanager;1" 34 | 35 | #define NS_INAMESPACEMANAGER_IID \ 36 | { 0xd74e83e6, 0xf932, 0x4289, \ 37 | { 0xac, 0x95, 0x9e, 0x10, 0x24, 0x30, 0x88, 0xd6 } } 38 | 39 | /** 40 | * The Name Space Manager tracks the association between a NameSpace 41 | * URI and the int32_t runtime id. Mappings between NameSpaces and 42 | * NameSpace prefixes are managed by nsINameSpaces. 43 | * 44 | * All NameSpace URIs are stored in a global table so that IDs are 45 | * consistent accross the app. NameSpace IDs are only consistent at runtime 46 | * ie: they are not guaranteed to be consistent accross app sessions. 47 | * 48 | * The nsINameSpaceManager needs to have a live reference for as long as 49 | * the NameSpace IDs are needed. 50 | * 51 | */ 52 | 53 | class nsINameSpaceManager : public nsISupports 54 | { 55 | public: 56 | NS_DECLARE_STATIC_IID_ACCESSOR(NS_INAMESPACEMANAGER_IID) 57 | 58 | virtual nsresult RegisterNameSpace(const nsAString& aURI, 59 | int32_t& aNameSpaceID) = 0; 60 | 61 | virtual nsresult GetNameSpaceURI(int32_t aNameSpaceID, nsAString& aURI) = 0; 62 | virtual int32_t GetNameSpaceID(const nsAString& aURI) = 0; 63 | 64 | virtual bool HasElementCreator(int32_t aNameSpaceID) = 0; 65 | }; 66 | 67 | NS_DEFINE_STATIC_IID_ACCESSOR(nsINameSpaceManager, NS_INAMESPACEMANAGER_IID) 68 | 69 | nsresult NS_GetNameSpaceManager(nsINameSpaceManager** aInstancePtrResult); 70 | 71 | void NS_NameSpaceManagerShutdown(); 72 | 73 | #endif // nsINameSpaceManager_h___ 74 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPseudoElementList.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | /* atom list for CSS pseudo-elements */ 7 | 8 | /* 9 | * This file contains the list of nsIAtoms and their values for CSS 10 | * pseudo-elements. It is designed to be used as inline input to 11 | * nsCSSPseudoElements.cpp *only* through the magic of C preprocessing. All 12 | * entries must be enclosed either in the macro CSS_PSEUDO_ELEMENT; 13 | * these macros will have cruel and unusual things done to them. The 14 | * entries should be kept in some sort of logical order. 15 | * 16 | * Code including this file MUST define CSS_PSEUDO_ELEMENT, which takes 17 | * three parameters: 18 | * name_ : The C++ identifier used for the atom (which will be a member 19 | * of nsCSSPseudoElements) 20 | * value_ : The pseudo-element as a string, with single-colon syntax, 21 | * used as the string value of the atom. 22 | * flags_ : A bitfield containing flags defined in nsCSSPseudoElements.h 23 | */ 24 | 25 | // OUTPUT_CLASS=nsCSSPseudoElements 26 | // MACRO_NAME=CSS_PSEUDO_ELEMENT 27 | 28 | CSS_PSEUDO_ELEMENT(after, ":after", CSS_PSEUDO_ELEMENT_IS_CSS2) 29 | CSS_PSEUDO_ELEMENT(before, ":before", CSS_PSEUDO_ELEMENT_IS_CSS2) 30 | 31 | CSS_PSEUDO_ELEMENT(firstLetter, ":first-letter", 32 | CSS_PSEUDO_ELEMENT_IS_CSS2 | 33 | CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) 34 | CSS_PSEUDO_ELEMENT(firstLine, ":first-line", 35 | CSS_PSEUDO_ELEMENT_IS_CSS2 | 36 | CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) 37 | 38 | CSS_PSEUDO_ELEMENT(mozSelection, ":-moz-selection", 39 | CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS) 40 | 41 | // XXXbz should we really allow random content to style these? Maybe 42 | // use our flags to prevent that? 43 | CSS_PSEUDO_ELEMENT(mozFocusInner, ":-moz-focus-inner", 0) 44 | CSS_PSEUDO_ELEMENT(mozFocusOuter, ":-moz-focus-outer", 0) 45 | 46 | // XXXbz should we really allow random content to style these? Maybe 47 | // use our flags to prevent that? 48 | CSS_PSEUDO_ELEMENT(mozListBullet, ":-moz-list-bullet", 0) 49 | CSS_PSEUDO_ELEMENT(mozListNumber, ":-moz-list-number", 0) 50 | 51 | CSS_PSEUDO_ELEMENT(mozMathStretchy, ":-moz-math-stretchy", 0) 52 | CSS_PSEUDO_ELEMENT(mozMathAnonymous, ":-moz-math-anonymous", 0) 53 | 54 | // HTML5 Forms pseudo elements 55 | CSS_PSEUDO_ELEMENT(mozProgressBar, ":-moz-progress-bar", 0) 56 | CSS_PSEUDO_ELEMENT(mozRangeTrack, ":-moz-range-track", 0) 57 | CSS_PSEUDO_ELEMENT(mozRangeProgress, ":-moz-range-progress", 0) 58 | CSS_PSEUDO_ELEMENT(mozRangeThumb, ":-moz-range-thumb", 0) 59 | CSS_PSEUDO_ELEMENT(mozMeterBar, ":-moz-meter-bar", 0) 60 | CSS_PSEUDO_ELEMENT(mozPlaceholder, ":-moz-placeholder", 0) 61 | -------------------------------------------------------------------------------- /Alba.CsCss/Common/nsNameSpaceManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Alba.CsCss.Internal.Extensions; 3 | 4 | // Somewhat similar to XmlNamespaceManager. 5 | namespace Alba.CsCss 6 | { 7 | internal class nsNameSpaceManager 8 | { 9 | private readonly Dictionary mURIToIDTable = new Dictionary(); 10 | private readonly List mURIArray = new List(); 11 | 12 | public static readonly nsNameSpaceManager Instance = new nsNameSpaceManager(); 13 | 14 | public nsNameSpaceManager () 15 | { 16 | RegisterNameSpace("http://www.w3.org/2000/xmlns/", nsNameSpace.XMLNS); 17 | RegisterNameSpace("http://www.w3.org/XML/1998/namespace", nsNameSpace.XML); 18 | RegisterNameSpace("http://www.w3.org/1999/xhtml", nsNameSpace.XHTML); 19 | RegisterNameSpace("http://www.w3.org/1999/xlink", nsNameSpace.XLink); 20 | RegisterNameSpace("http://www.w3.org/1999/XSL/Transform", nsNameSpace.XSLT); 21 | RegisterNameSpace("http://www.mozilla.org/xbl", nsNameSpace.XBL); 22 | RegisterNameSpace("http://www.w3.org/1998/Math/MathML", nsNameSpace.MathML); 23 | RegisterNameSpace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", nsNameSpace.RDF); 24 | RegisterNameSpace("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", nsNameSpace.XUL); 25 | RegisterNameSpace("http://www.w3.org/2000/svg", nsNameSpace.SVG); 26 | } 27 | 28 | public nsresult RegisterNameSpace (string aURI, int aNameSpaceID) 29 | { 30 | return RegisterNameSpace(aURI, out aNameSpaceID); 31 | } 32 | 33 | public nsresult RegisterNameSpace (string aURI, out int aNameSpaceID) 34 | { 35 | if (aURI == "") { 36 | aNameSpaceID = nsNameSpace.None; 37 | } 38 | else if (!mURIToIDTable.TryGetValue(aURI, out aNameSpaceID)) { 39 | aNameSpaceID = mURIArray.Count + 1; 40 | mURIToIDTable.Add(aURI, aNameSpaceID); 41 | mURIArray.Add(aURI); 42 | } 43 | return nsresult.OK; 44 | } 45 | 46 | public nsresult GetNameSpaceURI (int aNameSpaceID, ref string aURI) 47 | { 48 | int index = aNameSpaceID - 1; 49 | if (0 <= index && index < mURIArray.Count) { 50 | aURI = mURIArray[index]; 51 | return nsresult.OK; 52 | } 53 | else { 54 | aURI = aURI.Trim(); // yes, the original code is fucked up 55 | return nsresult.ERROR_ILLEGAL_VALUE; 56 | } 57 | } 58 | 59 | public string GetNameSpaceURI (int aNameSpaceID) 60 | { 61 | string uri = ""; 62 | return GetNameSpaceURI(aNameSpaceID, ref uri).Succeeded() ? uri : null; 63 | } 64 | 65 | public int GetNameSpaceID (string aURI) 66 | { 67 | return aURI == "" ? nsNameSpace.None : mURIToIDTable.GetOrDefault(aURI, nsNameSpace.Unknown); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/nsMediaFeatures.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "cpp"); 6 | string sourceFeatures = source.ReMatchGet(@"(?s)nsMediaFeatures::features\[\] = {(.*?)};"); 7 | 8 | var T4 = GetT4(); 9 | T4.GenerateFile("nsMediaFeatures.conv.cs", () => GenerateMediaFeatures(sourceFeatures)); 10 | T4.Process(); 11 | #> 12 | <#+ 13 | void GenerateMediaFeatures (string source) { 14 | #> 15 | // 16 | // Generated file. Do not edit manually. 17 | // 18 | 19 | using System.Collections.Generic; 20 | 21 | namespace Alba.CsCss.Style 22 | { 23 | <#+ WriteTypeRenames("nsMediaFeature"); #> 24 | 25 | internal partial class nsMediaFeatures 26 | { 27 | private static readonly List features = new List { 28 | <#= ConvertMediaFeaturesSource(source).Unindent(4).Indent(12) #> 29 | //new CssMediaFeature() 30 | }; 31 | 32 | private static readonly CssMediaFeature EmptyFeature = new CssMediaFeature(); 33 | } 34 | } 35 | <#+ 36 | } // GenerateMediaFeatures 37 | #> 38 | <#+ 39 | string ConvertMediaFeaturesSource (string source) 40 | { 41 | bool isStandardFeaturesProcessed = false; 42 | return source 43 | 44 | // whitespace 45 | .ReReplace(@"\r", "") 46 | 47 | // common c++ 48 | .Replace("nullptr", "null") 49 | .Replace("::", ".") 50 | 51 | // specific expressions 52 | .ReReplace(@"{ (.*) }", "$1") // union 53 | .ReReplace(@"&nsGkAtoms", "nsGkAtoms") 54 | .ReReplace( 55 | @"{$,$,$,$,$}".Replace("$", "([^,]+)"), 56 | m => { 57 | string name = m.Get(1).Trim(), 58 | range = m.Get(2).Trim().Replace("nsMediaFeature.e", "nsMediaFeature.RangeType."), 59 | value = m.Get(3).Trim().Replace("nsMediaFeature.e", "nsMediaFeature.ValueType."), 60 | data = m.Get(4).Trim(); 61 | if (name.Contains("_moz_is_resource_document")) 62 | isStandardFeaturesProcessed = true; 63 | if (isStandardFeaturesProcessed) 64 | return "// {0}".Fmt(name); 65 | else if (data == "null") 66 | return "new nsMediaFeature({0}, {1}, {2})".Fmt(name, range, value); 67 | else if (data.StartsWith("k")) 68 | return "new nsMediaFeature({0}, {1}, {2}, nsCSSProps.{3})".Fmt(name, range, value, data); 69 | else 70 | return "new nsMediaFeature({0}, {1}, {2}, {3})".Fmt(name, range, value, data); 71 | }) 72 | 73 | // whitespace 74 | .ReReplace(@"\n\s*;\n", "\n") 75 | .ReReplace(@"\n{3,}", "\n\n") 76 | .ReReplace(@"\n", "\r\n") 77 | .Trim() 78 | ; 79 | } 80 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Values/CssValueGradient.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace Alba.CsCss.Style 5 | { 6 | [DebuggerDisplay ("gradient()")] 7 | public class CssValueGradient 8 | { 9 | internal readonly List mStops = new List(); 10 | internal readonly CssValue[] mRadialValues = new CssValue[2]; 11 | internal bool mIsRadial, mIsRepeating, mIsExplicitSize, mIsLegacySyntax; 12 | internal CssValuePair mBgPos = new CssValuePair(); 13 | internal CssValue mAngle; 14 | 15 | internal CssValueGradient (bool aIsRadial, bool aIsRepeating) 16 | { 17 | mIsRadial = aIsRadial; 18 | mIsRepeating = aIsRepeating; 19 | } 20 | 21 | internal CssValue GetRadialShape () 22 | { 23 | return mRadialValues[0]; 24 | } 25 | 26 | internal CssValue GetRadialSize () 27 | { 28 | return mRadialValues[1]; 29 | } 30 | 31 | internal CssValue GetRadiusX () 32 | { 33 | return mRadialValues[0]; 34 | } 35 | 36 | internal CssValue GetRadiusY () 37 | { 38 | return mRadialValues[1]; 39 | } 40 | 41 | internal void SetRadialShape (CssValue aValue) 42 | { 43 | mRadialValues[0] = aValue; 44 | } 45 | 46 | internal void SetRadialSize (CssValue aValue) 47 | { 48 | mRadialValues[1] = aValue; 49 | } 50 | 51 | internal void SetRadiusX (CssValue aValue) 52 | { 53 | mRadialValues[0] = aValue; 54 | } 55 | 56 | internal void SetRadiusY (CssValue aValue) 57 | { 58 | mRadialValues[1] = aValue; 59 | } 60 | 61 | // public interface 62 | 63 | public IList Stops 64 | { 65 | get { return mStops; } 66 | } 67 | 68 | public bool IsRadial 69 | { 70 | get { return mIsRadial; } 71 | } 72 | 73 | public bool IsRepeating 74 | { 75 | get { return mIsRepeating; } 76 | } 77 | 78 | public bool IsExplicitSize 79 | { 80 | get { return mIsExplicitSize; } 81 | } 82 | 83 | public CssValuePair BgPos 84 | { 85 | get { return mBgPos; } 86 | } 87 | 88 | public CssValue Angle 89 | { 90 | get { return mAngle; } 91 | } 92 | 93 | public CssValue RadialShape 94 | { 95 | get { return mRadialValues[0]; } 96 | } 97 | 98 | public CssValue RadialSize 99 | { 100 | get { return mRadialValues[1]; } 101 | } 102 | 103 | public CssValue RadiusX 104 | { 105 | get { return mRadialValues[0]; } 106 | } 107 | 108 | public CssValue RadiusY 109 | { 110 | get { return mRadialValues[1]; } 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssFontFace.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | public class CssFontFace 10 | { 11 | private CssValue mFamily; 12 | private CssValue mStyle; 13 | private CssValue mWeight; 14 | private CssValue mStretch; 15 | private CssValue mSrc; 16 | private CssValue mUnicodeRange; 17 | private CssValue mFontFeatureSettings; 18 | private CssValue mFontLanguageOverride; 19 | 20 | internal CssValue GetValue (nsCSSFontDesc aDescID) 21 | { 22 | switch (aDescID) { 23 | case nsCSSFontDesc.Family: return mFamily; 24 | case nsCSSFontDesc.Style: return mStyle; 25 | case nsCSSFontDesc.Weight: return mWeight; 26 | case nsCSSFontDesc.Stretch: return mStretch; 27 | case nsCSSFontDesc.Src: return mSrc; 28 | case nsCSSFontDesc.UnicodeRange: return mUnicodeRange; 29 | case nsCSSFontDesc.FontFeatureSettings: return mFontFeatureSettings; 30 | case nsCSSFontDesc.FontLanguageOverride: return mFontLanguageOverride; 31 | default: throw new ArgumentOutOfRangeException("aDescID"); 32 | } 33 | } 34 | 35 | internal void SetValue (nsCSSFontDesc aDescID, CssValue value) 36 | { 37 | switch (aDescID) { 38 | case nsCSSFontDesc.Family: mFamily = value; break; 39 | case nsCSSFontDesc.Style: mStyle = value; break; 40 | case nsCSSFontDesc.Weight: mWeight = value; break; 41 | case nsCSSFontDesc.Stretch: mStretch = value; break; 42 | case nsCSSFontDesc.Src: mSrc = value; break; 43 | case nsCSSFontDesc.UnicodeRange: mUnicodeRange = value; break; 44 | case nsCSSFontDesc.FontFeatureSettings: mFontFeatureSettings = value; break; 45 | case nsCSSFontDesc.FontLanguageOverride: mFontLanguageOverride = value; break; 46 | default: throw new ArgumentOutOfRangeException("aDescID"); 47 | } 48 | } 49 | 50 | // Public interface 51 | 52 | public CssValue Family 53 | { 54 | get { return mFamily; } 55 | } 56 | 57 | public CssValue Style 58 | { 59 | get { return mStyle; } 60 | } 61 | 62 | public CssValue Weight 63 | { 64 | get { return mWeight; } 65 | } 66 | 67 | public CssValue Stretch 68 | { 69 | get { return mStretch; } 70 | } 71 | 72 | public CssValue Src 73 | { 74 | get { return mSrc; } 75 | } 76 | 77 | public CssValue UnicodeRange 78 | { 79 | get { return mUnicodeRange; } 80 | } 81 | 82 | public CssValue FontFeatureSettings 83 | { 84 | get { return mFontFeatureSettings; } 85 | } 86 | 87 | public CssValue FontLanguageOverride 88 | { 89 | get { return mFontLanguageOverride; } 90 | } 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/nsMediaFeaturesH.h: -------------------------------------------------------------------------------- 1 | /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | /* the features that media queries can test */ 7 | 8 | #ifndef nsMediaFeatures_h_ 9 | #define nsMediaFeatures_h_ 10 | 11 | #include "nsError.h" 12 | 13 | class nsIAtom; 14 | class nsPresContext; 15 | class nsCSSValue; 16 | 17 | struct nsMediaFeature; 18 | typedef nsresult 19 | (* nsMediaFeatureValueGetter)(nsPresContext* aPresContext, 20 | const nsMediaFeature* aFeature, 21 | nsCSSValue& aResult); 22 | 23 | struct nsMediaFeature { 24 | nsIAtom **mName; // extra indirection to point to nsGkAtoms members 25 | 26 | enum RangeType { eMinMaxAllowed, eMinMaxNotAllowed }; 27 | RangeType mRangeType; 28 | 29 | enum ValueType { 30 | // All value types allow eCSSUnit_Null to indicate that no value 31 | // was given (in addition to the types listed below). 32 | eLength, // values are such that nsCSSValue::IsLengthUnit() is true 33 | eInteger, // values are eCSSUnit_Integer 34 | eFloat, // values are eCSSUnit_Number 35 | eBoolInteger,// values are eCSSUnit_Integer (0, -0, or 1 only) 36 | eIntRatio, // values are eCSSUnit_Array of two eCSSUnit_Integer 37 | eResolution, // values are in eCSSUnit_Inch (for dpi), 38 | // eCSSUnit_Pixel (for dppx), or 39 | // eCSSUnit_Centimeter (for dpcm) 40 | eEnumerated, // values are eCSSUnit_Enumerated (uses keyword table) 41 | eIdent // values are eCSSUnit_Ident 42 | // Note that a number of pieces of code (both for parsing and 43 | // for matching of valueless expressions) assume that all numeric 44 | // value types cannot be negative. The parsing code also does 45 | // not allow zeros in eIntRatio types. 46 | }; 47 | ValueType mValueType; 48 | 49 | union { 50 | // In static arrays, it's the first member that's initialized. We 51 | // need that to be void* so we can initialize both other types. 52 | // This member should never be accessed by name. 53 | const void* mInitializer_; 54 | // If mValueType == eEnumerated: const int32_t*: keyword table in 55 | // the same format as the keyword tables in nsCSSProps. 56 | const int32_t* mKeywordTable; 57 | // If mGetter == GetSystemMetric (which implies mValueType == 58 | // eBoolInteger): nsIAtom * const *, for the system metric. 59 | nsIAtom * const * mMetric; 60 | } mData; 61 | 62 | // A function that returns the current value for this feature for a 63 | // given presentation. If it returns eCSSUnit_Null, the feature is 64 | // not present. 65 | nsMediaFeatureValueGetter mGetter; 66 | }; 67 | 68 | class nsMediaFeatures { 69 | public: 70 | // Terminated with an entry whose mName is null. 71 | static const nsMediaFeature features[]; 72 | }; 73 | 74 | #endif /* !defined(nsMediaFeatures_h_) */ 75 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssStyleSheet.CssRuleKind.g.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.Collections.Generic; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | public partial class CssStyleSheet 10 | { 11 | public IEnumerable CharsetRules 12 | { 13 | get { return GetRules(); } 14 | } 15 | 16 | public IEnumerable AllCharsetRules 17 | { 18 | get { return GetAllRules(); } 19 | } 20 | 21 | public IEnumerable ImportRules 22 | { 23 | get { return GetRules(); } 24 | } 25 | 26 | public IEnumerable AllImportRules 27 | { 28 | get { return GetAllRules(); } 29 | } 30 | 31 | public IEnumerable NamespaceRules 32 | { 33 | get { return GetRules(); } 34 | } 35 | 36 | public IEnumerable AllNamespaceRules 37 | { 38 | get { return GetAllRules(); } 39 | } 40 | 41 | public IEnumerable StyleRules 42 | { 43 | get { return GetRules(); } 44 | } 45 | 46 | public IEnumerable AllStyleRules 47 | { 48 | get { return GetAllRules(); } 49 | } 50 | 51 | public IEnumerable MediaRules 52 | { 53 | get { return GetRules(); } 54 | } 55 | 56 | public IEnumerable AllMediaRules 57 | { 58 | get { return GetAllRules(); } 59 | } 60 | 61 | public IEnumerable FontFaceRules 62 | { 63 | get { return GetRules(); } 64 | } 65 | 66 | public IEnumerable AllFontFaceRules 67 | { 68 | get { return GetAllRules(); } 69 | } 70 | 71 | public IEnumerable PageRules 72 | { 73 | get { return GetRules(); } 74 | } 75 | 76 | public IEnumerable AllPageRules 77 | { 78 | get { return GetAllRules(); } 79 | } 80 | 81 | public IEnumerable KeyframeRules 82 | { 83 | get { return GetRules(); } 84 | } 85 | 86 | public IEnumerable AllKeyframeRules 87 | { 88 | get { return GetAllRules(); } 89 | } 90 | 91 | public IEnumerable KeyframesRules 92 | { 93 | get { return GetRules(); } 94 | } 95 | 96 | public IEnumerable AllKeyframesRules 97 | { 98 | get { return GetAllRules(); } 99 | } 100 | 101 | public IEnumerable SupportsRules 102 | { 103 | get { return GetRules(); } 104 | } 105 | 106 | public IEnumerable AllSupportsRules 107 | { 108 | get { return GetAllRules(); } 109 | } 110 | 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Alba.CsCss/Common/ErrorReporter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Text; 4 | using Alba.CsCss.Globalization; 5 | using Alba.CsCss.Style; 6 | 7 | namespace Alba.CsCss 8 | { 9 | internal class ErrorReporter 10 | { 11 | private readonly CssScanner mScanner; 12 | private readonly CssStyleSheet mSheet; 13 | private readonly CssLoader mLoader; 14 | internal readonly Uri mUri; 15 | internal readonly StringBuilder mError = new StringBuilder(); 16 | internal string mFileName, mErrorLine; 17 | internal int mErrorLineNumber, mErrorColumnNumber; 18 | private int mPrevErrorLineNumber; 19 | 20 | internal ErrorReporter (CssScanner aScanner, CssStyleSheet aSheet, CssLoader aLoader, Uri aUri) 21 | { 22 | mScanner = aScanner; 23 | mSheet = aSheet; 24 | mLoader = aLoader; 25 | mUri = aUri; 26 | } 27 | 28 | internal void OutputError () 29 | { 30 | if (mError.Length == 0) 31 | return; 32 | if (mFileName == null) 33 | mFileName = mUri != null ? mUri.AbsoluteUri : "dynamic"; 34 | AlbaCsCssTraceSources.CssParser.TraceEvent(TraceEventType.Warning, 0, 35 | "{0} Source: {1} (line {2}, column {3})", 36 | mError, mFileName, mErrorLineNumber, mErrorColumnNumber); 37 | mLoader.FireParseError(this); 38 | ClearError(); 39 | } 40 | 41 | internal void ClearError () 42 | { 43 | mError.Length = 0; 44 | } 45 | 46 | private void AddToError (string aErrorText) 47 | { 48 | if (mError.Length == 0) { 49 | mError.Append(aErrorText); 50 | mErrorLineNumber = mScanner.GetLineNumber(); 51 | mErrorColumnNumber = mScanner.GetColumnLineNumber(); 52 | if (mErrorLine == null || mErrorLineNumber != mPrevErrorLineNumber) { 53 | mErrorLine = mScanner.GetCurrentLine(); 54 | mPrevErrorLineNumber = mErrorLineNumber; 55 | } 56 | } 57 | else { 58 | mError.Append(" "); 59 | mError.Append(aErrorText); 60 | } 61 | } 62 | 63 | internal void ReportUnexpected (string aMessage) 64 | { 65 | AddToError(CssResources.GetString(aMessage)); 66 | } 67 | 68 | internal void ReportUnexpected (string aMessage, string aParam) 69 | { 70 | AddToError(CssResources.FormatString(aMessage, aParam)); 71 | } 72 | 73 | internal void ReportUnexpected (string aMessage, CssToken aToken) 74 | { 75 | var sbToken = new StringBuilder(); 76 | aToken.AppendToString(sbToken); 77 | AddToError(CssResources.FormatString(aMessage, sbToken.ToString())); 78 | } 79 | 80 | internal void ReportUnexpected (string aMessage, CssToken aToken, char aChar) 81 | { 82 | AddToError(CssResources.FormatString(aMessage, aToken, aChar)); 83 | } 84 | 85 | internal void ReportUnexpectedEOF (string aMessage) 86 | { 87 | AddToError(CssResources.FormatString("PEUnexpEOF2", CssResources.GetString(aMessage))); 88 | } 89 | 90 | internal void ReportUnexpected (char aExpected) 91 | { 92 | AddToError(CssResources.FormatString("PEUnexpEOF2", string.Format("'{0}'", aExpected))); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSFontDescList.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <#@ include file="nsCSSFontDescList.ttinclude" #> 5 | <# 6 | var T4 = GetT4(); 7 | //T4.GenerateFile("nsCSSFontDescList.g.txt", () => GenerateCssFontDescListText()); 8 | T4.GenerateFile("nsCSSFontDesc.g.cs", () => GenerateCssFontDesc()); 9 | T4.GenerateFile("CssFontFace.g.cs", () => GenerateCssFontFace()); 10 | T4.GenerateFile("nsCSSProps.CSSFontDescList.g.cs", () => GenerateCssProps()); 11 | T4.Process(); 12 | #> 13 | 14 | <#+ void GenerateCssFontDescListText () { #> 15 | // 16 | // Generated file. Do not edit manually. 17 | // 18 | 19 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 20 | // 21 | // Name: <#=desc.Name#> 22 | // Method: <#=desc.Method#> 23 | <#+ } #> 24 | <#+ } /* void GenerateCssFontDescListText */ #> 25 | 26 | <#+ void GenerateCssFontDesc () { #> 27 | // 28 | // Generated file. Do not edit manually. 29 | // 30 | 31 | namespace Alba.CsCss.Style 32 | { 33 | internal enum nsCSSFontDesc 34 | { 35 | UNKNOWN, 36 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 37 | <#=desc.Method#>, 38 | <#+ } #> 39 | COUNT 40 | } 41 | } 42 | <#+ } /* void GenerateCssFontDesc */ #> 43 | 44 | <#+ void GenerateCssFontFace () { #> 45 | // 46 | // Generated file. Do not edit manually. 47 | // 48 | 49 | using System; 50 | 51 | namespace Alba.CsCss.Style 52 | { 53 | public class CssFontFace 54 | { 55 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 56 | private CssValue m<#=desc.Method#>; 57 | <#+ } #> 58 | 59 | internal CssValue GetValue (nsCSSFontDesc aDescID) 60 | { 61 | switch (aDescID) { 62 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 63 | case nsCSSFontDesc.<#=desc.Method#>: return m<#=desc.Method#>; 64 | <#+ } #> 65 | default: throw new ArgumentOutOfRangeException("aDescID"); 66 | } 67 | } 68 | 69 | internal void SetValue (nsCSSFontDesc aDescID, CssValue value) 70 | { 71 | switch (aDescID) { 72 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 73 | case nsCSSFontDesc.<#=desc.Method#>: m<#=desc.Method#> = value; break; 74 | <#+ } #> 75 | default: throw new ArgumentOutOfRangeException("aDescID"); 76 | } 77 | } 78 | 79 | // Public interface 80 | 81 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 82 | public CssValue <#=desc.Method#> 83 | { 84 | get { return m<#=desc.Method#>; } 85 | } 86 | 87 | <#+ } #> 88 | } 89 | } 90 | <#+ } /* void GenerateCssFontFace */ #> 91 | 92 | <#+ void GenerateCssProps () { #> 93 | // 94 | // Generated file. Do not edit manually. 95 | // 96 | 97 | using System.Collections.Generic; 98 | using Alba.CsCss.Internal.Extensions; 99 | 100 | namespace Alba.CsCss.Style 101 | { 102 | internal partial class nsCSSProps 103 | { 104 | private static readonly string[] kCSSRawFontDescs = { 105 | <#+ foreach (CssFontDesc desc in GetCssFontDescs()) { #> 106 | "<#=desc.Name#>", 107 | <#+ } #> 108 | }; 109 | 110 | private static readonly Dictionary gFontDescTable = kCSSRawFontDescs.ToCaseInsensitiveNameTable(); 111 | } 112 | } 113 | <#+ } /* void GenerateCssProps */ #> 114 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/nsCSSProps.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Linq; 3 | using Alba.CsCss.Internal.Extensions; 4 | using int32_t = System.Int32; 5 | 6 | namespace Alba.CsCss.Style 7 | { 8 | internal partial class nsCSSProps 9 | { 10 | private static int FindIndexOfKeyword (CssKeyword aKeyword, int[] aTable) 11 | { 12 | int32_t index = 0; 13 | while ((CssKeyword)(aTable[index]) != CssKeyword.Unknown) { 14 | if ((CssKeyword)(aTable[index]) == aKeyword) 15 | return index; 16 | index += 2; 17 | } 18 | return -1; 19 | } 20 | 21 | public static bool FindKeyword (CssKeyword aKeyword, int[] aTable, ref int aResult) 22 | { 23 | int32_t index = FindIndexOfKeyword(aKeyword, aTable); 24 | if (index >= 0) { 25 | aResult = aTable[index + 1]; 26 | return true; 27 | } 28 | return false; 29 | } 30 | 31 | public static string GetStringValue (CssProperty aProperty) 32 | { 33 | return kCSSRawProperties[(int)aProperty]; 34 | } 35 | 36 | public static bool IsEnabled (CssProperty aProperty) 37 | { 38 | return true; // gPropertyEnabled is an array of true, so generating it is pointless 39 | } 40 | 41 | public static bool IsShorthand (CssProperty aProperty) 42 | { 43 | return (aProperty >= CssProperty.PropertyCountNoShorthands); 44 | } 45 | 46 | public static nsCSSFontDesc LookupFontDesc (string aFontDesc) 47 | { 48 | return (nsCSSFontDesc)(gFontDescTable.GetOrDefault(aFontDesc, -1)); 49 | } 50 | 51 | public static CssProperty LookupProperty (string aProperty, EnabledState aEnabled) 52 | { 53 | CssProperty res = (CssProperty)gPropertyTable.GetOrDefault(aProperty, -1); 54 | if (res >= CssProperty.PropertyCount) { 55 | if (IsEnabled(res) || aEnabled == EnabledState.Any) { 56 | res = gAliases[res - CssProperty.PropertyCount]; 57 | Debug.Assert(0 <= res && res < CssProperty.PropertyCount, "aliases must not point to other aliases"); 58 | } 59 | else { 60 | res = CssProperty.Unknown; 61 | } 62 | } 63 | if (res != CssProperty.Unknown && aEnabled == EnabledState.Enabled && !IsEnabled(res)) { 64 | res = CssProperty.Unknown; 65 | } 66 | return res; 67 | } 68 | 69 | public static int ParserVariant (CssProperty aProperty) 70 | { 71 | return kParserVariantTable[(int)aProperty]; 72 | } 73 | 74 | public static bool PropHasFlags (CssProperty aProperty, int aFlags) 75 | { 76 | return (kFlagsTable[(int)aProperty] & aFlags) == aFlags; 77 | } 78 | 79 | public static int PropertyParseType (CssProperty aProperty) 80 | { 81 | return kFlagsTable[(int)aProperty] & PARSE_PROPERTY_MASK; 82 | } 83 | 84 | public static CssProperty[] SubpropertyEntryFor (CssProperty aProperty, bool skipUnknown = false) 85 | { 86 | CssProperty[] res = kSubpropertyTable[aProperty - CssProperty.PropertyCountNoShorthands]; 87 | return skipUnknown ? res.Where(p => p != CssProperty.Unknown).ToArray() : res; 88 | } 89 | 90 | public static int ValueRestrictions (CssProperty aProperty) 91 | { 92 | return kFlagsTable[(int)aProperty] & VALUE_RESTRICTION_MASK; 93 | } 94 | 95 | internal enum EnabledState 96 | { 97 | Enabled, 98 | Any 99 | }; 100 | } 101 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsCSSPropAliasList.h: -------------------------------------------------------------------------------- 1 | /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | /* 7 | * a list of all CSS property aliases with data about them, for preprocessing 8 | */ 9 | 10 | /****** 11 | 12 | This file contains the list of all CSS properties that are just 13 | aliases for other properties (e.g., for when we temporarily continue 14 | to support a prefixed property after adding support for its unprefixed 15 | form). It is designed to be used as inline input through the magic of 16 | C preprocessing. All entries must be enclosed in the appropriate 17 | CSS_PROP_ALIAS macro which will have cruel and unusual things done to 18 | it. 19 | 20 | The arguments to CSS_PROP_ALIAS are: 21 | 22 | -. 'aliasname' entries represent a CSS property name and *must* use 23 | only lowercase characters. 24 | 25 | -. 'id' should be the same as the 'id' field in nsCSSPropList.h for 26 | the property that 'aliasname' is being aliased to. 27 | 28 | -. 'method' is the CSS2Properties property name. Unlike 29 | nsCSSPropList.h, prefixes should just be included in this file (rather 30 | than needing the CSS_PROP_DOMPROP_PREFIXED(prop) macro). 31 | 32 | -. 'pref' is the name of a pref that controls whether the property 33 | is enabled. The property is enabled if 'pref' is an empty string, 34 | or if the boolean property whose name is 'pref' is set to true. 35 | 36 | ******/ 37 | 38 | CSS_PROP_ALIAS(-moz-transform-origin, transform_origin, MozTransformOrigin, "layout.css.prefixes.transforms") 39 | CSS_PROP_ALIAS(-moz-perspective-origin, perspective_origin, MozPerspectiveOrigin, "layout.css.prefixes.transforms") 40 | CSS_PROP_ALIAS(-moz-perspective, perspective, MozPerspective, "layout.css.prefixes.transforms") 41 | CSS_PROP_ALIAS(-moz-transform-style, transform_style, MozTransformStyle, "layout.css.prefixes.transforms") 42 | CSS_PROP_ALIAS(-moz-backface-visibility, backface_visibility, MozBackfaceVisibility, "layout.css.prefixes.transforms") 43 | CSS_PROP_ALIAS(-moz-border-image, border_image, MozBorderImage, "layout.css.prefixes.border-image") 44 | CSS_PROP_ALIAS(-moz-transition, transition, MozTransition, "layout.css.prefixes.transitions") 45 | CSS_PROP_ALIAS(-moz-transition-delay, transition_delay, MozTransitionDelay, "layout.css.prefixes.transitions") 46 | CSS_PROP_ALIAS(-moz-transition-duration, transition_duration, MozTransitionDuration, "layout.css.prefixes.transitions") 47 | CSS_PROP_ALIAS(-moz-transition-property, transition_property, MozTransitionProperty, "layout.css.prefixes.transitions") 48 | CSS_PROP_ALIAS(-moz-transition-timing-function, transition_timing_function, MozTransitionTimingFunction, "layout.css.prefixes.transitions") 49 | CSS_PROP_ALIAS(-moz-animation, animation, MozAnimation, "layout.css.prefixes.animations") 50 | CSS_PROP_ALIAS(-moz-animation-delay, animation_delay, MozAnimationDelay, "layout.css.prefixes.animations") 51 | CSS_PROP_ALIAS(-moz-animation-direction, animation_direction, MozAnimationDirection, "layout.css.prefixes.animations") 52 | CSS_PROP_ALIAS(-moz-animation-duration, animation_duration, MozAnimationDuration, "layout.css.prefixes.animations") 53 | CSS_PROP_ALIAS(-moz-animation-fill-mode, animation_fill_mode, MozAnimationFillMode, "layout.css.prefixes.animations") 54 | CSS_PROP_ALIAS(-moz-animation-iteration-count, animation_iteration_count, MozAnimationIterationCount, "layout.css.prefixes.animations") 55 | CSS_PROP_ALIAS(-moz-animation-name, animation_name, MozAnimationName, "layout.css.prefixes.animations") 56 | CSS_PROP_ALIAS(-moz-animation-play-state, animation_play_state, MozAnimationPlayState, "layout.css.prefixes.animations") 57 | CSS_PROP_ALIAS(-moz-animation-timing-function, animation_timing_function, MozAnimationTimingFunction, "layout.css.prefixes.animations") 58 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Media/Original/nsMediaFeatures.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | 5 | using System.Collections.Generic; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | using nsMediaFeature = CssMediaFeature; 10 | 11 | internal partial class nsMediaFeatures 12 | { 13 | private static readonly List features = new List { 14 | new nsMediaFeature(nsGkAtoms.width, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Length), 15 | new nsMediaFeature(nsGkAtoms.height, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Length), 16 | new nsMediaFeature(nsGkAtoms.deviceWidth, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Length), 17 | new nsMediaFeature(nsGkAtoms.deviceHeight, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Length), 18 | new nsMediaFeature(nsGkAtoms.orientation, nsMediaFeature.RangeType.MinMaxNotAllowed, nsMediaFeature.ValueType.Enumerated, nsCSSProps.kOrientationKeywords), 19 | new nsMediaFeature(nsGkAtoms.aspectRatio, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.IntRatio), 20 | new nsMediaFeature(nsGkAtoms.deviceAspectRatio, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.IntRatio), 21 | new nsMediaFeature(nsGkAtoms.color, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Integer), 22 | new nsMediaFeature(nsGkAtoms.colorIndex, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Integer), 23 | new nsMediaFeature(nsGkAtoms.monochrome, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Integer), 24 | new nsMediaFeature(nsGkAtoms.resolution, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Resolution), 25 | new nsMediaFeature(nsGkAtoms.scan, nsMediaFeature.RangeType.MinMaxNotAllowed, nsMediaFeature.ValueType.Enumerated, nsCSSProps.kScanKeywords), 26 | new nsMediaFeature(nsGkAtoms.grid, nsMediaFeature.RangeType.MinMaxNotAllowed, nsMediaFeature.ValueType.BoolInteger), 27 | // Mozilla extensions 28 | new nsMediaFeature(nsGkAtoms._moz_device_pixel_ratio, nsMediaFeature.RangeType.MinMaxAllowed, nsMediaFeature.ValueType.Float), 29 | new nsMediaFeature(nsGkAtoms._moz_device_orientation, nsMediaFeature.RangeType.MinMaxNotAllowed, nsMediaFeature.ValueType.Enumerated, nsCSSProps.kOrientationKeywords), 30 | // nsGkAtoms._moz_is_resource_document, 31 | // nsGkAtoms._moz_scrollbar_start_backward, 32 | // nsGkAtoms._moz_scrollbar_start_forward, 33 | // nsGkAtoms._moz_scrollbar_end_backward, 34 | // nsGkAtoms._moz_scrollbar_end_forward, 35 | // nsGkAtoms._moz_scrollbar_thumb_proportional, 36 | // nsGkAtoms._moz_images_in_menus, 37 | // nsGkAtoms._moz_images_in_buttons, 38 | // nsGkAtoms._moz_windows_default_theme, 39 | // nsGkAtoms._moz_mac_graphite_theme, 40 | // nsGkAtoms._moz_mac_lion_theme, 41 | // nsGkAtoms._moz_windows_compositor, 42 | // nsGkAtoms._moz_windows_classic, 43 | // nsGkAtoms._moz_windows_glass, 44 | // nsGkAtoms._moz_touch_enabled, 45 | // nsGkAtoms._moz_maemo_classic, 46 | // nsGkAtoms._moz_menubar_drag, 47 | // nsGkAtoms._moz_windows_theme, 48 | // Internal -moz-is-glyph media feature: applies only inside SVG glyphs. 49 | // Internal because it is really only useful in the user agent anyway 50 | // and therefore not worth standardizing. 51 | // nsGkAtoms._moz_is_glyph, 52 | // Null-mName terminator: 53 | // null, 54 | //new CssMediaFeature() 55 | }; 56 | 57 | private static readonly CssMediaFeature EmptyFeature = new CssMediaFeature(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssStyleSheet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using Alba.CsCss.Internal.Extensions; 6 | 7 | namespace Alba.CsCss.Style 8 | { 9 | [DebuggerDisplay ("StyleSheet {mSheetURI}: Rules.Count = {mOrderedRules.Count}")] 10 | public partial class CssStyleSheet 11 | { 12 | // from nsCSSStyleSheetInner 13 | private nsXMLNameSpaceMap mNameSpaceMap; 14 | private Uri mBaseURI, mSheetURI; 15 | private readonly List mOrderedRules = new List(); 16 | 17 | internal CssStyleSheet () 18 | {} 19 | 20 | internal nsXMLNameSpaceMap GetNameSpaceMap () 21 | { 22 | return mNameSpaceMap; 23 | } 24 | 25 | internal Uri GetSheetURI () 26 | { 27 | return mSheetURI; 28 | } 29 | 30 | internal Uri GetBaseURI () 31 | { 32 | return mBaseURI; 33 | } 34 | 35 | internal void SetURIs (Uri aSheetURI, Uri aBaseURI) 36 | { 37 | mSheetURI = aSheetURI; 38 | mBaseURI = aBaseURI; 39 | } 40 | 41 | internal nsIPrincipal Principal () 42 | { 43 | return nsIPrincipal.Default; 44 | } 45 | 46 | internal int StyleRuleCount () 47 | { 48 | return mOrderedRules.Count; 49 | } 50 | 51 | internal nsresult GetStyleRuleAt (int aIndex, ref CssRule aRule) 52 | { 53 | aRule = mOrderedRules[aIndex]; 54 | return nsresult.OK; 55 | } 56 | 57 | internal void AppendStyleRule (CssRule aRule) 58 | { 59 | mOrderedRules.Add(aRule); 60 | aRule.SetStyleSheet(this); 61 | if (aRule.GetKind() == CssRuleKind.Namespace) 62 | RegisterNamespaceRule((CssNamespaceRule)aRule); 63 | } 64 | 65 | private void RegisterNamespaceRule (CssNamespaceRule aRule) 66 | { 67 | if (mNameSpaceMap == null) 68 | CreateNamespaceMap(); 69 | // ReSharper disable once PossibleNullReferenceException - CreateNamespaceMap ensures it is not null 70 | mNameSpaceMap.AddPrefix(aRule.GetPrefix(), aRule.GetURLSpec()); 71 | } 72 | 73 | private void CreateNamespaceMap () 74 | { 75 | mNameSpaceMap = new nsXMLNameSpaceMap(false); 76 | mNameSpaceMap.AddPrefix(null, nsNameSpace.Unknown); 77 | } 78 | 79 | // My 80 | 81 | internal void Fix () 82 | { 83 | foreach (var rule in AllRules) 84 | rule.Fix(); 85 | } 86 | 87 | // Public interface 88 | 89 | public Uri SheetUri 90 | { 91 | get { return mSheetURI; } 92 | set { mSheetURI = value; } 93 | } 94 | 95 | public Uri BaseUri 96 | { 97 | get { return mBaseURI; } 98 | set { mBaseURI = value; } 99 | } 100 | 101 | public IList Rules 102 | { 103 | get { return mOrderedRules; } 104 | } 105 | 106 | public IEnumerable AllRules 107 | { 108 | get 109 | { 110 | return mOrderedRules.SelectMany(rule => rule.TraverseTree(subRule => { 111 | var groupRule = subRule as CssGroupRule; 112 | return groupRule != null ? groupRule.Rules : Enumerable.Empty(); 113 | })); 114 | } 115 | } 116 | 117 | private IEnumerable GetRules () where TRule : CssRule 118 | { 119 | return mOrderedRules.OfType(); 120 | } 121 | 122 | private IEnumerable GetAllRules () where TRule : CssRule 123 | { 124 | return AllRules.OfType(); 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/CssTokenType.cs: -------------------------------------------------------------------------------- 1 | namespace Alba.CsCss.Style 2 | { 3 | // Token types; in close but not perfect correspondence to the token 4 | // categorization in section 4.1.1 of CSS2.1. (The deviations are all 5 | // the fault of css3-selectors, which has requirements that can only be 6 | // met by changing the generic tokenization.) The comment on each line 7 | // illustrates the form of each identifier. 8 | public enum CssTokenType 9 | { 10 | // White space of any kind. No value fields are used. Note that 11 | // comments do *not* count as white space; comments separate tokens 12 | // but are not themselves tokens. 13 | Whitespace, // 14 | 15 | // Identifier-like tokens. mIdent is the text of the identifier. 16 | // The difference between ID and Hash is: if the text after the # 17 | // would have been a valid Ident if the # hadn't been there, the 18 | // scanner produces an ID token. Otherwise it produces a Hash token. 19 | // (This distinction is required by css3-selectors.) 20 | Ident, // word 21 | Function, // word( 22 | AtKeyword, // @word 23 | ID, // #word 24 | Hash, // #0word 25 | 26 | // Numeric tokens. mNumber is the floating-point value of the 27 | // number, and mHasSign indicates whether there was an explicit sign 28 | // (+ or -) in front of the number. If mIntegerValid is true, the 29 | // number had the lexical form of an integer, and mInteger is its 30 | // integer value. Lexically integer values outside the range of a 31 | // 32-bit signed number are clamped to the maximum values; mNumber 32 | // will indicate a 'truer' value in that case. Percentage tokens 33 | // are always considered not to be integers, even if their numeric 34 | // value is integral (100% => mNumber = 1.0). For Dimension 35 | // tokens, mIdent holds the text of the unit. 36 | Number, // 1 -5 +2e3 3.14159 7.297352e-3 37 | Dimension, // 24px 8.5in 38 | Percentage, // 85% 1280.4% 39 | 40 | // String-like tokens. In all cases, mIdent holds the text 41 | // belonging to the string, and mSymbol holds the delimiter 42 | // character, which may be ', ", or zero (only for unquoted URLs). 43 | // Bad_String and Bad_URL tokens are emitted when the closing 44 | // delimiter or parenthesis was missing. 45 | String, // 'foo bar' "foo bar" 46 | Bad_String, // 'foo bar 47 | URL, // url(foobar) url("foo bar") 48 | Bad_URL, // url(foo 49 | 50 | // Any one-character symbol. mSymbol holds the character. 51 | Symbol, // . ; { } ! * 52 | 53 | // Match operators. These are single tokens rather than pairs of 54 | // Symbol tokens because css3-selectors forbids the presence of 55 | // comments between the two characters. No value fields are used; 56 | // the token type indicates which operator. 57 | Includes, // ~= 58 | Dashmatch, // |= 59 | Beginsmatch, // ^= 60 | Endsmatch, // $= 61 | Containsmatch, // *= 62 | 63 | // Unicode-range token: currently used only in @font-face. 64 | // The lexical rule for this token includes several forms that are 65 | // semantically invalid. Therefore, mIdent always holds the 66 | // complete original text of the token (so we can print it 67 | // accurately in diagnostics), and mIntegerValid is true iff the 68 | // token is semantically valid. In that case, mInteger holds the 69 | // lowest value included in the range, and mInteger2 holds the 70 | // highest value included in the range. 71 | URange, // U+007e U+01?? U+2000-206F 72 | 73 | // HTML comment delimiters, ignored as a unit when they appear at 74 | // the top level of a style sheet, for compatibility with websites 75 | // written for compatibility with pre-CSS browsers. This token type 76 | // subsumes the css2.1 CDO and CDC tokens, which are always treated 77 | // the same by the parser. mIdent holds the text of the token, for 78 | // diagnostics. 79 | HTMLComment, // 80 | }; 81 | } -------------------------------------------------------------------------------- /Alba.CsCss/Internal/nsStyleUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Alba.CsCss.Internal 4 | { 5 | internal class nsStyleUtil 6 | { 7 | internal static void AppendEscapedCSSIdent (StringBuilder aIdent, StringBuilder aReturn) 8 | { 9 | // The relevant parts of the CSS grammar are: 10 | // ident [-]?{nmstart}{nmchar}* 11 | // nmstart [_a-z]|{nonascii}|{escape} 12 | // nmchar [_a-z0-9-]|{nonascii}|{escape} 13 | // nonascii [^\0-\177] 14 | // escape {unicode}|\\[^\n\r\f0-9a-f] 15 | // unicode \\[0-9a-f]{1,6}(\r\n|[ \n\r\t\f])? 16 | // from http://www.w3.org/TR/CSS21/syndata.html#tokenization 17 | 18 | string ident = aIdent.ToString(); 19 | int i = 0; 20 | int end = ident.Length; 21 | 22 | if (i == end) 23 | return; 24 | 25 | // A leading dash does not need to be escaped as long as it is not the 26 | // *only* character i the identifier. 27 | if (i + 1 != end && ident[i] == '-') { 28 | aReturn.Append('-'); 29 | ++i; 30 | } 31 | 32 | // Escape a digit at the start (including after a dash), 33 | // numerically. If we didn't escape it numerically, it would get 34 | // interpreted as a numeric escape for the wrong character. 35 | // A second dash immediately after a leading dash must also be 36 | // escaped, but this may be done symbolically. 37 | if (i != end && (ident[i] == '-' || ('0' <= ident[i] && ident[i] <= '9'))) { 38 | if (ident[i] == '-') { 39 | aReturn.Append("\\-"); 40 | } 41 | else { 42 | aReturn.AppendFormat("\\{0:X} ", (int)ident[i]); 43 | } 44 | ++i; 45 | } 46 | 47 | for (; i != end; ++i) { 48 | char ch = ident[i]; 49 | if (ch < 0x20 || (0x7F <= ch && ch < 0xA0)) { 50 | // Escape U+0000 through U+001F and U+007F through U+009F numerically. 51 | aReturn.AppendFormat("\\{0:X} ", (int)ident[i]); 52 | } 53 | else { 54 | // Escape ASCII non-identifier printables as a backslash plus 55 | // the character. 56 | if (ch < 0x7F && 57 | ch != '_' && ch != '-' && 58 | (ch < '0' || '9' < ch) && 59 | (ch < 'A' || 'Z' < ch) && 60 | (ch < 'a' || 'z' < ch)) { 61 | aReturn.Append('\\'); 62 | } 63 | aReturn.Append(ch); 64 | } 65 | } 66 | } 67 | 68 | internal static void AppendEscapedCSSString (StringBuilder aString, StringBuilder aReturn, char quoteChar = '"') 69 | { 70 | aReturn.Append(quoteChar); 71 | 72 | string str = aString.ToString(); 73 | int i = 0; 74 | int end = str.Length; 75 | for (; i != end; i++) { 76 | if (str[i] < 0x20 || (str[i] >= 0x7F && str[i] < 0xA0)) { 77 | // Escape U+0000 through U+001F and U+007F through U+009F numerically. 78 | aReturn.AppendFormat("\\{0:X} ", (int)str[i]); 79 | } 80 | else { 81 | if (str[i] == '"' || str[i] == '\'' || str[i] == '\\') { 82 | // Escape backslash and quote characters symbolically. 83 | // It's not technically necessary to escape the quote 84 | // character that isn't being used to delimit the string, 85 | // but we do it anyway because that makes testing simpler. 86 | aReturn.Append('\\'); 87 | } 88 | aReturn.Append(str[i]); 89 | } 90 | } 91 | 92 | aReturn.Append(quoteChar); 93 | } 94 | 95 | public static byte FloatToColorComponent (float aAlpha) 96 | { 97 | return (byte)CommonUtil.NSToIntRound(aAlpha * 255); 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/nsStyleConsts.tt: -------------------------------------------------------------------------------- 1 | <#@ template hostspecific="true" debug="true" #> 2 | <#@ output extension="/" #> 3 | <#@ include file="..\..\T4\Common.ttinclude" #> 4 | <# 5 | string source = LoadText(ext: "h"); 6 | 7 | var T4 = GetT4(); 8 | T4.GenerateFile("nsStyle.conv.cs", () => GenerateStyleConsts(source)); 9 | T4.Process(); 10 | #> 11 | <#+ 12 | void GenerateStyleConsts (string source) { 13 | #> 14 | // 15 | // Generated file. Do not edit manually. 16 | // 17 | 18 | using Alba.CsCss.Gfx; 19 | 20 | namespace Alba.CsCss.Style 21 | { 22 | public partial class CssStyle 23 | { 24 | <#= ConvertStyleConstsSource(source).Indent(8) #> 25 | } 26 | } 27 | <#+ 28 | } // GenerateStyleConsts 29 | #> 30 | <#+ 31 | string ConvertStyleConstsSource (string source) { 32 | return source 33 | 34 | // whitespace 35 | .ReReplace(@"\r", "") 36 | 37 | // specific methods removal 38 | .ReReplace(@"(?s)static inline mozilla::css::Side operator\+\+\(mozilla::css::Side& side, int\).*?\n}\n", "") 39 | 40 | // specific preprocessor 41 | .ReReplace(@".*nsStyleConsts_h___.*", "") // header guard 42 | .ReReplace(@"(?s)#define (NS_SIDE_|NS_FOR_|NS_HALF_|NS_FULL_).*?(?\w+) \ + # constant name with prefix removed 46 | (?\(? (-?\d+ | 0x[0-9a-f]+ | 1<<\d+) \)?) \ *? # NN or 0xHH or 1<\ ? (//.* | /\*.*)? )$ # one-line or block comment", 48 | m => "public const int {0} = {1};{2}".Fmt( 49 | ToPascalId(m.Get("Name")), m.Get("IntValue"), m.Get("Remainder"))) 50 | .ReReplace(@"(?imnx)^ 51 | \#define \ + 52 | NS_(STYLE_)? (?\w+) \ + # constant name with prefix removed 53 | (?\(? -?\d*\.\d+f \)?) \ *? # N.NNf in optional brackets 54 | (?\ ? (//.* | /\*.*)? )$ # one-line or block comment", 55 | m => "public const float {0} = {1};{2}".Fmt( 56 | ToPascalId(m.Get("Name")), m.Get("FloatValue"), m.Get("Remainder"))) 57 | .ReReplace(@"(?mnx)^ 58 | \#define \ + 59 | NS_(STYLE_)? (?\w+) \ + # constant name with prefix removed 60 | \(? ( # aliased constant name(s) 61 | NS_(STYLE_)? (?\w+) (\ *\|\ *)? # aliased constant name ending with optional | operator 62 | )+ \)? \ *? 63 | (?\ ? (//.* | /\*.*)? )$ # one-line or block comment", 64 | m => { 65 | string name = ToPascalId(m.Get("Name")), 66 | namesValue = m.GetAll("NamesValue") 67 | .Select(v => v.StartsWith("FONT_") ? v.ReReplace(@"^FONT_", "nsFont.") : ToPascalId(v)) 68 | .JoinString(" | "), 69 | remainder = m.Get("Remainder"); 70 | //namesValue = namesValue.StartsWith("FONT_") ? namesValue.ReReplace(@"^FONT_", "nsFont.") : ToPascalId(namesValue); 71 | return "public const int {0} = {1};{2}".Fmt(name, namesValue, remainder); 72 | }) 73 | 74 | // common preprocessor 75 | .ReReplace(@"#include .*", "") 76 | .ReReplace(@"#undef .*", "") 77 | .ReReplace(@"#ifdef (\w+)", "#if $1") 78 | .ReReplace(@"#ifndef (\w+)", "#if !$1") 79 | .ReReplace(@"using .*", "") 80 | 81 | // whitespace 82 | .ReReplace(@"\n\s*;\n", "\n") 83 | .ReReplace(@"\n{3,}", "\n\n") 84 | .ReReplace(@"\n", "\r\n") 85 | .Trim() 86 | ; 87 | } 88 | #> -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/Rule.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 | 6 | /* base class for all rule types in a CSS style sheet */ 7 | 8 | #ifndef mozilla_css_Rule_h___ 9 | #define mozilla_css_Rule_h___ 10 | 11 | #include "nsIStyleRule.h" 12 | #include "nsIDOMCSSRule.h" 13 | #include "nsCSSStyleSheet.h" 14 | 15 | class nsIStyleSheet; 16 | class nsIDocument; 17 | struct nsRuleData; 18 | template struct already_AddRefed; 19 | class nsHTMLCSSStyleSheet; 20 | 21 | namespace mozilla { 22 | namespace css { 23 | class GroupRule; 24 | 25 | #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ 26 | virtual void MapRuleInfoInto(nsRuleData* aRuleData); 27 | 28 | #define DECL_STYLE_RULE_INHERIT \ 29 | DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ 30 | virtual nsIDOMCSSRule* GetDOMRule(); \ 31 | virtual nsIDOMCSSRule* GetExistingDOMRule(); 32 | 33 | class Rule : public nsIStyleRule { 34 | protected: 35 | Rule() 36 | : mSheet(0), 37 | mParentRule(nullptr) 38 | { 39 | } 40 | 41 | Rule(const Rule& aCopy) 42 | : mSheet(aCopy.mSheet), 43 | mParentRule(aCopy.mParentRule) 44 | { 45 | } 46 | 47 | virtual ~Rule() {} 48 | 49 | public: 50 | 51 | // The constants in this list must maintain the following invariants: 52 | // If a rule of type N must appear before a rule of type M in stylesheets 53 | // then N < M 54 | // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of 55 | // rules can come between two rules of type IMPORT_RULE. 56 | enum { 57 | UNKNOWN_RULE = 0, 58 | CHARSET_RULE, 59 | IMPORT_RULE, 60 | NAMESPACE_RULE, 61 | STYLE_RULE, 62 | MEDIA_RULE, 63 | FONT_FACE_RULE, 64 | PAGE_RULE, 65 | KEYFRAME_RULE, 66 | KEYFRAMES_RULE, 67 | DOCUMENT_RULE, 68 | SUPPORTS_RULE 69 | }; 70 | 71 | virtual int32_t GetType() const = 0; 72 | 73 | nsCSSStyleSheet* GetStyleSheet() const; 74 | nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const; 75 | 76 | // Return the document the rule lives in, if any 77 | nsIDocument* GetDocument() const 78 | { 79 | nsCSSStyleSheet* sheet = GetStyleSheet(); 80 | return sheet ? sheet->GetDocument() : nullptr; 81 | } 82 | 83 | virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); 84 | // This does not need to be virtual, because GroupRule and MediaRule are not 85 | // used for inline style. 86 | void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet); 87 | 88 | void SetParentRule(GroupRule* aRule) { 89 | // We don't reference count this up reference. The group rule 90 | // will tell us when it's going away or when we're detached from 91 | // it. 92 | mParentRule = aRule; 93 | } 94 | 95 | /** 96 | * Clones |this|. Never returns NULL. 97 | */ 98 | virtual already_AddRefed Clone() const = 0; 99 | 100 | // Note that this returns null for inline style rules since they aren't 101 | // supposed to have a DOM rule representation (and our code wouldn't work). 102 | virtual nsIDOMCSSRule* GetDOMRule() = 0; 103 | 104 | // Like GetDOMRule(), but won't create one if we don't have one yet 105 | virtual nsIDOMCSSRule* GetExistingDOMRule() = 0; 106 | 107 | // to implement methods on nsIDOMCSSRule 108 | nsresult GetParentRule(nsIDOMCSSRule** aParentRule); 109 | nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); 110 | 111 | // This is pure virtual because all of Rule's data members are non-owning and 112 | // thus measured elsewhere. 113 | virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) 114 | const MOZ_MUST_OVERRIDE = 0; 115 | 116 | // This is used to measure nsCOMArrays. 117 | static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement, 118 | nsMallocSizeOfFun aMallocSizeOf, 119 | void* aData); 120 | 121 | protected: 122 | // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*. The former 123 | // if the low bit is 0, the latter if the low bit is 1. 124 | uintptr_t mSheet; 125 | GroupRule* mParentRule; 126 | }; 127 | 128 | } // namespace css 129 | } // namespace mozilla 130 | 131 | #endif /* mozilla_css_Rule_h___ */ -------------------------------------------------------------------------------- /Alba.CsCss.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alba.CsCss", "Alba.CsCss\Alba.CsCss.csproj", "{72DD968A-2B97-4D3D-8A87-80A76C6C830A}" 5 | EndProject 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C9C8075B-D7F9-49DD-99B3-C58FFD794F0E}" 7 | ProjectSection(SolutionItems) = preProject 8 | .nuget\Build.cmd = .nuget\Build.cmd 9 | .nuget\css.png = .nuget\css.png 10 | .nuget\NuGet.Config = .nuget\NuGet.Config 11 | .nuget\NuGet.exe = .nuget\NuGet.exe 12 | .nuget\NuGet.targets = .nuget\NuGet.targets 13 | .nuget\Upload.cmd = .nuget\Upload.cmd 14 | EndProjectSection 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alba.Framework.CodeGeneration", "Alba.Framework\Alba.Framework.CodeGeneration\Alba.Framework.CodeGeneration.csproj", "{6B7272D1-B052-4B4D-B4F2-9C11E5BE1C89}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alba.Framework", "Alba.Framework\Alba.Framework\Alba.Framework.csproj", "{62730B23-450C-4B93-8D5C-F7037DB6D263}" 19 | EndProject 20 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{37E08910-E2AB-4F30-81DA-CC145C1C12B5}" 21 | ProjectSection(SolutionItems) = preProject 22 | Build\Common.targets = Build\Common.targets 23 | Build\CommonTests.targets = Build\CommonTests.targets 24 | EndProjectSection 25 | EndProject 26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{72F60BBC-C668-48E3-87EF-E76DE15BEC61}" 27 | EndProject 28 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alba.CsCss.Tests", "Alba.CsCss.Tests\Alba.CsCss.Tests.csproj", "{4FB98F2C-9377-4A81-A723-F40CBA686663}" 29 | EndProject 30 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Alba.Framework.Testing", "Alba.Framework\Alba.Framework.Testing\Alba.Framework.Testing.csproj", "{D4A932D6-F7BE-4EE4-89F4-F72BD270286B}" 31 | EndProject 32 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Global", "Global", "{09653AE6-3A14-4470-8A71-6724E4A31F98}" 33 | ProjectSection(SolutionItems) = preProject 34 | License.md = License.md 35 | ReadMe.md = ReadMe.md 36 | EndProjectSection 37 | EndProject 38 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".git", ".git", "{B2941A83-2797-49F8-BFB4-370A0A32B248}" 39 | ProjectSection(SolutionItems) = preProject 40 | .gitignore = .gitignore 41 | .gitmodules = .gitmodules 42 | EndProjectSection 43 | EndProject 44 | Global 45 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 46 | Debug|Any CPU = Debug|Any CPU 47 | Release|Any CPU = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 50 | {72DD968A-2B97-4D3D-8A87-80A76C6C830A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {72DD968A-2B97-4D3D-8A87-80A76C6C830A}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {72DD968A-2B97-4D3D-8A87-80A76C6C830A}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {72DD968A-2B97-4D3D-8A87-80A76C6C830A}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {6B7272D1-B052-4B4D-B4F2-9C11E5BE1C89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {6B7272D1-B052-4B4D-B4F2-9C11E5BE1C89}.Release|Any CPU.ActiveCfg = Release|Any CPU 56 | {62730B23-450C-4B93-8D5C-F7037DB6D263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 57 | {62730B23-450C-4B93-8D5C-F7037DB6D263}.Debug|Any CPU.Build.0 = Debug|Any CPU 58 | {62730B23-450C-4B93-8D5C-F7037DB6D263}.Release|Any CPU.ActiveCfg = Release|Any CPU 59 | {62730B23-450C-4B93-8D5C-F7037DB6D263}.Release|Any CPU.Build.0 = Release|Any CPU 60 | {4FB98F2C-9377-4A81-A723-F40CBA686663}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 61 | {4FB98F2C-9377-4A81-A723-F40CBA686663}.Debug|Any CPU.Build.0 = Debug|Any CPU 62 | {4FB98F2C-9377-4A81-A723-F40CBA686663}.Release|Any CPU.ActiveCfg = Release|Any CPU 63 | {4FB98F2C-9377-4A81-A723-F40CBA686663}.Release|Any CPU.Build.0 = Release|Any CPU 64 | {D4A932D6-F7BE-4EE4-89F4-F72BD270286B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 65 | {D4A932D6-F7BE-4EE4-89F4-F72BD270286B}.Debug|Any CPU.Build.0 = Debug|Any CPU 66 | {D4A932D6-F7BE-4EE4-89F4-F72BD270286B}.Release|Any CPU.ActiveCfg = Release|Any CPU 67 | {D4A932D6-F7BE-4EE4-89F4-F72BD270286B}.Release|Any CPU.Build.0 = Release|Any CPU 68 | EndGlobalSection 69 | GlobalSection(SolutionProperties) = preSolution 70 | HideSolutionNode = FALSE 71 | EndGlobalSection 72 | GlobalSection(NestedProjects) = preSolution 73 | {4FB98F2C-9377-4A81-A723-F40CBA686663} = {72F60BBC-C668-48E3-87EF-E76DE15BEC61} 74 | {D4A932D6-F7BE-4EE4-89F4-F72BD270286B} = {72F60BBC-C668-48E3-87EF-E76DE15BEC61} 75 | EndGlobalSection 76 | EndGlobal 77 | -------------------------------------------------------------------------------- /Alba.CsCss/Style/Original/CssToken.conv.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit manually. 3 | // 4 | // ReSharper disable RedundantUsingDirective 5 | // ReSharper disable RedundantCast 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.Text; 10 | using Alba.CsCss.Internal; 11 | using Alba.CsCss.Internal.Extensions; 12 | 13 | using int32_t = System.Int32; 14 | using uint8_t = System.Byte; 15 | using uint32_t = System.Int32; 16 | using PRUnichar = System.Char; 17 | 18 | namespace Alba.CsCss.Style 19 | { 20 | using nsCSSToken = CssToken; 21 | using nsCSSTokenType = CssTokenType; 22 | 23 | internal partial class CssToken 24 | { 25 | /** 26 | * Append the textual representation of |this| to |aBuffer|. 27 | */ 28 | internal void AppendToString(StringBuilder aBuffer) 29 | { 30 | switch (mType) { 31 | case nsCSSTokenType.Ident: 32 | nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer); 33 | break; 34 | 35 | case nsCSSTokenType.AtKeyword: 36 | aBuffer.Append('@'); 37 | nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer); 38 | break; 39 | 40 | case nsCSSTokenType.ID: 41 | case nsCSSTokenType.Hash: 42 | aBuffer.Append('#'); 43 | nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer); 44 | break; 45 | 46 | case nsCSSTokenType.Function: 47 | nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer); 48 | aBuffer.Append('('); 49 | break; 50 | 51 | case nsCSSTokenType.URL: 52 | case nsCSSTokenType.Bad_URL: 53 | aBuffer.AppendLiteral("url("); 54 | if (mSymbol != ((PRUnichar)(0))) { 55 | nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol); 56 | } else { 57 | aBuffer.Append(mIdent); 58 | } 59 | if (mType == nsCSSTokenType.URL) { 60 | aBuffer.Append(((PRUnichar)(')'))); 61 | } 62 | break; 63 | 64 | case nsCSSTokenType.Number: 65 | if (mIntegerValid) { 66 | aBuffer.AppendInt(mInteger, 10); 67 | } else { 68 | aBuffer.AppendFloat(mNumber); 69 | } 70 | break; 71 | 72 | case nsCSSTokenType.Percentage: 73 | aBuffer.AppendFloat(mNumber * 100.0f); 74 | aBuffer.Append(((PRUnichar)('%'))); 75 | break; 76 | 77 | case nsCSSTokenType.Dimension: 78 | if (mIntegerValid) { 79 | aBuffer.AppendInt(mInteger, 10); 80 | } else { 81 | aBuffer.AppendFloat(mNumber); 82 | } 83 | nsStyleUtil.AppendEscapedCSSIdent(mIdent, aBuffer); 84 | break; 85 | 86 | case nsCSSTokenType.Bad_String: 87 | nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol); 88 | // remove the trailing quote character 89 | aBuffer.Truncate(aBuffer.Length() - 1); 90 | break; 91 | 92 | case nsCSSTokenType.String: 93 | nsStyleUtil.AppendEscapedCSSString(mIdent, aBuffer, mSymbol); 94 | break; 95 | 96 | case nsCSSTokenType.Symbol: 97 | aBuffer.Append(mSymbol); 98 | break; 99 | 100 | case nsCSSTokenType.Whitespace: 101 | aBuffer.Append(' '); 102 | break; 103 | 104 | case nsCSSTokenType.HTMLComment: 105 | case nsCSSTokenType.URange: 106 | aBuffer.Append(mIdent); 107 | break; 108 | 109 | case nsCSSTokenType.Includes: 110 | aBuffer.AppendLiteral("~="); 111 | break; 112 | case nsCSSTokenType.Dashmatch: 113 | aBuffer.AppendLiteral("|="); 114 | break; 115 | case nsCSSTokenType.Beginsmatch: 116 | aBuffer.AppendLiteral("^="); 117 | break; 118 | case nsCSSTokenType.Endsmatch: 119 | aBuffer.AppendLiteral("$="); 120 | break; 121 | case nsCSSTokenType.Containsmatch: 122 | aBuffer.AppendLiteral("*="); 123 | break; 124 | 125 | default: 126 | throw new Exception("invalid token type"); 127 | break; 128 | } 129 | } 130 | } 131 | } 132 | --------------------------------------------------------------------------------