Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Provide a way of adding more buttons to the view.

Only the Full Screen playback button is implemented for movies here.

Next we should discuss which buttons we actually want by default. Opinions about that seem to differ.
  • Loading branch information...
commit 2b774463dd226a8c3ada454a6d6a9bf06c0d6d0b 1 parent 72e11d2
@ssp authored
View
6 ClickToFlash.xcodeproj/project.pbxproj
@@ -45,6 +45,7 @@
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 */; };
+ 6C05EE1E1081E59700616436 /* CTFButtonsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C05EE1D1081E59700616436 /* CTFButtonsView.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 */; };
@@ -156,6 +157,8 @@
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>"; };
+ 6C05EE1C1081E59700616436 /* CTFButtonsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFButtonsView.h; path = Plugin/CTFButtonsView.h; sourceTree = "<group>"; };
+ 6C05EE1D1081E59700616436 /* CTFButtonsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFButtonsView.m; path = Plugin/CTFButtonsView.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>"; };
@@ -256,6 +259,8 @@
6C09647E10808D4B0006923A /* CTFMainButton.h */,
6C09630B107FCA610006923A /* CTFActionButton.m */,
6C09630A107FCA610006923A /* CTFActionButton.h */,
+ 6C05EE1D1081E59700616436 /* CTFButtonsView.m */,
+ 6C05EE1C1081E59700616436 /* CTFButtonsView.h */,
6C8E03FE10795EB900E21A50 /* CTFLoader.m */,
6C8E03FD10795EB900E21A50 /* CTFLoader.h */,
6C8EC6F310764F810053587F /* CTFKiller.m */,
@@ -527,6 +532,7 @@
6C8E03FF10795EB900E21A50 /* CTFLoader.m in Sources */,
6C09630C107FCA610006923A /* CTFActionButton.m in Sources */,
6C09648010808D4B0006923A /* CTFMainButton.m in Sources */,
+ 6C05EE1E1081E59700616436 /* CTFButtonsView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
24 Plugin/CTFButtonsView.h
@@ -0,0 +1,24 @@
+//
+// CTFButtonsView.h
+// ClickToFlash
+//
+// Created by Sven on 11.10.09.
+// Copyright 2009 earthlingsoft. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface CTFButtonsView : NSView {
+ NSMutableArray * buttons;
+}
+
++ (NSButton *) button;
+
+- (void) insertButton: (NSControl*) button atIndex: (NSInteger) index;
+- (void) addButton: (NSControl*) button;
+- (void) removeButton: (NSControl*) button;
+- (void) arrangeButtons;
+
+
+@end
View
126 Plugin/CTFButtonsView.m
@@ -0,0 +1,126 @@
+//
+// CTFButtonsView.m
+// ClickToFlash
+//
+// Created by Sven on 11.10.09.
+// Copyright 2009 earthlingsoft. All rights reserved.
+//
+
+#import "CTFButtonsView.h"
+
+static CGFloat interButtonGap = 4.;
+static CGFloat topMargin = 4.;
+static CGFloat rightMargin = 6.;
+static CGFloat bottomMargin = 4.;
+static CGFloat leftMargin = 32.;
+static CGFloat height = 32.;
+
+
+@implementation CTFButtonsView
+
+- (id) initWithFrame: (NSRect) frame {
+ self = [super initWithFrame: frame];
+
+ if (self != nil) {
+ buttons = [[NSMutableArray alloc] initWithCapacity:5];
+ }
+
+ return self;
+}
+
+
+- (void) dealloc {
+ [buttons release];
+ [super dealloc];
+}
+
+
+
+
+
+
+#pragma mark -
+#pragma mark Convenience
+
+
++ (NSButton *) button {
+ NSRect frame = NSMakeRect(.0, .0, 32., 32.); // correct frame is set later on -resizeWithOldSuperviewSize:
+ NSButton * button = [[[NSButton alloc] initWithFrame:frame] autorelease];
+ [button setButtonType: NSMomentaryLight];
+ [button setBezelStyle: NSTexturedRoundedBezelStyle];
+ return button;
+}
+
+
+
+
+
+#pragma mark -
+#pragma mark NSView subclassing
+
+- (void) resizeWithOldSuperviewSize: (NSSize) oldBoundsSize {
+ NSRect superRect = [[self superview] bounds];
+ CGFloat width = superRect.size.width - rightMargin - leftMargin;
+ CGFloat bottom = superRect.size.height - topMargin - height;
+
+ if ( bottom > 8. && width > 16.) {
+ NSRect newFrame = NSMakeRect(leftMargin, bottom, width, height);
+ [self setFrame: newFrame];
+ [self arrangeButtons];
+ [self setHidden: NO];
+ }
+ else {
+ [self setHidden: YES];
+ }
+
+}
+
+
+
+
+
+
+#pragma mark -
+#pragma mark Manage Buttons
+
+- (void) insertButton: (NSControl*) button atIndex: (NSInteger) index {
+ [buttons insertObject:button atIndex:index];
+ [self addSubview: button];
+ [self arrangeButtons];
+}
+
+
+- (void) addButton: (NSControl*) button {
+ [self insertButton:button atIndex:[buttons count]];
+}
+
+
+- (void) removeButton: (NSControl*) button {
+ [buttons removeObject:button];
+ [self arrangeButtons];
+}
+
+
+
+// Buttons are arranged at the top right of the view from the right;
+- (void) arrangeButtons {
+ NSSize mySize = [self bounds].size;
+ CGFloat currentPosition = mySize.width;
+
+ NSEnumerator * buttonEnum = [buttons objectEnumerator];
+ NSControl * button;
+ while ( (button = [buttonEnum nextObject]) ) {
+ NSRect buttonFrame = [button frame];
+ CGFloat buttonLeft = currentPosition - buttonFrame.size.width;
+ CGFloat buttonBottom = mySize.height - buttonFrame.size.height;
+ [button setFrameOrigin:NSMakePoint(buttonLeft, buttonBottom)];
+
+ // completely hide buttons that would be cut off
+ [button setHidden: (buttonLeft < 0)];
+
+ currentPosition = buttonLeft - interButtonGap;
+ }
+}
+
+
+@end
View
9 Plugin/CTFKillerVideo.h
@@ -47,6 +47,8 @@ enum CTFKVLookupStatus {
BOOL requiresConversion;
NSSize videoSize;
+
+ NSButton * fullscreenButton;
}
/*
@@ -122,8 +124,9 @@ enum CTFKVLookupStatus {
- (void) setLookupStatus: (enum CTFKVLookupStatus) newLookupStatus;
- (void) increaseActiveLookups;
- (void) decreaseActiveLookups;
-- (BOOL)requiresConversion;
-- (void)setRequiresConversion:(BOOL)newRequiresConversion;
-
+- (BOOL) requiresConversion;
+- (void) setRequiresConversion: (BOOL) newRequiresConversion;
+- (NSButton *) fullscreenButton;
+- (void) setFullscreenButton: (NSButton *) newFullscreenButton;
@end
View
36 Plugin/CTFKillerVideo.m
@@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTFUserDefaultsController.h"
#import "CTFUtilities.h"
#import "Plugin.h"
+#import "CTFButtonsView.h"
static NSString * divCSS = @"margin:auto;padding:0px;border:0px none;text-align:center;display:block;float:none;";
static NSString * sDisableVideoElement = @"disableVideoElement";
@@ -55,6 +56,7 @@ - (id) init {
requiresConversion = NO;
videoSize = NSZeroSize;
+ [self setFullscreenButton:nil];
}
return self;
@@ -62,6 +64,7 @@ - (id) init {
- (void) dealloc {
+ [self setFullscreenButton:nil];
[super dealloc];
}
@@ -682,6 +685,21 @@ - (BOOL) canPlayResponseResult: (NSURLResponse *) response {
+- (void) setupButtons {
+ if ( [self fullscreenButton] == nil ) {
+ NSButton * button = [CTFButtonsView button];
+ [button setImage: [NSImage imageNamed:NSImageNameEnterFullScreenTemplate]];
+ [button setToolTip: CtFLocalizedString( @"Play Fullscreen in QuickTime Player", @"*Same as for menu item, used in setupButtons*" )];
+ [button sizeToFit];
+ [button setTarget: self];
+ [button setAction: @selector(openFullscreenInQTPlayer:)];
+ [self setFullscreenButton: button];
+ [[[self plugin] buttonsView] addButton: button];
+ }
+}
+
+
+
#pragma mark -
#pragma mark Accessors
@@ -703,6 +721,7 @@ - (BOOL)hasVideo {
- (void)setHasVideo:(BOOL)newHasVideo {
hasVideo = newHasVideo;
+ [self setupButtons];
[[self plugin] setNeedsDisplay: YES];
}
@@ -713,6 +732,7 @@ - (BOOL)hasVideoHD {
- (void)setHasVideoHD:(BOOL)newHasVideoHD {
hasVideoHD = newHasVideoHD;
+ [self setupButtons];
[[self plugin] setNeedsDisplay: YES];
}
@@ -743,16 +763,24 @@ - (void) decreaseActiveLookups {
}
-- (BOOL)requiresConversion
-{
+- (BOOL) requiresConversion {
return requiresConversion;
}
-- (void)setRequiresConversion:(BOOL)newRequiresConversion
-{
+- (void) setRequiresConversion: (BOOL) newRequiresConversion {
requiresConversion = newRequiresConversion;
}
+
+- (NSButton *) fullscreenButton {
+ return fullscreenButton;
+}
+
+- (void) setFullscreenButton: (NSButton *) newFullscreenButton {
+ [newFullscreenButton retain];
+ [fullscreenButton release];
+ fullscreenButton = newFullscreenButton;
+}
@end
View
4 Plugin/Plugin.h
@@ -28,6 +28,7 @@ THE SOFTWARE.
#import <WebKit/WebKit.h>
@class CTFKiller;
+@class CTFButtonsView;
@interface CTFClickToFlashPlugin : NSView <WebPlugInViewFactory> {
NSArray *defaultWhitelist;
@@ -50,6 +51,7 @@ THE SOFTWARE.
BOOL _contextMenuIsVisible;
NSTimer *_delayingTimer;
+ CTFButtonsView * buttonsView;
CTFKiller * killer;
NSURL * previewURL;
@@ -86,6 +88,8 @@ THE SOFTWARE.
- (CTFKiller *) killer;
- (void)setKiller:(CTFKiller *)newKiller;
+- (CTFButtonsView *) buttonsView;
+- (void) setButtonsView: (CTFButtonsView *) newButtonsView;
- (DOMElement *)container;
- (void)setContainer:(DOMElement *)newValue;
- (NSString *)host;
View
28 Plugin/Plugin.m
@@ -36,7 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
#import "CTFLoader.h"
#import "CTFActionButton.h"
#import "CTFMainButton.h"
-
+#import "CTFButtonsView.h"
#define LOGGING_ENABLED 0
@@ -48,15 +48,13 @@ of this software and associated documentation files (the "Software"), to deal
static NSString *sAutoLoadInvisibleFlashViewsKey = @"autoLoadInvisibleViews";
static NSString *sPluginEnabled = @"pluginEnabled";
static NSString *sApplicationWhitelist = @"applicationWhitelist";
-static NSString *sDrawGearImageOnlyOnMouseOverHiddenPref = @"drawGearImageOnlyOnMouseOver";
+// static NSString *sDrawGearImageOnlyOnMouseOverHiddenPref = @"drawGearImageOnlyOnMouseOver";
// Info.plist key for app developers
static NSString *sCTFOptOutKey = @"ClickToFlashOptOut";
// Subview Tags
enum subviewTags {
- CTFGradientViewTag,
- CTFImageViewTag,
CTFMainButtonTag,
CTFActionButtonTag
};
@@ -312,8 +310,10 @@ - (id) initWithArguments:(NSDictionary *)arguments
[self setOriginalOpacityAttributes:originalOpacityDict];
+ NSRect myBounds = [self bounds];
+
// Add main control button
- CTFMainButton * mainButton = [[[CTFMainButton alloc] initWithFrame: [self bounds]] autorelease];
+ CTFMainButton * mainButton = [[[CTFMainButton alloc] initWithFrame: myBounds] autorelease];
[mainButton setTag: CTFMainButtonTag];
[mainButton setAutoresizingMask: (NSViewHeightSizable | NSViewWidthSizable) ];
[mainButton setButtonType: NSMomentaryPushInButton];
@@ -337,6 +337,12 @@ - (id) initWithArguments:(NSDictionary *)arguments
[actionButton setTag: CTFActionButtonTag];
[actionButton setAutoresizingMask: NSViewMaxXMargin | NSViewMinYMargin];
[self addSubview: actionButton];
+
+ // Add view for additional buttons (proper sizing is done by view itself)
+ CTFButtonsView * theButtonsView = [[[CTFButtonsView alloc] initWithFrame: myBounds] autorelease];
+ [theButtonsView setAutoresizingMask: NSViewWidthSizable];
+ [self addSubview: theButtonsView];
+ [self setButtonsView: theButtonsView];
}
return self;
@@ -360,6 +366,7 @@ - (void)webPlugInDestroy
[self setAttributes:nil];
[self setOriginalOpacityAttributes:nil];
[self setKiller:nil];
+ [self setButtonsView:nil];
[self setPreviewURL:nil];
[self setPreviewImage:nil];
@@ -985,6 +992,17 @@ - (void)setKiller:(CTFKiller *)newKiller
}
+- (CTFButtonsView *) buttonsView {
+ return buttonsView;
+}
+
+- (void) setButtonsView: (CTFButtonsView *) newButtonsView {
+ [newButtonsView retain];
+ [buttonsView release];
+ buttonsView = newButtonsView;
+}
+
+
- (NSURL *) previewURL {
return previewURL;
}
Please sign in to comment.
Something went wrong with that request. Please try again.