コード例 #1
0
        protected override bool OnMouseDown(EMouseButtons button)
        {
            if (IsEnabledInHierarchy() && browserHost != null && new Rect(0, 0, 1, 1).IsContainsPoint(MousePosition))
            {
                try
                {
                    Focus();

                    if (IsSupportedMouseButton(button))
                    {
                        browserHost.SendMouseClickEvent(GetCurrentMouseEvent(), ToCefMouseButton(button), false, 1);
                    }

                    //_logger.Debug(string.Format("Browser_MouseDown: ({0},{1})", cursorPos.X, cursorPos.Y));
                }
                catch (Exception ex)
                {
                    Log.Error("WebBrowserControl: Caught exception in OnMouseDown(): " + ex.Message);
                }

                return(true);
            }
            else
            {
                Unfocus();
            }

            return(base.OnMouseDown(button));
        }
コード例 #2
0
        //处理鼠标点击事件,up和down一起处理
        private static void HandleMouseButtonEvent(SDL_MouseButtonEvent e)
        {
            CefMouseEvent mouseEvent = new CefMouseEvent();

            mouseEvent.X = e.x;
            mouseEvent.Y = e.y;
            _host.SendMouseClickEvent(mouseEvent, GetMouseButtonFromSDL(e), e.state != 1, e.clicks);
        }
コード例 #3
0
        /// <summary>
        /// Sends a mouse up event to the browser.
        /// </summary>
        /// <param name="x">The x-coordinate of the mouse relative to the left edge of the view.</param>
        /// <param name="y">The y-coordinate of the mouse relative to the top edge of the view.</param>
        /// <param name="button">One of the <see cref="CefMouseButtonType"/> values.</param>
        /// <param name="clicks">A click count.</param>
        /// <param name="modifiers">A bitwise combination of the <see cref="CefEventFlags"/> values.</param>
        public void SendMouseUpEvent(int x, int y, CefMouseButtonType button, int clicks, CefEventFlags modifiers)
        {
            CefBrowserHost browserHost = this.BrowserObject?.Host;

            if (browserHost == null)
            {
                return;
            }

            InitMouseEvent(x, y, modifiers);
            browserHost.SendFocusEvent(true);
            browserHost.SendMouseClickEvent(_mouseEventProxy, button, true, clicks);
        }
