Exemplo n.º 1
0
        internal void AppendDeclarations(StyleDeclaration style, string declarations)
        {
            var tokenizer = CreateTokenizer(declarations);
            var builder   = new StylesheetComposer(tokenizer, this);

            builder.FillDeclarations(style);
        }
Exemplo n.º 2
0
        public TextPosition FillDeclarations(StyleDeclaration style)
        {
            var finalProperties = new Dictionary <string, IProperty>(StringComparer.OrdinalIgnoreCase);
            var token           = NextToken();

            _nodes.Push(style);
            ParseComments(ref token);

            while (token.IsNot(TokenType.EndOfFile, TokenType.CurlyBracketClose))
            {
                var sourceProperty     = CreateDeclarationWith(PropertyFactory.Instance.Create, ref token);
                var resolvedProperties = new[] { sourceProperty };

                if ((sourceProperty != null) && sourceProperty.HasValue)
                {
                    // For shorthand properties we need to first find out what alternate set of properties they will
                    // end up resolving into so that we can compare them with their previously parsed counterparts (if any)
                    // and determine which one takes priority over the other.
                    // Example 1: "margin-left: 5px !important; text-align:center; margin: 3px;";
                    // Example 2: "margin: 5px !important; text-align:center; margin-left: 3px;";
                    if (sourceProperty is ShorthandProperty)
                    {
                        var shorthandProperty = sourceProperty as ShorthandProperty;
                        resolvedProperties = PropertyFactory.Instance.CreateLonghandsFor(shorthandProperty.Name);
                        shorthandProperty.Export(resolvedProperties);
                    }

                    foreach (var resolvedProperty in resolvedProperties)
                    {
                        // The following relies on the fact that the tokens are processed in
                        // top-to-bottom order of how they are defined in the parsed style declaration.
                        // This handles exposing the correct value for a property when it appears multiple
                        // times in the same style declaration.
                        // Example: "background-color:green !important; text-align:center; background-color:yellow;";
                        // In this example even though background-color yellow is defined last, the previous value
                        // of green should be he one exposed given it is tagged as important.
                        // ------------------------------------------------------------------------------------------
                        // Only set this property if one of the following conditions is true:
                        // a) It was not previously added or...
                        // b) The previously added property is not tagged as important or ...
                        // c) The previously added property is tagged as important but so is this new one.
                        var shouldSetProperty =
                            !finalProperties.TryGetValue(resolvedProperty.Name, out var previousProperty) ||
                            !previousProperty.IsImportant ||
                            resolvedProperty.IsImportant;

                        if (shouldSetProperty)
                        {
                            style.SetProperty(resolvedProperty);
                            finalProperties[resolvedProperty.Name] = resolvedProperty;
                        }
                    }
                }

                ParseComments(ref token);
            }

            _nodes.Pop();
            return(token.Position);
        }
Exemplo n.º 3
0
        internal static StyleDeclaration ParseDeclarations(string declarations, bool quirksMode = false)
        {
            var decl = new StyleDeclaration();

            AppendDeclarations(decl, declarations, quirksMode);

            return(decl);
        }
Exemplo n.º 4
0
        internal static void AppendDeclarations(StyleDeclaration list, string css, bool quirksMode = false)
        {
            var parser = new Parser();//(new StyleSheet(), new StylesheetReader(declarations))


            parser.AddRuleSet(list.ParentRule ?? new StyleRule(list));

            parser._parsingContext = ParsingContext.InDeclaration;
            parser.Parse(css);
        }
Exemplo n.º 5
0
        public TextPosition FillDeclarations(StyleDeclaration style)
        {
            var token = NextToken();
            _nodes.Push(style);
            ParseComments(ref token);

            while (token.IsNot(TokenType.EndOfFile, TokenType.CurlyBracketClose))
            {
                //var property = CreateDeclarationWith(Factory.Properties.Create, ref token);
                var property = CreateDeclarationWith(PropertyFactory.Instance.Create, ref token);

                if ((property != null) && property.HasValue)
                {
                    style.SetProperty(property);
                }

                ParseComments(ref token);
            }

            _nodes.Pop();
            return token.Position;
        }
Exemplo n.º 6
0
 public KeyframeRule()
 {
     Declarations = new StyleDeclaration();
     RuleType     = RuleType.Keyframe;
 }
Exemplo n.º 7
0
 public StyleRule(StyleDeclaration declarations)
 {
     RuleType      = RuleType.Style;
     _declarations = declarations;
 }
Exemplo n.º 8
0
 public KeyframeRule()
 {
     Declarations = new StyleDeclaration();
     RuleType     = RuleType.Keyframe;
     _values      = new List <string>();
 }
Exemplo n.º 9
0
 public FontFaceRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.FontFace;
 }
Exemplo n.º 10
0
 public FontFaceRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.FontFace;
     AtRuleKeyword = "font-face";
 }
Exemplo n.º 11
0
 public PageRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.Page;
 }
Exemplo n.º 12
0
 public GenericRule()
 {
     Declarations = new StyleDeclaration();
 }
Exemplo n.º 13
0
 public ViewportRule(StyleDeclaration declarations)
 {
     RuleType      = RuleType.Viewport;
     _declarations = declarations;
     AtRuleKeyword = "viewport";
 }