Пример #1
0
        public TElement(IElement htmlElement, TElement parent)
        {
            NormalFlowChildren   = new List <TElement>();
            FloatFlowChildren    = new List <TElement>();
            AbsoluteFlowChildren = new List <TElement>();

            DefaultBackgroundColor = new Color(255, 255, 255, 255);
            DefaultBorderColor     = new Color(0, 0, 0, 255);
            DefaultForegroundColor = new Color(0, 0, 0, 255);

            Parent   = parent;
            Children = new List <TElement>();
            Canvas   = GfxFactory.Create <IGfxCanvas>();

            InitHtml(htmlElement);
            InitCss(htmlElement);
            ComputeBoundingBox();

            var elementFactory = new TElementFactory();

            foreach (IElement htmlChild in htmlElement.Children)
            {
                var child = elementFactory.Create(htmlChild, this);

                Children.Add(child);
                ComputeBoundingBox(child);
                AddToFlowList(child);
            }
        }
Пример #2
0
        public void Parse(string html)
        {
            var config   = new Configuration().WithCss();
            var parser   = new HtmlParser(config ?? Configuration.Default);
            var document = parser.Parse(html);

            var factory = new TElementFactory();

            Body = factory.Create(document.Body, null);
        }
Пример #3
0
        private void ComputeBoundingBox(TElement element)
        {
            var box = new TRectangle()
            {
                Width  = element.Css.Width.Value,
                Height = element.Css.Height.Value
            };

            var childFloatAttribute = element.GetFloat();

            if (childFloatAttribute == Float.None)
            {
                box.X = BoundingBox.Left;
                box.Y = LeftFloatPosition.Y;

                LeftFloatPosition.X   = BoundingBox.Left;
                LeftFloatPosition.Y  += box.Height;
                RightFloatPosition.Y += box.Height;
            }
            else if (childFloatAttribute == Float.Left)
            {
                box.X = LeftFloatPosition.X;
                box.Y = LeftFloatPosition.Y;

                LeftFloatPosition.X += box.Width;

                if (LeftFloatPosition.X + box.Width > BoundingBox.Width)
                {
                    LeftFloatPosition.X  = BoundingBox.Left;
                    LeftFloatPosition.Y += box.Height;
                }
            }
            else if (childFloatAttribute == Float.Right)
            {
                box.X = RightFloatPosition.X - box.Width;
                box.Y = RightFloatPosition.Y;

                RightFloatPosition.X -= box.Width;

                if (RightFloatPosition.X < BoundingBox.Left)
                {
                    RightFloatPosition.X  = BoundingBox.Width;
                    RightFloatPosition.Y += box.Height;
                }
            }

            element.BoundingBox = box;
        }
Пример #4
0
        private void AddToFlowList(TElement element)
        {
            switch (element.GetFloat())
            {
            case Float.None:
                NormalFlowChildren.Add(element);
                break;

            case Float.Left:
            case Float.Right:
                FloatFlowChildren.Add(element);
                break;
            }

            //TODO! Take element's Position into consideration too.
        }
Пример #5
0
 public TSpan(IElement htmlElement, TElement parent)
     : base(htmlElement, parent)
 {
 }
Пример #6
0
 public TBody(IElement htmlElement, TElement parent)
     : base(htmlElement, parent)
 {
 }
Пример #7
0
 public TParagraph(IElement htmlElement, TElement parent)
     : base(htmlElement, parent)
 {
 }
Пример #8
0
 public TDiv(IElement htmlElement, TElement parent)
     : base(htmlElement, parent)
 {
 }