Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 #include "platform/graphics/Gradient.h" | 37 #include "platform/graphics/Gradient.h" |
| 38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 static double kCurrentTimeBufferedDelta = 1.0; | 42 static double kCurrentTimeBufferedDelta = 1.0; |
| 43 | 43 |
| 44 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; | 44 typedef WTF::HashMap<const char*, Image*> MediaControlImageMap; |
| 45 static MediaControlImageMap* gMediaControlImageMap = 0; | 45 static MediaControlImageMap* gMediaControlImageMap = 0; |
| 46 | 46 |
| 47 // Current UI slider thumbs sizes. | |
| 48 const int mediaSliderThumbWidth = 32; | |
| 49 const int mediaSliderThumbHeight = 24; | |
| 50 const int mediaVolumeSliderThumbHeight = 24; | |
| 51 const int mediaVolumeSliderThumbWidth = 24; | |
| 52 | |
| 53 // New UI slider thumb sizes, shard between time and volume. | |
| 54 const int mediaSliderThumbTouchWidthNew = 36; // Touch zone size. | |
| 55 const int mediaSliderThumbTouchHeightNew = 48; | |
| 56 const int mediaSliderThumbPaintWidthNew = 12; // Painted area. | |
| 57 const int mediaSliderThumbPaintHeightNew = 12; | |
| 58 | |
| 59 // New UI overlay play button size. | |
| 60 const int mediaOverlayPlayButtonWidthNew = 48; | |
| 61 const int mediaOverlayPlayButtonHeightNew = 48; | |
| 62 | |
| 63 // New UI slider bar height. | |
| 64 const int mediaSliderBarHeight = 2; | |
| 65 | |
| 66 // Alpha for disabled elements. | |
| 67 const float kDisabledAlpha = 0.4; | |
| 68 | |
| 47 static Image* platformResource(const char* name) | 69 static Image* platformResource(const char* name) |
| 48 { | 70 { |
| 49 if (!gMediaControlImageMap) | 71 if (!gMediaControlImageMap) |
| 50 gMediaControlImageMap = new MediaControlImageMap(); | 72 gMediaControlImageMap = new MediaControlImageMap(); |
| 51 if (Image* image = gMediaControlImageMap->get(name)) | 73 if (Image* image = gMediaControlImageMap->get(name)) |
| 52 return image; | 74 return image; |
| 53 if (Image* image = Image::loadPlatformResource(name).leakRef()) { | 75 if (Image* image = Image::loadPlatformResource(name).leakRef()) { |
| 54 gMediaControlImageMap->set(name, image); | 76 gMediaControlImageMap->set(name, image); |
| 55 return image; | 77 return image; |
| 56 } | 78 } |
| 57 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 58 return 0; | 80 return 0; |
| 59 } | 81 } |
| 60 | 82 |
| 83 static Image* platformResource(const char* currentName, const char* newName) | |
| 84 { | |
| 85 // Return currentName or newName based on current or new playback. | |
| 86 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName); | |
| 87 } | |
| 88 | |
| 61 static bool hasSource(const HTMLMediaElement* mediaElement) | 89 static bool hasSource(const HTMLMediaElement* mediaElement) |
| 62 { | 90 { |
| 63 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY | 91 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY |
| 64 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; | 92 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; |
| 65 } | 93 } |
| 66 | 94 |
| 67 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image) | 95 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image, bool transparentIfNewUi = false) |
| 68 { | 96 { |
| 97 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
| 98 transparentIfNewUi = false; // New UI only. | |
| 99 | |
| 100 if (transparentIfNewUi) { | |
| 101 context->beginLayer(kDisabledAlpha); | |
| 102 } | |
| 69 context->drawImage(image, rect); | 103 context->drawImage(image, rect); |
| 104 if (transparentIfNewUi) { | |
| 105 context->endLayer(); | |
| 106 } | |
| 107 | |
| 70 return true; | 108 return true; |
| 71 } | 109 } |
| 72 | 110 |
| 73 bool MediaControlsPainter::paintMediaMuteButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) | 111 bool MediaControlsPainter::paintMediaMuteButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) |
| 74 { | 112 { |
| 75 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 113 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 76 if (!mediaElement) | 114 if (!mediaElement) |
| 77 return false; | 115 return false; |
| 78 | 116 |
| 79 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3"); | 117 // The new UI uses "muted" and "not muted" only. |
|
philipj_slow
2015/07/08 10:31:52
Is this by design? I was expecting the "waves" to
liberato (no reviews please)
2015/07/09 12:10:56
i'll verify that this wasn't overlooked, but i bel
liberato (no reviews please)
2015/07/14 22:10:36
it is intentional.
| |
| 80 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2"); | 118 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", |
| 81 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1"); | 119 "mediaplayerSoundLevel3New"); |
| 82 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0"); | 120 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", |
| 83 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled"); | 121 "mediaplayerSoundLevel3New"); |
| 122 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1", | |
| 123 "mediaplayerSoundLevel3New"); | |
| 124 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0", | |
| 125 "mediaplayerSoundLevel0New"); | |
| 126 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled", | |
| 127 "mediaplayerSoundLevel0New"); | |
| 84 | 128 |
| 85 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) | 129 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) |
| 86 return paintMediaButton(paintInfo.context, rect, soundDisabled); | 130 return paintMediaButton(paintInfo.context, rect, soundDisabled, true); |
| 87 | 131 |
| 88 if (mediaElement->muted() || mediaElement->volume() <= 0) | 132 if (mediaElement->muted() || mediaElement->volume() <= 0) |
| 89 return paintMediaButton(paintInfo.context, rect, soundLevel0); | 133 return paintMediaButton(paintInfo.context, rect, soundLevel0); |
| 90 | 134 |
| 91 if (mediaElement->volume() <= 0.33) | 135 if (mediaElement->volume() <= 0.33) |
| 92 return paintMediaButton(paintInfo.context, rect, soundLevel1); | 136 return paintMediaButton(paintInfo.context, rect, soundLevel1); |
| 93 | 137 |
| 94 if (mediaElement->volume() <= 0.66) | 138 if (mediaElement->volume() <= 0.66) |
| 95 return paintMediaButton(paintInfo.context, rect, soundLevel2); | 139 return paintMediaButton(paintInfo.context, rect, soundLevel2); |
| 96 | 140 |
| 97 return paintMediaButton(paintInfo.context, rect, soundLevel3); | 141 return paintMediaButton(paintInfo.context, rect, soundLevel3); |
| 98 } | 142 } |
| 99 | 143 |
| 100 bool MediaControlsPainter::paintMediaPlayButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) | 144 bool MediaControlsPainter::paintMediaPlayButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) |
| 101 { | 145 { |
| 102 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 146 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 103 if (!mediaElement) | 147 if (!mediaElement) |
| 104 return false; | 148 return false; |
| 105 | 149 |
| 106 static Image* mediaPlay = platformResource("mediaplayerPlay"); | 150 static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPl ayNew"); |
| 107 static Image* mediaPause = platformResource("mediaplayerPause"); | 151 static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayer PauseNew"); |
| 108 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" ); | 152 // For this case, the new UI draws the normal icon, but the entire panel |
| 153 // grays out. | |
| 154 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" , "mediaplayerPlayNew"); | |
| 109 | 155 |
| 110 if (!hasSource(mediaElement)) | 156 if (!hasSource(mediaElement)) |
| 111 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled); | 157 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, true ); |
| 112 | 158 |
| 113 Image * image = !object->node()->isMediaControlElement() || mediaControlElem entType(object->node()) == MediaPlayButton ? mediaPlay : mediaPause; | 159 Image * image = !object->node()->isMediaControlElement() || mediaControlElem entType(object->node()) == MediaPlayButton ? mediaPlay : mediaPause; |
| 114 return paintMediaButton(paintInfo.context, rect, image); | 160 return paintMediaButton(paintInfo.context, rect, image); |
| 115 } | 161 } |
| 116 | 162 |
| 117 bool MediaControlsPainter::paintMediaOverlayPlayButton(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) | 163 bool MediaControlsPainter::paintMediaOverlayPlayButton(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) |
| 118 { | 164 { |
| 119 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 165 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 120 if (!mediaElement) | 166 if (!mediaElement) |
| 121 return false; | 167 return false; |
| 122 | 168 |
| 123 if (!hasSource(mediaElement) || !mediaElement->togglePlayStateWillPlay()) | 169 if (!hasSource(mediaElement) || !mediaElement->togglePlayStateWillPlay()) |
| 124 return false; | 170 return false; |
| 125 | 171 |
| 126 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay"); | 172 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay", |
| 127 return paintMediaButton(paintInfo.context, rect, mediaOverlayPlay); | 173 "mediaplayerOverlayPlayNew"); |
| 174 | |
| 175 IntRect buttonRect(rect); | |
| 176 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
| 177 // Overlay play button is full-screen, so center. | |
| 178 buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2); | |
| 179 buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2) ; | |
| 180 buttonRect.setWidth(mediaOverlayPlayButtonWidthNew); | |
| 181 buttonRect.setHeight(mediaOverlayPlayButtonHeightNew); | |
| 182 } | |
| 183 | |
| 184 return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay); | |
| 128 } | 185 } |
| 129 | 186 |
| 130 static Image* getMediaSliderThumb() | 187 static Image* getMediaSliderThumb() |
| 131 { | 188 { |
| 132 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); | 189 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb", |
| 190 "mediaplayerSliderThumbNew"); | |
| 133 return mediaSliderThumb; | 191 return mediaSliderThumb; |
| 134 } | 192 } |
| 135 | 193 |
| 136 static void paintRoundedSliderBackground(const IntRect& rect, const ComputedStyl e&, GraphicsContext* context) | 194 static IntRect adjustSliderRectIfNewUi(const IntRect& rect, const ComputedStyle& style) |
| 137 { | 195 { |
| 138 int borderRadius = rect.height() / 2; | 196 // If we're using the new UI, create a short, vertically centered rect. |
| 197 // We don't specify this in CSS because it makes touch targets harder. | |
| 198 // Instead, we just adjust the drawing rect. If we're not using the | |
| 199 // new UI, then do nothing. | |
| 200 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
| 201 return rect; | |
| 202 | |
| 203 IntRect adjustedRect(rect); | |
| 204 float zoomedHeight = mediaSliderBarHeight * style.effectiveZoom(); | |
| 205 adjustedRect.setY(rect.center().y() - zoomedHeight / 2); | |
| 206 adjustedRect.setHeight(zoomedHeight); | |
| 207 | |
| 208 return adjustedRect; | |
| 209 } | |
| 210 | |
| 211 static void paintRoundedSliderBackground(const IntRect& rect, const ComputedStyl e& style, GraphicsContext* context, Color sliderBackgroundColor ) | |
| 212 { | |
| 213 IntRect adjustedRect(adjustSliderRectIfNewUi(rect, style)); | |
| 214 int borderRadius = adjustedRect.height() / 2; | |
| 139 IntSize radii(borderRadius, borderRadius); | 215 IntSize radii(borderRadius, borderRadius); |
| 140 Color sliderBackgroundColor = Color(11, 11, 11); | 216 |
| 141 context->fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), sliderBackgroundColor); | 217 context->fillRoundedRect(FloatRoundedRect(adjustedRect, radii, radii, radii, radii), sliderBackgroundColor); |
| 142 } | 218 } |
| 143 | 219 |
| 144 static void paintSliderRangeHighlight(const IntRect& rect, const ComputedStyle& style, GraphicsContext* context, int startPosition, int endPosition, Color start Color, Color endColor) | 220 static void paintSliderRangeHighlight(const IntRect& rect, const ComputedStyle& style, GraphicsContext* context, int startPosition, int endPosition, Color start Color, Color endColor) |
| 145 { | 221 { |
| 222 IntRect adjustedRect(adjustSliderRectIfNewUi(rect, style)); | |
| 223 | |
| 146 // Calculate border radius; need to avoid being smaller than half the slider height | 224 // Calculate border radius; need to avoid being smaller than half the slider height |
| 147 // because of https://bugs.webkit.org/show_bug.cgi?id=30143. | 225 // because of https://bugs.webkit.org/show_bug.cgi?id=30143. |
| 148 int borderRadius = rect.height() / 2; | 226 int borderRadius = adjustedRect.height() / 2; |
| 149 IntSize radii(borderRadius, borderRadius); | 227 IntSize radii(borderRadius, borderRadius); |
| 150 | 228 |
| 151 // Calculate highlight rectangle and edge dimensions. | 229 // Calculate highlight rectangle and edge dimensions. |
| 152 int startOffset = startPosition; | 230 int startOffset = startPosition; |
| 153 int endOffset = rect.width() - endPosition; | 231 int endOffset = adjustedRect.width() - endPosition; |
| 154 int rangeWidth = endPosition - startPosition; | 232 int rangeWidth = endPosition - startPosition; |
| 155 | 233 |
| 156 if (rangeWidth <= 0) | 234 if (rangeWidth <= 0) |
| 157 return; | 235 return; |
| 158 | 236 |
| 159 // Make sure the range width is bigger than border radius at the edges to re tain rounded corners. | 237 // Make sure the range width is bigger than border radius at the edges to re tain rounded corners. |
| 160 if (startOffset < borderRadius && rangeWidth < borderRadius) | 238 if (startOffset < borderRadius && rangeWidth < borderRadius) |
| 161 rangeWidth = borderRadius; | 239 rangeWidth = borderRadius; |
| 162 if (endOffset < borderRadius && rangeWidth < borderRadius) | 240 if (endOffset < borderRadius && rangeWidth < borderRadius) |
| 163 rangeWidth = borderRadius; | 241 rangeWidth = borderRadius; |
| 164 | 242 |
| 165 // Set rectangle to highlight range. | 243 // Set rectangle to highlight range. |
| 166 IntRect highlightRect = rect; | 244 IntRect highlightRect = adjustedRect; |
| 167 highlightRect.move(startOffset, 0); | 245 highlightRect.move(startOffset, 0); |
| 168 highlightRect.setWidth(rangeWidth); | 246 highlightRect.setWidth(rangeWidth); |
| 169 | 247 |
| 170 // Don't bother drawing an empty area. | 248 // Don't bother drawing an empty area. |
| 171 if (highlightRect.isEmpty()) | 249 if (highlightRect.isEmpty()) |
| 172 return; | 250 return; |
| 173 | 251 |
| 174 // Calculate white-grey gradient. | 252 // Calculate white-grey gradient. |
| 175 IntPoint sliderTopLeft = highlightRect.location(); | 253 IntPoint sliderTopLeft = highlightRect.location(); |
| 176 IntPoint sliderBottomLeft = sliderTopLeft; | 254 IntPoint sliderBottomLeft = sliderTopLeft; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 188 else if (startOffset < borderRadius) | 266 else if (startOffset < borderRadius) |
| 189 context->fillRoundedRect(FloatRoundedRect(highlightRect, radii, IntSize( 0, 0), radii, IntSize(0, 0)), startColor); | 267 context->fillRoundedRect(FloatRoundedRect(highlightRect, radii, IntSize( 0, 0), radii, IntSize(0, 0)), startColor); |
| 190 else if (endOffset < borderRadius) | 268 else if (endOffset < borderRadius) |
| 191 context->fillRoundedRect(FloatRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii), startColor); | 269 context->fillRoundedRect(FloatRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii), startColor); |
| 192 else | 270 else |
| 193 context->fillRect(highlightRect); | 271 context->fillRect(highlightRect); |
| 194 | 272 |
| 195 context->restore(); | 273 context->restore(); |
| 196 } | 274 } |
| 197 | 275 |
| 198 const int mediaSliderThumbWidth = 32; | |
| 199 | 276 |
| 200 bool MediaControlsPainter::paintMediaSlider(LayoutObject* object, const PaintInf o& paintInfo, const IntRect& rect) | 277 bool MediaControlsPainter::paintMediaSlider(LayoutObject* object, const PaintInf o& paintInfo, const IntRect& rect) |
| 201 { | 278 { |
| 202 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 279 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 203 if (!mediaElement) | 280 if (!mediaElement) |
| 204 return false; | 281 return false; |
| 205 | 282 |
| 206 const ComputedStyle& style = object->styleRef(); | 283 const ComputedStyle& style = object->styleRef(); |
| 207 GraphicsContext* context = paintInfo.context; | 284 GraphicsContext* context = paintInfo.context; |
| 208 | 285 |
| 209 paintRoundedSliderBackground(rect, style, context); | 286 // Should we paint the new UI grayed out? |
| 287 bool drawNewUiGrayed = !hasSource(mediaElement) && RuntimeEnabledFeatures::n ewMediaPlaybackUiEnabled(); | |
| 288 if (drawNewUiGrayed) { | |
| 289 context->beginLayer(kDisabledAlpha); | |
| 290 } | |
| 291 | |
| 292 // Paint the slider bar in the "no data buffered" state. | |
| 293 Color sliderBackgroundColor; | |
| 294 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
| 295 sliderBackgroundColor = Color(11, 11, 11); | |
| 296 else | |
| 297 sliderBackgroundColor = Color(0xda, 0xda, 0xda); | |
| 298 | |
| 299 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); | |
| 210 | 300 |
| 211 // Draw the buffered range. Since the element may have multiple buffered ran ges and it'd be | 301 // Draw the buffered range. Since the element may have multiple buffered ran ges and it'd be |
| 212 // distracting/'busy' to show all of them, show only the buffered range cont aining the current play head. | 302 // distracting/'busy' to show all of them, show only the buffered range cont aining the current play head. |
| 213 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered() ; | 303 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered() ; |
| 214 float duration = mediaElement->duration(); | 304 float duration = mediaElement->duration(); |
| 215 float currentTime = mediaElement->currentTime(); | 305 float currentTime = mediaElement->currentTime(); |
| 216 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime)) | 306 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime)) { |
| 307 if (drawNewUiGrayed) | |
| 308 context->endLayer(); | |
| 217 return true; | 309 return true; |
| 310 } | |
| 218 | 311 |
| 219 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { | 312 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { |
| 220 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); | 313 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); |
| 221 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); | 314 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); |
| 222 // The delta is there to avoid corner cases when buffered | 315 // The delta is there to avoid corner cases when buffered |
| 223 // ranges is out of sync with current time because of | 316 // ranges is out of sync with current time because of |
| 224 // asynchronous media pipeline and current time caching in | 317 // asynchronous media pipeline and current time caching in |
| 225 // HTMLMediaElement. | 318 // HTMLMediaElement. |
| 226 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=281 25 | 319 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=281 25 |
| 227 // FIXME: Remove this workaround when WebMediaPlayer | 320 // FIXME: Remove this workaround when WebMediaPlayer |
| 228 // has an asynchronous pause interface. | 321 // has an asynchronous pause interface. |
| 229 if (std::isnan(start) || std::isnan(end) | 322 if (std::isnan(start) || std::isnan(end) |
| 230 || start > currentTime + kCurrentTimeBufferedDelta || end < currentT ime) | 323 || start > currentTime + kCurrentTimeBufferedDelta || end < currentT ime) |
| 231 continue; | 324 continue; |
| 232 int startPosition = int(start * rect.width() / duration); | 325 int startPosition = int(start * rect.width() / duration); |
| 233 int currentPosition = int(currentTime * rect.width() / duration); | 326 int currentPosition = int(currentTime * rect.width() / duration); |
| 234 int endPosition = int(end * rect.width() / duration); | 327 int endPosition = int(end * rect.width() / duration); |
| 235 | 328 |
| 236 // Add half the thumb width proportionally adjusted to the current paint ing position. | 329 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
| 237 int thumbCenter = mediaSliderThumbWidth / 2; | 330 // Add half the thumb width proportionally adjusted to the current p ainting position. |
| 238 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width() ); | 331 int thumbCenter = mediaSliderThumbWidth / 2; |
| 239 currentPosition += addWidth; | 332 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.wid th()); |
| 333 currentPosition += addWidth; | |
| 334 } | |
| 240 | 335 |
| 241 // Draw white-ish highlight before current time. | 336 // Draw highlight before current time. |
| 242 Color startColor = Color(195, 195, 195); | 337 Color startColor; |
| 243 Color endColor = Color(217, 217, 217); | 338 Color endColor; |
| 339 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
| 340 startColor = Color(195, 195, 195); // white-ish. | |
| 341 endColor = Color(217, 217, 217); | |
| 342 } else { | |
| 343 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue. | |
| 344 } | |
| 345 | |
| 244 if (currentPosition > startPosition) | 346 if (currentPosition > startPosition) |
| 245 paintSliderRangeHighlight(rect, style, context, startPosition, curre ntPosition, startColor, endColor); | 347 paintSliderRangeHighlight(rect, style, context, startPosition, curre ntPosition, startColor, endColor); |
| 246 | 348 |
| 247 // Draw grey-ish highlight after current time. | 349 // Draw grey-ish highlight after current time. |
| 248 startColor = Color(60, 60, 60); | 350 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
| 249 endColor = Color(76, 76, 76); | 351 startColor = Color(60, 60, 60); |
| 352 endColor = Color(76, 76, 76); | |
| 353 } else { | |
| 354 startColor = endColor = Color(0x9f, 0x9f, 0x9f); // light grey. | |
| 355 } | |
| 250 | 356 |
| 251 if (endPosition > currentPosition) | 357 if (endPosition > currentPosition) |
| 252 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor); | 358 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor); |
| 253 | 359 |
| 360 if (drawNewUiGrayed) | |
| 361 context->endLayer(); | |
| 254 return true; | 362 return true; |
| 255 } | 363 } |
| 256 | 364 |
| 365 if (drawNewUiGrayed) | |
| 366 context->endLayer(); | |
| 367 | |
| 257 return true; | 368 return true; |
| 258 } | 369 } |
| 259 | 370 |
| 371 void MediaControlsPainter::adjustMediaSliderThumbPaintSize(const IntRect& rect, const ComputedStyle& style, IntRect& rectOut) | |
| 372 { | |
| 373 // Adjust the rectangle to be centered, the right size for the image. | |
| 374 // We do this because it's quite hard to get the thumb touch target | |
| 375 // to match. So, we provide the touch target size with | |
| 376 // adjustMediaSliderThumbSize(), and scale it back when we paint. | |
| 377 rectOut = rect; | |
| 378 | |
| 379 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
| 380 // ...except for the old UI. | |
| 381 return; | |
| 382 } | |
| 383 | |
| 384 float zoomLevel = style.effectiveZoom(); | |
| 385 int zoomedPaintWidth = mediaSliderThumbPaintWidthNew * zoomLevel; | |
| 386 int zoomedPaintHeight = mediaSliderThumbPaintHeightNew * zoomLevel; | |
| 387 | |
| 388 rectOut.setX(rect.center().x() - zoomedPaintWidth / 2); | |
| 389 rectOut.setY(rect.center().y() - zoomedPaintHeight / 2); | |
| 390 rectOut.setWidth(zoomedPaintWidth); | |
| 391 rectOut.setHeight(zoomedPaintHeight); | |
| 392 } | |
| 393 | |
| 260 bool MediaControlsPainter::paintMediaSliderThumb(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect) | 394 bool MediaControlsPainter::paintMediaSliderThumb(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect) |
| 261 { | 395 { |
| 262 if (!object->node()) | 396 if (!object->node()) |
| 263 return false; | 397 return false; |
| 264 | 398 |
| 265 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); | 399 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); |
| 266 if (!mediaElement) | 400 if (!mediaElement) |
| 267 return false; | 401 return false; |
| 268 | 402 |
| 269 if (!hasSource(mediaElement)) | 403 if (!hasSource(mediaElement)) |
| 270 return true; | 404 return true; |
| 271 | 405 |
| 272 Image* mediaSliderThumb = getMediaSliderThumb(); | 406 Image* mediaSliderThumb = getMediaSliderThumb(); |
| 273 return paintMediaButton(paintInfo.context, rect, mediaSliderThumb); | 407 IntRect paintRect; |
| 408 const ComputedStyle& style = object->styleRef(); | |
| 409 adjustMediaSliderThumbPaintSize(rect, style, paintRect); | |
| 410 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb); | |
| 274 } | 411 } |
| 275 | 412 |
| 276 const int mediaVolumeSliderThumbWidth = 24; | |
| 277 | |
| 278 bool MediaControlsPainter::paintMediaVolumeSlider(LayoutObject* object, const Pa intInfo& paintInfo, const IntRect& rect) | 413 bool MediaControlsPainter::paintMediaVolumeSlider(LayoutObject* object, const Pa intInfo& paintInfo, const IntRect& rect) |
| 279 { | 414 { |
| 280 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 415 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 281 if (!mediaElement) | 416 if (!mediaElement) |
| 282 return false; | 417 return false; |
| 283 | 418 |
| 284 GraphicsContext* context = paintInfo.context; | 419 GraphicsContext* context = paintInfo.context; |
| 285 const ComputedStyle& style = object->styleRef(); | 420 const ComputedStyle& style = object->styleRef(); |
| 286 | 421 |
| 287 paintRoundedSliderBackground(rect, style, context); | 422 // Paint the slider bar. |
| 423 Color sliderBackgroundColor; | |
| 424 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
| 425 sliderBackgroundColor = Color(11, 11, 11); | |
| 426 else | |
| 427 sliderBackgroundColor = Color(0x9f, 0x9f, 0x9f); | |
| 428 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); | |
| 288 | 429 |
| 289 // Calculate volume position for white background rectangle. | 430 // Calculate volume position for white background rectangle. |
| 290 float volume = mediaElement->volume(); | 431 float volume = mediaElement->volume(); |
| 291 if (std::isnan(volume) || volume < 0) | 432 if (std::isnan(volume) || volume < 0) |
| 292 return true; | 433 return true; |
| 293 if (volume > 1) | 434 if (volume > 1) |
| 294 volume = 1; | 435 volume = 1; |
| 295 if (!hasSource(mediaElement) || !mediaElement->hasAudio() || mediaElement->m uted()) | 436 if (!hasSource(mediaElement) || !mediaElement->hasAudio() || mediaElement->m uted()) |
| 296 volume = 0; | 437 volume = 0; |
| 297 | 438 |
| 298 // Calculate the position relative to the center of the thumb. | 439 // Calculate the position relative to the center of the thumb. |
| 299 float fillWidth = 0; | 440 float fillWidth = 0; |
| 300 if (volume > 0) { | 441 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
| 301 float thumbCenter = mediaVolumeSliderThumbWidth / 2; | 442 if (volume > 0) { |
| 302 float zoomLevel = style.effectiveZoom(); | 443 float thumbCenter = mediaVolumeSliderThumbWidth / 2; |
| 303 float positionWidth = volume * (rect.width() - (zoomLevel * thumbCenter) ); | 444 float zoomLevel = style.effectiveZoom(); |
| 304 fillWidth = positionWidth + (zoomLevel * thumbCenter / 2); | 445 float positionWidth = volume * (rect.width() - (zoomLevel * thumbCen ter)); |
| 446 fillWidth = positionWidth + (zoomLevel * thumbCenter / 2); | |
| 447 } | |
| 448 } else { | |
| 449 fillWidth = volume * rect.width(); | |
| 305 } | 450 } |
| 306 | 451 |
| 307 Color startColor = Color(195, 195, 195); | 452 Color startColor = Color(195, 195, 195); |
| 308 Color endColor = Color(217, 217, 217); | 453 Color endColor = Color(217, 217, 217); |
| 454 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
| 455 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue. | |
| 456 } | |
| 309 | 457 |
| 310 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor); | 458 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor); |
| 311 | 459 |
| 312 return true; | 460 return true; |
| 313 } | 461 } |
| 314 | 462 |
| 315 bool MediaControlsPainter::paintMediaVolumeSliderThumb(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) | 463 bool MediaControlsPainter::paintMediaVolumeSliderThumb(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) |
| 316 { | 464 { |
| 317 if (!object->node()) | 465 if (!object->node()) |
| 318 return false; | 466 return false; |
| 319 | 467 |
| 320 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); | 468 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); |
| 321 if (!mediaElement) | 469 if (!mediaElement) |
| 322 return false; | 470 return false; |
| 323 | 471 |
| 324 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) | 472 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) |
| 325 return true; | 473 return true; |
| 326 | 474 |
| 327 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb"); | 475 static Image* mediaVolumeSliderThumb = platformResource( |
| 328 return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); | 476 "mediaplayerVolumeSliderThumb", |
| 477 "mediaplayerVolumeSliderThumbNew"); | |
| 478 | |
| 479 IntRect paintRect; | |
| 480 const ComputedStyle& style = object->styleRef(); | |
| 481 adjustMediaSliderThumbPaintSize(rect, style, paintRect); | |
| 482 return paintMediaButton(paintInfo.context, paintRect, mediaVolumeSliderThumb ); | |
| 329 } | 483 } |
| 330 | 484 |
| 331 bool MediaControlsPainter::paintMediaFullscreenButton(LayoutObject* object, cons t PaintInfo& paintInfo, const IntRect& rect) | 485 bool MediaControlsPainter::paintMediaFullscreenButton(LayoutObject* object, cons t PaintInfo& paintInfo, const IntRect& rect) |
| 332 { | 486 { |
| 333 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 487 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 334 if (!mediaElement) | 488 if (!mediaElement) |
| 335 return false; | 489 return false; |
| 336 | 490 |
| 337 static Image* mediaFullscreenButton = platformResource("mediaplayerFullscree n"); | 491 // with the new player UI, we have separate assets for enter / exit |
| 338 return paintMediaButton(paintInfo.context, rect, mediaFullscreenButton); | 492 // full screen mode. |
| 493 static Image* mediaEnterFullscreenButton = platformResource( | |
| 494 "mediaplayerFullscreen", | |
| 495 "mediaplayerEnterFullscreen"); | |
| 496 static Image* mediaExitFullscreenButton = platformResource( | |
| 497 "mediaplayerFullscreen", | |
| 498 "mediaplayerExitFullscreen"); | |
| 499 | |
| 500 bool isEnabled = hasSource(mediaElement); | |
| 501 | |
| 502 if (mediaControlElementType(object->node()) == MediaExitFullscreenButton) | |
| 503 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButt on, !isEnabled); | |
|
philipj_slow
2015/07/08 10:31:52
Is there a test that would fail if the enter fulls
liberato (no reviews please)
2015/07/09 12:10:56
good point. will add.
| |
| 504 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton, !isEnabled); | |
| 339 } | 505 } |
| 340 | 506 |
| 341 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(LayoutObject* ob ject, const PaintInfo& paintInfo, const IntRect& rect) | 507 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(LayoutObject* ob ject, const PaintInfo& paintInfo, const IntRect& rect) |
| 342 { | 508 { |
| 343 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 509 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 344 if (!mediaElement) | 510 if (!mediaElement) |
| 345 return false; | 511 return false; |
| 346 | 512 |
| 347 static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosed Caption"); | 513 static Image* mediaClosedCaptionButton = platformResource( |
| 348 static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplay erClosedCaptionDisabled"); | 514 "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); |
| 515 static Image* mediaClosedCaptionButtonDisabled = platformResource( | |
| 516 "mediaplayerClosedCaptionDisabled", | |
| 517 "mediaplayerClosedCaptionDisabledNew"); | |
| 518 | |
| 519 bool isEnabled = hasSource(mediaElement); | |
| 349 | 520 |
| 350 if (mediaElement->closedCaptionsVisible()) | 521 if (mediaElement->closedCaptionsVisible()) |
| 351 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto n); | 522 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto n, !isEnabled); |
| 352 | 523 |
| 353 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis abled); | 524 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis abled, !isEnabled); |
| 354 } | 525 } |
| 355 | 526 |
| 356 bool MediaControlsPainter::paintMediaCastButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) | 527 bool MediaControlsPainter::paintMediaCastButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) |
| 357 { | 528 { |
| 358 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 529 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 359 if (!mediaElement) | 530 if (!mediaElement) |
| 360 return false; | 531 return false; |
| 361 | 532 |
| 362 static Image* mediaCastOn = platformResource("mediaplayerCastOn"); | 533 static Image* mediaCastOn = platformResource("mediaplayerCastOn", "mediaplay erCastOnNew"); |
| 363 static Image* mediaCastOff = platformResource("mediaplayerCastOff"); | 534 static Image* mediaCastOff = platformResource("mediaplayerCastOff", "mediapl ayerCastOffNew"); |
| 364 // To ensure that the overlaid cast button is visible when overlaid on pale videos we use a | 535 // To ensure that the overlaid cast button is visible when overlaid on pale videos we use a |
| 365 // different version of it for the overlaid case with a semi-opaque backgrou nd. | 536 // different version of it for the overlaid case with a semi-opaque backgrou nd. |
| 366 static Image* mediaOverlayCastOff = platformResource("mediaplayerOverlayCast Off"); | 537 static Image* mediaOverlayCastOff = platformResource( |
| 538 "mediaplayerOverlayCastOff", | |
| 539 "mediaplayerOverlayCastOffNew"); | |
| 540 | |
| 541 bool isEnabled = hasSource(mediaElement); | |
| 367 | 542 |
| 368 switch (mediaControlElementType(object->node())) { | 543 switch (mediaControlElementType(object->node())) { |
| 369 case MediaCastOnButton: | 544 case MediaCastOnButton: |
| 545 return paintMediaButton(paintInfo.context, rect, mediaCastOn, !isEnabled ); | |
| 370 case MediaOverlayCastOnButton: | 546 case MediaOverlayCastOnButton: |
| 371 return paintMediaButton(paintInfo.context, rect, mediaCastOn); | 547 return paintMediaButton(paintInfo.context, rect, mediaCastOn); |
| 372 case MediaCastOffButton: | 548 case MediaCastOffButton: |
| 373 return paintMediaButton(paintInfo.context, rect, mediaCastOff); | 549 return paintMediaButton(paintInfo.context, rect, mediaCastOff, !isEnable d); |
| 374 case MediaOverlayCastOffButton: | 550 case MediaOverlayCastOffButton: |
| 375 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); | 551 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); |
| 376 default: | 552 default: |
| 377 ASSERT_NOT_REACHED(); | 553 ASSERT_NOT_REACHED(); |
| 378 return false; | 554 return false; |
| 379 } | 555 } |
| 380 } | 556 } |
| 381 | 557 |
| 382 const int mediaSliderThumbHeight = 24; | |
| 383 const int mediaVolumeSliderThumbHeight = 24; | |
| 384 | |
| 385 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) | 558 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) |
| 386 { | 559 { |
| 387 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); | 560 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb", |
| 388 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb"); | 561 "mediaplayerSliderThumbNew"); |
| 562 static Image* mediaVolumeSliderThumb = platformResource( | |
| 563 "mediaplayerVolumeSliderThumb", | |
| 564 "mediaplayerVolumeSliderThumbNew"); | |
| 389 int width = 0; | 565 int width = 0; |
| 390 int height = 0; | 566 int height = 0; |
| 391 | 567 |
| 392 Image* thumbImage = 0; | 568 Image* thumbImage = 0; |
| 393 if (style.appearance() == MediaSliderThumbPart) { | 569 |
| 570 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
| 571 // Volume and time sliders are the same. | |
| 572 thumbImage = mediaSliderThumb; | |
| 573 width = mediaSliderThumbTouchWidthNew; | |
| 574 height = mediaSliderThumbTouchHeightNew; | |
| 575 } else if (style.appearance() == MediaSliderThumbPart) { | |
| 394 thumbImage = mediaSliderThumb; | 576 thumbImage = mediaSliderThumb; |
| 395 width = mediaSliderThumbWidth; | 577 width = mediaSliderThumbWidth; |
| 396 height = mediaSliderThumbHeight; | 578 height = mediaSliderThumbHeight; |
| 397 } else if (style.appearance() == MediaVolumeSliderThumbPart) { | 579 } else if (style.appearance() == MediaVolumeSliderThumbPart) { |
| 398 thumbImage = mediaVolumeSliderThumb; | 580 thumbImage = mediaVolumeSliderThumb; |
| 399 width = mediaVolumeSliderThumbWidth; | 581 width = mediaVolumeSliderThumbWidth; |
| 400 height = mediaVolumeSliderThumbHeight; | 582 height = mediaVolumeSliderThumbHeight; |
| 401 } | 583 } |
| 402 | 584 |
| 403 float zoomLevel = style.effectiveZoom(); | 585 float zoomLevel = style.effectiveZoom(); |
| 404 if (thumbImage) { | 586 if (thumbImage) { |
| 405 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); | 587 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); |
| 406 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); | 588 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); |
| 407 } | 589 } |
| 408 } | 590 } |
| 409 | 591 |
| 410 } // namespace blink | 592 } // namespace blink |
| OLD | NEW |