Ejemplo n.º 1
0
        public void MouseEvent(int x, int y, bool updown, MouseButton button)
        {
            //_lifespanHandler.MainBrowserHost.SendFocusEvent(true);
            //_lifespanHandler.MainBrowser.GetHost().SendFocusEvent(true);
            CefMouseEvent mouseEvent = new CefMouseEvent()
            {
                X = x,
                Y = y,
            };
            CefEventFlags      modifiers = new CefEventFlags();
            CefMouseButtonType mouse     = CefMouseButtonType.Left;

            if (button == MouseButton.Left)
            {
                modifiers |= CefEventFlags.LeftMouseButton;
                mouse      = CefMouseButtonType.Left;
            }
            if (button == MouseButton.Right)
            {
                mouse      = CefMouseButtonType.Right;
                modifiers |= CefEventFlags.RightMouseButton;
            }
            if (button == MouseButton.Middle)
            {
                mouse      = CefMouseButtonType.Middle;
                modifiers |= CefEventFlags.MiddleMouseButton;
            }
            mouseEvent.Modifiers = modifiers;
            // log.Info("CLICK:" + x + "," + y);


            _lifespanHandler.MainBrowser.GetHost().SendMouseClickEvent(mouseEvent, mouse, updown, 1);
        }
Ejemplo n.º 2
0
        CefMouseEvent GetCurrentMouseEvent()
        {
            Vec2 pos        = viewSize.ToVec2() * MousePosition;
            var  mouseEvent = new CefMouseEvent((int)pos.X, (int)pos.Y, GetCurrentKeyboardModifiers());

            return(mouseEvent);
        }
Ejemplo n.º 3
0
        public void SendMouseUpDown(int x, int y, CefMouseButtonType button, bool isMouseUp)
        {
            if (this.Browser != null)
            {
                var host = this.Browser.GetHost();

                if (!isMouseUp)
                {
                    if (IsContinuousClick(x, y, button))
                    {
                        clickCount++;
                    }
                    else
                    {
                        clickCount = 1;
                    }
                }

                var mouseEvent = new CefMouseEvent {
                    X = x, Y = y
                };
                host.SendMouseClickEvent(mouseEvent, button, isMouseUp, clickCount);

                lastClickPosX   = x;
                lastClickPosY   = y;
                lastClickButton = button;
                lastClickTime   = DateTime.Now;
            }
        }
