Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
6  ClickToFlash.xcodeproj/project.pbxproj
@@ -45,6 +45,7 @@
45 45
 		6953E4360F3EDE9D0014ECF7 /* CTFMenubarMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6953E4340F3EDE9D0014ECF7 /* CTFMenubarMenuController.m */; };
46 46
 		6953E43C0F3EDEB50014ECF7 /* MenubarMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6953E43A0F3EDEB50014ECF7 /* MenubarMenu.xib */; };
47 47
 		69A26D0C0F302C10006648BC /* NSBezierPath-RoundedRectangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */; };
  48
+		6C05EE1E1081E59700616436 /* CTFButtonsView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C05EE1D1081E59700616436 /* CTFButtonsView.m */; };
48 49
 		6C09630C107FCA610006923A /* CTFActionButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C09630B107FCA610006923A /* CTFActionButton.m */; };
49 50
 		6C09648010808D4B0006923A /* CTFMainButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6C09647F10808D4B0006923A /* CTFMainButton.m */; };
50 51
 		6C2C5A6A1068CE8700A90A54 /* Credits.css in Resources */ = {isa = PBXBuildFile; fileRef = A40485B110629B0E00FDC4E2 /* Credits.css */; };
@@ -156,6 +157,8 @@
156 157
 		6953E43B0F3EDEB50014ECF7 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Plugin/English.lproj/MenubarMenu.xib; sourceTree = "<group>"; };
157 158
 		69A26D0A0F302C10006648BC /* NSBezierPath-RoundedRectangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSBezierPath-RoundedRectangle.h"; path = "Plugin/NSBezierPath-RoundedRectangle.h"; sourceTree = "<group>"; };
158 159
 		69A26D0B0F302C10006648BC /* NSBezierPath-RoundedRectangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSBezierPath-RoundedRectangle.m"; path = "Plugin/NSBezierPath-RoundedRectangle.m"; sourceTree = "<group>"; };
  160
+		6C05EE1C1081E59700616436 /* CTFButtonsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFButtonsView.h; path = Plugin/CTFButtonsView.h; sourceTree = "<group>"; };
  161
+		6C05EE1D1081E59700616436 /* CTFButtonsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFButtonsView.m; path = Plugin/CTFButtonsView.m; sourceTree = "<group>"; };
159 162
 		6C09630A107FCA610006923A /* CTFActionButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFActionButton.h; path = Plugin/CTFActionButton.h; sourceTree = "<group>"; };
160 163
 		6C09630B107FCA610006923A /* CTFActionButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTFActionButton.m; path = Plugin/CTFActionButton.m; sourceTree = "<group>"; };
161 164
 		6C09647E10808D4B0006923A /* CTFMainButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTFMainButton.h; path = Plugin/CTFMainButton.h; sourceTree = "<group>"; };
@@ -256,6 +259,8 @@
256 259
 				6C09647E10808D4B0006923A /* CTFMainButton.h */,
257 260
 				6C09630B107FCA610006923A /* CTFActionButton.m */,
258 261
 				6C09630A107FCA610006923A /* CTFActionButton.h */,
  262
+				6C05EE1D1081E59700616436 /* CTFButtonsView.m */,
  263
+				6C05EE1C1081E59700616436 /* CTFButtonsView.h */,
259 264
 				6C8E03FE10795EB900E21A50 /* CTFLoader.m */,
260 265
 				6C8E03FD10795EB900E21A50 /* CTFLoader.h */,
261 266
 				6C8EC6F310764F810053587F /* CTFKiller.m */,
@@ -527,6 +532,7 @@
527 532
 				6C8E03FF10795EB900E21A50 /* CTFLoader.m in Sources */,
528 533
 				6C09630C107FCA610006923A /* CTFActionButton.m in Sources */,
529 534
 				6C09648010808D4B0006923A /* CTFMainButton.m in Sources */,
  535
+				6C05EE1E1081E59700616436 /* CTFButtonsView.m in Sources */,
530 536
 			);
