From d065a0cbc489c1a77ded61024083d2c23aa3a7a8 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Thu, 30 Oct 2014 17:35:09 -0700 Subject: [PATCH] New: added method initWithWindow in CPPlatformWindow The constructor initWithWindow: initializes a new CPPlatformWindow and set the given CPWindow as a fullPlatformWindow and bridgless window. When using this constructor, you don't need to work with the platformWindow anymore, you can use the method orderFront: and orderOut: of the CPWindow to open or close the CPPlatformWindow. You can also use the method setFrame: of the CPWindow to automatically change the contentRect of the CPPlatformWindow. In one word we assume that the given CPWindow and the CPPlatformWindow will have the same behavior. When not using the constructor initWithWindow:, the method setFrame: of the given CPWindow won't do anything to the CPPlateformWindow. Test app in Tests/Manual/CPPlatformWindow/ --- AppKit/CPWindow/CPWindow.j | 12 ++++++++++ AppKit/Platform/CPPlatformWindow.j | 24 +++++++++++++++++++ AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 3 +++ Tests/Manual/CPPlatformWindow/AppController.j | 9 ++----- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index e8fd603dc..b749b8768 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -569,6 +569,9 @@ CPTexturedBackgroundWindowMask var fullPlatformWindowViewClass = [[self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask], windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask]; + if (_platformWindow != [CPPlatformWindow primaryPlatformWindow]) + [_platformWindow setContentRect:[self frame]]; + [self _setWindowView:windowView]; [self setLevel:CPBackgroundWindowLevel]; @@ -753,6 +756,9 @@ CPTexturedBackgroundWindowMask if (originMoved) [self _moveChildWindows:delta]; } + + if ([_platformWindow _shouldUpdateContentRect] && _isFullPlatformWindow && _platformWindow != [CPPlatformWindow primaryPlatformWindow]) + [_platformWindow setContentRect:aFrame]; } /* @@ -904,6 +910,10 @@ CPTexturedBackgroundWindowMask [[self contentView] _addObservers]; #if PLATFORM(DOM) + + if (!_isVisible) + [_platformWindow _setShouldUpdateContentRect:NO]; + // -dw- if a sheet is clicked, the parent window should come up too if (_isSheet) [_parentView orderFront:self]; @@ -923,6 +933,8 @@ CPTexturedBackgroundWindowMask if (!CPApp._mainWindow) [self makeMainWindow]; + + [_platformWindow _setShouldUpdateContentRect:YES]; } /* diff --git a/AppKit/Platform/CPPlatformWindow.j b/AppKit/Platform/CPPlatformWindow.j index 628293117..e88a1ebf3 100644 --- a/AppKit/Platform/CPPlatformWindow.j +++ b/AppKit/Platform/CPPlatformWindow.j @@ -40,6 +40,8 @@ var PrimaryPlatformWindow = NULL; BOOL _hasShadow; unsigned _shadowStyle; CPString _title; + BOOL _shouldUpdateContentRect; + BOOL _hasInitializeInstanceWithWindow; #if PLATFORM(DOM) DOMWindow _DOMWindow; @@ -116,6 +118,17 @@ var PrimaryPlatformWindow = NULL; return self; } +- (id)initWithWindow:(CPWindow)aWindow +{ + self = [self initWithContentRect:CGRectMakeCopy([aWindow frame])]; + + [aWindow setPlatformWindow:self]; + [aWindow setFullPlatformWindow:YES]; + _hasInitializeInstanceWithWindow = YES; + + return self; +} + - (id)init { return [self initWithContentRect:CGRectMake(0.0, 0.0, 400.0, 500.0)]; @@ -281,6 +294,17 @@ var PrimaryPlatformWindow = NULL; return _title; } +- (BOOL)_shouldUpdateContentRect +{ + // We onyl update the contentRect with the frame of the bridgeless window if we have initialized the platform with the method initWithWindow: + return _shouldUpdateContentRect && _hasInitializeInstanceWithWindow; +} + +- (void)_setShouldUpdateContentRect:(BOOL)aBoolean +{ + _shouldUpdateContentRect = aBoolean; +} + @end #if PLATFORM(BROWSER) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 31b1810ef..cf83be2d6 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -988,6 +988,7 @@ var PreventScroll = true; - (void)_actualResizeEvent { + _shouldUpdateContentRect = NO; resizeTimer = nil; // FIXME: This is not the right way to do this. @@ -1021,6 +1022,8 @@ var PreventScroll = true; //window.liveResize = NO; [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + _shouldUpdateContentRect = YES; } - (void)touchEvent:(DOMEvent)aDOMEvent diff --git a/Tests/Manual/CPPlatformWindow/AppController.j b/Tests/Manual/CPPlatformWindow/AppController.j index 002edfeba..568b97345 100644 --- a/Tests/Manual/CPPlatformWindow/AppController.j +++ b/Tests/Manual/CPPlatformWindow/AppController.j @@ -22,12 +22,7 @@ - (void)applicationDidFinishLaunching:(CPNotification)aNotification { // This is called when the application is done loading. - - platformWindow = [[CPPlatformWindow alloc] init]; - [platformWindow setContentRect:[windowPlatformWindow contentRectForFrameRect:[windowPlatformWindow frame]]]; - - [windowPlatformWindow setPlatformWindow:platformWindow]; - [windowPlatformWindow setFullPlatformWindow:YES] + [[CPPlatformWindow alloc] initWithWindow:windowPlatformWindow]; } - (void)awakeFromCib @@ -52,7 +47,7 @@ - (IBAction)changeFrame:(id)sender { - [platformWindow setContentRect:CGRectMake(50, 50, 200, 200)]; + [windowPlatformWindow setFrame:CGRectMake(250, 250, 200, 200)]; } - (IBAction)showAlert:(id)sender