Represents a CSS Box of text or replaced elements.
The Box can contains other boxes, that's the way that the CSS Tree is composed. To know more about boxes visit CSS spec: http://www.w3.org/TR/CSS21/box.html
        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;
        }
        internal static LayoutFarm.HtmlBoxes.CssBox CreateCssBox(
            LayoutFarm.WebDom.IHtmlElement domE,
            LayoutFarm.HtmlBoxes.CssBox parentBox,
            LayoutFarm.Css.BoxSpec spec,
            LayoutFarm.HtmlBoxes.HtmlHost htmlhost)
        {
            //create cssbox 
            //test only!           
            var newspec = new BoxSpec();
            BoxSpec.InheritStyles(newspec, spec);
            newspec.BackgroundColor = Color.Blue;
            newspec.Width = new CssLength(50, CssUnitOrNames.Pixels);
            newspec.Height = new CssLength(50, CssUnitOrNames.Pixels);
            newspec.Position = CssPosition.Absolute;
            newspec.Freeze(); //freeze before use
            HtmlElement htmlElement = (HtmlElement)domE;
            var newBox = new CssBox(newspec, parentBox.RootGfx);
            newBox.SetController(domE);
            htmlElement.SetPrincipalBox(newBox);
            //auto set bc of the element

            parentBox.AppendChild(newBox);
            htmlhost.UpdateChildBoxes(htmlElement, true);
            //----------
            return newBox;
        }
        /// <summary>
        /// Draws all the border of the box with respect to style, width, etc.
        /// </summary>
        /// <param name="g">the device to draw into</param>
        /// <param name="box">the box to draw borders for</param>
        /// <param name="rect">the bounding rectangle to draw in</param>
        /// <param name="isFirst">is it the first rectangle of the element</param>
        /// <param name="isLast">is it the last rectangle of the element</param>
        public static void DrawBoxBorders(PaintVisitor p, CssBox box, RectangleF rect, bool isFirst, bool isLast)
        {
            if (rect.Width > 0 && rect.Height > 0)
            {
                if (box.BorderTopVisible)
                {
                    DrawBorder(CssSide.Top, box, p, rect, isFirst, isLast);
                }

                if (isFirst && box.BorderLeftVisible)
                {
                    DrawBorder(CssSide.Left, box, p, rect, true, isLast);
                }

                if (box.BorderBottomVisible)
                {
                    DrawBorder(CssSide.Bottom, box, p, rect, isFirst, isLast);
                }

                if (isLast && box.BorderRightVisible)
                {
                    DrawBorder(CssSide.Right, box, p, rect, isFirst, true);
                }
            }
        }
Beispiel #4
0
 public HitInfo(CssBox box, int x, int y)
 {
     this.hitObject = box;
     this.hitObjectKind = HitObjectKind.CssBox;
     this.localX = x;
     this.localY = y;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="g"></param>
 /// <param name="tableBox"> </param>
 public static void PerformLayout(CssBox tableBox, float hostAvailableWidth, LayoutVisitor lay)
 {
     var table = new CssTableLayoutEngine(tableBox, hostAvailableWidth);
     table._tmpIFonts = lay.SampleIFonts;
     table.Layout(lay);
     table._tmpIFonts = null;
 }
 public static float ConvertToPxWithFontAdjust(CssLength length, float hundredPercent, CssBox box)
 {
     //Return zero if no length specified, zero specified     
     switch (length.UnitOrNames)
     {
         case CssUnitOrNames.EmptyValue:
             return 0;
         case CssUnitOrNames.Percent:
             return (length.Number / 100f) * hundredPercent;
         case CssUnitOrNames.Ems:
             return length.Number * box.GetEmHeight();
         case CssUnitOrNames.Ex:
             return length.Number * (box.GetEmHeight() / 2);
         case CssUnitOrNames.Pixels:
             //atodo: check support for hi dpi
             return length.Number * (72f / 96f); //font adjust
         case CssUnitOrNames.Milimeters:
             return length.Number * 3.779527559f; //3 pixels per millimeter      
         case CssUnitOrNames.Centimeters:
             return length.Number * 37.795275591f; //37 pixels per centimeter 
         case CssUnitOrNames.Inches:
             return length.Number * 96f; //96 pixels per inch 
         case CssUnitOrNames.Points:
             return length.Number * (96f / 72f); // 1 point = 1/72 of inch   
         case CssUnitOrNames.Picas:
             return length.Number * 16f; // 1 pica = 12 points 
         default:
             return 0;
     }
 }
        internal override CssBox GetPrincipalBox(CssBox parentCssBox, HtmlHost htmlHost)
        {
            if (rootbox != null)
            {
                return this.rootbox;
            }
            else
            {
                var root = (HtmlElement)shadowDoc.RootNode;
                //1. builder 
                var renderTreeBuilder = htmlHost.GetRenderTreeBuilder();
                //------------------------------------------------------------------- 
                //2. generate render tree
                ////build rootbox from htmldoc

                var rootElement = renderTreeBuilder.BuildCssRenderTree2(shadowDoc,
                    htmlHost.BaseStylesheet,
                    htmlHost.RootGfx);
                //3. create small htmlContainer

                rootbox = new CssBox(this.Spec, parentCssBox.RootGfx);
                root.SetPrincipalBox(rootbox);
                htmlHost.UpdateChildBoxes(root, true);
                return rootbox;
            }
        }
        internal static LayoutFarm.HtmlBoxes.CssBox CreateCssBox(
            LayoutFarm.WebDom.IHtmlElement domE,
            LayoutFarm.HtmlBoxes.CssBox parentBox,
            LayoutFarm.Css.BoxSpec spec,
            LayoutFarm.HtmlBoxes.HtmlHost htmlhost)
        {


            //create cssbox 
            //test only!           
            var newspec = new BoxSpec();
            BoxSpec.InheritStyles(newspec, spec);
            newspec.BackgroundColor = Color.Blue;
            newspec.Width = new CssLength(50, CssUnitOrNames.Pixels);
            newspec.Height = new CssLength(50, CssUnitOrNames.Pixels);
            newspec.Position = CssPosition.Absolute;
            newspec.Freeze(); //freeze before use

            HtmlElement htmlElement = (HtmlElement)domE;
            var newBox = new CssBox(newspec, parentBox.RootGfx);
            newBox.SetController(domE);
            htmlElement.SetPrincipalBox(newBox);
            //auto set bc of the element

            parentBox.AppendChild(newBox);
            htmlhost.UpdateChildBoxes(htmlElement, true);
            //----------
            return newBox;
        }
Beispiel #9
0
 public FlexItem(CssBox box)
 {
     this.box = box;
     this.MinWidth = CssLength.AutoLength;
     this.MinHeight = CssLength.AutoLength;
     if (box.Width.IsEmptyOrAuto)
     {
         //auto
         minSizeW = box.InnerContentWidth;
         maxSizeW = MAXSIZE_W;
     }
     else
     {
         maxSizeW = minSizeW = box.VisualWidth;
     }
     if (box.Height.IsEmptyOrAuto)
     {
         minSizeH = box.InnerContentHeight;
         maxSizeH = MAXSIZE_H;
     }
     else
     {
         maxSizeH = minSizeH = box.VisualHeight;
     }
     this.PlanWidth = minSizeW;
     this.PlanHeight = minSizeH;
 }
 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;
 }
