コード例 #1
0
        // Token: 0x06007033 RID: 28723 RVA: 0x00203B70 File Offset: 0x00201D70
        protected sealed override Size ArrangeOverride(Size arrangeSize)
        {
            Rect empty = Rect.Empty;
            bool flag  = false;
            Size size  = arrangeSize;

            if (!this._suspendLayout)
            {
                TextDpi.SnapToTextDpi(ref size);
                if (this.Document != null)
                {
                    this.EnsureFormatter();
                    if (this._scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(this._scrollData.Viewport, size))
                        {
                            this._scrollData.Viewport = size;
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Extent, this._formatter.DocumentPage.Size))
                        {
                            this._scrollData.Extent = this._formatter.DocumentPage.Size;
                            flag = true;
                            if (Math.Abs(this._scrollData.ExtentWidth - this._scrollData.ViewportWidth) < 1.0)
                            {
                                this._scrollData.ExtentWidth = this._scrollData.ViewportWidth;
                            }
                            if (Math.Abs(this._scrollData.ExtentHeight - this._scrollData.ViewportHeight) < 1.0)
                            {
                                this._scrollData.ExtentHeight = this._scrollData.ViewportHeight;
                            }
                        }
                        Vector vector = new Vector(Math.Max(0.0, Math.Min(this._scrollData.ExtentWidth - this._scrollData.ViewportWidth, this._scrollData.HorizontalOffset)), Math.Max(0.0, Math.Min(this._scrollData.ExtentHeight - this._scrollData.ViewportHeight, this._scrollData.VerticalOffset)));
                        if (!DoubleUtil.AreClose(vector, this._scrollData.Offset))
                        {
                            this._scrollData.Offset = vector;
                            flag = true;
                        }
                        if (flag && this._scrollData.ScrollOwner != null)
                        {
                            this._scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                        empty = new Rect(this._scrollData.HorizontalOffset, this._scrollData.VerticalOffset, size.Width, size.Height);
                    }
                    this._formatter.Arrange(size, empty);
                    if (this._pageVisual != this._formatter.DocumentPage.Visual)
                    {
                        if (this._textView != null)
                        {
                            this._textView.OnPageConnected();
                        }
                        if (this._pageVisual != null)
                        {
                            base.RemoveVisualChild(this._pageVisual);
                        }
                        this._pageVisual = (PageVisual)this._formatter.DocumentPage.Visual;
                        base.AddVisualChild(this._pageVisual);
                    }
                    if (this._scrollData != null)
                    {
                        this._pageVisual.Offset = new Vector(-this._scrollData.HorizontalOffset, -this._scrollData.VerticalOffset);
                    }
                    PtsHelper.UpdateMirroringTransform(base.FlowDirection, FlowDirection.LeftToRight, this._pageVisual, size.Width);
                }
                else
                {
                    if (this._pageVisual != null)
                    {
                        if (this._textView != null)
                        {
                            this._textView.OnPageDisconnected();
                        }
                        base.RemoveVisualChild(this._pageVisual);
                        this._pageVisual = null;
                    }
                    if (this._scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(this._scrollData.Viewport, size))
                        {
                            this._scrollData.Viewport = size;
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Extent, default(Size)))
                        {
                            this._scrollData.Extent = default(Size);
                            flag = true;
                        }
                        if (!DoubleUtil.AreClose(this._scrollData.Offset, default(Vector)))
                        {
                            this._scrollData.Offset = default(Vector);
                            flag = true;
                        }
                        if (flag && this._scrollData.ScrollOwner != null)
                        {
                            this._scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                    }
                }
            }
            return(arrangeSize);
        }
