Skip to content

Commit

Permalink
Merge branch 'cocoa-killer' of git://github.com/ssp/clicktoflash into…
Browse files Browse the repository at this point in the history
… cocoa-killer
  • Loading branch information
simX committed Nov 6, 2009
2 parents 247545a + cdf7c52 commit fd8eff3
Show file tree
Hide file tree
Showing 10 changed files with 753 additions and 483 deletions.
12 changes: 12 additions & 0 deletions ClickToFlash.xcodeproj/project.pbxproj
Expand Up @@ -45,6 +45,8 @@
6953E4360F3EDE9D0014ECF7 /* CTFMenubarMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6953E4340F3EDE9D0014ECF7 /* CTFMenubarMenuController.m */; };
6953E43C0F3EDEB50014ECF7 /* MenubarMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6953E43A0F3EDEB50014ECF7 /* MenubarMenu.xib */; };
69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; };
6C09630C107FCA610006923A /* CTFActionButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C09630B107FCA610006923A /* CTFActionButton.m */; };
6C09648010808D4B0006923A /* CTFMainButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C09647F10808D4B0006923A /* CTFMainButton.m */; };
6C2C5A6A1068CE8700A90A54 /* Credits.css in Resources */ = {isa = PBXBuildFile; fileRef = A40485B110629B0E00FDC4E2 /* Credits.css */; };
6C436DAF107830A200A0D525 /* QTKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6C436DAE107830A200A0D525 /* QTKit.framework */; };
6C8E03FF10795EB900E21A50 /* CTFLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C8E03FE10795EB900E21A50 /* CTFLoader.m */; };
Expand Down Expand Up @@ -175,6 +177,10 @@
6953E43B0F3EDEB50014ECF7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Plugin/English.lproj/MenubarMenu.xib; sourceTree = "<group>"; };
69A26D0A0F302C10006648BC /* NSBezierPath-RoundedRectangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSBezierPath-RoundedRectangle.h"; path = "Plugin/NSBezierPath-RoundedRectangle.h"; sourceTree = "<group>"; };
69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSBezierPath-RoundedRectangle.m"; path = "Plugin/NSBezierPath-RoundedRectangle.m"; sourceTree = "<group>"; };
6C09630A107FCA610006923A /* CTFActionButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFActionButton.h; path = Plugin/CTFActionButton.h; sourceTree = "<group>"; };
6C09630B107FCA610006923A /* CTFActionButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFActionButton.m; path = Plugin/CTFActionButton.m; sourceTree = "<group>"; };
6C09647E10808D4B0006923A /* CTFMainButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFMainButton.h; path = Plugin/CTFMainButton.h; sourceTree = "<group>"; };
6C09647F10808D4B0006923A /* CTFMainButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFMainButton.m; path = Plugin/CTFMainButton.m; sourceTree = "<group>"; };
6C436DAE107830A200A0D525 /* QTKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QTKit.framework; path = /System/Library/Frameworks/QTKit.framework; sourceTree = "<absolute>"; };
6C8E03FD10795EB900E21A50 /* CTFLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFLoader.h; path = Plugin/CTFLoader.h; sourceTree = "<group>"; };
6C8E03FE10795EB900E21A50 /* CTFLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFLoader.m; path = Plugin/CTFLoader.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -283,6 +289,10 @@
children = (
55EB703D0E04A84F0016593D /* Plugin.m */,
55EB703C0E04A84F0016593D /* Plugin.h */,
6C09647F10808D4B0006923A /* CTFMainButton.m */,
6C09647E10808D4B0006923A /* CTFMainButton.h */,
6C09630B107FCA610006923A /* CTFActionButton.m */,
6C09630A107FCA610006923A /* CTFActionButton.h */,
6C8E03FE10795EB900E21A50 /* CTFLoader.m */,
6C8E03FD10795EB900E21A50 /* CTFLoader.h */,
6C8EC6F310764F810053587F /* CTFKiller.m */,
Expand Down Expand Up @@ -593,6 +603,8 @@
6C8EC7E9107686780053587F /* CTFKillerSIFR.m in Sources */,
6CC18AE61076D09B00D9E1A0 /* CTFKillerVimeo.m in Sources */,
6C8E03FF10795EB900E21A50 /* CTFLoader.m in Sources */,
6C09630C107FCA610006923A /* CTFActionButton.m in Sources */,
6C09648010808D4B0006923A /* CTFMainButton.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
28 changes: 28 additions & 0 deletions Plugin/CTFActionButton.h
@@ -0,0 +1,28 @@
//
// CTFActionButton.h
// ClickToFlash
//
// Created by Sven on 09.10.09.
// Copyright 2009 earthlingsoft. All rights reserved.
//

#import <Cocoa/Cocoa.h>




@interface CTFActionButton : NSButton {
}

+ (id) actionButton;

@end


@interface CTFActionButtonCell : NSButtonCell {

}

- (BOOL) gearVisible;

@end
156 changes: 156 additions & 0 deletions Plugin/CTFActionButton.m
@@ -0,0 +1,156 @@
//
// CTFActionButton.m
// ClickToFlash
//
// Created by Sven on 09.10.09.
// Copyright 2009 earthlingsoft. All rights reserved.
//

#import "CTFActionButton.h"
#import "CTFUtilities.h"

static CGFloat padding = 3.;
static CGFloat leftMargin = 5.;
static CGFloat backgroundOpacity = .8;


@implementation CTFActionButton

+ (id) actionButton {
CGFloat margin = 5.;
CGFloat size = 20.;
NSRect gearButtonRect = NSMakeRect( .0, .0, size + 2.*margin , size + 2.*margin );

CTFActionButton * gearButton = [[[CTFActionButton alloc] initWithFrame: gearButtonRect] autorelease];
[gearButton setButtonType: NSMomentaryPushInButton];

return gearButton;
}



#pragma mark NSButton subclassing

+ (Class) cellClass {
return NSClassFromString(@"CTFActionButtonCell");
}



- (void) mouseDown: (NSEvent *) event {
[NSMenu popUpContextMenu:[self menuForEvent:event] withEvent:event forView:self];
}



- (NSMenu*) menuForEvent: (NSEvent*) event {
return [[self superview] menuForEvent: event];
}



- (void) resizeWithOldSuperviewSize:(NSSize) oldBoundsSize {
NSPoint newOrigin;

if ( [[self cell ] gearVisible] ) {
NSSize superSize = [[self superview] bounds].size;
NSRect myRect = [self bounds];
newOrigin = NSMakePoint(myRect.origin.x, superSize.height - myRect.size.height);
}
else {
newOrigin = NSMakePoint( -1000. , -1000. );
}

[self setFrameOrigin: newOrigin];
}


@end






#pragma mark -
#pragma mark NSView subclassing



@implementation CTFActionButtonCell

#pragma mark NSCell subclassing

- (void) drawWithFrame: (NSRect) rect inView:(NSView *) controlView {
NSRect bounds = [[self controlView] bounds];

NSImage * gearImage = [NSImage imageNamed:@"NSActionTemplate"];
// On systems older than 10.5 we need to supply our own image.
if (gearImage == nil) {
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"NSActionTemplate" ofType:@"png"];
gearImage = [[[NSImage alloc] initWithContentsOfFile:path] autorelease];
}

if( gearImage ) {
CGFloat gearSize = [gearImage size].width; // assumes the gear to be square
CGFloat size = gearSize + 2.0 * padding;
CGFloat x = round(bounds.size.width * .5) - round(size * .5);
CGFloat y = round(bounds.size.height * .5 ) - round(size * .5);
NSRect backgroundFrame = NSMakeRect(x, y, size, size);

NSBezierPath * circle = [NSBezierPath bezierPathWithOvalInRect:backgroundFrame];
CGFloat alpha = ( [self isHighlighted] ) ? .9 : .7 ;
[[NSColor colorWithDeviceWhite:1.0 alpha:alpha] set];
[circle fill];

// draw the gear image
[gearImage drawAtPoint:NSMakePoint(x + padding, y + padding)
fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:.9];
}
}




#pragma mark -
#pragma mark Helper

- (BOOL) gearVisible {
NSRect bounds = [[[self controlView] superview] bounds ];
return NSWidth( bounds ) > 32 && NSHeight( bounds ) > 32;
}





#pragma mark -
#pragma mark Accessibility

- (NSArray *) accessibilityAttributeNames {
NSMutableArray * attributes = [[[super accessibilityAttributeNames] mutableCopy] autorelease];
[attributes addObject: NSAccessibilityDescriptionAttribute];
return attributes;
}



- (id) accessibilityAttributeValue: (NSString *) attribute {
id value;

if ( [attribute isEqualToString: NSAccessibilityDescriptionAttribute] ) {
value = CtFLocalizedString( @"ClickTo Flash Contextual menu", @"Accessibility: CTFActionButton, Title of Contextual Menu");
}
else if ( [attribute isEqualToString: NSAccessibilityParentAttribute] ){
value = NSAccessibilityUnignoredAncestor([[self controlView] superview]);
}
else {
value = [super accessibilityAttributeValue:attribute];
}
return value;
}


@end
6 changes: 3 additions & 3 deletions Plugin/CTFKillerVideo.m
Expand Up @@ -661,11 +661,11 @@ - (void) finishedLookups {
}



- (BOOL) canPlayResponseResult: (NSHTTPURLResponse *) response {
// We don't handle anything but HTTP requests.
- (BOOL) canPlayResponseResult: (NSURLResponse *) response {
BOOL result = NO;

if ( [response statusCode] == 200 ) {
if ( [((NSHTTPURLResponse*)response) statusCode] == 200 ) {
if ( [[response MIMEType] isEqualToString:@"video/mp4"] ) {
result = YES;
}
Expand Down
6 changes: 3 additions & 3 deletions Plugin/CTFLoader.m
Expand Up @@ -86,11 +86,11 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *) newDa



- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)theResponse {
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)theResponse {
[self setResponse: theResponse];

// We need to cancel HEAD fetching connections here as 10.5 may proceed to download the whole file otherwise (http://openradar.appspot.com/7019347)
if ( [self HEADOnly] && [theResponse statusCode] == 200 ) {
// We need to cancel HEAD fetching connections here as 10.5 may proceed to download the whole file otherwise ( http://openradar.appspot.com/7019347 )
if ( [self HEADOnly] && [(NSHTTPURLResponse*) theResponse statusCode] == 200 ) {
[self finish];
[connection cancel];
}
Expand Down
33 changes: 33 additions & 0 deletions Plugin/CTFMainButton.h
@@ -0,0 +1,33 @@
//
// CTFMainButton.h
// ClickToFlash
//
// Created by Sven on 10.10.09.
// Copyright 2009 earthlingsoft. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface CTFMainButton : NSButton {

}

@end



#pragma mark -

@interface CTFMainButtonCell : NSButtonCell {

}

- (void) drawGradientInRect: (NSRect) rect;
- (void) drawPreviewInRect: (NSRect) rect;
- (void) drawBadgeForBounds: (NSRect) bounds;
- (void) drawGlossForBounds: (NSRect) bounds;

- (NSString*) badgeLabelText;

@end

0 comments on commit fd8eff3

Please sign in to comment.