Ejemplo n.º 4
0
        private void HandleMouseNotification(MouseNotification n, CallerInfo caller)
        {
            var position    = GetPositionInViewport(n, caller);
            var mouseEvent  = new CefMouseEvent((int)position.X, (int)position.Y, CefEventFlags.None);
            var browserHost = webRenderer.BrowserHost;

            switch (n.Kind)
            {
            case MouseNotificationKind.MouseDown:
                var mouseDown = n as MouseDownNotification;
                browserHost.SendMouseClickEvent(mouseEvent, GetMouseButtonType(mouseDown.Buttons), mouseUp: false, clickCount: 1);
                break;

            case MouseNotificationKind.MouseUp:
                var mouseUp = n as MouseUpNotification;
                browserHost.SendMouseClickEvent(mouseEvent, GetMouseButtonType(mouseUp.Buttons), mouseUp: true, clickCount: 1);
                break;

            case MouseNotificationKind.MouseMove:
                browserHost.SendMouseMoveEvent(mouseEvent, mouseLeave: false);
                break;

            case MouseNotificationKind.MouseWheel:
                var mouseWheel = n as MouseWheelNotification;
                browserHost.SendMouseWheelEvent(mouseEvent, 0, mouseWheel.WheelDelta);
                break;

            case MouseNotificationKind.MouseHorizontalWheel:
                var mouseHWheel = n as MouseHorizontalWheelNotification;
                browserHost.SendMouseWheelEvent(mouseEvent, mouseHWheel.WheelDelta, 0);
                break;

            case MouseNotificationKind.MouseClick:
                var mouseClick = n as MouseClickNotification;
                browserHost.SendMouseClickEvent(mouseEvent, GetMouseButtonType(mouseClick.Buttons), mouseUp: false, clickCount: mouseClick.ClickCount);
                break;

            case MouseNotificationKind.DeviceLost:
                browserHost.SendMouseMoveEvent(mouseEvent, mouseLeave: true);
                break;

            default:
                throw new NotImplementedException();
            }

            CefMouseButtonType GetMouseButtonType(MouseButtons buttons)
            {
                if ((buttons & MouseButtons.Left) != 0)
                {
                    return(CefMouseButtonType.Left);
                }
                if ((buttons & MouseButtons.Middle) != 0)
                {
                    return(CefMouseButtonType.Middle);
                }
                if ((buttons & MouseButtons.Right) != 0)
                {
                    return(CefMouseButtonType.Right);
                }
                return(default);
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void SendMouseMove(CefMouseEvent e)
        {
            if (this.sHost == null)
            {
                return;
            }

            this.sHost.SendMouseMoveEvent(e, false);
        }
Ejemplo n.º 7
0
        public void MouseLeaveEvent()
        {
            CefMouseEvent mouseEvent = new CefMouseEvent()
            {
                X = 0,
                Y = 0
            };

            _lifespanHandler.MainBrowser.GetHost().SendMouseMoveEvent(mouseEvent, false);
        }
Ejemplo n.º 8
0
        public void MouseWheelEvent(int x, int y, int delta)
        {
            CefMouseEvent mouseEvent = new CefMouseEvent()
            {
                X = x,
                Y = y
            };

            _lifespanHandler.MainBrowser.GetHost().SendMouseWheelEvent(mouseEvent, 0, delta);
        }
Ejemplo n.º 9
0
 public void SendMouseWheel(int x, int y, int delta, bool isVertical)
 {
     if (this.Browser != null)
     {
         var host       = this.Browser.GetHost();
         var mouseEvent = new CefMouseEvent {
             X = x, Y = y
         };
         host.SendMouseWheelEvent(mouseEvent, isVertical ? delta : 0, !isVertical ? delta : 0);
     }
 }
Ejemplo n.º 10
0
        //处理鼠标移动的消息
        private static void HandleMouseMotionEvent(SDL_MouseMotionEvent mouseMotionEvent)
        {
            CefMouseEvent mouseEvent = new CefMouseEvent();

            mouseEvent.X = mouseMotionEvent.x;
            mouseEvent.Y = mouseMotionEvent.y;
            _host.SendMouseMoveEvent(mouseEvent, false);
            //这里暂不处理器modifier
            //mouseEvent.Modifiers=mouseMotionEvent.state.
            //return mouseEvent;
        }
Ejemplo n.º 11
0
        //private readonly CefMouseButtonType[] cefMouseButtons = { CefMouseButtonType.Left, CefMouseButtonType.Right, CefMouseButtonType.Middle };

        void Update()
        {
            if (shouldQuit)
            {
                return;
            }

            var p = Input.mousePosition;
            int i = 0;  //  use only left mouse button

            if (!prevMousePos.Equals(p))
            {
                var e = new CefMouseEvent {
                    X         = (int)p.x,
                    Y         = windowHeight - (int)p.y,
                    Modifiers = Input.GetMouseButtonDown(i) ? CefEventFlags.LeftMouseButton : 0
                };

                cefClient.SendMouseMove(e);
                prevMousePos = p;
            }
            if (Input.GetMouseButtonDown(i))
            {
                cefClient.SendMouseClick((int)p.x, windowHeight - (int)p.y, CefMouseButtonType.Left, false);
            }
            if (Input.GetMouseButtonUp(i))
            {
                cefClient.SendMouseClick((int)p.x, windowHeight - (int)p.y, CefMouseButtonType.Left, true);
            }

            //foreach (char code in Input.inputString)
            //{
            //    var ev = new CefKeyEvent
            //    {
            //        WindowsKeyCode = code,
            //        NativeKeyCode = code,
            //        EventType = CefKeyEventType.KeyDown
            //    };
            //    cefClient.SendKey(ev);
            //    ev.EventType = CefKeyEventType.Char;
            //    cefClient.SendKey(ev);
            //    ev.EventType = CefKeyEventType.KeyUp;
            //    cefClient.SendKey(ev);
            //}
        }
Ejemplo n.º 12
0
        public void SendMouseMove(int x, int y, CefMouseButtonType button)
        {
            if (this.Browser != null)
            {
                var host       = this.Browser.GetHost();
                var mouseEvent = new CefMouseEvent {
                    X = x, Y = y
                };
                if (button == CefMouseButtonType.Left)
                {
                    mouseEvent.Modifiers = CefEventFlags.LeftMouseButton;
                }
                else if (button == CefMouseButtonType.Middle)
                {
                    mouseEvent.Modifiers = CefEventFlags.MiddleMouseButton;
                }
                else if (button == CefMouseButtonType.Right)
                {
                    mouseEvent.Modifiers = CefEventFlags.RightMouseButton;
                }

                host.SendMouseMoveEvent(mouseEvent, false);
            }
        }
Ejemplo n.º 13
0
        public void MouseMoveEvent(int x, int y, MouseButton button)
        {
            CefMouseEvent mouseEvent = new CefMouseEvent()
            {
                X = x,
                Y = y,
            };
            CefEventFlags modifiers = new CefEventFlags();

            if (button == MouseButton.Left)
            {
                modifiers |= CefEventFlags.LeftMouseButton;
            }
            if (button == MouseButton.Right)
            {
                modifiers |= CefEventFlags.RightMouseButton;
            }
            if (button == MouseButton.Middle)
            {
                modifiers |= CefEventFlags.MiddleMouseButton;
            }
            mouseEvent.Modifiers = modifiers;
            _lifespanHandler.MainBrowser.GetHost().SendMouseMoveEvent(mouseEvent, false);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Send a mouse wheel event to the browser. The |x| and |y| coordinates are
 /// relative to the upper-left corner of the view. The |deltaX| and |deltaY|
 /// values represent the movement delta in the X and Y directions respectively.
 /// In order to scroll inside select popups with window rendering disabled
 /// CefRenderHandler::GetScreenPoint should be implemented properly.
 /// </summary>
 public void SendMouseWheelEvent(CefMouseEvent @event, int deltaX, int deltaY)
 {
     BrowserHost?.SendMouseWheelEvent(@event, deltaX, deltaY);
 }
Ejemplo n.º 15
0
        public CefController()
        {
            Tick += (sender, args) =>
            {
                if (ShowCursor)
                {
                    Game.DisableAllControlsThisFrame(0);
                    if (CefUtil.DISABLE_CEF)
                    {
                        Function.Call(Hash._SHOW_CURSOR_THIS_FRAME);
                    }
                }
                else
                {
                    return;
                }

                var res    = GTA.UI.Screen.Resolution;
                var mouseX = Function.Call <float>(Hash.GET_DISABLED_CONTROL_NORMAL, 0, (int)GTA.Control.CursorX) * res.Width;
                var mouseY = Function.Call <float>(Hash.GET_DISABLED_CONTROL_NORMAL, 0, (int)GTA.Control.CursorY) * res.Height;

                _lastMousePoint = new PointF(mouseX, mouseY);

                if (CEFManager._cursor != null)
                {
                    CEFManager._cursor.Location = new Point((int)mouseX, (int)mouseY);
                }


                var mouseDown   = Game.IsDisabledControlJustPressed(0, GTA.Control.CursorAccept);
                var mouseDownRN = Game.IsDisabledControlPressed(0, GTA.Control.CursorAccept);
                var mouseUp     = Game.IsDisabledControlJustReleased(0, GTA.Control.CursorAccept);

                var rmouseDown   = Game.IsDisabledControlJustPressed(0, GTA.Control.CursorCancel);
                var rmouseDownRN = Game.IsDisabledControlPressed(0, GTA.Control.CursorCancel);
                var rmouseUp     = Game.IsDisabledControlJustReleased(0, GTA.Control.CursorCancel);

                var wumouseDown = Game.IsDisabledControlPressed(0, GTA.Control.CursorScrollUp);
                var wdmouseDown = Game.IsDisabledControlPressed(0, GTA.Control.CursorScrollDown);

                if (!CefUtil.DISABLE_CEF)
                {
                    foreach (var browser in CEFManager.Browsers)
                    {
                        if (!browser.IsInitialized())
                        {
                            continue;
                        }

                        if (!browser._hasFocused)
                        {
                            browser._browser.GetHost().SetFocus(true);

                            browser._browser.GetHost().SetFocus(true);
                            browser._browser.GetHost().SendFocusEvent(true);
                            browser._hasFocused = true;
                        }

                        if (mouseX > browser.Position.X && mouseY > browser.Position.Y &&
                            mouseX < browser.Position.X + browser.Size.Width &&
                            mouseY < browser.Position.Y + browser.Size.Height)
                        {
                            var ev = new CefMouseEvent((int)(mouseX - browser.Position.X), (int)(mouseY - browser.Position.Y),
                                                       GetMouseModifiers(mouseDownRN, rmouseDownRN));

                            browser._browser
                            .GetHost()
                            .SendMouseMoveEvent(ev, false);

                            if (mouseDown)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseClickEvent(ev, CefMouseButtonType.Left, false, 1);
                            }

                            if (mouseUp)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseClickEvent(ev, CefMouseButtonType.Left, true, 1);
                            }

                            if (rmouseDown)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseClickEvent(ev, CefMouseButtonType.Right, false, 1);
                            }

                            if (rmouseUp)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseClickEvent(ev, CefMouseButtonType.Right, true, 1);
                            }

                            if (wdmouseDown)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseWheelEvent(ev, 0, -30);
                            }

                            if (wumouseDown)
                            {
                                browser._browser
                                .GetHost()
                                .SendMouseWheelEvent(ev, 0, 30);
                            }
                        }
                    }
                }
            };

            KeyDown += (sender, args) =>
            {
                if (!ShowCursor)
                {
                    return;
                }

                if (_justShownCursor && Util.Util.TickCount - _lastShownCursor < 500)
                {
                    _justShownCursor = false;
                    return;
                }

                if (!CefUtil.DISABLE_CEF)
                {
                    foreach (var browser in CEFManager.Browsers)
                    {
                        if (!browser.IsInitialized())
                        {
                            continue;
                        }

                        CefEventFlags mod = CefEventFlags.None;
                        if (args.Control)
                        {
                            mod |= CefEventFlags.ControlDown;
                        }
                        if (args.Shift)
                        {
                            mod |= CefEventFlags.ShiftDown;
                        }
                        if (args.Alt)
                        {
                            mod |= CefEventFlags.AltDown;
                        }

                        CefKeyEvent kEvent = new CefKeyEvent
                        {
                            EventType      = CefKeyEventType.KeyDown,
                            Modifiers      = mod,
                            WindowsKeyCode = (int)args.KeyCode,
                            NativeKeyCode  = (int)args.KeyValue
                        };
                        browser._browser.GetHost().SendKeyEvent(kEvent);

                        CefKeyEvent charEvent = new CefKeyEvent
                        {
                            EventType = CefKeyEventType.Char
                        };

                        var key = args.KeyCode;

                        if ((key == Keys.ShiftKey && _lastKey == Keys.Menu) ||
                            (key == Keys.Menu && _lastKey == Keys.ShiftKey))
                        {
                            ClassicChat.ActivateKeyboardLayout(1, 0);
                            return;
                        }

                        _lastKey = key;

                        if (key == Keys.Escape)
                        {
                            return;
                        }

                        var keyChar = ClassicChat.GetCharFromKey(key, Game.IsKeyPressed(Keys.ShiftKey), Game.IsKeyPressed(Keys.Menu) && Game.IsKeyPressed(Keys.ControlKey));

                        if (keyChar.Length == 0 || keyChar[0] == 27)
                        {
                            return;
                        }

                        charEvent.WindowsKeyCode = keyChar[0];
                        charEvent.Modifiers      = mod;
                        browser._browser.GetHost().SendKeyEvent(charEvent);
                    }
                }
            };

            KeyUp += (sender, args) =>
            {
                if (!CefUtil.DISABLE_CEF)
                {
                    if (!ShowCursor)
                    {
                        return;
                    }
                    foreach (var browser in CEFManager.Browsers)
                    {
                        if (!browser.IsInitialized())
                        {
                            continue;
                        }

                        CefKeyEvent kEvent = new CefKeyEvent
                        {
                            EventType      = CefKeyEventType.KeyUp,
                            WindowsKeyCode = (int)args.KeyCode
                        };
                        browser._browser.GetHost().SendKeyEvent(kEvent);
                    }
                }
            };
        }
