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

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

Issue 2392443009: reflow comments in core/paint (Closed)
Patch Set: Created 4 years, 2 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 sliderBackgroundColor); 255 sliderBackgroundColor);
256 } 256 }
257 257
258 static void paintSliderRangeHighlight(const IntRect& rect, 258 static void paintSliderRangeHighlight(const IntRect& rect,
259 const ComputedStyle& style, 259 const ComputedStyle& style,
260 GraphicsContext& context, 260 GraphicsContext& context,
261 int startPosition, 261 int startPosition,
262 int endPosition, 262 int endPosition,
263 Color startColor, 263 Color startColor,
264 Color endColor) { 264 Color endColor) {
265 // Calculate border radius; need to avoid being smaller than half the slider h eight 265 // Calculate border radius; need to avoid being smaller than half the slider
266 // because of https://bugs.webkit.org/show_bug.cgi?id=30143. 266 // height because of https://bugs.webkit.org/show_bug.cgi?id=30143.
267 float borderRadius = rect.height() / 2.0f; 267 float borderRadius = rect.height() / 2.0f;
268 FloatSize radii(borderRadius, borderRadius); 268 FloatSize radii(borderRadius, borderRadius);
269 269
270 // Calculate highlight rectangle and edge dimensions. 270 // Calculate highlight rectangle and edge dimensions.
271 int startOffset = startPosition; 271 int startOffset = startPosition;
272 int endOffset = rect.width() - endPosition; 272 int endOffset = rect.width() - endPosition;
273 int rangeWidth = endPosition - startPosition; 273 int rangeWidth = endPosition - startPosition;
274 274
275 if (rangeWidth <= 0) 275 if (rangeWidth <= 0)
276 return; 276 return;
277 277
278 // Make sure the range width is bigger than border radius at the edges to reta in rounded corners. 278 // Make sure the range width is bigger than border radius at the edges to
279 // retain rounded corners.
279 if (startOffset < borderRadius && rangeWidth < borderRadius) 280 if (startOffset < borderRadius && rangeWidth < borderRadius)
280 rangeWidth = borderRadius; 281 rangeWidth = borderRadius;
281 if (endOffset < borderRadius && rangeWidth < borderRadius) 282 if (endOffset < borderRadius && rangeWidth < borderRadius)
282 rangeWidth = borderRadius; 283 rangeWidth = borderRadius;
283 284
284 // Set rectangle to highlight range. 285 // Set rectangle to highlight range.
285 IntRect highlightRect = rect; 286 IntRect highlightRect = rect;
286 highlightRect.move(startOffset, 0); 287 highlightRect.move(startOffset, 0);
287 highlightRect.setWidth(rangeWidth); 288 highlightRect.setWidth(rangeWidth);
288 289
289 // Don't bother drawing an empty area. 290 // Don't bother drawing an empty area.
290 if (highlightRect.isEmpty()) 291 if (highlightRect.isEmpty())
291 return; 292 return;
292 293
293 // Calculate white-grey gradient. 294 // Calculate white-grey gradient.
294 FloatPoint sliderTopLeft = highlightRect.location(); 295 FloatPoint sliderTopLeft = highlightRect.location();
295 FloatPoint sliderBottomLeft = sliderTopLeft; 296 FloatPoint sliderBottomLeft = sliderTopLeft;
296 sliderBottomLeft.move(0, highlightRect.height()); 297 sliderBottomLeft.move(0, highlightRect.height());
297 RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft); 298 RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft);
298 gradient->addColorStop(0.0, startColor); 299 gradient->addColorStop(0.0, startColor);
299 gradient->addColorStop(1.0, endColor); 300 gradient->addColorStop(1.0, endColor);
300 301
301 // Fill highlight rectangle with gradient, potentially rounded if on left or r ight edge. 302 // Fill highlight rectangle with gradient, potentially rounded if on left or
303 // right edge.
302 SkPaint gradientPaint(context.fillPaint()); 304 SkPaint gradientPaint(context.fillPaint());
303 gradient->applyToPaint(gradientPaint, SkMatrix::I()); 305 gradient->applyToPaint(gradientPaint, SkMatrix::I());
304 306
305 if (startOffset < borderRadius && endOffset < borderRadius) 307 if (startOffset < borderRadius && endOffset < borderRadius)
306 context.drawRRect( 308 context.drawRRect(
307 FloatRoundedRect(highlightRect, radii, radii, radii, radii), 309 FloatRoundedRect(highlightRect, radii, radii, radii, radii),
308 gradientPaint); 310 gradientPaint);
309 else if (startOffset < borderRadius) 311 else if (startOffset < borderRadius)
310 context.drawRRect(FloatRoundedRect(highlightRect, radii, FloatSize(0, 0), 312 context.drawRRect(FloatRoundedRect(highlightRect, radii, FloatSize(0, 0),
311 radii, FloatSize(0, 0)), 313 radii, FloatSize(0, 0)),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 356
355 // Paint the slider bar in the "no data buffered" state. 357 // Paint the slider bar in the "no data buffered" state.
356 Color sliderBackgroundColor; 358 Color sliderBackgroundColor;
357 if (!useNewUi) 359 if (!useNewUi)
358 sliderBackgroundColor = Color(11, 11, 11); 360 sliderBackgroundColor = Color(11, 11, 11);
359 else 361 else
360 sliderBackgroundColor = Color(0xda, 0xda, 0xda); 362 sliderBackgroundColor = Color(0xda, 0xda, 0xda);
361 363
362 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); 364 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);
363 365
364 // Draw the buffered range. Since the element may have multiple buffered range s and it'd be 366 // Draw the buffered range. Since the element may have multiple buffered
365 // distracting/'busy' to show all of them, show only the buffered range contai ning the current play head. 367 // ranges and it'd be distracting/'busy' to show all of them, show only the
368 // buffered range containing the current play head.
366 TimeRanges* bufferedTimeRanges = mediaElement->buffered(); 369 TimeRanges* bufferedTimeRanges = mediaElement->buffered();
367 float duration = mediaElement->duration(); 370 float duration = mediaElement->duration();
368 float currentTime = mediaElement->currentTime(); 371 float currentTime = mediaElement->currentTime();
369 if (std::isnan(duration) || std::isinf(duration) || !duration || 372 if (std::isnan(duration) || std::isinf(duration) || !duration ||
370 std::isnan(currentTime)) 373 std::isnan(currentTime))
371 return; 374 return;
372 375
373 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) { 376 for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) {
374 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION); 377 float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION);
375 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION); 378 float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION);
376 // The delta is there to avoid corner cases when buffered 379 // The delta is there to avoid corner cases when buffered
377 // ranges is out of sync with current time because of 380 // ranges is out of sync with current time because of
378 // asynchronous media pipeline and current time caching in 381 // asynchronous media pipeline and current time caching in
379 // HTMLMediaElement. 382 // HTMLMediaElement.
380 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=28125 383 // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=28125
381 // FIXME: Remove this workaround when WebMediaPlayer 384 // FIXME: Remove this workaround when WebMediaPlayer
382 // has an asynchronous pause interface. 385 // has an asynchronous pause interface.
383 if (std::isnan(start) || std::isnan(end) || 386 if (std::isnan(start) || std::isnan(end) ||
384 start > currentTime + kCurrentTimeBufferedDelta || end < currentTime) 387 start > currentTime + kCurrentTimeBufferedDelta || end < currentTime)
385 continue; 388 continue;
386 int startPosition = int(start * rect.width() / duration); 389 int startPosition = int(start * rect.width() / duration);
387 int currentPosition = int(currentTime * rect.width() / duration); 390 int currentPosition = int(currentTime * rect.width() / duration);
388 int endPosition = int(end * rect.width() / duration); 391 int endPosition = int(end * rect.width() / duration);
389 392
390 if (!useNewUi) { 393 if (!useNewUi) {
391 // Add half the thumb width proportionally adjusted to the current paintin g position. 394 // Add half the thumb width proportionally adjusted to the current
395 // painting position.
392 int thumbCenter = mediaSliderThumbWidth / 2; 396 int thumbCenter = mediaSliderThumbWidth / 2;
393 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width()); 397 int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width());
394 currentPosition += addWidth; 398 currentPosition += addWidth;
395 } 399 }
396 400
397 // Draw highlight before current time. 401 // Draw highlight before current time.
398 Color startColor; 402 Color startColor;
399 Color endColor; 403 Color endColor;
400 if (!useNewUi) { 404 if (!useNewUi) {
401 startColor = Color(195, 195, 195); // white-ish. 405 startColor = Color(195, 195, 195); // white-ish.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 const PaintInfo& paintInfo, 602 const PaintInfo& paintInfo,
599 const IntRect& rect) { 603 const IntRect& rect) {
600 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 604 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
601 if (!mediaElement) 605 if (!mediaElement)
602 return false; 606 return false;
603 607
604 static Image* mediaCastOn = 608 static Image* mediaCastOn =
605 platformResource("mediaplayerCastOn", "mediaplayerCastOnNew"); 609 platformResource("mediaplayerCastOn", "mediaplayerCastOnNew");
606 static Image* mediaCastOff = 610 static Image* mediaCastOff =
607 platformResource("mediaplayerCastOff", "mediaplayerCastOffNew"); 611 platformResource("mediaplayerCastOff", "mediaplayerCastOffNew");
608 // To ensure that the overlaid cast button is visible when overlaid on pale vi deos we use a 612 // To ensure that the overlaid cast button is visible when overlaid on pale
609 // different version of it for the overlaid case with a semi-opaque background . 613 // videos we use a different version of it for the overlaid case with a
614 // semi-opaque background.
610 static Image* mediaOverlayCastOff = platformResource( 615 static Image* mediaOverlayCastOff = platformResource(
611 "mediaplayerOverlayCastOff", "mediaplayerOverlayCastOffNew"); 616 "mediaplayerOverlayCastOff", "mediaplayerOverlayCastOffNew");
612 617
613 bool isEnabled = mediaElement->hasRemoteRoutes(); 618 bool isEnabled = mediaElement->hasRemoteRoutes();
614 619
615 switch (mediaControlElementType(object.node())) { 620 switch (mediaControlElementType(object.node())) {
616 case MediaCastOnButton: 621 case MediaCastOnButton:
617 return paintMediaButton(paintInfo.context, rect, mediaCastOn, &object, 622 return paintMediaButton(paintInfo.context, rect, mediaCastOn, &object,
618 isEnabled); 623 isEnabled);
619 case MediaOverlayCastOnButton: 624 case MediaOverlayCastOnButton:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 } 727 }
723 728
724 float zoomLevel = style.effectiveZoom(); 729 float zoomLevel = style.effectiveZoom();
725 if (thumbImage) { 730 if (thumbImage) {
726 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); 731 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed));
727 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); 732 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed));
728 } 733 }
729 } 734 }
730 735
731 } // namespace blink 736 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698