Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: third_party/WebKit/Source/core/paint/MediaControlsPainter.cpp

Issue 2447503002: Remove newMediaPlaybackUi flag from content/ and Blink. (Closed)
Patch Set: fix mistake caught by tests Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const double kCurrentTimeBufferedDelta = 1.0; 42 static const 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. 47 // Slider thumb sizes, shard between time and volume.
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. 48 static const int mediaSliderThumbTouchWidthNew = 36; // Touch zone size.
55 static const int mediaSliderThumbTouchHeightNew = 48; 49 static const int mediaSliderThumbTouchHeightNew = 48;
56 static const int mediaSliderThumbPaintWidthNew = 12; // Painted area. 50 static const int mediaSliderThumbPaintWidthNew = 12; // Painted area.
57 static const int mediaSliderThumbPaintHeightNew = 12; 51 static const int mediaSliderThumbPaintHeightNew = 12;
58 52
59 // New UI overlay play button size. 53 // Overlay play button size.
60 static const int mediaOverlayPlayButtonWidthNew = 48; 54 static const int mediaOverlayPlayButtonWidthNew = 48;
61 static const int mediaOverlayPlayButtonHeightNew = 48; 55 static const int mediaOverlayPlayButtonHeightNew = 48;
62 56
63 // Alpha for disabled elements. 57 // Alpha for disabled elements.
64 static const float kDisabledAlpha = 0.4; 58 static const float kDisabledAlpha = 0.4;
65 59
66 static Image* platformResource(const char* name) { 60 static Image* platformResource(const char* name) {
67 if (!gMediaControlImageMap) 61 if (!gMediaControlImageMap)
68 gMediaControlImageMap = new MediaControlImageMap(); 62 gMediaControlImageMap = new MediaControlImageMap();
69 if (Image* image = gMediaControlImageMap->get(name)) 63 if (Image* image = gMediaControlImageMap->get(name))
70 return image; 64 return image;
71 if (Image* image = Image::loadPlatformResource(name).leakRef()) { 65 if (Image* image = Image::loadPlatformResource(name).leakRef()) {
72 gMediaControlImageMap->set(name, image); 66 gMediaControlImageMap->set(name, image);
73 return image; 67 return image;
74 } 68 }
75 ASSERT_NOT_REACHED(); 69 ASSERT_NOT_REACHED();
76 return 0; 70 return 0;
77 } 71 }
78 72
79 static Image* platformResource(const char* currentName, const char* newName) {
80 // Return currentName or newName based on current or new playback.
81 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()
82 ? newName
83 : currentName);
84 }
85
86 static bool hasSource(const HTMLMediaElement* mediaElement) { 73 static bool hasSource(const HTMLMediaElement* mediaElement) {
87 return mediaElement->getNetworkState() != HTMLMediaElement::kNetworkEmpty && 74 return mediaElement->getNetworkState() != HTMLMediaElement::kNetworkEmpty &&
88 mediaElement->getNetworkState() != HTMLMediaElement::kNetworkNoSource; 75 mediaElement->getNetworkState() != HTMLMediaElement::kNetworkNoSource;
89 } 76 }
90 77
91 static FloatRect adjustRectForPadding(IntRect rect, 78 static FloatRect adjustRectForPadding(IntRect rect,
92 const LayoutObject* object) { 79 const LayoutObject* object) {
93 FloatRect adjustedRect(rect); 80 FloatRect adjustedRect(rect);
94 81
95 if (!object) 82 if (!object)
(...skipping 11 matching lines...) Expand all
107 } 94 }
108 95
109 return adjustedRect; 96 return adjustedRect;
110 } 97 }
111 98
112 static bool paintMediaButton(GraphicsContext& context, 99 static bool paintMediaButton(GraphicsContext& context,
113 const IntRect& rect, 100 const IntRect& rect,
114 Image* image, 101 Image* image,
115 const LayoutObject* object, 102 const LayoutObject* object,
116 bool isEnabled) { 103 bool isEnabled) {
117 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
118 context.drawImage(image, rect);
119 return true;
120 }
121
122 FloatRect drawRect = adjustRectForPadding(rect, object); 104 FloatRect drawRect = adjustRectForPadding(rect, object);
123 105
124 if (!isEnabled) 106 if (!isEnabled)
125 context.beginLayer(kDisabledAlpha); 107 context.beginLayer(kDisabledAlpha);
126 108
127 context.drawImage(image, drawRect); 109 context.drawImage(image, drawRect);
128 110
129 if (!isEnabled) 111 if (!isEnabled)
130 context.endLayer(); 112 context.endLayer();
131 113
132 return true; 114 return true;
133 } 115 }
134 116
135 static bool paintMediaButton(GraphicsContext& context, 117 static bool paintMediaButton(GraphicsContext& context,
136 const IntRect& rect, 118 const IntRect& rect,
137 Image* image, 119 Image* image,
138 bool isEnabled = true) { 120 bool isEnabled = true) {
139 return paintMediaButton(context, rect, image, 0, isEnabled); 121 return paintMediaButton(context, rect, image, 0, isEnabled);
140 } 122 }
141 123
142 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, 124 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object,
143 const PaintInfo& paintInfo, 125 const PaintInfo& paintInfo,
144 const IntRect& rect) { 126 const IntRect& rect) {
145 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 127 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
146 if (!mediaElement) 128 if (!mediaElement)
147 return false; 129 return false;
148 130
149 // The new UI uses "muted" and "not muted" only. 131 // The new UI uses "muted" and "not muted" only.
150 static Image* soundLevel3 = 132 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3New");
151 platformResource("mediaplayerSoundLevel3", "mediaplayerSoundLevel3New"); 133 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel3New");
152 static Image* soundLevel2 = 134 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel3New");
153 platformResource("mediaplayerSoundLevel2", "mediaplayerSoundLevel3New"); 135 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0New");
154 static Image* soundLevel1 = 136 static Image* soundDisabled = platformResource("mediaplayerSoundLevel0New");
155 platformResource("mediaplayerSoundLevel1", "mediaplayerSoundLevel3New");
156 static Image* soundLevel0 =
157 platformResource("mediaplayerSoundLevel0", "mediaplayerSoundLevel0New");
158 static Image* soundDisabled =
159 platformResource("mediaplayerSoundDisabled", "mediaplayerSoundLevel0New");
160 137
161 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) 138 if (!hasSource(mediaElement) || !mediaElement->hasAudio())
162 return paintMediaButton(paintInfo.context, rect, soundDisabled, &object, 139 return paintMediaButton(paintInfo.context, rect, soundDisabled, &object,
163 false); 140 false);
164 141
165 if (mediaElement->muted() || mediaElement->volume() <= 0) 142 if (mediaElement->muted() || mediaElement->volume() <= 0)
166 return paintMediaButton(paintInfo.context, rect, soundLevel0, &object, 143 return paintMediaButton(paintInfo.context, rect, soundLevel0, &object,
167 true); 144 true);
168 145
169 if (mediaElement->volume() <= 0.33) 146 if (mediaElement->volume() <= 0.33)
170 return paintMediaButton(paintInfo.context, rect, soundLevel1, &object, 147 return paintMediaButton(paintInfo.context, rect, soundLevel1, &object,
171 true); 148 true);
172 149
173 if (mediaElement->volume() <= 0.66) 150 if (mediaElement->volume() <= 0.66)
174 return paintMediaButton(paintInfo.context, rect, soundLevel2, &object, 151 return paintMediaButton(paintInfo.context, rect, soundLevel2, &object,
175 true); 152 true);
176 153
177 return paintMediaButton(paintInfo.context, rect, soundLevel3, &object, true); 154 return paintMediaButton(paintInfo.context, rect, soundLevel3, &object, true);
178 } 155 }
179 156
180 bool MediaControlsPainter::paintMediaPlayButton(const LayoutObject& object, 157 bool MediaControlsPainter::paintMediaPlayButton(const LayoutObject& object,
181 const PaintInfo& paintInfo, 158 const PaintInfo& paintInfo,
182 const IntRect& rect) { 159 const IntRect& rect) {
183 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 160 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
184 if (!mediaElement) 161 if (!mediaElement)
185 return false; 162 return false;
186 163
187 static Image* mediaPlay = 164 static Image* mediaPlay = platformResource("mediaplayerPlayNew");
188 platformResource("mediaplayerPlay", "mediaplayerPlayNew"); 165 static Image* mediaPause = platformResource("mediaplayerPauseNew");
189 static Image* mediaPause =
190 platformResource("mediaplayerPause", "mediaplayerPauseNew");
191 // For this case, the new UI draws the normal icon, but the entire panel 166 // For this case, the new UI draws the normal icon, but the entire panel
192 // grays out. 167 // grays out.
193 static Image* mediaPlayDisabled = 168 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayNew");
194 platformResource("mediaplayerPlayDisabled", "mediaplayerPlayNew");
195 169
196 if (!hasSource(mediaElement)) 170 if (!hasSource(mediaElement))
197 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, &object, 171 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled, &object,
198 false); 172 false);
199 173
200 Image* image = 174 Image* image =
201 !object.node()->isMediaControlElement() || 175 !object.node()->isMediaControlElement() ||
202 mediaControlElementType(object.node()) == MediaPlayButton 176 mediaControlElementType(object.node()) == MediaPlayButton
203 ? mediaPlay 177 ? mediaPlay
204 : mediaPause; 178 : mediaPause;
205 return paintMediaButton(paintInfo.context, rect, image, &object, true); 179 return paintMediaButton(paintInfo.context, rect, image, &object, true);
206 } 180 }
207 181
208 bool MediaControlsPainter::paintMediaOverlayPlayButton( 182 bool MediaControlsPainter::paintMediaOverlayPlayButton(
209 const LayoutObject& object, 183 const LayoutObject& object,
210 const PaintInfo& paintInfo, 184 const PaintInfo& paintInfo,
211 const IntRect& rect) { 185 const IntRect& rect) {
212 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 186 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
213 if (!mediaElement) 187 if (!mediaElement)
214 return false; 188 return false;
215 189
216 if (!hasSource(mediaElement) || !mediaElement->paused()) 190 if (!hasSource(mediaElement) || !mediaElement->paused())
217 return false; 191 return false;
218 192
219 static Image* mediaOverlayPlay = 193 static Image* mediaOverlayPlay =
220 platformResource("mediaplayerOverlayPlay", "mediaplayerOverlayPlayNew"); 194 platformResource("mediaplayerOverlayPlayNew");
221 195
222 IntRect buttonRect(rect); 196 IntRect buttonRect(rect);
223 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 197
224 // Overlay play button covers the entire player, so center and draw a 198 // Overlay play button covers the entire player, so center and draw a
225 // smaller button. Center in the entire element. 199 // smaller button. Center in the entire element.
226 // TODO(liberato): object.enclosingBox()? 200 // TODO(liberato): object.enclosingBox()?
227 const LayoutBox* box = mediaElement->layoutObject()->enclosingBox(); 201 const LayoutBox* box = mediaElement->layoutObject()->enclosingBox();
228 if (!box) 202 if (!box)
229 return false; 203 return false;
230 int mediaHeight = box->pixelSnappedHeight(); 204 int mediaHeight = box->pixelSnappedHeight();
231 buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2); 205 buttonRect.setX(rect.center().x() - mediaOverlayPlayButtonWidthNew / 2);
232 buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2 + 206 buttonRect.setY(rect.center().y() - mediaOverlayPlayButtonHeightNew / 2 +
233 (mediaHeight - rect.height()) / 2); 207 (mediaHeight - rect.height()) / 2);
234 buttonRect.setWidth(mediaOverlayPlayButtonWidthNew); 208 buttonRect.setWidth(mediaOverlayPlayButtonWidthNew);
235 buttonRect.setHeight(mediaOverlayPlayButtonHeightNew); 209 buttonRect.setHeight(mediaOverlayPlayButtonHeightNew);
236 }
237 210
238 return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay); 211 return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay);
239 } 212 }
240 213
241 static Image* getMediaSliderThumb() {
242 static Image* mediaSliderThumb =
243 platformResource("mediaplayerSliderThumb", "mediaplayerSliderThumbNew");
244 return mediaSliderThumb;
245 }
246
247 static void paintRoundedSliderBackground(const IntRect& rect, 214 static void paintRoundedSliderBackground(const IntRect& rect,
248 const ComputedStyle& style, 215 const ComputedStyle& style,
249 GraphicsContext& context, 216 GraphicsContext& context,
250 Color sliderBackgroundColor) { 217 Color sliderBackgroundColor) {
251 float borderRadius = rect.height() / 2; 218 float borderRadius = rect.height() / 2;
252 FloatSize radii(borderRadius, borderRadius); 219 FloatSize radii(borderRadius, borderRadius);
253 220
254 context.fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), 221 context.fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii),
255 sliderBackgroundColor); 222 sliderBackgroundColor);
256 } 223 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 bool MediaControlsPainter::paintMediaSlider(const LayoutObject& object, 290 bool MediaControlsPainter::paintMediaSlider(const LayoutObject& object,
324 const PaintInfo& paintInfo, 291 const PaintInfo& paintInfo,
325 const IntRect& rect) { 292 const IntRect& rect) {
326 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 293 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
327 if (!mediaElement) 294 if (!mediaElement)
328 return false; 295 return false;
329 296
330 GraphicsContext& context = paintInfo.context; 297 GraphicsContext& context = paintInfo.context;
331 298
332 // Should we paint the slider partially transparent? 299 // Should we paint the slider partially transparent?
333 bool drawUiGrayed = !hasSource(mediaElement) && 300 bool drawUiGrayed = !hasSource(mediaElement);
334 RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
335 if (drawUiGrayed) 301 if (drawUiGrayed)
336 context.beginLayer(kDisabledAlpha); 302 context.beginLayer(kDisabledAlpha);
337 303
338 paintMediaSliderInternal(object, paintInfo, rect); 304 paintMediaSliderInternal(object, paintInfo, rect);
339 305
340 if (drawUiGrayed) 306 if (drawUiGrayed)
341 context.endLayer(); 307 context.endLayer();
342 308
343 return true; 309 return true;
344 } 310 }
345 311
346 void MediaControlsPainter::paintMediaSliderInternal(const LayoutObject& object, 312 void MediaControlsPainter::paintMediaSliderInternal(const LayoutObject& object,
347 const PaintInfo& paintInfo, 313 const PaintInfo& paintInfo,
348 const IntRect& rect) { 314 const IntRect& rect) {
349 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
350 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 315 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
351 if (!mediaElement) 316 if (!mediaElement)
352 return; 317 return;
353 318
354 const ComputedStyle& style = object.styleRef(); 319 const ComputedStyle& style = object.styleRef();
355 GraphicsContext& context = paintInfo.context; 320 GraphicsContext& context = paintInfo.context;
356 321
357 // Paint the slider bar in the "no data buffered" state. 322 // Paint the slider bar in the "no data buffered" state.
358 Color sliderBackgroundColor; 323 paintRoundedSliderBackground(rect, style, context, Color(0xda, 0xda, 0xda));
359 if (!useNewUi)
360 sliderBackgroundColor = Color(11, 11, 11);
361 else
362 sliderBackgroundColor = Color(0xda, 0xda, 0xda);
363
364 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);
365 324
366 // Draw the buffered range. Since the element may have multiple buffered 325 // Draw the buffered range. Since the element may have multiple buffered
367 // ranges and it'd be distracting/'busy' to show all of them, show only the 326 // ranges and it'd be distracting/'busy' to show all of them, show only the
368 // buffered range containing the current play head. 327 // buffered range containing the current play head.
369 TimeRanges* bufferedTimeRanges = mediaElement->buffered(); 328 TimeRanges* bufferedTimeRanges = mediaElement->buffered();
370 float duration = mediaElement->duration(); 329 float duration = mediaElement->duration();
371 float currentTime = mediaElement->currentTime(); 330 float currentTime = mediaElement->currentTime();
372 if (std::isnan(duration) || std::isinf(duration) || !duration || 331 if (std::isnan(duration) || std::isinf(duration) || !duration ||
373 std::isnan(currentTime)) 332 std::isnan(currentTime))
374 return; 333 return;
375 334
376 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { 335 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) {
377 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); 336 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION);
378 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); 337 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION);
379 // The delta is there to avoid corner cases when buffered 338 // The delta is there to avoid corner cases when buffered
380 // ranges is out of sync with current time because of 339 // ranges is out of sync with current time because of
381 // asynchronous media pipeline and current time caching in 340 // asynchronous media pipeline and current time caching in
382 // HTMLMediaElement. 341 // HTMLMediaElement.
383 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=28125 342 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=28125
384 // FIXME: Remove this workaround when WebMediaPlayer 343 // FIXME: Remove this workaround when WebMediaPlayer
385 // has an asynchronous pause interface. 344 // has an asynchronous pause interface.
386 if (std::isnan(start) || std::isnan(end) || 345 if (std::isnan(start) || std::isnan(end) ||
387 start > currentTime + kCurrentTimeBufferedDelta || end < currentTime) 346 start > currentTime + kCurrentTimeBufferedDelta || end < currentTime)
388 continue; 347 continue;
389 int startPosition = int(start * rect.width() / duration); 348 int startPosition = int(start * rect.width() / duration);
390 int currentPosition = int(currentTime * rect.width() / duration); 349 int currentPosition = int(currentTime * rect.width() / duration);
391 int endPosition = int(end * rect.width() / duration); 350 int endPosition = int(end * rect.width() / duration);
392 351
393 if (!useNewUi) { 352 // Draw highlight before current time.
394 // Add half the thumb width proportionally adjusted to the current 353 Color startColor = Color(0x42, 0x85, 0xf4);
395 // painting position. 354 Color endColor = Color(0x42, 0x85, 0xf4);
396 int thumbCenter = mediaSliderThumbWidth / 2; 355
397 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()); 356 if (currentPosition > startPosition) {
398 currentPosition += addWidth; 357 paintSliderRangeHighlight(rect, style, context, startPosition,
358 currentPosition, startColor, endColor);
399 } 359 }
400 360
401 // Draw highlight before current time. 361 // Draw dark grey highlight after current time.
402 Color startColor; 362 startColor = endColor = Color(0x5a, 0x5a, 0x5a);
403 Color endColor;
404 if (!useNewUi) {
405 startColor = Color(195, 195, 195); // white-ish.
406 endColor = Color(217, 217, 217);
407 } else {
408 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue.
409 }
410 363
411 if (currentPosition > startPosition) 364 if (endPosition > currentPosition) {
412 paintSliderRangeHighlight(rect, style, context, startPosition,
413 currentPosition, startColor, endColor);
414
415 // Draw grey-ish highlight after current time.
416 if (!useNewUi) {
417 startColor = Color(60, 60, 60);
418 endColor = Color(76, 76, 76);
419 } else {
420 startColor = endColor = Color(0x5a, 0x5a, 0x5a); // dark grey
421 }
422
423 if (endPosition > currentPosition)
424 paintSliderRangeHighlight(rect, style, context, currentPosition, 365 paintSliderRangeHighlight(rect, style, context, currentPosition,
425 endPosition, startColor, endColor); 366 endPosition, startColor, endColor);
426 367 }
427 return; 368 return;
428 } 369 }
429 } 370 }
430 371
431 void MediaControlsPainter::adjustMediaSliderThumbPaintSize( 372 void MediaControlsPainter::adjustMediaSliderThumbPaintSize(
432 const IntRect& rect, 373 const IntRect& rect,
433 const ComputedStyle& style, 374 const ComputedStyle& style,
434 IntRect& rectOut) { 375 IntRect& rectOut) {
435 // Adjust the rectangle to be centered, the right size for the image. 376 // Adjust the rectangle to be centered, the right size for the image.
436 // We do this because it's quite hard to get the thumb touch target 377 // We do this because it's quite hard to get the thumb touch target
437 // to match. So, we provide the touch target size with 378 // to match. So, we provide the touch target size with
438 // adjustMediaSliderThumbSize(), and scale it back when we paint. 379 // adjustMediaSliderThumbSize(), and scale it back when we paint.
439 rectOut = rect; 380 rectOut = rect;
440 381
441 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 382 const float zoomLevel = style.effectiveZoom();
442 // ...except for the old UI. 383 const float zoomedPaintWidth = mediaSliderThumbPaintWidthNew * zoomLevel;
443 return; 384 const float zoomedPaintHeight = mediaSliderThumbPaintHeightNew * zoomLevel;
444 }
445
446 float zoomLevel = style.effectiveZoom();
447 float zoomedPaintWidth = mediaSliderThumbPaintWidthNew * zoomLevel;
448 float zoomedPaintHeight = mediaSliderThumbPaintHeightNew * zoomLevel;
449 385
450 rectOut.setX(rect.center().x() - zoomedPaintWidth / 2); 386 rectOut.setX(rect.center().x() - zoomedPaintWidth / 2);
451 rectOut.setY(rect.center().y() - zoomedPaintHeight / 2); 387 rectOut.setY(rect.center().y() - zoomedPaintHeight / 2);
452 rectOut.setWidth(zoomedPaintWidth); 388 rectOut.setWidth(zoomedPaintWidth);
453 rectOut.setHeight(zoomedPaintHeight); 389 rectOut.setHeight(zoomedPaintHeight);
454 } 390 }
455 391
456 bool MediaControlsPainter::paintMediaSliderThumb(const LayoutObject& object, 392 bool MediaControlsPainter::paintMediaSliderThumb(const LayoutObject& object,
457 const PaintInfo& paintInfo, 393 const PaintInfo& paintInfo,
458 const IntRect& rect) { 394 const IntRect& rect) {
459 if (!object.node()) 395 if (!object.node())
460 return false; 396 return false;
461 397
462 const HTMLMediaElement* mediaElement = 398 const HTMLMediaElement* mediaElement =
463 toParentMediaElement(object.node()->ownerShadowHost()); 399 toParentMediaElement(object.node()->ownerShadowHost());
464 if (!mediaElement) 400 if (!mediaElement)
465 return false; 401 return false;
466 402
467 if (!hasSource(mediaElement)) 403 if (!hasSource(mediaElement))
468 return true; 404 return true;
469 405
470 Image* mediaSliderThumb = getMediaSliderThumb(); 406 static Image* mediaSliderThumb =
407 platformResource("mediaplayerSliderThumbNew");
471 IntRect paintRect; 408 IntRect paintRect;
472 const ComputedStyle& style = object.styleRef(); 409 const ComputedStyle& style = object.styleRef();
473 adjustMediaSliderThumbPaintSize(rect, style, paintRect); 410 adjustMediaSliderThumbPaintSize(rect, style, paintRect);
474 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb); 411 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb);
475 } 412 }
476 413
477 bool MediaControlsPainter::paintMediaVolumeSlider(const LayoutObject& object, 414 bool MediaControlsPainter::paintMediaVolumeSlider(const LayoutObject& object,
478 const PaintInfo& paintInfo, 415 const PaintInfo& paintInfo,
479 const IntRect& rect) { 416 const IntRect& rect) {
480 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 417 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
481 if (!mediaElement) 418 if (!mediaElement)
482 return false; 419 return false;
483 420
484 GraphicsContext& context = paintInfo.context; 421 GraphicsContext& context = paintInfo.context;
485 const ComputedStyle& style = object.styleRef(); 422 const ComputedStyle& style = object.styleRef();
486 423
487 // Paint the slider bar. 424 // Paint the slider bar.
488 Color sliderBackgroundColor; 425 paintRoundedSliderBackground(rect, style, context, Color(0x5a, 0x5a, 0x5a));
489 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
490 sliderBackgroundColor = Color(11, 11, 11);
491 else
492 sliderBackgroundColor = Color(0x5a, 0x5a, 0x5a); // dark grey
493 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);
494 426
495 // Calculate volume position for white background rectangle. 427 // Calculate volume position for white background rectangle.
496 float volume = mediaElement->volume(); 428 float volume = mediaElement->volume();
497 if (std::isnan(volume) || volume < 0) 429 if (std::isnan(volume) || volume < 0)
498 return true; 430 return true;
499 if (volume > 1) 431 if (volume > 1)
500 volume = 1; 432 volume = 1;
501 if (!hasSource(mediaElement) || !mediaElement->hasAudio() || 433 if (!hasSource(mediaElement) || !mediaElement->hasAudio() ||
502 mediaElement->muted()) 434 mediaElement->muted()) {
503 volume = 0; 435 volume = 0;
436 }
504 437
505 // Calculate the position relative to the center of the thumb. 438 // Calculate the position relative to the center of the thumb.
506 float fillWidth = 0; 439 const float fillWidth = volume * rect.width();
507 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 440 static const Color color = Color(0x42, 0x85, 0xf4); // blue
508 if (volume > 0) { 441 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, color, color);
509 float thumbCenter = mediaVolumeSliderThumbWidth / 2;
510 float zoomLevel = style.effectiveZoom();
511 float positionWidth = volume * (rect.width() - (zoomLevel * thumbCenter));
512 fillWidth = positionWidth + (zoomLevel * thumbCenter / 2);
513 }
514 } else {
515 fillWidth = volume * rect.width();
516 }
517
518 Color startColor = Color(195, 195, 195);
519 Color endColor = Color(217, 217, 217);
520 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
521 startColor = endColor = Color(0x42, 0x85, 0xf4); // blue.
522
523 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor,
524 endColor);
525 442
526 return true; 443 return true;
527 } 444 }
528 445
529 bool MediaControlsPainter::paintMediaVolumeSliderThumb( 446 bool MediaControlsPainter::paintMediaVolumeSliderThumb(
530 const LayoutObject& object, 447 const LayoutObject& object,
531 const PaintInfo& paintInfo, 448 const PaintInfo& paintInfo,
532 const IntRect& rect) { 449 const IntRect& rect) {
533 if (!object.node()) 450 if (!object.node())
534 return false; 451 return false;
535 452
536 const HTMLMediaElement* mediaElement = 453 const HTMLMediaElement* mediaElement =
537 toParentMediaElement(object.node()->ownerShadowHost()); 454 toParentMediaElement(object.node()->ownerShadowHost());
538 if (!mediaElement) 455 if (!mediaElement)
539 return false; 456 return false;
540 457
541 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) 458 if (!hasSource(mediaElement) || !mediaElement->hasAudio())
542 return true; 459 return true;
543 460
544 static Image* mediaVolumeSliderThumb = platformResource( 461 static Image* mediaVolumeSliderThumb =
545 "mediaplayerVolumeSliderThumb", "mediaplayerVolumeSliderThumbNew"); 462 platformResource("mediaplayerVolumeSliderThumbNew");
546 463
547 IntRect paintRect; 464 IntRect paintRect;
548 const ComputedStyle& style = object.styleRef(); 465 const ComputedStyle& style = object.styleRef();
549 adjustMediaSliderThumbPaintSize(rect, style, paintRect); 466 adjustMediaSliderThumbPaintSize(rect, style, paintRect);
550 return paintMediaButton(paintInfo.context, paintRect, mediaVolumeSliderThumb); 467 return paintMediaButton(paintInfo.context, paintRect, mediaVolumeSliderThumb);
551 } 468 }
552 469
553 bool MediaControlsPainter::paintMediaFullscreenButton( 470 bool MediaControlsPainter::paintMediaFullscreenButton(
554 const LayoutObject& object, 471 const LayoutObject& object,
555 const PaintInfo& paintInfo, 472 const PaintInfo& paintInfo,
556 const IntRect& rect) { 473 const IntRect& rect) {
557 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 474 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
558 if (!mediaElement) 475 if (!mediaElement)
559 return false; 476 return false;
560 477
561 // With the new player UI, we have separate assets for enter / exit 478 // With the new player UI, we have separate assets for enter / exit
562 // fullscreen mode. 479 // fullscreen mode.
563 static Image* mediaEnterFullscreenButton = 480 static Image* mediaEnterFullscreenButton =
564 platformResource("mediaplayerFullscreen", "mediaplayerEnterFullscreen"); 481 platformResource("mediaplayerEnterFullscreen");
565 static Image* mediaExitFullscreenButton = 482 static Image* mediaExitFullscreenButton =
566 platformResource("mediaplayerFullscreen", "mediaplayerExitFullscreen"); 483 platformResource("mediaplayerExitFullscreen");
567 484
568 bool isEnabled = hasSource(mediaElement); 485 bool isEnabled = hasSource(mediaElement);
569 486
570 if (mediaControlElementType(object.node()) == MediaExitFullscreenButton) 487 if (mediaControlElementType(object.node()) == MediaExitFullscreenButton)
571 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButton, 488 return paintMediaButton(paintInfo.context, rect, mediaExitFullscreenButton,
572 &object, isEnabled); 489 &object, isEnabled);
573 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton, 490 return paintMediaButton(paintInfo.context, rect, mediaEnterFullscreenButton,
574 &object, isEnabled); 491 &object, isEnabled);
575 } 492 }
576 493
577 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton( 494 bool MediaControlsPainter::paintMediaToggleClosedCaptionsButton(
578 const LayoutObject& object, 495 const LayoutObject& object,
579 const PaintInfo& paintInfo, 496 const PaintInfo& paintInfo,
580 const IntRect& rect) { 497 const IntRect& rect) {
581 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 498 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
582 if (!mediaElement) 499 if (!mediaElement)
583 return false; 500 return false;
584 501
585 static Image* mediaClosedCaptionButton = platformResource( 502 static Image* mediaClosedCaptionButton =
586 "mediaplayerClosedCaption", "mediaplayerClosedCaptionNew"); 503 platformResource("mediaplayerClosedCaptionNew");
587 static Image* mediaClosedCaptionButtonDisabled = 504 static Image* mediaClosedCaptionButtonDisabled =
588 platformResource("mediaplayerClosedCaptionDisabled", 505 platformResource("mediaplayerClosedCaptionDisabledNew");
589 "mediaplayerClosedCaptionDisabledNew");
590 506
591 bool isEnabled = mediaElement->hasClosedCaptions(); 507 bool isEnabled = mediaElement->hasClosedCaptions();
592 508
593 if (mediaElement->textTracksVisible()) 509 if (mediaElement->textTracksVisible())
594 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButton, 510 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButton,
595 &object, isEnabled); 511 &object, isEnabled);
596 512
597 return paintMediaButton(paintInfo.context, rect, 513 return paintMediaButton(paintInfo.context, rect,
598 mediaClosedCaptionButtonDisabled, &object, isEnabled); 514 mediaClosedCaptionButtonDisabled, &object, isEnabled);
599 } 515 }
600 516
601 bool MediaControlsPainter::paintMediaCastButton(const LayoutObject& object, 517 bool MediaControlsPainter::paintMediaCastButton(const LayoutObject& object,
602 const PaintInfo& paintInfo, 518 const PaintInfo& paintInfo,
603 const IntRect& rect) { 519 const IntRect& rect) {
604 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 520 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
605 if (!mediaElement) 521 if (!mediaElement)
606 return false; 522 return false;
607 523
608 static Image* mediaCastOn = 524 static Image* mediaCastOn = platformResource("mediaplayerCastOnNew");
609 platformResource("mediaplayerCastOn", "mediaplayerCastOnNew"); 525 static Image* mediaCastOff = platformResource("mediaplayerCastOffNew");
610 static Image* mediaCastOff =
611 platformResource("mediaplayerCastOff", "mediaplayerCastOffNew");
612 // To ensure that the overlaid cast button is visible when overlaid on pale 526 // To ensure that the overlaid cast button is visible when overlaid on pale
613 // videos we use a different version of it for the overlaid case with a 527 // videos we use a different version of it for the overlaid case with a
614 // semi-opaque background. 528 // semi-opaque background.
615 static Image* mediaOverlayCastOff = platformResource( 529 static Image* mediaOverlayCastOff =
616 "mediaplayerOverlayCastOff", "mediaplayerOverlayCastOffNew"); 530 platformResource("mediaplayerOverlayCastOffNew");
617 531
618 bool isEnabled = mediaElement->hasRemoteRoutes(); 532 bool isEnabled = mediaElement->hasRemoteRoutes();
619 533
620 switch (mediaControlElementType(object.node())) { 534 switch (mediaControlElementType(object.node())) {
621 case MediaCastOnButton: 535 case MediaCastOnButton:
622 return paintMediaButton(paintInfo.context, rect, mediaCastOn, &object, 536 return paintMediaButton(paintInfo.context, rect, mediaCastOn, &object,
623 isEnabled); 537 isEnabled);
624 case MediaOverlayCastOnButton: 538 case MediaOverlayCastOnButton:
625 return paintMediaButton(paintInfo.context, rect, mediaCastOn); 539 return paintMediaButton(paintInfo.context, rect, mediaCastOn);
626 case MediaCastOffButton: 540 case MediaCastOffButton:
627 return paintMediaButton(paintInfo.context, rect, mediaCastOff, &object, 541 return paintMediaButton(paintInfo.context, rect, mediaCastOff, &object,
628 isEnabled); 542 isEnabled);
629 case MediaOverlayCastOffButton: 543 case MediaOverlayCastOffButton:
630 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff); 544 return paintMediaButton(paintInfo.context, rect, mediaOverlayCastOff);
631 default: 545 default:
632 ASSERT_NOT_REACHED(); 546 ASSERT_NOT_REACHED();
633 return false; 547 return false;
634 } 548 }
635 } 549 }
636 550
637 bool MediaControlsPainter::paintMediaTrackSelectionCheckmark( 551 bool MediaControlsPainter::paintMediaTrackSelectionCheckmark(
638 const LayoutObject& object, 552 const LayoutObject& object,
639 const PaintInfo& paintInfo, 553 const PaintInfo& paintInfo,
640 const IntRect& rect) { 554 const IntRect& rect) {
641 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 555 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
642 if (!mediaElement) 556 if (!mediaElement)
643 return false; 557 return false;
644 558
645 static Image* mediaTrackSelectionCheckmark = 559 static Image* mediaTrackSelectionCheckmark =
646 platformResource("mediaplayerTrackSelectionCheckmark", 560 platformResource("mediaplayerTrackSelectionCheckmarkNew");
647 "mediaplayerTrackSelectionCheckmarkNew");
648 return paintMediaButton(paintInfo.context, rect, 561 return paintMediaButton(paintInfo.context, rect,
649 mediaTrackSelectionCheckmark); 562 mediaTrackSelectionCheckmark);
650 } 563 }
651 564
652 bool MediaControlsPainter::paintMediaClosedCaptionsIcon( 565 bool MediaControlsPainter::paintMediaClosedCaptionsIcon(
653 const LayoutObject& object, 566 const LayoutObject& object,
654 const PaintInfo& paintInfo, 567 const PaintInfo& paintInfo,
655 const IntRect& rect) { 568 const IntRect& rect) {
656 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 569 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
657 if (!mediaElement) 570 if (!mediaElement)
658 return false; 571 return false;
659 572
660 static Image* mediaClosedCaptionsIcon = platformResource( 573 static Image* mediaClosedCaptionsIcon =
661 "mediaplayerClosedCaptionsIcon", "mediaplayerClosedCaptionsIconNew"); 574 platformResource("mediaplayerClosedCaptionsIconNew");
662 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionsIcon); 575 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionsIcon);
663 } 576 }
664 577
665 bool MediaControlsPainter::paintMediaSubtitlesIcon(const LayoutObject& object, 578 bool MediaControlsPainter::paintMediaSubtitlesIcon(const LayoutObject& object,
666 const PaintInfo& paintInfo, 579 const PaintInfo& paintInfo,
667 const IntRect& rect) { 580 const IntRect& rect) {
668 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 581 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
669 if (!mediaElement) 582 if (!mediaElement)
670 return false; 583 return false;
671 584
672 static Image* mediaSubtitlesIcon = platformResource( 585 static Image* mediaSubtitlesIcon =
673 "mediaplayerSubtitlesIcon", "mediaplayerSubtitlesIconNew"); 586 platformResource("mediaplayerSubtitlesIconNew");
674 return paintMediaButton(paintInfo.context, rect, mediaSubtitlesIcon); 587 return paintMediaButton(paintInfo.context, rect, mediaSubtitlesIcon);
675 } 588 }
676 589
677 bool MediaControlsPainter::paintMediaOverflowMenu(const LayoutObject& object, 590 bool MediaControlsPainter::paintMediaOverflowMenu(const LayoutObject& object,
678 const PaintInfo& paintInfo, 591 const PaintInfo& paintInfo,
679 const IntRect& rect) { 592 const IntRect& rect) {
680 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 593 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
681 if (!mediaElement) 594 if (!mediaElement)
682 return false; 595 return false;
683 596
(...skipping 11 matching lines...) Expand all
695 return false; 608 return false;
696 609
697 bool isEnabled = hasSource(mediaElement); 610 bool isEnabled = hasSource(mediaElement);
698 611
699 static Image* mediaDownloadIcon = platformResource("mediaplayerDownloadIcon"); 612 static Image* mediaDownloadIcon = platformResource("mediaplayerDownloadIcon");
700 return paintMediaButton(paintInfo.context, rect, mediaDownloadIcon, &object, 613 return paintMediaButton(paintInfo.context, rect, mediaDownloadIcon, &object,
701 isEnabled); 614 isEnabled);
702 } 615 }
703 616
704 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) { 617 void MediaControlsPainter::adjustMediaSliderThumbSize(ComputedStyle& style) {
705 static Image* mediaSliderThumb = 618 const float zoomLevel = style.effectiveZoom();
706 platformResource("mediaplayerSliderThumb", "mediaplayerSliderThumbNew");
707 static Image* mediaVolumeSliderThumb = platformResource(
708 "mediaplayerVolumeSliderThumb", "mediaplayerVolumeSliderThumbNew");
709 int width = 0;
710 int height = 0;
711 619
712 Image* thumbImage = 0; 620 style.setWidth(Length(
713 621 static_cast<int>(mediaSliderThumbTouchWidthNew * zoomLevel), Fixed));
714 if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 622 style.setHeight(Length(
715 // Volume and time sliders are the same. 623 static_cast<int>(mediaSliderThumbTouchHeightNew * zoomLevel), Fixed));
716 thumbImage = mediaSliderThumb;
717 width = mediaSliderThumbTouchWidthNew;
718 height = mediaSliderThumbTouchHeightNew;
719 } else if (style.appearance() == MediaSliderThumbPart) {
720 thumbImage = mediaSliderThumb;
721 width = mediaSliderThumbWidth;
722 height = mediaSliderThumbHeight;
723 } else if (style.appearance() == MediaVolumeSliderThumbPart) {
724 thumbImage = mediaVolumeSliderThumb;
725 width = mediaVolumeSliderThumbWidth;
726 height = mediaVolumeSliderThumbHeight;
727 }
728
729 float zoomLevel = style.effectiveZoom();
730 if (thumbImage) {
731 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed));
732 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed));
733 }
734 } 624 }
735 625
736 } // namespace blink 626 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutThemeTest.cpp ('k') | third_party/WebKit/Source/core/testing/Internals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698