Ejemplo n.º 16
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;
            };
        }
Ejemplo n.º 17
0
 private void MouseMoveEvent(CefMouseEvent mouseEvent)
 {
     browserHost.SendMouseMoveEvent(mouseEvent, false);
 }
Ejemplo n.º 18
0
 private void MouseClickEvent(CefMouseEvent mouseEvent, int clickCount, CefMouseButtonType button, bool mouseUp)
 {
     browserHost.SendMouseClickEvent(mouseEvent, button, mouseUp, clickCount);
 }
Ejemplo n.º 19
0
 private void MouseScrollEvent(CefMouseEvent mouseEvent, int scroll)
 {
     browserHost.SendMouseWheelEvent(mouseEvent, 0, scroll);
 }
Ejemplo n.º 20
0
    void Update()
    {
        if (InstanceManager.Instance == null)
        {
            return;
        }

        if (!_initialized && InstanceManager.Instance.IsReady())
        {
            CefInstance  = InstanceManager.Instance.CreateCefInstance(Screen.width, Screen.height, URL);
            _initialized = true;
        }

        if (!CefInstance.IsInitialized)
        {
            return;
        }

        if (CaptureMouse)
        {
            CefMouseEvent cefMouseEvent;
            bool          updateMousePos = true;

            for (int i = 0; i < 2; i++)
            {
                bool newState = Input.GetMouseButton(i);

                if (newState != _mouseButtonStates[i])
                {
                    cefMouseEvent = new CefMouseEvent()
                    {
                        InstanceID      = CefInstance.InstanceID,
                        MouseButton     = i,
                        MouseButtonDown = newState,
                        MouseX          = (int)Input.mousePosition.x,
                        MouseY          = Screen.height - (int)Input.mousePosition.y,
                        ScollDeltaX     = (int)Input.mouseScrollDelta.x,
                        ScollDeltaY     = (int)Input.mouseScrollDelta.y,
                    };

                    _mouseButtonStates[i] = newState;
                    InstanceManager.Instance.SendEvent(cefMouseEvent);

                    updateMousePos = false;
                }
            }

            if (updateMousePos && (_lastMousePoint != Input.mousePosition || (Input.mouseScrollDelta.x != 0 || Input.mouseScrollDelta.y != 0)))
            {
                cefMouseEvent = new CefMouseEvent()
                {
                    InstanceID      = CefInstance.InstanceID,
                    MouseButton     = -1,
                    MouseButtonDown = false,
                    MouseX          = (int)Input.mousePosition.x,
                    MouseY          = Screen.height - (int)Input.mousePosition.y,
                    ScollDeltaX     = (int)Input.mouseScrollDelta.x,
                    ScollDeltaY     = (int)Input.mouseScrollDelta.y,
                };

                InstanceManager.Instance.SendEvent(cefMouseEvent);
                _lastMousePoint = Input.mousePosition;
            }
        }

        if (CaptureKeyboard)
        {
            if (Input.GetKeyDown(KeyCode.CapsLock))
            {
                _capslock = !_capslock;
            }
        }
    }
