mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-15 21:14:29 +00:00
setGlobalScrollerStyle-fixes
This commit is contained in:
1 parent
f5ca6c39f6
commit
9107322d28
2 files changed
+48
-56
No files matched your search
+13
-36
@@ -95,6 +95,10 @@ var TIMER_INTERVAL = 0.2,
|
||||
var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
CPScrollerStyleGlobalChangeNotification = @"CPScrollerStyleGlobalChangeNotification";
|
||||
|
||||
// _CPScrollViews will hold all created CPScrollView's in order to propagate changes
|
||||
// of scroller global style
|
||||
var _CPScrollViews;
|
||||
|
||||
/*!
|
||||
@ingroup appkit
|
||||
@class CPScrollView
|
||||
@@ -151,6 +155,8 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
CPScrollerStyleGlobal = _isBrowserUsingOverlayScrollers() ? CPScrollerStyleOverlay : CPScrollerStyleLegacy
|
||||
else
|
||||
CPScrollerStyleGlobal = globalValue;
|
||||
|
||||
_CPScrollViews = @[];
|
||||
}
|
||||
|
||||
+ (CPString)defaultThemeClass
|
||||
@@ -233,7 +239,10 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
+ (void)setGlobalScrollerStyle:(int)aStyle
|
||||
{
|
||||
CPScrollerStyleGlobal = aStyle;
|
||||
[[CPNotificationCenter defaultCenter] postNotificationName:CPScrollerStyleGlobalChangeNotification object:nil];
|
||||
|
||||
// We propagate the new scroller global style to all existing CPScrollView's
|
||||
for (var i = 0, count = [_CPScrollViews count]; i < count; i++)
|
||||
[_CPScrollViews[i] setScrollerStyle:CPScrollerStyleGlobal];
|
||||
}
|
||||
|
||||
|
||||
@@ -271,6 +280,8 @@ var CPScrollerStyleGlobal = CPScrollerStyleOverlay,
|
||||
_delegate = nil;
|
||||
_scrollTimer = nil;
|
||||
_implementedDelegateMethods = 0;
|
||||
|
||||
[_CPScrollViews addObject:self];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -1272,37 +1283,6 @@ Notifies the delegate when the scroll view has finished scrolling.
|
||||
#pragma mark -
|
||||
#pragma mark Overrides
|
||||
|
||||
|
||||
- (void)_removeObservers
|
||||
{
|
||||
if (!_isObserving)
|
||||
return;
|
||||
|
||||
[[CPNotificationCenter defaultCenter] removeObserver:self
|
||||
name:CPScrollerStyleGlobalChangeNotification
|
||||
object:nil];
|
||||
|
||||
[super _removeObservers];
|
||||
}
|
||||
|
||||
- (void)_addObservers
|
||||
{
|
||||
if (_isObserving)
|
||||
return;
|
||||
|
||||
//Make sure to have the last global style for the scroller
|
||||
[self _didReceiveDefaultStyleChange:nil];
|
||||
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didReceiveDefaultStyleChange:)
|
||||
name:CPScrollerStyleGlobalChangeNotification
|
||||
object:nil];
|
||||
|
||||
[super _addObservers];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)drawRect:(CGRect)aRect
|
||||
{
|
||||
[super drawRect:aRect];
|
||||
@@ -1568,10 +1548,7 @@ var CPScrollViewContentViewKey = @"CPScrollViewContentView",
|
||||
_scrollerStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerStyleKey] || CPScrollerStyleGlobal;
|
||||
_scrollerKnobStyle = [aCoder decodeObjectForKey:CPScrollViewScrollerKnobStyleKey] || CPScrollerKnobStyleDefault;
|
||||
|
||||
[[CPNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_didReceiveDefaultStyleChange:)
|
||||
name:CPScrollerStyleGlobalChangeNotification
|
||||
object:nil];
|
||||
[_CPScrollViews addObject:self];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
@@ -321,34 +321,16 @@
|
||||
[self assertFalse:hasScrolled];
|
||||
}
|
||||
|
||||
-(void)testNotificationsRegistered
|
||||
{
|
||||
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
|
||||
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
|
||||
styleMask:CPWindowNotSizable];
|
||||
|
||||
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:scrollView] equals:[] message:@"Notications registered for the scrollView in the notification center are wrong"];
|
||||
|
||||
[[theWindow contentView] addSubview:scrollView];
|
||||
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:scrollView] equals:[@"CPScrollerStyleGlobalChangeNotification"] message:@"Notications registered for the scrollView in the notification center are wrong"];
|
||||
|
||||
[[theWindow contentView] addSubview:scrollView];
|
||||
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:scrollView] equals:[@"CPScrollerStyleGlobalChangeNotification"] message:@"Notications registered for the scrollView in the notification center are wrong"];
|
||||
|
||||
[scrollView removeFromSuperview];
|
||||
[self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:scrollView] equals:[] message:@"Notications registered for the scrollView in the notification center are wrong"];
|
||||
}
|
||||
|
||||
- (void)testDocumentVisibleRect
|
||||
{
|
||||
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
|
||||
|
||||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
|
||||
styleMask:CPWindowNotSizable],
|
||||
windowView = [theWindow contentView],
|
||||
aScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
|
||||
aDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||
|
||||
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
|
||||
|
||||
[aScrollView setDocumentView:aDocumentView];
|
||||
[windowView addSubview:aScrollView];
|
||||
|
||||
@@ -365,6 +347,39 @@
|
||||
[self assertRect:CGRectMake(80, 80, 200, 200) equals:[aScrollView documentVisibleRect] message:@"documentVisibleRect is wrong in CPScrollView"];
|
||||
}
|
||||
|
||||
- (void)testSetGlobalScrollerStyle
|
||||
{
|
||||
// In this test, we set global scroller style to legacy, we create a scroll view, change global scroller style to overlay BEFORE placing the
|
||||
// scroll view in the view hierarchy, then we insert the scroll view in the view hierarchy and it should then have overlay as scroller style.
|
||||
|
||||
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleLegacy];
|
||||
|
||||
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
|
||||
styleMask:CPWindowNotSizable],
|
||||
windowView = [theWindow contentView],
|
||||
aScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
|
||||
aDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||
|
||||
[CPScrollView setGlobalScrollerStyle:CPScrollerStyleOverlay];
|
||||
|
||||
[aScrollView setDocumentView:aDocumentView];
|
||||
[windowView addSubview:aScrollView];
|
||||
|
||||
[self assert:CPScrollerStyleOverlay equals:[aScrollView scrollerStyle] message:@"Global scroller style was not applied to this CPScrollView"];
|
||||
|
||||
// In this test, we have global scroller style set to overlay. We create a scroll view, set the scroller style to legacy BEFORE placing the
|
||||
// scroll view in the view hierarchy, then insert it. It should have legacy as scroller style.
|
||||
|
||||
var anotherScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)],
|
||||
anotherDocumentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
|
||||
|
||||
[anotherScrollView setScrollerStyle:CPScrollerStyleLegacy];
|
||||
[anotherScrollView setDocumentView:anotherDocumentView];
|
||||
[windowView addSubview:anotherScrollView];
|
||||
|
||||
[self assert:CPScrollerStyleLegacy equals:[anotherScrollView scrollerStyle] message:@"Specific scroller style was overrided by global scroller style"];
|
||||
}
|
||||
|
||||
- (void)assertPoint:(CGPoint)expected equals:(CGPoint)actual message:(CPString)message
|
||||
{
|
||||
[self assert:expected.x equals:actual.x message:@"X: " + message];
|
||||
|
||||
Reference in new issue
Block a user