public virtual MarginsCollapseInfo StartChildMarginsHandling(IRenderer child, Rectangle layoutBox)
        {
            if (backupLayoutBox != null)
            {
                // this should happen only if previous kid was floated
                RestoreLayoutBoxAfterFailedLayoutAttempt(layoutBox);
                RemoveRendererChild(--processedChildrenNum);
                childMarginInfo = null;
            }
            rendererChildren.Add(child);
            int childIndex = processedChildrenNum++;
            // If renderer is floated, prepare layout box as if it was inline,
            // however it will be restored from backup when next kid processing will start.
            bool childIsBlockElement = !RendererIsFloated(child) && IsBlockElement(child);

            backupLayoutBox    = layoutBox.Clone();
            backupCollapseInfo = new MarginsCollapseInfo();
            collapseInfo.CopyTo(backupCollapseInfo);
            PrepareBoxForLayoutAttempt(layoutBox, childIndex, childIsBlockElement);
            if (childIsBlockElement)
            {
                childMarginInfo = CreateMarginsInfoForBlockChild(childIndex);
            }
            return(this.childMarginInfo);
        }
 public MarginsCollapseHandler(IRenderer renderer, MarginsCollapseInfo marginsCollapseInfo)
 {
     // Layout box and collapse info are saved before processing the next kid, in order to be able to restore it in case
     // the next kid is not placed. These values are not null only between startChildMarginsHandling and endChildMarginsHandling calls.
     this.renderer     = renderer;
     this.collapseInfo = marginsCollapseInfo != null ? marginsCollapseInfo : new MarginsCollapseInfo();
 }
 private void RestoreLayoutBoxAfterFailedLayoutAttempt(Rectangle layoutBox)
 {
     layoutBox.SetX(backupLayoutBox.GetX()).SetY(backupLayoutBox.GetY()).SetWidth(backupLayoutBox.GetWidth()).SetHeight
         (backupLayoutBox.GetHeight());
     backupCollapseInfo.CopyTo(collapseInfo);
     backupLayoutBox    = null;
     backupCollapseInfo = null;
 }
        /// <summary>This method shall be called after child occupied area is included into parent occupied area.</summary>
        public virtual void EndChildMarginsHandling(Rectangle layoutBox)
        {
            int childIndex = processedChildrenNum - 1;

            if (RendererIsFloated(GetRendererChild(childIndex)))
            {
                return;
            }
            if (childMarginInfo != null)
            {
                if (firstNotEmptyKidIndex == childIndex && childMarginInfo.IsSelfCollapsing())
                {
                    firstNotEmptyKidIndex = childIndex + 1;
                }
                collapseInfo.SetSelfCollapsing(collapseInfo.IsSelfCollapsing() && childMarginInfo.IsSelfCollapsing());
                lastKidCollapsedAfterHasClearanceApplied = childMarginInfo.IsSelfCollapsing() && childMarginInfo.IsClearanceApplied
                                                               ();
            }
            else
            {
                lastKidCollapsedAfterHasClearanceApplied = false;
                collapseInfo.SetSelfCollapsing(false);
            }
            if (prevChildMarginInfo != null)
            {
                FixPrevChildOccupiedArea(childIndex);
                UpdateCollapseBeforeIfPrevKidIsFirstAndSelfCollapsed(prevChildMarginInfo.GetOwnCollapseAfter());
            }
            if (firstNotEmptyKidIndex == childIndex && FirstChildMarginAdjoinedToParent(renderer))
            {
                if (!collapseInfo.IsSelfCollapsing())
                {
                    GetRidOfCollapseArtifactsAtopOccupiedArea();
                    if (childMarginInfo != null)
                    {
                        ProcessUsedChildBufferSpaceOnTop(layoutBox);
                    }
                }
            }
            prevChildMarginInfo = childMarginInfo;
            childMarginInfo     = null;
            backupLayoutBox     = null;
            backupCollapseInfo  = null;
        }
        private MarginsCollapseInfo CreateMarginsInfoForBlockChild(int childIndex)
        {
            bool ignoreChildTopMargin = false;
            // always assume that current child might be the last on this area
            bool ignoreChildBottomMargin = LastChildMarginAdjoinedToParent(renderer);

            if (childIndex == firstNotEmptyKidIndex)
            {
                ignoreChildTopMargin = FirstChildMarginAdjoinedToParent(renderer);
            }
            MarginsCollapse childCollapseBefore;

            if (childIndex == 0)
            {
                MarginsCollapse parentCollapseBefore = collapseInfo.GetCollapseBefore();
                childCollapseBefore = ignoreChildTopMargin ? parentCollapseBefore : new MarginsCollapse();
            }
            else
            {
                MarginsCollapse prevChildCollapseAfter = prevChildMarginInfo != null?prevChildMarginInfo.GetOwnCollapseAfter
                                                             () : null;

                childCollapseBefore = prevChildCollapseAfter != null ? prevChildCollapseAfter : new MarginsCollapse();
            }
            MarginsCollapse     parentCollapseAfter = collapseInfo.GetCollapseAfter().Clone();
            MarginsCollapse     childCollapseAfter  = ignoreChildBottomMargin ? parentCollapseAfter : new MarginsCollapse();
            MarginsCollapseInfo childMarginsInfo    = new MarginsCollapseInfo(ignoreChildTopMargin, ignoreChildBottomMargin
                                                                              , childCollapseBefore, childCollapseAfter);

            if (ignoreChildTopMargin && childIndex == firstNotEmptyKidIndex)
            {
                childMarginsInfo.SetBufferSpaceOnTop(collapseInfo.GetBufferSpaceOnTop());
            }
            if (ignoreChildBottomMargin)
            {
                childMarginsInfo.SetBufferSpaceOnBottom(collapseInfo.GetBufferSpaceOnBottom());
            }
            return(childMarginsInfo);
        }
Exemple #6
0
 public MarginsCollapseHandler(IRenderer renderer, MarginsCollapseInfo marginsCollapseInfo)
 {
     this.renderer     = renderer;
     this.collapseInfo = marginsCollapseInfo != null ? marginsCollapseInfo : new MarginsCollapseInfo();
 }