Beispiel #11
0
 public PartialBoxStrip(CssBox owner, float x, float y, float w, float h)
 {
     this.owner = owner;
     this._x = x;
     this._y = y;
     this._width = w;
     this._height = h;
 }
 public void Paint(CssBox box, PaintVisitor p)
 {
     p.FillRectangle(this.Color,
         box.LocalX + this.HBoxShadowOffset,
         box.LocalY + this.VBoxShadowOffset,
         box.VisualWidth,
         box.VisualHeight);
 }
        public void AddChild(CssBox owner, CssBox box)
        {
#if DEBUG
            if (owner == box)
            {
                throw new NotSupportedException();
            }
#endif
            CssBox.UnsafeSetNodes(box, owner, _boxes.AddLast(box));
        }
Beispiel #14
0
 internal void PushContaingBlock(CssBox box)
 {
     //enter new containing block
     OnPushContainingBlock(box);
     if (box != latestContainingBlock)
     {
         this.globalXOffset += box.LocalX;
         this.globalYOffset += box.LocalY;
         OnPushDifferentContainingBlock(box);
     }
     this.containgBlockStack.Push(box);
     this.latestContainingBlock = box;
 }
        public void MouseDown(UIMouseEventArgs e, CssBox startAt)
        {
            if (!_isBinded) return;
            if (startAt == null) return;
            //---------------------------------------------------- 
            ClearPreviousSelection();
            if (_latestMouseDownChain != null)
            {
                ReleaseHitChain(_latestMouseDownChain);
                _latestMouseDownChain = null;
            }
            this.lastDomLayoutVersion = this._htmlContainer.LayoutVersion;
            //----------------------------------------------------
            int x = e.X;
            int y = e.Y;
            this._mouseDownStartAt = startAt;
            this._mousedownX = x;
            this._mousedownY = y;
            CssBoxHitChain hitChain = GetFreeHitChain();
            hitChain.SetRootGlobalPosition(x, y);
            //1. hittest 
            BoxHitUtils.HitTest(startAt, x, y, hitChain);
            //2. propagate events
            SetEventOrigin(e, hitChain);
            ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
            {
                portal.PortalMouseDown(e);
                return true;
            });
            if (!e.CancelBubbling)
            {
                var prevMouseDownElement = this.currentMouseDown;
                e.CurrentContextElement = this.currentMouseDown = null; //clear
                ForEachEventListenerBubbleUp(e, hitChain, () =>
                {
                    //TODO: check accept keyboard
                    this.currentMouseDown = e.CurrentContextElement;
                    e.CurrentContextElement.ListenMouseDown(e);
                    if (prevMouseDownElement != null &&
                        prevMouseDownElement != currentMouseDown)
                    {
                        prevMouseDownElement.ListenLostMouseFocus(e);
                    }

                    return e.CancelBubbling;
                });
            }
            //----------------------------------
            //save mousedown hitchain
            this._latestMouseDownChain = hitChain;
        }
Beispiel #16
0
        public static void UnsafeSetContentRuns(CssBox box, List<CssRun> runs, bool isAllWhitespace)
        {
            box._aa_contentRuns = runs;
            if (isAllWhitespace)
            {
                box._boxCompactFlags |= BoxFlags.TEXT_IS_ALL_WHITESPACE;
            }
            else
            {
                box._boxCompactFlags &= ~BoxFlags.TEXT_IS_ALL_WHITESPACE;
            }

            //**
            box._boxCompactFlags &= ~BoxFlags.LAY_RUNSIZE_MEASURE;
        }
Beispiel #17
0
 //---------------------------------------------------------------------------------------
 public static void AddRunList(CssBox toBox,
     BoxSpec spec,
     List<CssRun> runlist,
     char[] buffer,
     bool isAllWhitespace)
 {
     CssBox.UnsafeSetTextBuffer(toBox, buffer);
     if (runlist != null)
     {
         for (int i = runlist.Count - 1; i >= 0; --i)
         {
             runlist[i].SetOwner(toBox);
         }
     }
     CssBox.UnsafeSetContentRuns(toBox, runlist, isAllWhitespace);
 }
 internal override CssBox GetPrincipalBox(CssBox parentCssBox, HtmlHost host)
 {
     if (this.CurrentPrincipalBox != null)
     {
         return this.CurrentPrincipalBox;
     }
     else
     {
         RenderElement re;
         object controller;
         lazyCreator((RootGraphic)parentCssBox.RootGfx, out re, out controller);
         CssBox wrapper = CustomCssBoxGenerator.CreateWrapper(controller, re, this.Spec, false);
         this.SetPrincipalBox(wrapper);
         return wrapper;
     }
 }
Beispiel #19
0
 public static CssBoxSvgRoot CreateSvgBox(CssBox parentBox,
     HtmlElement elementNode,
     Css.BoxSpec spec)
 {
     SvgFragment fragment = new SvgFragment();
     SvgRootEventPortal svgRootController = new SvgRootEventPortal(elementNode);
     CssBoxSvgRoot svgRoot = new CssBoxSvgRoot(
         elementNode.Spec,
         parentBox.RootGfx,
         fragment);
     svgRoot.SetController(svgRootController);
     svgRootController.SvgRoot = svgRoot;
     parentBox.AppendChild(svgRoot);
     CreateSvgBoxContent(fragment, elementNode);
     return svgRoot;
 }
