Chromium Code Reviews| Index: Source/core/platform/mac/NSScrollerImpDetails.mm |
| diff --git a/Source/core/platform/mac/NSScrollerImpDetails.mm b/Source/core/platform/mac/NSScrollerImpDetails.mm |
| index a5f09c5d519c0df39a5713c72bc1acc9152a3ce1..e8325b13b3b6bd76fa982fe92e47ccf40f5301f5 100644 |
| --- a/Source/core/platform/mac/NSScrollerImpDetails.mm |
| +++ b/Source/core/platform/mac/NSScrollerImpDetails.mm |
| @@ -29,28 +29,65 @@ |
| #include "RuntimeEnabledFeatures.h" |
| #include "core/platform/mac/NSScrollerImpDetails.h" |
| +namespace { |
| + |
| +// Declare notification names from the 10.7 SDK. |
| +#if !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| +NSString* NSPreferredScrollerStyleDidChangeNotification = @"NSPreferredScrollerStyleDidChangeNotification"; |
| +#endif |
| + |
| +// Storing the current NSScrollerStyle as a global is appreciably faster than |
| +// having it be a property of ScrollerStylerObserver. |
| +NSScrollerStyle g_scrollerStyle = NSScrollerStyleLegacy; |
| + |
| +} // anonymous namespace |
| + |
| +@interface ScrollerStyleObserver : NSObject |
| +- (id)init; |
| +- (void)preferredScrollerStyleDidChange:(NSNotification*)notification; |
| +@end |
| + |
| +@implementation ScrollerStyleObserver |
| +- (id)init |
| +{ |
| + self = [super init]; |
| + if (self) { |
|
eseidel
2013/10/15 21:56:02
I might have written if (!self)\n return nil;
Als
Nico
2013/10/15 22:00:14
I think the usual stanza in chromium is
if ((
ccameron
2013/10/15 22:19:02
Done.
Thought I'd caught all of the 2-spaces...
|
| + if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)]) { |
| + g_scrollerStyle = [NSScroller preferredScrollerStyle]; |
| + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| + [center addObserver:self |
| + selector:@selector(preferredScrollerStyleDidChange:) |
| + name:NSPreferredScrollerStyleDidChangeNotification |
| + object:nil]; |
| + } |
| + } |
| + return self; |
| +} |
| + |
| +- (void)preferredScrollerStyleDidChange:(NSNotification*)notification |
| +{ |
| + g_scrollerStyle = [NSScroller preferredScrollerStyle]; |
|
eseidel
2013/10/15 21:57:53
Do we need to tell somebody that this changed? Se
ccameron
2013/10/15 22:19:02
Something else /does/ trigger a re-layout when the
|
| +} |
| +@end |
| + |
| namespace WebCore { |
| bool isScrollbarOverlayAPIAvailable() |
| { |
| - static bool apiAvailable; |
| - static bool shouldInitialize = true; |
| - if (shouldInitialize) { |
| - shouldInitialize = false; |
| - Class scrollerImpClass = NSClassFromString(@"NSScrollerImp"); |
| - Class scrollerImpPairClass = NSClassFromString(@"NSScrollerImpPair"); |
| - apiAvailable = [scrollerImpClass respondsToSelector:@selector(scrollerImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] |
| - && [scrollerImpPairClass instancesRespondToSelector:@selector(scrollerStyle)]; |
| - } |
| + static bool apiAvailable = |
| + [NSClassFromString(@"NSScrollerImp") respondsToSelector:@selector(scrollerImpWithStyle:controlSize:horizontal:replacingScrollerImp:)] |
| + && [NSClassFromString(@"NSScrollerImpPair") instancesRespondToSelector:@selector(scrollerStyle)]; |
| return apiAvailable; |
| } |
| -NSScrollerStyle recommendedScrollerStyle() { |
| +NSScrollerStyle recommendedScrollerStyle() |
| +{ |
| if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) |
| return NSScrollerStyleOverlay; |
| - if ([NSScroller respondsToSelector:@selector(preferredScrollerStyle)]) |
| - return [NSScroller preferredScrollerStyle]; |
| - return NSScrollerStyleLegacy; |
| + |
| + // The ScrollerStyleObserver will update g_scrollerStyle at init and when needed. |
| + static ScrollerStyleObserver* scrollerStyleObserver = [[ScrollerStyleObserver alloc] init]; |
|
eseidel
2013/10/15 21:56:02
new] would have done the same as alloc] init];
Nico
2013/10/15 22:00:14
Yeah, but alloc init is more common for some reaso
ccameron
2013/10/15 22:19:02
Left this one as-is.
|
| + return g_scrollerStyle; |
| } |
| } |