531 537
 			runOnlyForDeploymentPostprocessing = 0;
532 538
 		};
24  Plugin/CTFButtonsView.h
... ...
@@ -0,0 +1,24 @@
  1
+//
  2
+//  CTFButtonsView.h
  3
+//  ClickToFlash
  4
+//
  5
+//  Created by  Sven on 11.10.09.
  6
+//  Copyright 2009 earthlingsoft. All rights reserved.
  7
+//
  8
+
  9
+#import <Cocoa/Cocoa.h>
  10
+
  11
+
  12
+@interface CTFButtonsView : NSView {
  13
+	NSMutableArray * buttons;
  14
+}
  15
+
  16
++ (NSButton *) button;
  17
+
  18
+- (void) insertButton: (NSControl*) button atIndex: (NSInteger) index;
  19
+- (void) addButton: (NSControl*) button;
  20
+- (void) removeButton: (NSControl*) button;
  21
+- (void) arrangeButtons;
  22
+
  23
+
  24
+@end
126  Plugin/CTFButtonsView.m
... ...
@@ -0,0 +1,126 @@
  1
+//
  2
+//  CTFButtonsView.m
  3
+//  ClickToFlash
  4
+//
  5
+//  Created by  Sven on 11.10.09.
  6
+//  Copyright 2009 earthlingsoft. All rights reserved.
  7
+//
  8
+
  9
+#import "CTFButtonsView.h"
  10
+
  11
+static CGFloat interButtonGap = 4.;
  12
+static CGFloat topMargin = 4.;
  13
+static CGFloat rightMargin = 6.;
  14
+static CGFloat bottomMargin = 4.;
  15
+static CGFloat leftMargin = 32.;
  16
+static CGFloat height = 32.;
  17
+
  18
+
  19
+@implementation CTFButtonsView
  20
+
  21
+- (id) initWithFrame: (NSRect) frame {
  22
+	self = [super initWithFrame: frame];
  23
+	
  24
+	if (self != nil) {
  25
+		buttons = [[NSMutableArray alloc] initWithCapacity:5];
  26
+	}
  27
+	
  28
+	return self;
  29
+}
  30
+
  31
+
  32
+- (void) dealloc {
  33
+	[buttons release];
  34
+	[super dealloc];
  35
+}
  36
+
  37
+
  38
+
  39
+
  40
+
  41
+
  42
+#pragma mark -
  43
+#pragma mark Convenience
  44
+
  45
+
  46
++ (NSButton *) button {
  47
+	NSRect frame = NSMakeRect(.0, .0, 32., 32.); // correct frame is set later on -resizeWithOldSuperviewSize:
  48
+	NSButton * button = [[[NSButton alloc] initWithFrame:frame] autorelease];
  49
+	[button setButtonType: NSMomentaryLight];
  50
+	[button setBezelStyle: NSTexturedRoundedBezelStyle];
  51
+	return button;
  52
+}
  53
+
  54
+
  55
+
  56
+
  57
+
  58
+#pragma mark -
  59
+#pragma mark NSView subclassing
  60
+
  61
+- (void) resizeWithOldSuperviewSize: (NSSize) oldBoundsSize {
  62
+	NSRect superRect = [[self superview] bounds];
  63
+	CGFloat width = superRect.size.width - rightMargin - leftMargin;
  64
+	CGFloat bottom = superRect.size.height - topMargin - height;
  65
+	
  66
+	if ( bottom > 8. && width > 16.) {
  67
+		NSRect newFrame = NSMakeRect(leftMargin, bottom, width, height);
  68
+		[self setFrame: newFrame];
  69
+		[self arrangeButtons];
  70
+		[self setHidden: NO];
  71
+	}
  72
+	else {
  73
+		[self setHidden: YES];
  74
+	}
  75
+	
  76
+}
  77
+
  78
+
  79
+
  80
+
  81
+
  82
+
  83
+#pragma mark -
  84
+#pragma mark Manage Buttons
  85
+
  86
