From 0cfb53cea4fa5a7f80bf1c0b8737f8b74d61d8d4 Mon Sep 17 00:00:00 2001 From: Mathieu Monney Date: Mon, 18 Nov 2013 15:29:41 +0100 Subject: [PATCH 1/2] Changing a CALayer in a menu callback doesn't trigger re-draw / re-layout --- AppKit/CPMenu/CPMenu.j | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 394c4e952..c03f4bd6c 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 @@ -999,6 +1000,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 */ From c528421a8e3c1762f30721ac72f21dbe468abe36 Mon Sep 17 00:00:00 2001 From: Mathieu Monney Date: Fri, 19 Dec 2014 13:42:40 +0100 Subject: [PATCH 2/2] Added unit test for pull request #2018 --- .../Manual/CPMenuCALayerTest/AppController.j | 75 +++++++++++++ Tests/Manual/CPMenuCALayerTest/Info.plist | 12 ++ Tests/Manual/CPMenuCALayerTest/Jakefile | 93 ++++++++++++++++ .../CPMenuCALayerTest/Resources/spinner.gif | Bin 0 -> 1434 bytes .../Manual/CPMenuCALayerTest/index-debug.html | 103 ++++++++++++++++++ Tests/Manual/CPMenuCALayerTest/index.html | 78 +++++++++++++ Tests/Manual/CPMenuCALayerTest/main.j | 18 +++ 7 files changed, 379 insertions(+) create mode 100644 Tests/Manual/CPMenuCALayerTest/AppController.j create mode 100644 Tests/Manual/CPMenuCALayerTest/Info.plist create mode 100644 Tests/Manual/CPMenuCALayerTest/Jakefile create mode 100644 Tests/Manual/CPMenuCALayerTest/Resources/spinner.gif create mode 100644 Tests/Manual/CPMenuCALayerTest/index-debug.html create mode 100644 Tests/Manual/CPMenuCALayerTest/index.html create mode 100644 Tests/Manual/CPMenuCALayerTest/main.j 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 0000000000000000000000000000000000000000..a5e705f6cbdf914e5e714c35a8dfef807f19e3c2 GIT binary patch literal 1434 zcmZvbdrVVj7{t$-UNOu86#VHu^|s&3rWfwHBbPG_8{SrlB{Tv1uvvj4t6zP!)#d!Ogc zP^62J^$0+~?-ZcXXpBaq%jFsw8L`=H2?+@R02Yg-*Xw;gACBV^i3CMahr>Z667S!? zk3LDe>VLEsU;sWo$Py~o!gWuaIAnaG3Sv``&tvc+8DJO!| zt4fcbQ8tW}a&xZfgtQ9BnFYLvGG|PvCNlg&uh@Q^w9Pz}+I^hCj`vu9JQADPqdkyk zR40xycD9geUgJu1e;$L`Fpa)?Wl-2&6hO@U*KrPqK(I1H=1h?2fce}6GhhP1oBZC# z1e@gt-qFa6lZrl%s1>bdxg*W)Ebt__O(4sj6(*2X@ciUClwHH#U(NRM7XAjS z+scDZ32J*PCoslsgS~#ZlCCGo`r>S6F)Ghw5wVlqHioFaw?ucD(XoLJ0j;28oPoPV z9A}dR$0SKn>uExfkl#j09o;v$BZ909R=*p{ATNq8BJW;YduX2QMOU7$a$_L5e!G^g zpbkx5G4&FZ%7m14rTN}5YB(;x7$5XOc_hf3E|Hw$TVg)P#qf~}nOn03uqsp>UG>vi zWThIoO)-1Q#@u#O;fMC#WAf@Xj70-0g9YZ;dA$HH1fW1q=9-c>>_yA0S$7M*5?}vi z)8MU`Q%P!7sEBBnd$DrKgFQ2?O%6LpdaC%F8Pn-)EC2t=j~ zoaLamla$FX!GQqWi!%s>sj-#5SJX0IF!TP=r21Z}s)k#btN0?=I7uD9C)Gb$fZ#sm zaVq7g`LwZ%PfNpN^_N-IGLHj@AV`s#4&va7_{Hw63G6BkSGXHdogTZ%QOiRb bDpZ@qYcJKM>x%b%*HX74c8MnqfHi*u-bC?g literal 0 HcmV?d00001 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); +}