diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index e96fd03c6..6c23e1408 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -27,6 +27,7 @@ @import "CPKeyValueBinding.j" @import "CPMenuItem.j" +@import "CALayer.j" @global CPApp @@ -1016,6 +1017,10 @@ var _CPMenuBarVisible = NO, // an additional mouse move after all this, but not in other browsers. // This will be fixed correctly with the coming run loop changes. [_CPDisplayServer run]; + + // If layers are updated within the menu callback, the re-draw & re-layout doesn't occur until a mouse move. + // We force the update here. + [CALayer runLoopUpdateLayers]; } /* @ignore */ diff --git a/Tests/Manual/CPMenuCALayerTest/AppController.j b/Tests/Manual/CPMenuCALayerTest/AppController.j new file mode 100644 index 000000000..89e268e3a --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/AppController.j @@ -0,0 +1,75 @@ +/* + * AppController.j + * CPMenuCALayerTest + * + * Created by Mathieu Monney on December 19, 2014. + * Copyright 2014, Vidinoti SA, All rights reserved. + */ + +@import + +@implementation MyLayer : CALayer +{ +} + +- (void)drawInContext:(CGContext)aContext { + CGContextSetFillColor(aContext, [CPColor blackColor]); + CGContextFillRect(aContext, _bounds); +} + +@end + +@implementation AppController : CPObject +{ + MyLayer layer; +} + +-(void)changeSize:(id)sender { + var scale = [[sender selectedItem] title]; + scale = scale.substr(0,scale.length-1); + + // Change the affine transform of the layer to make sure it is updated due to + // https://github.com/cappuccino/cappuccino/pull/2018 + var af = CGAffineTransformMakeScale(scale/100.0,scale/100.0); + [layer setAffineTransform:af]; +} + +- (void)applicationDidFinishLaunching:(CPNotification)aNotification +{ + var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], + contentView = [theWindow contentView], + popupButton = [[CPPopUpButton alloc] initWithFrame:CGRectMakeZero()]; + + // Changing the button should change the size of the layer if #2018 is fixed. + [popupButton addItemsWithTitles:[@"100%",@"50%",@"25%"]]; + [popupButton sizeToFit]; + [popupButton setAction:@selector(changeSize:)]; + [popupButton setTarget:self]; + + [popupButton setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; + [popupButton setCenter:[contentView center]]; + + [contentView addSubview:popupButton]; + + [theWindow orderFront:self]; + + var layerRoot = [[CALayer alloc ] init]; + [layerRoot setBounds:CGRectMake(0,0,[contentView bounds].size.width,[contentView bounds].size.height)]; + [layerRoot setPosition:CGPointMake(0,0)]; + [contentView setWantsLayer:YES]; + + [contentView setLayer:layerRoot]; + + layer = [[MyLayer alloc ] init]; + [layer setBounds:CGRectMake(0,0,100,100)]; + [layer setPosition:CGPointMake([contentView bounds].size.width/2,[contentView bounds].size.height/2-100)]; + [layer setNeedsDisplay]; + + [layerRoot addSublayer:layer]; + + // Uncomment the following line to turn on the standard menu bar. + //[CPMenu setMenuBarVisible:YES]; +} + + +@end diff --git a/Tests/Manual/CPMenuCALayerTest/Info.plist b/Tests/Manual/CPMenuCALayerTest/Info.plist new file mode 100644 index 000000000..24626d6d2 --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/Info.plist @@ -0,0 +1,12 @@ + + + + + CPApplicationDelegateClass + AppController + CPBundleName + CPMenuCALayerTest + CPPrincipalClass + CPApplication + + diff --git a/Tests/Manual/CPMenuCALayerTest/Jakefile b/Tests/Manual/CPMenuCALayerTest/Jakefile new file mode 100644 index 000000000..0c730a17a --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/Jakefile @@ -0,0 +1,93 @@ +/* + * Jakefile + * CPMenuCALayerTest + * + * Created by Mathieu Monney on December 19, 2014. + * Copyright 2014, Vidinoti SA, All rights reserved. + */ + +var ENV = require("system").env, + FILE = require("file"), + JAKE = require("jake"), + task = JAKE.task, + FileList = JAKE.FileList, + app = require("cappuccino/jake").app, + configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug", + OS = require("os"); + +app ("CPMenuCALayerTest", function(task) +{ + task.setBuildIntermediatesPath(FILE.join("Build", "CPMenuCALayerTest.build", configuration)); + task.setBuildPath(FILE.join("Build", configuration)); + + task.setProductName("CPMenuCALayerTest"); + task.setIdentifier("com.yourcompany.CPMenuCALayerTest"); + task.setVersion("1.0"); + task.setAuthor("WireLoad, LLC"); + task.setEmail("feedback @nospam@ yourcompany.com"); + task.setSummary("CPMenuCALayerTest"); + task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**"))); + task.setResources(new FileList("Resources/**")); + task.setIndexFilePath("index.html"); + task.setInfoPlistPath("Info.plist"); + + if (configuration === "Debug") + task.setCompilerFlags("-DDEBUG -g"); + else + task.setCompilerFlags("-O"); +}); + +task ("default", ["CPMenuCALayerTest"], function() +{ + printResults(configuration); +}); + +task ("build", ["default"]); + +task ("debug", function() +{ + ENV["CONFIGURATION"] = "Debug"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("release", function() +{ + ENV["CONFIGURATION"] = "Release"; + JAKE.subjake(["."], "build", ENV); +}); + +task ("run", ["debug"], function() +{ + OS.system(["open", FILE.join("Build", "Debug", "CPMenuCALayerTest", "index.html")]); +}); + +task ("run-release", ["release"], function() +{ + OS.system(["open", FILE.join("Build", "Release", "CPMenuCALayerTest", "index.html")]); +}); + +task ("deploy", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Deployment", "CPMenuCALayerTest")); + OS.system(["press", "-f", FILE.join("Build", "Release", "CPMenuCALayerTest"), FILE.join("Build", "Deployment", "CPMenuCALayerTest")]); + printResults("Deployment") +}); + +task ("desktop", ["release"], function() +{ + FILE.mkdirs(FILE.join("Build", "Desktop", "CPMenuCALayerTest")); + require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CPMenuCALayerTest"), FILE.join("Build", "Desktop", "CPMenuCALayerTest", "CPMenuCALayerTest.app")); + printResults("Desktop") +}); + +task ("run-desktop", ["desktop"], function() +{ + OS.system([FILE.join("Build", "Desktop", "CPMenuCALayerTest", "CPMenuCALayerTest.app", "Contents", "MacOS", "NativeHost"), "-i"]); +}); + +function printResults(configuration) +{ + print("----------------------------"); + print(configuration+" app built at path: "+FILE.join("Build", configuration, "CPMenuCALayerTest")); + print("----------------------------"); +} diff --git a/Tests/Manual/CPMenuCALayerTest/Resources/spinner.gif b/Tests/Manual/CPMenuCALayerTest/Resources/spinner.gif new file mode 100644 index 000000000..a5e705f6c Binary files /dev/null and b/Tests/Manual/CPMenuCALayerTest/Resources/spinner.gif differ diff --git a/Tests/Manual/CPMenuCALayerTest/index-debug.html b/Tests/Manual/CPMenuCALayerTest/index-debug.html new file mode 100644 index 000000000..4fc4522a8 --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/index-debug.html @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + CPMenuCALayerTest + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + diff --git a/Tests/Manual/CPMenuCALayerTest/index.html b/Tests/Manual/CPMenuCALayerTest/index.html new file mode 100644 index 000000000..2533a9151 --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/index.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + CPMenuCALayerTest + + + + + + + + + + + + +
+
+ + + +
+
+ + + + diff --git a/Tests/Manual/CPMenuCALayerTest/main.j b/Tests/Manual/CPMenuCALayerTest/main.j new file mode 100644 index 000000000..501d94484 --- /dev/null +++ b/Tests/Manual/CPMenuCALayerTest/main.j @@ -0,0 +1,18 @@ +/* + * AppController.j + * CPMenuCALayerTest + * + * Created by Mathieu Monney on December 19, 2014. + * Copyright 2014, Vidinoti SA, All rights reserved. + */ + +@import +@import + +@import "AppController.j" + + +function main(args, namedArgs) +{ + CPApplicationMain(args, namedArgs); +}