Пример #1
0
        static DecoratorTests()
        {
            QUnit.module("Decorator tests");

            QUnit.test("Set Decorator.Child succeeds with null", delegate
            {
                Decorator d = new Decorator();
                d.Child = null;
            });

            QUnit.test("Set Decorator.Child succeeds with Control", delegate
            {
                Decorator d = new Decorator();
                UiElement c = new UiElement();
                d.Child = c;

                QUnit.ok(d.Child == c, "child should be the control");
                QUnit.ok(c.Parent == d, "parent should be the decorator");
            });

            QUnit.test("Reset Decorator.Child clears child's parent", delegate
            {
                Decorator d = new Decorator();
                UiElement c = new UiElement();
                d.Child = c;

                d.Child = null;

                QUnit.ok(d.Child == null, "child should be null");
                QUnit.ok(c.Parent == null, "parent should be null");
            });
        }
Пример #2
0
        static RegionTests()
        {
            QUnit.module("Region tests");

            QUnit.test("Region.GetRegion succeeds with null", delegate
            {
                QUnit.equals(Region.GetRegion(null), null, "should return null");
            });

            QUnit.test("Region.GetRegion succeeds with unparented control", delegate
            {
                UiElement c = new UiElement();
                QUnit.equals(Region.GetRegion(c), null, "should return null");
            });

            QUnit.test("Region.GetRegion succeeds with parented control", delegate
            {
                Region r = new Region();
                UiElement c = new UiElement();
                r.Child = c;

                QUnit.ok(Region.GetRegion(c) == r, "should return the region");
            });

            QUnit.test("Region.GetRegion succeeds with parented control chain", delegate
            {
                Region r = new Region();
                Decorator d = new Decorator();
                UiElement c = new UiElement();
                d.Child = c;
                r.Child = d;

                QUnit.ok(Region.GetRegion(c) == r, "should return the region");
            });
        }
Пример #3
0
        private static void OnUpdateHighlightPass(UiElement owner, float delta)
        {
            var localDelta = (float) Math.Sin(Math.PI*delta);

            owner.Alpha = localDelta;
            owner.Scale = new Vector2(1.0f + localDelta);
            owner.Offset = new Vector2(30, 0.0f)*delta;
        }
Пример #4
0
        public void FocusFirstElement()
        {
            var firstElement = _interactableElements.FirstOrDefault();
            if (firstElement == CurrentElement) return;

            CurrentElement?.Unfocus();

            _elementToGetFocus = firstElement;
        }
Пример #5
0
        public ActionResult Delete(UiElement viewModel)
        {
            if (ModelState.IsValid) {
                _service.Remove(viewModel.UiElementId);

                return RedirectToAction("Index");
            }

            return View();
        }
Пример #6
0
        public override void AddChild(UiElement child)
        {
            var pos = Children.Sum(c => c.Height);

            child.Y = (short)pos;
            child.X = 0;
            base.AddChild(child);
            pos = Children.Sum(c => c.Height);
            if (Autosize && pos > Height)
            {
                Height = (short)pos;
            }
        }
Пример #7
0
        private void UiElement_OnSelected(UiElement uiElement)
        {
            var screenshotsPath = uiElement.CaptureInformativeScreenshotToFile();

            setPropertyValue("SourceImgPath", screenshotsPath);
            setPropertyValue("Selector", new InArgument <string>(uiElement.Selector));
            grid1.Visibility = System.Windows.Visibility.Hidden;
            setPropertyValue("ProcessName", new InArgument <string>(uiElement.ProcessName));
            setPropertyValue("visibility", System.Windows.Visibility.Visible);
            string displayName = getPropertyValue("_DisplayName") + " \"" + uiElement.ProcessName + " " + uiElement.Name + "\"";

            setPropertyValue("DisplayName", displayName);
        }
Пример #8
0
        public void ColumnHeadersPresenter()
        {
            using var app = Application.AttachOrLaunch(ExeFileName, "ListViewWindow");
            var window    = app.MainWindow;
            var listView  = window.FindListView();
            var presenter = listView.ColumnHeadersPresenter;

            Assert.IsInstanceOf <GridViewHeaderRowPresenter>(UiElement.FromAutomationElement(presenter.AutomationElement));
            Assert.AreEqual(2, presenter.Headers.Count);

            Assert.AreEqual("Key", presenter.Headers[0].Text);
            Assert.AreEqual("Value", presenter.Headers[1].Text);
        }
