Exemplo n.º 1
0
    public virtual void TestReadWrite()
    {
        CssStyleDeclaration csd = getCSD(false);

        csd.SetProperty("foo", "newvalue", "");

        CssValue cssValue = (CssValue)csd.GetPropertyCssValue("foo");

        Assert.AreEqual("newvalue", cssValue.CssText);
        Assert.AreEqual("", csd.GetPropertyPriority("foo"));

        csd.SetProperty("foo", "value2", "important");
        cssValue = (CssValue)csd.GetPropertyCssValue("foo");
        Assert.AreEqual("value2", cssValue.CssText);
        Assert.AreEqual("important", csd.GetPropertyPriority("foo"));
    }
Exemplo n.º 2
0
        /// <summary>
        /// Set the presentation attributes of the given element in the style declaration
        /// </summary>
        private void SetPresentationAttributes(CssStyleDeclaration styleDeclaration, XElement element)
        {
            foreach (var attributeName in presentationAttributes)
            {
                XAttribute attribute = element.Attribute(attributeName);

                if (attribute != null)
                {
                    styleDeclaration.SetProperty(attributeName, attribute.Value);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set the properties from the global styles
        /// </summary>
        void SetPropertiesFromGlobalStyles(CssStyleDeclaration styleDeclarationToModify, XElement element)
        {
            var styleDeclarations = cssStyleSheet.GetStylesForElement(element);

            foreach (var styleDeclaration in styleDeclarations)
            {
                foreach (var name in styleDeclaration.Properties)
                {
                    var value = styleDeclaration.GetProperty(name);
                    styleDeclarationToModify.SetProperty(name, value);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fills the given parent style with declarations given by the tokens.
        /// </summary>
        public void FillDeclarations(CssStyleDeclaration style)
        {
            var token = _tokenizer.Get();

            while (token.IsNot(CssTokenType.Eof, CssTokenType.CurlyBracketClose))
            {
                var property = CreateDeclaration(ref token);

                if (property != null && property.HasValue)
                {
                    style.SetProperty(property);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set the properties from the style sheets from the given selector
        /// </summary>
        private void SetProperties(CssStyleDeclaration styleDeclarationToModify, string selector)
        {
            foreach (var styleSheet in cssStyleSheets)
            {
                var styleDeclarations = styleSheet.GetStylesForSelector(selector);

                foreach (var styleDeclaration in styleDeclarations)
                {
                    foreach (var name in styleDeclaration.Properties)
                    {
                        var value = styleDeclaration.GetPropertyValue(name);
                        styleDeclarationToModify.SetProperty(name, value);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Fills the given parent style with declarations given by the tokens.
        /// </summary>
        public void FillDeclarations(CssStyleDeclaration style)
        {
            var token = NextToken();

            CollectTrivia(ref token);

            while (token.IsNot(CssTokenType.Eof, CssTokenType.CurlyBracketClose))
            {
                var property = CreateDeclarationWith(Factory.Properties.Create, ref token);

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

                CollectTrivia(ref token);
            }
        }
Exemplo n.º 7
0
        public void CssPropertyFactoryCalls()
        {
            var parser  = new CssParser();
            var decl    = new CssStyleDeclaration(parser);
            var invalid = decl.CreateProperty("invalid");
            var border  = decl.CreateProperty("border");
            var color   = decl.CreateProperty("color");

            decl.SetProperty(color);
            var colorAgain = decl.CreateProperty("color");

            Assert.IsNull(invalid);
            Assert.IsNotNull(border);
            Assert.IsNotNull(color);
            Assert.IsNotNull(colorAgain);

            Assert.IsInstanceOf <CssBorderProperty>(border);
            Assert.IsInstanceOf <CssColorProperty>(color);
            Assert.AreEqual(color, colorAgain);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Fills the given parent style with declarations given by the tokens.
        /// </summary>
        public TextPosition FillDeclarations(CssStyleDeclaration style)
        {
            var token = NextToken();

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

            while (token.IsNot(CssTokenType.EndOfFile, CssTokenType.CurlyBracketClose))
            {
                var property = CreateDeclarationWith(Factory.Properties.Create, ref token);

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

                CollectTrivia(ref token);
            }

            _nodes.Pop();
            return(token.Position);
        }
Exemplo n.º 9
0
    public void TestReadOnly()
    {
        CssStyleDeclaration csd = getCSD();

        csd.SetProperty("foo", "bar", "");
    }