Beispiel #1
0
        /// <summary>
        ///     Applies style to all boxes in the tree
        /// </summary>
        private void CascadeStyles(CssBox startBox)
        {
            var someBlock = false;

            foreach (var b in startBox.Boxes)
            {
                b.InheritStyle();

                if (b.HtmlTag != null)
                {
                    //Check if tag name matches with a defined class
                    if (MediaBlocks["all"].ContainsKey(b.HtmlTag.TagName))
                    {
                        MediaBlocks["all"][b.HtmlTag.TagName].AssignTo(b);
                    }

                    //Check if class="" attribute matches with a defined style
                    if (b.HtmlTag.HasAttribute("class") &&
                        MediaBlocks["all"].ContainsKey("." + b.HtmlTag.Attributes["class"]))
                    {
                        MediaBlocks["all"]["." + b.HtmlTag.Attributes["class"]].AssignTo(b);
                    }

                    b.HtmlTag.TranslateAttributes(b);

                    //Check for the style="" attribute
                    if (b.HtmlTag.HasAttribute("style"))
                    {
                        var block = new CssBlock(b.HtmlTag.Attributes["style"]);
                        block.AssignTo(b);
                    }

                    //Check for the <style> tag
                    if (b.HtmlTag.TagName.Equals("style", StringComparison.CurrentCultureIgnoreCase) &&
                        b.Boxes.Count == 1)
                    {
                        FeedStyleSheet(b.Boxes[0].Text);
                    }

                    //Check for the <link rel=stylesheet> tag
                    if (b.HtmlTag.TagName.Equals("link", StringComparison.CurrentCultureIgnoreCase) &&
                        b.GetAttribute("rel", string.Empty)
                        .Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                    {
                        FeedStyleSheet(CssValue.GetStyleSheet(b.GetAttribute("href", string.Empty)));
                    }
                }

                CascadeStyles(b);
            }

            if (someBlock)
            {
                foreach (var box in startBox.Boxes)
                {
                    box.Display = CssConstants.Block;
                }
            }
        }
        private void CascadeStyles(CssBox startBox)
        {
            bool flag = false;

            foreach (CssBox box in startBox.Boxes)
            {
                box.InheritStyle();
                if (box.HtmlTag != null)
                {
                    if (this.MediaBlocks["all"].ContainsKey(box.HtmlTag.TagName))
                    {
                        this.MediaBlocks["all"][box.HtmlTag.TagName].AssignTo(box);
                    }
                    if (box.HtmlTag.HasAttribute("class") && this.MediaBlocks["all"].ContainsKey(string.Concat(".", box.HtmlTag.Attributes["class"])))
                    {
                        this.MediaBlocks["all"][string.Concat(".", box.HtmlTag.Attributes["class"])].AssignTo(box);
                    }
                    box.HtmlTag.TranslateAttributes(box);
                    if (box.HtmlTag.HasAttribute("style"))
                    {
                        CssBlock cssBlock = new CssBlock(box.HtmlTag.Attributes["style"]);
                        cssBlock.AssignTo(box);
                    }
                    if (box.HtmlTag.TagName.Equals("style", StringComparison.CurrentCultureIgnoreCase) && box.Boxes.Count == 1)
                    {
                        this.FeedStyleSheet(box.Boxes[0].Text);
                    }
                    if (box.HtmlTag.TagName.Equals("link", StringComparison.CurrentCultureIgnoreCase) && box.GetAttribute("rel", string.Empty).Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                    {
                        this.FeedStyleSheet(CssValue.GetStyleSheet(box.GetAttribute("href", string.Empty)));
                    }
                }
                this.CascadeStyles(box);
            }
            if (flag)
            {
                foreach (CssBox cssBox in startBox.Boxes)
                {
                    cssBox.Display = "block";
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Applies style to all boxes in the tree
        /// </summary>
        private void CascadeStyles(CssBox startBox)
        {
            bool someBlock = false;

            foreach (CssBox b in startBox.Boxes)
            {
                b.InheritStyle();

                if (b.HtmlTag != null)
                {
                    //Check if tag name matches with a defined class
                    if (MediaBlocks["all"].ContainsKey(b.HtmlTag.TagName))
                    {
                        MediaBlocks["all"][b.HtmlTag.TagName].AssignTo(b);
                    }

                    //Check if class="" attribute matches with a defined style
                    if (b.HtmlTag.HasAttribute("class") &&
                        MediaBlocks["all"].ContainsKey("." + b.HtmlTag.Attributes["class"]))
                    {
                        MediaBlocks["all"]["." + b.HtmlTag.Attributes["class"]].AssignTo(b);
                    }

                    b.HtmlTag.TranslateAttributes(b);

                    //Check for the style="" attribute
                    if (b.HtmlTag.HasAttribute("style"))
                    {
                        CssBlock block = new CssBlock(b.HtmlTag.Attributes["style"]);
                        block.AssignTo(b);
                    }

                    //Check for the <style> tag
                    if (b.HtmlTag.TagName.Equals("style", StringComparison.CurrentCultureIgnoreCase) &&
                        b.Boxes.Count == 1)
                    {
                        FeedStyleSheet(b.Boxes[0].Text);
                    }

                    //Check for the <link rel=stylesheet> tag
                    if (b.HtmlTag.TagName.Equals("link", StringComparison.CurrentCultureIgnoreCase) &&
                        b.GetAttribute("rel", string.Empty).Equals("stylesheet", StringComparison.CurrentCultureIgnoreCase))
                    {
                        FeedStyleSheet(CssValue.GetStyleSheet(b.GetAttribute("href", string.Empty)));
                    }
                }

                CascadeStyles(b);
            }

            if (someBlock)
            {
                foreach (CssBox box in startBox.Boxes)
                {
                    box.Display = CssConstants.Block;
                }
            }
        }