Browse Source

Revert "Make sure Popups do not attempt to take focus when they are shown (#16365)"

This reverts commit 80d73e4411.
customers/outsystems-11.1.x-without-2-prs-for-testing
Steven Kirk 1 year ago
parent
commit
9678bbacbe
  1. 17
      native/Avalonia.Native/src/OSX/AvnView.mm
  2. 28
      src/Avalonia.Native/PopupImpl.cs
  3. 2
      src/Avalonia.Native/TopLevelImpl.cs
  4. 19
      src/Windows/Avalonia.Win32/PopupImpl.cs

17
native/Avalonia.Native/src/OSX/AvnView.mm

@ -297,22 +297,7 @@
) )
) )
) )
{ [self becomeFirstResponder];
WindowBaseImpl* windowBase = dynamic_cast<WindowBaseImpl*>(_parent.getRaw());
if(windowBase != nullptr){
WindowBaseImpl* parent = windowBase->Parent;
if(parent != nullptr){
auto parentWindow = parent->Window;
[parentWindow makeFirstResponder:parent->View];
}
} else{
[self becomeFirstResponder];
}
}
if(_parent != nullptr) if(_parent != nullptr)
{ {

28
src/Avalonia.Native/PopupImpl.cs

@ -8,6 +8,8 @@ namespace Avalonia.Native
class PopupImpl : WindowBaseImpl, IPopupImpl class PopupImpl : WindowBaseImpl, IPopupImpl
{ {
private readonly ITopLevelImpl _parent; private readonly ITopLevelImpl _parent;
private readonly IAvnPopup _native;
private readonly AvaloniaNativeTextInputMethod _inputMethod;
public PopupImpl(IAvaloniaNativeFactory factory, public PopupImpl(IAvaloniaNativeFactory factory,
ITopLevelImpl parent) : base(factory) ITopLevelImpl parent) : base(factory)
@ -16,7 +18,7 @@ namespace Avalonia.Native
using (var e = new PopupEvents(this)) using (var e = new PopupEvents(this))
{ {
Init(new MacOSTopLevelHandle(factory.CreatePopup(e)), factory.CreateScreens()); Init(new MacOSTopLevelHandle(_native = factory.CreatePopup(e)), factory.CreateScreens());
} }
PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize)); PopupPositioner = new ManagedPopupPositioner(new ManagedPopupPositionerPopupImplHelper(parent, MoveResize));
@ -26,15 +28,10 @@ namespace Avalonia.Native
parent = popupImpl._parent; parent = popupImpl._parent;
} }
if (parent is WindowBaseImpl windowBaseImpl)
{
Native!.SetParent(windowBaseImpl.Native);
}
//Use the parent's input context to process events //Use the parent's input context to process events
if (parent is TopLevelImpl topLevelImpl) if (parent is TopLevelImpl topLevelImpl)
{ {
InputMethod = topLevelImpl.InputMethod; _inputMethod = topLevelImpl.InputMethod;
} }
} }
@ -43,13 +40,6 @@ namespace Avalonia.Native
base.Init(handle, screens); base.Init(handle, screens);
} }
public override void Dispose()
{
Native!.SetParent(null);
base.Dispose();
}
private void MoveResize(PixelPoint position, Size size, double scaling) private void MoveResize(PixelPoint position, Size size, double scaling)
{ {
Position = position; Position = position;
@ -81,6 +71,16 @@ namespace Avalonia.Native
} }
} }
public override void Show(bool activate, bool isDialog)
{
var parent = _parent;
while (parent is PopupImpl p)
parent = p._parent;
if (parent is WindowImpl w)
w.Native.TakeFocusFromChildren();
base.Show(false, isDialog);
}
public override IPopupImpl CreatePopup() => new PopupImpl(Factory, this); public override IPopupImpl CreatePopup() => new PopupImpl(Factory, this);
public void SetWindowManagerAddShadowHint(bool enabled) public void SetWindowManagerAddShadowHint(bool enabled)

2
src/Avalonia.Native/TopLevelImpl.cs

@ -110,7 +110,7 @@ internal class TopLevelImpl : ITopLevelImpl, IFramebufferPlatformSurface
public IAvnTopLevel? Native => _handle?.Native; public IAvnTopLevel? Native => _handle?.Native;
public IPlatformHandle? Handle => _handle; public IPlatformHandle? Handle => _handle;
public AvaloniaNativeTextInputMethod? InputMethod { get; protected set; } public AvaloniaNativeTextInputMethod? InputMethod { get; private set; }
public Size ClientSize public Size ClientSize
{ {
get get

19
src/Windows/Avalonia.Win32/PopupImpl.cs

@ -22,6 +22,25 @@ namespace Avalonia.Win32
{ {
// Popups are always shown non-activated. // Popups are always shown non-activated.
UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate); UnmanagedMethods.ShowWindow(Handle.Handle, UnmanagedMethods.ShowWindowCommand.ShowNoActivate);
// We need to steal focus if it's held by a child window of our toplevel window
var parent = _parent;
while(parent != null)
{
if(parent is PopupImpl pi)
parent = pi._parent;
else
break;
}
if(parent == null)
return;
var focusOwner = UnmanagedMethods.GetFocus();
if (focusOwner != IntPtr.Zero &&
UnmanagedMethods.GetAncestor(focusOwner, UnmanagedMethods.GetAncestorFlags.GA_ROOT)
== parent.Handle?.Handle)
UnmanagedMethods.SetFocus(parent.Handle.Handle);
} }
protected override bool ShouldTakeFocusOnClick => false; protected override bool ShouldTakeFocusOnClick => false;

Loading…
Cancel
Save