Exemplo n.º 1
0
        protected Rectangle GetClientRectangle(ELEMENT_REGION outerBoundary)
        {
            Rectangle elementBounds = GetClientRectangle();

            try
            {
                if (outerBoundary == ELEMENT_REGION.BORDER)
                {
                    return(new Rectangle(elementBounds.Location, elementBounds.Size));
                }

                int marginTop    = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringMarginTop, HTMLElement, null, true);
                int marginBottom = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringMarginBottom, HTMLElement, null, true);
                int marginLeft   = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringMarginLeft, HTMLElement, null, false);
                int marginRight  = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringMarginRight, HTMLElement, null, false);

                int paddingTop    = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringPaddingTop, HTMLElement, null, true);
                int paddingBottom = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringPaddingBottom, HTMLElement, null, true);
                int paddingLeft   = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringPaddingLeft, HTMLElement, null, false);
                int paddingRight  = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringPaddingRight, HTMLElement, null, false);

                int borderTop    = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringBorderTop, HTMLElement, null, true);
                int borderBottom = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringBorderBottom, HTMLElement, null, true);
                int borderLeft   = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringBorderLeft, HTMLElement, null, false);
                int borderRight  = (int)HTMLElementHelper.CSSUnitStringToPointSize(HTMLElementHelper.CSSUnitStringBorderRight, HTMLElement, null, false);

                int offsetX;
                int offsetY;
                int offsetRight;
                int offsetBottom;
                if (outerBoundary == ELEMENT_REGION.PADDING)
                {
                    offsetX      = borderLeft;
                    offsetY      = borderTop;
                    offsetRight  = -borderRight;
                    offsetBottom = -borderBottom;
                }
                else if (outerBoundary == ELEMENT_REGION.CONTENT)
                {
                    offsetX      = paddingLeft + borderLeft;
                    offsetY      = paddingTop + borderTop;
                    offsetRight  = -paddingRight - borderRight;
                    offsetBottom = -paddingBottom - borderBottom;
                }
                else if (outerBoundary == ELEMENT_REGION.MARGIN)
                {
                    offsetX      = -marginLeft;
                    offsetY      = -marginTop;
                    offsetRight  = marginRight;
                    offsetBottom = marginBottom;
                }
                else
                {
                    throw new ArgumentException("Unnsupported ELEMENT_REGION: " + outerBoundary.ToString());
                }

                Rectangle rect = new Rectangle(elementBounds.Location, elementBounds.Size);
                rect.X      += offsetX;
                rect.Y      += offsetY;
                rect.Width  += offsetRight - offsetX;
                rect.Height += offsetBottom - offsetY;
                return(rect);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Error calculating element paint boundary: " + e.ToString());
                return(new Rectangle(elementBounds.Location, elementBounds.Size));
            }
        }