2009-10-15 Eric Carlson <eric.carlson@apple.com>
[WebKit-https.git] / WebKit / mac / WebView / WebVideoFullscreenHUDWindowController.mm
index 824d29295a2b7463901e03d2dc76c06c33db3656..423629899743548cd77615648c0da16db21d5171 100644 (file)
 
 #import <QTKit/QTKit.h>
 #import "WebKitSystemInterface.h"
+#import "WebTypesInternal.h"
 #import <wtf/RetainPtr.h>
+#import <limits>
+
+using namespace std;
 
 #define HAVE_MEDIA_CONTROL (!defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD))
 
@@ -140,7 +144,9 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
 - (void)dealloc
 {
     ASSERT(!_timelineUpdateTimer);
+#if !defined(BUILDING_ON_TIGER)
     ASSERT(!_area);
+#endif
     [_timeline release];
     [_remainingTimeText release];
     [_elapsedTimeText release];
@@ -149,6 +155,7 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
     [super dealloc];
 }
 
+#if !defined(BUILDING_ON_TIGER)
 - (void)setArea:(NSTrackingArea *)area
 {
     if (area == _area)
@@ -156,6 +163,7 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
     [_area release];
     _area = [area retain];
 }
+#endif
 
 - (id<WebVideoFullscreenHUDWindowControllerDelegate>)delegate
 {
@@ -179,7 +187,11 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
 
     // Note that this creates a retain cycle between the window and us.
     _timelineUpdateTimer = [[NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(updateTime) userInfo:nil repeats:YES] retain];
+#if defined(BUILDING_ON_TIGER)
+    [[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:(NSString*)kCFRunLoopCommonModes];
+#else
     [[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:NSRunLoopCommonModes];
+#endif
 }
 
 - (void)unscheduleTimeUpdate
@@ -198,7 +210,11 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
         [window setAlphaValue:0];
 
     [window makeKeyAndOrderFront:self];
+#if defined(BUILDING_ON_TIGER)
+    [window setAlphaValue:1];
+#else
     [[window animator] setAlphaValue:1];
+#endif
     [self scheduleTimeUpdate];
 
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fadeWindowOut) object:nil];
@@ -209,7 +225,11 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
 - (void)fadeWindowOut
 {
     [NSCursor setHiddenUntilMouseMoves:YES];
+#if defined(BUILDING_ON_TIGER)
+    [[self window] setAlphaValue:0];
+#else
     [[[self window] animator] setAlphaValue:0];
+#endif
     [self performSelector:@selector(unscheduleTimeUpdate) withObject:nil afterDelay:1];
 }
 
@@ -218,8 +238,10 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fadeWindowOut) object:nil];
     [self unscheduleTimeUpdate];
     NSWindow *window = [self window];
+#if !defined(BUILDING_ON_TIGER)
     [[window contentView] removeTrackingArea:_area];
     [self setArea:nil];
+#endif
     [window close];
     [window setDelegate:nil];
     [self setWindow:nil];
@@ -280,8 +302,10 @@ static NSTextField *createTimeTextField(NSRect frame)
     NSView *background = [[NSView alloc] init];
 #endif
     [window setContentView:background];
+#if !defined(BUILDING_ON_TIGER)
     _area = [[NSTrackingArea alloc] initWithRect:[background bounds] options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways owner:self userInfo:nil];
     [background addTrackingArea:_area];
+#endif
     [background release];    
 
     NSView *contentView = [[self window] contentView];
@@ -303,6 +327,8 @@ static NSTextField *createTimeTextField(NSRect frame)
     CGFloat left = kMargin;
     NSControl *volumeDownButton = createControlWithMediaUIControlType(WKMediaUIControlVolumeDownButton, NSMakeRect(left, top - kButtonSize / 2 - kButtonMiniSize / 2, kButtonMiniSize, kButtonMiniSize));
     [contentView addSubview:volumeDownButton];
+    [volumeDownButton setTarget:self];
+    [volumeDownButton setAction:@selector(decrementVolume:)];
     [volumeDownButton release];
 
     static const int volumeSliderWidth = 50;
@@ -315,9 +341,11 @@ static NSTextField *createTimeTextField(NSRect frame)
     [contentView addSubview:_volumeSlider];
 
     left = kMargin + kButtonMiniSize + volumeSliderWidth + kButtonMiniSize / 2;
-    NSControl *button = createControlWithMediaUIControlType(WKMediaUIControlVolumeUpButton, NSMakeRect(left, top - kButtonSize / 2 - kButtonMiniSize / 2, kButtonMiniSize, kButtonMiniSize));
-    [contentView addSubview:button];
-    [button release];
+    NSControl *volumeUpButton = createControlWithMediaUIControlType(WKMediaUIControlVolumeUpButton, NSMakeRect(left, top - kButtonSize / 2 - kButtonMiniSize / 2, kButtonMiniSize, kButtonMiniSize));
+    [volumeUpButton setTarget:self];
+    [volumeUpButton setAction:@selector(incrementVolume:)];
+    [contentView addSubview:volumeUpButton];
+    [volumeUpButton release];
     
     static const int timeTextWidth = 50;
     static const int sliderHeight = 13;
@@ -405,6 +433,24 @@ static NSTextField *createTimeTextField(NSRect frame)
     [self setVolume:[_volumeSlider doubleValue]];
 }
 
+- (void)decrementVolume:(id)sender
+{
+    if (![_delegate mediaElement])
+        return;
+
+    double volume = [self volume] - 10;
+    [self setVolume:max(volume, 0.)];
+}
+
+- (void)incrementVolume:(id)sender
+{
+    if (![_delegate mediaElement])
+        return;
+
+    double volume = [self volume] + 10;
+    [self setVolume:min(volume, [self maxVolume])];
+}
+
 - (double)volume
 {
     return [_delegate mediaElement] ? [_delegate mediaElement]->volume() * [self maxVolume] : 0;
@@ -415,6 +461,8 @@ static NSTextField *createTimeTextField(NSRect frame)
     if (![_delegate mediaElement])
         return;
     WebCore::ExceptionCode e;
+    if ([_delegate mediaElement]->muted())
+        [_delegate mediaElement]->setMuted(false);
     [_delegate mediaElement]->setVolume(volume / [self maxVolume], e);
 }