Пример #9
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            Window currWindow = ActiveWindow.Get(context);
            IntPtr _handle    = handle.Get(context);

            if (currWindow == null)
            {
                currWindow = new Window();
                currWindow.setWindowHwnd((int)_handle);
            }
            try
            {
                var       selStr  = Selector.Get(context);
                UiElement element = UiElement.FromSelector(selStr);

                if (currWindow != null)
                {
                    Win32Api.SendMessage((IntPtr)currWindow.getWindowHwnd(), Win32Api.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
                else if (element != null)
                {
                    Win32Api.SendMessage(element.WindowHandle, Win32Api.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
                else
                {
                    PropertyDescriptor property = context.DataContext.GetProperties()[WindowActive.OpenBrowsersPropertyTag];
                    if (property == null)
                    {
                        property = context.DataContext.GetProperties()[WindowAttach.OpenBrowsersPropertyTag];
                    }
                    if (property != null)
                    {
                        Window getBrowser = property.GetValue(context.DataContext) as Window;
                        Win32Api.SendMessage((IntPtr)getBrowser.getWindowHwnd(), Win32Api.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "关闭窗口错误产生", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
            m_Delegate = new runDelegate(Run);
            return(m_Delegate.BeginInvoke(callback, state));
        }
Пример #10
0
 public override void AddChild(UiElement child)
 {
     if (Children.Any())
     {
         throw new ArgumentException("Child already set", nameof(child));
     }
     if (child.Width >= Width)
     {
         child.Width = (short)(Width - 1);
     }
     child.X = 0;
     child.Y = 0;
     base.AddChild(child);
 }
Пример #11
0
        public override void Process(out UiElement ui, XmlNode t, Builder builder)
        {
            var r = new Navigator();

            foreach (XmlNode p in t.ChildNodes)
            {
                var pp = new Page {
                    Caption = p.GetAttributeByName("caption")
                };
                builder.UiBaseElement(p.ChildNodes, pp.Childs);
                r.Pages.Add(pp);
            }
            ui = r;
        }
Пример #12
0
        protected override void Execute(CodeActivityContext context)
        {
            try
            {
                string attrName    = AttrName.Get(context);
                object attrValue   = AttrValue.Get(context);
                Int32  timeOut     = TimeOut.Get(context);
                bool   isFoundFlag = false;

                UiElement         element = Common.GetValueOrDefault(context, this.Element, null);
                AutomationElement autoEle = element.NativeObject as AutomationElement;
                FrameworkAutomationElementBase baseFrame = autoEle.FrameworkAutomationElement;
                PropertyId[] ids       = autoEle.GetSupportedPropertiesDirect();
                PropertyId   currentId = null;
                for (int i = 0; i < ids.Length; i++)
                {
                    if (String.Equals(ids[i].Name, attrName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        currentId = ids[i];
                        break;
                    }
                }
                for (int i = 0; i < timeOut / 1000; i++)
                {
                    if (attrValue == baseFrame.GetPropertyValue(currentId))
                    {
                        isFoundFlag = true;
                        break;
                    }
                    Thread.Sleep(1000);
                }
                if (!isFoundFlag && !ContinueOnError.Get(context))
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "相应元素的属性值未匹配,获取属性失败");
                    throw new Exception("获取属性失败,过程中断");
                }
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "等待获取元素属性过程出错", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }
Пример #13
0
        public void ActiveInHierarchy_ActiveState_CorrectActivity(
            [Values(true, false)] bool expectedActive
            )
        {
            // Arrange
            _go.SetActive(expectedActive);
            var element = new UiElement(_go);

            // Act
            var actualActive = element.IsActive;

            // Assert
            Assert.AreEqual(expectedActive, actualActive);
        }
Пример #14
0
        public override void DoExecute()
        {
            switch (PlaybackObject.action)
            {
            case "Click":
                try
                {
                    if (UiElement.AutomationElement.Current.IsEnabled)
                    {
                        UiElement.AsTabItem().Click();

                        Result = true;
                    }
                    else
                    {
                        Result = false;
                    }
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            case "IsSelected":
                try
                {
                    if (UiElement.AsTabItem().IsSelected)
                    {
                        Result = true;
                    }
                    else
                    {
                        Result = false;
                        return;
                    }
                }
                catch (Exception)
                {
                    Result = false;
                }
                break;

            default:
                Result = false;
                //Thread.Sleep(2000);
                break;
            }
        }
Пример #15
0
        protected override void Execute(CodeActivityContext context)
        {
            Int32 _delayAfter  = GetValueOrDefault(context, this.DelayAfter, 3000);
            Int32 _delayBefore = GetValueOrDefault(context, this.DelayBefore, 2000);

            try
            {
                Thread.Sleep(_delayBefore);
                var       selStr  = Selector.Get(context);
                UiElement element = GetValueOrDefault(context, this.Element, null);
                if (element == null && selStr != null)
                {
                    element = UiElement.FromSelector(selStr);
                }
                Int32 pointX = 0;
                Int32 pointY = 0;
                if (element != null)
                {
                    pointX = element.GetClickablePoint().X;
                    pointY = element.GetClickablePoint().Y;
                    element.SetForeground();
                    element.Focus();
                }
                else
                {
                    SharedObject.Instance.Output(SharedObject.enOutputType.Error, "有一个错误产生", "查找不到元素");
                    if (ContinueOnError.Get(context))
                    {
                        return;
                    }
                    else
                    {
                        throw new NotImplementedException("查找不到元素");
                    }
                }
                Thread.Sleep(_delayAfter);
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "设置键盘焦点失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                }
                else
                {
                    throw;
                }
            }
        }
Пример #16
0
        public override void DoExecute()
        {
            switch (PlaybackObject.action)
            {
            case "Select":
                try
                {
                    if (UiElement.AsCheckBox().IsChecked == false)
                    {
                        UiElement.AsCheckBox().Click();
                        Result = true;
                    }
                    else
                    {
                        Result = false;
                    }
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            case "Unselect":
                try
                {
                    if (UiElement.AsCheckBox().IsChecked == true)
                    {
                        UiElement.AsCheckBox().Click();
                        Result = true;
                    }
                    else
                    {
                        Result = false;
                    }
                }
                catch (Exception)
                {
                    Result = false;
                    //throw;
                }
                break;

            default:
                Result = false;
                break;
            }
        }
Пример #17
0
        public static bool DealVirtualKeyPress(string keyType)
        {
            bool bResult = false;

            foreach (VirtualKey item in Enum.GetValues(typeof(VirtualKey)))
            {
                if (keyType == item.ToString())
                {
                    UiElement.KeyboardPress(item);
                    bResult = true;
                    break;
                }
            }
            return(bResult);
        }
Пример #18
0
        public MyUIElement(RPARemoteObj context)
        {
            this.context           = context;
            node                   = new UiElement(SelectorStrategy.DEFAULT);
            node.Timeout           = 30000;
            node.WaitForReadyLevel = WaitForReady.INTERACTIVE;
            var selector = context.selector;

            if (!string.IsNullOrEmpty(selector))
            {
                Selector  filter = new Selector(selector);
                FindScope scope  = filter.IsTopLevel() ? FindScope.FIND_TOP_LEVELS : FindScope.FIND_DESCENDANTS;
                node = node.FindFirst(scope, filter);
            }
        }
Пример #19
0
        /// <summary>
        /// Removes a Target from the Animator Target list
        /// </summary>
        /// <param name="target">target to remove</param>
        private void RemoveTarget(UiElement target)
        {
            if (Targets.Contains(target))
            {
                if (target is Button btn)
                {
                    btn.RemoveFromClickEvent(OnClick);
                    btn.RemoveFromEnterEvent(OnEnter);
                    btn.RemoveFromHoverEvent(OnHover);
                    btn.RemoveFromLeaveEvent(OnLeave);
                }

                Targets.Remove(target);
            }
        }
Пример #20
0
        /// <summary>
        /// Creates a Bullet for the spaceship and enqueue it to the movement list.
        /// </summary>
        private void Shoot()
        {
            if (_shots.PlayerShots.Count >= _difficulty.BulletsForSpaceShip)
            {
                return;
            }

            var rocket = new UiElement()
            {
                PositionX = _spaceShip.PositionX, PositionY = _spaceShip.PositionY - 2, Icon = "|"
            };

            rocket.Draw();
            _shots.PendingShots.Enqueue(rocket);
        }
Пример #21
0
        //private static void SaveImage(string id, Tesseract.Pix pix)
        //{
        //    try
        //    {
        //        if(!Directory.Exists("logs"))
        //        {
        //            Directory.CreateDirectory("logs");
        //        }
        //        pix.Save($"logs\\{id}.bmp");
        //    }
        //    catch
        //    {
        //        // dont care...
        //    }
        //}

        public bool IsVisible(UiElement element)
        {
            if (element.Image != null)
            {
                return(IsImageVisible(element));
            }

            Debug.Assert(!string.IsNullOrWhiteSpace(element.Text));
            var text      = GetText(element).TrimStart().TrimEnd();
            var isVisible = text == element.Text;

            Overlay?.ShowIsVisibile(element, isVisible);
            //_logger.LogDebug($"{element.Id} IsVisible: {isVisible}");
            return(isVisible);
        }
Пример #22
0
 public override void Resolve(UiElement e, XmlNode markupTag)
 {
     if (markupTag.HasAttribute("onclick"))
     {
         e.Events["onclick"] = markupTag.GetAttributeByName("onclick");
     }
     if (markupTag.HasAttribute("onhover"))
     {
         e.Events["onhover"] = markupTag.GetAttributeByName("onhover");
     }
     if (markupTag.HasAttribute("onclick"))
     {
         e.Events["onleave"] = markupTag.GetAttributeByName("onleave");
     }
 }
Пример #23
0
        private void UiElement_OnSelected(UiElement uiElement)
        {
            System.Drawing.Point point = uiElement.GetClickablePoint();
            IntPtr windowhandle        = uiElement.WindowHandle;
            int    i = 0;

            var screenshotsPath = uiElement.CaptureInformativeScreenshotToFile();

            setPropertyValue("SourceImgPath", screenshotsPath);
            setPropertyValue("Selector", new InArgument <string>(uiElement.Selector));
            navigateTextBlock.Visibility = System.Windows.Visibility.Hidden;
            setPropertyValue("visibility", System.Windows.Visibility.Visible);
            string displayName = getPropertyValue("_DisplayName") + " \"" + uiElement.ProcessName + " " + uiElement.Name + "\"";

            setPropertyValue("DisplayName", displayName);
        }
Пример #24
0
        private void UpdateUiElementUnderCursor()
        {
            PointerEventData pointerEventData = ((CustomInputModule)EventSystem.current.currentInputModule).GetPointerData();

            GameObject obj = pointerEventData.pointerCurrentRaycast.gameObject;

            if (obj != null)
            {
                UiElement ui = obj.GetComponent <UiElement>();
                _uiElementUnderCursor = ui;
            }
            else
            {
                _uiElementUnderCursor = null;
            }
        }
        public override void DoExecute()
        {
            switch (Control.action)
            {
            case "Click":
                UiElement.AsButton().Click();
                break;

            case "DoubleClick":
                UiElement.AsButton().DoubleClick();
                break;

            default: Thread.Sleep(2000);
                break;
            }
        }
Пример #26
0
    public void Setup()
    {
        var rootGO = new GameObject("rootGo");
        _rootTransform = rootGO.transform;
        var canvasGO = new GameObject("Canvas", typeof(Canvas));
        canvasGO.transform.SetParent(rootGO.transform);
        var eventSystemGO = new GameObject("EventSystem", typeof(EventSystem));
        eventSystemGO.transform.SetParent(rootGO.transform);
        var testButtonGO = new GameObject("TestButton", typeof(RectTransform), typeof(Button));
        testButtonGO.transform.SetParent(canvasGO.transform);
        _button = rootGO.GetComponentInChildren<Button>();

        var agent = new NativeUnityDriverAgent();
        var driver = new UnityDriver(agent);
        _buttonElement = driver.FindElement(By.Type<Button>());
    }
Пример #27
0
        public static bool HasValidationError(this UiElement item)
        {
            var itemStatus = item.ItemStatus;

            if (itemStatus.Contains("HasError: True"))
            {
                return(true);
            }

            if (itemStatus.Contains("HasError: False"))
            {
                return(false);
            }

            throw new InvalidOperationException();
        }
Пример #28
0
        private Bitmap GrabElement(UiElement element)
        {
            var x       = element.X.GetValueOrDefault() * _window.Width;
            var y       = element.Y.GetValueOrDefault() * _window.Height;
            var w       = element.W.GetValueOrDefault() * _window.Width;
            var h       = element.H.GetValueOrDefault() * _window.Height;
            var section = _window.GrabScreen((int)x, (int)y, (int)w, (int)h);

            if (Settings.SaveRawImages)
            {
                var dir = Path.Combine("logs", "raw");
                Directory.CreateDirectory(dir);
                section.Save(Path.Combine(dir, $"{element.Id}.bmp"), System.Drawing.Imaging.ImageFormat.Bmp);
            }
            return(section);
        }
        private void UiElement_OnSelected(UiElement uiElement)
        {
            var screenshotsPath = uiElement.CaptureInformativeScreenshotToFile();

            setPropertyValue("SourceImgPath", screenshotsPath);
            setPropertyValue("Selector", new InArgument <string>(uiElement.Selector));
            setPropertyValue("visibility", System.Windows.Visibility.Visible);
            InArgument <Int32> _offsetX = uiElement.GetClickablePoint().X;
            InArgument <Int32> _offsetY = uiElement.GetClickablePoint().Y;

            setPropertyValue("offsetX", _offsetX);
            setPropertyValue("offsetY", _offsetY);
            string displayName = getPropertyValue("_DisplayName") + " \"" + uiElement.ProcessName + " " + uiElement.Name + "\"";

            setPropertyValue("DisplayName", displayName);
        }
Пример #30
0
        public void FindExplicit()
        {
            using var app = Application.Launch(ExeFileName, Window);
            var window = app.MainWindow;
            var button = window.FindButton("With explicit ToolTip");

            Mouse.Position = button.Bounds.Center();
            var toolTip = button.FindToolTip();

            Assert.AreEqual(false, toolTip.IsOffscreen);
            Assert.AreEqual("Explicit tool tip text.", toolTip.Text);
            Assert.IsInstanceOf <ToolTip>(UiElement.FromAutomationElement(toolTip.AutomationElement));

            window.FindButton("Lose focus").Click();
            Assert.AreEqual(true, toolTip.IsOffscreen);
        }
        public override void DoExecute()
        {
            switch (PlaybackObject.action)
            {
            case "SetText":
                try
                {
                    if (UiElement.AsComboBox().IsEditable.Equals(true))
                    {
                        UiElement.AsTextBox().Enter(PlaybackObject.text);
                        Result = true;
                    }
                    else
                    {
                        Result = false;
                    }
                }
                catch (Exception)
                {
                    Result = false;
                }
                break;

            case "Select":
                try
                {
                    //AutomationElement a = UiElement.AutomationElement;
                    //ExpandCollapsePattern expandCollapsePattern = a.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
                    //expandCollapsePattern.Expand();
                    //var cbxEditItems = UiElement.FindAll(TreeScope.Subtree, new System.Windows.Automation.PropertyCondition(AutomationElement.ClassNameProperty, "ComboBoxItem"));
                    //cbxEditItems[PlaybackObject.itemIndex].AutomationElement.SelectionItemPattern().Select();
                    //expandCollapsePattern.Collapse();
                    UiElement.AsComboBox().Select(PlaybackObject.itemIndex);
                    UiElement.AsComboBox().Collapse();
                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                }
                break;

            default:
                Result = false;
                break;
            }
        }
Пример #32
0
        internal void UiBaseElement(XmlNodeList t, List <ElementBase> parent)
        {
            foreach (XmlNode markupTag in t)
            {
                if (markupTag is XmlComment)
                {
                    continue;
                }
                var e = new UiElement();

                new DefaultEventProvider().Resolve(e, markupTag);

                if (Processors[markupTag.Name] != null)
                {
                    Processors[markupTag.Name].Process(out e, markupTag, this);
                }
                else
                {
                    throw new EfmlException("'" + markupTag.Name + "'-Tag is not found");
                }

                if (markupTag.HasAttribute("id"))
                {
                    e.ID = markupTag.GetAttributeByName("id");
                }
                else
                {
                    throw new EfmlException("'id' attribute is required on '" + markupTag.Name + "'");
                }

                if (markupTag.HasAttribute("Content"))
                {
                    string l = markupTag.GetAttributeByName("Content");

                    e.content = l;
                }
                else
                {
                    e.content = markupTag.InnerText;
                }

                if (e.GetType().Name != typeof(UiElement).Name)
                {
                    parent.Add(e);
                }
            }
        }
Пример #33
0
        protected override void Execute(CodeActivityContext context)
        {
            // Dispatcher.CurrentDispatcher.Invoke(new Action(() => System.Windows.Application.Current.MainWindow.WindowState = System.Windows.WindowState.Minimized));
            //Dispatcher.CurrentDispatcher.Invoke(new Action(delegate
            //{
            //    UiElement.StartElementHighlight();
            //    //System.Windows.Application.Current.MainWindow.WindowState = System.Windows.WindowState.Minimized;
            //}));
            try
            {
                System.Windows.Application.Current.Dispatcher.InvokeAsync(() =>
                {
                    UiElement.OnSelected = UiElement_OnSelected;
                    UiElement.OnCanceled = UiElement_OnCanceled;
                    UiElement.StartElementHighlight();
                });

                while (true)
                {
                    if (isSelectedFlag)
                    {
                        context.SetValue(SelectedElement, uiElement);
                        break;
                    }
                    if (isCanceledFlag)
                    {
                        break;
                    }
                    Thread.Sleep(200);
                }
                isSelectedFlag = false;
                isCanceledFlag = false;
            }
            catch (Exception e)
            {
                SharedObject.Instance.Output(SharedObject.enOutputType.Error, "屏幕截图失败", e.Message);
                if (ContinueOnError.Get(context))
                {
                    return;
                }
                else
                {
                    throw e;
                }
            }
        }
Пример #34
0
        public void Click(UiElement element)
        {
            var x = element.X.GetValueOrDefault();
            var y = element.Y.GetValueOrDefault();

            if (element.W.HasValue)
            {
                x = RandomizeWithinRange(x, x + element.W.Value);
            }

            if (element.H.HasValue)
            {
                y = RandomizeWithinRange(y, y + element.H.Value);
            }

            _window.ClickAt(x, y);
        }
Пример #35
0
        public void SelectionItem_SelectionContainer()
        {
            // Arrange
            var expectedValue = new UiElement();
            var element       =
                FakeFactory.GetAutomationElementForMethodsOfObjectModel(
                    new IBasePattern[] { FakeFactory.GetSelectionItemPattern(new PatternsData()
                {
                    SelectionItemPattern_SelectionContainer = expectedValue
                }) }) as ISupportsSelectionItemPattern;

            // Act

            // Assert
            MbUnit.Framework.Assert.AreEqual(expectedValue, element.SelectionContainer);
            Assert.Equal(expectedValue, element.SelectionContainer);
        }
Пример #36
0
 protected void AddUiElement(UiElement element)
 {
     _interactableElements.Add(element);
     _rearrangeList = true;
 }
Пример #37
0
        public void ControllerOnMoveToPreviousElement()
        {
            var lastElement = CurrentElement;
            if (CurrentElement == null)
            {
                CurrentElement = _interactableElements.FirstOrDefault();
            }
            else
            {
                var index = _interactableElements.IndexOf(CurrentElement);
                CurrentElement = index == 0 ? _interactableElements[_interactableElements.Count - 1] : _interactableElements[index - 1];
            }

            if (lastElement != CurrentElement)
            {
                lastElement?.Unfocus();
                CurrentElement?.Focus();
            }
        }
Пример #38
0
 public UiFocusContainer()
 {
     _interactableElements = new List<UiElement>();
     InputControllers = new List<OverlayInputController>();
     CurrentElement = null;
 }
Пример #39
0
 public SubtitlesEditModel(UiElement element)
 {
     Element = element;
     Alias = (UiElement.Aliass)element.Alias;
 }
Пример #40
0
        private void ControllerOnMoveToNextElement()
        {
            var lastElement = CurrentElement;
            if (CurrentElement == null)
            {
                CurrentElement = _interactableElements.FirstOrDefault();
            }
            else
            {
                var index = _interactableElements.IndexOf(CurrentElement);
                CurrentElement = index == _interactableElements.Count - 1 ? _interactableElements[0] : _interactableElements[index + 1];
            }

            if (lastElement != CurrentElement)
            {
                lastElement?.Unfocus();
                CurrentElement?.Focus();
            }
        }
Пример #41
0
        public virtual void Update(GameTime gameTime)
        {
            if (_rearrangeList)
            {
                _interactableElements.RemoveAll(e => !e.IsInteractable);
                _interactableElements.Sort((e1, e2) => e1.TabIndex.CompareTo(e2.TabIndex));
            }

            foreach (var inputController in InputControllers)
            {
                inputController.Update(this);
            }

            if (_elementToGetFocus != null && _elementToGetFocus.State == UiState.Active)
            {
                _elementToGetFocus.Focus();
                CurrentElement = _elementToGetFocus;
                _elementToGetFocus = null;
            }
        }
Пример #42
0
        static LayoutTests()
        {
            QUnit.module("Control tests");

            QUnit.test("create Control succeeds", delegate
            {
                UiElement c = new UiElement();
            });

            QUnit.test("Control.GetParent() succeeds and is null", delegate
            {
                UiElement c = new UiElement();
                QUnit.ok(c.Parent == null, "should be null");
            });

            QUnit.module("Region layout tests");

            QUnit.test("Region.layOut succeeds with no root", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                r.LayOut();
            });

            QUnit.test("Region.layOut succeeds with exact space available", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 20;
                c.YAxis.Length = 20;
                c.XAxis.Alignment = AxisAlignment.Near;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Width, 20);
                QUnit.equals(c.MeasuredSize.Height, 20);
                QUnit.equals(c.YArrangement.Length, 20);
                QUnit.equals(c.XArrangement.Length, 20);
                QUnit.equals(c.YArrangement.Position, 0);
                QUnit.equals(c.XArrangement.Position, 0);
            });

            QUnit.test("Region.layOut clips width", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 30;
                c.YAxis.Length = 10;
                c.XAxis.Alignment = AxisAlignment.Near;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Width, 30);
                QUnit.equals(c.XArrangement.Length, 20);
            });

            QUnit.test("Region.layOut does not clip minWidth", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 30;
                c.XAxis.MinLength = 25;
                c.YAxis.Length = 10;
                c.XAxis.Alignment = AxisAlignment.Near;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Width, 30);
                QUnit.equals(c.XArrangement.Length, 25);
            });

            QUnit.test("Region.layOut stretches width", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 10;
                c.YAxis.Length = 10;
                c.XAxis.Alignment = AxisAlignment.Stretch;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Width, 10);
                QUnit.equals(c.XArrangement.Length, 20);
            });

            QUnit.test("Region.layOut stretches width, respects maxWidth", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 10;
                c.XAxis.MaxLength = 15;
                c.YAxis.Length = 10;
                c.XAxis.Alignment = AxisAlignment.Stretch;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Width, 10);
                QUnit.equals(c.XArrangement.Length, 15);
            });

            QUnit.test("Region.layOut clips height", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 10;
                c.YAxis.Length = 30;
                c.XAxis.Alignment = AxisAlignment.Near;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Height, 30);
                QUnit.equals(c.YArrangement.Length, 20);
            });

            QUnit.test("Region.layOut does not clip minMinHeight", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.YAxis.Length = 30;
                c.YAxis.MinLength = 25;
                c.XAxis.Length = 10;
                c.XAxis.Alignment = AxisAlignment.Near;
                c.YAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Height, 30);
                QUnit.equals(c.YArrangement.Length, 25);
            });

            QUnit.test("Region.layOut stretches height", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.XAxis.Length = 10;
                c.YAxis.Length = 10;
                c.YAxis.Alignment = AxisAlignment.Stretch;
                c.XAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Height, 10);
                QUnit.equals(c.YArrangement.Length, 20);
            });

            QUnit.test("Region.layOut stretches width, respects maxWidth", delegate
            {
                jQueryObject host = jQuery.FromHtml("<div style='width: 20px; height: 20px'>");
                jQuery.FromHtml("#qunit-fixture").Append(host);

                Region r = new Region();
                r.Host = host[0];

                UiElement c = new UiElement();
                c.YAxis.Length = 10;
                c.YAxis.MaxLength = 15;
                c.XAxis.Length = 10;
                c.YAxis.Alignment = AxisAlignment.Stretch;
                c.XAxis.Alignment = AxisAlignment.Near;

                r.Child = c;

                r.LayOut();

                QUnit.equals(c.MeasuredSize.Height, 10);
                QUnit.equals(c.YArrangement.Length, 15);
            });
        }
