public WrapperCssBoxBase(object controller,
                          BoxSpec spec,
                          RootGraphic rootgfx, CssDisplay display)
     : base(spec, new CssBoxRootGfxBridge(rootgfx), display)
 {
     this.SetController(controller);
 }
 public WrapperCssBoxBase(object controller,
      BoxSpec spec,
      RootGraphic root, CssDisplay display)
     : base(spec, root, display)
 {
     this.SetController(controller);
 }
Exemplo n.º 3
0
        public static CssBox CreateTableColumnOrColumnGroup(CssBox parent,
            HtmlElement childElement, bool fixDisplayType, CssDisplay selectedCssDisplayType)
        {
            CssBox col = null;
            if (fixDisplayType)
            {
                col = new CssBox(childElement.Spec, parent.RootGfx, selectedCssDisplayType);
            }
            else
            {
                col = new CssBox(childElement.Spec, parent.RootGfx);
            }
            col.SetController(childElement);
            parent.AppendChild(col);
            string spanValue;
            int spanNum = 1;//default
            if (childElement.TryGetAttribute(WellknownName.Span, out spanValue))
            {
                if (!int.TryParse(spanValue, out spanNum))
                {
                    spanNum = 1;
                }
                if (spanNum < 0)
                {
                    spanNum = -spanNum;
                }
            }

            col.SetRowSpanAndColSpan(1, spanNum);
            return col;
        }
Exemplo n.º 4
0
 public WrapperCssBoxBase(object controller,
                          BoxSpec spec,
                          RootGraphic root, CssDisplay display)
     : base(spec, root, display)
 {
     this.SetController(controller);
 }
Exemplo n.º 5
0
 public static CssBox CreateOtherPredefinedTableElement(CssBox parent,
     HtmlElement childElement, CssDisplay selectedCssDisplayType)
 {
     var newBox = new CssBox(childElement.Spec, parent.RootGfx, selectedCssDisplayType);
     newBox.SetController(childElement);
     parent.AppendChild(newBox);
     return newBox;
 }
Exemplo n.º 6
0
        public static void ChangeDisplayType(CssBox box, CssDisplay newdisplay)
        {
            TransplateDisplayOutsideInside(newdisplay, out box._displayOutside, out box._displayInside);

            if ((box._boxCompactFlags & BoxFlags.DONT_CHANGE_DISPLAY_TYPE) == 0)
            {
                box._cssDisplay = newdisplay;
            }


            //box.OutsideDisplayIsInline = ((newdisplay == CssDisplay.Inline ||
            //        newdisplay == CssDisplay.InlineBlock ||
            //        newdisplay == CssDisplay.InlineFlex)
            //        && !box.IsBrElement);
            box.OutsideDisplayIsInline = box._displayOutside == CssDisplayOutside.Inline && !box.IsBrElement;

            //---------------------------

            box._isVisible = box._cssDisplay != CssDisplay.None && box._myspec.Visibility == CssVisibility.Visible;

            box._renderBGAndBorder = box._cssDisplay != Css.CssDisplay.Inline ||
                                     box.Position == CssPosition.Absolute || //out of flow
                                     box.Position == CssPosition.Fixed;      //out of flow

            //-------------------------
            //check containing property
            //-------------------------
            switch (newdisplay)
            {
            case CssDisplay.Block:
            case CssDisplay.InlineBlock:

            case CssDisplay.ListItem:
            case CssDisplay.Table:
            case CssDisplay.InlineTable:
            case CssDisplay.TableCell:

            case CssDisplay.Flex:
            case CssDisplay.InlineFlex:
                box._boxCompactFlags |= BoxFlags.HAS_CONTAINER_PROP;
                break;

            default:
                //no container properties
                box._boxCompactFlags &= ~BoxFlags.HAS_CONTAINER_PROP;
                break;
            }
            //-------------------------
        }
Exemplo n.º 7
0
        public static string GetCssValue(this CssDisplay value)
        {
            switch (value)
            {
            case CssDisplay.Inherit:
                return("inherit");

            case CssDisplay.None:
                return("none");

            case CssDisplay.Block:
                return("block");

            case CssDisplay.InlineBlock:
                return("inline-block");

            default:
                throw new Exception();
            }
        }
