protected virtual void OnCurrentHwndSourceChanged(DependencyPropertyChangedEventArgs e) { Initialize(); // Unregister the old keyboard input site. IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite; if (keyboardInputSite != null) { ((IKeyboardInputSink)this).KeyboardInputSite = null; keyboardInputSite.Unregister(); } // Register the new keyboard input site with the containing // HwndSource. IKeyboardInputSink sink = CurrentHwndSource; if (sink != null) { ((IKeyboardInputSink)this).KeyboardInputSite = sink.RegisterKeyboardInputSink(this); } // Set the owner of the RedirectedWindow to our CurrentHwndSource. // This keeps the RedirectedWindow on top of the HwndSource. if (CurrentHwndSource != null) { HWND hwndSource = new HWND(CurrentHwndSource.Handle); HWND hwndRoot = hwndSource; // User32NativeMethods.GetAncestor(hwndSource, GA.ROOT); // need to get the top-level window? NativeMethods.SetWindowLongPtr( _redirectedWindow.Handle, GWL.HWNDPARENT, hwndRoot.DangerousGetHandle()); } }
protected virtual void UnregisterSourceKeyboardInputSink() { IKeyboardInputSink keyboardInputSink = this; if (keyboardInputSink.KeyboardInputSite != null) { keyboardInputSink.KeyboardInputSite.Unregister(); } }
protected virtual void RegisterSourceKeyboardInputSink(IKeyboardInputSink sourceKeyboardInputSink) { IKeyboardInputSink keyboardInputSink = this; if (sourceKeyboardInputSink != null) { keyboardInputSink.KeyboardInputSite = sourceKeyboardInputSink.RegisterKeyboardInputSink(this); } }
private void OnSourceChanged(object sender, SourceChangedEventArgs e) { IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite; if (keyboardInputSite != null) { ((IKeyboardInputSink)this).KeyboardInputSite = null; keyboardInputSite.Unregister(); } IKeyboardInputSink sink = source as IKeyboardInputSink; if (sink != null) { ((IKeyboardInputSink)this).KeyboardInputSite = sink.RegisterKeyboardInputSink(this); } source = e.NewSource; if (!isBuildingWindow) { isBuildingWindow = true; HwndSource parent = (HwndSource)e.NewSource; try { if (hWnd.Handle == IntPtr.Zero) { hWnd = new HandleRef(this, ((INativeHandleContract)contract.Contract).GetHandle()); LayoutUpdated += OnLayoutUpdated; IsEnabledChanged += OnEnabledChanged; IsVisibleChanged += OnVisibleChanged; PostMessage(new HandleRef(null, Handle), 0x9005, parent.Handle, IntPtr.Zero); PostMessage(new HandleRef(null, Handle), 0x9002, IntPtr.Zero, IntPtr.Zero); InvalidateMeasure(); } } finally { isBuildingWindow = false; } } else { Debug.Assert(false); } }
private void OnSourceChanged(object sender, SourceChangedEventArgs e) { IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite; if (keyboardInputSite != null) { if (this._fTrusted.Value) { new UIPermission(PermissionState.Unrestricted).Assert(); } try { ((IKeyboardInputSink)this).KeyboardInputSite = null; keyboardInputSite.Unregister(); } finally { if (this._fTrusted.Value) { CodeAccessPermission.RevertAssert(); } } } IKeyboardInputSink keyboardInputSink = PresentationSource.CriticalFromVisual(this, false) as IKeyboardInputSink; if (keyboardInputSink != null) { if (this._fTrusted.Value) { new UIPermission(PermissionState.Unrestricted).Assert(); } try { ((IKeyboardInputSink)this).KeyboardInputSite = keyboardInputSink.RegisterKeyboardInputSink(this); } finally { if (this._fTrusted.Value) { CodeAccessPermission.RevertAssert(); } } } this.BuildOrReparentWindow(); }
public HwndSourceKeyboardInputSite(HwndSource source, IKeyboardInputSink sink) { if (source == null) { throw new ArgumentNullException("source"); } if (sink == null) { throw new ArgumentNullException("sink"); } if (!(sink is UIElement)) { throw new ArgumentException(SR.Get(SRID.KeyboardSinkMustBeAnElement), "sink"); } _source = source; _sink = sink; _sink.KeyboardInputSite = this; _sinkElement = sink as UIElement; }
public HwndSourceKeyboardInputSite(HwndSource source, IKeyboardInputSink sink) { if(source == null) { throw new ArgumentNullException("source"); } if(sink == null) { throw new ArgumentNullException("sink"); } if(!(sink is UIElement)) { throw new ArgumentException(SR.Get(SRID.KeyboardSinkMustBeAnElement), "sink"); } _source = source; _sink = sink; _sink.KeyboardInputSite = this; _sinkElement = sink as UIElement; }
protected override bool ProcessDialogKey(Keys keyData) { if (base.ProcessDialogKey(keyData) || OverrideTabStop == false || HwndHost == null) { return(true); } if ((keyData & (Keys.Alt | Keys.Control)) == Keys.None) { Keys keyCode = (Keys)keyData & Keys.KeyCode; if (keyCode == Keys.Tab) { IKeyboardInputSink sink = HwndHost; if (sink == null || sink.KeyboardInputSite == null) { return(false); } return(sink.KeyboardInputSite.OnNoMoreTabStops( new TraversalRequest((keyData & Keys.Shift) == Keys.None ? FocusNavigationDirection.Next : FocusNavigationDirection.Previous))); } } return(false); }
private void OnSourceChanged(object sender, SourceChangedEventArgs e) { // Remove ourselves as an IKeyboardInputSinks child of our previous // containing window. IKeyboardInputSite keyboardInputSite = ((IKeyboardInputSink)this).KeyboardInputSite; if (keyboardInputSite != null) { // Derived classes that implement IKeyboardInputSink should support setting it to null. ((IKeyboardInputSink)this).KeyboardInputSite = null; keyboardInputSite.Unregister(); } // Add ourselves as an IKeyboardInputSinks child of our containing window. IKeyboardInputSink source = PresentationSource.CriticalFromVisual(this, false /* enable2DTo3DTransition */) as IKeyboardInputSink; if (source != null) { ((IKeyboardInputSink)this).KeyboardInputSite = source.RegisterKeyboardInputSink(this); } BuildOrReparentWindow(); }
protected IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { CheckDisposed(true); if (sink == null) { throw new ArgumentNullException("sink"); } if (sink.KeyboardInputSite != null) { throw new ArgumentException(SR.Get(SRID.KeyboardSinkAlreadyOwned)); } HwndSourceKeyboardInputSite site = new HwndSourceKeyboardInputSite(this, sink); if (_keyboardInputSinkChildren == null) _keyboardInputSinkChildren = new List<HwndSourceKeyboardInputSite>(); _keyboardInputSinkChildren.Add(site); return site; }
protected virtual new IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { return default(IKeyboardInputSite); }
IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { return default(IKeyboardInputSite); }
IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { return(RegisterKeyboardInputSinkCore(sink)); }
// General security note on the implementation pattern of this interface. In Dev10 it was chosen // to expose the interface implementation for overriding to customers. We did so by keeping the // explicit interface implementations (that do have the property of being hidden from the public // contract, which limits IntelliSense on derived types like WebBrowser) while sticking protected // virtuals next to them. Those virtuals contain our base implementation, while the explicit // interface implementation methods do call trivially into the virtuals. // // This comment outlines the security rationale applied to those methods. // // <SecurityNote Name="IKeyboardInputSink_Implementation"> // The security attributes on the virtual methods within this region mirror the corresponding // IKeyboardInputSink methods; customers can override those methods, so we insert a LinkDemand // to encourage them to have a LinkDemand too (via FxCop). /// <summary> /// Registers a IKeyboardInputSink with the HwndSource in order /// to retreive a unique IKeyboardInputSite for it. /// </summary> protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { throw new InvalidOperationException(SR.Get(SRID.HwndHostDoesNotSupportChildKeyboardSinks)); }
protected virtual new IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { return(default(IKeyboardInputSite)); }
IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { return(default(IKeyboardInputSite)); }
IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { throw new NotSupportedException(); }
protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { throw new InvalidOperationException("RedirectedHwndHost does not support child keyboard sinks be default."); }
public IKeyboardInputSite RegisterKeyboardInputSink(IKeyboardInputSink sink) { throw new InvalidOperationException("HwndHostDoesNotSupportChildKeyboardSinks"); }
private async void wvMain_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e) { try { tbUrl.Text = wvMain.Source.AbsoluteUri; string title = wvMain.CoreWebView2.DocumentTitle; Global.MainWindow.Title = "ArtSoftWebBrowser2019 " + title; string url = wvMain.Source.AbsoluteUri; if (wvMain.Source.Host == "www.google.pl") { string[] lpa = wvMain.Source.AbsoluteUri.Split(new char[] { '#' }); url = lpa[0]; } Global.Link = Global.DataBase.Link.Where(l => l.Url == url).FirstOrDefault(); if (Global.Link == null) { Global.Link = new Link(); Global.Link.Name = title.Substring(0, Math.Min(title.Length, 50)); Global.Link.Url = wvMain.Source.AbsoluteUri; Global.Link.Type = string.Empty; Global.Link.Description = string.Empty; Global.Link.Path = string.Empty; Global.Link.Added = false; Global.Link.Active = false; Global.Link.Loaded = DateTime.Now; Global.Link.Time = 0; Global.DataBase.Link.Add(Global.Link); } Global.Link.Opened = DateTime.Now; Global.DataBase.SaveChanges(); Global.Info = new Info(); Global.Info.Opened = DateTime.Now; Global.Info.Ticked = DateTime.Now; Global.Info.Time = 0; await wvMain.EnsureCoreWebView2Async(null); wvMain.CoreWebView2.AddHostObjectToScript("linkhandler", new LinkHandler()); string script = ""; script += "const lh = chrome.webview.hostObjects.linkhandler;"; script += "var links = document.getElementsByTagName('a');"; script += "for (var i = 0; i < links.length; i++)"; script += "{"; script += " var link = links[i];"; script += " link.onmouseover = function(e){ lh.OnMouseOver(e.srcElement.href, e.screenY, e.screenX) };"; script += " link.onmouseout = function(){ lh.OnMouseOut() };"; script += "}"; await wvMain.ExecuteScriptAsync(script); string cs = GetStatusText(Global.Link); lblStatus.Content = cs; IKeyboardInputSink kis = Global.Browser.wvMain; kis.TabInto(new TraversalRequest(FocusNavigationDirection.First)); Dispatcher.Invoke(delegate() { cbTime.IsChecked = true; }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
protected override void RegisterSourceKeyboardInputSink(IKeyboardInputSink sourceKeyboardInputSink) { }
IKeyboardInputSite IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { return RegisterKeyboardInputSinkCore(sink); }
protected virtual IKeyboardInputSite RegisterKeyboardInputSinkCore(IKeyboardInputSink sink) { throw new InvalidOperationException(SR.Get(SRID.HwndHostDoesNotSupportChildKeyboardSinks)); }
IKeyboardInputSite System.Windows.Interop.IKeyboardInputSink.RegisterKeyboardInputSink(IKeyboardInputSink sink) { throw new NotSupportedException(); }