Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Introduce native TopLevelImpl #15800

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
183919D91DB9AAB5D700C2EA /* WindowImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 18391CD090AA776E7E841AC9 /* WindowImpl.h */; };
18391AA7E0BBA74D184C5734 /* AutoFitContentView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839166350F32661F3ABD70F /* AutoFitContentView.mm */; };
18391AC16726CBC45856233B /* AvnWindow.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839155B28B20FFB672D29C6 /* AvnWindow.mm */; };
18391AC65ADD7DDD33FBE737 /* PopupImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 183910513F396141938832B5 /* PopupImpl.h */; };
18391C28BF1823B5464FDD36 /* ResizeScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 1839171D898F9BFC1373631A /* ResizeScope.h */; };
18391CF07316F819E76B617C /* IWindowStateChanged.h in Headers */ = {isa = PBXBuildFile; fileRef = 183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */; };
18391D4EB311BC7EF8B8C0A6 /* AvnView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1839132D0E2454D911F1D1F9 /* AvnView.mm */; };
Expand Down Expand Up @@ -61,10 +60,11 @@
ED3791C42862E1F40080BD62 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED3791C32862E1F40080BD62 /* UniformTypeIdentifiers.framework */; };
ED754D262A97306B0078B4DF /* PlatformRenderTimer.mm in Sources */ = {isa = PBXBuildFile; fileRef = ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */; };
EDF8CDCD2964CB01001EE34F /* PlatformSettings.mm in Sources */ = {isa = PBXBuildFile; fileRef = EDF8CDCC2964CB01001EE34F /* PlatformSettings.mm */; };
F10084842BFF1F9E0024303E /* TopLevelImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = F10084832BFF1F9E0024303E /* TopLevelImpl.h */; };
F10084862BFF1FB40024303E /* TopLevelImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = F10084852BFF1FB40024303E /* TopLevelImpl.mm */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
183910513F396141938832B5 /* PopupImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PopupImpl.h; sourceTree = "<group>"; };
1839122E037567BDD1D09DEB /* WindowProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowProtocol.h; sourceTree = "<group>"; };
1839132D0E2454D911F1D1F9 /* AvnView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AvnView.mm; sourceTree = "<group>"; };
183913C6BFD6856BD42D19FD /* IWindowStateChanged.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IWindowStateChanged.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -125,6 +125,8 @@
ED3791C32862E1F40080BD62 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformRenderTimer.mm; sourceTree = "<group>"; };
EDF8CDCC2964CB01001EE34F /* PlatformSettings.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformSettings.mm; sourceTree = "<group>"; };
F10084832BFF1F9E0024303E /* TopLevelImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TopLevelImpl.h; sourceTree = "<group>"; };
F10084852BFF1FB40024303E /* TopLevelImpl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TopLevelImpl.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -164,9 +166,11 @@
AB7A61E62147C814003C5833 = {
isa = PBXGroup;
children = (
F10084852BFF1FB40024303E /* TopLevelImpl.mm */,
ED754D252A97306B0078B4DF /* PlatformRenderTimer.mm */,
855EDC9E28C6546F00807998 /* PlatformBehaviorInhibition.mm */,
8D2F3511292F6AAE007FCF54 /* AvnTextInputMethodDelegate.h */,
F10084832BFF1F9E0024303E /* TopLevelImpl.h */,
8D300D68292E1E5D00320C49 /* AvnTextInputMethod.mm */,
8D300D64292D0A6800320C49 /* AvnTextInputMethod.h */,
BC11A5BC2608D58F0017BAD0 /* automation.h */,
Expand Down Expand Up @@ -214,7 +218,6 @@
1839155B28B20FFB672D29C6 /* AvnWindow.mm */,
18391DB45C7D892E61BF388C /* WindowInterfaces.h */,
18391BB698579F40F1783F31 /* PopupImpl.mm */,
183910513F396141938832B5 /* PopupImpl.h */,
64B1EBEECBE13D8616D7C934 /* metal.mm */,
64B1E4FA7D9D6E5F47AA8606 /* noarc.mm */,
64B1E26F2B1B9C577BF52F06 /* noarc.h */,
Expand All @@ -237,6 +240,7 @@
buildActionMask = 2147483647;
files = (
37155CE4233C00EB0034DCE9 /* menu.h in Headers */,
F10084842BFF1F9E0024303E /* TopLevelImpl.h in Headers */,
BC11A5BE2608D58F0017BAD0 /* automation.h in Headers */,
183916173528EC2737DBE5E1 /* WindowBaseImpl.h in Headers */,
1839171DCC651B0638603AC4 /* INSWindowHolder.h in Headers */,
Expand All @@ -249,7 +253,6 @@
18391E1381E2D5BFD60265A9 /* AutoFitContentView.h in Headers */,
18391F1E2411C79405A9943A /* WindowProtocol.h in Headers */,
183914E50CF6D2EFC1667F7C /* WindowInterfaces.h in Headers */,
18391AC65ADD7DDD33FBE737 /* PopupImpl.h in Headers */,
64B1ECA861163C0EFF0E502B /* noarc.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -332,6 +335,7 @@
AB00E4F72147CA920032A60A /* main.mm in Sources */,
37C09D8821580FE4006A6758 /* SystemDialogs.mm in Sources */,
1839179A55FC1421BEE83330 /* WindowBaseImpl.mm in Sources */,
F10084862BFF1FB40024303E /* TopLevelImpl.mm in Sources */,
1839125F057B0A4EB1760058 /* WindowImpl.mm in Sources */,
18391068E48EF96E3DB5FDAB /* ResizeScope.mm in Sources */,
18391D4EB311BC7EF8B8C0A6 /* AvnView.mm in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
version = "1.3">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
Expand Down
6 changes: 3 additions & 3 deletions native/Avalonia.Native/src/OSX/AvnView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

#import <AppKit/AppKit.h>
#include "common.h"
#include "WindowImpl.h"
#include "TopLevelImpl.h"
#include "KeyTransform.h"

@class AvnAccessibilityElement;
@protocol IRenderTarget;

@interface AvnView : NSView<NSTextInputClient, NSDraggingDestination, AvnTextInputMethodDelegate, CALayerDelegate>
-(AvnView* _Nonnull) initWithParent: (WindowBaseImpl* _Nonnull) parent;
-(AvnView* _Nonnull) initWithParent: (TopLevelImpl* _Nonnull) parent;
-(NSEvent* _Nonnull) lastMouseDownEvent;
-(AvnPoint) translateLocalPoint:(AvnPoint)pt;
-(void) onClosed;

-(AvnPlatformResizeReason) getResizeReason;
-(void) setResizeReason:(AvnPlatformResizeReason)reason;
-(void) setRenderTarget:(NSObject<IRenderTarget>*)target;
-(void) setRenderTarget:(NSObject<IRenderTarget>* _Nonnull)target;
+ (AvnPoint)toAvnPoint:(CGPoint)p;
@end
48 changes: 27 additions & 21 deletions native/Avalonia.Native/src/OSX/AvnView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "AvnView.h"
#include "automation.h"
#import "WindowInterfaces.h"
#import "WindowImpl.h"

@implementation AvnView
{
ComPtr<WindowBaseImpl> _parent;
ComPtr<TopLevelImpl> _parent;
NSTrackingArea* _area;
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed;
AvnInputModifiers _modifierState;
Expand Down Expand Up @@ -67,7 +68,7 @@ -(void)displayLayer: (CALayer*)layer
[self updateLayer];
}

-(AvnView*) initWithParent: (WindowBaseImpl*) parent
-(AvnView*) initWithParent: (TopLevelImpl*) parent
{
self = [super init];
[self setWantsLayer:YES];
Expand Down Expand Up @@ -155,7 +156,7 @@ -(void)setFrameSize:(NSSize)newSize

auto reason = [self inLiveResize] ? ResizeUser : _resizeReason;

_parent->BaseEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
_parent->TopLevelEvents->Resized(AvnSize{newSize.width, newSize.height}, reason);
}
}

Expand All @@ -167,14 +168,14 @@ - (void)updateLayer
return;
}

_parent->BaseEvents->RunRenderPriorityJobs();
_parent->TopLevelEvents->RunRenderPriorityJobs();

if (_parent == nullptr)
{
return;
}

_parent->BaseEvents->Paint();
_parent->TopLevelEvents->Paint();
}

- (void)drawRect:(NSRect)dirtyRect
Expand Down Expand Up @@ -207,7 +208,7 @@ - (void) viewDidChangeBackingProperties

if(_parent != nullptr)
{
_parent->BaseEvents->ScalingChanged([_parent->Window backingScaleFactor]);
_parent->TopLevelEvents->ScalingChanged([[self window] backingScaleFactor]);
}

[super viewDidChangeBackingProperties];
Expand All @@ -219,19 +220,24 @@ - (bool) ignoreUserInput:(bool)trigerInputWhenDisabled
{
return TRUE;
}

id<AvnWindowProtocol> parentWindow = nullptr;

auto parentWindow = _parent->GetWindowProtocol();
if([[self window] conformsToProtocol:@protocol(AvnWindowProtocol)]){
parentWindow = (id<AvnWindowProtocol>)[self window];
}

if(parentWindow == nil || ![parentWindow shouldTryToHandleEvents])
if(parentWindow != nullptr && ![parentWindow shouldTryToHandleEvents])
{
if(trigerInputWhenDisabled)
{
auto window = dynamic_cast<WindowImpl*>(_parent.getRaw());

if(window != nullptr)
{
window->WindowEvents->GotInputWhenDisabled();
WindowImpl* windowImpl = dynamic_cast<WindowImpl*>(_parent.getRaw());

if(windowImpl == nullptr){
return FALSE;
}

windowImpl->WindowEvents->GotInputWhenDisabled();
}

return TRUE;
Expand Down Expand Up @@ -301,15 +307,15 @@ - (void)mouseEvent:(NSEvent *)event withType:(AvnRawMouseEventType) type

if(_parent != nullptr)
{
_parent->BaseEvents->RawMouseEvent(type, timestamp, modifiers, point, delta);
_parent->TopLevelEvents->RawMouseEvent(type, timestamp, modifiers, point, delta);
}

[super mouseMoved:event];
}

- (BOOL) resignFirstResponder
{
_parent->BaseEvents->LostFocus();
_parent->TopLevelEvents->LostFocus();
return YES;
}

Expand Down Expand Up @@ -461,7 +467,7 @@ - (void) keyboardEvent: (NSEvent *) event withType: (AvnRawKeyEventType)type
auto timestamp = static_cast<uint64_t>([event timestamp] * 1000);
auto modifiers = [self getModifiers:[event modifierFlags]];

_parent->BaseEvents->RawKeyEvent(type, timestamp, modifiers, key, physicalKey, keySymbolUtf8);
_parent->TopLevelEvents->RawKeyEvent(type, timestamp, modifiers, key, physicalKey, keySymbolUtf8);
}

- (void)flagsChanged:(NSEvent *)event
Expand Down Expand Up @@ -521,7 +527,7 @@ - (void)flagsChanged:(NSEvent *)event
}

- (bool) handleKeyDown: (NSTimeInterval) timestamp withKey:(AvnKey)key withPhysicalKey:(AvnPhysicalKey)physicalKey withModifiers:(AvnInputModifiers)modifiers withKeySymbol:(NSString*)keySymbol {
return _parent->BaseEvents->RawKeyEvent(KeyDown, timestamp, modifiers, key, physicalKey, [keySymbol UTF8String]);
return _parent->TopLevelEvents->RawKeyEvent(KeyDown, timestamp, modifiers, key, physicalKey, [keySymbol UTF8String]);
}

- (void)keyDown:(NSEvent *)event
Expand Down Expand Up @@ -575,7 +581,7 @@ - (void)keyDown:(NSEvent *)event
if(keySymbol != nullptr && key != AvnKeyEnter){
auto timestamp = static_cast<uint64_t>([event timestamp] * 1000);

_parent->BaseEvents->RawTextInputEvent(timestamp, [keySymbol UTF8String]);
_parent->TopLevelEvents->RawTextInputEvent(timestamp, [keySymbol UTF8String]);
}
}
}
Expand Down Expand Up @@ -707,7 +713,7 @@ - (void)insertText:(id)string replacementRange:(NSRange)replacementRange

uint64_t timestamp = static_cast<uint64_t>([NSDate timeIntervalSinceReferenceDate] * 1000);

_parent->BaseEvents->RawTextInputEvent(timestamp, [text UTF8String]);
_parent->TopLevelEvents->RawTextInputEvent(timestamp, [text UTF8String]);
}

- (NSUInteger)characterIndexForPoint:(NSPoint)point
Expand All @@ -733,7 +739,7 @@ - (NSDragOperation)triggerAvnDragEvent: (AvnDragEventType) type info: (id <NSDra
NSDragOperation nsop = [info draggingSourceOperationMask];

auto effects = ConvertDragDropEffects(nsop);
int reffects = (int)_parent->BaseEvents
int reffects = (int)_parent->TopLevelEvents
->DragEvent(type, point, modifiers, effects,
CreateClipboard([info draggingPasteboard], nil),
GetAvnDataObjectHandleFromDraggingInfo(info));
Expand Down Expand Up @@ -799,7 +805,7 @@ - (AvnAccessibilityElement *) accessibilityChild
{
if (_accessibilityChild == nil)
{
auto peer = _parent->BaseEvents->GetAutomationPeer();
auto peer = _parent->TopLevelEvents->GetAutomationPeer();

if (peer == nil)
return nil;
Expand Down
5 changes: 2 additions & 3 deletions native/Avalonia.Native/src/OSX/AvnWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "WindowImpl.h"
#include "AvnView.h"
#include "WindowInterfaces.h"
#include "PopupImpl.h"

@implementation CLASS_NAME
{
Expand Down Expand Up @@ -231,7 +230,7 @@ - (void)windowWillClose:(NSNotification *_Nonnull)notification
//
// If we don't implement this, then isZoomed always returns true for a non-
// resizable window ¯\_(ツ)_/¯
- (NSRect)windowWillUseStandardFrame:(NSWindow*)window
- (NSRect)windowWillUseStandardFrame:(NSWindow* _Nonnull)window
defaultFrame:(NSRect)newFrame {
return newFrame;
}
Expand Down Expand Up @@ -397,7 +396,7 @@ - (BOOL)windowShouldZoom:(NSWindow *_Nonnull)window toFrame:(NSRect)newFrame
return _parent->CanZoom();
}

-(void)windowDidResignKey:(NSNotification *)notification
-(void)windowDidResignKey:(NSNotification* _Nonnull)notification
{
if(_parent)
_parent->BaseEvents->Deactivated();
Expand Down
4 changes: 4 additions & 0 deletions native/Avalonia.Native/src/OSX/INSWindowHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
struct INSWindowHolder
{
virtual NSWindow* _Nonnull GetNSWindow () = 0;
};

struct INSViewHolder
{
virtual AvnView* _Nonnull GetNSView () = 0;
};

Expand Down
9 changes: 0 additions & 9 deletions native/Avalonia.Native/src/OSX/PopupImpl.h

This file was deleted.

12 changes: 5 additions & 7 deletions native/Avalonia.Native/src/OSX/PopupImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#import "WindowBaseImpl.h"
#import "WindowProtocol.h"
#import <AppKit/AppKit.h>
#include "PopupImpl.h"

class PopupImpl : public virtual WindowBaseImpl, public IAvnPopup
{
Expand All @@ -23,7 +22,7 @@
END_INTERFACE_MAP()
virtual ~PopupImpl(){}
ComPtr<IAvnWindowEvents> WindowEvents;
PopupImpl(IAvnWindowEvents* events) : WindowBaseImpl(events)
PopupImpl(IAvnWindowEvents* events) : TopLevelImpl(events), WindowBaseImpl(events)
{
WindowEvents = events;
[Window setLevel:NSPopUpMenuWindowLevel];
Expand All @@ -35,13 +34,12 @@ virtual NSWindowStyleMask CalculateStyleMask() override
}

public:
virtual bool ShouldTakeFocusOnShow() override
{
return false;
}

virtual HRESULT Show(bool activate, bool isDialog) override
{
auto windowProtocol = GetWindowProtocol();

[windowProtocol setEnabled:true];

return WindowBaseImpl::Show(activate, true);
}
};
Expand Down
Loading
Loading