コード例 #4
0
        private void AttachEventHandlers(WpfCefBrowser browser)
        {
            browser.GotKeyboardFocus += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        _browserHost.SendFocusEvent(true);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in GotFocus()", ex);
                }
            };

            browser.LostKeyboardFocus += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        _browserHost.SendFocusEvent(false);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in LostFocus()", ex);
                }
            };

            browser.MouseLeave += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        CefMouseEvent mouseEvent = new CefMouseEvent()
                        {
                            X = 0,
                            Y = 0
                        };

                        mouseEvent.Modifiers = GetMouseModifiers();

                        _browserHost.SendMouseMoveEvent(mouseEvent, true);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in MouseLeave()", ex);
                }
            };

            browser.MouseMove += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        Point cursorPos = arg.GetPosition(this);

                        CefMouseEvent mouseEvent = new CefMouseEvent()
                        {
                            X = (int)cursorPos.X,
                            Y = (int)cursorPos.Y
                        };

                        mouseEvent.Modifiers = GetMouseModifiers();

                        _browserHost.SendMouseMoveEvent(mouseEvent, false);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in MouseMove()", ex);
                }
            };

            browser.MouseDown += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        Focus();

                        Point cursorPos = arg.GetPosition(this);

                        CefMouseEvent mouseEvent = new CefMouseEvent()
                        {
                            X = (int)cursorPos.X,
                            Y = (int)cursorPos.Y,
                        };

                        mouseEvent.Modifiers = GetMouseModifiers();

                        if (arg.ChangedButton == MouseButton.Left)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Left, false, arg.ClickCount);
                        }
                        else if (arg.ChangedButton == MouseButton.Middle)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Middle, false, arg.ClickCount);
                        }
                        else if (arg.ChangedButton == MouseButton.Right)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Right, false, arg.ClickCount);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in MouseDown()", ex);
                }
            };

            browser.MouseUp += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        Point cursorPos = arg.GetPosition(this);

                        CefMouseEvent mouseEvent = new CefMouseEvent()
                        {
                            X = (int)cursorPos.X,
                            Y = (int)cursorPos.Y,
                        };

                        mouseEvent.Modifiers = GetMouseModifiers();

                        if (arg.ChangedButton == MouseButton.Left)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Left, true, 1);
                        }
                        else if (arg.ChangedButton == MouseButton.Middle)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Middle, true, 1);
                        }
                        else if (arg.ChangedButton == MouseButton.Right)
                        {
                            _browserHost.SendMouseClickEvent(mouseEvent, CefMouseButtonType.Right, true, 1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in MouseUp()", ex);
                }
            };


            browser.MouseWheel += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        Point cursorPos = arg.GetPosition(this);

                        CefMouseEvent mouseEvent = new CefMouseEvent()
                        {
                            X = (int)cursorPos.X,
                            Y = (int)cursorPos.Y,
                        };

                        _browserHost.SendMouseWheelEvent(mouseEvent, 0, arg.Delta);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in MouseWheel()", ex);
                }
            };

            // TODO: require more intelligent processing
            browser.PreviewTextInput += (sender, arg) =>
            {
                if (_browserHost != null)
                {
                    _logger.Debug("TextInput: text {0}", arg.Text);

                    foreach (var c in arg.Text)
                    {
                        CefKeyEvent keyEvent = new CefKeyEvent()
                        {
                            EventType      = CefKeyEventType.Char,
                            WindowsKeyCode = (int)c,
                        };

                        keyEvent.Modifiers = GetKeyboardModifiers();

                        _browserHost.SendKeyEvent(keyEvent);
                    }
                }

                arg.Handled = true;
            };

            // TODO: require more intelligent processing
            browser.PreviewKeyDown += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        CefKeyEvent keyEvent = new CefKeyEvent()
                        {
                            EventType      = CefKeyEventType.RawKeyDown,
                            WindowsKeyCode = KeyInterop.VirtualKeyFromKey(arg.Key == Key.System ? arg.SystemKey : arg.Key),
                            NativeKeyCode  = 0,
                            IsSystemKey    = arg.Key == Key.System,
                        };

                        keyEvent.Modifiers = GetKeyboardModifiers();

                        _browserHost.SendKeyEvent(keyEvent);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in PreviewKeyDown()", ex);
                }

                arg.Handled = HandledKeys.Contains(arg.Key);
            };

            // TODO: require more intelligent processing
            browser.PreviewKeyUp += (sender, arg) =>
            {
                try
                {
                    if (_browserHost != null)
                    {
                        //_logger.Debug(string.Format("KeyUp: system key {0}, key {1}", arg.SystemKey, arg.Key));
                        CefKeyEvent keyEvent = new CefKeyEvent()
                        {
                            EventType      = CefKeyEventType.KeyUp,
                            WindowsKeyCode = KeyInterop.VirtualKeyFromKey(arg.Key == Key.System ? arg.SystemKey : arg.Key),
                            NativeKeyCode  = 0,
                            IsSystemKey    = arg.Key == Key.System,
                        };

                        keyEvent.Modifiers = GetKeyboardModifiers();

                        _browserHost.SendKeyEvent(keyEvent);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in PreviewKeyUp()", ex);
                }

                arg.Handled = true;
            };
        }
コード例 #5
0
 private void MouseClickEvent(CefMouseEvent mouseEvent, int clickCount, CefMouseButtonType button, bool mouseUp)
 {
     browserHost.SendMouseClickEvent(mouseEvent, button, mouseUp, clickCount);
 }