GetEnclosingElement() public method

public GetEnclosingElement ( ) : AutomationElement
return AutomationElement
Ejemplo n.º 1
0
        public static int CountTextUnit(TextUnit tu, TextPatternRange rangeToCount)
        {
            ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null");  // Sanity check

            TextPatternRange clone = rangeToCount.Clone();

            int count = clone.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, tu, Int32.MaxValue);
        
            // Provider / Text Unit specific offsets    
            switch(typeOfProvider)
            {
            case "win32":
            case "winform":
                {
                    // This is to correct the fact that our line count will skip the last line if it 
                    // DOES NOT have a trailing \r, \n or \r\n
                    if( tu == TextUnit.Line ) 
                    {
                        string text = rangeToCount.GetText(-1);
                        AutomationElement element = rangeToCount.GetEnclosingElement();
                        if( IsTrailingCRLF(element, text) == 0 )
                            count++;
                    }
                }
                break;
            case "wpf":
                break;
            } 
            
            return count;
        }
Ejemplo n.º 2
0
        internal static int Win32CountTextUnit(TextUnit textUnit, TextPatternRange rangeToCount)
        {
            AutomationElement element = null;
            string actualText = "";

            ValidateArgumentNonNull(rangeToCount, "rangeToCount argument cannot be null");  // Sanity check

            // Get text
            try
            {
                actualText = rangeToCount.GetText(-1);
                element = rangeToCount.GetEnclosingElement();
                if (element == null)
                    throw new InvalidOperationException("Null automation element incorrectly returned by TextPatternRange.GetEnclosingElement() in Win32CountTextUnit()");
            }
            catch (Exception exception)
            {
                if (IsCriticalException(exception))
                    throw;

                throw new InvalidOperationException("Unable to call TextPatternRange.GetText() in Win32CountTextUnit()", exception);
            }

            // Count text units and assign to array element
            switch (textUnit)
            {
                case TextUnit.Character:
                    return actualText.Length;
                case TextUnit.Format:
                    return CountTextUnit(TextUnit.Format, rangeToCount);
                case TextUnit.Word:
                    return CountTextUnit(TextUnit.Word, rangeToCount);
                case TextUnit.Line:
                    return Win32CountLines(element);
                case TextUnit.Paragraph:
                    return CountParagraphs(actualText);
                case TextUnit.Page:
                    return 1;
                case TextUnit.Document:
                    return 1;
                default:
                    throw new ArgumentException("CountTextUnits() does not support " + textUnit.ToString());
            }
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------------
        // Wrapper for TextPatternRange.GetEnclosingElement Method
        //---------------------------------------------------------------------------
        internal void Range_GetEnclosingElement(TextPatternRange callingRange, ref AutomationElement parent, Type expectedException, CheckType checkType)
        {
            string call = "TextPatternRange.GetEnclosingElement()";
            Comment("---Calling " + call);

            if (callingRange == null)
                throw new ArgumentNullException(call + " requires non-NULL TextPatterncallingRange");

            try
            {
                parent = callingRange.GetEnclosingElement();
            }
            catch (Exception actualException)
            {
                if (Library.IsCriticalException(actualException))
                    throw;

                TestException(expectedException, actualException, call, checkType);
                return;
            }
            TestNoExceptionQuiet(expectedException, call, checkType);
        }