Commit 12da8133 authored by mitz@apple.com's avatar mitz@apple.com

Made the remaining time display show negative zero at the end of the

video.

Reviewed by Anders Carlsson.

Made other cleanup.

* WebView/WebVideoFullscreenHUDWindowController.h: Reverted the types of
_timeline and _volumeSlider to the more generic NSControl.
* WebView/WebVideoFullscreenHUDWindowController.mm:
(-[WebVideoFullscreenHUDWindowController scheduleTimeUpdate]): Cleaned
up style.
(-[WebVideoFullscreenHUDWindowController windowDidLoad]): Added an
assertion that the cast to NSButton * is legal. Removed casts.
(-[WebVideoFullscreenHUDWindowController updateTime]): Use
-setValue:forKey: instead of an NSSlider method.
(timeToString): Changed to support only non-negative values and
simplified.
(-[WebVideoFullscreenHUDWindowController remainingTimeText]): Always
prepend a “-” to the time.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50426 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5c31137e
2009-11-02 Dan Bernstein <mitz@apple.com>
Reviewed by Anders Carlsson.
Made the remaining time display show negative zero at the end of the
video.
Made other cleanup.
* WebView/WebVideoFullscreenHUDWindowController.h: Reverted the types of
_timeline and _volumeSlider to the more generic NSControl.
* WebView/WebVideoFullscreenHUDWindowController.mm:
(-[WebVideoFullscreenHUDWindowController scheduleTimeUpdate]): Cleaned
up style.
(-[WebVideoFullscreenHUDWindowController windowDidLoad]): Added an
assertion that the cast to NSButton * is legal. Removed casts.
(-[WebVideoFullscreenHUDWindowController updateTime]): Use
-setValue:forKey: instead of an NSSlider method.
(timeToString): Changed to support only non-negative values and
simplified.
(-[WebVideoFullscreenHUDWindowController remainingTimeText]): Always
prepend a “-” to the time.
2009-11-02 Dan Bernstein <mitz@apple.com> 2009-11-02 Dan Bernstein <mitz@apple.com>
Reviewed by John Sullivan. Reviewed by John Sullivan.
......
...@@ -41,10 +41,10 @@ namespace WebCore { ...@@ -41,10 +41,10 @@ namespace WebCore {
BOOL _mouseIsInHUD; BOOL _mouseIsInHUD;
BOOL _isEndingFullscreen; BOOL _isEndingFullscreen;
NSSlider *_timeline; NSControl *_timeline;
NSTextField *_remainingTimeText; NSTextField *_remainingTimeText;
NSTextField *_elapsedTimeText; NSTextField *_elapsedTimeText;
NSSlider *_volumeSlider; NSControl *_volumeSlider;
NSButton *_playButton; NSButton *_playButton;
} }
......
...@@ -10,17 +10,16 @@ ...@@ -10,17 +10,16 @@
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#if ENABLE(VIDEO) #if ENABLE(VIDEO)
...@@ -33,6 +32,7 @@ ...@@ -33,6 +32,7 @@
#import <JavaScriptCore/UnusedParam.h> #import <JavaScriptCore/UnusedParam.h>
#import <WebCore/HTMLMediaElement.h> #import <WebCore/HTMLMediaElement.h>
using namespace WebCore;
using namespace std; using namespace std;
static inline CGFloat webkit_CGFloor(CGFloat value) static inline CGFloat webkit_CGFloor(CGFloat value)
...@@ -72,11 +72,6 @@ static inline CGFloat webkit_CGFloor(CGFloat value) ...@@ -72,11 +72,6 @@ static inline CGFloat webkit_CGFloor(CGFloat value)
- (void)exitFullscreen:(id)sender; - (void)exitFullscreen:(id)sender;
@end @end
//
// HUD Window
//
@interface WebVideoFullscreenHUDWindow : NSWindow @interface WebVideoFullscreenHUDWindow : NSWindow
@end @end
...@@ -143,10 +138,6 @@ static inline CGFloat webkit_CGFloor(CGFloat value) ...@@ -143,10 +138,6 @@ static inline CGFloat webkit_CGFloor(CGFloat value)
@end @end
//
// HUD Window Controller
//
static const CGFloat windowHeight = 59; static const CGFloat windowHeight = 59;
static const CGFloat windowWidth = 438; static const CGFloat windowWidth = 438;
...@@ -243,7 +234,7 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3; ...@@ -243,7 +234,7 @@ static const NSTimeInterval HUDWindowFadeOutDelay = 3;
// Note that this creates a retain cycle between the window and us. // 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]; _timelineUpdateTimer = [[NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(updateTime) userInfo:nil repeats:YES] retain];
#if defined(BUILDING_ON_TIGER) #if defined(BUILDING_ON_TIGER)
[[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:(NSString*)kCFRunLoopCommonModes]; [[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:(NSString *)kCFRunLoopCommonModes];
#else #else
[[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:NSRunLoopCommonModes]; [[NSRunLoop currentRunLoop] addTimer:_timelineUpdateTimer forMode:NSRunLoopCommonModes];
#endif #endif
...@@ -373,7 +364,7 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -373,7 +364,7 @@ static NSTextField *createTimeTextField(NSRect frame)
#endif #endif
[window setContentView:background]; [window setContentView:background];
#if !defined(BUILDING_ON_TIGER) #if !defined(BUILDING_ON_TIGER)
_area = [[NSTrackingArea alloc] initWithRect:[background bounds] options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways owner:self userInfo:nil]; _area = [[NSTrackingArea alloc] initWithRect:[background bounds] options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways owner:self userInfo:nil];
[background addTrackingArea:_area]; [background addTrackingArea:_area];
#endif #endif
[background release]; [background release];
...@@ -382,6 +373,7 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -382,6 +373,7 @@ static NSTextField *createTimeTextField(NSRect frame)
CGFloat center = webkit_CGFloor((windowWidth - playButtonWidth) / 2); CGFloat center = webkit_CGFloor((windowWidth - playButtonWidth) / 2);
_playButton = (NSButton *)createControlWithMediaUIControlType(WKMediaUIControlPlayPauseButton, NSMakeRect(center, windowHeight - playButtonTopMargin - playButtonHeight, playButtonWidth, playButtonHeight)); _playButton = (NSButton *)createControlWithMediaUIControlType(WKMediaUIControlPlayPauseButton, NSMakeRect(center, windowHeight - playButtonTopMargin - playButtonHeight, playButtonWidth, playButtonHeight));
ASSERT([_playButton isKindOfClass:[NSButton class]]);
[_playButton setTarget:self]; [_playButton setTarget:self];
[_playButton setAction:@selector(togglePlaying:)]; [_playButton setAction:@selector(togglePlaying:)];
[contentView addSubview:_playButton]; [contentView addSubview:_playButton];
...@@ -402,7 +394,7 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -402,7 +394,7 @@ static NSTextField *createTimeTextField(NSRect frame)
[volumeDownButton release]; [volumeDownButton release];
left += volumeButtonWidth; left += volumeButtonWidth;
_volumeSlider = (NSSlider *)createControlWithMediaUIControlType(WKMediaUIControlSlider, NSMakeRect(left, volumeControlsBottom + webkit_CGFloor((volumeButtonHeight - volumeSliderHeight) / 2), volumeSliderWidth, volumeSliderHeight)); _volumeSlider = createControlWithMediaUIControlType(WKMediaUIControlSlider, NSMakeRect(left, volumeControlsBottom + webkit_CGFloor((volumeButtonHeight - volumeSliderHeight) / 2), volumeSliderWidth, volumeSliderHeight));
[_volumeSlider setValue:[NSNumber numberWithDouble:[self maxVolume]] forKey:@"maxValue"]; [_volumeSlider setValue:[NSNumber numberWithDouble:[self maxVolume]] forKey:@"maxValue"];
[_volumeSlider setTarget:self]; [_volumeSlider setTarget:self];
[_volumeSlider setAction:@selector(volumeChanged:)]; [_volumeSlider setAction:@selector(volumeChanged:)];
...@@ -416,7 +408,7 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -416,7 +408,7 @@ static NSTextField *createTimeTextField(NSRect frame)
[volumeUpButton release]; [volumeUpButton release];
#ifdef HAVE_MEDIA_CONTROL #ifdef HAVE_MEDIA_CONTROL
_timeline = (NSSlider *)WKCreateMediaUIControl(WKMediaUIControlTimeline); _timeline = WKCreateMediaUIControl(WKMediaUIControlTimeline);
#else #else
_timeline = [[NSSlider alloc] init]; _timeline = [[NSSlider alloc] init];
#endif #endif
...@@ -438,11 +430,6 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -438,11 +430,6 @@ static NSTextField *createTimeTextField(NSRect frame)
[window center]; [window center];
} }
/*
* Bindings
*
*/
- (void)updateVolume - (void)updateVolume
{ {
[_volumeSlider setDoubleValue:[self volume]]; [_volumeSlider setDoubleValue:[self volume]];
...@@ -453,7 +440,7 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -453,7 +440,7 @@ static NSTextField *createTimeTextField(NSRect frame)
[self updateVolume]; [self updateVolume];
[_timeline setFloatValue:[self currentTime]]; [_timeline setFloatValue:[self currentTime]];
[_timeline setMaxValue:[self duration]]; [_timeline setValue:[NSNumber numberWithDouble:[self duration]] forKey:@"maxValue"];
[_remainingTimeText setStringValue:[self remainingTimeText]]; [_remainingTimeText setStringValue:[self remainingTimeText]];
[_elapsedTimeText setStringValue:[self elapsedTimeText]]; [_elapsedTimeText setStringValue:[self elapsedTimeText]];
...@@ -577,30 +564,29 @@ static NSTextField *createTimeTextField(NSRect frame) ...@@ -577,30 +564,29 @@ static NSTextField *createTimeTextField(NSRect frame)
static NSString *timeToString(double time) static NSString *timeToString(double time)
{ {
ASSERT_ARG(time, time >= 0);
if (!isfinite(time)) if (!isfinite(time))
time = 0; time = 0;
int seconds = fabs(time); int seconds = fabs(time);
int hours = seconds / (60 * 60); int hours = seconds / (60 * 60);
int minutes = (seconds / 60) % 60; int minutes = (seconds / 60) % 60;
seconds %= 60; seconds %= 60;
if (hours) {
if (hours > 9)
return [NSString stringWithFormat:@"%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds];
else
return [NSString stringWithFormat:@"%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds];
}
else
return [NSString stringWithFormat:@"%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds];
if (hours)
return [NSString stringWithFormat:@"%d:%02d:%02d", hours, minutes, seconds];
return [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
} }
- (NSString *)remainingTimeText - (NSString *)remainingTimeText
{ {
if (![_delegate mediaElement]) HTMLMediaElement* mediaElement = [_delegate mediaElement];
if (!mediaElement)
return @""; return @"";
// Negative number return [@"-" stringByAppendingString:timeToString(mediaElement->duration() - mediaElement->currentTime())];
return timeToString([_delegate mediaElement]->currentTime() - [_delegate mediaElement]->duration());
} }
- (NSString *)elapsedTimeText - (NSString *)elapsedTimeText
...@@ -611,10 +597,7 @@ static NSString *timeToString(double time) ...@@ -611,10 +597,7 @@ static NSString *timeToString(double time)
return timeToString([_delegate mediaElement]->currentTime()); return timeToString([_delegate mediaElement]->currentTime());
} }
/* #pragma mark NSResponder
* Tracking area callbacks
*
*/
- (void)mouseEntered:(NSEvent *)theEvent - (void)mouseEntered:(NSEvent *)theEvent
{ {
...@@ -629,11 +612,6 @@ static NSString *timeToString(double time) ...@@ -629,11 +612,6 @@ static NSString *timeToString(double time)
[self fadeWindowIn]; [self fadeWindowIn];
} }
/*
* Other Interface callbacks
*
*/
- (void)rewind:(id)sender - (void)rewind:(id)sender
{ {
if (![_delegate mediaElement]) if (![_delegate mediaElement])
...@@ -655,10 +633,7 @@ static NSString *timeToString(double time) ...@@ -655,10 +633,7 @@ static NSString *timeToString(double time)
[_delegate requestExitFullscreen]; [_delegate requestExitFullscreen];
} }
/* #pragma mark NSWindowDelegate
* Window callback
*
*/
- (void)windowDidExpose:(NSNotification *)notification - (void)windowDidExpose:(NSNotification *)notification
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment