Permalink
Browse files

Re-factoring for Sound (part 2)

  • Loading branch information...
1 parent a176150 commit 03ad21bac9eb4709295b61a46951ecf8c9f6125e shazron committed Apr 30, 2010
View
@@ -3,9 +3,12 @@
* phonegap-mac
*
* Created by shazron on 10-04-08.
- * Copyright 2010 __MyCompanyName__. All rights reserved.
+ * Copyright 2010 Nitobi Software Inc. All rights reserved.
*
*/
-#define USER_AGENT_IPHONE_OS @"Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
+#define kStartPage @"index.html"
+#define kStartFolder @"www"
+
+
View
@@ -9,13 +9,16 @@
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
+@class WebViewDelegate;
@interface ContentView : NSView {
IBOutlet WebView* webView;
+ WebViewDelegate* delegate;
}
@property (retain) WebView* webView;
+@property (retain) WebViewDelegate* delegate;
@end
View
@@ -7,115 +7,45 @@
//
#import "ContentView.h"
+#import "WebViewDelegate.h"
#import "phonegap_macAppDelegate.h"
@implementation ContentView
-@synthesize webView;
+@synthesize webView, delegate;
- (void) awakeFromNib
{
- [self.webView setFrameLoadDelegate:self];
- [self.webView setUIDelegate:self];
- [self.webView setResourceLoadDelegate:self];
- [self.webView setDownloadDelegate:self];
- [self.webView setPolicyDelegate:self];
+ self.delegate = [[[WebViewDelegate alloc] init] autorelease];
+ [self.webView setFrameLoadDelegate:self.delegate];
+ [self.webView setUIDelegate:self.delegate];
+ [self.webView setResourceLoadDelegate:self.delegate];
+ [self.webView setDownloadDelegate:self.delegate];
+ [self.webView setPolicyDelegate:self.delegate];
}
-- (id)initWithFrame:(NSRect)frame {
+- (id)initWithFrame:(NSRect)frame
+{
self = [super initWithFrame:frame];
if (self) {
// init here
}
return self;
}
-- (void)drawRect:(NSRect)dirtyRect {
+- (void) drawRect:(NSRect)dirtyRect
+{
// Drawing code here.
}
-- (void)windowResized:(NSNotification *)notification;
+- (void) windowResized:(NSNotification*)notification;
{
NSWindow* window = (NSWindow*)notification.object;
NSSize size = [window frame].size;
- NSLog(@"window width = %f, window height = %f", size.width, size.height);
- [self.webView setFrame:NSMakeRect(0, 0, size.width, size.height - [phonegap_macAppDelegate titleBarHeight:window])];
-}
-
-- (void)webView:(WebView *)webView windowScriptObjectAvailable:(WebScriptObject *)windowScriptObject;
-{
- [windowScriptObject setValue:self forKey:@"phonegap"];
-}
-
-- (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)message;
-{
- if (![message isKindOfClass:[NSDictionary class]]) return;
-
- //NSLog(@"js console: %@", [message description]);
- NSLog(@"js: %@:%@: %@",
- [[message objectForKey:@"sourceURL"] lastPathComponent], //could be nil
- [message objectForKey:@"lineNumber"],
- [message objectForKey:@"message"]);
-}
-
-- (void) playSound:(NSString*)soundFile
-{
- NSURL* fileUrl = [NSURL fileURLWithPath:[phonegap_macAppDelegate pathForResource:soundFile]];
- NSLog(@"SoundFile:%@", [fileUrl description]);
-
- NSSound* sound = [[NSSound alloc] initWithContentsOfURL:fileUrl byReference:YES];
- [sound play];
-}
-
-#pragma mark WebScripting protocol
-
-//------------------------------------------------------------------------------
-// • + isSelectorExcludedFromWebScript:
-//------------------------------------------------------------------------------
-// loops through the list to see if the given selector is acceptable.
-
-+ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector
-{
- BOOL result = YES;
-
- int i = 0;
- static SEL *acceptableList = NULL;
- SEL currentSelector;
-
- if (acceptableList == NULL && (acceptableList = calloc(256, sizeof(SEL)))) //up to 256 selectors
- {
- acceptableList[i++] = @selector(playSound:);
- }
-
- i = 0;
- while (result == YES && (currentSelector = acceptableList[i++]))
- {
- //checking for exclusions
- result = !(selector == currentSelector);
- }
-
- return result;
-}
-
-// helper so we don't have to have underscores and stuff in js to refer to the right method
-+ (NSString *)webScriptNameForSelector:(SEL)aSelector;
-{
- id result = nil;
-
- if (aSelector == @selector(playSound:))
- result = @"playSound";
-
-
- return result;
+ DebugNSLog(@"window width = %f, window height = %f", size.width, size.height);
+ [self.webView setFrame:NSMakeRect(0, 0, size.width, size.height - [[Utils sharedInstance] titleBarHeight:window])];
}
-// right now exclude all properties (eg keys) until we re-factor
-+ (BOOL)isKeyExcludedFromWebScript:(const char *)name;
-{
- return YES;
-}
-
-
@end
Oops, something went wrong.

0 comments on commit 03ad21b

Please sign in to comment.