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 static const int mediaSliderThumbWidth = 32; | |
49 static const int mediaSliderThumbHeight = 24; | |
50 static const int mediaVolumeSliderThumbHeight = 24; | |
51 static const int mediaVolumeSliderThumbWidth = 24; | |
52 | |
53 // New UI slider thumb sizes, shard between time and volume. | |
54 static const int mediaSliderThumbTouchWidthNew = 36; // Touch zone size. | |
55 static const int mediaSliderThumbTouchHeightNew = 48; | |
56 static const int mediaSliderThumbPaintWidthNew = 12; // Painted area. | |
57 static const int mediaSliderThumbPaintHeightNew = 12; | |
58 | |
59 // New UI overlay play button size. | |
60 static const int mediaOverlayPlayButtonWidthNew = 48; | |
61 static const int mediaOverlayPlayButtonHeightNew = 48; | |
62 | |
63 // New UI slider bar height. | |
64 static const int mediaSliderBarHeight = 2; | |
65 | |
66 // Alpha for disabled elements. | |
67 static 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 isEnabled = false) |
68 { | 96 { |
97 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
98 isEnabled = false; // New UI only. | |
99 | |
100 if (isEnabled) | |
101 context->beginLayer(kDisabledAlpha); | |
102 | |
69 context->drawImage(image, rect); | 103 context->drawImage(image, rect); |
104 | |
105 if (isEnabled) | |
106 context->endLayer(); | |
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. |
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 | |
200 bool MediaControlsPainter::paintMediaSlider(LayoutObject* object, const PaintInf o& paintInfo, const IntRect& rect) | 276 bool MediaControlsPainter::paintMediaSlider(LayoutObject* object, const PaintInf o& paintInfo, const IntRect& rect) |
201 { | 277 { |
202 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 278 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
203 if (!mediaElement) | 279 if (!mediaElement) |
204 return false; | 280 return false; |
205 | 281 |
282 GraphicsContext* context = paintInfo.context; | |
283 | |
284 // Should we paint the new UI grayed out? | |
285 bool drawNewUiGrayed = !hasSource(mediaElement) && RuntimeEnabledFeatures::n ewMediaPlaybackUiEnabled(); | |
286 if (drawNewUiGrayed) | |
287 context->beginLayer(kDisabledAlpha); | |
288 | |
289 paintMediaSliderInternal(object, paintInfo, rect); | |
290 | |
291 if (drawNewUiGrayed) | |
292 context->endLayer(); | |
293 | |
294 return true; | |
295 } | |
296 | |
297 void MediaControlsPainter::paintMediaSliderInternal(LayoutObject* object, const PaintInfo& paintInfo, const IntRect& rect) | |
298 { | |
299 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | |
300 HTMLMediaElement* mediaElement = toParentMediaElement(object); | |
301 if (!mediaElement) | |
302 return; | |
303 | |
206 const ComputedStyle& style = object->styleRef(); | 304 const ComputedStyle& style = object->styleRef(); |
207 GraphicsContext* context = paintInfo.context; | 305 GraphicsContext* context = paintInfo.context; |
208 | 306 |
209 paintRoundedSliderBackground(rect, style, context); | 307 // Paint the slider bar in the "no data buffered" state. |
308 Color sliderBackgroundColor; | |
309 if (!useNewUi) | |
310 sliderBackgroundColor = Color(11, 11, 11); | |
311 else | |
312 sliderBackgroundColor = Color(0xda, 0xda, 0xda); | |
313 | |
314 // TODO(liberato): for the new ui case, draw only after the thumb. does thi s work | |
315 // if we're past the buffered range? probably not. | |
316 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); | |
210 | 317 |
211 // Draw the buffered range. Since the element may have multiple buffered ran ges and it'd be | 318 // 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. | 319 // distracting/'busy' to show all of them, show only the buffered range cont aining the current play head. |
213 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered() ; | 320 RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered() ; |
214 float duration = mediaElement->duration(); | 321 float duration = mediaElement->duration(); |
215 float currentTime = mediaElement->currentTime(); | 322 float currentTime = mediaElement->currentTime(); |
216 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime)) | 323 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime)) |
217 return true; | 324 return; |
218 | 325 |
219 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { | 326 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { |
220 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); | 327 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); |
221 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); | 328 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); |
222 // The delta is there to avoid corner cases when buffered | 329 // The delta is there to avoid corner cases when buffered |
223 // ranges is out of sync with current time because of | 330 // ranges is out of sync with current time because of |
224 // asynchronous media pipeline and current time caching in | 331 // asynchronous media pipeline and current time caching in |
225 // HTMLMediaElement. | 332 // HTMLMediaElement. |
226 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=281 25 | 333 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=281 25 |
227 // FIXME: Remove this workaround when WebMediaPlayer | 334 // FIXME: Remove this workaround when WebMediaPlayer |
228 // has an asynchronous pause interface. | 335 // has an asynchronous pause interface. |
229 if (std::isnan(start) || std::isnan(end) | 336 if (std::isnan(start) || std::isnan(end) |
230 || start > currentTime + kCurrentTimeBufferedDelta || end < currentT ime) | 337 || start > currentTime + kCurrentTimeBufferedDelta || end < currentT ime) |
231 continue; | 338 continue; |
232 int startPosition = int(start * rect.width() / duration); | 339 int startPosition = int(start * rect.width() / duration); |
233 int currentPosition = int(currentTime * rect.width() / duration); | 340 int currentPosition = int(currentTime * rect.width() / duration); |
234 int endPosition = int(end * rect.width() / duration); | 341 int endPosition = int(end * rect.width() / duration); |
235 | 342 |
236 // Add half the thumb width proportionally adjusted to the current paint ing position. | 343 if (!useNewUi) { |
237 int thumbCenter = mediaSliderThumbWidth / 2; | 344 // Add half the thumb width proportionally adjusted to the current p ainting position. |
238 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width() ); | 345 int thumbCenter = mediaSliderThumbWidth / 2; |
239 currentPosition += addWidth; | 346 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.wid th()); |
347 currentPosition += addWidth; | |
348 } | |
240 | 349 |
241 // Draw white-ish highlight before current time. | 350 // Draw highlight before current time. |
242 Color startColor = Color(195, 195, 195); | 351 Color startColor; |
243 Color endColor = Color(217, 217, 217); | 352 Color endColor; |
353 if (!useNewUi) { | |
354 startColor = Color(195, 195, 195); // white-ish. | |
355 endColor = Color(217, 217, 217); | |
356 } else { | |
357 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue. | |
358 } | |
359 | |
244 if (currentPosition > startPosition) | 360 if (currentPosition > startPosition) |
245 paintSliderRangeHighlight(rect, style, context, startPosition, curre ntPosition, startColor, endColor); | 361 paintSliderRangeHighlight(rect, style, context, startPosition, curre ntPosition, startColor, endColor); |
246 | 362 |
247 // Draw grey-ish highlight after current time. | 363 // Draw grey-ish highlight after current time. |
248 startColor = Color(60, 60, 60); | 364 if (!useNewUi) { |
249 endColor = Color(76, 76, 76); | 365 startColor = Color(60, 60, 60); |
366 endColor = Color(76, 76, 76); | |
367 } else { | |
368 startColor = endColor = Color(0x9f, 0x9f, 0x9f); // light grey. | |
369 } | |
250 | 370 |
251 if (endPosition > currentPosition) | 371 if (endPosition > currentPosition) |
252 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor); | 372 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor); |
253 | 373 |
254 return true; | 374 return; |
375 } | |
376 } | |
377 | |
378 void MediaControlsPainter::adjustMediaSliderThumbPaintSize(const IntRect& rect, const ComputedStyle& style, IntRect& rectOut) | |
379 { | |
380 // Adjust the rectangle to be centered, the right size for the image. | |
381 // We do this because it's quite hard to get the thumb touch target | |
382 // to match. So, we provide the touch target size with | |
383 // adjustMediaSliderThumbSize(), and scale it back when we paint. | |
384 rectOut = rect; | |
385 | |
386 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
387 // ...except for the old UI. | |
388 return; | |
255 } | 389 } |
256 | 390 |
257 return true; | 391 float zoomLevel = style.effectiveZoom(); |
392 int zoomedPaintWidth = mediaSliderThumbPaintWidthNew * zoomLevel; | |
393 int zoomedPaintHeight = mediaSliderThumbPaintHeightNew * zoomLevel; | |
394 | |
395 rectOut.setX(rect.center().x() - zoomedPaintWidth / 2); | |
396 rectOut.setY(rect.center().y() - zoomedPaintHeight / 2); | |
397 rectOut.setWidth(zoomedPaintWidth); | |
398 rectOut.setHeight(zoomedPaintHeight); | |
258 } | 399 } |
259 | 400 |
260 bool MediaControlsPainter::paintMediaSliderThumb(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect) | 401 bool MediaControlsPainter::paintMediaSliderThumb(LayoutObject* object, const Pai ntInfo& paintInfo, const IntRect& rect) |
261 { | 402 { |
262 if (!object->node()) | 403 if (!object->node()) |
263 return false; | 404 return false; |
264 | 405 |
265 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); | 406 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); |
266 if (!mediaElement) | 407 if (!mediaElement) |
267 return false; | 408 return false; |
268 | 409 |
269 if (!hasSource(mediaElement)) | 410 if (!hasSource(mediaElement)) |
270 return true; | 411 return true; |
271 | 412 |
272 Image* mediaSliderThumb = getMediaSliderThumb(); | 413 Image* mediaSliderThumb = getMediaSliderThumb(); |
273 return paintMediaButton(paintInfo.context, rect, mediaSliderThumb); | 414 IntRect paintRect; |
415 const ComputedStyle& style = object->styleRef(); | |
416 adjustMediaSliderThumbPaintSize(rect, style, paintRect); | |
417 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb); | |
274 } | 418 } |
275 | 419 |
276 const int mediaVolumeSliderThumbWidth = 24; | |
277 | |
278 bool MediaControlsPainter::paintMediaVolumeSlider(LayoutObject* object, const Pa intInfo& paintInfo, const IntRect& rect) | 420 bool MediaControlsPainter::paintMediaVolumeSlider(LayoutObject* object, const Pa intInfo& paintInfo, const IntRect& rect) |
279 { | 421 { |
280 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 422 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
281 if (!mediaElement) | 423 if (!mediaElement) |
282 return false; | 424 return false; |
283 | 425 |
284 GraphicsContext* context = paintInfo.context; | 426 GraphicsContext* context = paintInfo.context; |
285 const ComputedStyle& style = object->styleRef(); | 427 const ComputedStyle& style = object->styleRef(); |
286 | 428 |
287 paintRoundedSliderBackground(rect, style, context); | 429 // Paint the slider bar. |
430 Color sliderBackgroundColor; | |
431 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
432 sliderBackgroundColor = Color(11, 11, 11); | |
433 else | |
434 sliderBackgroundColor = Color(0x9f, 0x9f, 0x9f); | |
435 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); | |
288 | 436 |
289 // Calculate volume position for white background rectangle. | 437 // Calculate volume position for white background rectangle. |
290 float volume = mediaElement->volume(); | 438 float volume = mediaElement->volume(); |
291 if (std::isnan(volume) || volume < 0) | 439 if (std::isnan(volume) || volume < 0) |
292 return true; | 440 return true; |
293 if (volume > 1) | 441 if (volume > 1) |
294 volume = 1; | 442 volume = 1; |
295 if (!hasSource(mediaElement) || !mediaElement->hasAudio() || mediaElement->m uted()) | 443 if (!hasSource(mediaElement) || !mediaElement->hasAudio() || mediaElement->m uted()) |
296 volume = 0; | 444 volume = 0; |
297 | 445 |
298 // Calculate the position relative to the center of the thumb. | 446 // Calculate the position relative to the center of the thumb. |
299 float fillWidth = 0; | 447 float fillWidth = 0; |
300 if (volume > 0) { | 448 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { |
301 float thumbCenter = mediaVolumeSliderThumbWidth / 2; | 449 if (volume > 0) { |
302 float zoomLevel = style.effectiveZoom(); | 450 float thumbCenter = mediaVolumeSliderThumbWidth / 2; |
303 float positionWidth = volume * (rect.width() - (zoomLevel * thumbCenter) ); | 451 float zoomLevel = style.effectiveZoom(); |
304 fillWidth = positionWidth + (zoomLevel * thumbCenter / 2); | 452 float positionWidth = volume * (rect.width() - (zoomLevel * thumbCen ter)); |
453 fillWidth = positionWidth + (zoomLevel * thumbCenter / 2); | |
454 } | |
455 } else { | |
456 fillWidth = volume * rect.width(); | |
305 } | 457 } |
306 | 458 |
307 Color startColor = Color(195, 195, 195); | 459 Color startColor = Color(195, 195, 195); |
308 Color endColor = Color(217, 217, 217); | 460 Color endColor = Color(217, 217, 217); |
461 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | |
462 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue. | |
309 | 463 |
310 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor); | 464 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor); |
311 | 465 |
312 return true; | 466 return true; |
313 } | 467 } |
314 | 468 |
315 bool MediaControlsPainter::paintMediaVolumeSliderThumb(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) | 469 bool MediaControlsPainter::paintMediaVolumeSliderThumb(LayoutObject* object, con st PaintInfo& paintInfo, const IntRect& rect) |
316 { | 470 { |
317 if (!object->node()) | 471 if (!object->node()) |
318 return false; | 472 return false; |
319 | 473 |
320 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); | 474 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); |
321 if (!mediaElement) | 475 if (!mediaElement) |
322 return false; | 476 return false; |
323 | 477 |
324 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) | 478 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) |
325 return true; | 479 return true; |
326 | 480 |
327 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb"); | 481 static Image* mediaVolumeSliderThumb = platformResource( |
328 return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); | 482 "mediaplayerVolumeSliderThumb", |
483 "mediaplayerVolumeSliderThumbNew"); | |
484 | |
485 IntRect paintRect; | |
486 const ComputedStyle& style = object->styleRef(); | |
487 adjustMediaSliderThumbPaintSize(rect, style, paintRect); | |
488 return paintMediaButton(paintInfo.context, paintRect, mediaVolumeSliderThumb ); | |
329 } | 489 } |
330 | 490 |
331 bool MediaControlsPainter::paintMediaFullscreenButton(LayoutObject* object, cons t PaintInfo& paintInfo, const IntRect& rect) | 491 bool MediaControlsPainter::paintMediaFullscreenButton(LayoutObject* object, cons t PaintInfo& paintInfo, const IntRect& rect) |
332 { | 492 { |
333 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 493 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
334 if (!mediaElement) | 494 if (!mediaElement) |
335 return false; | 495 return false; |
336 | 496 |
337 static Image* mediaFullscreenButton = platformResource("mediaplayerFullscree n"); | 497 // With the new player UI, we have separate assets for enter / exit |
338 return paintMediaButton(paintInfo.context, rect, mediaFullscreenButton); | 498 // full screen mode. |
philipj_slow
2015/07/10 14:51:59
s/full screen/fullscreen/
(I obsess about this: h
liberato (no reviews please)
2015/07/10 15:32:20
:)
| |
499 static Image* mediaEnterFullscreenButton = platformResource( | |
500 "mediaplayerFullscreen", | |
501 "mediaplayerEnterFullscreen"); | |
502 static Image* mediaExitFullscreenButton = platformResource( | |
503 "mediaplayerFullscreen", | |
504 "mediaplayerExitFullscreen"); | |
505 | |
506 bool isEnabled = hasSource(mediaElement); | |
507 | |
508 if (mediaControlElementType(object->node()) == MediaExitFullscreenButton) | |
509 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButt on, !isEnabled); | |
510 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton, !isEnabled); | |
339 } | 511 } |
340 | 512 |
341 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(LayoutObject* ob ject, const PaintInfo& paintInfo, const IntRect& rect) | 513 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(LayoutObject* ob ject, const PaintInfo& paintInfo, const IntRect& rect) |
342 { | 514 { |
343 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 515 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
344 if (!mediaElement) | 516 if (!mediaElement) |
345 return false; | 517 return false; |
346 | 518 |
347 static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosed Caption"); | 519 static Image* mediaClosedCaptionButton = platformResource( |
348 static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplay erClosedCaptionDisabled"); | 520 "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); |
521 static Image* mediaClosedCaptionButtonDisabled = platformResource( | |
522 "mediaplayerClosedCaptionDisabled", | |
523 "mediaplayerClosedCaptionDisabledNew"); | |
524 | |
525 bool isEnabled = hasSource(mediaElement); | |
349 | 526 |
350 if (mediaElement->closedCaptionsVisible()) | 527 if (mediaElement->closedCaptionsVisible()) |
351 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto n); | 528 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto n, !isEnabled); |
352 | 529 |
353 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis abled); | 530 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis abled, !isEnabled); |
354 } | 531 } |
355 | 532 |
356 bool MediaControlsPainter::paintMediaCastButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) | 533 bool MediaControlsPainter::paintMediaCastButton(LayoutObject* object, const Pain tInfo& paintInfo, const IntRect& rect) |
357 { | 534 { |
358 HTMLMediaElement* mediaElement = toParentMediaElement(object); | 535 HTMLMediaElement* mediaElement = toParentMediaElement(object); |
359 if (!mediaElement) | 536 if (!mediaElement) |
360 return false; | 537 return false; |
361 | 538 |
362 static Image* mediaCastOn = platformResource("mediaplayerCastOn"); | 539 static Image* mediaCastOn = platformResource("mediaplayerCastOn", "mediaplay erCastOnNew"); |
363 static Image* mediaCastOff = platformResource("mediaplayerCastOff"); | 540 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 | 541 // 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. | 542 // different version of it for the overlaid case with a semi-opaque backgrou nd. |
366 static Image* mediaOverlayCastOff = platformResource("mediaplayerOverlayCast Off"); | 543 static Image* mediaOverlayCastOff = platformResource( |
544 "mediaplayerOverlayCastOff", | |
545 "mediaplayerOverlayCastOffNew"); | |
546 | |
547 bool isEnabled = hasSource(mediaElement); | |
367 | 548 |
368 switch (mediaControlElementType(object->node())) { | 549 switch (mediaControlElementType(object->node())) { |
369 case MediaCastOnButton: | 550 case MediaCastOnButton: |
551 return paintMediaButton(paintInfo.context, rect, mediaCastOn, !isEnabled ); | |
370 case MediaOverlayCastOnButton: | 552 case MediaOverlayCastOnButton: |
371 return paintMediaButton(paintInfo.context, rect, mediaCastOn); | 553 return paintMediaButton(paintInfo.context, rect, mediaCastOn); |
372 case MediaCastOffButton: | 554 case MediaCastOffButton: |
373 return paintMediaButton(paintInfo.context, rect, mediaCastOff); | 555 return paintMediaButton(paintInfo.context, rect, mediaCastOff, !isEnable d); |
374 case MediaOverlayCastOffButton: | 556 case MediaOverlayCastOffButton: |
375 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); | 557 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); |
376 default: | 558 default: |
377 ASSERT_NOT_REACHED(); | 559 ASSERT_NOT_REACHED(); |
378 return false; | 560 return false; |
379 } | 561 } |
380 } | 562 } |
381 | 563 |
382 const int mediaSliderThumbHeight = 24; | |
383 const int mediaVolumeSliderThumbHeight = 24; | |
384 | |
385 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) | 564 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) |
386 { | 565 { |
387 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); | 566 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb", |
388 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb"); | 567 "mediaplayerSliderThumbNew"); |
568 static Image* mediaVolumeSliderThumb = platformResource( | |
569 "mediaplayerVolumeSliderThumb", | |
570 "mediaplayerVolumeSliderThumbNew"); | |
389 int width = 0; | 571 int width = 0; |
390 int height = 0; | 572 int height = 0; |
391 | 573 |
392 Image* thumbImage = 0; | 574 Image* thumbImage = 0; |
393 if (style.appearance() == MediaSliderThumbPart) { | 575 |
576 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { | |
577 // Volume and time sliders are the same. | |
578 thumbImage = mediaSliderThumb; | |
579 width = mediaSliderThumbTouchWidthNew; | |
580 height = mediaSliderThumbTouchHeightNew; | |
581 } else if (style.appearance() == MediaSliderThumbPart) { | |
394 thumbImage = mediaSliderThumb; | 582 thumbImage = mediaSliderThumb; |
395 width = mediaSliderThumbWidth; | 583 width = mediaSliderThumbWidth; |
396 height = mediaSliderThumbHeight; | 584 height = mediaSliderThumbHeight; |
397 } else if (style.appearance() == MediaVolumeSliderThumbPart) { | 585 } else if (style.appearance() == MediaVolumeSliderThumbPart) { |
398 thumbImage = mediaVolumeSliderThumb; | 586 thumbImage = mediaVolumeSliderThumb; |
399 width = mediaVolumeSliderThumbWidth; | 587 width = mediaVolumeSliderThumbWidth; |
400 height = mediaVolumeSliderThumbHeight; | 588 height = mediaVolumeSliderThumbHeight; |
401 } | 589 } |
402 | 590 |
403 float zoomLevel = style.effectiveZoom(); | 591 float zoomLevel = style.effectiveZoom(); |
404 if (thumbImage) { | 592 if (thumbImage) { |
405 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); | 593 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); |
406 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); | 594 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); |
407 } | 595 } |
408 } | 596 } |
409 | 597 |
410 } // namespace blink | 598 } // namespace blink |
OLD | NEW |