Exemplo n.º 8
0
        public CssBox(BoxSpec spec, CssDisplay displayType)
        {
            _aa_boxes = new CssBoxCollection();
#if DEBUG
            //if (__aa_dbugId == 13)
            //{
            //}
            if (!spec.IsFreezed)
            {
                //must be freezed
                throw new NotSupportedException();
            }
#endif

            //assign spec
            _boxCompactFlags |= BoxFlags.DONT_CHANGE_DISPLAY_TYPE;
            _cssDisplay       = displayType;
            _myspec           = spec;
            //----------------------------
            EvaluateSpec(spec);
            ChangeDisplayType(this, _myspec.CssDisplay);
        }
Exemplo n.º 9
0
        public CssBox(BoxSpec spec, RootGraphic rootgfx, CssDisplay displayType)
        {
            this.rootgfx = rootgfx;
            this._aa_boxes = new CssBoxCollection();
#if DEBUG
            //if (this.__aa_dbugId == 6)
            //{
            //}
            if (!spec.IsFreezed)
            {
                //must be freezed 
                throw new NotSupportedException();
            }
#endif

            //assign spec             
            this._boxCompactFlags |= BoxFlags.DONT_CHANGE_DISPLAY_TYPE;
            this._cssDisplay = displayType;
            this._myspec = spec;
            //---------------------------- 
            EvaluateSpec(spec);
            ChangeDisplayType(this, _myspec.CssDisplay);
        }
Exemplo n.º 10
0
 public static string ToCssStringValue(this CssDisplay value)
 {
     return(_cssDisplayMap.GetStringFromValue(value));
 }
        public static void ChangeDisplayType(CssBox box, CssDisplay newdisplay)
        {
            TransplateDisplayOutsideInside(newdisplay, out box._displayOutside, out box._displayInside);
            if ((box._boxCompactFlags & BoxFlags.DONT_CHANGE_DISPLAY_TYPE) == 0)
            {
                box._cssDisplay = newdisplay;
            }


            //box.OutsideDisplayIsInline = ((newdisplay == CssDisplay.Inline ||
            //        newdisplay == CssDisplay.InlineBlock ||
            //        newdisplay == CssDisplay.InlineFlex)
            //        && !box.IsBrElement);
            box.OutsideDisplayIsInline = box._displayOutside == CssDisplayOutside.Inline && !box.IsBrElement;
            //---------------------------

            box._isVisible = box._cssDisplay != CssDisplay.None && box._myspec.Visibility == CssVisibility.Visible;
            box._renderBGAndBorder = box._cssDisplay != Css.CssDisplay.Inline ||
                   box.Position == CssPosition.Absolute || //out of flow
                   box.Position == CssPosition.Fixed; //out of flow
            //-------------------------
            //check containing property 
            //-------------------------
            switch (newdisplay)
            {
                case CssDisplay.Block:
                case CssDisplay.InlineBlock:

                case CssDisplay.ListItem:
                case CssDisplay.Table:
                case CssDisplay.InlineTable:
                case CssDisplay.TableCell:

                case CssDisplay.Flex:
                case CssDisplay.InlineFlex:
                    box._boxCompactFlags |= BoxFlags.HAS_CONTAINER_PROP;
                    break;
                default:
                    //no container properties 
                    box._boxCompactFlags &= ~BoxFlags.HAS_CONTAINER_PROP;
                    break;
            }
            //-------------------------
        }
Exemplo n.º 12
0
 public static T SetDisplay <T>(this T control, CssDisplay cssDisplay) where T : HtmlControl
 {
     control.Display = cssDisplay;
     return(control);
 }
Exemplo n.º 13
0
        public static CssBox CreateTableColumnOrColumnGroup(CssBox parent,
                                                            HtmlElement childElement, bool fixDisplayType, CssDisplay selectedCssDisplayType)
        {
            CssBox col = null;

            if (fixDisplayType)
            {
                col = new CssBox(childElement.Spec, parent.RootGfx, selectedCssDisplayType);
            }
            else
            {
                col = new CssBox(childElement.Spec, parent.RootGfx);
            }
            col.SetController(childElement);
            parent.AppendChild(col);
            string spanValue;
            int    spanNum = 1;//default

            if (childElement.TryGetAttribute(WellknownName.Span, out spanValue))
            {
                if (!int.TryParse(spanValue, out spanNum))
                {
                    spanNum = 1;
                }
                if (spanNum < 0)
                {
                    spanNum = -spanNum;
                }
            }

            col.SetRowSpanAndColSpan(1, spanNum);
            return(col);
        }
