CSS box for hr element.
Inheritance: CssBox
Ejemplo n.º 1
0
        internal CssBox CreateBox(CssBox parentBox, HtmlElement childElement, bool fullmode)
        {
            //----------------------------------------- 
            //1. create new box
            //----------------------------------------- 
            //some box has predefined behaviour 
            CssBox newBox = null;
            switch (childElement.WellknownElementName)
            {
                case WellKnownDomNodeName.br:
                    //special treatment for br
                    newBox = new CssBox(childElement.Spec, parentBox.RootGfx);
                    newBox.SetController(childElement);
                    CssBox.SetAsBrBox(newBox);
                    CssBox.ChangeDisplayType(newBox, CssDisplay.Block);
                    parentBox.AppendChild(newBox);
                    childElement.SetPrincipalBox(newBox);
                    return newBox;
                case WellKnownDomNodeName.img:

                    //auto append newBox to parentBox
                    newBox = CreateImageBox(parentBox, childElement);
                    childElement.SetPrincipalBox(newBox);
                    return newBox;
                case WellKnownDomNodeName.hr:
                    newBox = new CssBoxHr(childElement.Spec, parentBox.RootGfx);
                    newBox.SetController(childElement);
                    parentBox.AppendChild(newBox);
                    childElement.SetPrincipalBox(newBox);
                    return newBox;
                //-----------------------------------------------------
                //TODO: simplify this ...
                //table-display elements, fix display type
                case WellKnownDomNodeName.td:
                case WellKnownDomNodeName.th:
                    newBox = TableBoxCreator.CreateTableCell(parentBox, childElement, true);
                    break;
                case WellKnownDomNodeName.col:
                    newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, true, CssDisplay.TableColumn);
                    break;
                case WellKnownDomNodeName.colgroup:
                    newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, true, CssDisplay.TableColumnGroup);
                    break;
                case WellKnownDomNodeName.tr:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableRow);
                    break;
                case WellKnownDomNodeName.tbody:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableRowGroup);
                    break;
                case WellKnownDomNodeName.table:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.Table);
                    break;
                case WellKnownDomNodeName.caption:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableCaption);
                    break;
                case WellKnownDomNodeName.thead:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableHeaderGroup);
                    break;
                case WellKnownDomNodeName.tfoot:
                    newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableFooterGroup);
                    break;
                //---------------------------------------------------
                case WellKnownDomNodeName.canvas:
                case WellKnownDomNodeName.input:

                    newBox = this.CreateCustomCssBox(parentBox, childElement, childElement.Spec);
                    if (newBox != null)
                    {
                        childElement.SetPrincipalBox(newBox);
                        return newBox;
                    }
                    goto default; //else goto default *** 
                //---------------------------------------------------
                case WellKnownDomNodeName.svg:
                    {
                        //1. create svg container node 
                        newBox = Svg.SvgCreator.CreateSvgBox(parentBox, childElement, childElement.Spec);
                        childElement.SetPrincipalBox(newBox);
                        return newBox;
                    }
                case WellKnownDomNodeName.NotAssign:
                case WellKnownDomNodeName.Unknown:
                    {
                        //custom tag
                        //check if this is tag is registered as custom element
                        //-----------------------------------------------
                        if (childElement.HasCustomPrincipalBoxGenerator)
                        {
                            var childbox = childElement.GetPrincipalBox(parentBox, this);
                            parentBox.AppendChild(childbox);
                            return childbox;
                        }

                        //----------------------------------------------- 
                        LayoutFarm.Composers.CreateCssBoxDelegate foundBoxGen;
                        if (((HtmlDocument)childElement.OwnerDocument).TryGetCustomBoxGenerator(childElement.Name, out foundBoxGen))
                        {
                            //create custom box 
                            newBox = foundBoxGen(childElement, parentBox, childElement.Spec, this);
                        }
                        if (newBox == null)
                        {
                            goto default;
                        }
                        else
                        {
                            childElement.SetPrincipalBox(newBox);
                            return newBox;
                        }
                    }
                default:
                    {
                        BoxSpec childSpec = childElement.Spec;
                        switch (childSpec.CssDisplay)
                        {
                            //not fixed display type
                            case CssDisplay.TableCell:
                                newBox = TableBoxCreator.CreateTableCell(parentBox, childElement, false);
                                break;
                            case CssDisplay.TableColumn:
                                newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, false, CssDisplay.TableColumn);
                                break;
                            case CssDisplay.TableColumnGroup:
                                newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, false, CssDisplay.TableColumnGroup);
                                break;
                            case CssDisplay.ListItem:
                                newBox = ListItemBoxCreator.CreateListItemBox(parentBox, childElement);
                                break;
                            default:
                                newBox = new CssBox(childSpec, parentBox.RootGfx);
                                newBox.SetController(childElement);
                                parentBox.AppendChild(newBox);
                                break;
                        }
                    }
                    break;
            }

            childElement.SetPrincipalBox(newBox);
            UpdateChildBoxes(childElement, fullmode);
            return newBox;
        }
