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