Exemplo n.º 14
0
        public static CssBox CreateOtherPredefinedTableElement(CssBox parent,
                                                               HtmlElement childElement, CssDisplay selectedCssDisplayType)
        {
            var newBox = new CssBox(childElement.Spec, parent.RootGfx, selectedCssDisplayType);

            newBox.SetController(childElement);
            parent.AppendChild(newBox);
            return(newBox);
        }
Exemplo n.º 15
0
        /// <summary>
        /// evaluate computed value
        /// </summary>
        internal void ReEvaluateComputedValues(ITextService iFonts, CssBox containingBlock)
        {
            //depend on parent
            //1. fonts
            if (this.ParentBox != null)
            {
                if (this.ParentBox.ResolvedFont == null)
                {
                    //TODO: review this ... WHY?
                    ReEvaluateFont(iFonts, containingBlock.ResolvedFont.SizeInPixels);
                }
                else
                {
                    ReEvaluateFont(iFonts, this.ParentBox.ResolvedFont.SizeInPixels);
                }


                //2. actual word spacing
                //_actualWordSpacing = this.NoEms(this.InitSpec.LineHeight);
                //3. font size
                //len = len.ConvertEmToPoints(parentBox.ActualFont.SizeInPoints);
            }
            else
            {
                ReEvaluateFont(iFonts, containingBlock.ResolvedFont.SizeInPixels);
                //_actualFont = this.Spec.GetFont(containingBlock.Spec);
            }

            //-----------------------------------------------------------------------
            float cbWidth            = containingBlock.VisualWidth;
            int   tmpBoxCompactFlags = _boxCompactFlags;

            _boxCompactFlags |= BoxFlags.LAY_EVAL_COMPUTE_VALUES;
            //www.w3.org/TR/CSS2/box.html#margin-properties
            //w3c: margin applies to all elements except elements table display type
            //other than table-caption,table and inline table
            CssDisplay cssDisplay = this.CssDisplay;
            BoxSpec    spec       = _myspec;

            switch (cssDisplay)
            {
            case CssDisplay.None:
            {
                return;
            }

            case CssDisplay.TableCell:
            case CssDisplay.TableColumn:
            case CssDisplay.TableColumnGroup:
            case CssDisplay.TableFooterGroup:
            case CssDisplay.TableHeaderGroup:
            case CssDisplay.TableRow:
            case CssDisplay.TableRowGroup:
            {
                //no margin
            }
            break;

            default:
            {
                //if (__aa_dbugId == 5)
                //{
                //    int a = spec.__aa_dbugId;

                //}

                _actualMarginLeft   = RecalculateMargin(spec.MarginLeft, cbWidth);
                _actualMarginTop    = RecalculateMargin(spec.MarginTop, cbWidth);
                _actualMarginRight  = RecalculateMargin(spec.MarginRight, cbWidth);
                _actualMarginBottom = RecalculateMargin(spec.MarginBottom, cbWidth);
            }
            break;
            }
            //www.w3.org/TR/CSS2/box.html#padding-properties
            switch (cssDisplay)
            {
            case CssDisplay.TableRowGroup:
            case CssDisplay.TableHeaderGroup:
            case CssDisplay.TableFooterGroup:
            case CssDisplay.TableRow:
            case CssDisplay.TableColumnGroup:
            case CssDisplay.TableColumn:
            {
                //no padding
            }
            break;

            default:
            {
                //-----------------------------------------------------------------------
                //padding
                _actualPaddingLeft   = RecalculatePadding(spec.PaddingLeft, cbWidth);
                _actualPaddingTop    = RecalculatePadding(spec.PaddingTop, cbWidth);
                _actualPaddingRight  = RecalculatePadding(spec.PaddingRight, cbWidth);
                _actualPaddingBottom = RecalculatePadding(spec.PaddingBottom, cbWidth);
            }
            break;
            }

            //-----------------------------------------------------------------------
            //borders
            float a1, a2, a3, a4;

            _actualBorderLeftWidth   = a1 = (spec.BorderLeftStyle == CssBorderStyle.None) ? 0 : CssValueParser.GetActualBorderWidth(spec.BorderLeftWidth, this);
            _actualBorderTopWidth    = a2 = (spec.BorderTopStyle == CssBorderStyle.None) ? 0 : CssValueParser.GetActualBorderWidth(spec.BorderTopWidth, this);
            _actualBorderRightWidth  = a3 = (spec.BorderRightStyle == CssBorderStyle.None) ? 0 : CssValueParser.GetActualBorderWidth(spec.BorderRightWidth, this);
            _actualBorderBottomWidth = a4 = (spec.BorderBottomStyle == CssBorderStyle.None) ? 0 : CssValueParser.GetActualBorderWidth(spec.BorderBottomWidth, this);
            //---------------------------------------------------------------------------

            _borderLeftVisible  = a1 > 0 && spec.BorderLeftStyle >= CssBorderStyle.Visible;
            _borderTopVisible   = a2 > 0 && spec.BorderTopStyle >= CssBorderStyle.Visible;
            _borderRightVisible = a3 > 0 && spec.BorderRightStyle >= CssBorderStyle.Visible;
            _borderBottomVisble = a4 > 0 && spec.BorderBottomStyle >= CssBorderStyle.Visible;
            //extension ***
            if (a1 + a2 + a3 + a4 > 0)
            {
                //css 2.1 border can't be nagative values

                tmpBoxCompactFlags |= BoxFlags.HAS_SOME_VISIBLE_BORDER;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_SOME_VISIBLE_BORDER;
            }
            //---------------------------------------------------------------------------

            _actualCornerNE = a1 = CssValueParser.ConvertToPx(spec.CornerNERadius, 0, this);
            _actualCornerNW = a2 = CssValueParser.ConvertToPx(spec.CornerNWRadius, 0, this);
            _actualCornerSE = a3 = CssValueParser.ConvertToPx(spec.CornerSERadius, 0, this);
            _actualCornerSW = a4 = CssValueParser.ConvertToPx(spec.CornerSWRadius, 0, this);
            if ((a1 + a2 + a3 + a4) > 0)
            {
                //evaluate
                tmpBoxCompactFlags |= BoxFlags.HAS_ROUND_CORNER;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_ROUND_CORNER;
            }
            //---------------------------------------------------------------------------
            //evaluate bg

            if (BackgroundGradient != Color.Transparent ||
                RenderUtils.IsColorVisible(ActualBackgroundColor))
            {
                tmpBoxCompactFlags |= BoxFlags.HAS_VISIBLE_BG;
            }
            else
            {
                tmpBoxCompactFlags &= ~BoxFlags.HAS_VISIBLE_BG;
            }



            if (spec.WordSpacing.IsNormalWordSpacing)
            {
                _actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont);
            }
            else
            {
                _actualWordSpacing = iFonts.MeasureWhitespace(_resolvedFont)
                                     + CssValueParser.ConvertToPx(spec.WordSpacing, 1, this);
            }
            //----------------------------------------------
            _boxCompactFlags = tmpBoxCompactFlags;
            //----------------------------------------------

            //text indent
            _actualTextIndent = CssValueParser.ConvertToPx(spec.TextIndent, containingBlock.VisualWidth, this);
            _actualBorderSpacingHorizontal = spec.BorderSpacingHorizontal.Number;
            _actualBorderSpacingVertical   = spec.BorderSpacingVertical.Number;
            //-----------------------
            //_actualLineHeight = 0.9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this);
            //expected width expected height
            //_expectedWidth = CssValueParser.ParseLength(Width, cbWidth, this);
            //_expectedHight = CssValueParser.ParseLength(Height, containingBlock.SizeHeight, this);
            ////----------------------------------------------


            //www.w3.org/TR/CSS2/visudet.html#line-height
            //line height,
            //percent value of line height :
            // is refer to font size of the element itself
            //if (this.LineHeight.Number > 0)
            //{
            //    _actualLineHeight = .9f * CssValueParser.ConvertToPx(LineHeight, this.GetEmHeight(), this);
            //}
            //else
            //{
            //    _actualLineHeight = .9f * (this.GetEmHeight());
            //}


            if (_myspec.HasBoxShadow)
            {
                //temp fix here
                //TODO: review move shadow to external decoration object/box
                if (_decorator == null)
                {
                    _decorator = new CssBoxDecorator();
                }
                _decorator.HBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowHOffset, 0, this);
                _decorator.VBoxShadowOffset = (int)CssValueParser.ConvertToPx(spec.BoxShadowVOffset, 0, this);
                _decorator.Color            = spec.BoxShadowColor;
            }
            else
            {
                _decorator = null;
            }
        }
        static void TransplateDisplayOutsideInside(CssDisplay cssDisplay, out CssDisplayOutside outside, out CssDisplayInside inside)
        {
            //Short display     Full display    Generated box
            //none  〃                           subtree omitted from box tree
            //contents  〃                       element replaced by contents in box tree

            //block         'block flow'        block-level block container aka block box
            //flow-root     'block flow-root'   block-level block container that establishes a new block formatting context (BFC)
            //inline        'inline flow'       inline box
            //inline-block  'inline flow-root'  inline-level block container
            //run-in        'run-in flow'       run-in box (inline box with special box-tree-munging rules)
            //list-item      'list-item block flow'     block box with additional marker box
            //inline list-item  'list-item inline flow'     inline box with additional marker box
            //flex           'block flex'       block-level flex container
            //inline-flex    'inline flex'  inline-level flex container
            //grid           'block grid'   block-level grid container
            //inline-grid    'inline grid'  inline-level grid container
            //ruby           'inline ruby'  inline-level ruby container
            //block ruby     'block ruby'   block box containing ruby container
            //table          'block table'  block-level table wrapper box containing table box
            //inline-table   'inline table'     inline-level table wrapper box containing table box
            //table-cell     'table-cell flow'  table cell block container
            //table-caption  'table-caption flow'   table cell block container
            //ruby-base      'ruby-base flow'   layout-specific internal box
            //ruby-text       'ruby-text flow'  layout-specific internal box
            //other <display-internal>  〃   layout-specific internal box
            switch (cssDisplay)
            {
            default:
                throw new NotSupportedException();

            case CssDisplay.TableColumn:
            case CssDisplay.TableColumnGroup:
            case CssDisplay.TableRow:
            case CssDisplay.TableRowGroup:
            case CssDisplay.TableHeaderGroup:
            case CssDisplay.TableFooterGroup:
            case CssDisplay.None:
                outside = CssDisplayOutside.Internal;
                inside  = CssDisplayInside.Internal;
                break;

            //outside -> inline
            case CssDisplay.Inline:
                outside = CssDisplayOutside.Inline;     //*
                inside  = CssDisplayInside.Flow;
                break;

            case CssDisplay.InlineBlock:
                outside = CssDisplayOutside.Inline;     //*
                inside  = CssDisplayInside.FlowRoot;
                break;

            case CssDisplay.InlineTable:
                outside = CssDisplayOutside.Inline;     //*
                inside  = CssDisplayInside.Table;
                break;

            case CssDisplay.InlineFlex:
                outside = CssDisplayOutside.Inline;     //*
                inside  = CssDisplayInside.Flex;
                break;

            //-------
            //outside -> block
            case CssDisplay.ListItem:
                outside = CssDisplayOutside.Block;
                inside  = CssDisplayInside.Flow;
                break;

            case CssDisplay.Flex:
                outside = CssDisplayOutside.Block;
                inside  = CssDisplayInside.Flex;
                break;

            case CssDisplay.Block:
                outside = CssDisplayOutside.Block;
                inside  = CssDisplayInside.Flow;
                break;

            case CssDisplay.Table:
                outside = CssDisplayOutside.Block;
                inside  = CssDisplayInside.Table;
                break;

            //-----------------
            //special
            case CssDisplay.TableCaption:
                outside = CssDisplayOutside.TableCaption;
                inside  = CssDisplayInside.Flow;
                break;

            case CssDisplay.TableCell:
                outside = CssDisplayOutside.TableCell;
                inside  = CssDisplayInside.Flow;
                break;
            }
        }
