Permalink
Browse files

merging in upstream and fixing conflict

  • Loading branch information...
2 parents c7edee1 + 18c541a commit 24887fdd1cb403bc08078c465715fafb1d9ecd34 @Machx committed Jan 15, 2013
View
@@ -0,0 +1,23 @@
+We love that you're interested in contributing to this project!
+
+To make the process as painless as possible, we have just a couple of guidelines
+that should make life easier for everyone involved.
+
+## Prefer Pull Requests
+
+If you know exactly how to implement the feature being suggested or fix the bug
+being reported, please open a pull request instead of an issue. Pull requests are easier than
+patches or inline code blocks for discussing and merging the changes.
+
+If you can't make the change yourself, please open an issue after making sure
+that one isn't already logged.
+
+## Contributing Code
+
+Fork this repository, make it awesomer (preferably in a branch named for the
+topic), send a pull request!
+
+All code contributions should match our [coding
+conventions](https://github.com/github/objective-c-conventions).
+
+Thanks for contributing! :boom::camel:
View
@@ -1,4 +1,4 @@
-**Copyright (c) 2012, GitHub, Inc.**
+**Copyright (c) 2012 - 2013, GitHub, Inc.**
**All rights reserved.**
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
View
@@ -8,12 +8,6 @@ This framework is very much a work in progress at the moment, and should be cons
To start building the framework, clone this repository and then run `git submodule update --init --recursive`. This will automatically pull down any dependencies.
-## Contributing
-
-Fork this repository, make it awesomer (preferably in a branch named for the topic), send a pull request!
-
-All contributions should match our [coding conventions](https://github.com/github/objective-c-conventions).
-
## License
Rebel is released under the MIT license. See [LICENSE.md](https://github.com/github/Rebel/blob/master/LICENSE.md).
Oops, something went wrong.
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0450"
+ LastUpgradeVersion = "0460"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -8,32 +8,30 @@
#import "CAAnimation+RBLBlockAdditions.h"
-#import <objc/runtime.h>
-
-static void *RBLCAAnimationCompletionBlockAssociatedObjectKey = &RBLCAAnimationCompletionBlockAssociatedObjectKey;
-
@interface RBLCAAnimationDelegate : NSObject
-
+@property (nonatomic, copy) void (^completion)(BOOL finished);
@end
@implementation CAAnimation (RBLBlockAdditions)
- (void)setRbl_completionBlock:(void (^)(BOOL))block {
- RBLCAAnimationDelegate *delegateStub = [[RBLCAAnimationDelegate alloc] init];
- self.delegate = delegateStub;
- objc_setAssociatedObject(self, RBLCAAnimationCompletionBlockAssociatedObjectKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ RBLCAAnimationDelegate *stub = [[RBLCAAnimationDelegate alloc] init];
+ stub.completion = block;
+ self.delegate = stub;
}
- (void (^)(BOOL))rbl_completionBlock {
- return objc_getAssociatedObject(self, RBLCAAnimationCompletionBlockAssociatedObjectKey);
+ return ([self.delegate isKindOfClass:RBLCAAnimationDelegate.class] ? [(RBLCAAnimationDelegate *)self.delegate completion] : nil);
}
@end
@implementation RBLCAAnimationDelegate
- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
- if (animation.rbl_completionBlock != nil) animation.rbl_completionBlock(flag);
+ if (self.completion != nil) {
+ self.completion(flag);
+ }
}
@end
@@ -0,0 +1,16 @@
+//
+// NSAttributedString+RBLHTMLAdditions.h
+// Rebel
+//
+// Created by Justin Spahr-Summers on 2012-12-11.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import <AppKit/AppKit.h>
+
+@interface NSAttributedString (RBLHTMLAdditions)
+
+// Returns an attributed string initialized from HTML.
++ (instancetype)rbl_attributedStringWithHTML:(NSString *)HTMLString;
+
+@end
@@ -0,0 +1,25 @@
+//
+// NSAttributedString+RBLHTMLAdditions.m
+// Rebel
+//
+// Created by Justin Spahr-Summers on 2012-12-11.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import "NSAttributedString+RBLHTMLAdditions.h"
+
+@implementation NSAttributedString (RBLHTMLAdditions)
+
++ (instancetype)rbl_attributedStringWithHTML:(NSString *)HTMLString {
+ NSParameterAssert(HTMLString != nil);
+
+ NSStringEncoding encoding = HTMLString.fastestEncoding;
+
+ NSData *data = [HTMLString dataUsingEncoding:encoding];
+ if (data == nil) return nil;
+
+ NSDictionary *options = @{ NSCharacterEncodingDocumentAttribute: @(encoding) };
+ return [[self alloc] initWithHTML:data options:options documentAttributes:NULL];
+}
+
+@end
@@ -0,0 +1,26 @@
+//
+// NSFont+RBLFallbackAdditions.h
+// Rebel
+//
+// Created by Justin Spahr-Summers on 2012-12-09.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSFont (RBLFallbackAdditions)
+
+// Looks up a font with the given name and size.
+//
+// If text rendered in the returned font uses a glyph not present in
+// `fontName`, the fonts specified by `fallbackNames` are searched in order, and
+// the glyph is rendered in the first font that provides it.
+//
+// If `fontName` does not exist on the system, `fallbackNames` is searched in
+// order for a replacement font.
+//
+// Returns a font that renders in `fontName` by default, and `fallbackNames`
+// only if necessary, or `nil` if no fonts by the given names could be found.
++ (NSFont *)rbl_fontWithName:(NSString *)fontName size:(CGFloat)fontSize fallbackNames:(NSArray *)fallbackNames;
+
+@end
@@ -0,0 +1,41 @@
+//
+// NSFont+RBLFallbackAdditions.m
+// Rebel
+//
+// Created by Justin Spahr-Summers on 2012-12-09.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import "NSFont+RBLFallbackAdditions.h"
+
+@implementation NSFont (RBLFallbackAdditions)
+
++ (NSFont *)rbl_fontWithName:(NSString *)fontName size:(CGFloat)fontSize fallbackNames:(NSArray *)fallbackNames {
+ NSParameterAssert(fontName != nil);
+
+ NSMutableArray *fallbackDescriptors = [NSMutableArray arrayWithCapacity:fallbackNames.count];
+ for (NSString *fallbackName in fallbackNames) {
+ [fallbackDescriptors addObject:[NSFontDescriptor fontDescriptorWithName:fallbackName size:fontSize]];
+ }
+
+ NSMutableArray *remainingFontNames = [fallbackNames mutableCopy];
+ NSAssert(fallbackDescriptors.count == remainingFontNames.count, @"Should have the same number of fallback font descriptors (%lu) as names to try (%lu)", (unsigned long)fallbackDescriptors.count, (unsigned long)remainingFontNames.count);
+
+ while (YES) {
+ NSDictionary *attributes = @{ NSFontNameAttribute: fontName, NSFontCascadeListAttribute: fallbackDescriptors };
+
+ NSFont *font = [NSFont fontWithDescriptor:[NSFontDescriptor fontDescriptorWithFontAttributes:attributes] size:fontSize];
+ if (font != nil) return font;
+
+ if (remainingFontNames.count == 0) break;
+
+ // Try the next font in the list.
+ fontName = remainingFontNames[0];
+ [remainingFontNames removeObjectAtIndex:0];
+ [fallbackDescriptors removeObjectAtIndex:0];
+ }
+
+ return nil;
+}
+
+@end
View
@@ -7,8 +7,7 @@
//
#import <Foundation/Foundation.h>
-
-#import "RBLView.h"
+#import <Rebel/RBLView.h>
@class RBLPopover;
@class RBLPopoverBackgroundView;
@@ -38,12 +37,12 @@ typedef void (^RBLPopoverDelegateBlock)(RBLPopover *popover);
// A popover.
// This aims to replicate the API of `NSPopover`, within reason, whilst offering
-// more flexibility when it comes to customising of it's appearance.
+// more flexibility when it comes to customising of its appearance.
//
// A note on layers: by default the clipping method which the popover uses to
-// clip it's subviews to it's outline does _not_ support any layer backed or
+// clip its subviews to its outline does _not_ support any layer backed or
// hosting views. This can be worked around by adding mask layers to any layers
-// you add to the popover or it's subviews.
+// you add to the popover or its subviews.
@interface RBLPopover : NSResponder
// The view controller providing the view displayed within the popover.
@@ -95,6 +94,9 @@ typedef void (^RBLPopoverDelegateBlock)(RBLPopover *popover);
// animation has successfully completed.
@property (nonatomic, copy) RBLPopoverDelegateBlock didShowBlock;
+// Use for animation when showing and closing the popover.
+@property (nonatomic, assign) NSTimeInterval fadeDuration;
+
// Designated initialiser.
//
// Returns a newly initialised `RBLPopover`.
@@ -116,16 +118,9 @@ typedef void (^RBLPopoverDelegateBlock)(RBLPopover *popover);
// popover to fit on the screen, preferredEdge is used.
- (void)showRelativeToRect:(CGRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(CGRectEdge)preferredEdge;
-// Closes the popover with the default fadeout duration (if the popover
-// animates).
+// Closes the popover with the `fadeDuration` (if the popover animates).
- (void)close;
-// Closes the popover with the given duration. If animates is set to NO the
-// popover closes immediately.
-//
-// duration - The duration of the fade animation.
-- (void)closeWithFadeoutDuration:(NSTimeInterval)duration;
-
// Convenience method exposed for nib files.
- (IBAction)performClose:(id)sender;
View
@@ -33,18 +33,14 @@ - (CGRectEdge)arrowEdgeForPopoverEdge:(CGRectEdge)popoverEdge;
//***************************************************************************
-static NSTimeInterval const RBLPopoverDefaultFadeDuration = 0.3;
-
-//***************************************************************************
-
@interface RBLPopover ()
// The window we are using to display the popover.
@property (nonatomic, strong) RBLPopoverWindow *popoverWindow;
// The identifier for the event monitor we are using to watch for mouse clicks
// outisde of the popover.
-// We are not responsible for it's memory management.
+// We are not responsible for its memory management.
@property (nonatomic, weak) id transientEventMonitor;
// The size the content view was before the popover was shown.
@@ -116,6 +112,7 @@ - (instancetype)initWithContentViewController:(NSViewController *)viewController
_backgroundViewClass = RBLPopoverBackgroundView.class;
_behavior = RBLPopoverViewControllerBehaviorApplicationDefined;
_animates = YES;
+ _fadeDuration = 0.3;
return self;
}
@@ -289,7 +286,7 @@ - (void)showRelativeToRect:(CGRect)positioningRect ofView:(NSView *)positioningV
};
if (self.animates) {
- [NSView rbl_animateWithDuration:RBLPopoverDefaultFadeDuration animations:^{
+ [NSView rbl_animateWithDuration:self.fadeDuration animations:^{
[self.popoverWindow.animator setAlphaValue:1.0];
} completion:postDisplayBlock];
} else {
@@ -301,10 +298,6 @@ - (void)showRelativeToRect:(CGRect)positioningRect ofView:(NSView *)positioningV
#pragma mark Closing
- (void)close {
- [self closeWithFadeoutDuration:RBLPopoverDefaultFadeDuration];
-}
-
-- (void)closeWithFadeoutDuration:(NSTimeInterval)duration {
if (!self.shown) return;
[self removeEventMonitor];
@@ -321,7 +314,7 @@ - (void)closeWithFadeoutDuration:(NSTimeInterval)duration {
};
if (self.animates) {
- [NSView rbl_animateWithDuration:duration animations:^{
+ [NSView rbl_animateWithDuration:self.fadeDuration animations:^{
[self.popoverWindow.animator setAlphaValue:0.0];
} completion:windowTeardown];
} else {
View
@@ -0,0 +1,17 @@
+//
+// RBLScrollView.h
+// Rebel
+//
+// Created by Jonathan Willing on 12/4/12.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+// A NSScrollView subclass which uses an instance of RBLClipView
+// as the clip view instead of NSClipView.
+//
+// Layer-backed by default.
+@interface RBLScrollView : NSScrollView
+
+@end
View
@@ -0,0 +1,43 @@
+//
+// RBLScrollView.m
+// Rebel
+//
+// Created by Jonathan Willing on 12/4/12.
+// Copyright (c) 2012 GitHub. All rights reserved.
+//
+
+#import "RBLScrollView.h"
+#import "RBLClipView.h"
+
+@implementation RBLScrollView
+
+#pragma mark Lifecycle
+
+- (id)initWithFrame:(NSRect)frameRect {
+ self = [super initWithFrame:frameRect];
+ if (self == nil) return nil;
+
+ [self swapClipView];
+
+ return self;
+}
+
+- (void)awakeFromNib {
+ [super awakeFromNib];
+
+ if (![self.contentView isKindOfClass:RBLClipView.class] ) {
+ [self swapClipView];
+ }
+}
+
+#pragma mark Clip view swapping
+
+- (void)swapClipView {
+ self.wantsLayer = YES;
+ id documentView = self.documentView;
+ RBLClipView *clipView = [[RBLClipView alloc] initWithFrame:self.contentView.frame];
+ self.contentView = clipView;
+ self.documentView = documentView;
+}
+
+@end
Oops, something went wrong.

0 comments on commit 24887fd

Please sign in to comment.