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

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

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Return currentName or newName based on current or new playback. 82 // Return currentName or newName based on current or new playback.
83 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName); 83 return platformResource(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() ? newName : currentName);
84 } 84 }
85 85
86 static bool hasSource(const HTMLMediaElement* mediaElement) 86 static bool hasSource(const HTMLMediaElement* mediaElement)
87 { 87 {
88 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY 88 return mediaElement->networkState() != HTMLMediaElement::NETWORK_EMPTY
89 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE; 89 && mediaElement->networkState() != HTMLMediaElement::NETWORK_NO_SOURCE;
90 } 90 }
91 91
92 static bool paintMediaButton(GraphicsContext* context, const IntRect& rect, Imag e* image, bool isEnabled = true) 92 static bool paintMediaButton(GraphicsContext& context, const IntRect& rect, Imag e* image, bool isEnabled = true)
93 { 93 {
94 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) 94 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
95 isEnabled = true; // New UI only. 95 isEnabled = true; // New UI only.
96 96
97 if (!isEnabled) 97 if (!isEnabled)
98 context->beginLayer(kDisabledAlpha); 98 context.beginLayer(kDisabledAlpha);
99 99
100 context->drawImage(image, rect); 100 context.drawImage(image, rect);
101 101
102 if (!isEnabled) 102 if (!isEnabled)
103 context->endLayer(); 103 context.endLayer();
104 104
105 return true; 105 return true;
106 } 106 }
107 107
108 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons t PaintInfo& paintInfo, const IntRect& rect) 108 bool MediaControlsPainter::paintMediaMuteButton(const LayoutObject& object, cons t PaintInfo& paintInfo, const IntRect& rect)
109 { 109 {
110 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 110 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
111 if (!mediaElement) 111 if (!mediaElement)
112 return false; 112 return false;
113 113
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay); 187 return paintMediaButton(paintInfo.context, buttonRect, mediaOverlayPlay);
188 } 188 }
189 189
190 static Image* getMediaSliderThumb() 190 static Image* getMediaSliderThumb()
191 { 191 {
192 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb", 192 static Image* mediaSliderThumb = platformResource("mediaplayerSliderThumb",
193 "mediaplayerSliderThumbNew"); 193 "mediaplayerSliderThumbNew");
194 return mediaSliderThumb; 194 return mediaSliderThumb;
195 } 195 }
196 196
197 static void paintRoundedSliderBackground(const IntRect& rect, const ComputedStyl e& style, GraphicsContext* context, Color sliderBackgroundColor ) 197 static void paintRoundedSliderBackground(const IntRect& rect, const ComputedStyl e& style, GraphicsContext& context, Color sliderBackgroundColor )
198 { 198 {
199 float borderRadius = rect.height() / 2; 199 float borderRadius = rect.height() / 2;
200 FloatSize radii(borderRadius, borderRadius); 200 FloatSize radii(borderRadius, borderRadius);
201 201
202 context->fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), sliderBackgroundColor); 202 context.fillRoundedRect(FloatRoundedRect(rect, radii, radii, radii, radii), sliderBackgroundColor);
203 } 203 }
204 204
205 static void paintSliderRangeHighlight(const IntRect& rect, const ComputedStyle& style, GraphicsContext* context, int startPosition, int endPosition, Color start Color, Color endColor) 205 static void paintSliderRangeHighlight(const IntRect& rect, const ComputedStyle& style, GraphicsContext& context, int startPosition, int endPosition, Color start Color, Color endColor)
206 { 206 {
207 // Calculate border radius; need to avoid being smaller than half the slider height 207 // Calculate border radius; need to avoid being smaller than half the slider height
208 // because of https://bugs.webkit.org/show_bug.cgi?id=30143. 208 // because of https://bugs.webkit.org/show_bug.cgi?id=30143.
209 float borderRadius = rect.height() / 2.0f; 209 float borderRadius = rect.height() / 2.0f;
210 FloatSize radii(borderRadius, borderRadius); 210 FloatSize radii(borderRadius, borderRadius);
211 211
212 // Calculate highlight rectangle and edge dimensions. 212 // Calculate highlight rectangle and edge dimensions.
213 int startOffset = startPosition; 213 int startOffset = startPosition;
214 int endOffset = rect.width() - endPosition; 214 int endOffset = rect.width() - endPosition;
215 int rangeWidth = endPosition - startPosition; 215 int rangeWidth = endPosition - startPosition;
(...skipping 18 matching lines...) Expand all
234 234
235 // Calculate white-grey gradient. 235 // Calculate white-grey gradient.
236 FloatPoint sliderTopLeft = highlightRect.location(); 236 FloatPoint sliderTopLeft = highlightRect.location();
237 FloatPoint sliderBottomLeft = sliderTopLeft; 237 FloatPoint sliderBottomLeft = sliderTopLeft;
238 sliderBottomLeft.move(0, highlightRect.height()); 238 sliderBottomLeft.move(0, highlightRect.height());
239 RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft ); 239 RefPtr<Gradient> gradient = Gradient::create(sliderTopLeft, sliderBottomLeft );
240 gradient->addColorStop(0.0, startColor); 240 gradient->addColorStop(0.0, startColor);
241 gradient->addColorStop(1.0, endColor); 241 gradient->addColorStop(1.0, endColor);
242 242
243 // Fill highlight rectangle with gradient, potentially rounded if on left or right edge. 243 // Fill highlight rectangle with gradient, potentially rounded if on left or right edge.
244 context->save(); 244 context.save();
245 context->setFillGradient(gradient); 245 context.setFillGradient(gradient);
246 246
247 if (startOffset < borderRadius && endOffset < borderRadius) 247 if (startOffset < borderRadius && endOffset < borderRadius)
248 context->fillRoundedRect(FloatRoundedRect(highlightRect, radii, radii, r adii, radii), startColor); 248 context.fillRoundedRect(FloatRoundedRect(highlightRect, radii, radii, ra dii, radii), startColor);
249 else if (startOffset < borderRadius) 249 else if (startOffset < borderRadius)
250 context->fillRoundedRect(FloatRoundedRect(highlightRect, radii, FloatSiz e(0, 0), radii, FloatSize(0, 0)), startColor); 250 context.fillRoundedRect(FloatRoundedRect(highlightRect, radii, FloatSize (0, 0), radii, FloatSize(0, 0)), startColor);
251 else if (endOffset < borderRadius) 251 else if (endOffset < borderRadius)
252 context->fillRoundedRect(FloatRoundedRect(highlightRect, FloatSize(0, 0) , radii, FloatSize(0, 0), radii), startColor); 252 context.fillRoundedRect(FloatRoundedRect(highlightRect, FloatSize(0, 0), radii, FloatSize(0, 0), radii), startColor);
253 else 253 else
254 context->fillRect(highlightRect); 254 context.fillRect(highlightRect);
255 255
256 context->restore(); 256 context.restore();
257 } 257 }
258 258
259 bool MediaControlsPainter::paintMediaSlider(const LayoutObject& object, const Pa intInfo& paintInfo, const IntRect& rect) 259 bool MediaControlsPainter::paintMediaSlider(const LayoutObject& object, const Pa intInfo& paintInfo, const IntRect& rect)
260 { 260 {
261 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 261 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
262 if (!mediaElement) 262 if (!mediaElement)
263 return false; 263 return false;
264 264
265 GraphicsContext* context = paintInfo.context; 265 GraphicsContext& context = paintInfo.context;
266 266
267 // Should we paint the slider partially transparent? 267 // Should we paint the slider partially transparent?
268 bool drawUiGrayed = !hasSource(mediaElement) && RuntimeEnabledFeatures::newM ediaPlaybackUiEnabled(); 268 bool drawUiGrayed = !hasSource(mediaElement) && RuntimeEnabledFeatures::newM ediaPlaybackUiEnabled();
269 if (drawUiGrayed) 269 if (drawUiGrayed)
270 context->beginLayer(kDisabledAlpha); 270 context.beginLayer(kDisabledAlpha);
271 271
272 paintMediaSliderInternal(object, paintInfo, rect); 272 paintMediaSliderInternal(object, paintInfo, rect);
273 273
274 if (drawUiGrayed) 274 if (drawUiGrayed)
275 context->endLayer(); 275 context.endLayer();
276 276
277 return true; 277 return true;
278 } 278 }
279 279
280 void MediaControlsPainter::paintMediaSliderInternal(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect) 280 void MediaControlsPainter::paintMediaSliderInternal(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect)
281 { 281 {
282 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); 282 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
283 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 283 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
284 if (!mediaElement) 284 if (!mediaElement)
285 return; 285 return;
286 286
287 const ComputedStyle& style = object.styleRef(); 287 const ComputedStyle& style = object.styleRef();
288 GraphicsContext* context = paintInfo.context; 288 GraphicsContext& context = paintInfo.context;
289 289
290 // Paint the slider bar in the "no data buffered" state. 290 // Paint the slider bar in the "no data buffered" state.
291 Color sliderBackgroundColor; 291 Color sliderBackgroundColor;
292 if (!useNewUi) 292 if (!useNewUi)
293 sliderBackgroundColor = Color(11, 11, 11); 293 sliderBackgroundColor = Color(11, 11, 11);
294 else 294 else
295 sliderBackgroundColor = Color(0xda, 0xda, 0xda); 295 sliderBackgroundColor = Color(0xda, 0xda, 0xda);
296 296
297 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); 297 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);
298 298
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 adjustMediaSliderThumbPaintSize(rect, style, paintRect); 397 adjustMediaSliderThumbPaintSize(rect, style, paintRect);
398 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb); 398 return paintMediaButton(paintInfo.context, paintRect, mediaSliderThumb);
399 } 399 }
400 400
401 bool MediaControlsPainter::paintMediaVolumeSlider(const LayoutObject& object, co nst PaintInfo& paintInfo, const IntRect& rect) 401 bool MediaControlsPainter::paintMediaVolumeSlider(const LayoutObject& object, co nst PaintInfo& paintInfo, const IntRect& rect)
402 { 402 {
403 const HTMLMediaElement* mediaElement = toParentMediaElement(object); 403 const HTMLMediaElement* mediaElement = toParentMediaElement(object);
404 if (!mediaElement) 404 if (!mediaElement)
405 return false; 405 return false;
406 406
407 GraphicsContext* context = paintInfo.context; 407 GraphicsContext& context = paintInfo.context;
408 const ComputedStyle& style = object.styleRef(); 408 const ComputedStyle& style = object.styleRef();
409 409
410 // Paint the slider bar. 410 // Paint the slider bar.
411 Color sliderBackgroundColor; 411 Color sliderBackgroundColor;
412 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) 412 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
413 sliderBackgroundColor = Color(11, 11, 11); 413 sliderBackgroundColor = Color(11, 11, 11);
414 else 414 else
415 sliderBackgroundColor = Color(0x9f, 0x9f, 0x9f); 415 sliderBackgroundColor = Color(0x9f, 0x9f, 0x9f);
416 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor); 416 paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);
417 417
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 570 }
571 571
572 float zoomLevel = style.effectiveZoom(); 572 float zoomLevel = style.effectiveZoom();
573 if (thumbImage) { 573 if (thumbImage) {
574 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed)); 574 style.setWidth(Length(static_cast<int>(width * zoomLevel), Fixed));
575 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed)); 575 style.setHeight(Length(static_cast<int>(height * zoomLevel), Fixed));
576 } 576 }
577 } 577 }
578 578
579 } // namespace blink 579 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698