Пример #43
0
 private void ControllerOnOnAction(UiElement uiElement)
 {
     CurrentElement?.OnAction();
 }
Пример #44
0
 /// <summary>
 /// Adds a child control to compound element.
 /// </summary>
 /// <param name="element"></param>
 protected void AddChildElement(UiElement element)
 {
     _children.Add(element);
 }
Пример #45
0
 protected void RemoveChild(UiElement element)
 {
     _children.Remove(element);
 }
Пример #46
0
        private void collectAncestry(
            ref System.Collections.Generic.List<string> listForNodes,
            ref System.Collections.Generic.List<string> listForCode,
            IUiElement element)
        {
            cleanAncestry();
            
            TreeWalker walker =
                new TreeWalker(
                    Condition.TrueCondition);
            
            try {
                
                // 20131109
                //AutomationElementIUiElement testparent = element;
                IUiElement testparent = element;
                // 20140312
                // if (testparent != null && (int)testparent.Current.ProcessId > 0) {
                if (testparent != null && (int)testparent.GetCurrent().ProcessId > 0) {
                    listForNodes.Add(getNodeNameFromAutomationElement(testparent));
                    // 20131109
                    //if (testparent != AutomationElement.RootElement) {
                    if (!Equals(testparent, UiElement.RootElement)) {
                        listForCode.Add(getCodeFromAutomationElement(testparent, walker));
                    }
                    /*
                    if (testparent != UiElement.RootElement) {
                        listForCode.Add(getCodeFromAutomationElement(testparent, walker));
                    }
                     */
                }
                
                // 20140312
                // while (testparent != null && (int)testparent.Current.ProcessId > 0) {
                while (testparent != null && (int)testparent.GetCurrent().ProcessId > 0) {
                    testparent =
                        // 20131109
                        //walker.GetParent(testparent);
                        // 20131118
                        // property to method
                        //new UiElement(walker.GetParent(testparent.SourceElement));
                        // 20140102
                        // new UiElement(walker.GetParent(testparent.GetSourceElement()));
                        new UiElement(walker.GetParent(testparent.GetSourceElement() as AutomationElement));
                    // 20140312
                    // if (testparent.Current.ProcessId <= 0) continue;
                    if (testparent.GetCurrent().ProcessId <= 0) continue;
                    /*
                    if (testparent == null || (int) testparent.Current.ProcessId <= 0) continue;
                     */
                    listForNodes.Add(getNodeNameFromAutomationElement(testparent));
                    // 20131109
                    //if (testparent != AutomationElement.RootElement) {
                    if (!Equals(testparent, UiElement.RootElement)) {
                        listForCode.Add(getCodeFromAutomationElement(testparent, walker));
                    }
                    /*
                    if (testparent != UiElement.RootElement) {
                        listForCode.Add(getCodeFromAutomationElement(testparent, walker));
                    }
                     */

                    /*
                    if (testparent != null && (int)testparent.Current.ProcessId > 0) {
                        listForNodes.Add(getNodeNameFromAutomationElement(testparent));
                        if (testparent != AutomationElement.RootElement) {
                            listForCode.Add(getCodeFromAutomationElement(testparent, walker));
                        }
                    }
                     */
                }
            } catch (Exception eNew)  {

                txtFullCode.Text = eNew.Message;
            }
        }
 public void SelectionItem_SelectionContainer()
 {
     // Arrange
     var expectedValue = new UiElement();
     var element =
         FakeFactory.GetAutomationElementForMethodsOfObjectModel(
             new IBasePattern[] { FakeFactory.GetSelectionItemPattern(new PatternsData() { SelectionItemPattern_SelectionContainer = expectedValue }) }) as ISupportsSelectionItemPattern;
     
     // Act
     
     // Assert
     MbUnit.Framework.Assert.AreEqual(expectedValue, element.SelectionContainer);
     Assert.Equal(expectedValue, element.SelectionContainer);
 }
        public void GridItem_ContainingGrid()
        {
            // Arrange
            IUiElement expectedValue = new UiElement();
            var element =
                FakeFactory.GetAutomationElementForMethodsOfObjectModel(
                    new IBasePattern[] { FakeFactory.GetGridItemPattern(new PatternsData() { GridItemPattern_ContainingGrid = expectedValue }) }) as ISupportsGridItemPattern;
            
            // Act
            
            // Assert
            // Assert.AreEqual(expectedValue as IUiElement, element.GridContainingGrid as IUiElement);
            // 20140312
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.Name, element.GridContainingGrid.Current.Name);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.AutomationId, element.GridContainingGrid.Current.AutomationId);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.ClassName, element.GridContainingGrid.Current.ClassName);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.ControlType, element.GridContainingGrid.Current.ControlType);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.BoundingRectangle, element.GridContainingGrid.Current.BoundingRectangle);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.NativeWindowHandle, element.GridContainingGrid.Current.NativeWindowHandle);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.ProcessId, element.GridContainingGrid.Current.ProcessId);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.IsEnabled, element.GridContainingGrid.Current.IsEnabled);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.IsOffscreen, element.GridContainingGrid.Current.IsOffscreen);
//            MbUnit.Framework.Assert.AreEqual(expectedValue.Current.AcceleratorKey, element.GridContainingGrid.Current.AcceleratorKey);
//            
//            Xunit.Assert.Equal(expectedValue.Current.Name, element.GridContainingGrid.Current.Name);
//            Xunit.Assert.Equal(expectedValue.Current.AutomationId, element.GridContainingGrid.Current.AutomationId);
//            Xunit.Assert.Equal(expectedValue.Current.ClassName, element.GridContainingGrid.Current.ClassName);
//            Xunit.Assert.Equal(expectedValue.Current.ControlType, element.GridContainingGrid.Current.ControlType);
//            Xunit.Assert.Equal(expectedValue.Current.BoundingRectangle, element.GridContainingGrid.Current.BoundingRectangle);
//            Xunit.Assert.Equal(expectedValue.Current.NativeWindowHandle, element.GridContainingGrid.Current.NativeWindowHandle);
//            Xunit.Assert.Equal(expectedValue.Current.ProcessId, element.GridContainingGrid.Current.ProcessId);
//            Xunit.Assert.Equal(expectedValue.Current.IsEnabled, element.GridContainingGrid.Current.IsEnabled);
//            Xunit.Assert.Equal(expectedValue.Current.IsOffscreen, element.GridContainingGrid.Current.IsOffscreen);
//            Xunit.Assert.Equal(expectedValue.Current.AcceleratorKey, element.GridContainingGrid.Current.AcceleratorKey);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().Name, element.GridContainingGrid.GetCurrent().Name);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().AutomationId, element.GridContainingGrid.GetCurrent().AutomationId);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().ClassName, element.GridContainingGrid.GetCurrent().ClassName);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().ControlType, element.GridContainingGrid.GetCurrent().ControlType);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().BoundingRectangle, element.GridContainingGrid.GetCurrent().BoundingRectangle);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().NativeWindowHandle, element.GridContainingGrid.GetCurrent().NativeWindowHandle);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().ProcessId, element.GridContainingGrid.GetCurrent().ProcessId);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().IsEnabled, element.GridContainingGrid.GetCurrent().IsEnabled);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().IsOffscreen, element.GridContainingGrid.GetCurrent().IsOffscreen);
            MbUnit.Framework.Assert.AreEqual(expectedValue.GetCurrent().AcceleratorKey, element.GridContainingGrid.GetCurrent().AcceleratorKey);
            
            Xunit.Assert.Equal(expectedValue.GetCurrent().Name, element.GridContainingGrid.GetCurrent().Name);
            Xunit.Assert.Equal(expectedValue.GetCurrent().AutomationId, element.GridContainingGrid.GetCurrent().AutomationId);
            Xunit.Assert.Equal(expectedValue.GetCurrent().ClassName, element.GridContainingGrid.GetCurrent().ClassName);
            Xunit.Assert.Equal(expectedValue.GetCurrent().ControlType, element.GridContainingGrid.GetCurrent().ControlType);
            Xunit.Assert.Equal(expectedValue.GetCurrent().BoundingRectangle, element.GridContainingGrid.GetCurrent().BoundingRectangle);
            Xunit.Assert.Equal(expectedValue.GetCurrent().NativeWindowHandle, element.GridContainingGrid.GetCurrent().NativeWindowHandle);
            Xunit.Assert.Equal(expectedValue.GetCurrent().ProcessId, element.GridContainingGrid.GetCurrent().ProcessId);
            Xunit.Assert.Equal(expectedValue.GetCurrent().IsEnabled, element.GridContainingGrid.GetCurrent().IsEnabled);
            Xunit.Assert.Equal(expectedValue.GetCurrent().IsOffscreen, element.GridContainingGrid.GetCurrent().IsOffscreen);
            Xunit.Assert.Equal(expectedValue.GetCurrent().AcceleratorKey, element.GridContainingGrid.GetCurrent().AcceleratorKey);
        }
 public ControlCantBeFocusedException(string message, UiElement uiElement)
     : base(message, uiElement)
 {
 }
 protected void InvokeAction(UiElement element)
 {
     OnAction?.Invoke(element);
 }