Beispiel #20
0
        public override void CustomRecomputedValue(CssBox containingBlock)
        {
            var svgElement = this.SvgSpec;
            //recompute value if need  
            var cnode = svgElement.GetFirstNode();
            ReEvaluateArgs reEvalArgs = new ReEvaluateArgs(
                containingBlock.VisualWidth,
                100,
                containingBlock.GetEmHeight());
            while (cnode != null)
            {
                cnode.Value.ReEvaluateComputeValue(ref reEvalArgs);
                cnode = cnode.Next;
            }

            this.SetVisualSize(500, 500);
        }
 public void PushContainingBlock(CssBox box)
 {
     if (latestFloatingContext == null)
     {
         latestFloatingContext = new FloatingContext(box);
         totalContext.Add(latestFloatingContext);
     }
     else
     {
         if (box.Float != Css.CssFloat.None)
         {
             latestFloatingContext = new FloatingContext(box);
             totalContext.Add(latestFloatingContext);
         }
     }
     floatingContexts.Add(latestFloatingContext);
 }
        /// <summary>
        /// Draw the background image of the given box in the given rectangle.<br/>
        /// Handle background-repeat and background-position values.
        /// </summary>
        /// <param name="g">the device to draw into</param>
        /// <param name="box">the box to draw its background image</param>
        /// <param name="imageLoadHandler">the handler that loads image to draw</param>
        /// <param name="rectangle">the rectangle to draw image in</param>
        public static void DrawBackgroundImage(Canvas g, CssBox box, ImageBinder imageBinder, RectangleF rectangle)
        {
            var image = imageBinder.Image;
            //temporary comment image scale code 
            var imgSize = image.Size;
            //new Size(imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width,
            //                 imageLoadHandler.Rectangle == Rectangle.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height);

            // get the location by BackgroundPosition value
            var location = GetLocation(box.BackgroundPositionX, box.BackgroundPositionY, rectangle, imgSize);
            //var srcRect = imageLoadHandler.Rectangle == Rectangle.Empty
            //                  ? new Rectangle(0, 0, imgSize.Width, imgSize.Height)
            //                  : new Rectangle(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height);
            var srcRect = new Rectangle(0, 0, image.Width, image.Height);
            // initial image destination rectangle
            var destRect = new Rectangle(location, imgSize);
            // need to clip so repeated image will be cut on rectangle

            var prevClip = g.CurrentClipRect;
            PixelFarm.Drawing.Rectangle copyRect = new PixelFarm.Drawing.Rectangle(
               (int)rectangle.X,
               (int)rectangle.Y,
               (int)rectangle.Width,
               (int)rectangle.Height);
            copyRect.Intersect(prevClip);
            g.SetClipRect(copyRect);
            switch (box.BackgroundRepeat)
            {
                case CssBackgroundRepeat.NoRepeat:
                    g.DrawImage(image, new RectangleF(location, imgSize), new RectangleF(0, 0, image.Width, image.Height));
                    break;
                case CssBackgroundRepeat.RepeatX:
                    DrawRepeatX(g, image, rectangle, srcRect, destRect, imgSize);
                    break;
                case CssBackgroundRepeat.RepeatY:
                    DrawRepeatY(g, image, rectangle, srcRect, destRect, imgSize);
                    break;
                default:
                    DrawRepeat(g, image, rectangle, srcRect, destRect, imgSize);
                    break;
            }

            g.SetClipRect(prevClip);
        }
Beispiel #23
0
        public override LayoutFarm.HtmlBoxes.CssBox CreateCssBox(
            DomElement domE,
            LayoutFarm.HtmlBoxes.CssBox parentBox,
            BoxSpec spec,
            HtmlHost host)
        {
            switch (domE.Name)
            {
            case "input":
            {
                var inputBox = CreateInputBox(domE, parentBox, spec, myHost.RootGfx, host);
                if (inputBox != null)
                {
                    return(inputBox);
                }
            }
            break;

            case "canvas":
            {
                //test only
                //TODO: review here
                var canvas     = new LayoutFarm.CustomWidgets.MiniAggCanvasBox(400, 400);
                var wrapperBox = CreateWrapper(
                    canvas,
                    canvas.GetPrimaryRenderElement(myHost.RootGfx),
                    spec, true);
                parentBox.AppendChild(wrapperBox);
                return(wrapperBox);
            }
            }

            //default unknown
            var simpleBox = new LayoutFarm.CustomWidgets.Box(100, 20);

            simpleBox.BackColor = PixelFarm.Drawing.Color.LightGray;
            var wrapperBox2 = CreateWrapper(
                simpleBox,
                simpleBox.GetPrimaryRenderElement(myHost.RootGfx),
                spec, false);

            parentBox.AppendChild(wrapperBox2);
            return(wrapperBox2);
        }
        static void GetBorderBorderDrawingInfo(CssBox box,
            CssSide borderSide,
            out CssBorderStyle borderStyle,
            out Color borderColor,
            out float actualBorderWidth)
        {
            switch (borderSide)
            {
                case CssSide.Top:

                    actualBorderWidth = box.ActualBorderTopWidth;
                    borderStyle = box.BorderTopStyle;
                    borderColor = (borderStyle == CssBorderStyle.Inset) ?
                                    Darken(box.BorderTopColor) :
                                    box.BorderTopColor;
                    break;
                case CssSide.Left:
                    actualBorderWidth = box.ActualBorderLeftWidth;
                    borderStyle = box.BorderLeftStyle;
                    borderColor = (borderStyle == CssBorderStyle.Inset) ?
                                    Darken(box.BorderLeftColor) :
                                    box.BorderLeftColor;
                    break;
                case CssSide.Right:
                    actualBorderWidth = box.ActualBorderRightWidth;
                    borderStyle = box.BorderRightStyle;
                    borderColor = (borderStyle == CssBorderStyle.Outset) ?
                                    Darken(box.BorderRightColor) :
                                    box.BorderRightColor;
                    break;
                case CssSide.Bottom:
                    actualBorderWidth = box.ActualBorderBottomWidth;
                    borderStyle = box.BorderBottomStyle;
                    borderColor = (borderStyle == CssBorderStyle.Outset) ?
                                    Darken(box.BorderBottomColor) :
                                    box.BorderBottomColor;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("border");
            }
        }
        public static CssBox CreateTableCell(CssBox parent, HtmlElement childElement, bool fixDisplayType)
        {
            CssBox tableCell = null;
            if (fixDisplayType)
            {
                tableCell = new CssBox(childElement.Spec, parent.RootGfx, CssDisplay.TableCell);
            }
            else
            {
                tableCell = new CssBox(childElement.Spec, parent.RootGfx);
            }
            tableCell.SetController(childElement);
            parent.AppendChild(tableCell);
            //----------------------------------------------------------------------------------------------


            //----------------------------------------------------------------------------------------------
            //get rowspan and colspan here 
            int nRowSpan = 1;
            int nColSpan = 1;
            string rowspan;
            if (childElement.TryGetAttribute(WellknownName.RowSpan, out rowspan))
            {
                if (!int.TryParse(rowspan, out nRowSpan))
                {
                    nRowSpan = 1;
                }
            }
            string colspan;
            if (childElement.TryGetAttribute(WellknownName.ColSpan, out colspan))
            {
                if (!int.TryParse(colspan, out nColSpan))
                {
                    nColSpan = 1;
                }
            }
            //---------------------------------------------------------- 
            tableCell.SetRowSpanAndColSpan(nRowSpan, nColSpan);
            return tableCell;
        }