コード例 #2
0
        /// <summary>
        /// Content arrangement.
        /// </summary>
        /// <param name="arrangeSize">Size that element should use to arrange itself and its children.</param>
        protected sealed override Size ArrangeOverride(Size arrangeSize)
        {
            Rect   viewport = Rect.Empty;
            Vector offset;
            bool   invalidateScrollInfo = false;
            Size   safeArrangeSize      = arrangeSize;

            if (!_suspendLayout)
            {
                // Convert to TextDpi and convert back to double, to make sure that we are not
                // getting rounding errors later.
                TextDpi.SnapToTextDpi(ref safeArrangeSize);

                if (Document != null)
                {
                    // Create bottomless formatter, if necessary.
                    EnsureFormatter();

                    // Arrange bottomless content.
                    if (_scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(_scrollData.Viewport, safeArrangeSize))
                        {
                            _scrollData.Viewport = safeArrangeSize;
                            invalidateScrollInfo = true;
                        }

                        if (!DoubleUtil.AreClose(_scrollData.Extent, _formatter.DocumentPage.Size))
                        {
                            _scrollData.Extent   = _formatter.DocumentPage.Size;
                            invalidateScrollInfo = true;
                            // DocumentPage Size is calculated by converting double to int and then back to double.
                            // This conversion may produce rounding errors and force us to show scrollbars in cases
                            // when extent is within 1px from viewport. To workaround this issue, snap extent to viewport
                            // if we are within 1px range.
                            if (Math.Abs(_scrollData.ExtentWidth - _scrollData.ViewportWidth) < 1)
                            {
                                _scrollData.ExtentWidth = _scrollData.ViewportWidth;
                            }
                            if (Math.Abs(_scrollData.ExtentHeight - _scrollData.ViewportHeight) < 1)
                            {
                                _scrollData.ExtentHeight = _scrollData.ViewportHeight;
                            }
                        }
                        offset = new Vector(
                            Math.Max(0, Math.Min(_scrollData.ExtentWidth - _scrollData.ViewportWidth, _scrollData.HorizontalOffset)),
                            Math.Max(0, Math.Min(_scrollData.ExtentHeight - _scrollData.ViewportHeight, _scrollData.VerticalOffset)));
                        if (!DoubleUtil.AreClose(offset, _scrollData.Offset))
                        {
                            _scrollData.Offset   = offset;
                            invalidateScrollInfo = true;
                        }
                        if (invalidateScrollInfo && _scrollData.ScrollOwner != null)
                        {
                            _scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                        viewport = new Rect(_scrollData.HorizontalOffset, _scrollData.VerticalOffset, safeArrangeSize.Width, safeArrangeSize.Height);
                    }
                    _formatter.Arrange(safeArrangeSize, viewport);

                    // Connect to visual tree.
                    if (_pageVisual != _formatter.DocumentPage.Visual)
                    {
                        if (_textView != null)
                        {
                            _textView.OnPageConnected();
                        }
                        if (_pageVisual != null)
                        {
                            RemoveVisualChild(_pageVisual);
                        }
                        _pageVisual = (PageVisual)_formatter.DocumentPage.Visual;
                        AddVisualChild(_pageVisual);
                    }

                    // Set appropriate content offset
                    if (_scrollData != null)
                    {
                        _pageVisual.Offset = new Vector(-_scrollData.HorizontalOffset, -_scrollData.VerticalOffset);
                    }

                    // DocumentPage.Visual is always returned in LeftToRight FlowDirection.
                    // Hence, if the the current FlowDirection is RightToLeft,
                    // mirroring transform need to be applied to the content.
                    PtsHelper.UpdateMirroringTransform(FlowDirection, FlowDirection.LeftToRight, _pageVisual, safeArrangeSize.Width);
                }
                else
                {
                    if (_pageVisual != null)
                    {
                        if (_textView != null)
                        {
                            _textView.OnPageDisconnected();
                        }
                        RemoveVisualChild(_pageVisual);
                        _pageVisual = null;
                    }
                    // Arrange bottomless content.
                    if (_scrollData != null)
                    {
                        if (!DoubleUtil.AreClose(_scrollData.Viewport, safeArrangeSize))
                        {
                            _scrollData.Viewport = safeArrangeSize;
                            invalidateScrollInfo = true;
                        }
                        if (!DoubleUtil.AreClose(_scrollData.Extent, new Size()))
                        {
                            _scrollData.Extent   = new Size();
                            invalidateScrollInfo = true;
                        }
                        if (!DoubleUtil.AreClose(_scrollData.Offset, new Vector()))
                        {
                            _scrollData.Offset   = new Vector();
                            invalidateScrollInfo = true;
                        }
                        if (invalidateScrollInfo && _scrollData.ScrollOwner != null)
                        {
                            _scrollData.ScrollOwner.InvalidateScrollInfo();
                        }
                    }
                }
            }
            return(arrangeSize);
        }