Merge pull request #945 from rcancro/aslayoutPixelBounds

Enforce pixels bounds for ASLayout size/position, while also protecting against underspecified layouts setting NaN or Inf on CALayer.
This commit is contained in:
appleguy
2015-12-16 17:40:50 -08:00
2 changed files with 29 additions and 4 deletions

View File

@@ -1816,8 +1816,28 @@ void recursivelyEnsureDisplayForLayer(CALayer *layer)
CGRect subnodeFrame = CGRectZero;
for (ASLayout *subnodeLayout in _layout.sublayouts) {
ASDisplayNodeAssert([_subnodes containsObject:subnodeLayout.layoutableObject], @"Cached sublayouts must only contain subnodes' layout.");
subnodeFrame.origin = subnodeLayout.position;
subnodeFrame.size = subnodeLayout.size;
CGPoint adjustedOrigin = subnodeLayout.position;
if (isfinite(adjustedOrigin.x) == NO) {
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
adjustedOrigin.x = 0;
}
if (isfinite(adjustedOrigin.y) == NO) {
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
adjustedOrigin.y = 0;
}
subnodeFrame.origin = adjustedOrigin;
CGSize adjustedSize = subnodeLayout.size;
if (isfinite(adjustedSize.width) == NO) {
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid size");
adjustedSize.width = 0;
}
if (isfinite(adjustedSize.height) == NO) {
ASDisplayNodeAssert(0, @"subnodeLayout has an invalid position");
adjustedSize.height = 0;
}
subnodeFrame.size = adjustedSize;
subnode = ((ASDisplayNode *)subnodeLayout.layoutableObject);
[subnode setFrame:subnodeFrame];
}

View File

@@ -11,6 +11,7 @@
#import "ASLayout.h"
#import "ASAssert.h"
#import "ASLayoutSpecUtilities.h"
#import "ASInternalHelpers.h"
#import <stack>
CGPoint const CGPointNull = {NAN, NAN};
@@ -37,8 +38,12 @@ extern BOOL CGPointIsNull(CGPoint point)
ASLayout *l = [super new];
if (l) {
l->_layoutableObject = layoutableObject;
l->_size = size;
l->_position = position;
l->_size = CGSizeMake(ASCeilPixelValue(size.width), ASCeilPixelValue(size.height));
if (CGPointIsNull(position) == NO) {
l->_position = CGPointMake(ASCeilPixelValue(position.x), ASCeilPixelValue(position.y));
} else {
l->_position = position;
}
l->_sublayouts = [sublayouts copy];
}
return l;