+- (void) insertButton: (NSControl*) button atIndex: (NSInteger) index {
  87
+	[buttons insertObject:button atIndex:index];
  88
+	[self addSubview: button];
  89
+	[self arrangeButtons];
  90
+}
  91
+
  92
+
  93
+- (void) addButton: (NSControl*) button {
  94
+	[self insertButton:button atIndex:[buttons count]];
  95
+}
  96
+
  97
+
  98
+- (void) removeButton: (NSControl*) button {
  99
+	[buttons removeObject:button];
  100
+	[self arrangeButtons];
  101
+}
  102
+
  103
+	 
  104
+
  105
+// Buttons are arranged at the top right of the view from the right;
  106
+- (void) arrangeButtons {
  107
+	NSSize mySize = [self bounds].size;
  108
+	CGFloat currentPosition = mySize.width;
  109
+	
  110
+	NSEnumerator * buttonEnum = [buttons objectEnumerator];
  111
+	NSControl * button;
  112
+	while ( (button = [buttonEnum nextObject]) ) {
  113
+		NSRect buttonFrame = [button frame];
  114
+		CGFloat buttonLeft = currentPosition - buttonFrame.size.width;
  115
+		CGFloat buttonBottom = mySize.height - buttonFrame.size.height;
  116
+		[button setFrameOrigin:NSMakePoint(buttonLeft, buttonBottom)];
  117
+		
  118
+		// completely hide buttons that would be cut off
  119
+		[button setHidden: (buttonLeft < 0)];
  120
+		
  121
+		currentPosition = buttonLeft - interButtonGap;
  122
+	}
  123
+}
  124
+
  125
+
  126
+@end
9  Plugin/CTFKillerVideo.h
@@ -47,6 +47,8 @@ enum CTFKVLookupStatus {
47 47
 	BOOL requiresConversion;
48 48
 	
49 49
 	NSSize videoSize;
  50
+	
  51
+	NSButton * fullscreenButton;
50 52
 }
51 53
 
