| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. | 2 * Copyright (C) 2009 Apple Inc. |
| 3 * Copyright (C) 2009 Google Inc. | 3 * Copyright (C) 2009 Google Inc. |
| 4 * All rights reserved. | 4 * All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 15 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 #include "core/layout/LayoutMediaControls.h" | 29 #include "core/paint/MediaControlsPainter.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 31 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
| 32 #include "core/html/HTMLMediaElement.h" | 32 #include "core/html/HTMLMediaElement.h" |
| 33 #include "core/html/TimeRanges.h" | 33 #include "core/html/TimeRanges.h" |
| 34 #include "core/paint/PaintInfo.h" | 34 #include "core/paint/PaintInfo.h" |
| 35 #include "core/style/ComputedStyle.h" |
| 35 #include "platform/graphics/Gradient.h" | 36 #include "platform/graphics/Gradient.h" |
| 36 #include "platform/graphics/GraphicsContext.h" | 37 #include "platform/graphics/GraphicsContext.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 41 static double kCurrentTimeBufferedDelta = 1.0; |
| 42 |
| 40 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; | 43 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; |
| 41 static MediaControlImageMap* gMediaControlImageMap = 0; | 44 static MediaControlImageMap* gMediaControlImageMap = 0; |
| 42 static double kCurrentTimeBufferedDelta = 1.0; | |
| 43 | 45 |
| 44 static Image* platformResource(const char* name) | 46 static Image* platformResource(const char* name) |
| 45 { | 47 { |
| 46 if (!gMediaControlImageMap) | 48 if (!gMediaControlImageMap) |
| 47 gMediaControlImageMap = new MediaControlImageMap(); | 49 gMediaControlImageMap = new MediaControlImageMap(); |
| 48 if (Image* image = gMediaControlImageMap->get(name)) | 50 if (Image* image = gMediaControlImageMap->get(name)) |
| 49 return image; | 51 return image; |
| 50 if (Image* image = Image::loadPlatformResource(name).leakRef()) { | 52 if (Image* image = Image::loadPlatformResource(name).leakRef()) { |
| 51 gMediaControlImageMap->set(name, image); | 53 gMediaControlImageMap->set(name, image); |
| 52 return image; | 54 return image; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 case MediaCastOffButton: | 370 case MediaCastOffButton: |
| 369 return paintMediaButton(paintInfo.context, rect, mediaCastOff); | 371 return paintMediaButton(paintInfo.context, rect, mediaCastOff); |
| 370 case MediaOverlayCastOffButton: | 372 case MediaOverlayCastOffButton: |
| 371 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); | 373 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); |
| 372 default: | 374 default: |
| 373 ASSERT_NOT_REACHED(); | 375 ASSERT_NOT_REACHED(); |
| 374 return false; | 376 return false; |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 | 379 |
| 378 bool LayoutMediaControls::paintMediaControlsPart(MediaControlElementType part, L
ayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect) | 380 bool MediaControlsPainter::paintMediaControlsPart(MediaControlElementType part,
LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect) |
| 379 { | 381 { |
| 380 switch (part) { | 382 switch (part) { |
| 381 case MediaMuteButton: | 383 case MediaMuteButton: |
| 382 case MediaUnMuteButton: | 384 case MediaUnMuteButton: |
| 383 return paintMediaMuteButton(object, paintInfo, rect); | 385 return paintMediaMuteButton(object, paintInfo, rect); |
| 384 case MediaPauseButton: | 386 case MediaPauseButton: |
| 385 case MediaPlayButton: | 387 case MediaPlayButton: |
| 386 return paintMediaPlayButton(object, paintInfo, rect); | 388 return paintMediaPlayButton(object, paintInfo, rect); |
| 387 case MediaShowClosedCaptionsButton: | 389 case MediaShowClosedCaptionsButton: |
| 388 return paintMediaToggleClosedCaptionsButton(object, paintInfo, rect); | 390 return paintMediaToggleClosedCaptionsButton(object, paintInfo, rect); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 414 case MediaFullScreenVolumeSliderThumb: | 416 case MediaFullScreenVolumeSliderThumb: |
| 415 ASSERT_NOT_REACHED(); | 417 ASSERT_NOT_REACHED(); |
| 416 break; | 418 break; |
| 417 } | 419 } |
| 418 return false; | 420 return false; |
| 419 } | 421 } |
| 420 | 422 |
| 421 const int mediaSliderThumbHeight = 24; | 423 const int mediaSliderThumbHeight = 24; |
| 422 const int mediaVolumeSliderThumbHeight = 24; | 424 const int mediaVolumeSliderThumbHeight = 24; |
| 423 | 425 |
| 424 void LayoutMediaControls::adjustMediaSliderThumbSize(ComputedStyle& style) | 426 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) |
| 425 { | 427 { |
| 426 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); | 428 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); |
| 427 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl
iderThumb"); | 429 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl
iderThumb"); |
| 428 int width = 0; | 430 int width = 0; |
| 429 int height = 0; | 431 int height = 0; |
| 430 | 432 |
| 431 Image* thumbImage = 0; | 433 Image* thumbImage = 0; |
| 432 if (style.appearance() == MediaSliderThumbPart) { | 434 if (style.appearance() == MediaSliderThumbPart) { |
| 433 thumbImage = mediaSliderThumb; | 435 thumbImage = mediaSliderThumb; |
| 434 width = mediaSliderThumbWidth; | 436 width = mediaSliderThumbWidth; |
| 435 height = mediaSliderThumbHeight; | 437 height = mediaSliderThumbHeight; |
| 436 } else if (style.appearance() == MediaVolumeSliderThumbPart) { | 438 } else if (style.appearance() == MediaVolumeSliderThumbPart) { |
| 437 thumbImage = mediaVolumeSliderThumb; | 439 thumbImage = mediaVolumeSliderThumb; |
| 438 width = mediaVolumeSliderThumbWidth; | 440 width = mediaVolumeSliderThumbWidth; |
| 439 height = mediaVolumeSliderThumbHeight; | 441 height = mediaVolumeSliderThumbHeight; |
| 440 } | 442 } |
| 441 | 443 |
| 442 float zoomLevel = style.effectiveZoom(); | 444 float zoomLevel = style.effectiveZoom(); |
| 443 if (thumbImage) { | 445 if (thumbImage) { |
| 444 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); | 446 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); |
| 445 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); | 447 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); |
| 446 } | 448 } |
| 447 } | 449 } |
| 448 | 450 |
| 449 static String formatChromiumMediaControlsTime(float time, float duration) | |
| 450 { | |
| 451 if (!std::isfinite(time)) | |
| 452 time = 0; | |
| 453 if (!std::isfinite(duration)) | |
| 454 duration = 0; | |
| 455 int seconds = static_cast<int>(fabsf(time)); | |
| 456 int hours = seconds / (60 * 60); | |
| 457 int minutes = (seconds / 60) % 60; | |
| 458 seconds %= 60; | |
| 459 | |
| 460 // duration defines the format of how the time is rendered | |
| 461 int durationSecs = static_cast<int>(fabsf(duration)); | |
| 462 int durationHours = durationSecs / (60 * 60); | |
| 463 int durationMins = (durationSecs / 60) % 60; | |
| 464 | |
| 465 if (durationHours || hours) | |
| 466 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours,
minutes, seconds); | |
| 467 if (durationMins > 9) | |
| 468 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, sec
onds); | |
| 469 | |
| 470 return String::format("%s%01d:%02d", (time < 0 ? "-" : ""), minutes, seconds
); | |
| 471 } | |
| 472 | |
| 473 String LayoutMediaControls::formatMediaControlsTime(float time) | |
| 474 { | |
| 475 return formatChromiumMediaControlsTime(time, time); | |
| 476 } | |
| 477 | |
| 478 String LayoutMediaControls::formatMediaControlsCurrentTime(float currentTime, fl
oat duration) | |
| 479 { | |
| 480 return formatChromiumMediaControlsTime(currentTime, duration); | |
| 481 } | |
| 482 | |
| 483 } // namespace blink | 451 } // namespace blink |
| OLD | NEW |