Beispiel #26
0
 internal void PopContainingBlock()
 {
     switch (this.containgBlockStack.Count)
     {
         case 0:
             {
             }
             break;
         case 1:
             {
                 //last on
                 var box = this.containgBlockStack.Pop();
                 OnPopContainingBlock();
                 if (this.latestContainingBlock != box)
                 {
                     this.globalXOffset -= box.LocalX;
                     this.globalYOffset -= box.LocalY;
                     OnPopDifferentContaingBlock(box);
                 }
                 this.latestContainingBlock = null;
             }
             break;
         default:
             {
                 var box = this.containgBlockStack.Pop();
                 OnPopContainingBlock();
                 if (this.latestContainingBlock != box)
                 {
                     this.globalXOffset -= box.LocalX;
                     this.globalYOffset -= box.LocalY;
                     OnPopDifferentContaingBlock(box);
                 }
                 this.latestContainingBlock = containgBlockStack.Peek();
             }
             break;
     }
 }
Beispiel #27
0
        protected override void OnElementChanged()
        {
            CssBox box = this.principalBox;
            if (box is CssScrollView)
            {
                return;
            }
            //change 
            var boxSpec = CssBox.UnsafeGetBoxSpec(box);
            //create scrollbar


            var scrollView = new CssScrollView(boxSpec, box.RootGfx);
            scrollView.SetController(this);
            scrollView.SetVisualSize(box.VisualWidth, box.VisualHeight);
            scrollView.SetExpectedSize(box.VisualWidth, box.VisualHeight);
            box.ParentBox.InsertChild(box, scrollView);
            box.ParentBox.RemoveChild(box);
            //scrollbar width= 10
            scrollView.SetInnerBox(box);
            //change primary render element
            this.principalBox = scrollView;
            scrollView.InvalidateGraphics();
        }
        /// <summary>
        /// Draw specific border (top/bottom/left/right) with the box data (style/width/rounded).<br/>
        /// </summary>
        /// <param name="borderSide">desired border to draw</param>
        /// <param name="box">the box to draw its borders, contain the borders data</param>
        /// <param name="g">the device to draw into</param>
        /// <param name="rect">the rectangle the border is enclosing</param>
        /// <param name="isLineStart">Specifies if the border is for a starting line (no bevel on left)</param>
        /// <param name="isLineEnd">Specifies if the border is for an ending line (no bevel on right)</param>
        static void DrawBorder(CssSide borderSide, CssBox box,
                               PaintVisitor p, RectangleF rect, bool isLineStart, bool isLineEnd)
        {
            float          actualBorderWidth;
            Color          borderColor;
            CssBorderStyle style;

            GetBorderBorderDrawingInfo(box, borderSide, out style, out borderColor, out actualBorderWidth);
            DrawBoard g = p.InnerCanvas;

            if (box.HasSomeRoundCorner)
            {
                GraphicsPath borderPath = GetRoundedBorderPath(p, borderSide, box, rect);
                if (borderPath != null)
                {
                    // rounded border need special path
                    var smooth = g.SmoothingMode;
                    if (!p.AvoidGeometryAntialias && box.HasSomeRoundCorner)
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                    }


                    p.DrawPath(borderPath, borderColor, actualBorderWidth);
                    //using (var pen = GetPen(p.Platform, style, borderColor, actualBorderWidth))
                    //using (borderPath)
                    //{
                    //    g.DrawPath(pen, borderPath);
                    //}
                    g.SmoothingMode = smooth;
                }
            }
            else
            {
                // non rounded border
                switch (style)
                {
                case CssBorderStyle.Inset:
                case CssBorderStyle.Outset:
                {
                    // inset/outset border needs special rectangle
                    PointF[] borderPnts = new PointF[4];
                    SetInOutsetRectanglePoints(borderSide, box, rect, isLineStart, isLineEnd, borderPnts);
                    g.FillPolygon(borderColor, borderPnts);
                }
                break;

                default:
                {
                    // solid/dotted/dashed border draw as simple line


                    //using (var pen = GetPen(p.Platform, style, borderColor, actualBorderWidth))
                    //{
                    var prevColor = g.StrokeColor;
                    g.StrokeColor = borderColor;
                    float prevStrokeW = g.StrokeWidth;
                    g.StrokeWidth = actualBorderWidth;
                    switch (borderSide)
                    {
                    case CssSide.Top:
                        g.DrawLine((float)Math.Ceiling(rect.Left), rect.Top + box.ActualBorderTopWidth / 2, rect.Right - 1, rect.Top + box.ActualBorderTopWidth / 2);
                        break;

                    case CssSide.Left:
                        g.DrawLine(rect.Left + box.ActualBorderLeftWidth / 2, (float)Math.Ceiling(rect.Top), rect.Left + box.ActualBorderLeftWidth / 2, (float)Math.Floor(rect.Bottom));
                        break;

                    case CssSide.Bottom:
                        g.DrawLine((float)Math.Ceiling(rect.Left), rect.Bottom - box.ActualBorderBottomWidth / 2, rect.Right - 1, rect.Bottom - box.ActualBorderBottomWidth / 2);
                        break;

                    case CssSide.Right:
                        g.DrawLine(rect.Right - box.ActualBorderRightWidth / 2, (float)Math.Ceiling(rect.Top), rect.Right - box.ActualBorderRightWidth / 2, (float)Math.Floor(rect.Bottom));
                        break;
                    }

                    g.StrokeWidth = prevStrokeW;
                    g.StrokeColor = prevColor;
                }
                break;
                }
            }
        }
Beispiel #29
0
        internal void CloseLine(LayoutVisitor lay)
        {
#if DEBUG
            this.dbugIsClosed = true;
#endif

            //=============================================================
            //part 1: MakeStrips()
            //=============================================================
            //***
            List <CssRun>          myruns    = this._runs;
            CssBox                 lineOwner = this._ownerBox;
            List <PartialBoxStrip> tmpStrips = lay.GetReadyStripList();
            //---------------------------------------------------------------------------
            //first level
            Dictionary <CssBox, PartialBoxStrip> unqiueStrips = lay.GetReadyStripDic();
            //location of run and strip related to its containng block
            float maxRight  = 0;
            float maxBottom = 0;
            int   j         = myruns.Count;

            float firstRunStartAt = 0;
            for (int i = 0; i < j; ++i)
            {
                CssRun run = myruns[i];
                if (i == 0)
                {
                    firstRunStartAt = run.Left;
                }
                maxRight  = run.Right > maxRight ? run.Right : maxRight;
                maxBottom = run.Bottom > maxBottom ? run.Bottom : maxBottom;
                if (run.IsSpaces)
                {
                    //strip size include whitespace ?
                    continue;
                }
                //-------------
                //first level data
                RegisterStripPart(run.OwnerBox, run.Left, run.Top, run.Right, run.Bottom, tmpStrips, unqiueStrips);
            }

            //---------------------------------------------------------------------------
            //other step to upper layer, until no new strip
            int newStripIndex = 0;
            for (int numNewStripCreate = tmpStrips.Count; numNewStripCreate > 0; newStripIndex += numNewStripCreate)
            {
                numNewStripCreate = StepUpRegisterStrips(unqiueStrips, lineOwner, tmpStrips, newStripIndex);
            }

            this._bottomUpBoxStrips = tmpStrips.ToArray();

            lay.ReleaseStripList(tmpStrips);
            lay.ReleaseStripDic(unqiueStrips);
            //=============================================================
            //part 2: Calculate
            //=============================================================

            this.CacheLineHeight         = maxBottom;
            this.CachedLineContentWidth  = maxRight;
            this.CachedExactContentWidth = (maxRight - firstRunStartAt);

            if (lineOwner.VisualWidth < CachedLineContentWidth)
            {
                this.CachedLineContentWidth = this.OwnerBox.VisualWidth;
            }
        }
Beispiel #30
0
        internal void PaintRuns(PaintVisitor p)
        {
            //iterate from each words
            CssBox latestOwner = null;
            var    innerCanvas = p.InnerCanvas;

            var enterFont  = innerCanvas.CurrentFont;
            var enterColor = innerCanvas.CurrentTextColor;

            var tmpRuns = this._runs;
            int j       = tmpRuns.Count;

            for (int i = 0; i < j; ++i)
            {
                //-----------------
#if DEBUG
                dbugCounter.dbugRunPaintCount++;
#endif
                //-----------------

                CssRun w = tmpRuns[i];
                switch (w.Kind)
                {
                case CssRunKind.SolidContent:
                {
                    w.OwnerBox.Paint(p, new RectangleF(w.Left, w.Top, w.Width, w.Height));
                } break;

                case CssRunKind.BlockRun:
                {
                    //Console.WriteLine("blockrun");
                    CssBlockRun blockRun = (CssBlockRun)w;

                    int ox = p.CanvasOriginX;
                    int oy = p.CanvasOriginY;

                    p.SetCanvasOrigin(ox + (int)blockRun.Left, oy + (int)blockRun.Top);

                    blockRun.ContentBox.Paint(p);

                    p.SetCanvasOrigin(ox, oy);
                } break;

                case CssRunKind.Text:
                {
                    if (latestOwner != w.OwnerBox)
                    {
                        //change
                        latestOwner = w.OwnerBox;
                        //change font when change owner
                        p.InnerCanvas.CurrentFont      = latestOwner.ActualFont;
                        p.InnerCanvas.CurrentTextColor = latestOwner.ActualColor;
                    }

                    CssTextRun textRun   = (CssTextRun)w;
                    var        wordPoint = new PointF(w.Left, w.Top);
                    p.DrawText(CssBox.UnsafeGetTextBuffer(w.OwnerBox),
                               textRun.TextStartIndex,
                               textRun.TextLength, wordPoint,
                               new SizeF(w.Width, w.Height));
                } break;

                default:
                {
#if DEBUG
                    // w.OwnerBox.dbugPaintTextWordArea(g, offset, w);
#endif
                } break;
                }
            }

            //---
            //exit
            if (j > 0)
            {
                innerCanvas.CurrentFont      = enterFont;
                innerCanvas.CurrentTextColor = enterColor;
            }
        }
Beispiel #31
0
 //-------------------------------------------------------
 internal static LinkedListNode <CssBox> UnsafeGetLinkedNode(CssBox box)
 {
     return(box._linkedNode);
 }
Beispiel #32
0
 internal static List <CssRun> UnsafeGetRunList(CssBox box)
 {
     return(box._aa_contentRuns);
 }
Beispiel #33
0
 public static BoxSpec UnsafeGetBoxSpec(CssBox box)
 {
     //this method is for BoxCreator and debug only!
     //box.Spec is private
     return(box._myspec);
 }
Beispiel #34
0
 public static object UnsafeGetController(CssBox box)
 {
     return(box._controller);
 }
 public void KeyPress(UIKeyEventArgs e, CssBox startAt)
 {
     //send focus to current input element
 }
 public void MouseWheel(UIMouseEventArgs e, CssBox startAt)
 {
 }
Beispiel #37
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;
        }
Beispiel #38
0
 CssBox CreateCustomCssBox(CssBox parent,
   LayoutFarm.WebDom.DomElement tag,
   LayoutFarm.Css.BoxSpec boxspec)
 {
     for (int i = generators.Count - 1; i >= 0; --i)
     {
         var newbox = generators[i].CreateCssBox(tag, parent, boxspec, this);
         if (newbox != null)
         {
             return newbox;
         }
     }
     return null;
 }
