// Token: 0x06006605 RID: 26117 RVA: 0x001CAE4C File Offset: 0x001C904C
        internal override IInputElement InputHitTest(double offset)
        {
            DependencyObject dependencyObject = null;
            TextContainer    textContainer    = this._owner.TextContainer as TextContainer;
            double           num = base.CalculateXOffsetShift();

            if (textContainer != null)
            {
                CharacterHit characterHitFromDistance;
                if (this._line.HasOverflowed && this._owner.ParagraphProperties.TextTrimming != TextTrimming.None)
                {
                    Invariant.Assert(DoubleUtil.AreClose(num, 0.0));
                    TextLine textLine = this._line.Collapse(new TextCollapsingProperties[]
                    {
                        base.GetCollapsingProps(this._wrappingWidth, this._owner.ParagraphProperties)
                    });
                    Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed");
                    characterHitFromDistance = textLine.GetCharacterHitFromDistance(offset);
                }
                else
                {
                    characterHitFromDistance = this._line.GetCharacterHitFromDistance(offset - num);
                }
                TextPointer textPointer = new TextPointer(this._owner.ContentStart, this.CalcPositionOffset(characterHitFromDistance), LogicalDirection.Forward);
                if (textPointer != null)
                {
                    TextPointerContext pointerContext;
                    if (characterHitFromDistance.TrailingLength == 0)
                    {
                        pointerContext = textPointer.GetPointerContext(LogicalDirection.Forward);
                    }
                    else
                    {
                        pointerContext = textPointer.GetPointerContext(LogicalDirection.Backward);
                    }
                    if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.ElementEnd)
                    {
                        dependencyObject = (textPointer.Parent as TextElement);
                    }
                    else if (pointerContext == TextPointerContext.ElementStart)
                    {
                        dependencyObject = textPointer.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                    }
                }
            }
            return(dependencyObject as IInputElement);
        }
        // Token: 0x0600686D RID: 26733 RVA: 0x001D7434 File Offset: 0x001D5634
        internal IInputElement InputHitTest(int urOffset)
        {
            DependencyObject dependencyObject = null;
            int          num = this.CalculateUOffsetShift();
            CharacterHit characterHitFromDistance;

            if (this._line.HasOverflowed && this.TextParagraph.Properties.TextTrimming != TextTrimming.None)
            {
                Invariant.Assert(num == 0);
                TextLine textLine = this._line.Collapse(new TextCollapsingProperties[]
                {
                    this.GetCollapsingProps(this._wrappingWidth, this.TextParagraph.Properties)
                });
                Invariant.Assert(textLine.HasCollapsed, "Line has not been collapsed");
                characterHitFromDistance = textLine.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urOffset));
            }
            else
            {
                characterHitFromDistance = this._line.GetCharacterHitFromDistance(TextDpi.FromTextDpi(urOffset - num));
            }
            int         cp          = this._paraClient.Paragraph.ParagraphStartCharacterPosition + characterHitFromDistance.FirstCharacterIndex + characterHitFromDistance.TrailingLength;
            TextPointer textPointer = TextContainerHelper.GetTextPointerFromCP(this._paraClient.Paragraph.StructuralCache.TextContainer, cp, LogicalDirection.Forward) as TextPointer;

            if (textPointer != null)
            {
                TextPointerContext pointerContext = textPointer.GetPointerContext((characterHitFromDistance.TrailingLength == 0) ? LogicalDirection.Forward : LogicalDirection.Backward);
                if (pointerContext == TextPointerContext.Text || pointerContext == TextPointerContext.ElementEnd)
                {
                    dependencyObject = textPointer.Parent;
                }
                else if (pointerContext == TextPointerContext.ElementStart)
                {
                    dependencyObject = textPointer.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                }
            }
            return(dependencyObject as IInputElement);
        }
示例#3
0
        // ------------------------------------------------------------------
        //  Hit tests to the correct ContentElement within the line.
        //
        //      offset - offset within the line.
        //
        // Returns: ContentElement which has been hit.
        // ------------------------------------------------------------------
        internal override IInputElement InputHitTest(double offset)
        {
            TextContainer      tree;
            DependencyObject   element;
            CharacterHit       charHit;
            TextPointer        position;
            TextPointerContext type = TextPointerContext.None;

            element = null;

            // We can only support hittesting text elements in a TextContainer.
            // If the TextContainer is not a TextContainer, return null which higher up the stack
            // will be converted into a reference to the control itself.
            tree = _owner.TextContainer as TextContainer;

            // Adjusted offset for shift due to trailing spaces rendering
            double delta = CalculateXOffsetShift();

            if (tree != null)
            {
                if (_line.HasOverflowed && _owner.ParagraphProperties.TextTrimming != TextTrimming.None)
                {
                    // We should not shift offset in this case
                    Invariant.Assert(DoubleUtil.AreClose(delta, 0));
                    System.Windows.Media.TextFormatting.TextLine line = _line.Collapse(GetCollapsingProps(_wrappingWidth, _owner.ParagraphProperties));
                    Invariant.Assert(line.HasCollapsed, "Line has not been collapsed");

                    // Get TextPointer from specified distance.
                    charHit = line.GetCharacterHitFromDistance(offset);
                }
                else
                {
                    charHit = _line.GetCharacterHitFromDistance(offset - delta);
                }

                position = new TextPointer(_owner.ContentStart, CalcPositionOffset(charHit), LogicalDirection.Forward);

                if (position != null)
                {
                    if (charHit.TrailingLength == 0)
                    {
                        // Start of character. Look forward
                        type = position.GetPointerContext(LogicalDirection.Forward);
                    }
                    else
                    {
                        // End of character. Look backward
                        type = position.GetPointerContext(LogicalDirection.Backward);
                    }

                    // Get element only for Text & Start/End element, for all other positions
                    // return null (it means that the line owner has been hit).
                    if (type == TextPointerContext.Text || type == TextPointerContext.ElementEnd)
                    {
                        element = position.Parent as TextElement;
                    }
                    else if (type == TextPointerContext.ElementStart)
                    {
                        element = position.GetAdjacentElementFromOuterPosition(LogicalDirection.Forward);
                    }
                }
            }

            return(element as IInputElement);
        }