Exemplo n.º 17
0
 public static T WithDisplay <T>(this T control, CssDisplay value) where T : Control
 {
     control.Style.Display = value;
     return(control);
 }
        static void TransplateDisplayOutsideInside(CssDisplay cssDisplay, out CssDisplayOutside outside, out CssDisplayInside inside)
        {
            //Short display 	Full display 	Generated box
            //none 	〃 	                        subtree omitted from box tree
            //contents 	〃 	                    element replaced by contents in box tree

            //block 	    'block flow' 	    block-level block container aka block box
            //flow-root 	'block flow-root' 	block-level block container that establishes a new block formatting context (BFC)
            //inline 	    'inline flow' 	    inline box
            //inline-block 	'inline flow-root' 	inline-level block container
            //run-in 	    'run-in flow' 	    run-in box (inline box with special box-tree-munging rules)
            //list-item 	 'list-item block flow' 	block box with additional marker box
            //inline list-item 	'list-item inline flow' 	inline box with additional marker box
            //flex 	         'block flex'       block-level flex container
            //inline-flex 	 'inline flex' 	inline-level flex container
            //grid 	         'block grid' 	block-level grid container
            //inline-grid 	 'inline grid' 	inline-level grid container
            //ruby 	         'inline ruby' 	inline-level ruby container
            //block ruby 	 'block ruby' 	block box containing ruby container
            //table 	     'block table' 	block-level table wrapper box containing table box
            //inline-table 	 'inline table' 	inline-level table wrapper box containing table box
            //table-cell 	 'table-cell flow' 	table cell block container
            //table-caption  'table-caption flow' 	table cell block container
            //ruby-base 	 'ruby-base flow' 	layout-specific internal box
            //ruby-text 	  'ruby-text flow' 	layout-specific internal box
            //other <display-internal> 	〃 	layout-specific internal box
            switch (cssDisplay)
            {
                default:
                    throw new NotSupportedException();
                case CssDisplay.TableColumn:
                case CssDisplay.TableColumnGroup:
                case CssDisplay.TableRow:
                case CssDisplay.TableRowGroup:
                case CssDisplay.TableHeaderGroup:
                case CssDisplay.TableFooterGroup:
                case CssDisplay.None:
                    outside = CssDisplayOutside.Internal;
                    inside = CssDisplayInside.Internal;
                    break;
                //outside -> inline
                case CssDisplay.Inline:
                    outside = CssDisplayOutside.Inline; //*
                    inside = CssDisplayInside.Flow;
                    break;
                case CssDisplay.InlineBlock:
                    outside = CssDisplayOutside.Inline; //*
                    inside = CssDisplayInside.FlowRoot;
                    break;
                case CssDisplay.InlineTable:
                    outside = CssDisplayOutside.Inline; //*
                    inside = CssDisplayInside.Table;
                    break;
                case CssDisplay.InlineFlex:
                    outside = CssDisplayOutside.Inline; //*
                    inside = CssDisplayInside.Flex;
                    break;
                //-------
                //outside -> block
                case CssDisplay.ListItem:
                    outside = CssDisplayOutside.Block;
                    inside = CssDisplayInside.Flow;
                    break;
                case CssDisplay.Flex:
                    outside = CssDisplayOutside.Block;
                    inside = CssDisplayInside.Flex;
                    break;
                case CssDisplay.Block:
                    outside = CssDisplayOutside.Block;
                    inside = CssDisplayInside.Flow;
                    break;
                case CssDisplay.Table:
                    outside = CssDisplayOutside.Block;
                    inside = CssDisplayInside.Table;
                    break;
                //-----------------
                //special
                case CssDisplay.TableCaption:
                    outside = CssDisplayOutside.TableCaption;
                    inside = CssDisplayInside.Flow;
                    break;
                case CssDisplay.TableCell:
                    outside = CssDisplayOutside.TableCell;
                    inside = CssDisplayInside.Flow;
                    break;
            }
        }