Ejemplo n.º 2
0
        internal CssBox CreateBox(CssBox parentBox, HtmlElement childElement, bool fullmode)
        {
            //-----------------------------------------
            //1. create new box
            //-----------------------------------------
            //some box has predefined behaviour
            CssBox newBox = null;

            switch (childElement.WellknownElementName)
            {
            case WellKnownDomNodeName.br:
                //special treatment for br
                newBox = new CssBox(childElement.Spec, parentBox.RootGfx);
                newBox.SetController(childElement);
                CssBox.SetAsBrBox(newBox);
                CssBox.ChangeDisplayType(newBox, CssDisplay.Block);
                parentBox.AppendChild(newBox);
                childElement.SetPrincipalBox(newBox);
                return(newBox);

            case WellKnownDomNodeName.img:

                //auto append newBox to parentBox
                newBox = CreateImageBox(parentBox, childElement);
                childElement.SetPrincipalBox(newBox);
                return(newBox);

            case WellKnownDomNodeName.hr:
                newBox = new CssBoxHr(childElement.Spec, parentBox.RootGfx);
                newBox.SetController(childElement);
                parentBox.AppendChild(newBox);
                childElement.SetPrincipalBox(newBox);
                return(newBox);

            //-----------------------------------------------------
            //TODO: simplify this ...
            //table-display elements, fix display type
            case WellKnownDomNodeName.td:
            case WellKnownDomNodeName.th:
                newBox = TableBoxCreator.CreateTableCell(parentBox, childElement, true);
                break;

            case WellKnownDomNodeName.col:
                newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, true, CssDisplay.TableColumn);
                break;

            case WellKnownDomNodeName.colgroup:
                newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, true, CssDisplay.TableColumnGroup);
                break;

            case WellKnownDomNodeName.tr:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableRow);
                break;

            case WellKnownDomNodeName.tbody:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableRowGroup);
                break;

            case WellKnownDomNodeName.table:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.Table);
                break;

            case WellKnownDomNodeName.caption:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableCaption);
                break;

            case WellKnownDomNodeName.thead:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableHeaderGroup);
                break;

            case WellKnownDomNodeName.tfoot:
                newBox = TableBoxCreator.CreateOtherPredefinedTableElement(parentBox, childElement, CssDisplay.TableFooterGroup);
                break;

            //---------------------------------------------------
            case WellKnownDomNodeName.canvas:
            case WellKnownDomNodeName.input:

                newBox = this.CreateCustomCssBox(parentBox, childElement, childElement.Spec);
                if (newBox != null)
                {
                    childElement.SetPrincipalBox(newBox);
                    return(newBox);
                }
                goto default;     //else goto default ***

            //---------------------------------------------------
            case WellKnownDomNodeName.svg:
            {
                //1. create svg container node
                newBox = _svgCreator.CreateSvgBox(parentBox, childElement, childElement.Spec);
                childElement.SetPrincipalBox(newBox);
                return(newBox);
            }

            case WellKnownDomNodeName.NotAssign:
            case WellKnownDomNodeName.Unknown:
            {
                //custom tag
                //check if this is tag is registered as custom element
                //-----------------------------------------------
                if (childElement.HasCustomPrincipalBoxGenerator)
                {
                    var childbox = childElement.GetPrincipalBox(parentBox, this);
                    parentBox.AppendChild(childbox);
                    return(childbox);
                }

                //-----------------------------------------------
                LayoutFarm.Composers.CreateCssBoxDelegate foundBoxGen;
                if (((HtmlDocument)childElement.OwnerDocument).TryGetCustomBoxGenerator(childElement.Name, out foundBoxGen))
                {
                    //create custom box
                    newBox = foundBoxGen(childElement, parentBox, childElement.Spec, this);
                }
                if (newBox == null)
                {
                    goto default;
                }
                else
                {
                    childElement.SetPrincipalBox(newBox);
                    return(newBox);
                }
            }

            default:
            {
                BoxSpec childSpec = childElement.Spec;
                switch (childSpec.CssDisplay)
                {
                //not fixed display type
                case CssDisplay.TableCell:
                    newBox = TableBoxCreator.CreateTableCell(parentBox, childElement, false);
                    break;

                case CssDisplay.TableColumn:
                    newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, false, CssDisplay.TableColumn);
                    break;

                case CssDisplay.TableColumnGroup:
                    newBox = TableBoxCreator.CreateTableColumnOrColumnGroup(parentBox, childElement, false, CssDisplay.TableColumnGroup);
                    break;

                case CssDisplay.ListItem:
                    newBox = ListItemBoxCreator.CreateListItemBox(parentBox, childElement);
                    break;

                default:
                    newBox = new CssBox(childSpec, parentBox.RootGfx);
                    newBox.SetController(childElement);
                    parentBox.AppendChild(newBox);
                    break;
                }
            }
            break;
            }

            childElement.SetPrincipalBox(newBox);
            UpdateChildBoxes(childElement, fullmode);
            return(newBox);
        }