Beispiel #39
0
        void SetupEndHitPoint(CssBoxHitChain startChain, CssBoxHitChain endChain, ITextService textService)
        {
            //find global location of end point
            HitInfo    endHit         = endChain.GetLastHit();
            int        xposOnEndLine  = 0;
            CssLineBox endline        = null;
            int        run_sel_offset = 0;

            //find endline first
            _endHitRunCharIndex = 0;
            _endHitRun          = null;
            switch (endHit.hitObjectKind)
            {
            default:
            {
                throw new NotSupportedException();
            }

            case HitObjectKind.Run:
            {
                CssRun endRun = (CssRun)endHit.hitObject;
                //if (endRun.Text != null && endRun.Text.Contains("Jose"))
                //{
                //}

                int run_sel_index;
                endRun.FindSelectionPoint(textService,
                                          endHit.localX,
                                          out run_sel_index,
                                          out run_sel_offset);
                endline             = endRun.HostLine;
                xposOnEndLine       = (int)(endRun.Left + run_sel_offset);
                _endHitRunCharIndex = run_sel_index;
                _endHitRun          = endRun;
            }
            break;

            case HitObjectKind.LineBox:
            {
                endline       = (CssLineBox)endHit.hitObject;
                xposOnEndLine = endHit.localX;
            }
            break;

            case HitObjectKind.CssBox:
            {
                CssBox hitBox = (CssBox)endHit.hitObject;
                endline       = FindNearestLine(hitBox, endChain.RootGlobalY, 5);
                xposOnEndLine = endHit.localX;
            }
            break;
            }

#if DEBUG
            if (xposOnEndLine == 0)
            {
            }
#endif

            //----------------------------------
            _selectedLines = new List <CssLineBox>();
            if (_startHitHostLine == endline)
            {
                _selectedLines.Add(endline);
                _startHitHostLine.Select(_startLineBeginSelectionAtPixel, xposOnEndLine,
                                         _startHitRun, _startHitRunCharIndex,
                                         _endHitRun, _endHitRunCharIndex);
                return; //early exit here ***
            }
            //----------------------------------
            //select on different line
            LineWalkVisitor lineWalkVisitor = null;
            int             breakAtLevel;
            if (FindCommonGround(startChain, endChain, out breakAtLevel) && breakAtLevel > 0)
            {
                object      hit1        = endChain.GetHitInfo(breakAtLevel).hitObject;
                CssBlockRun hitBlockRun = hit1 as CssBlockRun;
                //multiple select
                //1. first part
                if (hitBlockRun != null)
                {
                    _startHitHostLine.Select(_startLineBeginSelectionAtPixel, (int)hitBlockRun.Left,
                                             _startHitRun, _startHitRunCharIndex,
                                             _endHitRun, _endHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(hitBlockRun);
                }
                else
                {
                    _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                    _selectedLines.Add(_startHitHostLine);
                    lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
                }
            }
            else
            {
                _startHitHostLine.SelectPartialToEnd(_startLineBeginSelectionAtPixel, _startHitRun, _startHitRunCharIndex);
                _selectedLines.Add(_startHitHostLine);
                lineWalkVisitor = new LineWalkVisitor(_startHitHostLine);
            }

            lineWalkVisitor.SetWalkTargetPosition(endChain.RootGlobalX, endChain.RootGlobalY);
            lineWalkVisitor.Walk(endline, (lineCoverage, linebox, partialLineRun) =>
            {
                switch (lineCoverage)
                {
                case LineCoverage.EndLine:
                    {
                        //found end line
                        linebox.SelectPartialFromStart(xposOnEndLine, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.PartialLine:
                    {
                        linebox.SelectPartialFromStart((int)partialLineRun.Right, _endHitRun, _endHitRunCharIndex);
                        _selectedLines.Add(linebox);
                    }
                    break;

                case LineCoverage.FullLine:
                    {
                        //check if hitpoint is in the line area
                        linebox.SelectFull();
                        _selectedLines.Add(linebox);
                    }
                    break;
                }
            });
        }
Beispiel #40
0
 internal void PaintBorder(CssBox box, CssSide border, Color solidColor, RectangleF rect)
 {
     PointF[] borderPoints = new PointF[4];
     BorderPaintHelper.DrawBorder(solidColor, border, borderPoints, this.canvas, box, rect);
 }
Beispiel #41
0
 public static void UnsafeSetTextBuffer(CssBox box, char[] textBuffer)
 {
     //TODO: change to unsafe static
     box._buffer = textBuffer;
 }
 public bool ProcessDialogKey(UIKeyEventArgs e, CssBox startAt)
 {
     //send focus to current input element
     return(false);
 }
Beispiel #43
0
 public static void UnsafeSetParent(CssBox box, CssBox parent)
 {
     box._parentBox = parent;
 }
 public void KeyUp(UIKeyEventArgs e, CssBox startAt)
 {
 }
Beispiel #45
0
 internal static CssBoxCollection UnsafeGetChildren(CssBox box)
 {
     return(box._aa_boxes);
 }
 public static void SetAsBrBox(CssBox box)
 {
     box._boxCompactFlags |= BoxFlags.IS_BR_ELEM;
 }
Beispiel #47
0
 internal static void UnsafeSetNodes(CssBox childNode, CssBox parent, LinkedListNode <CssBox> linkNode)
 {
     childNode._parentBox  = parent;
     childNode._linkedNode = linkNode;
 }
 protected static void SetAsCustomCssBox(CssBox box)
 {
     box._boxCompactFlags |= BoxFlags.IS_CUSTOM_CSSBOX;
 }
Beispiel #49
0
 internal static char[] UnsafeGetTextBuffer(CssBox box)
 {
     return(box._buffer);
 }
Beispiel #50
0
 //-----------------------------------------------------
 internal void AddToLatePaintList(CssBox box)
 {
     this.latePaintStack.AddLayerItem(box);
 }
        /// <summary>
        /// Gets the index of the box to be used on a (ordered) list
        /// </summary>
        /// <returns></returns>
        static int GetIndexForList(CssBox box, HtmlElement childElement)
        {
            HtmlElement parentNode = childElement.ParentNode as HtmlElement;
            int index = 1;
            string reversedAttrValue;
            bool reversed = false;
            if (parentNode.TryGetAttribute(WellknownName.Reversed, out reversedAttrValue))
            {
                reversed = true;
            }
            string startAttrValue;
            if (!parentNode.TryGetAttribute(WellknownName.Start, out startAttrValue))
            {
                //if not found
                //TODO: not to loop count ?

                if (reversed)
                {
                    index = 0;
                    foreach (CssBox b in box.ParentBox.GetChildBoxIter())
                    {
                        if (b.CssDisplay == CssDisplay.ListItem)
                        {
                            index++;
                        }
                    }
                }
                else
                {
                    index = 1;
                }
            }
            foreach (CssBox b in box.ParentBox.GetChildBoxIter())
            {
                if (b == box)
                    return index;
                if (b.CssDisplay == CssDisplay.ListItem)
                    index += reversed ? -1 : 1;
            }
            return index;
        }
Beispiel #52
0
 internal void PaintBorders(CssBox box, RectangleF stripArea, bool isFirstLine, bool isLastLine)
 {
     LayoutFarm.HtmlBoxes.BorderPaintHelper.DrawBoxBorders(this, box, stripArea, isFirstLine, isLastLine);
 }
        /// <summary>
        /// Makes a border path for rounded borders.<br/>
        /// To support rounded dotted/dashed borders we need to use arc in the border path.<br/>
        /// Return null if the border is not rounded.<br/>
        /// </summary>
        /// <param name="border">Desired border</param>
        /// <param name="b">Box which the border corresponds</param>
        /// <param name="r">the rectangle the border is enclosing</param>
        /// <returns>Beveled border path, null if there is no rounded corners</returns>
        static GraphicsPath GetRoundedBorderPath(PaintVisitor p, CssSide border, CssBox b, RectangleF r)
        {
            GraphicsPath path = null;

            switch (border)
            {
            case CssSide.Top:
                if (b.ActualCornerNW > 0 || b.ActualCornerNE > 0)
                {
                    path = new GraphicsPath();
                    if (b.ActualCornerNW > 0)
                    {
                        path.AddArc(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNW * 2, b.ActualCornerNW * 2, 180f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2, r.Left + b.ActualBorderLeftWidth, r.Top + b.ActualBorderTopWidth / 2);
                    }
                    if (b.ActualCornerNE > 0)
                    {
                        path.AddArc(r.Right - b.ActualCornerNE * 2 - b.ActualBorderRightWidth / 2, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNE * 2, b.ActualCornerNE * 2, 270f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Right - b.ActualCornerNE * 2 - b.ActualBorderRightWidth, r.Top + b.ActualBorderTopWidth / 2, r.Right - b.ActualBorderRightWidth / 2, r.Top + b.ActualBorderTopWidth / 2);
                    }
                }
                break;

            case CssSide.Bottom:
                if (b.ActualCornerSW > 0 || b.ActualCornerSE > 0)
                {
                    path = new GraphicsPath();
                    if (b.ActualCornerSE > 0)
                    {
                        path.AddArc(r.Right - b.ActualCornerNE * 2 - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualCornerSE * 2 - b.ActualBorderBottomWidth / 2, b.ActualCornerSE * 2, b.ActualCornerSE * 2, 0f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2, r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2 - .1f);
                    }
                    if (b.ActualCornerSW > 0)
                    {
                        path.AddArc(r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualCornerSW * 2 - b.ActualBorderBottomWidth / 2, b.ActualCornerSW * 2, b.ActualCornerSW * 2, 90f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Left + b.ActualBorderLeftWidth / 2 + .1f, r.Bottom - b.ActualBorderBottomWidth / 2, r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2);
                    }
                }
                break;

            case CssSide.Right:
                if (b.ActualCornerNE > 0 || b.ActualCornerSE > 0)
                {
                    path = new GraphicsPath();
                    if (b.ActualCornerNE > 0 && b.BorderTopStyle >= CssBorderStyle.Visible)
                    {
                        path.AddArc(r.Right - b.ActualCornerNE * 2 - b.ActualBorderRightWidth / 2, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNE * 2, b.ActualCornerNE * 2, 270f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Right - b.ActualBorderRightWidth / 2, r.Top + b.ActualCornerNE + b.ActualBorderTopWidth / 2, r.Right - b.ActualBorderRightWidth / 2, r.Top + b.ActualCornerNE + b.ActualBorderTopWidth / 2 + .1f);
                    }

                    if (b.ActualCornerSE > 0 &&
                        b.BorderBottomStyle >= CssBorderStyle.Visible)
                    {
                        path.AddArc(r.Right - b.ActualCornerSE * 2 - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualCornerSE * 2 - b.ActualBorderBottomWidth / 2, b.ActualCornerSE * 2, b.ActualCornerSE * 2, 0f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualCornerSE - b.ActualBorderBottomWidth / 2 - .1f, r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualCornerSE - b.ActualBorderBottomWidth / 2);
                    }
                }
                break;

            case CssSide.Left:
                if (b.ActualCornerNW > 0 || b.ActualCornerSW > 0)
                {
                    path = new GraphicsPath();
                    if (b.ActualCornerSW > 0 && b.BorderTopStyle >= CssBorderStyle.Visible)    //(b.BorderTopStyle == CssConstants.None || b.BorderTopStyle == CssConstants.Hidden))
                    {
                        path.AddArc(r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualCornerSW * 2 - b.ActualBorderBottomWidth / 2, b.ActualCornerSW * 2, b.ActualCornerSW * 2, 90f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualCornerSW - b.ActualBorderBottomWidth / 2, r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualCornerSW - b.ActualBorderBottomWidth / 2 - .1f);
                    }

                    if (b.ActualCornerNW > 0 &&
                        b.BorderBottomStyle >= CssBorderStyle.Visible)
                    {
                        path.AddArc(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNW * 2, b.ActualCornerNW * 2, 180f, 90f);
                    }
                    else
                    {
                        path.AddLine(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualCornerNW + b.ActualBorderTopWidth / 2 + .1f, r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualCornerNW + b.ActualBorderTopWidth / 2);
                    }
                }
                break;
            }

            return(path);
        }
Beispiel #54
0
            static IEnumerable <CssLineBox> GetLineWalkDownIter(LineWalkVisitor visitor, CssBox box)
            {
                //recursive
                float y = visitor._globalY;

                if (box.LineBoxCount > 0)
                {
                    foreach (CssLineBox linebox in box.GetLineBoxIter())
                    {
                        visitor._globalY = y + linebox.CachedLineTop;
                        yield return(linebox);
                    }
                }
                else
                {
                    //element based
                    foreach (CssBox childbox in box.GetChildBoxIter())
                    {
                        visitor._globalY = y + childbox.LocalY;
                        //recursive
                        foreach (var linebox in GetLineWalkDownIter(visitor, childbox))
                        {
                            yield return(linebox);
                        }
                    }
                }

                visitor._globalY = y;
            }
Beispiel #55
0
        LayoutFarm.HtmlBoxes.CssBox CreateInputBox(DomElement domE,
                                                   LayoutFarm.HtmlBoxes.CssBox parentBox,
                                                   BoxSpec spec,
                                                   LayoutFarm.RootGraphic rootgfx, HtmlHost host)
        {
            var typeAttr = domE.FindAttribute("type");

            if (typeAttr != null)
            {
                switch (typeAttr.Value)
                {
                case "text":
                {
                    // user can specific width of textbox
                    //var textbox = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    var textbox    = new LayoutFarm.CustomWidgets.TextBoxContainer(100, 20, false);
                    var wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    //place holder support
                    var placeHolderAttr = domE.FindAttribute("placeholder");
                    if (placeHolderAttr != null)
                    {
                        textbox.PlaceHolderText = placeHolderAttr.Value;
                    }
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "button":
                {
                    //use subdom? technique
                    //todo: review the technique here
                    var button       = new HtmlWidgets.Button(60, 30);
                    var ihtmlElement = domE as LayoutFarm.WebDom.IHtmlElement;
                    if (ihtmlElement != null)
                    {
                        button.Text = ihtmlElement.innerHTML;
                    }
                    else
                    {
                        button.Text = "";
                    }
                    button.Text = "testButton";
                    DomElement buttonDom    = button.GetPresentationDomNode((HtmlDocument)domE.OwnerDocument);
                    CssBox     buttonCssBox = host.CreateBox2(parentBox, (WebDom.Impl.HtmlElement)buttonDom, true);     // CreateCssBox(buttonDom, parentBox, spec, host);
                    //var ui = button.GetPrimaryUIElement(this.myHost);

                    //var wrapperBox = CreateWrapper(
                    //    button,
                    //    ui.GetPrimaryRenderElement(rootgfx),
                    //    spec, true);
                    //parentBox.AppendChild(wrapperBox);
                    //return wrapperBox;

                    parentBox.AppendChild(buttonCssBox);
                    return(buttonCssBox);
                }

                case "textbox":
                {
                    var    textbox    = new LayoutFarm.CustomWidgets.TextBox(100, 17, false);
                    CssBox wrapperBox = CreateWrapper(
                        textbox,
                        textbox.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }

                case "radio":
                {
                    //tempfix -> just copy the Button code,
                    //TODO: review here, use proper radio button
                    var    box        = new LayoutFarm.CustomWidgets.Box(20, 20);
                    CssBox wrapperBox = CreateWrapper(
                        box,
                        box.GetPrimaryRenderElement(rootgfx),
                        spec, true);
                    parentBox.AppendChild(wrapperBox);
                    return(wrapperBox);
                }
                }
            }
            return(null);
        }
 public static void DrawBorder(CssSide border, PointF[] borderPts, DrawBoard g, CssBox box, Color solidColor, RectangleF rectangle)
 {
     SetInOutsetRectanglePoints(border, box, rectangle, true, true, borderPts);
     g.FillPolygon(solidColor, borderPts);
 }
Beispiel #57
0
 public CssBox CreateBox2(CssBox parentBox, WebDom.Impl.HtmlElement childElement, bool fullmode)
 {
     return CreateBox(parentBox, (HtmlElement)childElement, fullmode);
 }
        public void MouseMove(UIMouseEventArgs e, CssBox startAt)
        {
            if (!_isBinded)
            {
                return;
            }
            if (startAt == null)
            {
                return;
            }
            //-----------------------------------------
            int x = e.X;
            int y = e.Y;

            if (e.IsDragging && _latestMouseDownChain != null)
            {
                //dragging *** , if changed
                if (this._mousedownX != x || this._mousedownY != y)
                {
                    //handle mouse drag
                    CssBoxHitChain hitChain = GetFreeHitChain();
                    hitChain.SetRootGlobalPosition(x, y);
                    BoxHitUtils.HitTest(startAt, x, y, hitChain);
                    SetEventOrigin(e, hitChain);
                    //---------------------------------------------------------
                    //propagate mouse drag
                    ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
                    {
                        portal.PortalMouseMove(e);
                        return(true);
                    });
                    //---------------------------------------------------------
                    if (!e.CancelBubbling)
                    {
                        ClearPreviousSelection();
                        if (_latestMouseDownChain.Count > 0 && hitChain.Count > 0)
                        {
                            if (this._htmlContainer.LayoutVersion != this.lastDomLayoutVersion)
                            {
                                //the dom has been changed so...
                                //need to evaluate hitchain at mousedown position again
                                int lastRootGlobalX = _latestMouseDownChain.RootGlobalX;
                                int lastRootGlobalY = _latestMouseDownChain.RootGlobalY;
                                _latestMouseDownChain.Clear();
                                _latestMouseDownChain.SetRootGlobalPosition(lastRootGlobalX, lastRootGlobalY);
                                BoxHitUtils.HitTest(_mouseDownStartAt, lastRootGlobalX, lastRootGlobalY, _latestMouseDownChain);
                            }

                            //create selection range
                            var newSelectionRange = new SelectionRange(
                                _latestMouseDownChain,
                                hitChain,
                                this.ifonts);
                            if (newSelectionRange.IsValid)
                            {
                                this._htmlContainer.SetSelection(newSelectionRange);
                            }
                            else
                            {
                                this._htmlContainer.SetSelection(null);
                            }
                        }
                        else
                        {
                            this._htmlContainer.SetSelection(null);
                        }

                        ForEachEventListenerBubbleUp(e, hitChain, () =>
                        {
                            e.CurrentContextElement.ListenMouseMove(e);
                            return(true);
                        });
                    }

                    //---------------------------------------------------------
                    ReleaseHitChain(hitChain);
                }
            }
            else
            {
                //mouse move
                //---------------------------------------------------------
                CssBoxHitChain hitChain = GetFreeHitChain();
                hitChain.SetRootGlobalPosition(x, y);
                BoxHitUtils.HitTest(startAt, x, y, hitChain);
                SetEventOrigin(e, hitChain);
                //---------------------------------------------------------

                ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
                {
                    portal.PortalMouseMove(e);
                    return(true);
                });
                //---------------------------------------------------------
                if (!e.CancelBubbling)
                {
                    ForEachEventListenerBubbleUp(e, hitChain, () =>
                    {
                        e.CurrentContextElement.ListenMouseMove(e);
                        return(true);
                    });
                }
                ReleaseHitChain(hitChain);
            }
        }
Beispiel #59
0
        CssBox CreateImageBox(CssBox parent, HtmlElement childElement)
        {
            string imgsrc;
            ImageBinder imgBinder = null;
            if (childElement.TryGetAttribute(WellknownName.Src, out imgsrc))
            {
                var clientImageBinder = new ClientImageBinder(imgsrc);
                imgBinder = clientImageBinder;
                clientImageBinder.SetOwner(childElement);
            }
            else
            {
                var clientImageBinder = new ClientImageBinder(null);
                imgBinder = clientImageBinder;
                clientImageBinder.SetOwner(childElement);
            }

            CssBoxImage boxImage = new CssBoxImage(childElement.Spec, parent.RootGfx, imgBinder);
            boxImage.SetController(childElement);
            parent.AppendChild(boxImage);
            return boxImage;
        }
        public void MouseUp(UIMouseEventArgs e, CssBox startAt)
        {
            if (!_isBinded)
            {
                return;
            }
            if (startAt == null)
            {
                return;
            }
            //----------------------------------------------------

            DateTime snapMouseUpTime   = DateTime.Now;
            TimeSpan timediff          = snapMouseUpTime - lastimeMouseUp;
            bool     isAlsoDoubleClick = timediff.Milliseconds < DOUBLE_CLICK_SENSE;

            this.lastimeMouseUp = snapMouseUpTime;
            //-----------------------------------------
            CssBoxHitChain hitChain = GetFreeHitChain();

            hitChain.SetRootGlobalPosition(e.X, e.Y);
            //1. prob hit chain only
            BoxHitUtils.HitTest(startAt, e.X, e.Y, hitChain);
            SetEventOrigin(e, hitChain);
            //2. invoke css event and script event
            ForEachOnlyEventPortalBubbleUp(e, hitChain, (portal) =>
            {
                portal.PortalMouseUp(e);
                return(true);
            });
            if (!e.CancelBubbling)
            {
                ForEachEventListenerBubbleUp(e, hitChain, () =>
                {
                    e.CurrentContextElement.ListenMouseUp(e);
                    return(e.CancelBubbling);
                });
            }

            if (!e.IsCanceled)
            {
                //--------------------
                //click or double click
                //--------------------
                if (isAlsoDoubleClick)
                {
                    ForEachEventListenerBubbleUp(e, hitChain, () =>
                    {
                        e.CurrentContextElement.ListenMouseDoubleClick(e);
                        return(e.CancelBubbling);
                    });
                }
                else
                {
                    ForEachEventListenerBubbleUp(e, hitChain, () =>
                    {
                        e.CurrentContextElement.ListenMouseClick(e);
                        return(e.CancelBubbling);
                    });
                }
            }

            ReleaseHitChain(hitChain);
            if (this._latestMouseDownChain != null)
            {
                this._latestMouseDownChain.Clear();
                //Console.WriteLine(dbugNN++);
                this._latestMouseDownChain = null;
            }
        }