Beispiel #1
0
        public void DomContentChanged_ChangeContentOfTextInputWithKeyPressAndMoveToSecondInput_DomContentChangedShouldFire()
        {
            string html = "<input id=\"one\" type=\"text\" value=\"hello\" /><input id=\"two\" type=\"text\"  value=\"world\" />";

            _browser.TestLoadHtml(html);

            // Place browser on a form and show it. This is need to make the gecko accept the key press.
            Form f = new Form();

            f.Controls.Add(_browser);
            _browser.Visible = true;
            f.Show();

            // Focus first input box
            _browser.Document.GetHtmlElementById("one").Focus();
            GeckoRange range = _browser.Document.CreateRange();

            range.SelectNode(_browser.Document.GetHtmlElementById("one"));
            _browser.Window.Selection.AddRange(range);

            // record if DomContentChanged event happened.
            bool contentChangedEventReceived = false;

            _browser.DomContentChanged += (sender, e) => contentChangedEventReceived = true;


            // Modify first input by sending a keypress.
            // This could be refactored but at least it shows how to invoke a keypress using nsITextInputProcessor
            var instance = Xpcom.CreateInstance <nsITextInputProcessor>("@mozilla.org/text-input-processor;1");

            using (var context = new AutoJSContext(_browser.Window))
            {
                var result = context.EvaluateScript(
                    @"new KeyboardEvent('', { key: 'a', code: 'KeyA', keyCode: KeyboardEvent.DOM_VK_A });");
                instance.BeginInputTransaction((mozIDOMWindow)_browser.Document.DefaultView.DomWindow, new TestCallback());
                nsString.Set(instance.SetPendingCompositionString, "hi");
                instance.Keyup((nsIDOMEvent)result.ToComObject(context.ContextPointer), 0, 1);
                result = context.EvaluateScript(
                    @"new KeyboardEvent('', { key: 'Enter', code: 'Enter' });");
                instance.FlushPendingComposition(null, 0, 2);
                instance.CommitComposition((nsIDOMEvent)result.ToComObject(context.ContextPointer), 0, 2);
            }

            // DomContentChanged Event should fire when we move we move to next element.
            _browser.Document.GetHtmlElementById("two").Focus();
            range.SelectNode(_browser.Document.GetHtmlElementById("two"));
            _browser.Window.Selection.RemoveAllRanges();
            _browser.Window.Selection.AddRange(range);

            Assert.IsTrue(contentChangedEventReceived);
        }
        public void DomContentChanged_ChangeContentOfTextInputWithKeyPressAndMoveToSecondInput_DomContentChangedShouldFire()
        {
            string html = "<input id=\"one\" type=\"text\" value=\"hello\" /><input id=\"two\" type=\"text\"  value=\"world\" />";

            LoadHtml(html);

            // Place browser on a form and show it. This is need to make the gecko accept the key press.
            Form f = new Form();

            f.Controls.Add(browser);
            browser.Visible = true;
            f.Show();

            // Focus first input box
            browser.Document.GetElementById("one").Focus();
            GeckoRange range = browser.Document.CreateRange();

            range.SelectNode(browser.Document.GetElementById("one"));
            browser.Window.Selection.AddRange(range);

            // record if DomContentChanged event happened.
            bool contentChangedEventReceived = false;

            browser.DomContentChanged += (sender, e) => contentChangedEventReceived = true;


            // Modify first input by sending a keypress.
            // TODO: create wrapper for nsIDOMWindowUtils
            nsIDOMWindowUtils utils = Xpcom.QueryInterface <nsIDOMWindowUtils>(browser.Window.DomWindow);

            using (nsAString type = new nsAString("keypress"))
            {
                utils.SendKeyEvent(type, 0, 102, 0, false);
            }

            // DomContentChanged Event should fire when we move we move to next element.
            browser.Document.GetElementById("two").Focus();
            range.SelectNode(browser.Document.GetElementById("two"));
            browser.Window.Selection.RemoveAllRanges();
            browser.Window.Selection.AddRange(range);

            Assert.IsTrue(contentChangedEventReceived);
        }
 /// <summary>
 /// Get the Individual rectangles that make up a selection.
 /// </summary>
 public static Rectangle[] GetClientRects( GeckoRange range )
 {
     nsIDOMClientRectList rects = range.DomRange.GetClientRects();
     return WinFormsConverter.WrapDomClientRectList( rects );
 }
 /// <summary>
 /// Get Rectange which surrounds entire selection.
 /// </summary>
 /// <param name="selection"></param>
 /// <returns></returns>
 public static Rectangle GetBoundingClientRect( GeckoRange range )
 {
     nsIDOMClientRect domRect = range.DomRange.GetBoundingClientRect();
     if ( domRect == null ) return Rectangle.Empty;
     return WinFormsConverter.WrapDomClientRect( domRect );
 }