Ejemplo n.º 21
0
 /// <summary>
 /// Call this method when the user completes the drag operation by dropping
 /// the object onto the web view (after calling DragTargetDragEnter).
 /// The object being dropped is |drag_data|, given as an argument to
 /// the previous DragTargetDragEnter call.
 /// This method is only used when window rendering is disabled.
 /// </summary>
 public void DragTargetDrop(CefMouseEvent mouseEvent)
 {
     BrowserHost?.DragTargetDrop(mouseEvent);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Call this method each time the mouse is moved across the web view during
 /// a drag operation (after calling DragTargetDragEnter and before calling
 /// DragTargetDragLeave/DragTargetDrop).
 /// This method is only used when window rendering is disabled.
 /// </summary>
 public void DragTargetDragOver(CefMouseEvent mouseEvent, CefDragOperationsMask allowedOps)
 {
     BrowserHost?.DragTargetDragOver(mouseEvent, allowedOps);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Call this method when the user drags the mouse into the web view (before
 /// calling DragTargetDragOver/DragTargetLeave/DragTargetDrop).
 /// |drag_data| should not contain file contents as this type of data is not
 /// allowed to be dragged into the web view. File contents can be removed using
 /// CefDragData::ResetFileContents (for example, if |drag_data| comes from
 /// CefRenderHandler::StartDragging).
 /// This method is only used when window rendering is disabled.
 /// </summary>
 public void DragTargetDragEnter(CefDragData dragData, CefMouseEvent mouseEvent, CefDragOperationsMask allowedOps)
 {
     BrowserHost?.DragTargetDragEnter(dragData, mouseEvent, allowedOps);
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Send a mouse move event to the browser. The |x| and |y| coordinates are
 /// relative to the upper-left corner of the view.
 /// </summary>
 public void SendMouseMoveEvent(CefMouseEvent @event, bool mouseLeave)
 {
     BrowserHost?.SendMouseMoveEvent(@event, mouseLeave);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Send a mouse click event to the browser. The |x| and |y| coordinates are
 /// relative to the upper-left corner of the view.
 /// </summary>
 public void SendMouseClickEvent(CefMouseEvent @event, CefMouseButtonType type, bool mouseUp, int clickCount)
 {
     BrowserHost?.SendMouseClickEvent(@event, type, mouseUp, clickCount);
 }
Ejemplo n.º 26
0
        public void ReceiveEvent(CefEvent cefEvent)
        {
            #region Handle mouse event

            if (cefEvent is CefMouseEvent)
            {
                CefMouseEvent cefMouseEvent = (CefMouseEvent)cefEvent;
                MouseEvent    mouseEvent;
                CefEventFlags mouseEventFlags = CefEventFlags.None;

                if (cefMouseEvent.MouseButton != -1)
                {
                    MouseButtonType pressedButton;

                    switch (cefMouseEvent.MouseButton)
                    {
                    case 0:
                        pressedButton   = MouseButtonType.Left;
                        mouseEventFlags = CefEventFlags.LeftMouseButton;
                        break;

                    case 1:
                        pressedButton   = MouseButtonType.Right;
                        mouseEventFlags = CefEventFlags.RightMouseButton;
                        break;

                    case 2:
                        pressedButton   = MouseButtonType.Middle;
                        mouseEventFlags = CefEventFlags.MiddleMouseButton;
                        break;

                    default:
                        pressedButton   = MouseButtonType.Left;
                        mouseEventFlags = CefEventFlags.LeftMouseButton;
                        break;
                    }

                    mouseEvent = new MouseEvent(cefMouseEvent.MouseX, cefMouseEvent.MouseY, mouseEventFlags);

                    _browser.GetBrowser().GetHost().SendMouseClickEvent(mouseEvent, pressedButton, !cefMouseEvent.MouseButtonDown, 1);
                }

                mouseEvent = new MouseEvent(cefMouseEvent.MouseX, cefMouseEvent.MouseY, mouseEventFlags);

                if (cefMouseEvent.ScollDeltaX != 0 || cefMouseEvent.ScollDeltaY != 0)
                {
                    _browser.GetBrowser().GetHost().SendMouseWheelEvent(mouseEvent, cefMouseEvent.ScollDeltaX * 100, cefMouseEvent.ScollDeltaY * 100);
                }

                if (cefMouseEvent.MouseButton != -1)
                {
                    return;
                }

                _browser.GetBrowser().GetHost().SendMouseMoveEvent(mouseEvent, false);

                return;
            }

            #endregion

            #region Handle keyboard event

            if (cefEvent is CefKeyboardEvent)
            {
                CefKeyboardEvent cefKeyboardEvent = (CefKeyboardEvent)cefEvent;

                // handle
                KeyEvent keyEvent = new KeyEvent()
                {
                    Type                 = cefKeyboardEvent.IsChar ? KeyEventType.Char : (cefKeyboardEvent.IsDown ? KeyEventType.KeyDown : KeyEventType.KeyUp),
                    WindowsKeyCode       = cefKeyboardEvent.IsChar ? GetCharsFromKeys(cefKeyboardEvent.Key, cefKeyboardEvent.Shift)[0] : cefKeyboardEvent.Key,
                    FocusOnEditableField = true,
                    Modifiers            = cefKeyboardEvent.Shift ? CefEventFlags.ShiftDown : CefEventFlags.None,
                    IsSystemKey          = false
                };

                _browser.GetBrowser().GetHost().SendKeyEvent(keyEvent);

                return;
            }

            #endregion

            #region Handle javascript event

            if (cefEvent is CefEvalJavascriptEvent)
            {
                CefEvalJavascriptEvent javascriptEvent = (CefEvalJavascriptEvent)cefEvent;

                if (javascriptEvent.CallbackID.Length > 0)
                {
                    Task <JavascriptResponse> task = _browser.EvaluateScriptAsync(javascriptEvent.Javascript);
                    task.ContinueWith(result => SendCallback(javascriptEvent, result.Result.Result.ToString()));

                    return;
                }

                _browser.EvaluateScriptAsync(javascriptEvent.Javascript);

                return;
            }

            #endregion

            #region Handle static call result event

            if (cefEvent is CefJavascriptResultEvent)
            {
                _staticBinding.HandleEvent((CefJavascriptResultEvent)cefEvent);

                return;
            }

            #endregion
        }