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

Side by Side Diff: Source/core/rendering/RenderMediaControlsChromium.cpp

Issue 21430003: Implement interfaces in PaintInfo and make it a class. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@getterPaintInfo01
Patch Set: Second try Created 7 years, 4 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY 58 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY
59 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; 59 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE;
60 } 60 }
61 61
62 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image) 62 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image)
63 { 63 {
64 context->drawImage(image, rect); 64 context->drawImage(image, rect);
65 return true; 65 return true;
66 } 66 }
67 67
68 static bool paintMediaMuteButton(RenderObject* object, const PaintInfo& paintInf o, const IntRect& rect) 68 static bool paintMediaMuteButton(RenderObject* object, PaintInfo& paintInfo, con st IntRect& rect)
69 { 69 {
70 HTMLMediaElement* mediaElement = toParentMediaElement(object); 70 HTMLMediaElement* mediaElement = toParentMediaElement(object);
71 if (!mediaElement) 71 if (!mediaElement)
72 return false; 72 return false;
73 73
74 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3"); 74 static Image* soundLevel3 = platformResource("mediaplayerSoundLevel3");
75 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2"); 75 static Image* soundLevel2 = platformResource("mediaplayerSoundLevel2");
76 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1"); 76 static Image* soundLevel1 = platformResource("mediaplayerSoundLevel1");
77 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0"); 77 static Image* soundLevel0 = platformResource("mediaplayerSoundLevel0");
78 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled"); 78 static Image* soundDisabled = platformResource("mediaplayerSoundDisabled");
79 79
80 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) 80 if (!hasSource(mediaElement) || !mediaElement->hasAudio())
81 return paintMediaButton(paintInfo.context, rect, soundDisabled); 81 return paintMediaButton(paintInfo.getContext(), rect, soundDisabled);
82 82
83 if (mediaElement->muted() || mediaElement->volume() <= 0) 83 if (mediaElement->muted() || mediaElement->volume() <= 0)
84 return paintMediaButton(paintInfo.context, rect, soundLevel0); 84 return paintMediaButton(paintInfo.getContext(), rect, soundLevel0);
85 85
86 if (mediaElement->volume() <= 0.33) 86 if (mediaElement->volume() <= 0.33)
87 return paintMediaButton(paintInfo.context, rect, soundLevel1); 87 return paintMediaButton(paintInfo.getContext(), rect, soundLevel1);
88 88
89 if (mediaElement->volume() <= 0.66) 89 if (mediaElement->volume() <= 0.66)
90 return paintMediaButton(paintInfo.context, rect, soundLevel2); 90 return paintMediaButton(paintInfo.getContext(), rect, soundLevel2);
91 91
92 return paintMediaButton(paintInfo.context, rect, soundLevel3); 92 return paintMediaButton(paintInfo.getContext(), rect, soundLevel3);
93 } 93 }
94 94
95 static bool paintMediaPlayButton(RenderObject* object, const PaintInfo& paintInf o, const IntRect& rect) 95 static bool paintMediaPlayButton(RenderObject* object, PaintInfo& paintInfo, con st IntRect& rect)
96 { 96 {
97 HTMLMediaElement* mediaElement = toParentMediaElement(object); 97 HTMLMediaElement* mediaElement = toParentMediaElement(object);
98 if (!mediaElement) 98 if (!mediaElement)
99 return false; 99 return false;
100 100
101 static Image* mediaPlay = platformResource("mediaplayerPlay"); 101 static Image* mediaPlay = platformResource("mediaplayerPlay");
102 static Image* mediaPause = platformResource("mediaplayerPause"); 102 static Image* mediaPause = platformResource("mediaplayerPause");
103 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" ); 103 static Image* mediaPlayDisabled = platformResource("mediaplayerPlayDisabled" );
104 104
105 if (!hasSource(mediaElement)) 105 if (!hasSource(mediaElement))
106 return paintMediaButton(paintInfo.context, rect, mediaPlayDisabled); 106 return paintMediaButton(paintInfo.getContext(), rect, mediaPlayDisabled) ;
107 107
108 return paintMediaButton(paintInfo.context, rect, mediaElement->canPlay() ? m ediaPlay : mediaPause); 108 return paintMediaButton(paintInfo.getContext(), rect, mediaElement->canPlay( ) ? mediaPlay : mediaPause);
109 } 109 }
110 110
111 static bool paintMediaOverlayPlayButton(RenderObject* object, const PaintInfo& p aintInfo, const IntRect& rect) 111 static bool paintMediaOverlayPlayButton(RenderObject* object, PaintInfo& paintIn fo, const IntRect& rect)
112 { 112 {
113 HTMLMediaElement* mediaElement = toParentMediaElement(object); 113 HTMLMediaElement* mediaElement = toParentMediaElement(object);
114 if (!mediaElement) 114 if (!mediaElement)
115 return false; 115 return false;
116 116
117 if (!hasSource(mediaElement) || !mediaElement->canPlay()) 117 if (!hasSource(mediaElement) || !mediaElement->canPlay())
118 return false; 118 return false;
119 119
120 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay"); 120 static Image* mediaOverlayPlay = platformResource("mediaplayerOverlayPlay");
121 return paintMediaButton(paintInfo.context, rect, mediaOverlayPlay); 121 return paintMediaButton(paintInfo.getContext(), rect, mediaOverlayPlay);
122 } 122 }
123 123
124 static Image* getMediaSliderThumb() 124 static Image* getMediaSliderThumb()
125 { 125 {
126 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb"); 126 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb");
127 return mediaSliderThumb; 127 return mediaSliderThumb;
128 } 128 }
129 129
130 static void paintRoundedSliderBackground(const IntRect& rect, const RenderStyle* style, GraphicsContext* context) 130 static void paintRoundedSliderBackground(const IntRect& rect, const RenderStyle* style, GraphicsContext* context)
131 { 131 {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 else if (endOffset < borderRadius) 188 else if (endOffset < borderRadius)
189 context->fillRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii, startColor); 189 context->fillRoundedRect(highlightRect, IntSize(0, 0), radii, IntSize(0, 0), radii, startColor);
190 else 190 else
191 context->fillRect(highlightRect); 191 context->fillRect(highlightRect);
192 192
193 context->restore(); 193 context->restore();
194 } 194 }
195 195
196 const int mediaSliderThumbWidth = 32; 196 const int mediaSliderThumbWidth = 32;
197 197
198 static bool paintMediaSlider(RenderObject* object, const PaintInfo& paintInfo, c onst IntRect& rect) 198 static bool paintMediaSlider(RenderObject* object, PaintInfo& paintInfo, const I ntRect& rect)
199 { 199 {
200 HTMLMediaElement* mediaElement = toParentMediaElement(object); 200 HTMLMediaElement* mediaElement = toParentMediaElement(object);
201 if (!mediaElement) 201 if (!mediaElement)
202 return false; 202 return false;
203 203
204 RenderStyle* style = object->style(); 204 RenderStyle* style = object->style();
205 GraphicsContext* context = paintInfo.context; 205 GraphicsContext* context = paintInfo.getContext();
206 206
207 paintRoundedSliderBackground(rect, style, context); 207 paintRoundedSliderBackground(rect, style, context);
208 208
209 // Draw the buffered range. Since the element may have multiple buffered ran ges and it'd be 209 // Draw the buffered range. Since the element may have multiple buffered ran ges and it'd be
210 // distracting/'busy' to show all of them, show only the buffered range cont aining the current play head. 210 // distracting/'busy' to show all of them, show only the buffered range cont aining the current play head.
211 RefPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered(); 211 RefPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered();
212 float duration = mediaElement->duration(); 212 float duration = mediaElement->duration();
213 float currentTime = mediaElement->currentTime(); 213 float currentTime = mediaElement->currentTime();
214 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime)) 214 if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan( currentTime))
215 return true; 215 return true;
(...skipping 24 matching lines...) Expand all
240 240
241 if (endPosition > currentPosition) 241 if (endPosition > currentPosition)
242 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor); 242 paintSliderRangeHighlight(rect, style, context, currentPosition, end Position, startColor, endColor);
243 243
244 return true; 244 return true;
245 } 245 }
246 246
247 return true; 247 return true;
248 } 248 }
249 249
250 static bool paintMediaSliderThumb(RenderObject* object, const PaintInfo& paintIn fo, const IntRect& rect) 250 static bool paintMediaSliderThumb(RenderObject* object, PaintInfo& paintInfo, co nst IntRect& rect)
251 { 251 {
252 ASSERT(object->node()); 252 ASSERT(object->node());
253 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); 253 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host());
254 if (!mediaElement) 254 if (!mediaElement)
255 return false; 255 return false;
256 256
257 if (!hasSource(mediaElement)) 257 if (!hasSource(mediaElement))
258 return true; 258 return true;
259 259
260 Image* mediaSliderThumb = getMediaSliderThumb(); 260 Image* mediaSliderThumb = getMediaSliderThumb();
261 return paintMediaButton(paintInfo.context, rect, mediaSliderThumb); 261 return paintMediaButton(paintInfo.getContext(), rect, mediaSliderThumb);
262 } 262 }
263 263
264 const int mediaVolumeSliderThumbWidth = 24; 264 const int mediaVolumeSliderThumbWidth = 24;
265 265
266 static bool paintMediaVolumeSlider(RenderObject* object, const PaintInfo& paintI nfo, const IntRect& rect) 266 static bool paintMediaVolumeSlider(RenderObject* object, PaintInfo& paintInfo, c onst IntRect& rect)
267 { 267 {
268 HTMLMediaElement* mediaElement = toParentMediaElement(object); 268 HTMLMediaElement* mediaElement = toParentMediaElement(object);
269 if (!mediaElement) 269 if (!mediaElement)
270 return false; 270 return false;
271 271
272 GraphicsContext* context = paintInfo.context; 272 GraphicsContext* context = paintInfo.getContext();
273 RenderStyle* style = object->style(); 273 RenderStyle* style = object->style();
274 274
275 paintRoundedSliderBackground(rect, style, context); 275 paintRoundedSliderBackground(rect, style, context);
276 276
277 // Calculate volume position for white background rectangle. 277 // Calculate volume position for white background rectangle.
278 float volume = mediaElement->volume(); 278 float volume = mediaElement->volume();
279 if (std::isnan(volume) || volume < 0) 279 if (std::isnan(volume) || volume < 0)
280 return true; 280 return true;
281 if (volume > 1) 281 if (volume > 1)
282 volume = 1; 282 volume = 1;
(...skipping 10 matching lines...) Expand all
293 } 293 }
294 294
295 Color startColor = Color(195, 195, 195); 295 Color startColor = Color(195, 195, 195);
296 Color endColor = Color(217, 217, 217); 296 Color endColor = Color(217, 217, 217);
297 297
298 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor); 298 paintSliderRangeHighlight(rect, style, context, 0.0, fillWidth, startColor, endColor);
299 299
300 return true; 300 return true;
301 } 301 }
302 302
303 static bool paintMediaVolumeSliderThumb(RenderObject* object, const PaintInfo& p aintInfo, const IntRect& rect) 303 static bool paintMediaVolumeSliderThumb(RenderObject* object, PaintInfo& paintIn fo, const IntRect& rect)
304 { 304 {
305 ASSERT(object->node()); 305 ASSERT(object->node());
306 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host()); 306 HTMLMediaElement* mediaElement = toParentMediaElement(object->node()->shadow Host());
307 if (!mediaElement) 307 if (!mediaElement)
308 return false; 308 return false;
309 309
310 if (!hasSource(mediaElement) || !mediaElement->hasAudio()) 310 if (!hasSource(mediaElement) || !mediaElement->hasAudio())
311 return true; 311 return true;
312 312
313 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb"); 313 static Image* mediaVolumeSliderThumb = platformResource("mediaplayerVolumeSl iderThumb");
314 return paintMediaButton(paintInfo.context, rect, mediaVolumeSliderThumb); 314 return paintMediaButton(paintInfo.getContext(), rect, mediaVolumeSliderThumb );
315 } 315 }
316 316
317 static bool paintMediaFullscreenButton(RenderObject* object, const PaintInfo& pa intInfo, const IntRect& rect) 317 static bool paintMediaFullscreenButton(RenderObject* object, PaintInfo& paintInf o, const IntRect& rect)
318 { 318 {
319 HTMLMediaElement* mediaElement = toParentMediaElement(object); 319 HTMLMediaElement* mediaElement = toParentMediaElement(object);
320 if (!mediaElement) 320 if (!mediaElement)
321 return false; 321 return false;
322 322
323 static Image* mediaFullscreenButton = platformResource("mediaplayerFullscree n"); 323 static Image* mediaFullscreenButton = platformResource("mediaplayerFullscree n");
324 return paintMediaButton(paintInfo.context, rect, mediaFullscreenButton); 324 return paintMediaButton(paintInfo.getContext(), rect, mediaFullscreenButton) ;
325 } 325 }
326 326
327 static bool paintMediaToggleClosedCaptionsButton(RenderObject* object, const Pai ntInfo& paintInfo, const IntRect& rect) 327 static bool paintMediaToggleClosedCaptionsButton(RenderObject* object, PaintInfo & paintInfo, const IntRect& rect)
328 { 328 {
329 HTMLMediaElement* mediaElement = toParentMediaElement(object); 329 HTMLMediaElement* mediaElement = toParentMediaElement(object);
330 if (!mediaElement) 330 if (!mediaElement)
331 return false; 331 return false;
332 332
333 static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosed Caption"); 333 static Image* mediaClosedCaptionButton = platformResource("mediaplayerClosed Caption");
334 static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplay erClosedCaptionDisabled"); 334 static Image* mediaClosedCaptionButtonDisabled = platformResource("mediaplay erClosedCaptionDisabled");
335 335
336 if (mediaElement->webkitClosedCaptionsVisible()) 336 if (mediaElement->webkitClosedCaptionsVisible())
337 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButto n); 337 return paintMediaButton(paintInfo.getContext(), rect, mediaClosedCaption Button);
338 338
339 return paintMediaButton(paintInfo.context, rect, mediaClosedCaptionButtonDis abled); 339 return paintMediaButton(paintInfo.getContext(), rect, mediaClosedCaptionButt onDisabled);
340 } 340 }
341 341
342 342
343 bool RenderMediaControlsChromium::paintMediaControlsPart(MediaControlElementType part, RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) 343 bool RenderMediaControlsChromium::paintMediaControlsPart(MediaControlElementType part, RenderObject* object, PaintInfo& paintInfo, const IntRect& rect)
344 { 344 {
345 switch (part) { 345 switch (part) {
346 case MediaMuteButton: 346 case MediaMuteButton:
347 case MediaUnMuteButton: 347 case MediaUnMuteButton:
348 return paintMediaMuteButton(object, paintInfo, rect); 348 return paintMediaMuteButton(object, paintInfo, rect);
349 case MediaPauseButton: 349 case MediaPauseButton:
350 case MediaPlayButton: 350 case MediaPlayButton:
351 return paintMediaPlayButton(object, paintInfo, rect); 351 return paintMediaPlayButton(object, paintInfo, rect);
352 case MediaShowClosedCaptionsButton: 352 case MediaShowClosedCaptionsButton:
353 return paintMediaToggleClosedCaptionsButton(object, paintInfo, rect); 353 return paintMediaToggleClosedCaptionsButton(object, paintInfo, rect);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 { 442 {
443 return formatChromiumMediaControlsTime(time, time); 443 return formatChromiumMediaControlsTime(time, time);
444 } 444 }
445 445
446 String RenderMediaControlsChromium::formatMediaControlsCurrentTime(float current Time, float duration) 446 String RenderMediaControlsChromium::formatMediaControlsCurrentTime(float current Time, float duration)
447 { 447 {
448 return formatChromiumMediaControlsTime(currentTime, duration); 448 return formatChromiumMediaControlsTime(currentTime, duration);
449 } 449 }
450 450
451 } // namespace WebCore 451 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698