| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Return currentName or newName based on current or new playback. | 81 // Return currentName or newName based on current or new playback. |
| 82 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()
? newName : currentName); | 82 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()
? newName : currentName); |
| 83 } | 83 } |
| 84 | 84 |
| 85 static bool hasSource(const HTMLMediaElement* mediaElement) | 85 static bool hasSource(const HTMLMediaElement* mediaElement) |
| 86 { | 86 { |
| 87 return mediaElement->getNetworkState() != HTMLMediaElement::NETWORK_EMPTY | 87 return mediaElement->getNetworkState() != HTMLMediaElement::NETWORK_EMPTY |
| 88 && mediaElement->getNetworkState() != HTMLMediaElement::NETWORK_NO_SOURC
E; | 88 && mediaElement->getNetworkState() != HTMLMediaElement::NETWORK_NO_SOURC
E; |
| 89 } | 89 } |
| 90 | 90 |
| 91 static bool paintMediaButton(GraphicsContext& context, const IntRect& rect, Imag
e* image, bool isEnabled = true) | 91 static FloatRect adjustRectForPadding(IntRect rect, const LayoutObject* object) |
| 92 { | 92 { |
| 93 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | 93 FloatRect adjustedRect(rect); |
| 94 isEnabled = true; // New UI only. | 94 |
| 95 if (!object) |
| 96 return adjustedRect; |
| 97 |
| 98 if (const ComputedStyle* style = object->style()) { |
| 99 const float paddingLeft = style->paddingLeft().getFloatValue(); |
| 100 const float paddingTop = style->paddingTop().getFloatValue(); |
| 101 const float paddingRight = style->paddingRight().getFloatValue(); |
| 102 const float paddingBottom = style->paddingBottom().getFloatValue(); |
| 103 adjustedRect = FloatRect(rect.x() + paddingLeft, |
| 104 rect.y() + paddingTop, |
| 105 rect.width() - paddingLeft - paddingRight, |
| 106 rect.height() - paddingTop - paddingBottom); |
| 107 } |
| 108 |
| 109 return adjustedRect; |
| 110 } |
| 111 |
| 112 static bool paintMediaButton(GraphicsContext& context, const IntRect& rect, Imag
e* image, const LayoutObject* object, bool isEnabled) |
| 113 { |
| 114 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
| 115 context.drawImage(image, rect); |
| 116 return true; |
| 117 } |
| 118 |
| 119 FloatRect drawRect = adjustRectForPadding(rect, object); |
| 95 | 120 |
| 96 if (!isEnabled) | 121 if (!isEnabled) |
| 97 context.beginLayer(kDisabledAlpha); | 122 context.beginLayer(kDisabledAlpha); |
| 98 | 123 |
| 99 context.drawImage(image, rect); | 124 context.drawImage(image, drawRect, FloatRect(FloatPoint(), FloatSize(image->
size()))); |
| 100 | 125 |
| 101 if (!isEnabled) | 126 if (!isEnabled) |
| 102 context.endLayer(); | 127 context.endLayer(); |
| 103 | 128 |
| 104 return true; | 129 return true; |
| 105 } | 130 } |
| 106 | 131 |
| 132 static bool paintMediaButton(GraphicsContext& context, const IntRect& rect, Imag
e* image, bool isEnabled = true) |
| 133 { |
| 134 return paintMediaButton(context, rect, image, 0, isEnabled); |
| 135 } |
| 136 |
| 107 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) | 137 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) |
| 108 { | 138 { |
| 109 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 139 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 110 if (!mediaElement) | 140 if (!mediaElement) |
| 111 return false; | 141 return false; |
| 112 | 142 |
| 113 // The new UI uses "muted" and "not muted" only. | 143 // The new UI uses "muted" and "not muted" only. |
| 114 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", | 144 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3", |
| 115 "mediaplayerSoundLevel3New"); | 145 "mediaplayerSoundLevel3New"); |
| 116 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", | 146 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2", |
| 117 "mediaplayerSoundLevel3New"); | 147 "mediaplayerSoundLevel3New"); |
| 118 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1", | 148 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1", |
| 119 "mediaplayerSoundLevel3New"); | 149 "mediaplayerSoundLevel3New"); |
| 120 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0", | 150 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0", |
| 121 "mediaplayerSoundLevel0New"); | 151 "mediaplayerSoundLevel0New"); |
| 122 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled", | 152 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled", |
| 123 "mediaplayerSoundLevel0New"); | 153 "mediaplayerSoundLevel0New"); |
| 124 | 154 |
| 125 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) | 155 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) |
| 126 return paintMediaButton(paintInfo.context, rect, soundDisabled, false); | 156 return paintMediaButton(paintInfo.context, rect, soundDisabled, &object,
false); |
| 127 | 157 |
| 128 if (mediaElement->muted() || mediaElement->volume() <= 0) | 158 if (mediaElement->muted() || mediaElement->volume() <= 0) |
| 129 return paintMediaButton(paintInfo.context, rect, soundLevel0); | 159 return paintMediaButton(paintInfo.context, rect, soundLevel0, &object, t
rue); |
| 130 | 160 |
| 131 if (mediaElement->volume() <= 0.33) | 161 if (mediaElement->volume() <= 0.33) |
| 132 return paintMediaButton(paintInfo.context, rect, soundLevel1); | 162 return paintMediaButton(paintInfo.context, rect, soundLevel1, &object, t
rue); |
| 133 | 163 |
| 134 if (mediaElement->volume() <= 0.66) | 164 if (mediaElement->volume() <= 0.66) |
| 135 return paintMediaButton(paintInfo.context, rect, soundLevel2); | 165 return paintMediaButton(paintInfo.context, rect, soundLevel2, &object, t
rue); |
| 136 | 166 |
| 137 return paintMediaButton(paintInfo.context, rect, soundLevel3); | 167 return paintMediaButton(paintInfo.context, rect, soundLevel3, &object, true)
; |
| 138 } | 168 } |
| 139 | 169 |
| 140 bool MediaControlsPainter::paintMediaPlayButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) | 170 bool MediaControlsPainter::paintMediaPlayButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) |
| 141 { | 171 { |
| 142 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 172 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 143 if (!mediaElement) | 173 if (!mediaElement) |
| 144 return false; | 174 return false; |
| 145 | 175 |
| 146 static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPl
ayNew"); | 176 static Image* mediaPlay = platformResource("mediaplayerPlay", "mediaplayerPl
ayNew"); |
| 147 static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayer
PauseNew"); | 177 static Image* mediaPause = platformResource("mediaplayerPause", "mediaplayer
PauseNew"); |
| 148 // For this case, the new UI draws the normal icon, but the entire panel | 178 // For this case, the new UI draws the normal icon, but the entire panel |
| 149 // grays out. | 179 // grays out. |
| 150 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled"
, "mediaplayerPlayNew"); | 180 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled"
, "mediaplayerPlayNew"); |
| 151 | 181 |
| 152 if (!hasSource(mediaElement)) | 182 if (!hasSource(mediaElement)) |
| 153 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, fals
e); | 183 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, &obj
ect, false); |
| 154 | 184 |
| 155 Image * image = !object.node()->isMediaControlElement() || mediaControlEleme
ntType(object.node()) == MediaPlayButton ? mediaPlay : mediaPause; | 185 Image * image = !object.node()->isMediaControlElement() || mediaControlEleme
ntType(object.node()) == MediaPlayButton ? mediaPlay : mediaPause; |
| 156 return paintMediaButton(paintInfo.context, rect, image); | 186 return paintMediaButton(paintInfo.context, rect, image, &object, true); |
| 157 } | 187 } |
| 158 | 188 |
| 159 bool MediaControlsPainter::paintMediaOverlayPlayButton(const LayoutObject& objec
t, const PaintInfo& paintInfo, const IntRect& rect) | 189 bool MediaControlsPainter::paintMediaOverlayPlayButton(const LayoutObject& objec
t, const PaintInfo& paintInfo, const IntRect& rect) |
| 160 { | 190 { |
| 161 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 191 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 162 if (!mediaElement) | 192 if (!mediaElement) |
| 163 return false; | 193 return false; |
| 164 | 194 |
| 165 if (!hasSource(mediaElement) || !mediaElement->paused()) | 195 if (!hasSource(mediaElement) || !mediaElement->paused()) |
| 166 return false; | 196 return false; |
| 167 | 197 |
| 168 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay", | 198 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay", |
| 169 "mediaplayerOverlayPlayNew"); | 199 "mediaplayerOverlayPlayNew"); |
| 170 | 200 |
| 171 IntRect buttonRect(rect); | 201 IntRect buttonRect(rect); |
| 172 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | 202 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
| 173 // Overlay play button covers the entire player, so center and draw a | 203 // Overlay play button covers the entire player, so center and draw a |
| 174 // smaller button. Center in the entire element. | 204 // smaller button. Center in the entire element. |
| 205 // TODO(liberato): object.enclosingBox()? |
| 175 const LayoutBox* box = mediaElement->layoutObject()->enclosingBox(); | 206 const LayoutBox* box = mediaElement->layoutObject()->enclosingBox(); |
| 176 if (!box) | 207 if (!box) |
| 177 return false; | 208 return false; |
| 178 int mediaHeight = box->pixelSnappedHeight(); | 209 int mediaHeight = box->pixelSnappedHeight(); |
| 179 buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2); | 210 buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2); |
| 180 buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2 | 211 buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2 |
| 181 + (mediaHeight - rect.height()) / 2); | 212 + (mediaHeight - rect.height()) / 2); |
| 182 buttonRect.setWidth(mediaOverlayPlayButtonWidthNew); | 213 buttonRect.setWidth(mediaOverlayPlayButtonWidthNew); |
| 183 buttonRect.setHeight(mediaOverlayPlayButtonHeightNew); | 214 buttonRect.setHeight(mediaOverlayPlayButtonHeightNew); |
| 184 } | 215 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 static Image* mediaEnterFullscreenButton = platformResource( | 510 static Image* mediaEnterFullscreenButton = platformResource( |
| 480 "mediaplayerFullscreen", | 511 "mediaplayerFullscreen", |
| 481 "mediaplayerEnterFullscreen"); | 512 "mediaplayerEnterFullscreen"); |
| 482 static Image* mediaExitFullscreenButton = platformResource( | 513 static Image* mediaExitFullscreenButton = platformResource( |
| 483 "mediaplayerFullscreen", | 514 "mediaplayerFullscreen", |
| 484 "mediaplayerExitFullscreen"); | 515 "mediaplayerExitFullscreen"); |
| 485 | 516 |
| 486 bool isEnabled = hasSource(mediaElement); | 517 bool isEnabled = hasSource(mediaElement); |
| 487 | 518 |
| 488 if (mediaControlElementType(object.node()) == MediaExitFullscreenButton) | 519 if (mediaControlElementType(object.node()) == MediaExitFullscreenButton) |
| 489 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButt
on, isEnabled); | 520 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButt
on, &object, isEnabled); |
| 490 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton,
isEnabled); | 521 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton,
&object, isEnabled); |
| 491 } | 522 } |
| 492 | 523 |
| 493 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(const LayoutObje
ct& object, const PaintInfo& paintInfo, const IntRect& rect) | 524 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(const LayoutObje
ct& object, const PaintInfo& paintInfo, const IntRect& rect) |
| 494 { | 525 { |
| 495 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 526 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 496 if (!mediaElement) | 527 if (!mediaElement) |
| 497 return false; | 528 return false; |
| 498 | 529 |
| 499 static Image* mediaClosedCaptionButton = platformResource( | 530 static Image* mediaClosedCaptionButton = platformResource( |
| 500 "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); | 531 "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); |
| 501 static Image* mediaClosedCaptionButtonDisabled = platformResource( | 532 static Image* mediaClosedCaptionButtonDisabled = platformResource( |
| 502 "mediaplayerClosedCaptionDisabled", | 533 "mediaplayerClosedCaptionDisabled", |
| 503 "mediaplayerClosedCaptionDisabledNew"); | 534 "mediaplayerClosedCaptionDisabledNew"); |
| 504 | 535 |
| 505 bool isEnabled = mediaElement->hasClosedCaptions(); | 536 bool isEnabled = mediaElement->hasClosedCaptions(); |
| 506 | 537 |
| 507 if (mediaElement->closedCaptionsVisible()) | 538 if (mediaElement->closedCaptionsVisible()) |
| 508 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto
n, isEnabled); | 539 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto
n, &object, isEnabled); |
| 509 | 540 |
| 510 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis
abled, isEnabled); | 541 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis
abled, &object, isEnabled); |
| 511 } | 542 } |
| 512 | 543 |
| 513 bool MediaControlsPainter::paintMediaCastButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) | 544 bool MediaControlsPainter::paintMediaCastButton(const LayoutObject& object, cons
t PaintInfo& paintInfo, const IntRect& rect) |
| 514 { | 545 { |
| 515 const HTMLMediaElement* mediaElement = toParentMediaElement(object); | 546 const HTMLMediaElement* mediaElement = toParentMediaElement(object); |
| 516 if (!mediaElement) | 547 if (!mediaElement) |
| 517 return false; | 548 return false; |
| 518 | 549 |
| 519 static Image* mediaCastOn = platformResource("mediaplayerCastOn", "mediaplay
erCastOnNew"); | 550 static Image* mediaCastOn = platformResource("mediaplayerCastOn", "mediaplay
erCastOnNew"); |
| 520 static Image* mediaCastOff = platformResource("mediaplayerCastOff", "mediapl
ayerCastOffNew"); | 551 static Image* mediaCastOff = platformResource("mediaplayerCastOff", "mediapl
ayerCastOffNew"); |
| 521 // To ensure that the overlaid cast button is visible when overlaid on pale
videos we use a | 552 // To ensure that the overlaid cast button is visible when overlaid on pale
videos we use a |
| 522 // different version of it for the overlaid case with a semi-opaque backgrou
nd. | 553 // different version of it for the overlaid case with a semi-opaque backgrou
nd. |
| 523 static Image* mediaOverlayCastOff = platformResource( | 554 static Image* mediaOverlayCastOff = platformResource( |
| 524 "mediaplayerOverlayCastOff", | 555 "mediaplayerOverlayCastOff", |
| 525 "mediaplayerOverlayCastOffNew"); | 556 "mediaplayerOverlayCastOffNew"); |
| 526 | 557 |
| 527 bool isEnabled = mediaElement->hasRemoteRoutes(); | 558 bool isEnabled = mediaElement->hasRemoteRoutes(); |
| 528 | 559 |
| 529 switch (mediaControlElementType(object.node())) { | 560 switch (mediaControlElementType(object.node())) { |
| 530 case MediaCastOnButton: | 561 case MediaCastOnButton: |
| 531 return paintMediaButton(paintInfo.context, rect, mediaCastOn, isEnabled)
; | 562 return paintMediaButton(paintInfo.context, rect, mediaCastOn, &object, i
sEnabled); |
| 532 case MediaOverlayCastOnButton: | 563 case MediaOverlayCastOnButton: |
| 533 return paintMediaButton(paintInfo.context, rect, mediaCastOn); | 564 return paintMediaButton(paintInfo.context, rect, mediaCastOn); |
| 534 case MediaCastOffButton: | 565 case MediaCastOffButton: |
| 535 return paintMediaButton(paintInfo.context, rect, mediaCastOff, isEnabled
); | 566 return paintMediaButton(paintInfo.context, rect, mediaCastOff, &object,
isEnabled); |
| 536 case MediaOverlayCastOffButton: | 567 case MediaOverlayCastOffButton: |
| 537 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); | 568 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); |
| 538 default: | 569 default: |
| 539 ASSERT_NOT_REACHED(); | 570 ASSERT_NOT_REACHED(); |
| 540 return false; | 571 return false; |
| 541 } | 572 } |
| 542 } | 573 } |
| 543 | 574 |
| 544 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) | 575 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) |
| 545 { | 576 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 569 } | 600 } |
| 570 | 601 |
| 571 float zoomLevel = style.effectiveZoom(); | 602 float zoomLevel = style.effectiveZoom(); |
| 572 if (thumbImage) { | 603 if (thumbImage) { |
| 573 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); | 604 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); |
| 574 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); | 605 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); |
| 575 } | 606 } |
| 576 } | 607 } |
| 577 | 608 |
| 578 } // namespace blink | 609 } // namespace blink |
| OLD | NEW |