| 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. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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/layout/PaintInfo.h" | 34 #include "core/layout/PaintInfo.h" |
| 35 #include "platform/graphics/Gradient.h" | 35 #include "platform/graphics/Gradient.h" |
| 36 #include "platform/graphics/GraphicsContext.h" | 36 #include "platform/graphics/GraphicsContext.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; | 40 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; |
| 41 static MediaControlImageMap* gMediaControlImageMap = 0; | 41 static MediaControlImageMap* gMediaControlImageMap = 0; |
| 42 static double kCurrentTimeBufferedDelta = 1.0; |
| 42 | 43 |
| 43 static Image* platformResource(const char* name) | 44 static Image* platformResource(const char* name) |
| 44 { | 45 { |
| 45 if (!gMediaControlImageMap) | 46 if (!gMediaControlImageMap) |
| 46 gMediaControlImageMap = new MediaControlImageMap(); | 47 gMediaControlImageMap = new MediaControlImageMap(); |
| 47 if (Image* image = gMediaControlImageMap->get(name)) | 48 if (Image* image = gMediaControlImageMap->get(name)) |
| 48 return image; | 49 return image; |
| 49 if (Image* image = Image::loadPlatformResource(name).leakRef()) { | 50 if (Image* image = Image::loadPlatformResource(name).leakRef()) { |
| 50 gMediaControlImageMap->set(name, image); | 51 gMediaControlImageMap->set(name, image); |
| 51 return image; | 52 return image; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // distracting/'busy' to show all of them, show only the buffered range cont
aining the current play head. | 209 // distracting/'busy' to show all of them, show only the buffered range cont
aining the current play head. |
| 209 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered()
; | 210 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered()
; |
| 210 float duration = mediaElement->duration(); | 211 float duration = mediaElement->duration(); |
| 211 float currentTime = mediaElement->currentTime(); | 212 float currentTime = mediaElement->currentTime(); |
| 212 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(
currentTime)) | 213 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(
currentTime)) |
| 213 return true; | 214 return true; |
| 214 | 215 |
| 215 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { | 216 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { |
| 216 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); | 217 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); |
| 217 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); | 218 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); |
| 218 if (std::isnan(start) || std::isnan(end) || start > currentTime || end <
currentTime) | 219 // The delta is there to avoid corner cases when buffered |
| 220 // ranges is out of sync with current time because of |
| 221 // asynchronous media pipeline and current time caching in |
| 222 // HTMLMediaElement. |
| 223 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=281
25 |
| 224 // FIXME: Remove this workaround when WebMediaPlayer |
| 225 // has an asynchronous pause interface. |
| 226 if (std::isnan(start) || std::isnan(end) |
| 227 || start > currentTime + kCurrentTimeBufferedDelta || end < currentT
ime) |
| 219 continue; | 228 continue; |
| 220 int startPosition = int(start * rect.width() / duration); | 229 int startPosition = int(start * rect.width() / duration); |
| 221 int currentPosition = int(currentTime * rect.width() / duration); | 230 int currentPosition = int(currentTime * rect.width() / duration); |
| 222 int endPosition = int(end * rect.width() / duration); | 231 int endPosition = int(end * rect.width() / duration); |
| 223 | 232 |
| 224 // Add half the thumb width proportionally adjusted to the current paint
ing position. | 233 // Add half the thumb width proportionally adjusted to the current paint
ing position. |
| 225 int thumbCenter = mediaSliderThumbWidth / 2; | 234 int thumbCenter = mediaSliderThumbWidth / 2; |
| 226 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()
); | 235 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()
); |
| 227 currentPosition += addWidth; | 236 currentPosition += addWidth; |
| 228 | 237 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 { | 475 { |
| 467 return formatChromiumMediaControlsTime(time, time); | 476 return formatChromiumMediaControlsTime(time, time); |
| 468 } | 477 } |
| 469 | 478 |
| 470 String LayoutMediaControls::formatMediaControlsCurrentTime(float currentTime, fl
oat duration) | 479 String LayoutMediaControls::formatMediaControlsCurrentTime(float currentTime, fl
oat duration) |
| 471 { | 480 { |
| 472 return formatChromiumMediaControlsTime(currentTime, duration); | 481 return formatChromiumMediaControlsTime(currentTime, duration); |
| 473 } | 482 } |
| 474 | 483 |
| 475 } // namespace blink | 484 } // namespace blink |
| OLD | NEW |