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

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

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

Powered by Google App Engine
This is Rietveld 408576698