52 54
 /*
@@ -122,8 +124,9 @@ enum CTFKVLookupStatus {
122 124
 - (void) setLookupStatus: (enum CTFKVLookupStatus) newLookupStatus;
123 125
 - (void) increaseActiveLookups;
124 126
 - (void) decreaseActiveLookups;
125  
-- (BOOL)requiresConversion;
126  
-- (void)setRequiresConversion:(BOOL)newRequiresConversion;
127  
-
  127
+- (BOOL) requiresConversion;
  128
+- (void) setRequiresConversion: (BOOL) newRequiresConversion;
  129
+- (NSButton *) fullscreenButton;
  130
+- (void) setFullscreenButton: (NSButton *) newFullscreenButton;
128 131
 
129 132
 @end
36  Plugin/CTFKillerVideo.m
@@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
31 31
 #import "CTFUserDefaultsController.h"
32 32
 #import "CTFUtilities.h"
33 33
 #import "Plugin.h"
  34
+#import "CTFButtonsView.h"
34 35
 
35 36
 static NSString * divCSS = @"margin:auto;padding:0px;border:0px none;text-align:center;display:block;float:none;";
36 37
 static NSString * sDisableVideoElement = @"disableVideoElement";
@@ -55,6 +56,7 @@ - (id) init {
55 56
 		requiresConversion = NO;
56 57
 		
57 58
 		videoSize = NSZeroSize;
  59
+		[self setFullscreenButton:nil];
58 60
 	}
59 61
 	
60 62
 	return self;
@@ -62,6 +64,7 @@ - (id) init {
62 64
 
63 65
 
64 66
 - (void) dealloc {
  67
+	[self setFullscreenButton:nil];
65 68
 	[super dealloc];
66 69
 }
67 70
 
@@ -682,6 +685,21 @@ - (BOOL) canPlayResponseResult: (NSURLResponse *) response {
682 685
 
683 686
 
684 687
 
  688
+- (void) setupButtons {
  689
+	if ( [self fullscreenButton] == nil ) {
  690
+		NSButton * button = [CTFButtonsView button];
  691
+		[button setImage: [NSImage imageNamed:NSImageNameEnterFullScreenTemplate]];
  692
+		[button setToolTip: CtFLocalizedString( @"Play Fullscreen in QuickTime Player", @"*Same as for menu item, used in setupButtons*" )];
  693
+		[button sizeToFit];
  694
+		[button setTarget: self];
  695
+		[button setAction: @selector(openFullscreenInQTPlayer:)];
  696
+		[self setFullscreenButton: button];
  697
+		[[[self plugin] buttonsView] addButton: button];
  698
+	}
  699
+}
  700
+
  701
+
  702
+
685 703
 
686 704
 #pragma mark -
687 705
 #pragma mark Accessors
@@ -703,6 +721,7 @@ - (BOOL)hasVideo {
703 721
 
704 722
 - (void)setHasVideo:(BOOL)newHasVideo {
705 723
 	hasVideo = newHasVideo;
  724
+	[self setupButtons];
706 725
 	[[self plugin] setNeedsDisplay: YES];
707 726
 }
708 727
 
@@ -713,6 +732,7 @@ - (BOOL)hasVideoHD {
713 732
 
714 733
 - (void)setHasVideoHD:(BOOL)newHasVideoHD {
715 734
 	hasVideoHD = newHasVideoHD;
  735
+	[self setupButtons];
716 736
 	[[self plugin] setNeedsDisplay: YES];
717 737
 }
718 738
 
@@ -743,16 +763,24 @@ - (void) decreaseActiveLookups {
743 763
 }
744 764
 
745 765
 
746  
-- (BOOL)requiresConversion
747  
-{
  766
+- (BOOL) requiresConversion {
748 767
 	return requiresConversion;
749 768
 }
750 769
 
751  
-- (void)setRequiresConversion:(BOOL)newRequiresConversion
752  
-{
  770
+- (void) setRequiresConversion: (BOOL) newRequiresConversion {
753 771
 	requiresConversion = newRequiresConversion;
754 772
 }
755 773
 
  774
+			
  775
+- (NSButton *) fullscreenButton {
  776
+	return fullscreenButton;
  777
+}
  778
+
  779
+- (void) setFullscreenButton: (NSButton *) newFullscreenButton {
  780
+	[newFullscreenButton retain];
  781
+	[fullscreenButton release];
  782
+	fullscreenButton = newFullscreenButton;
  783
+}			
756 784
 
757 785
 @end
758 786
 
4  Plugin/Plugin.h
@@ -28,6 +28,7 @@ THE SOFTWARE.
28 28
 #import <WebKit/WebKit.h>
29 29
 
30 30
 @class CTFKiller;
  31
+@class CTFButtonsView;
31 32
 
32 33
 @interface CTFClickToFlashPlugin : NSView <WebPlugInViewFactory> {
33 34
 	NSArray *defaultWhitelist;
@@ -50,6 +51,7 @@ THE SOFTWARE.
50 51
 	BOOL _contextMenuIsVisible;
51 52
 	NSTimer *_delayingTimer;
52 53
 	
  54
+	CTFButtonsView * buttonsView;
53 55
 	CTFKiller * killer;
54 56
 	
55 57
 	NSURL * previewURL;
@@ -86,6 +88,8 @@ THE SOFTWARE.
86 88
 
87 89
 - (CTFKiller *) killer;
88 90
 - (void)setKiller:(CTFKiller *)newKiller;
  91
+- (CTFButtonsView *) buttonsView;
  92
+- (void) setButtonsView: (CTFButtonsView *) newButtonsView;
89 93
 - (DOMElement *)container;
90 94
 - (void)setContainer:(DOMElement *)newValue;
91 95
 - (NSString *)host;
28  Plugin/Plugin.m
@@ -36,7 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
36 36
 #import "CTFLoader.h"
37 37
 #import "CTFActionButton.h"
38 38
 #import "CTFMainButton.h"
39  
-
  39
+#import "CTFButtonsView.h"
40 40
 
41 41
 #define LOGGING_ENABLED 0
42 42
 
@@ -48,15 +48,13 @@ of this software and associated documentation files (the "Software"), to deal
48 48
 static NSString *sAutoLoadInvisibleFlashViewsKey = @"autoLoadInvisibleViews";
49 49
 static NSString *sPluginEnabled = @"pluginEnabled";
50 50
 static NSString *sApplicationWhitelist = @"applicationWhitelist";
51  
-static NSString *sDrawGearImageOnlyOnMouseOverHiddenPref = @"drawGearImageOnlyOnMouseOver";
  51
+// static NSString *sDrawGearImageOnlyOnMouseOverHiddenPref = @"drawGearImageOnlyOnMouseOver";
52 52
 
53 53
 // Info.plist key for app developers
54 54
 static NSString *sCTFOptOutKey = @"ClickToFlashOptOut";
55 55
 
56 56
 // Subview Tags
57 57
 enum subviewTags {
58  
-	CTFGradientViewTag,
59  
-	CTFImageViewTag,
60 58
 	CTFMainButtonTag,
61 59
 	CTFActionButtonTag
62 60
 };
@@ -312,8 +310,10 @@ - (id) initWithArguments:(NSDictionary *)arguments
312 310
 		
313 311
 		[self setOriginalOpacityAttributes:originalOpacityDict];
314 312
 		
  313
+		NSRect myBounds = [self bounds];
  314
+		
315 315
 		// Add main control button
316  
-		CTFMainButton * mainButton = [[[CTFMainButton alloc] initWithFrame: [self bounds]] autorelease];
  316
+		CTFMainButton * mainButton = [[[CTFMainButton alloc] initWithFrame: myBounds] autorelease];
317 317
 		[mainButton setTag: CTFMainButtonTag];
318 318
 		[mainButton setAutoresizingMask: (NSViewHeightSizable | NSViewWidthSizable) ];
319 319
 		[mainButton setButtonType: NSMomentaryPushInButton];
@@ -337,6 +337,12 @@ - (id) initWithArguments:(NSDictionary *)arguments
337 337
 		[actionButton setTag: CTFActionButtonTag];
338 338
 		[actionButton setAutoresizingMask: NSViewMaxXMargin | NSViewMinYMargin];
339 339
 		[self addSubview: actionButton];
  340
+		
  341
+		// Add view for additional buttons (proper sizing is done by view itself)
  342
+		CTFButtonsView * theButtonsView = [[[CTFButtonsView alloc] initWithFrame: myBounds] autorelease];
  343
+		[theButtonsView setAutoresizingMask: NSViewWidthSizable];
  344
+		[self addSubview: theButtonsView];
  345
+		[self setButtonsView: theButtonsView];
340 346
 	}
341 347
 
342 348
     return self;
@@ -360,6 +366,7 @@ - (void)webPlugInDestroy
360 366
 	[self setAttributes:nil];
361 367
 	[self setOriginalOpacityAttributes:nil];
362 368
 	[self setKiller:nil];
  369
+	[self setButtonsView:nil];
363 370
 	[self setPreviewURL:nil];
364 371
 	[self setPreviewImage:nil];
365 372
 	
@@ -985,6 +992,17 @@ - (void)setKiller:(CTFKiller *)newKiller
985 992
 }
986 993
 
987 994
 
  995
+- (CTFButtonsView *) buttonsView {
  996
+	return buttonsView;
  997
+}
  998
+
  999
+- (void) setButtonsView: (CTFButtonsView *) newButtonsView {
  1000
+	[newButtonsView retain];
  1001
+	[buttonsView release];
  1002
+	buttonsView = newButtonsView;
  1003
+}
  1004
+
  1005
+
988 1006
 - (NSURL *) previewURL {
989 1007
 	return previewURL;
990 1008
 }

0 notes on commit 2b77446

Please sign in to comment.
Something went wrong with that request. Please try again.