/// <summary> /// Sends a mouse wheel 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="deltaX">A movement delta in the X direction.</param> /// <param name="deltaY">A movement delta in the Y direction.</param> public void SendMouseWheelEvent(int x, int y, int deltaX, int deltaY) { CefBrowserHost browserHost = this.BrowserObject?.Host; if (browserHost == null) { return; } InitMouseEvent(x, y, CefEventFlags.None); browserHost.SendMouseWheelEvent(_mouseEventProxy, deltaX, deltaY); }
protected override bool OnMouseWheel(int delta) { bool result = base.OnMouseWheel(delta); if (IsEnabledInHierarchy() && browserHost != null && new Rect(0, 0, 1, 1).IsContainsPoint(MousePosition)) { try { browserHost.SendMouseWheelEvent(GetCurrentMouseEvent(), 0, delta); } catch (Exception ex) { Log.Error("WebBrowserControl: Caught exception in OnMouseWheel(): " + ex.Message); } } return(result); }
protected override bool OnMouseWheel(int delta) { bool result = base.OnMouseWheel(delta); if (EnabledInHierarchy && VisibleInHierarchy && browserHost != null && new Rectangle(0, 0, 1, 1).Contains(MousePosition)) { try { browserHost.SendMouseWheelEvent(GetCurrentMouseEvent(), 0, delta); } catch (Exception ex) { Log.Error("UIWebBrowser: Caught exception in OnMouseWheel: " + ex.Message); } } return(result); }
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; }; }
private void MouseScrollEvent(CefMouseEvent mouseEvent, int scroll) { browserHost.SendMouseWheelEvent(mouseEvent, 0, scroll); }